/* =========================================================================
   BIBLIOTHECA — multi-tenant reader's-wiki platform
   Design system: "Abyssal" (dark) + "Tide" (light)
   Adapted from the Metazoa reference. Per-book accent is injected at runtime
   into --accent / --accent-2 on :root.
   ========================================================================= */

/* ----------------------------- Design tokens ----------------------------- */
:root {
  --font-reading: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --step--1: clamp(0.83rem, 0.80rem + 0.15vw, 0.92rem);
  --step-0:  clamp(1.00rem, 0.96rem + 0.20vw, 1.12rem);
  --step-1:  clamp(1.20rem, 1.12rem + 0.40vw, 1.45rem);
  --step-2:  clamp(1.45rem, 1.32rem + 0.66vw, 1.90rem);
  --step-3:  clamp(1.80rem, 1.55rem + 1.20vw, 2.65rem);
  --step-4:  clamp(2.20rem, 1.75rem + 2.20vw, 3.80rem);

  --reading-measure: 70ch;

  --sidebar-w: 19rem;
  --toc-w: 16rem;
  --topbar-h: 3.75rem;
  --radius: 14px;
  --radius-sm: 9px;
  --gap: clamp(1rem, 2vw, 2rem);

  /* Category accent hues (shared) */
  --cat-core-concept: #6ee7d7;
  --cat-mechanism:    #7cc4ff;
  --cat-evolution:    #c4a6ff;
  --cat-organism:     #6ee79a;
  --cat-person:       #ffce6e;
  --cat-place:        #ff9bb0;
  --cat-theme:        #9ad0ff;
  --cat-default:      #9fb3c4;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  /* per-book accent — overridden at runtime; sensible defaults */
  --accent:    #46e0c4;
  --accent-2:  #5bb8ff;
}

/* --------------------------------- DARK ----------------------------------- */
:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg:        #070d14;
  --bg-deep:   #04080d;
  --surface:   #0d1722;
  --surface-2: #122031;
  --surface-3: #18293b;
  --border:    #1e3346;
  --border-strong: #2c4a64;
  --ink:       #dfeaf2;
  --ink-soft:  #a9bccb;
  --ink-mute:  #6f8497;
  --accent-ink:#04201b;
  --glow:      0 0 0 1px color-mix(in oklab, var(--accent) 18%, transparent), 0 8px 40px -12px color-mix(in oklab, var(--accent) 30%, transparent);
  --shadow:    0 18px 50px -20px rgba(0,0,0,.75);
  --shadow-sm: 0 6px 20px -10px rgba(0,0,0,.6);
  --mark:      color-mix(in oklab, var(--accent) 26%, transparent);
  --mark-edge: color-mix(in oklab, var(--accent) 55%, transparent);
  --note-bg:   #1a2c1f;
  --selection: color-mix(in oklab, var(--accent-2) 30%, transparent);
  --abyss: radial-gradient(120% 90% at 50% -10%, #0d2030 0%, #070d14 45%, #04080d 100%);
  --good: #6ee79a; --warn: #ffce6e; --bad: #ff8a8a; --info: #7cc4ff;
}

