/* Shared base for every page: the typefaces, theme tokens, page shell, top
   navigation, buttons and the drop-down menu.

   Two typefaces, self-hosted from static/fonts (SIL Open Font License, see the LICENSE
   files there):
     --font-serif  Spectral: the archive name (600), page titles and reading text (400)
     --font-ui     Work Sans: navigation (500), controls, labels and metadata
   plus --font-mono (the system monospace) for small kicker labels above page titles.
   Use the variables; don't name a font family anywhere else. */

@font-face { font-family: 'Spectral'; font-style: normal; font-weight: 400; font-display: swap;
    src: url('fonts/spectral-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Spectral'; font-style: normal; font-weight: 400; font-display: swap;
    src: url('fonts/spectral-latin-ext-400-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Spectral'; font-style: italic; font-weight: 400; font-display: swap;
    src: url('fonts/spectral-latin-400-italic.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Spectral'; font-style: italic; font-weight: 400; font-display: swap;
    src: url('fonts/spectral-latin-ext-400-italic.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Spectral'; font-style: normal; font-weight: 600; font-display: swap;
    src: url('fonts/spectral-latin-600-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Spectral'; font-style: normal; font-weight: 600; font-display: swap;
    src: url('fonts/spectral-latin-ext-600-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Spectral'; font-style: italic; font-weight: 600; font-display: swap;
    src: url('fonts/spectral-latin-600-italic.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Spectral'; font-style: italic; font-weight: 600; font-display: swap;
    src: url('fonts/spectral-latin-ext-600-italic.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Work Sans'; font-style: normal; font-weight: 100 900; font-display: swap;
    src: url('fonts/work-sans-latin-wght-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Work Sans'; font-style: normal; font-weight: 100 900; font-display: swap;
    src: url('fonts/work-sans-latin-ext-wght-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'Work Sans'; font-style: italic; font-weight: 100 900; font-display: swap;
    src: url('fonts/work-sans-latin-wght-italic.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

/* --- Colour palettes ---
   Charcoal is the default and Sepia the alternate, chosen with the palette button in
   the top nav (static/theme.js stores the choice; _nav.html applies it before the page
   draws by setting data-theme='charcoal' unless the reader chose Sepia). The variables
   below hold Sepia; :root[data-theme='charcoal'] overrides them. Every colour on the site should come from these variables; to tint, use
   color-mix(in srgb, var(--accent-blue) 15%, transparent) rather than a fixed rgba(). */
:root {
    color-scheme: dark;
    --bg-primary: #2a241f;           /* page */
    --bg-secondary: #302a24;         /* panels, cards, menus */
    --bg-tertiary: #373029;          /* panel bars, buttons, hover */
    --bg-nav: #24201d;               /* top navigation */
    --bg-inset: #211c18;             /* inputs and wells, darker than the page */
    --scan-mat: #51483d;             /* behind a scanned page (never tint the scan itself) */
    --border: #5b4e42;
    --border-soft: #3c342c;          /* row dividers */
    --border-strong: #7a6a58;        /* hovered borders */
    --text-primary: #f2e7d0;
    --text-reading: #e9dcc3;         /* long passages: answers, transcriptions in cards */
    --text-secondary: #c2b29b;
    --text-muted: #a8977f;           /* placeholders, unavailable links; still 4.5:1 */
    --accent-blue: #efb873;          /* amber accent (name kept from the old palette) */
    --accent-bright: #f7d3a0;        /* accent hover, highlighted terms */
    --accent-soft: #5a4230;          /* cited-text fill */
    --on-accent: #2a1d10;            /* text on an accent fill */
    --nav-active-rule: #a1c6b8;      /* dusty teal under the current tab */
    --accent-red: #f85149;
    --font-serif: 'Spectral', Georgia, serif;
    --font-ui: 'Work Sans', -apple-system, 'Segoe UI', sans-serif;
    --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    --reading-font: var(--font-serif);   /* older name, same serif */
}
:root[data-theme='charcoal'] {
    --bg-primary: #141516;
    --bg-secondary: #1d1f20;
    --bg-tertiary: #222425;
    --bg-nav: #141516;
    --bg-inset: #0e0f10;
    --scan-mat: #282a2b;
    --border: #383a39;
    --border-soft: #26282a;
    --border-strong: #55575a;
    --text-primary: #eeeae1;
    --text-reading: #e3dfd6;
    --text-secondary: #b6b5ad;
    --text-muted: #8f8e87;
    --accent-blue: #e0bb65;
    --accent-bright: #ecce86;
    --accent-soft: #453c27;
    --on-accent: #141516;
    --nav-active-rule: #e0bb65;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-ui);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

a { color: var(--accent-blue); }
h1, h2 { font-family: var(--font-serif); font-weight: 600; letter-spacing: -0.005em; }
h1 { font-weight: 400; letter-spacing: -0.02em; }   /* page titles: Spectral Regular */

/* --- Page header: a kicker with a short rule, the title, then a dotted meta line ---
   <div class="kicker"><span class="rule"></span>Letter</div> <h1>…</h1>
   <div class="meta-line"><span>…</span><i></i><span>…</span></div> */
.kicker {
    display: flex; align-items: center; gap: 11px;
    font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--nav-active-rule);
}
.kicker .rule { width: 24px; height: 1px; background: currentColor; flex-shrink: 0; }
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; color: var(--text-secondary); font-size: 15px; }
.meta-line i { width: 3px; height: 3px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.meta-line .who { color: var(--text-primary); }
button, input, select, textarea { font-family: inherit; }
code, kbd, pre { font-family: inherit; }

/* --- Top nav (markup in templates/_nav.html) --- */
.topnav {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: 52px;
    gap: 14px;
    background: var(--bg-nav);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topnav .brand {
    display: inline-flex; align-items: center; gap: 9px; margin-right: 10px;
    font-family: var(--font-serif); font-weight: 600; font-size: 18px; white-space: nowrap;
    color: var(--text-primary); text-decoration: none;
}
.topnav .brand svg { width: 26px; height: 26px; flex-shrink: 0; color: var(--accent-blue); }
.topnav .brand:hover { color: var(--accent-blue); }
.topnav .tabs { display: flex; gap: 4px; }
.topnav .tab {
    position: relative; padding: 7px 14px; border-radius: 10px; text-decoration: none;
    font-size: 15px; font-weight: 500; color: var(--text-secondary); white-space: nowrap;
}
.topnav .tab:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.topnav .tab.active { color: var(--text-primary); }
.topnav .tab.active::after {     /* a rule under the current tab, not a filled pill */
    content: ''; position: absolute; left: 14px; right: 14px; bottom: 0; height: 2px;
    border-radius: 1px; background: var(--nav-active-rule);
}
.topnav .saved-link.active { color: var(--accent-blue); }
.topnav .spacer { flex: 1; }
.topnav .saved-link { display: inline-flex; align-items: center; gap: 6px; }
.topnav .saved-link svg { width: 15px; height: 15px; }
.topnav .logout {
    font-size: 13.5px; color: var(--text-secondary); text-decoration: none; white-space: nowrap;
    padding: 5px 12px; border: 1px solid var(--border); border-radius: 10px;
}
.topnav .logout:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.topnav .theme-toggle {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 32px; height: 30px; padding: 0; cursor: pointer;
    background: none; color: var(--text-secondary); border: 1px solid var(--border); border-radius: 10px;
}
.topnav .theme-toggle:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.topnav .theme-toggle svg { width: 16px; height: 16px; }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 8px; font: inherit; font-size: 14px;
    border: 1px solid var(--border); background: var(--bg-tertiary);
    color: var(--text-primary); text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent-blue); color: var(--accent-blue); }
.btn.primary { background: var(--accent-blue); border-color: var(--accent-blue); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { opacity: 0.9; color: var(--on-accent); }
.btn[disabled], .btn.disabled { opacity: 0.4; pointer-events: none; }

.ai-badge {
    display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
    text-transform: uppercase; color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
}

/* --- Drop-down menu: <details class="menu"><summary class="btn">…</summary><div class="menu-list">…
   static/menu.js closes it on an outside click or Esc. --- */
.menu { position: relative; display: inline-block; }
.menu > summary { list-style: none; user-select: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after {
    content: ''; width: 6px; height: 6px; margin-left: 4px; margin-top: -3px;
    border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg);
}
.menu[open] > summary::after { transform: rotate(-135deg); margin-top: 3px; }
.menu-list {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 220px;
    background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 10px;
    padding: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}
.menu-list.left { right: auto; left: 0; }
.menu-list a, .menu-list button {
    display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 7px;
    background: none; border: none; font: inherit; font-size: 14.5px; cursor: pointer;
    color: var(--text-primary); text-decoration: none;
}
.menu-list a:hover, .menu-list button:hover { background: var(--bg-tertiary); color: var(--accent-blue); }
.menu-list small { display: block; color: var(--text-secondary); font-size: 12.5px; }
