/* content/chrome.css */
/* Loaded right after default.css: the menu button, sidebar card, mobile
   drawer and home-page lists. */

/* --------------------------------------------------------------------------
   Header menu button. Wide screens: summons the floating sidebar card.
   .mobile: opens the drawer.
   -------------------------------------------------------------------------- */
.menu-toggle {
    margin-left: auto;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    min-height: 44px;
    padding: 0 1rem;
    background: none;
    color: var(--header-text);
    border: 1px solid color-mix(in srgb, var(--header-text) 30%, transparent);
    border-radius: 999px;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle svg,
.menu-fab svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.menu-toggle:hover,
.menu-toggle[aria-expanded="true"] {
    background: color-mix(in srgb, var(--accent-color) 25%, transparent);
    border-color: var(--accent-color);
}

.menu-toggle:focus-visible,
.menu-fab:focus-visible,
#close-sidebar:focus-visible,
#theme-toggle:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Sidebar — wide screens: a floating card bottom-right (theme.js fades it
   in near the end of a post, or the Posts button summons it).
   -------------------------------------------------------------------------- */
#sidebar {
    position: fixed;
    right: 2rem;
    bottom: 2rem;
    width: 280px;
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
    border-radius: 6px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

#sidebar.force-visible {
    opacity: 1 !important;
    pointer-events: auto !important;
}

#sidebar .sidebar-content {
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* On the card the close button floats in the corner and the home link is
   left to the page header. */
.sidebar-head {
    position: absolute;
    top: 5px;
    right: 10px;
    z-index: 1;
}

.sidebar-home {
    display: none;
}

#close-sidebar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    font-weight: bold;
    color: var(--text-muted);
    transition: color 0.2s ease, background-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

#close-sidebar:hover {
    color: var(--accent-color);
}

/* The drawer's copy of the TOC only exists for .mobile (see below). */
.drawer-toc {
    display: none;
}

/* The in-page |||  sidebar (index.md) duplicates #sidebar on wide screens. */
.main-content .sidebar {
    display: none;
}

.latest-posts h2,
.drawer-toc h2 {
    margin-top: 0;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--sidebar-border);
    padding-bottom: 0.5rem;
}

.latest-posts ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.latest-posts li {
    margin-bottom: 0.8rem;
    font-size: 0.88rem;
    display: flex;
    flex-direction: column;
}

.latest-posts .date {
    font-family: var(--font-heading);
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.latest-posts a {
    text-decoration: none;
    font-weight: 600;
}

.latest-posts a:hover {
    color: var(--accent-color);
}

.directory-link {
    margin-top: 1.5rem;
    text-align: center;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Floating menu button: .mobile only, once the header is scrolled away. */
.menu-fab {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

/* --------------------------------------------------------------------------
   .mobile — set on <html> before first paint (style.go) and kept current
   by theme.js, for windows 900px wide or less. Every mobile variant is
   written `.mobile .thing`, so a post's sheet can do the same.
   -------------------------------------------------------------------------- */

.mobile .main-header {
    padding: 1rem 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    margin-bottom: 2rem;
}

.mobile .header-content {
    gap: 0.85rem;
}

.mobile .main-header h1 {
    font-size: 1.15rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.mobile .header-logo img {
    height: 40px;
    width: 40px;
}

.mobile .menu-toggle {
    padding: 0 0.85rem;
}

/* The drawer: off-canvas from the right, full height, scrolls on its own
   while the page underneath is locked (html.drawer-open). */
.mobile #sidebar {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(88vw, 380px);
    height: 100%;
    height: 100dvh;
    max-height: none;
    padding: 0;
    border: none;
    border-left: 1px solid var(--sidebar-border);
    border-radius: 16px 0 0 16px;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.35);
    opacity: 1 !important;
    pointer-events: auto !important;
    visibility: hidden;
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.3s;
    touch-action: pan-y;
    z-index: 200;
}

.mobile #sidebar.open {
    visibility: visible;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
}

/* Following the finger: no easing while dragged. */
.mobile #sidebar.dragging {
    transition: none;
}

.mobile .sidebar-head {
    position: static;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 0.6rem 0.6rem 1.25rem;
    padding-top: max(0.6rem, env(safe-area-inset-top));
    border-bottom: 1px solid var(--sidebar-border);
}