/* --------------------------------- LIGHT ---------------------------------- */
[data-theme="light"] {
  color-scheme: light;
  --bg:        #f4f1e9;
  --bg-deep:   #ece7da;
  --surface:   #fffdf8;
  --surface-2: #faf7ef;
  --surface-3: #f1ece0;
  --border:    #e2dccd;
  --border-strong: #cabfa6;
  --ink:       #21303a;
  --ink-soft:  #455563;
  --ink-mute:  #76808a;
  --accent-ink:#ffffff;
  --glow:      0 0 0 1px color-mix(in oklab, var(--accent) 16%, transparent), 0 10px 36px -14px color-mix(in oklab, var(--accent) 34%, transparent);
  --shadow:    0 22px 50px -28px rgba(43,58,71,.40);
  --shadow-sm: 0 8px 22px -14px rgba(43,58,71,.30);
  --mark:      color-mix(in oklab, var(--accent) 30%, #f5cd5a 30%);
  --mark-edge: color-mix(in oklab, var(--accent) 60%, #d69e19);
  --note-bg:   #fff4d6;
  --selection: color-mix(in oklab, var(--accent-2) 20%, transparent);
  --abyss: radial-gradient(120% 90% at 50% -10%, #fffdf8 0%, #f4f1e9 55%, #ece7da 100%);
  --good: #1f8f4d; --warn: #b07b14; --bad: #c0392b; --info: #1f6fb2;

  --cat-core-concept: #0c8c7e;
  --cat-mechanism:    #1f6fb2;
  --cat-evolution:    #6b46c1;
  --cat-organism:     #1f8f4d;
  --cat-person:       #b07b14;
  --cat-place:        #c14b67;
  --cat-theme:        #2563a8;
  --cat-default:      #5a6b78;
}

/* ------------------------------- Base ------------------------------------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 1rem); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  background-image: var(--abyss);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
::selection { background: var(--selection); }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img { max-width: 100%; height: auto; display: block; }
h1,h2,h3,h4 { font-family: var(--font-ui); line-height: 1.18; font-weight: 650; letter-spacing: -.01em; }
hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
code, kbd { font-family: var(--font-mono); font-size: .9em; }
kbd {
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 6px; padding: .08em .42em; font-size: .8em; color: var(--ink-soft);
}
button { font-family: inherit; }
input, textarea, select { font-family: var(--font-ui); }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--ink-mute); font-size: .95rem; letter-spacing: .04em; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 20px; border: 2px solid transparent; background-clip: content-box; }

/* ------------------------------ Reading progress -------------------------- */
#progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  z-index: 60; transition: width .15s linear; box-shadow: 0 0 12px var(--accent);
}

/* --------------------------------- Topbar --------------------------------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 50;
  display: flex; align-items: center; gap: .75rem; padding: 0 clamp(.8rem, 2vw, 1.4rem);
  background: color-mix(in oklab, var(--bg) 78%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: .82rem; color: var(--ink); }
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .mark { width: 26px; height: 26px; flex: none; color: var(--accent); }
.topbar .brand small { color: var(--ink-mute); font-weight: 600; letter-spacing: .04em; text-transform: none; display: block; }
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  background: transparent; border: 1px solid transparent; color: var(--ink-soft); cursor: pointer;
  transition: background .2s, color .2s, border-color .2s; position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
.icon-btn svg { width: 20px; height: 20px; }
[data-theme="dark"] #theme-btn .t-light, [data-theme="light"] #theme-btn .t-dark { display: none; }
#theme-btn { overflow: hidden; }
.count-badge {
  position: absolute; top: 2px; right: 2px; background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; font-size: .6rem; min-width: 15px; height: 15px; display: grid; place-items: center;
  padding: 0 3px; font-weight: 700;
}

.search-trigger {
  display: flex; align-items: center; gap: .6rem; height: 40px; padding: 0 .8rem; min-width: 13rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--ink-mute);
  cursor: pointer; font-family: var(--font-ui); font-size: .9rem; transition: border-color .2s, box-shadow .2s;
}
.search-trigger:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.search-trigger svg { width: 17px; height: 17px; }
.search-trigger .kbds { margin-left: auto; display: flex; gap: .2rem; }
@media (max-width: 680px){ .search-trigger { min-width: 0; } .search-trigger .label, .search-trigger .kbds { display: none; } }

/* account menu */
.acct { position: relative; }
.acct-btn {
  display: inline-flex; align-items: center; gap: .5rem; height: 40px; padding: 0 .55rem; border-radius: 10px;
  background: transparent; border: 1px solid transparent; color: var(--ink-soft); cursor: pointer; font-size: .9rem;
  transition: background .2s, border-color .2s, color .2s;
}
.acct-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); font-weight: 700; font-size: .8rem;
}
.acct-name { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 680px){ .acct-name { display: none; } }
.menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 14rem; z-index: 70;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow);
  padding: .4rem; display: none; flex-direction: column; gap: 1px;
}
.menu.open { display: flex; }
.menu .m-head { padding: .6rem .7rem .5rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.menu .m-head .nm { font-weight: 650; color: var(--ink); }
.menu .m-head .em { font-size: .78rem; color: var(--ink-mute); overflow: hidden; text-overflow: ellipsis; }
.menu .m-head .lvl { font-size: .7rem; color: var(--accent); letter-spacing: .06em; text-transform: uppercase; margin-top: .2rem; }
.menu a, .menu button {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 8px; text-align: left; width: 100%;
  background: none; border: none; color: var(--ink-soft); font-size: .9rem; cursor: pointer; text-decoration: none;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.menu a svg, .menu button svg { width: 17px; height: 17px; flex: none; }
.menu .sep { height: 1px; background: var(--border); margin: .3rem 0; }

/* --------------------------------- Layout --------------------------------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0,1fr); min-height: 100vh; }
@media (max-width: 1040px){ .shell { grid-template-columns: 1fr; } }

/* Sidebar */
.sidebar {
  position: sticky; top: var(--topbar-h); align-self: start;
  height: calc(100vh - var(--topbar-h)); overflow-y: auto; overscroll-behavior: contain;
  padding: 1.2rem .8rem 4rem; border-right: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 55%, transparent);
}
.sidebar .side-book { display: flex; gap: .7rem; align-items: center; padding: .3rem .65rem 1rem; margin-bottom: .6rem; border-bottom: 1px solid var(--border); }
.sidebar .side-book img { width: 38px; height: 54px; object-fit: cover; border-radius: 5px; box-shadow: var(--shadow-sm); flex: none; }
.sidebar .side-book .t { font-weight: 650; font-size: .92rem; line-height: 1.25; color: var(--ink); }
.sidebar .side-book .a { font-size: .78rem; color: var(--ink-mute); }
.sidebar .nav-group { margin-bottom: .35rem; }
.sidebar .nav-group > .group-head {
  display: flex; align-items: center; gap: .5rem; width: 100%; cursor: pointer;
  padding: .5rem .65rem; border: none; background: none; color: var(--ink-mute);
  font-family: var(--font-ui); font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  border-radius: 8px;
}
.sidebar .nav-group > .group-head:hover { color: var(--ink); background: var(--surface-2); }
.sidebar .nav-group > .group-head .chev { margin-left: auto; transition: transform .2s var(--ease); width: 14px; height: 14px; }
.sidebar .nav-group[data-collapsed="true"] > .group-head .chev { transform: rotate(-90deg); }
.sidebar .nav-group[data-collapsed="true"] > .group-items { display: none; }
.sidebar .group-items { display: flex; flex-direction: column; gap: 1px; padding-bottom: .4rem; }
.sidebar a.nav-link {
  display: flex; align-items: center; gap: .55rem; padding: .42rem .7rem; border-radius: 8px;
  color: var(--ink-soft); font-size: .9rem; line-height: 1.3; text-decoration: none; transition: background .15s, color .15s;
}
.sidebar a.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sidebar a.nav-link .num { flex: none; font-variant-numeric: tabular-nums; font-size: .76rem; color: var(--ink-mute); min-width: 1.3em; }
.sidebar a.nav-link.active { background: color-mix(in oklab, var(--accent) 16%, transparent); color: var(--ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
.sidebar a.nav-link.active .num { color: var(--accent); }
.sidebar .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

/* Mobile sidebar */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 44; opacity: 0; pointer-events: none; transition: opacity .25s; }
@media (max-width: 1040px){
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 45; width: min(86vw, 22rem);
    transform: translateX(-105%); transition: transform .28s var(--ease); background: var(--surface);
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
}
@media (min-width: 1041px){ #menu-btn { display: none; } }

/* Main + content column */
.main { padding-top: var(--topbar-h); min-width: 0; }
.content-wrap { display: grid; grid-template-columns: minmax(0,1fr) var(--toc-w); gap: clamp(1.5rem, 4vw, 4rem); max-width: 78rem; margin: 0 auto; padding: clamp(1.4rem, 3vw, 3rem) clamp(1.1rem, 3vw, 3rem) 6rem; }
.content-wrap.solo { grid-template-columns: minmax(0,1fr); }
@media (max-width: 1280px){ .content-wrap { grid-template-columns: minmax(0,1fr); } .toc-rail { display: none; } }
article.doc { min-width: 0; }

/* full-width page (library, admin, auth) — no sidebar */
.page { padding-top: var(--topbar-h); min-height: 100vh; }
.container { max-width: 80rem; margin: 0 auto; padding: clamp(1.4rem, 3vw, 2.6rem) clamp(1.1rem, 3vw, 2.4rem) 6rem; }
.container.narrow { max-width: 52rem; }

/* TOC rail */
.toc-rail { position: sticky; top: calc(var(--topbar-h) + 1.5rem); align-self: start; max-height: calc(100vh - var(--topbar-h) - 3rem); overflow-y: auto; }
.toc-rail h4 { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-mute); margin: 0 0 .8rem; padding-left: .9rem; }
.toc-rail a { display: block; padding: .3rem .9rem; border-left: 2px solid var(--border); color: var(--ink-mute); font-size: .85rem; line-height: 1.35; }
.toc-rail a:hover { color: var(--ink); border-color: var(--border-strong); text-decoration: none; }
.toc-rail a.active { color: var(--accent); border-color: var(--accent); }

/* ------------------------------- Doc typography --------------------------- */
.doc .eyebrow, .eyebrow { display: inline-flex; align-items: center; gap: .5rem; font-size: .76rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: .9rem; }
.doc h1.title, h1.title { font-size: var(--step-4); margin: 0 0 .4rem; }
.doc .subtitle, .subtitle { font-size: var(--step-1); color: var(--ink-soft); font-weight: 400; margin: 0 0 1.4rem; font-family: var(--font-reading); font-style: italic; }
.doc .lede, .lede { font-size: var(--step-1); line-height: 1.55; color: var(--ink-soft); font-family: var(--font-reading); margin: 0 0 2rem; max-width: var(--reading-measure); }

/* Readable prose */
.prose { max-width: var(--reading-measure); font-family: var(--font-reading); font-size: var(--step-1); line-height: 1.78; }
.prose p { margin: 0 0 1.25em; }
.prose p.first { text-indent: 0; }
.prose p.continued { text-indent: 1.4em; }
.prose p.continued:first-child, .prose h2 + p.continued { text-indent: 0; }
.prose .extract { margin: 1.8em 0; padding: .2em 0 .2em 1.4em; border-left: 3px solid var(--accent); color: var(--ink-soft); font-size: .95em; font-style: italic; }
.prose h2 { font-family: var(--font-ui); font-size: var(--step-2); margin: 2.6em 0 .9em; padding-bottom: .35em; border-bottom: 1px solid var(--border); scroll-margin-top: calc(var(--topbar-h) + 1rem); }
.prose h2 .sec-num { color: var(--accent); font-size: .6em; vertical-align: middle; margin-right: .5em; font-variant-numeric: tabular-nums; }
.prose h3 { font-size: var(--step-1); margin: 2em 0 .7em; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1.25em; }
.prose li { margin: .3em 0; }
.prose blockquote { margin: 1.6em 0; padding: .3em 0 .3em 1.4rem; border-left: 3px solid var(--accent); font-style: italic; color: var(--ink-soft); }
.prose code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: .08em .35em; }
.prose sup.fn-ref, .prose sup.en-ref { color: var(--accent-2); cursor: help; font-weight: 700; }
.prose i, .prose em { font-style: italic; }

/* markdown rendered column (essays, summaries, themes, concepts) */
.md { font-family: var(--font-reading); font-size: var(--step-1); line-height: 1.78; max-width: var(--reading-measure); }
.md h2 { font-family: var(--font-ui); font-size: var(--step-2); margin: 2em 0 .7em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.md h3 { font-family: var(--font-ui); font-size: var(--step-1); margin: 1.7em 0 .6em; }
.md p { margin: 0 0 1.1em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.md li { margin: .35em 0; }
.md blockquote { margin: 1.4em 0; padding: .2em 0 .2em 1.3rem; border-left: 3px solid var(--accent); font-style: italic; color: var(--ink-soft); }
.md code { font-family: var(--font-mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: .08em .35em; font-size: .85em; }
.md strong { font-weight: 700; color: var(--ink); }
.md a { color: var(--accent-2); }
.md hr { margin: 1.8rem 0; }

/* Footnote tooltip */
.fn-pop { position: absolute; z-index: 70; max-width: 22rem; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 10px; padding: .8rem 1rem; box-shadow: var(--shadow); font-family: var(--font-ui); font-size: .85rem; line-height: 1.55; color: var(--ink-soft); }

/* ------------------------------- Components ------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: .4em; padding: .18em .65em; border-radius: 999px;
  font-family: var(--font-ui); font-size: .72rem; font-weight: 650; letter-spacing: .02em; line-height: 1.4;
  border: 1px solid color-mix(in oklab, var(--cat, var(--cat-default)) 45%, transparent);
  color: var(--cat, var(--cat-default)); background: color-mix(in oklab, var(--cat, var(--cat-default)) 14%, transparent);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--cat, var(--cat-default)); }
[data-cat="core-concept"]{ --cat: var(--cat-core-concept); }
[data-cat="mechanism"]{ --cat: var(--cat-mechanism); }
[data-cat="evolution"]{ --cat: var(--cat-evolution); }
[data-cat="organism"]{ --cat: var(--cat-organism); }
[data-cat="person"]{ --cat: var(--cat-person); }
[data-cat="place"]{ --cat: var(--cat-place); }
[data-cat="theme"]{ --cat: var(--cat-theme); }

.card {
  display: flex; flex-direction: column; gap: .5rem; padding: 1.1rem 1.2rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); transition: border-color .2s, transform .2s, box-shadow .2s;
}
.card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.card h3 { margin: 0; font-size: var(--step-0); }
.card p { margin: 0; color: var(--ink-soft); font-size: .92rem; line-height: 1.55; }
.card .meta { font-size: .78rem; color: var(--ink-mute); }
a.card { color: inherit; text-decoration: none; }
a.card:hover { text-decoration: none; }

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr)); }

.callout {
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2);
  padding: 1.1rem 1.3rem; margin: 1.6rem 0;
}
.callout.accent { border-left: 4px solid var(--accent); }
.callout h4 { margin: 0 0 .5rem; font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }

.keypoints { list-style: none; padding: 0; margin: 0; display: grid; gap: .7rem; }
.keypoints li { position: relative; padding-left: 1.7rem; line-height: 1.55; color: var(--ink-soft); }
.keypoints li::before { content: ""; position: absolute; left: 0; top: .55em; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 18%, transparent); }

.quote {
  font-family: var(--font-reading); font-style: italic; font-size: var(--step-1); line-height: 1.6;
  border-left: 3px solid var(--accent); padding: .3rem 0 .3rem 1.4rem; margin: 1.5rem 0; color: var(--ink);
}

.pill-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; }

.chip {
  display: inline-flex; align-items: center; gap: .4rem; padding: .35em .8em; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-soft); font-size: .85rem; text-decoration: none;
  transition: border-color .15s, color .15s, background .15s; cursor: pointer;
}
.chip:hover { border-color: var(--border-strong); color: var(--ink); text-decoration: none; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

/* Page header band */
.page-head { margin-bottom: 2rem; }
.crumbs { font-size: .8rem; color: var(--ink-mute); margin-bottom: 1rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--ink-mute); }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { opacity: .5; }

/* Prev / next */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3rem; }
.pager a { display: flex; flex-direction: column; gap: .25rem; padding: 1rem 1.2rem; border: 1px solid var(--border); border-radius: var(--radius); color: inherit; background: var(--surface); transition: border-color .2s, transform .2s; }
.pager a:hover { border-color: var(--border-strong); transform: translateY(-2px); text-decoration: none; }
.pager a.next { text-align: right; align-items: flex-end; }
.pager .dir { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-mute); }
.pager .t { font-weight: 600; color: var(--ink); }
.pager span.empty { border: 1px dashed var(--border); border-radius: var(--radius); }
@media (max-width: 560px){ .pager { grid-template-columns: 1fr; } }

/* Hero */
.hero { position: relative; padding: clamp(2rem,5vw,4rem) 0 1rem; }
.hero .eyebrow { color: var(--accent); }
.hero h1 { font-size: var(--step-4); margin: .4rem 0; }
.hero .by { font-family: var(--font-reading); font-style: italic; color: var(--ink-soft); font-size: var(--step-1); }
.hero .epi { max-width: 46ch; margin: 1.6rem 0; font-family: var(--font-reading); color: var(--ink-soft); font-style: italic; line-height: 1.6; border-left: 2px solid var(--border-strong); padding-left: 1.2rem; }
.cta-row { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 1.5rem; }
.btn { display: inline-flex; align-items: center; gap: .5rem; padding: .7rem 1.2rem; border-radius: 10px; font-weight: 600; font-size: .92rem; cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); transition: transform .15s, box-shadow .2s, border-color .2s; text-decoration: none; }
.btn:hover { transform: translateY(-2px); text-decoration: none; box-shadow: var(--shadow-sm); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); border-color: transparent; box-shadow: var(--glow); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; justify-content: center; }
.btn.danger { color: var(--bad); border-color: color-mix(in oklab, var(--bad) 45%, transparent); }
.btn svg { width: 18px; height: 18px; }

