/* ============================================================
   TOS Resources — Shared Site Stylesheet
   Institutional monochrome redesign (April 2026)

   Single palette — no dark mode. Warm off-white paper, charcoal
   text, hairline gray borders. Times New Roman for all serif
   content, Arial for UI chrome only.

   Loaded after each page's inline <style> block so these rules
   win the cascade on shared components. Page-specific rules
   stay inline and keep working as-is.
   ============================================================ */

:root {
    color-scheme: light;

    /* Surfaces — pure white paper */
    --color-bg: #ffffff;
    --color-surface: #ffffff;
    --color-surface-alt: #f2efe6;
    --color-surface-sunken: #e8e4d9;

    /* Text — all body copy is black. Only truly tertiary
       metadata (timestamps, tiny labels) uses the subtle gray. */
    --color-text: #1a1a1a;
    --color-text-muted: #1a1a1a;
    --color-text-subtle: #5a5a5a;

    /* Borders — soft hairlines */
    --color-border: #c9c4b6;
    --color-border-strong: #8a8578;
    --color-rule: #d9d4c5;

    /* Accent — charcoal, not a color. Plain document feel. */
    --color-accent: #1a1a1a;
    --color-accent-hover: #4a4a4a;
    --color-accent-tint: #ece8dd;
    --color-accent-on: #ffffff;

    /* Header / top chrome — charcoal masthead */
    --color-header-bg: #1a1a1a;
    --color-header-text: #f5f2ea;
    --color-header-hover: rgba(255, 255, 255, 0.08);

    /* Typography — Times New Roman, universally. No exceptions. */
    --font-serif: "Times New Roman", Times, Georgia, serif;
    --font-sans: "Times New Roman", Times, Georgia, serif;
    --font-mono: "Times New Roman", Times, Georgia, serif;

    /* Touch targets — WCAG 2.5.5 minimum */
    --touch-min: 44px;

    /* Radii — flat, disciplined */
    --radius-sm: 2px;
    --radius-md: 3px;

    /* Elevation — flat by default */
    --shadow-none: none;
    --shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* --------------------------------------------------------
   Neutralize any dark-mode rules left in inline CSS.
   The OS may still prefer dark; we explicitly stay light.
   -------------------------------------------------------- */
html {
    color-scheme: light;
    background: var(--color-bg);
}

/* Universal font: Times New Roman for EVERY element, including
   form controls and UI chrome. This overrides browser defaults
   on <button>, <input>, etc. that otherwise pick up the OS font. */
*, *::before, *::after {
    font-family: "Times New Roman", Times, Georgia, serif;
}

/* --------------------------------------------------------
   Base typography
   -------------------------------------------------------- */
body {
    font-family: var(--font-serif);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 17px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-serif);
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: normal;
}

p {
    color: var(--color-text);
}

hr {
    border: 0;
    border-top: 1px solid var(--color-rule);
    margin: 32px 0;
}

/* --------------------------------------------------------
   Content links — underlined, monochrome. Classic document.
   -------------------------------------------------------- */