.mobile .sidebar-home {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 44px;
    color: var(--text-color);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
}

.mobile .sidebar-home img {
    width: 28px;
    height: 28px;
    margin: 0;
    border-radius: 50%;
}

.mobile #close-sidebar {
    width: 44px;
    height: 44px;
    font-size: 1.8rem;
}

.mobile #close-sidebar:active {
    background: color-mix(in srgb, var(--accent-color) 15%, transparent);
}

.mobile #sidebar .sidebar-content {
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
}

.mobile .drawer-toc {
    display: block;
    margin-bottom: 1.75rem;
}

.mobile .drawer-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1.35;
}

.mobile .drawer-toc ol {
    border-left: 1px solid var(--sidebar-border);
}

.mobile .drawer-toc a {
    display: block;
    margin-left: -1px;
    padding: 0.55em 0.5em 0.55em 0.85em;
    border-left: 2px solid transparent;
    color: color-mix(in srgb, var(--text-color) 72%, transparent);
    text-decoration: none;
}

.mobile .drawer-toc li.toc-l1 > a { padding-left: 1.35em; }
.mobile .drawer-toc li.toc-l2 > a { padding-left: 2em; font-size: 0.94em; }

.mobile .drawer-toc li.toc-has-sub {
    position: relative;
}
.mobile .drawer-toc li.toc-has-sub > a {
    padding-right: 2.6em;
}
.mobile .drawer-toc .toc-fold {
    top: 0.2em;
    width: 2.4em;
    height: 2.4em;
}

.mobile .drawer-toc li.in-path > a {
    color: color-mix(in srgb, var(--toc-hue) 70%, var(--text-color));
}
.mobile .drawer-toc li > a.active {
    color: var(--toc-hue);
    border-left-color: var(--toc-hue);
}

/* Post links as full-width rows: big enough to hit with a thumb. */
.mobile .latest-posts li {
    margin: 0;
    font-size: 0.95rem;
    border-bottom: 1px solid color-mix(in srgb, var(--sidebar-border) 60%, transparent);
}

.mobile .latest-posts li:last-child {
    border-bottom: none;
}

.mobile .latest-posts .date {
    padding-top: 0.6rem;
    margin: 0;
    pointer-events: none;
}

.mobile .latest-posts a {
    display: block;
    padding: 0.1rem 0 0.65rem;
}

.mobile .directory-link a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    text-decoration: none;
}

.mobile #theme-toggle {
    min-height: 48px;
    border-radius: 8px;
    margin-top: 0.75rem;
}

.mobile .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(8, 4, 14, 0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
    -webkit-tap-highlight-color: transparent;
}

.mobile .sidebar-backdrop.open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s;
}

.mobile .menu-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: calc(1rem + env(safe-area-inset-right));
    bottom: calc(1rem + env(safe-area-inset-bottom));
    z-index: 120;
    width: 56px;
    height: 56px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--accent-color);
    color: #fff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(24px) scale(0.85);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
    -webkit-tap-highlight-color: transparent;
}

.mobile .menu-fab.visible {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s;
}

.mobile .menu-fab:active {
    transform: scale(0.92);
}

.mobile .menu-fab svg {
    width: 24px;
    height: 24px;
}

/* Drawer open: the page stops scrolling. theme.js parks the offset in
   body's `top` so it doesn't jump. */
html.drawer-open,
html.drawer-open body {
    overflow: hidden;
}

html.drawer-open body {
    position: fixed;
    left: 0;
    right: 0;
}

/* Home page: the ||| list shows in the flow, as a card, so it's found
   without opening anything. */
.mobile .main-content .sidebar {
    display: block;
    margin: 3rem 0 0;
    padding: 1.25rem 1.25rem 1.5rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 12px;
}

.mobile .main-content .sidebar .directory-link {
    margin-top: 1rem;
}

/* Wide things scroll inside themselves instead of being clipped by the
   body's overflow-x: hidden. */
.mobile .main-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile .main-content mjx-container[display="true"] {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.mobile .main-content video,
.mobile .main-content iframe {
    max-width: 100%;
}

.mobile .toc summary {
    padding: 0.35rem 0;
}

.mobile .main-content .toc a {
    padding-top: 0.5em;
    padding-bottom: 0.5em;
}

.mobile .read-more-btn {
    padding: 14px 28px;
}