.stat-row { display: flex; flex-wrap: wrap; gap: 2rem; margin: 2.5rem 0; padding: 1.4rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.stat { display: flex; flex-direction: column; }
.stat .n { font-size: var(--step-2); font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat .l { font-size: .8rem; color: var(--ink-mute); letter-spacing: .04em; }

.sec-title { display: flex; align-items: center; gap: .8rem; margin: 2.6rem 0 1.2rem; font-size: var(--step-2); }
.sec-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ============================== LIBRARY =================================== */
/* ---- Hero ---- */
.lib-hero {
  position: relative; overflow: hidden; border-radius: calc(var(--radius) + 4px);
  margin: .25rem 0 2.2rem; padding: clamp(2rem, 4.5vw, 3.4rem) clamp(1.4rem, 4vw, 3rem);
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2.5rem; align-items: center;
  background:
    radial-gradient(135% 150% at 6% -25%, color-mix(in oklab, var(--accent) 24%, transparent), transparent 52%),
    radial-gradient(120% 150% at 112% 135%, color-mix(in oklab, var(--accent-2) 22%, transparent), transparent 50%),
    linear-gradient(170deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.lib-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .45;
  background-image:
    linear-gradient(color-mix(in oklab, var(--border) 60%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in oklab, var(--border) 60%, transparent) 1px, transparent 1px);
  background-size: 34px 34px;
  -webkit-mask-image: radial-gradient(75% 75% at 28% 14%, #000, transparent 78%);
          mask-image: radial-gradient(75% 75% at 28% 14%, #000, transparent 78%);
}
.lib-hero-main { position: relative; z-index: 1; }
.lib-hero h1 { font-size: var(--step-4); line-height: 1.04; letter-spacing: -.015em; margin: .2rem 0 .7rem; max-width: 16ch; }
.lib-hero p { color: var(--ink-soft); max-width: 54ch; font-size: var(--step-0); margin: 0 0 1.5rem; line-height: 1.6; }

.lib-search {
  display: flex; align-items: center; gap: .65rem; max-width: 32rem;
  background: color-mix(in oklab, var(--bg) 50%, var(--surface)); border: 1px solid var(--border-strong);
  border-radius: 14px; padding: 0 .85rem; height: 52px; transition: border-color .15s, box-shadow .15s;
}
.lib-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 18%, transparent); }
.lib-search svg { width: 19px; height: 19px; color: var(--ink-mute); flex: none; }
.lib-search input { flex: 1; background: none; border: none; outline: none; color: var(--ink); font-size: 1.02rem; }
.lib-search kbd { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-mute); background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; padding: .08rem .42rem; }

.lib-metrics { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.7rem; margin-top: 1.6rem; }
.metric { position: relative; display: flex; align-items: baseline; gap: .4rem; }
.metric + .metric::before { content: ""; position: absolute; left: -.95rem; top: 50%; width: 4px; height: 4px; border-radius: 50%; background: var(--border-strong); transform: translateY(-50%); }
.metric b { font-size: 1.3rem; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--ink); }
.metric span { font-size: .82rem; color: var(--ink-mute); }
.lib-hero .cta-row { margin-top: 1.6rem; }

/* hero cover fan */
.lib-hero-shelf { position: relative; z-index: 1; width: 252px; height: 234px; flex: none; }
.shelf-cover {
  position: absolute; bottom: 0; left: 50%; width: 132px; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 3px 8px 8px 3px;
  box-shadow: -9px 4px 0 -8px color-mix(in oklab, #000 40%, transparent),
              -14px 22px 38px -16px rgba(0,0,0,.65),
              0 0 0 1px color-mix(in oklab, var(--border) 65%, transparent);
  transform: translateX(-50%) translateX(calc((var(--i) - 2) * 48px)) rotate(calc((var(--i) - 2) * 5deg));
  transition: transform .4s var(--ease);
}
.shelf-cover::after { content: ""; position: absolute; inset: 0 0 0 auto; width: 4px; background: linear-gradient(90deg, transparent, rgba(0,0,0,.25)); }
.lib-hero:hover .shelf-cover { transform: translateX(-50%) translateX(calc((var(--i) - 2) * 60px)) rotate(calc((var(--i) - 2) * 3.5deg)); }

@media (max-width: 980px) { .lib-hero { grid-template-columns: 1fr; gap: 1.5rem; } .lib-hero-shelf { display: none; } }

/* ---- Toolbar ---- */
.lib-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.lib-toolbar-l { display: flex; align-items: baseline; gap: .7rem; }
.lib-h2 { font-size: var(--step-2); margin: 0; letter-spacing: -.01em; }
.lib-count { font-size: .85rem; color: var(--ink-mute); font-variant-numeric: tabular-nums; }
.lib-toolbar-r { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }

.lib-filter { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.chip { border: none; background: none; color: var(--ink-mute); font: inherit; font-size: .82rem; font-weight: 600; padding: .35rem .85rem; border-radius: 999px; cursor: pointer; transition: color .15s, background .15s; }
.chip:hover { color: var(--ink); }
.chip.active { color: var(--accent-ink); background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: var(--shadow-sm); }

.lib-sort { position: relative; display: inline-flex; align-items: center; }
.lib-sort select { appearance: none; -webkit-appearance: none; background: var(--surface); border: 1px solid var(--border); color: var(--ink); font: inherit; font-size: .85rem; font-weight: 600; padding: .5rem 2.1rem .5rem .85rem; border-radius: 10px; cursor: pointer; transition: border-color .15s; }
.lib-sort select:hover { border-color: var(--border-strong); }
.lib-sort svg { position: absolute; right: .6rem; width: 15px; height: 15px; color: var(--ink-mute); pointer-events: none; }

.view-toggle { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; }
.view-toggle button { display: grid; place-items: center; width: 33px; height: 31px; border: none; background: none; color: var(--ink-mute); border-radius: 8px; cursor: pointer; transition: .15s; }
.view-toggle button svg { width: 17px; height: 17px; }
.view-toggle button:hover { color: var(--ink); }
.view-toggle button.active { background: var(--surface-3); color: var(--accent); box-shadow: var(--shadow-sm); }

/* ---- Grid of portrait covers ---- */
.book-grid { display: grid; gap: clamp(1.3rem, 2.2vw, 2rem) clamp(1.2rem, 2vw, 1.8rem); grid-template-columns: repeat(auto-fill, minmax(min(100%, 14.5rem), 1fr)); }
.book-card { position: relative; display: flex; flex-direction: column; gap: .85rem; text-decoration: none; color: inherit; animation: cardIn .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 45ms); }
.book-card:hover { text-decoration: none; }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.bc-cover { position: relative; }
.cover-frame {
  position: relative; aspect-ratio: 2 / 3; border-radius: 4px 9px 9px 4px; overflow: hidden;
  background: linear-gradient(150deg, color-mix(in oklab, var(--bc-accent, var(--accent)) 65%, #0b1118), color-mix(in oklab, var(--bc-accent2, var(--accent-2)) 65%, #0b1118));
  box-shadow: inset 0 1px 0 0 color-mix(in oklab, #fff 12%, transparent), var(--shadow);
  transition: transform .32s var(--ease), box-shadow .32s var(--ease);
}
.cover-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-frame::before { content: ""; position: absolute; top: 0; left: 0; bottom: 0; width: 9px; z-index: 2; background: linear-gradient(90deg, rgba(0,0,0,.34), rgba(0,0,0,.05) 62%, rgba(255,255,255,.10)); }
.cover-frame.nocover::after { content: attr(data-title); position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 1.4rem .9rem; font-family: var(--font-reading); font-style: italic; font-size: var(--step-1); line-height: 1.25; color: #fff; }

.bc-sheen { position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; background: linear-gradient(105deg, transparent 32%, rgba(255,255,255,.40) 48%, transparent 64%); }
.book-card:hover .cover-frame { transform: translateY(-7px) rotate(-.7deg); box-shadow: inset 0 1px 0 0 color-mix(in oklab, #fff 16%, transparent), var(--glow), 0 32px 52px -22px rgba(0,0,0,.72); }
.book-card:hover .bc-sheen { animation: sheen .75s var(--ease); }
@keyframes sheen { 0% { opacity: 0; transform: translateX(-45%); } 28% { opacity: 1; } 100% { opacity: 0; transform: translateX(65%); } }

.bc-cta { position: absolute; left: 50%; bottom: .7rem; z-index: 4; display: inline-flex; align-items: center; gap: .3rem; transform: translate(-50%, 8px); opacity: 0; transition: .28s var(--ease); background: color-mix(in oklab, var(--bg-deep) 68%, transparent); color: #fff; border: 1px solid color-mix(in oklab, #fff 26%, transparent); backdrop-filter: blur(8px); border-radius: 999px; padding: .34rem .85rem; font-size: .78rem; font-weight: 600; }
.bc-cta svg { width: 14px; height: 14px; }
.book-card:hover .bc-cta { opacity: 1; transform: translate(-50%, 0); }
.book-card:focus-visible { outline: none; }
.book-card:focus-visible .cover-frame { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }

.lock-badge { position: absolute; top: .6rem; right: .6rem; z-index: 5; display: inline-flex; align-items: center; gap: .3rem; background: color-mix(in oklab, var(--bg-deep) 70%, transparent); color: #fff; border: 1px solid color-mix(in oklab, #fff 22%, transparent); border-radius: 999px; padding: .22rem .58rem; font-size: .7rem; font-weight: 600; backdrop-filter: blur(6px); }
.lock-badge svg { width: 12px; height: 12px; }
.book-card.locked .cover-frame { filter: saturate(.55) brightness(.7); }

.bc-meta { display: flex; flex-direction: column; gap: .16rem; padding: 0 .15rem; }
.bc-title { font-size: 1.02rem; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; transition: color .15s; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card:hover .bc-title { color: var(--accent); }
.bc-author { font-size: .82rem; color: var(--ink-mute); }
.bc-stats { display: flex; flex-wrap: wrap; gap: .1rem .8rem; margin-top: .4rem; font-size: .74rem; color: var(--ink-mute); }
.bc-stats b { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---- List view ---- */
.book-list { display: flex; flex-direction: column; gap: .7rem; }
.book-row { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 1.1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem .8rem .8rem; text-decoration: none; color: inherit; transition: border-color .18s, transform .18s, box-shadow .18s; animation: cardIn .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 35ms); }
.book-row:hover { border-color: var(--border-strong); transform: translateX(3px); box-shadow: var(--shadow-sm); text-decoration: none; }
.br-cover { position: relative; width: 48px; aspect-ratio: 2 / 3; flex: none; border-radius: 3px 5px 5px 3px; overflow: hidden; background: linear-gradient(150deg, color-mix(in oklab, var(--bc-accent, var(--accent)) 65%, #0b1118), color-mix(in oklab, var(--bc-accent2, var(--accent-2)) 65%, #0b1118)); box-shadow: var(--shadow-sm); }
.br-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.br-cover.nocover::after { content: attr(data-title); position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: .3rem; font-family: var(--font-reading); font-style: italic; font-size: .6rem; line-height: 1.1; color: #fff; }
.br-main { min-width: 0; }
.br-title { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.lock-inline { color: var(--ink-mute); display: inline-flex; } .lock-inline svg { width: 13px; height: 13px; }
.br-sub { font-size: .85rem; color: var(--ink-mute); font-family: var(--font-reading); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.br-author { font-size: .8rem; color: var(--ink-soft); margin-top: .12rem; }
.br-stats { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.br-go { color: var(--ink-mute); display: grid; place-items: center; transition: transform .18s, color .18s; } .br-go svg { width: 18px; height: 18px; }
.book-row:hover .br-go { color: var(--accent); transform: translateX(2px); }
.book-row.locked .br-cover { filter: saturate(.55) brightness(.72); }

.stat-chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; color: var(--ink-mute); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .2rem .55rem; }
.stat-chip b { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

@media (max-width: 680px) {
  .book-row { grid-template-columns: auto 1fr auto; }
  .br-stats { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .book-card, .book-row { animation: none; }
  .book-card:hover .bc-sheen { animation: none; }
}

/* ============================== AUTH ===================================== */
/* Full-screen split: branded showcase panel + form. This is the landing page. */
.auth-screen {
  position: relative;
  min-height: 100vh; min-height: 100svh;
  display: grid; grid-template-columns: 1.05fr 1fr;
}
.auth-theme { position: fixed; top: 1rem; right: 1rem; z-index: 5; }

.auth-aside {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 2rem;
  padding: clamp(2rem, 5vw, 4.25rem);
  color: var(--ink);
  background:
    radial-gradient(115% 80% at 8% 6%, color-mix(in oklab, var(--accent) 42%, transparent), transparent 58%),
    radial-gradient(120% 95% at 98% 102%, color-mix(in oklab, var(--accent-2) 40%, transparent), transparent 55%),
    var(--bg-deep);
  border-right: 1px solid var(--border);
}
/* oversized watermark mark (first brandMark in the aside) */
.auth-aside > .mark:first-child {
  position: absolute; width: 80%; height: auto; right: -22%; top: 8%;
  color: var(--accent); opacity: .06; pointer-events: none; transform: rotate(8deg);
}
.auth-brand { position: relative; display: inline-flex; align-items: center; gap: .7rem; font-weight: 800; letter-spacing: .2px; color: var(--ink); }
.auth-brand .mark { width: 30px; height: 30px; color: var(--accent); }
.auth-brand span { display: flex; flex-direction: column; line-height: 1.05; font-size: 1.15rem; }
.auth-brand small { font-weight: 500; font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-mute); }

.auth-aside-body { position: relative; margin-top: auto; max-width: 30rem; }
.auth-aside-body h2 { font-size: var(--step-3); line-height: 1.08; margin: 0 0 1rem; letter-spacing: -.01em; }
.auth-aside-body > p { color: var(--ink-soft); font-size: 1.02rem; line-height: 1.6; margin: 0 0 1.8rem; }
.auth-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.auth-points li { display: flex; gap: .85rem; align-items: flex-start; font-size: .92rem; color: var(--ink-soft); line-height: 1.5; }
.auth-points b { color: var(--ink); }
.ap-ico { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: color-mix(in oklab, var(--accent) 16%, transparent); border: 1px solid color-mix(in oklab, var(--accent) 34%, transparent); color: var(--accent); }
.ap-ico svg { width: 17px; height: 17px; }
.auth-aside-foot { position: relative; font-size: .82rem; color: var(--ink-mute); font-style: italic; }

.auth-main { display: grid; place-items: center; padding: clamp(1.5rem, 4vw, 3rem); background: var(--bg); }
.auth-main .auth-card { width: 100%; max-width: 25rem; }
.auth-card-brand { display: none; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.1rem; color: var(--ink); margin-bottom: 1.4rem; }
.auth-card-brand .mark { width: 26px; height: 26px; color: var(--accent); }

.auth-wrap { max-width: 26rem; margin: clamp(2rem, 7vh, 6rem) auto 4rem; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.2rem 2rem; box-shadow: var(--shadow-sm); }
.auth-card h1 { font-size: var(--step-2); margin: 0 0 .4rem; }
.auth-card .sub { color: var(--ink-mute); font-size: .9rem; margin: 0 0 1.6rem; }

@media (max-width: 880px) {
  .auth-screen { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-card-brand { display: inline-flex; }
  .auth-main { background: var(--bg-deep); }
}
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.field input, .field textarea, .field select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: .65rem .8rem;
  color: var(--ink); font-size: .95rem; outline: none; transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.field textarea { resize: vertical; min-height: 5rem; }
.form-error { background: color-mix(in oklab, var(--bad) 14%, transparent); border: 1px solid color-mix(in oklab, var(--bad) 45%, transparent); color: var(--bad); padding: .6rem .8rem; border-radius: 9px; font-size: .85rem; margin-bottom: 1rem; }
.form-ok { background: color-mix(in oklab, var(--good) 14%, transparent); border: 1px solid color-mix(in oklab, var(--good) 45%, transparent); color: var(--good); padding: .6rem .8rem; border-radius: 9px; font-size: .85rem; margin-bottom: 1rem; }
.auth-alt { margin-top: 1.3rem; text-align: center; font-size: .88rem; color: var(--ink-mute); }

/* ------------------------------- Highlights & notes ----------------------- */
mark.hl { background: var(--mark); color: inherit; border-radius: 3px; padding: .02em 0; box-shadow: inset 0 -2px 0 var(--mark-edge); cursor: pointer; transition: background .15s; }
mark.hl:hover { background: color-mix(in oklab, var(--mark) 70%, var(--ink)); }
mark.hl.has-note { box-shadow: inset 0 -2px 0 var(--accent-2); }
mark.hl.has-note::after { content: "\2726"; font-size: .6em; vertical-align: super; color: var(--accent-2); margin-left: 1px; }
mark.hl[data-color="teal"]   { background: var(--mark); box-shadow: inset 0 -2px 0 var(--mark-edge); }
mark.hl[data-color="gold"]   { background: color-mix(in oklab, var(--cat-person) 38%, transparent); box-shadow: inset 0 -2px 0 var(--cat-person); }
mark.hl[data-color="rose"]   { background: color-mix(in oklab, var(--cat-place) 36%, transparent); box-shadow: inset 0 -2px 0 var(--cat-place); }
mark.hl[data-color="violet"] { background: color-mix(in oklab, var(--cat-evolution) 34%, transparent); box-shadow: inset 0 -2px 0 var(--cat-evolution); }

/* selection toolbar */
.sel-tools {
  position: absolute; z-index: 80; display: flex; align-items: center; gap: 2px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(6px) scale(.96); pointer-events: none; transition: opacity .15s, transform .15s;
}
.sel-tools.show { opacity: 1; transform: none; pointer-events: auto; }
.sel-tools button { display: inline-flex; align-items: center; height: 34px; padding: 0 .6rem; gap: .35rem; border: none; background: none; color: var(--ink-soft); border-radius: 8px; cursor: pointer; font-family: var(--font-ui); font-size: .82rem; }
.sel-tools button:hover { background: var(--surface-3); color: var(--ink); }
.sel-tools button svg { width: 16px; height: 16px; }
.sel-tools .swatches { display: flex; gap: 3px; padding: 0 4px; }
.sel-tools .swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.sel-tools .sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }

/* note popover / editor */
.note-pop {
  position: absolute; z-index: 82; width: min(22rem, 90vw); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; opacity: 0; transform: translateY(6px); pointer-events: none; transition: opacity .15s, transform .15s;
}
.note-pop.show { opacity: 1; transform: none; pointer-events: auto; }
.note-pop .q { font-family: var(--font-reading); font-style: italic; font-size: .9rem; color: var(--ink-soft); border-left: 2px solid var(--accent); padding-left: .7rem; margin-bottom: .7rem; max-height: 5rem; overflow: auto; }
.note-pop textarea { width: 100%; min-height: 5rem; resize: vertical; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; color: var(--ink); font-family: var(--font-ui); font-size: .9rem; line-height: 1.5; }
.note-pop textarea:focus { outline: none; border-color: var(--accent); }
.note-pop .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .7rem; }
.note-pop .row .left { display: flex; gap: .3rem; }
.btn-sm { padding: .4rem .8rem; font-size: .82rem; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--ink); cursor: pointer; }
.btn-sm:hover { background: var(--surface-3); }
.btn-sm.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-sm.danger { color: var(--bad); }

/* Annotations drawer */
.drawer { position: fixed; top: 0; right: 0; z-index: 90; height: 100vh; width: min(26rem, 92vw); background: var(--surface); border-left: 1px solid var(--border-strong); box-shadow: var(--shadow); transform: translateX(105%); transition: transform .3s var(--ease); display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer header { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.drawer header h3 { margin: 0; font-size: 1rem; }
.drawer header .spacer { flex: 1; }
.drawer .body { overflow-y: auto; padding: 1rem 1.2rem; flex: 1; }
.drawer .empty { color: var(--ink-mute); text-align: center; padding: 3rem 1rem; font-size: .9rem; }
.anno { border: 1px solid var(--border); border-radius: 10px; padding: .8rem .9rem; margin-bottom: .8rem; background: var(--surface-2); cursor: pointer; transition: border-color .15s; }
.anno:hover { border-color: var(--border-strong); }
.anno .a-q { font-family: var(--font-reading); font-style: italic; font-size: .88rem; color: var(--ink); border-left: 3px solid var(--mark-edge); padding-left: .6rem; }
.anno .a-note { margin-top: .5rem; font-size: .85rem; color: var(--ink-soft); background: var(--note-bg); border-radius: 6px; padding: .5rem .6rem; }
.anno .a-meta { margin-top: .5rem; font-size: .72rem; color: var(--ink-mute); display: flex; justify-content: space-between; }
.anno .a-meta a { color: var(--ink-mute); }
.drawer .guest-hint { font-size: .8rem; color: var(--ink-mute); background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 8px; padding: .6rem .7rem; margin-bottom: .9rem; }
.drawer .guest-hint a { color: var(--accent-2); }

/* ------------------------------- Search modal ----------------------------- */
.modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
.modal-root.open { display: block; }
.modal-root .backdrop { position: absolute; inset: 0; background: rgba(2,6,12,.55); backdrop-filter: blur(4px); }
.search-modal { position: relative; max-width: 42rem; margin: 9vh auto 0; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; max-height: 76vh; display: flex; flex-direction: column; }
.search-modal .s-input { display: flex; align-items: center; gap: .7rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.search-modal .s-input svg { width: 20px; height: 20px; color: var(--ink-mute); flex: none; }
.search-modal input { flex: 1; background: none; border: none; outline: none; color: var(--ink); font-family: var(--font-ui); font-size: 1.1rem; }
.search-modal input::placeholder { color: var(--ink-mute); }
.search-modal .s-results { overflow-y: auto; padding: .5rem; }
.search-modal .s-cat { font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-mute); padding: .8rem .8rem .3rem; }
.s-hit { display: flex; align-items: flex-start; gap: .7rem; padding: .6rem .8rem; border-radius: 10px; cursor: pointer; text-decoration: none; color: inherit; }
.s-hit.active, .s-hit:hover { background: var(--surface-2); text-decoration: none; }
.s-hit .s-ico { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: color-mix(in oklab, var(--cat, var(--accent)) 18%, transparent); color: var(--cat, var(--accent)); font-size: .8rem; }
.s-hit .s-main { min-width: 0; }
.s-hit .s-title { font-weight: 600; font-size: .95rem; }
.s-hit .s-title mark { background: color-mix(in oklab, var(--accent) 30%, transparent); color: inherit; border-radius: 2px; }
.s-hit .s-sub { font-size: .82rem; color: var(--ink-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-hit .s-sub mark { background: color-mix(in oklab, var(--accent) 24%, transparent); color: inherit; border-radius: 2px; }
.search-modal .s-foot { display: flex; gap: 1rem; padding: .6rem 1rem; border-top: 1px solid var(--border); font-size: .76rem; color: var(--ink-mute); }
.search-modal .s-foot span { display: inline-flex; align-items: center; gap: .35rem; }
.search-modal .s-empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-mute); }

/* Glossary controls */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1.5rem 0 2rem; }
.filter-bar input.q { flex: 1; min-width: 12rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .9rem; color: var(--ink); font-family: var(--font-ui); }
.filter-bar input.q:focus { outline: none; border-color: var(--accent); }
.toggle-cat { cursor: pointer; user-select: none; }
.toggle-cat[aria-pressed="false"] { opacity: .4; }
.gloss-letter { font-size: var(--step-1); color: var(--accent); margin: 1.8rem 0 .6rem; font-variant-numeric: tabular-nums; }
.gloss-list { display: grid; gap: .9rem; }
.gloss-item { display: grid; gap: .3rem; padding: 1rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); transition: border-color .15s; }
.gloss-item:hover { border-color: var(--border-strong); }
.gloss-item h3 { margin: 0; font-size: var(--step-0); display: flex; align-items: center; gap: .6rem; }
.gloss-item h3 a { color: var(--ink); }
.gloss-item p { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.gloss-item .gloss-meta { font-size: .78rem; color: var(--ink-mute); }

/* Photo gallery */
.gallery { columns: 2; column-gap: 1rem; }
@media (max-width: 720px){ .gallery { columns: 1; } }
.gallery figure { break-inside: avoid; margin: 0 0 1rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.gallery figcaption { padding: .8rem 1rem; font-size: .85rem; color: var(--ink-soft); line-height: 1.5; }

/* ============================== WISHLIST ================================== */
.wish-item { display: flex; gap: 1rem; padding: 1rem 1.2rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: .9rem; }
.wish-vote { display: flex; flex-direction: column; align-items: center; gap: .2rem; flex: none; min-width: 3rem; }
.wish-vote button { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--ink-soft); cursor: pointer; }
.wish-vote button:hover { border-color: var(--accent); color: var(--accent); }
.wish-vote button.voted { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.wish-vote .count { font-weight: 700; font-variant-numeric: tabular-nums; }
.wish-main { flex: 1; min-width: 0; }
.wish-main h3 { margin: 0 0 .2rem; font-size: var(--step-0); }
.wish-main .by { color: var(--ink-mute); font-size: .85rem; }
.wish-main .note { color: var(--ink-soft); font-size: .9rem; margin-top: .4rem; }
.status-badge { display: inline-flex; align-items: center; gap: .35rem; padding: .18em .65em; border-radius: 999px; font-size: .72rem; font-weight: 650; border: 1px solid; }
.status-requested { color: var(--info); border-color: color-mix(in oklab, var(--info) 45%, transparent); background: color-mix(in oklab, var(--info) 12%, transparent); }
.status-approved  { color: var(--good); border-color: color-mix(in oklab, var(--good) 45%, transparent); background: color-mix(in oklab, var(--good) 12%, transparent); }
.status-queued    { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 45%, transparent); background: color-mix(in oklab, var(--warn) 12%, transparent); }
.status-processing{ color: var(--accent); border-color: color-mix(in oklab, var(--accent) 45%, transparent); background: color-mix(in oklab, var(--accent) 12%, transparent); }
.status-done      { color: var(--good); border-color: color-mix(in oklab, var(--good) 45%, transparent); background: color-mix(in oklab, var(--good) 16%, transparent); }
.status-rejected  { color: var(--bad); border-color: color-mix(in oklab, var(--bad) 45%, transparent); background: color-mix(in oklab, var(--bad) 12%, transparent); }
.mod-controls { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; align-items: center; }
.mod-controls select { padding: .3rem .5rem; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); font-size: .82rem; }

/* ============================== CONTRIBUTE =============================== */
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 2.4rem 1.4rem; text-align: center; color: var(--ink-mute); background: var(--surface); transition: border-color .15s, background .15s; cursor: pointer; }
.dropzone.drag { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 8%, var(--surface)); color: var(--ink); }
.dropzone svg { width: 34px; height: 34px; margin: 0 auto .7rem; color: var(--accent); }
.dropzone .fname { color: var(--ink); font-weight: 600; margin-top: .5rem; }
.job-log { background: var(--bg-deep); border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem; font-family: var(--font-mono); font-size: .8rem; line-height: 1.6; max-height: 22rem; overflow-y: auto; color: var(--ink-soft); }
.job-log .ts { color: var(--ink-mute); }
.job-log .stg { color: var(--accent); }
.progress-track { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin: 1rem 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s var(--ease); border-radius: 999px; }

/* ============================== ADMIN ==================================== */
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin: 1.4rem 0 1.8rem; flex-wrap: wrap; }
.tabs a { padding: .6rem .9rem; color: var(--ink-mute); font-weight: 600; font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.stat-cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); margin-bottom: 2rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.3rem; }
.stat-card .n { font-size: var(--step-3); font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1; }
.stat-card .l { font-size: .82rem; color: var(--ink-mute); margin-top: .3rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th { text-align: left; padding: .7rem .9rem; color: var(--ink-mute); font-weight: 600; font-size: .76rem; letter-spacing: .06em; text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl td { padding: .7rem .9rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: var(--surface-2); }
table.tbl select { padding: .3rem .5rem; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); font-size: .82rem; }
.grant-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.grant-chip { font-size: .72rem; padding: .15rem .5rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-mute); cursor: pointer; }
.grant-chip.on { background: color-mix(in oklab, var(--accent) 18%, transparent); color: var(--accent); border-color: color-mix(in oklab, var(--accent) 45%, transparent); }

/* access-required panel */
.access-panel { max-width: 32rem; margin: 4rem auto; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem 2rem; }
.access-panel .lock-ico { width: 48px; height: 48px; margin: 0 auto 1rem; color: var(--ink-mute); }
.access-panel h2 { margin: 0 0 .6rem; }
.access-panel p { color: var(--ink-soft); margin: 0 0 1.4rem; }

/* Toast */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 110; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--ink); padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); font-size: .88rem; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* footer */
.site-foot { border-top: 1px solid var(--border); margin-top: 4rem; padding: 2rem 0; color: var(--ink-mute); font-size: .85rem; line-height: 1.6; }
.site-foot a { color: var(--ink-soft); }

/* loading / empty states */
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-pad { display: grid; place-items: center; gap: 1rem; padding: 5rem 1rem; color: var(--ink-mute); }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: .9rem; text-align: center; color: var(--ink-mute); padding: 3.5rem 1rem; grid-column: 1 / -1; }
.empty-state svg { width: 34px; height: 34px; opacity: .55; }
.empty-state p { margin: 0; }

/* utility */
.muted { color: var(--ink-mute); }
.soft { color: var(--ink-soft); }
.center { text-align: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.mt-0{margin-top:0}.mb-0{margin-bottom:0}.mt-1{margin-top:1rem}.mt-2{margin-top:2rem}
.flow > * + * { margin-top: 1.1rem; }
.hidden { display: none !important; }
.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; }