a {
    color: var(--color-accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
a:hover {
    color: var(--color-accent-hover);
    text-decoration: underline;
}

/* UI chrome — nav, buttons, cards. No underlines here. */
.page-nav a,
.header-bar a,
.button,
a.button,
.btn,
.btn-primary,
.btn-secondary,
.download-btn,
.download-btn.primary,
.download-btn.secondary,
.card a.button,
nav a,
.tab,
a.tab,
.chip,
a.chip,
.topic-chip,
a.topic-chip,
.filter-chip,
a.filter-chip {
    text-decoration: none;
}

/* --------------------------------------------------------
   UI chrome font — restrained sans for functional surfaces
   -------------------------------------------------------- */
.header-bar,
.header-bar span,
.page-nav,
.page-nav a,
button,
.button,
input,
select,
textarea,
.badge,
.source-badge,
.meta,
.metadata,
.reading-time,
.filter-chip,
.topic-chip,
.sort-btn,
.chip,
.pill,
.tag,
.label,
.stats,
.stat {
    font-family: var(--font-sans);
}

code, kbd, samp, pre {
    font-family: var(--font-mono);
}

/* --------------------------------------------------------
   Header + primary nav — charcoal masthead
   -------------------------------------------------------- */
.header-bar {
    background: var(--color-header-bg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.header-bar span {
    color: var(--color-header-text);
    letter-spacing: 0.1em;
    font-weight: 500;
}

.page-nav {
    background: var(--color-header-bg);
    border-top: 1px solid var(--color-header-hover);
}
.page-nav a {
    color: var(--color-header-text);
    font-weight: 500;
    letter-spacing: 0.09em;
    padding: 12px 16px;
    font-size: 0.72rem;
}
.page-nav a:hover {
    background: var(--color-header-hover);
    color: #ffffff;
}
.page-nav a.active {
    background: var(--color-header-hover);
    color: #ffffff;
}

/* --------------------------------------------------------
   Hero / page intros
   -------------------------------------------------------- */
.hero h1 {
    color: var(--color-text);
    font-family: var(--font-serif);
    font-weight: 700;
    letter-spacing: normal;
}
.hero p {
    color: var(--color-text-muted);
}

/* --------------------------------------------------------
   Cards — flat, hairline borders, no accent bar
   -------------------------------------------------------- */
.card,
.literature-callout a,
.resource-card,
.topic-card,
.related-card,
.decision-card,
.start-card,
.download-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left-width: 1px;
    border-left-color: var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-none);
    color: var(--color-text);
}

.card:hover,
.literature-callout a:hover,
.resource-card:hover,
.topic-card:hover,
.related-card:hover,
.decision-card:hover,
.start-card:hover,
.download-card:hover {
    border-color: var(--color-border-strong);
    border-left-color: var(--color-border-strong);
    box-shadow: var(--shadow-subtle);
}

.card h2,
.card h3,
.card h4 {
    color: var(--color-text);
}

.literature-callout .callout-text strong {
    color: var(--color-text);
}
.literature-callout .callout-text span {
    color: var(--color-text-muted);
}

/* --------------------------------------------------------
   Buttons — functional, charcoal, no gloss
   -------------------------------------------------------- */
.btn,
button.primary,
.button.primary,
a.button.primary,
.download-btn.primary,
.btn-primary {
    background: var(--color-accent);
    color: var(--color-accent-on);
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-weight: 500;
    letter-spacing: 0.02em;
    box-shadow: var(--shadow-none);
    transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:hover,
button.primary:hover,
.button.primary:hover,
a.button.primary:hover,
.download-btn.primary:hover,
.btn-primary:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    box-shadow: var(--shadow-none);
}

.btn-secondary,
.button.secondary,
a.button.secondary,
.download-btn.secondary {
    background: transparent;
    color: var(--color-accent);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-weight: 500;
}
.btn-secondary:hover,
.button.secondary:hover,
a.button.secondary:hover,
.download-btn.secondary:hover {
    border-color: var(--color-accent);
    color: var(--color-text);
    background: var(--color-accent-tint);
}

/* --------------------------------------------------------
   Rules, separators, callouts
   -------------------------------------------------------- */
.section-divider,
.rule {
    border-top: 1px solid var(--color-rule);
}

.callout,
.info-box,
.note {
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: var(--radius-sm);
    color: var(--color-text);
}

/* --------------------------------------------------------
   Focus — visible on paper
   -------------------------------------------------------- */
:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ============================================================
   Mobile drawer + hamburger (Phase 1 of the mobile overhaul)

   Below 900px the horizontal .page-nav is hidden and a
   hamburger button in the top-right of .header-bar opens a
   right-side drawer containing primary nav + "On this page"
   section anchors. At >=900px the existing horizontal nav
   remains unchanged and the hamburger is hidden.
   ============================================================ */

/* Make .header-bar a positioning context for the hamburger. */
.header-bar {
    position: relative;
}

.nav-toggle {
    position: absolute;
    top: 50%;
    left: 16px;
    right: auto;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-sm);
    color: var(--color-header-text);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.nav-toggle:hover {
    background: var(--color-header-hover);
    border-color: rgba(255, 255, 255, 0.35);
}
.nav-toggle svg {
    width: 22px;
    height: 22px;
    display: block;
}

/* Backdrop behind the drawer. */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
    z-index: 200;
}

/* The drawer itself — full-screen sheet, slides in from the left. */
.drawer {
    position: fixed;
    top: 0;
    left: 0;
    right: auto;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    background: var(--color-bg);
    border-left: none;
    border-right: 1px solid var(--color-border);
    box-shadow: none;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 201;
    display: flex;
    flex-direction: column;
    overscroll-behavior: contain;
    overflow-y: auto;
}

/* Open state — toggled by JS via body.drawer-open. */
body.drawer-open {
    overflow: hidden;
}
body.drawer-open .drawer-backdrop {
    opacity: 1;
    visibility: visible;
}
body.drawer-open .drawer {
    transform: translateX(0);
}

/* Drawer header — site title + close button. */
.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--color-header-bg);
    color: var(--color-header-text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.drawer-title {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-header-text);
}
.drawer-close {
    width: auto;
    height: 44px;
    padding: 0 16px 0 12px;
    gap: 8px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-sm);
    color: var(--color-header-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.drawer-close:hover {
    background: var(--color-header-hover);
    border-color: rgba(255, 255, 255, 0.35);
}
.drawer-close svg {
    width: 18px;
    height: 18px;
    display: block;
    flex-shrink: 0;
}
.drawer-close::after {
    content: "Close Menu";
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Navigation list inside the drawer. */
.drawer nav {
    padding: 8px 0;
}
.drawer-section-label {
    display: block;
    padding: 18px 20px 8px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-text-subtle);
}
.drawer a {
    display: block;
    padding: 14px 20px;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-text);
    text-decoration: none;
    border-left: 3px solid transparent;
    min-height: 48px;
    box-sizing: border-box;
}
.drawer a:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
    text-decoration: none;
}
.drawer a.active {
    border-left-color: var(--color-accent);
    background: var(--color-surface-alt);
    font-weight: 600;
}
.drawer-divider {
    height: 1px;
    background: var(--color-rule);
    margin: 8px 20px;
    border: 0;
}
.drawer-onpage a {
    font-size: 0.9rem;
    font-weight: 400;
    padding-left: 32px;
    color: var(--color-text-muted);
}
.drawer-onpage:empty,
.drawer-onpage-label:has(+ .drawer-onpage:empty) {
    display: none;
}
.drawer-footer {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid var(--color-rule);
    background: var(--color-surface-alt);
}
.drawer-footer a {
    padding: 8px 0;
    font-size: 0.85rem;
    min-height: 0;
    border-left: 0;
}

/* Breakpoint: mobile default, desktop at >= 900px.
   Hamburger visible below 900px; horizontal nav visible at >= 900px. */
.nav-toggle {
    display: inline-flex;
}
.page-nav {
    display: none;
}

/* Mobile header: flex layout so the left-side hamburger doesn't
   overlap the centered title. Nav-toggle goes first (order -1),
   the title span gets padding-right to keep text visually centered. */
@media (max-width: 899px) {
    .header-bar {
        display: flex;
        align-items: center;
    }
    .header-bar > span {
        flex: 1;
        text-align: center;
        padding-right: 56px;
    }
    .nav-toggle {
        position: static;
        transform: none;
        order: -1;
        flex-shrink: 0;
    }
}

@media (min-width: 900px) {
    .nav-toggle {
        display: none;
    }
    .page-nav {
        display: flex;
    }
    .drawer,
    .drawer-backdrop {
        display: none;
    }
}

/* Respect reduced-motion: no slide animations. */
@media (prefers-reduced-motion: reduce) {
    .drawer,
    .drawer-backdrop {
        transition: none;
    }
}

/* ============================================================
   Phase 3 — data-mobile-only details auto-expand on desktop

   On mobile the element acts as a normal collapsible <details>.
   On desktop (≥900px): display:contents makes the wrapper
   transparent so badge items (or other content) always show;
   the summary toggle is hidden. JS in site.js also sets
   open=true on desktop as a belt-and-suspenders guarantee.
   ============================================================ */
@media (min-width: 900px) {
    .badge-legend details[data-mobile-only] {
        display: contents;
    }
    .badge-legend details[data-mobile-only] > summary {
        display: none;
    }
}

/* ============================================================
   Phase 3 — Filter bottom sheet (literature page, mobile only)
   ============================================================ */

.filter-toggle {
    display: none; /* shown on mobile via @media below */
}

.filter-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
    z-index: 148;
}

body.filter-open .filter-sheet-backdrop {
    opacity: 1;
    visibility: visible;
}

/* Filter panel: inline block on desktop, bottom sheet on mobile */
#filter-panel {
    /* desktop: transparent wrapper — children display at their
       normal positions in the page flow */
}

@media (max-width: 899px) {
    .filter-toggle {
        display: flex;
        align-items: center;
        gap: 8px;
        margin: 0 20px 12px;
        padding: 0 20px;
        min-height: 44px;
        width: calc(100% - 40px);
        box-sizing: border-box;
        background: #ffffff;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-sm);
        font-size: 0.88rem;
        font-weight: 600;
        color: var(--color-text);
        cursor: pointer;
        letter-spacing: 0.02em;
        transition: border-color 0.15s;
    }
    .filter-toggle:hover {
        border-color: var(--color-border-strong);
    }
    .filter-toggle svg {
        flex-shrink: 0;
    }
    .filter-count {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        border-radius: 10px;
        background: var(--color-accent);
        color: #fff;
        font-size: 0.8rem;
        font-weight: 700;
        margin-left: 4px;
    }
    .filter-count:empty {
        display: none;
    }
    #filter-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-bg);
        border-top: 1px solid var(--color-border);
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
        transform: translateY(100%);
        transition: transform 0.25s ease;
        z-index: 149;
        max-height: 72vh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    body.filter-open #filter-panel {
        transform: translateY(0);
    }
    .filter-panel-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        background: var(--color-header-bg);
        color: var(--color-header-text);
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        position: sticky;
        top: 0;
        z-index: 1;
    }
    .filter-panel-title {
        font-size: 0.78rem;
        font-weight: 500;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        color: var(--color-header-text);
    }
    .filter-panel-close {
        width: 40px;
        height: 40px;
        padding: 0;
        background: transparent;
        border: 1px solid rgba(255, 255, 255, 0.18);
        border-radius: var(--radius-sm);
        color: var(--color-header-text);
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
        transition: background 0.15s;
    }
    .filter-panel-close:hover {
        background: var(--color-header-hover);
    }
    /* Inside-panel layout adjustments */
    #filter-panel .topic-filter,
    #filter-panel .controls-bar,
    #filter-panel .advanced-search {
        max-width: none;
        width: 100%;
    }
    #filter-panel .topic-filter {
        padding: 16px 20px;
    }
    #filter-panel .topic-filter-label {
        margin-bottom: 12px;
    }
    #filter-panel .controls-bar {
        padding: 0 20px 16px;
    }
    #filter-panel .advanced-search {
        padding: 0 20px 16px;
        margin-top: 0;
    }
}

@media (min-width: 900px) {
    .filter-panel-header {
        display: none;
    }
    .filter-sheet-backdrop {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #filter-panel,
    .filter-sheet-backdrop {
        transition: none;
    }
}

/* ============================================================
   Phase 4 — Dense-page section collapsing (mobile only)

   .entry-collapse  — wraps a single h3 + its content.
                      summary styled to match .topic-content h3.
   .section-collapse — wraps an entire section body (h2 becomes
                       summary). Styled to match .topic-content h2.

   Both carry data-mobile-only; syncOpen() in site.js opens them
   at ≥900px. Desktop: summary non-interactive, content visible.
   ============================================================ */

.entry-collapse > summary {
    list-style: none;
    cursor: pointer;
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.4;
    margin: 28px 0 10px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    user-select: none;
    -webkit-user-select: none;
}
.entry-collapse > summary::-webkit-details-marker { display: none; }
.entry-collapse > summary::after {
    content: "▾";
    font-size: 0.85rem;
    font-family: var(--font-sans);
    color: var(--color-text-subtle);
    transition: transform 0.2s;
    flex-shrink: 0;
    margin-left: 10px;
    font-weight: normal;
}
.entry-collapse[open] > summary::after { transform: rotate(-180deg); }

.section-collapse > summary {
    list-style: none;
    cursor: pointer;
    font-family: var(--font-serif);
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.25;
    margin-bottom: 14px;
    letter-spacing: -0.01em;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    user-select: none;
    -webkit-user-select: none;
}
.section-collapse > summary::-webkit-details-marker { display: none; }
.section-collapse > summary::after {
    content: "▾";
    font-size: 1rem;
    color: var(--color-text-subtle);
    transition: transform 0.2s;
    flex-shrink: 0;
    margin-left: 12px;
    font-weight: normal;
    letter-spacing: normal;
}
.section-collapse[open] > summary::after { transform: rotate(-180deg); }

@media (min-width: 900px) {
    .entry-collapse > summary,
    .section-collapse > summary {
        cursor: default;
        pointer-events: none;
    }
    .entry-collapse > summary::after,
    .section-collapse > summary::after {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .entry-collapse > summary::after,
    .section-collapse > summary::after {
        transition: none;
    }
}

/* ============================================================
   Phase 5 — Typography + polish pass on mobile

   - Badge font floor raised to 0.8rem on mobile (inline pages
     define 0.68rem; this override wins at equal specificity
     because site.css loads after the inline <style> block)
   ============================================================ */

@media (max-width: 899px) {
    .badge {
        font-size: 0.8rem;
    }
}

/* ============================================================
   Reading progress bar — thin line at viewport top showing
   scroll position on long content pages.
   ============================================================ */

.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    background: #2563eb;
    z-index: 9999;
    pointer-events: none;
    height: 3px;
    width: var(--progress, 0%);
}

@media (max-width: 899px) {
    .reading-progress {
        display: none;
    }
}

.progress-ring {
    position: absolute;
    top: -4px;
    left: -4px;
    pointer-events: none;
    transform: rotate(-90deg);
}

.progress-ring__circle {
    transition: stroke-dashoffset 0.15s ease;
    stroke: #2563eb;
    fill: none;
}

@media (min-width: 900px) {
    .progress-ring {
        display: none;
    }
}

/* ============================================================
   Screen-reader-only utility
   ============================================================ */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   ZIP download button — preparing state
   ============================================================ */

.download-all-btn.zip-preparing {
    opacity: 0.7;
    animation: zip-pulse 1.4s ease-in-out infinite;
}

@keyframes zip-pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}
