/* Grimoire. Two themes, one identity: gold leaf and rubric red on parchment
   by day, on aubergine ink by night. Every colour is a token below. */

/* ---------- Light: warm parchment ---------- */
:root {
  color-scheme: light;
  --bg: #efe4cc;
  --bg-2: #e4d5b4;
  --bg-glow: #f8f0de;
  --surface: #f7efdd;
  --surface-2: #ebdfc5;
  --surface-3: #e1d2b2;
  --line: #d4c4a0;
  --line-strong: #b5a079;
  --text: #2a1f15;
  --text-2: #5c4935;
  --accent: #835a10;
  --accent-fill: #c8983c;
  --accent-fill-hover: #d6a74b;
  --on-accent: #20160a;
  --accent-soft: rgba(200, 152, 60, 0.2);
  --accent-glow: rgba(200, 152, 60, 0.45);
  --rubric: #962c21;
  --k-main: #835a10;
  --k-side: #2b6656;
  --k-whatif: #9c3f34;
  --k-muted: #9a8a70;
  --leaf-bg: #f9f2e3;
  --leaf-bg-2: #f0e5cc;
  --leaf-ink: #2a1f15;
  --leaf-ink-2: #65513d;
  --leaf-hl: rgba(200, 152, 60, 0.24);
  --voice-mix: 100%;
  --shadow: rgba(70, 46, 16, 0.22);
  --shadow-strong: rgba(70, 46, 16, 0.42);
  --scrim: rgba(52, 36, 18, 0.5);
  --page-edge: #f3ead6;
  --page-edge-line: #cdbd9a;
  --spine: rgba(40, 24, 8, 0.35);
  --gloss: rgba(255, 255, 255, 0.18);
  --grain-opacity: 0.32;
  --grain-blend: multiply;
}

/* ---------- Dark: deep aubergine ink ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #120d19;
  --bg-2: #0b0810;
  --bg-glow: #2b1d3a;
  --surface: #1c1526;
  --surface-2: #251c31;
  --surface-3: #30253f;
  --line: #352a45;
  --line-strong: #54466a;
  --text: #f2e9d8;
  --text-2: #b9afc5;
  --accent: #e0b762;
  --accent-fill: #d6aa52;
  --accent-fill-hover: #e4bb66;
  --on-accent: #1a1207;
  --accent-soft: rgba(224, 183, 98, 0.14);
  --accent-glow: rgba(224, 183, 98, 0.55);
  --rubric: #ec9a84;
  --k-main: #e0b762;
  --k-side: #8fc4b3;
  --k-whatif: #eb9e8c;
  --k-muted: #6e6382;
  --leaf-bg: #1a1423;
  --leaf-bg-2: #140f1c;
  --leaf-ink: #efe5d3;
  --leaf-ink-2: #ada1ba;
  --leaf-hl: rgba(224, 183, 98, 0.13);
  --voice-mix: 40%;
  --shadow: rgba(0, 0, 0, 0.5);
  --shadow-strong: rgba(0, 0, 0, 0.82);
  --scrim: rgba(6, 4, 10, 0.74);
  --page-edge: #dccfb3;
  --page-edge-line: #a6977a;
  --spine: rgba(0, 0, 0, 0.55);
  --gloss: rgba(255, 255, 255, 0.07);
  --grain-opacity: 0.5;
  --grain-blend: soft-light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #120d19;
    --bg-2: #0b0810;
    --bg-glow: #2b1d3a;
    --surface: #1c1526;
    --surface-2: #251c31;
    --surface-3: #30253f;
    --line: #352a45;
    --line-strong: #54466a;
    --text: #f2e9d8;
    --text-2: #b9afc5;
    --accent: #e0b762;
    --accent-fill: #d6aa52;
    --accent-fill-hover: #e4bb66;
    --on-accent: #1a1207;
    --accent-soft: rgba(224, 183, 98, 0.14);
    --accent-glow: rgba(224, 183, 98, 0.55);
    --rubric: #ec9a84;
    --k-main: #e0b762;
    --k-side: #8fc4b3;
    --k-whatif: #eb9e8c;
    --k-muted: #6e6382;
    --leaf-bg: #1a1423;
    --leaf-bg-2: #140f1c;
    --leaf-ink: #efe5d3;
    --leaf-ink-2: #ada1ba;
    --leaf-hl: rgba(224, 183, 98, 0.13);
    --voice-mix: 40%;
    --shadow: rgba(0, 0, 0, 0.5);
    --shadow-strong: rgba(0, 0, 0, 0.82);
    --scrim: rgba(6, 4, 10, 0.74);
    --page-edge: #dccfb3;
    --page-edge-line: #a6977a;
    --spine: rgba(0, 0, 0, 0.55);
    --gloss: rgba(255, 255, 255, 0.07);
    --grain-opacity: 0.5;
    --grain-blend: soft-light;
  }
}

/* ---------- Scale ---------- */
:root {
  --display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --text-face: "Alegreya", "Iowan Old Style", Georgia, serif;
  --ui: "Alegreya Sans", "Gill Sans", "Segoe UI", sans-serif;

  --fs-xs: 0.8125rem;   /* 13 */
  --fs-sm: 0.9375rem;   /* 15 */
  --fs-md: 1.0625rem;   /* 17 */
  --fs-lg: 1.3125rem;   /* 21 */
  --fs-xl: 1.625rem;    /* 26 */
  --fs-2xl: 2.125rem;   /* 34 */
  --fs-3xl: clamp(3.75rem, 8vw, 6.75rem);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;
  --r-sm: 4px; --r-md: 8px; --r-lg: 14px; --r-pill: 999px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --bar-h: 58px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100vh; min-height: 100dvh; }
html { background: var(--bg); }
body {
  background-color: var(--bg);
  background-image:
    radial-gradient(110% 70% at 50% -10%, var(--bg-glow) 0%, transparent 62%),
    radial-gradient(90% 60% at 50% 120%, var(--bg-2) 0%, transparent 70%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
/* paper grain over everything, very faint */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100;
  opacity: var(--grain-opacity); mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5  0 0 0 0 .5  0 0 0 0 .5  0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 22px; height: 22px; flex: none; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }

/* theme toggle: shows the theme you would switch to */
.theme-toggle { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 50%; color: var(--text-2); transition: color .2s var(--ease), background-color .2s var(--ease); }
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle .ico-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .ico-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .ico-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .ico-moon { display: none; }
}

/* ---------- Library ---------- */
.library { max-width: 1180px; margin: 0 auto; padding: var(--s8) var(--s6) 96px; }
.library-head { position: relative; margin-bottom: 64px; }
.corner { position: absolute; top: -40px; right: 0; }
.wordmark {
  font-family: var(--display); font-weight: 600; font-size: var(--fs-3xl);
  line-height: .9; letter-spacing: -0.015em; margin: 0; color: var(--text);
}
.wordmark::first-letter { color: var(--accent); }
.library-sub { font-family: var(--text-face); font-style: italic; color: var(--text-2); font-size: var(--fs-lg); margin: var(--s4) 0 0; max-width: 40ch; }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 56px 40px; align-items: start; }
.tome { display: block; color: inherit; text-decoration: none; border-radius: var(--r-md); }
.tome-cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 3px 7px 7px 3px; overflow: visible;
  background: var(--surface-2);
  /* page block on the fore-edge, then the drop shadow */
  box-shadow:
    3px 2px 0 -1px var(--page-edge), 3px 2px 0 0 var(--page-edge-line),
    6px 4px 0 -1px var(--page-edge), 6px 4px 0 0 var(--page-edge-line),
    0 26px 36px -20px var(--shadow-strong);
  transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}
.tome-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; border-radius: inherit; }
.tome-cover::before { /* spine crease */
  content: ""; position: absolute; inset: 0 auto 0 0; width: 12px; z-index: 1; border-radius: 3px 0 0 3px;
  background: linear-gradient(90deg, var(--spine), var(--gloss) 55%, transparent);
}
.tome-cover::after { /* soft sheen */
  content: ""; position: absolute; inset: 0; z-index: 1; border-radius: inherit; pointer-events: none;
  background: linear-gradient(115deg, var(--gloss) 0%, transparent 38%);
}
.tome:hover .tome-cover, .tome:focus-visible .tome-cover {
  transform: translateY(-6px) rotate(-.4deg);
  box-shadow:
    3px 2px 0 -1px var(--page-edge), 3px 2px 0 0 var(--page-edge-line),
    6px 4px 0 -1px var(--page-edge), 6px 4px 0 0 var(--page-edge-line),
    0 36px 44px -22px var(--shadow-strong);
}
.tome-blank { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s5); text-align: center; font-family: var(--display); font-size: var(--fs-xl); line-height: 1.1; color: var(--accent); border: 1px solid var(--line); border-radius: inherit; }
.ribbon {
  position: absolute; top: -4px; right: 22px; width: 16px; height: 54px; z-index: 2;
  background: var(--rubric);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
  filter: drop-shadow(0 2px 2px var(--shadow));
}
.tome-series { margin: var(--s5) 0 0; font-size: var(--fs-xs); color: var(--accent); font-weight: 500; }
.tome-series + .tome-title { margin-top: 2px; }
.tome-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-lg); line-height: 1.15; margin: var(--s5) 0 var(--s1); transition: color .2s var(--ease); }
.tome:hover .tome-title { color: var(--accent); }
.tome-meta { color: var(--text-2); font-size: var(--fs-sm); margin: 0; }
.tome-progress { height: 3px; background: var(--surface-3); margin-top: var(--s3); border-radius: 2px; overflow: hidden; }
.tome-progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-fill), var(--accent)); border-radius: 2px; box-shadow: 0 0 8px var(--accent-glow); }
.shelf-empty { font-family: var(--text-face); font-style: italic; color: var(--text-2); font-size: var(--fs-md); }

/* ---------- Reader ---------- */
.reader {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: var(--bar-h) minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}
.bar {
  display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s4); min-width: 0;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--surface), transparent);
  background-color: var(--bg);
}
.bar-back { display: inline-flex; align-items: center; gap: var(--s1); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); padding: 6px 8px 6px 2px; flex: none; border-radius: var(--r-pill); }
.bar-back:hover { color: var(--text); }
.bar-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: var(--s4); justify-content: center; }
.bar-book { font-family: var(--display); font-weight: 600; font-size: var(--fs-lg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar-chapter { font-family: var(--text-face); font-style: italic; color: var(--text-2); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 40%; }
.bar-tools { display: flex; gap: var(--s1); flex: none; align-items: center; }
.tool { text-decoration: none; display: inline-flex; align-items: center; gap: var(--s2); height: 40px; padding: 0 var(--s3); border-radius: var(--r-pill); color: var(--text-2); font-size: var(--fs-sm); transition: color .2s var(--ease), background-color .2s var(--ease); }
.tool.theme-toggle { width: 40px; padding: 0; justify-content: center; }
.tool:hover { color: var(--text); background: var(--surface-2); }
.tool[aria-pressed="true"], .tool[aria-expanded="true"] { color: var(--on-accent); background: var(--accent-fill); }

.stage { position: relative; display: flex; min-height: 0; }
.folio { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; padding: var(--s5) 72px; }
.page { margin: 0; height: 100%; width: 100%; display: flex; align-items: center; justify-content: center; }
.page img {
  max-width: 100%; max-height: 100%; display: block; border-radius: 2px;
  background: var(--surface-2);
  box-shadow: 0 1px 0 var(--line), 0 40px 70px -36px var(--shadow-strong), 0 0 0 1px var(--line);
  animation: page-in .35s var(--ease);
}
@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
.page.is-dream img { filter: saturate(.85); }

/* page without art yet: an unpainted folio */
.unpainted {
  position: relative; height: 100%; max-height: 100%; aspect-ratio: 2 / 3; max-width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s3);
  padding: var(--s6); text-align: center; border-radius: 2px;
  background-color: var(--surface);
  background-image:
    radial-gradient(80% 60% at 50% 40%, var(--bg-glow), transparent 75%),
    repeating-linear-gradient(0deg, transparent 0 27px, var(--accent-soft) 27px 28px);
  box-shadow: 0 0 0 1px var(--line), 0 40px 70px -36px var(--shadow-strong);
  color: var(--text);
}
.unpainted::before { /* double rule frame */
  content: ""; position: absolute; inset: 14px; border: 1px solid var(--line-strong); outline: 1px solid var(--line); outline-offset: 4px; pointer-events: none;
}
.unpainted-n { font-family: var(--display); font-weight: 500; font-size: clamp(88px, 15vh, 168px); line-height: .9; color: var(--accent); }
.unpainted .fleuron { width: 120px; height: 24px; color: var(--accent); opacity: .8; }
.unpainted-ch { font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); color: var(--text); line-height: 1.15; max-width: 22ch; }
.unpainted-note { color: var(--text-2); font-family: var(--text-face); font-style: italic; font-size: var(--fs-sm); max-width: 28ch; margin: 0; }

.turn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 96px; display: grid; place-items: center;
  color: var(--text-2); border-radius: var(--r-pill); z-index: 2;
  transition: color .2s var(--ease), background-color .2s var(--ease);
}
.turn:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.turn:disabled { visibility: hidden; }
.turn svg { width: 28px; height: 28px; }
.turn-prev { left: var(--s3); }
.turn-next { right: var(--s3); }

/* ---------- Transcript leaf ---------- */
.leaf {
  flex: none; width: 410px; max-width: 42vw;
  display: flex; flex-direction: column; min-height: 0;
  background-color: var(--leaf-bg);
  background-image: linear-gradient(170deg, var(--leaf-bg) 30%, var(--leaf-bg-2));
  color: var(--leaf-ink);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 48px -28px var(--shadow-strong);
}
.leaf-grip { display: none; }
.leaf-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s5) var(--s5) var(--s2) var(--s6); }
.leaf-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); margin: 0; color: var(--leaf-ink); }
.leaf-close { color: var(--leaf-ink-2); width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; }
.leaf-close:hover { background: var(--leaf-hl); color: var(--leaf-ink); }
.lines { list-style: none; margin: 0; padding: var(--s2) var(--s5) var(--s7) var(--s6); overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.line {
  position: relative; padding: 10px 12px 10px 16px; margin: 0 0 var(--s1) -16px;
  border-radius: var(--r-sm); cursor: pointer;
  font-family: var(--text-face); font-size: var(--fs-md); line-height: 1.55; color: var(--leaf-ink);
  transition: background-color .25s var(--ease);
}
.line:hover { background: var(--leaf-hl); }
.line::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px;
  background: transparent; transition: background-color .25s var(--ease);
}
.line.is-current { background: var(--leaf-hl); }
.line.is-current::before { background: var(--rubric); }
.line.is-skipped .said, .line.is-skipped .who { color: var(--leaf-ink-2); }
.who {
  display: block; font-family: var(--text-face); font-weight: 700; font-variant: small-caps;
  letter-spacing: .04em; font-size: var(--fs-sm); line-height: 1.2; margin-bottom: 2px;
  color: color-mix(in oklab, var(--voice, var(--rubric)) var(--voice-mix), var(--leaf-ink));
}
.t-caption .said, .t-thought .said { font-style: italic; }
.t-thought .said::before { content: "("; } .t-thought .said::after { content: ")"; }
.t-shout .said { font-weight: 700; }
.t-sfx .said { font-family: var(--display); font-weight: 700; letter-spacing: .12em; color: var(--leaf-ink-2); }
.t-caption .who, .t-sfx .who { color: var(--leaf-ink-2); }
.lines-empty { font-family: var(--text-face); font-style: italic; color: var(--leaf-ink-2); padding: var(--s2) 0; }

/* ---------- Deck ---------- */
.deck {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4) 28px; flex-wrap: wrap;
  padding: var(--s3) var(--s5) calc(var(--s3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background-color: var(--bg);
  background-image: linear-gradient(transparent, var(--surface));
}
.listen { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.play {
  width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-fill); color: var(--on-accent);
  box-shadow: 0 6px 18px -8px var(--accent-glow);
  transition: background-color .2s var(--ease), transform .2s var(--ease);
}
.play:hover { background: var(--accent-fill-hover); }
.play:active { transform: scale(.96); }
.play svg { width: 24px; height: 24px; }
.reader[data-play="playing"] .play { box-shadow: 0 0 0 6px var(--accent-soft), 0 6px 18px -8px var(--accent-glow); }
.stop { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); flex: none; }
.stop:hover { color: var(--text); background: var(--surface-2); }
.mode { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-pill); padding: 3px; margin-left: 6px; flex: none; background: var(--surface); }
.mode-opt { padding: 6px 14px; border-radius: var(--r-pill); font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; transition: color .2s var(--ease), background-color .2s var(--ease); }
.mode-opt:hover { color: var(--text); }
.mode-opt[aria-checked="true"] { background: var(--surface-3); color: var(--text); }
.now { margin: 0 0 0 var(--s2); font-family: var(--text-face); font-style: italic; color: var(--text-2); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.nav { display: flex; align-items: center; gap: 14px; flex: 0 1 380px; min-width: 220px; }
.count { font-family: var(--display); font-weight: 600; font-size: var(--fs-lg); white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }
.count-of { color: var(--text-2); font-weight: 500; }

input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; width: 100%; height: 28px; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--surface-3); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6.5px; border-radius: 50%; background: var(--accent-fill); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--accent); }
input[type="range"]::-moz-range-track { height: 3px; background: var(--surface-3); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent-fill); border: 2px solid var(--bg); }
input[type="range"]:disabled { opacity: .4; }
.scrub { flex: 1; min-width: 0; }

/* ---------- Settings ---------- */
.settings {
  position: fixed; top: calc(var(--bar-h) + var(--s2)); right: var(--s4); z-index: 20;
  width: min(330px, calc(100vw - 32px)); max-height: calc(100dvh - var(--bar-h) - 24px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s5) var(--s5) var(--s4); box-shadow: 0 30px 60px -24px var(--shadow-strong);
  animation: pop .18s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.settings-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); margin: 0 0 var(--s3); }
.settings-sub { font-family: var(--display); font-weight: 600; font-size: var(--fs-lg); margin: var(--s2) 0 var(--s3); padding-top: var(--s4); border-top: 1px solid var(--line); }
.setting { border: 0; padding: 0; margin: 0 0 var(--s4); display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-sm); min-width: 0; }
.setting legend { color: var(--text-2); margin-bottom: 6px; padding: 0; }
.setting label { display: flex; align-items: center; gap: var(--s2); }
.setting input[type="radio"] { accent-color: var(--accent); }
.setting-range span { display: flex; justify-content: space-between; color: var(--text-2); }
.setting-range output { color: var(--text); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 3px; background: var(--bg); }
.seg label { position: relative; justify-content: center; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; width: 100%; text-align: center; padding: 5px 0; border-radius: var(--r-pill); color: var(--text-2); }
.seg input:checked + span { background: var(--surface-3); color: var(--text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.settings-note { color: var(--text-2); font-size: var(--fs-xs); margin: var(--s1) 0 0; line-height: 1.45; }

/* ---------- Book page ---------- */
.bookpage { max-width: 1200px; margin: 0 auto; padding: var(--s5) var(--s6) 96px; }
.pagebar { display: flex; align-items: center; justify-content: space-between; }
.crumb { display: inline-flex; align-items: center; gap: var(--s1); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); padding: 6px 10px 6px 0; border-radius: var(--r-pill); }
.crumb:hover { color: var(--text); }
.book-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 72px; margin-top: var(--s5); align-items: start; }
.book-head { position: sticky; top: var(--s5); }
.book-cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 3px 7px 7px 3px; background: var(--surface-2);
  box-shadow:
    3px 2px 0 -1px var(--page-edge), 3px 2px 0 0 var(--page-edge-line),
    6px 4px 0 -1px var(--page-edge), 6px 4px 0 0 var(--page-edge-line),
    0 30px 44px -24px var(--shadow-strong);
}
.book-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; border-radius: inherit; }
.book-cover { overflow: hidden; }
.book-cover .tome-blank { font-size: var(--fs-lg); padding: var(--s4); overflow-wrap: anywhere; }
.book-cover::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 12px; z-index: 1; border-radius: 3px 0 0 3px; background: linear-gradient(90deg, var(--spine), var(--gloss) 55%, transparent); }
.book-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); line-height: 1.06; margin: var(--s5) 0 var(--s2); text-wrap: balance; }
.book-credit { color: var(--text-2); font-size: var(--fs-sm); margin: 0 0 var(--s4); }
.book-progress { font-family: var(--text-face); font-style: italic; color: var(--text); font-size: var(--fs-md); margin: 0 0 var(--s5); }
.book-facts { margin: 0 0 var(--s5); display: grid; gap: var(--s1) 0; font-size: var(--fs-sm); }
.book-facts dt { color: var(--text-2); font-weight: 500; margin-top: var(--s2); }
.book-facts dt:first-child { margin-top: 0; }
.book-facts dd { margin: 0; color: var(--text); font-family: var(--text-face); line-height: 1.45; }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 26px;
  border-radius: var(--r-pill); background: var(--accent-fill); color: var(--on-accent);
  text-decoration: none; font-weight: 700; font-size: var(--fs-md);
  box-shadow: 0 8px 22px -10px var(--accent-glow);
  transition: background-color .2s var(--ease), transform .2s var(--ease);
}
.btn-primary:hover { background: var(--accent-fill-hover); transform: translateY(-1px); }
.tabs { display: flex; gap: var(--s6); border-bottom: 1px solid var(--line); margin-bottom: var(--s6); }
.tab { font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); color: var(--text-2); text-decoration: none; padding: var(--s1) 0 var(--s3); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .2s var(--ease), border-color .2s var(--ease); }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Story tree ---------- */
.k-main { --kc: var(--k-main); }
.k-side { --kc: var(--k-side); }
.k-whatif { --kc: var(--k-whatif); }
.s-placeholder { --kc-line: var(--k-muted); }

.tree-legend { display: flex; flex-wrap: wrap; gap: var(--s2) 22px; color: var(--text-2); font-size: var(--fs-sm); margin: 0 0 var(--s6); }
.legend-item { display: inline-flex; align-items: center; gap: var(--s2); }
.legend-item svg { width: 18px; height: 18px; }

.tree-rows { list-style: none; margin: 0; padding: 0; }
.tnode { --row-i: 0; position: relative; min-height: 104px; padding: 0 0 var(--s5) 58px; }
.tnode:not(.k-main) { min-height: 132px; padding-left: 108px; padding-top: 16px; padding-bottom: 60px; }
.tnode.end-deadend, .tnode.end-continue { padding-bottom: 36px; }

/* trunk: a lit gilt line with a soft glow, dim where unread */
.rail-trunk { position: absolute; left: 23px; top: 0; bottom: 0; width: 3px; border-radius: 2px; background: linear-gradient(var(--line-strong), var(--line)); transform-origin: top; }
.rail-trunk.is-lit { background: linear-gradient(var(--accent), var(--accent-fill)); box-shadow: 0 0 10px var(--accent-glow), 0 0 2px var(--accent-glow); }
.rail-trunk.from-marker { top: 34px; }
.rail-trunk.to-marker { bottom: auto; height: 34px; }
.rail-trunk.stub { display: none; }
.rail-art { position: absolute; left: 0; top: 0; width: 140px; height: 120px; overflow: visible; pointer-events: none; }
.rail-tail { position: absolute; left: 0; bottom: 0; width: 140px; height: 60px; overflow: visible; pointer-events: none; }
.branch { fill: none; stroke: var(--kc-line, var(--kc)); stroke-width: 2.25; stroke-linecap: round; }
.branch-glow { fill: none; stroke: var(--kc); stroke-width: 6; stroke-linecap: round; opacity: .16; }
.s-placeholder .branch { stroke-dasharray: 1.5 6; }
.s-placeholder .branch-glow { display: none; }
.junction { fill: var(--bg); stroke: var(--kc-line, var(--kc)); stroke-width: 2; }
.seed { fill: var(--accent); }
.rail-lane { position: absolute; left: 75px; top: 84px; bottom: 60px; width: 2.25px; border-radius: 2px; background: var(--kc-line, var(--kc)); transform-origin: top; }
.end-continue .rail-lane { bottom: 0; background: linear-gradient(var(--kc-line, var(--kc)), transparent); }
.end-deadend .rail-lane { bottom: auto; height: 22px; }
.rail-stop { position: absolute; left: 67px; top: 106px; width: 18px; height: 2.25px; border-radius: 2px; background: var(--kc-line, var(--kc)); }
.s-placeholder .rail-lane { background: repeating-linear-gradient(var(--k-muted) 0 2px, transparent 2px 8px); }
.s-placeholder.end-continue .rail-lane { background: repeating-linear-gradient(var(--k-muted) 0 2px, transparent 2px 8px); -webkit-mask-image: linear-gradient(#000, transparent); mask-image: linear-gradient(#000, transparent); }

.marker { transform-box: fill-box; transform-origin: center; transition: transform .25s var(--ease); }
.marker-halo { fill: var(--accent-soft); stroke: none; }
.marker-shape { fill: var(--bg); stroke: var(--kc); stroke-width: 2; transition: fill .25s var(--ease); }
.marker-core { fill: var(--kc); }
.is-read .marker-shape { fill: var(--kc); }
.marker-track { fill: none; stroke: var(--line); stroke-width: 2.5; }
.marker-arc { fill: none; stroke: var(--kc); stroke-width: 2.5; stroke-linecap: round; filter: drop-shadow(0 0 3px var(--accent-glow)); }
.s-placeholder .marker-shape { fill: var(--bg); stroke: var(--k-muted); stroke-dasharray: 3 3; }
.is-current .marker-halo { animation: halo 2.6s var(--ease) 1.2s 2 both; }
@keyframes halo { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.tnode:hover .marker, .tnode:focus-within .marker { transform: scale(1.12); }
.s-placeholder:hover .marker { transform: none; }

.tnode-body { position: relative; display: block; padding: var(--s3) var(--s4) var(--s3); margin-left: -16px; border-radius: var(--r-md); color: inherit; text-decoration: none; max-width: 64ch; transition: background-color .2s var(--ease); }
a.tnode-body:hover { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
a.tnode-body:focus-visible { outline-offset: 0; }
.tnode-kind { display: block; font-size: var(--fs-sm); color: var(--kc); line-height: 1.3; font-weight: 500; }
.tnode-title { display: block; font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); line-height: 1.12; margin: 2px 0 var(--s1); color: var(--text); transition: color .2s var(--ease); }
a.tnode-body:hover .tnode-title { color: var(--accent); }
.tnode:not(.k-main) .tnode-title { font-size: 1.375rem; }
.tnode-meta { display: block; font-size: var(--fs-sm); color: var(--text-2); }
.is-current .tnode-meta { color: var(--accent); font-weight: 500; }
.tnode-summary { display: block; font-family: var(--text-face); font-style: italic; font-size: var(--fs-md); line-height: 1.5; color: var(--text-2); margin-top: var(--s2); }
.s-placeholder .tnode-body { cursor: default; }
.s-placeholder .tnode-title { color: var(--text-2); font-style: italic; }
.s-placeholder .tnode-kind { color: var(--text-2); }
.s-placeholder .tnode-meta { font-style: italic; }

/* draw-in on load */
.tree-rows.is-drawing .rail-trunk { animation: grow-y .45s var(--ease) both; animation-delay: calc(var(--row-i) * 70ms); }
.tree-rows.is-drawing .rail-lane { animation: grow-y .35s var(--ease) both; animation-delay: calc(var(--row-i) * 70ms + 380ms); }
.tree-rows.is-drawing .branch.draws { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .5s var(--ease) forwards; animation-delay: calc(var(--row-i) * 70ms + 120ms); }
.tree-rows.is-drawing .rail-tail .branch.draws { animation-delay: calc(var(--row-i) * 70ms + 560ms); }
.tree-rows.is-drawing .marker, .tree-rows.is-drawing .junction, .tree-rows.is-drawing .rail-stop, .tree-rows.is-drawing .branch-glow { animation: fade-in .4s var(--ease) both; animation-delay: calc(var(--row-i) * 70ms + 240ms); }
.tree-rows.is-drawing .tnode-body { animation: rise .5s var(--ease) both; animation-delay: calc(var(--row-i) * 70ms + 140ms); }
.tree-rows.is-drawing .s-placeholder .branch { animation: fade-in .5s var(--ease) both; animation-delay: calc(var(--row-i) * 70ms + 160ms); }
@keyframes grow-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Codex ---------- */
.codex-nav {
  position: sticky; top: 0; z-index: 3; display: flex; flex-wrap: wrap; gap: var(--s2);
  padding: var(--s3) 0; margin-top: -12px;
  background-color: var(--bg);
  box-shadow: 0 10px 14px -12px var(--shadow);
}
.codex-jump { display: inline-flex; align-items: center; gap: var(--s2); padding: 6px 14px; border: 1px solid var(--line); border-radius: var(--r-pill); color: var(--text); text-decoration: none; font-size: var(--fs-sm); background: var(--surface); transition: border-color .2s var(--ease), background-color .2s var(--ease); }
.codex-jump:hover { border-color: var(--accent); }
.codex-count { color: var(--text-2); font-size: var(--fs-xs); }
.codex-section { scroll-margin-top: 72px; margin-top: var(--s6); }
.codex-heading { display: flex; align-items: center; gap: var(--s4); font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); margin: 0 0 var(--s4); }
.codex-heading::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); }
.codex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; }
.codex-card {
  display: flex; flex-direction: column; text-align: left; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); overflow: hidden; box-shadow: 0 14px 24px -20px var(--shadow-strong);
  transition: border-color .2s var(--ease), transform .25s var(--ease), box-shadow .25s var(--ease);
}
.codex-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 22px 30px -20px var(--shadow-strong); }
.codex-img { display: block; position: relative; aspect-ratio: 4 / 5; overflow: hidden; background-color: var(--surface-2); background-image: radial-gradient(90% 70% at 50% 45%, var(--surface), var(--surface-2)); }
.codex-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; transition: transform .4s var(--ease); }
.codex-card:hover .codex-img img { transform: scale(1.03); }
.codex-missing { display: grid; place-items: center; height: 100%; color: var(--text-2); font-style: italic; font-size: var(--fs-sm); }
.codex-name { font-family: var(--display); font-weight: 600; font-size: 1.1875rem; line-height: 1.15; padding: var(--s3) var(--s3) 2px; color: var(--text); }
.codex-desc { font-size: var(--fs-xs); line-height: 1.45; color: var(--text-2); padding: 0; margin: 2px var(--s3) var(--s3); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.codex-empty { font-family: var(--text-face); font-style: italic; color: var(--text-2); }

/* ---------- Dialogs ---------- */
dialog { color: inherit; border: 0; padding: 0; }
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(4px); }
dialog[open] { animation: dialog-in .22s var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.lightbox { width: min(1120px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: auto; box-shadow: 0 40px 80px -30px var(--shadow-strong); }
.lightbox[open] { display: grid; grid-template-columns: minmax(0, 1fr) 330px; }
.lightbox img { width: 100%; height: min(78vh, 820px); object-fit: contain; background: var(--surface-2); display: block; }
.lb-text { padding: var(--s6) var(--s5); }
.lb-name { font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); line-height: 1.08; margin: 0 40px var(--s2) 0; }
.lb-cat { color: var(--accent); font-size: var(--fs-sm); margin: 0 0 var(--s4); font-weight: 500; }
.lb-desc { font-family: var(--text-face); font-size: var(--fs-md); line-height: 1.55; margin: 0 0 var(--s4); }
.lb-meta { color: var(--text-2); font-size: var(--fs-sm); margin: 0 0 var(--s3); overflow-wrap: anywhere; }
.lb-source { color: var(--text); font-size: var(--fs-sm); text-underline-offset: 3px; }
.lb-source:hover { color: var(--accent); }
.lb-close { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--text-2); background: var(--surface); z-index: 1; box-shadow: 0 0 0 1px var(--line); }
.lb-close:hover { color: var(--text); }

.choice {
  width: min(580px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  padding: var(--s6) var(--s6) var(--s5); border-radius: var(--r-lg); color: var(--leaf-ink);
  background-color: var(--leaf-bg);
  background-image: linear-gradient(170deg, var(--leaf-bg) 30%, var(--leaf-bg-2));
  border: 1px solid var(--line);
  box-shadow: 0 40px 80px -30px var(--shadow-strong);
}
.choice-done { font-family: var(--text-face); font-style: italic; color: var(--leaf-ink-2); margin: 0 0 2px; }
.choice-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); line-height: 1.1; margin: 0 0 var(--s5); }
.choice-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.choice-opt {
  display: block; width: 100%; text-align: left; padding: 14px 18px 15px 20px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--kc);
  transition: background-color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
}
.choice-opt:hover:not(:disabled) { background: var(--surface-2); transform: translateX(2px); box-shadow: 0 10px 20px -16px var(--shadow-strong); }
.choice-opt:disabled { cursor: default; border-style: dashed; border-left-color: var(--k-muted); background: transparent; }
.choice-kind { display: block; font-size: var(--fs-sm); color: var(--kc); font-weight: 700; }
.choice-opt:disabled .choice-kind, .choice-opt:disabled .choice-name { color: var(--leaf-ink-2); }
.choice-name { display: block; font-family: var(--display); font-weight: 600; font-size: 1.4375rem; line-height: 1.15; color: var(--leaf-ink); margin: 2px 0; }
.choice-note { display: block; font-family: var(--text-face); font-style: italic; font-size: var(--fs-sm); line-height: 1.45; color: var(--leaf-ink-2); }
.choice-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin-top: var(--s5); flex-wrap: wrap; }
.choice-tree { color: var(--rubric); font-size: var(--fs-sm); text-underline-offset: 3px; }
.choice-stay { font-size: var(--fs-sm); color: var(--leaf-ink-2); padding: var(--s2) var(--s1); }
.choice-stay:hover { color: var(--leaf-ink); }


/* ---------- Shared controls ---------- */
.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; }
.link-btn { color: var(--accent); font-size: var(--fs-sm); text-decoration: underline; text-underline-offset: 3px; padding: 2px 0; }
.link-btn:hover { color: var(--text); }
.btn-block { width: 100%; }
.btn-primary:disabled { opacity: .6; cursor: progress; }
button.btn-primary { border: 0; cursor: pointer; }
.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 18px;
  border-radius: var(--r-pill); border: 1px solid var(--line-strong); color: var(--text); background: var(--surface);
  text-decoration: none; font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
  transition: border-color .2s var(--ease), background-color .2s var(--ease);
}
.btn-secondary:hover { border-color: var(--accent); background: var(--surface-2); }
.btn-quiet { color: var(--text-2); font-size: var(--fs-sm); padding: var(--s2) var(--s1); }
.btn-quiet:hover { color: var(--text); }
.form { display: grid; gap: var(--s4); }
.field { display: grid; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.field input, .field textarea, .field select {
  font: inherit; font-size: var(--fs-md); color: var(--text); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: 10px 12px; width: 100%; min-width: 0;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.field textarea { resize: vertical; min-height: 84px; font-family: var(--text-face); line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-inline { display: inline-flex; align-items: center; gap: var(--s2); max-width: 100%; min-width: 0; }
/* sized by its longest option (a 61-character title), so it has to be allowed to shrink */
.field-inline select { width: auto; max-width: 100%; flex: 0 1 auto; padding: 8px 10px; font-size: var(--fs-sm); text-overflow: ellipsis; }
.field-hint { margin: -8px 0 0; color: var(--text-2); font-size: var(--fs-xs); }
.form-error { margin: 0; color: var(--rubric); font-size: var(--fs-sm); font-weight: 500; }
.form-ok { margin: 0; color: var(--k-side); font-size: var(--fs-sm); font-weight: 500; }
.empty-note { list-style: none; color: var(--text-2); font-family: var(--text-face); font-style: italic; font-size: var(--fs-sm); }

.stars-static { display: inline-flex; gap: 2px; color: var(--accent); vertical-align: middle; }
.stars-static svg { width: 16px; height: 16px; fill: none; color: var(--line-strong); }
.stars-static svg.on { fill: var(--accent-fill); color: var(--accent); }
.tool.is-rated svg { fill: var(--accent-fill); color: var(--accent); }

.user-link { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px 0 8px; border-radius: var(--r-pill); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); transition: color .2s var(--ease), background-color .2s var(--ease); }
.user-link:hover { color: var(--text); background: var(--surface-2); }
.corner { display: flex; align-items: center; gap: var(--s1); }
.pagebar-tools { display: flex; align-items: center; gap: var(--s1); }

.seal {
  position: absolute; left: 12px; bottom: 12px; z-index: 2;
  padding: 4px 12px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700;
  color: var(--on-accent); background: var(--accent-fill); box-shadow: 0 4px 10px -4px var(--shadow-strong);
}
.tome-stars { margin: 2px 0 4px; }
.my-rating { display: flex; align-items: center; gap: var(--s3); margin: calc(-1 * var(--s3)) 0 var(--s5); flex-wrap: wrap; }

/* ---------- Sign in ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--s6) var(--s4); }
.auth-card {
  width: min(420px, 100%); padding: var(--s7) var(--s6) var(--s6);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: 0 40px 80px -40px var(--shadow-strong);
}
.auth-mark { font-size: clamp(3rem, 12vw, 4.25rem); text-align: center; }
.auth-lede { text-align: center; font-family: var(--text-face); font-style: italic; color: var(--text-2); margin: var(--s3) 0 var(--s6); }
.auth-sso { display: grid; gap: var(--s4); margin-bottom: var(--s4); }
.auth-or { display: flex; align-items: center; gap: var(--s3); margin: var(--s2) 0 0; color: var(--text-2); font-size: var(--fs-sm); }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-sso-error { text-align: center; margin-bottom: var(--s4); }
.auth-switch { text-align: center; color: var(--text-2); font-size: var(--fs-sm); margin: var(--s5) 0 0; }

/* ---------- Profile ---------- */
.profile, .redo { max-width: 1120px; margin: 0 auto; padding: var(--s5) var(--s6) 96px; }
.profile-head, .redo-head { margin: var(--s6) 0 var(--s6); }
.profile-name { font-family: var(--display); font-weight: 600; font-size: clamp(2.5rem, 6vw, 3.75rem); line-height: 1; margin: 0; }
.profile-sub { color: var(--text-2); font-family: var(--text-face); font-style: italic; font-size: var(--fs-md); margin: var(--s2) 0 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); margin: 0 0 var(--s6); }
.stat { margin: 0; padding: var(--s5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: var(--s1); }
.stat-n { margin: 0; font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); line-height: 1; color: var(--accent); font-variant-numeric: lining-nums; }
.stat-label { color: var(--text-2); font-size: var(--fs-sm); }
.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s5); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s5) var(--s5) var(--s5); min-width: 0; }
.panel-wide { grid-column: 1 / -1; }
.panel-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); margin: 0 0 var(--s4); }
.panel .setting { margin-bottom: var(--s4); }
.setting-label { color: var(--text-2); font-size: var(--fs-sm); }
.panel .seg { max-width: 360px; }
.seg[role="radiogroup"]:has(label:nth-child(2):last-child) { grid-template-columns: repeat(2, 1fr); }
.fav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); counter-reset: fav; }
.fav { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.fav:last-child { border-bottom: 0; }
.fav-label { color: var(--text); text-decoration: none; font-family: var(--display); font-weight: 600; font-size: var(--fs-lg); line-height: 1.2; min-width: 0; }
.fav-label:hover { color: var(--accent); }
.feedback-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.fb-item { padding: var(--s4) 0; border-bottom: 1px solid var(--line); display: grid; gap: var(--s2); }
.fb-item:last-child { border-bottom: 0; }
.fb-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.fb-label { color: var(--text); font-weight: 500; text-decoration: none; }
.fb-label:hover { color: var(--accent); }
.fb-text { margin: 0; font-family: var(--text-face); color: var(--text); line-height: 1.5; }
.fb-edit { justify-self: start; }
.fb-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs); border: 1px solid var(--line-strong); color: var(--text-2); background: var(--bg); }
.chip.is-negative { color: var(--rubric); border-color: var(--rubric); }
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s4); }
.switch { display: inline-flex; align-items: center; gap: var(--s3); cursor: pointer; font-size: var(--fs-sm); color: var(--text); position: relative; }
.switch input { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.switch-track { width: 44px; height: 26px; border-radius: 13px; background: var(--surface-3); border: 1px solid var(--line-strong); position: relative; flex: none; transition: background-color .2s var(--ease); }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-2); transition: transform .2s var(--ease), background-color .2s var(--ease); }
.switch input:checked + .switch-track { background: var(--accent-fill); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: var(--on-accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.table-wrap { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.users-table th, .users-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.users-table thead th { color: var(--text-2); font-weight: 500; }
.users-table tbody th { font-weight: 700; }
#btn-logout { margin-top: var(--s4); }

.notice { margin: 0 0 var(--s4); padding: var(--s3) var(--s4); border-radius: var(--r-md); border: 1px solid var(--accent); background: var(--accent-soft); color: var(--text); font-size: var(--fs-sm); }
.form-tight { margin-bottom: var(--s5); padding-bottom: var(--s5); border-bottom: 1px solid var(--line); }
.creds-note { margin: 0; font-family: var(--text-face); line-height: 1.5; color: var(--leaf-ink); }
.rate .field-hint { color: var(--leaf-ink-2); margin-top: -8px; }

/* ---------- Needs redo ---------- */
.redo-tools { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s6); }
.redo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s5); }
.redo-item { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--s5); padding: var(--s4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.redo-img { display: block; position: relative; aspect-ratio: 2 / 3; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); box-shadow: 0 0 0 1px var(--line); }
.redo-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.redo-body { display: grid; gap: var(--s2); align-content: start; min-width: 0; }
.redo-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); margin: 0; line-height: 1.1; }
.redo-meta { margin: 0; color: var(--text-2); font-size: var(--fs-sm); }
.redo-score { display: flex; align-items: center; gap: var(--s2); color: var(--text); font-size: var(--fs-sm); }
.redo-notes { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; gap: var(--s3); }
.redo-notes li { display: grid; gap: 2px; padding-left: var(--s3); border-left: 2px solid var(--line-strong); }
.redo-note-who { color: var(--text-2); font-size: var(--fs-xs); }
.redo-note-text { font-family: var(--text-face); color: var(--text); }

/* ---------- Rating dialog ---------- */
.rate {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  padding: var(--s6) var(--s6) var(--s5); border-radius: var(--r-lg); color: var(--leaf-ink);
  background-color: var(--leaf-bg); background-image: linear-gradient(170deg, var(--leaf-bg) 30%, var(--leaf-bg-2));
  border: 1px solid var(--line); box-shadow: 0 40px 80px -30px var(--shadow-strong);
}
.rate form { display: grid; gap: var(--s4); }
.rate-sub { margin: 0 0 -10px; font-family: var(--text-face); font-style: italic; color: var(--leaf-ink-2); }
.rate-title { margin: 0; font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); line-height: 1.1; }
.stars { border: 0; margin: 0; padding: 0; display: flex; gap: 4px; }
.stars label { position: relative; cursor: pointer; width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--r-md); color: var(--line-strong); }
.stars input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.stars svg { width: 34px; height: 34px; fill: none; transition: transform .15s var(--ease), fill .15s var(--ease), color .15s var(--ease); }
.stars label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 0; }
/* fill up to the checked star, or to the hovered one while pointing */
.stars:has(input[value="1"]:checked) label:nth-of-type(-n+1) svg,
.stars:has(input[value="2"]:checked) label:nth-of-type(-n+2) svg,
.stars:has(input[value="3"]:checked) label:nth-of-type(-n+3) svg,
.stars:has(input[value="4"]:checked) label:nth-of-type(-n+4) svg,
.stars:has(input[value="5"]:checked) label:nth-of-type(-n+5) svg { fill: var(--accent-fill); color: var(--accent); }
@media (hover: hover) {
  .stars:hover label svg { fill: none; color: var(--line-strong); }
  .stars label:hover svg, .stars label:has(~ label:hover) svg { fill: var(--accent-fill); color: var(--accent); transform: scale(1.06); }
}
.tagset { border: 0; margin: 0; padding: 0; }
.tagset legend { padding: 0; margin-bottom: var(--s2); color: var(--leaf-ink-2); font-size: var(--fs-sm); }
.tag-list { display: flex; flex-wrap: wrap; gap: var(--s2); }
.tag { position: relative; cursor: pointer; }
.tag input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tag span { display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--line-strong); color: var(--leaf-ink); background: var(--surface); font-size: var(--fs-sm); transition: background-color .15s var(--ease), border-color .15s var(--ease); }
.tag:hover span { border-color: var(--accent); }
.tag input:checked + span { background: var(--accent-fill); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
.tag.is-negative input:checked + span { background: var(--rubric); border-color: var(--rubric); color: var(--leaf-bg); }
.tag input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.rate .field { color: var(--leaf-ink-2); }
.rate .field textarea { background: var(--surface); color: var(--leaf-ink); }
.rate .form-error { color: var(--rubric); }
.rate-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); }
.rate-foot .btn-quiet { color: var(--leaf-ink-2); }

@media (max-width: 899px) {
  .profile, .redo { padding: var(--s3) var(--s4) 72px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  .stat { padding: var(--s4); }
  .stat-n { font-size: var(--fs-xl); }
  .profile-grid { grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
  .panel { padding: var(--s4); }
  .redo-item { grid-template-columns: 96px minmax(0, 1fr); gap: var(--s4); padding: var(--s3); }
  .rate { padding: var(--s5) 20px var(--s4); }
  .rate-title { font-size: var(--fs-xl); }
  .stars label { width: 44px; height: 44px; }
  .auth-card { padding: var(--s6) var(--s5) var(--s5); }
  .reader .bar-tools .theme-toggle { display: none; }
  .user-link .user-name { display: none; }
  .user-link { padding: 0; width: 40px; justify-content: center; }
}


/* ---------- Default-password banner ---------- */
.cred-banner {
  display: flex; align-items: center; justify-content: center; gap: var(--s3); flex-wrap: wrap;
  padding: 10px var(--s4); font-size: var(--fs-sm); text-align: center;
  background: var(--rubric); color: var(--leaf-bg);
}
.cred-banner a { color: var(--leaf-bg); font-weight: 700; text-underline-offset: 3px; }
body[data-view="reader"] .cred-banner, body[data-view="auth"] .cred-banner { display: none; }

/* ---------- Planned shelf and typographic covers ---------- */
.planned { margin-top: 88px; padding-top: var(--s6); border-top: 1px solid var(--line); }
.shelf-heading { font-family: var(--display); font-weight: 600; font-size: var(--fs-2xl); margin: 0; }
.shelf-note { font-family: var(--text-face); font-style: italic; color: var(--text-2); margin: var(--s1) 0 var(--s6); }
.planned-series + .planned-series { margin-top: var(--s7); }
.planned-series-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-xl); margin: 0 0 var(--s4); color: var(--text); }
.shelf-planned { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 40px 28px; }
.tome-planned .tome-title { font-size: var(--fs-md); }
.type-cover {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
  padding: var(--s5) var(--s4); text-align: center; overflow: hidden;
  color: var(--text); border: 1px solid var(--line);
  background-color: var(--surface);
}
.type-cover::after { opacity: .5; }
.type-cover.v0 { background-image: radial-gradient(90% 70% at 50% 30%, color-mix(in oklab, var(--accent-fill) 22%, var(--surface)), var(--surface-2)); }
.type-cover.v1 { background-image: radial-gradient(90% 70% at 50% 30%, color-mix(in oklab, var(--rubric) 18%, var(--surface)), var(--surface-2)); }
.type-cover.v2 { background-image: radial-gradient(90% 70% at 50% 30%, color-mix(in oklab, var(--k-side) 20%, var(--surface)), var(--surface-2)); }
.type-cover.v3 { background-image: radial-gradient(90% 70% at 50% 30%, color-mix(in oklab, var(--k-whatif) 18%, var(--surface)), var(--surface-2)); }
.type-series { font-size: var(--fs-xs); color: var(--accent); font-weight: 700; position: relative; z-index: 2; max-width: 100%; }
.type-rule { width: 40px; height: 1px; background: var(--line-strong); position: relative; z-index: 2; }
.type-title { font-family: var(--display); font-weight: 600; font-size: var(--fs-lg); line-height: 1.12; position: relative; z-index: 2; overflow-wrap: anywhere; text-wrap: balance; }
.type-order { font-family: var(--text-face); font-style: italic; font-size: var(--fs-sm); color: var(--text-2); position: relative; z-index: 2; }
.planned-tag {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 3;
  padding: 3px 12px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700;
  color: var(--text); background: var(--bg); border: 1px dashed var(--line-strong); white-space: nowrap;
}
.book-type-cover { position: absolute; inset: 0; border-radius: inherit; }
.planned-badge {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 20px; margin: 0;
  border-radius: var(--r-pill); border: 1px dashed var(--line-strong); color: var(--text); font-weight: 700; font-size: var(--fs-sm);
}
@media (max-width: 899px) {
  .book-type-cover { padding: var(--s2); gap: 4px; }
  .book-type-cover .type-title { font-size: var(--fs-sm); }
  .book-type-cover .type-series, .book-type-cover .type-order { font-size: 0.6875rem; }
  .shelf-planned { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 16px; }
  .planned { margin-top: 56px; }
}


/* ---------- What-if requests ---------- */
.tree-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3) var(--s5); flex-wrap: wrap; margin-bottom: var(--s6); }
.tree-head .tree-legend { margin: 0; }
.req-toggle { font-size: var(--fs-sm); color: var(--text-2); }
.tnode-action {
  display: inline-flex; align-items: center; gap: 6px; margin: 2px 0 0; padding: 4px 10px 4px 6px;
  border-radius: var(--r-pill); font-size: var(--fs-xs); color: var(--text-2);
  opacity: 0; transition: opacity .2s var(--ease), color .2s var(--ease), background-color .2s var(--ease);
}
.tnode-action svg { width: 16px; height: 16px; }
.tnode:hover .tnode-action, .tnode:focus-within .tnode-action, .tnode-action:focus-visible { opacity: 1; }
.tnode-action:hover { color: var(--text); background: var(--surface-2); }
@media (hover: none) { .tnode-action { opacity: 1; } }
.sprouts { list-style: none; margin: var(--s1) 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sprouts:empty { display: none; }
.sprout {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 8px;
  border: 1px dashed var(--line-strong); border-radius: var(--r-pill);
  font-size: var(--fs-xs); color: var(--text-2); background: transparent;
}
.sprout svg { width: 16px; height: 16px; color: var(--accent); }
.sprout::before { /* dashed shoot back to the trunk */
  content: ""; position: absolute; right: 100%; top: 50%; width: 22px; border-top: 1.5px dashed var(--line-strong);
}
.tnode.k-main .sprout::before { width: 26px; }
.sprout:hover, .sprout:focus-visible { color: var(--text); border-color: var(--accent); }
.sprout-tip {
  position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 5; width: max-content; max-width: 280px;
  padding: 6px 10px; border-radius: var(--r-md); background: var(--text); color: var(--bg);
  font-size: var(--fs-sm); line-height: 1.35; white-space: normal; text-align: left;
  opacity: 0; transform: translateY(2px); pointer-events: none; transition: opacity .15s var(--ease), transform .15s var(--ease);
}
.sprout:hover .sprout-tip, .sprout:focus-visible .sprout-tip { opacity: 1; transform: none; }

.wi-dialog { width: min(640px, calc(100vw - 32px)); }
.wi-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--s3); }
.field-error { margin: -10px 0 0; color: var(--rubric); font-size: var(--fs-sm); font-weight: 500; }
.wi-dialog .setting { margin: 0; }
.wi-dialog .setting legend { color: var(--leaf-ink-2); }
.wi-dialog .seg { background: var(--surface); }
.wi-dialog .seg span { color: var(--leaf-ink-2); font-size: var(--fs-sm); }
.wi-dialog .seg input:checked + span { color: var(--leaf-ink); }
.wi-dialog .seg input:disabled + span { opacity: .45; cursor: not-allowed; }
.seg-4 { grid-template-columns: repeat(4, 1fr); }
.wi-dialog .field select { background: var(--surface); color: var(--leaf-ink); }
.wi-dialog .field input { background: var(--surface); color: var(--leaf-ink); }
.wi-done { display: grid; gap: var(--s4); }
.wi-facts { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s4); font-size: var(--fs-sm); }
.wi-facts dt { color: var(--leaf-ink-2); }
.wi-facts dd { margin: 0; font-family: var(--text-face); }

.wi-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.wi-admin-list { gap: var(--s4); }
.wi-item { padding: var(--s4) 0; border-bottom: 1px solid var(--line); display: grid; gap: var(--s2); }
.wi-item:last-child { border-bottom: 0; }
.wi-admin-item { padding: var(--s5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.wi-admin-item:last-child { border-bottom: 1px solid var(--line); }
.wi-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.wi-name { font-family: var(--display); font-weight: 600; font-size: var(--fs-lg); line-height: 1.2; }
.wi-where { margin: 0; color: var(--text-2); font-size: var(--fs-sm); }
.wi-premise { margin: 0; font-family: var(--text-face); line-height: 1.5; }
.wi-review { margin: 0; font-size: var(--fs-sm); color: var(--text-2); font-style: italic; }
.wi-actions { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.wi-confirm { font-size: var(--fs-sm); color: var(--text); }
.wi-danger { color: var(--rubric); }
.chip.st { font-weight: 700; }
.chip.st-approved { color: var(--k-side); border-color: var(--k-side); }
.chip.st-in_progress { color: var(--accent); border-color: var(--accent); }
.chip.st-done { color: var(--on-accent); background: var(--accent-fill); border-color: var(--accent); }
.chip.st-declined { color: var(--text-2); border-style: dashed; }
.admin-links { display: inline-flex; gap: var(--s2); flex-wrap: wrap; }
@media (max-width: 899px) {
  .wi-grid { grid-template-columns: minmax(0, 1fr); }
  .seg-4 { grid-template-columns: repeat(2, 1fr); border-radius: var(--r-lg); }
  .seg-4 span { border-radius: var(--r-md); }
  .seg-3 span { font-size: var(--fs-xs); }
  .wi-admin-item { padding: var(--s4); }
}

/* ---------- Narrow screens ---------- */
@media (max-width: 899px) {
  .bar { gap: var(--s2); padding: 0 var(--s1) 0 var(--s1); }
  .bar-chapter { display: none; }
  .bar-title { justify-content: flex-start; }
  .bar-book { font-size: var(--fs-md); }
  .bar-back span, .tool-label { display: none; }
  .tool { padding: 0; width: 38px; justify-content: center; }
  .bar-tools { gap: 0; }
  .folio { padding: var(--s3) var(--s2); }
  .turn { width: 40px; height: 72px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); opacity: .92; }
  .turn-prev { left: var(--s1); } .turn-next { right: var(--s1); }

  .leaf {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
    width: auto; max-width: none; max-height: 52%;
    border-left: 0; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -24px 44px -18px var(--shadow-strong);
    animation: sheet-up .24s var(--ease);
  }
  /* The sheet covers up to the bottom 52% of the stage; while it is open, centre
     the page-turn buttons in the part above it so they stay whole and tappable. */
  .stage:has(> .leaf:not([hidden])) .turn { top: 24%; }
  .leaf-grip { display: block; width: 44px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 10px auto 0; }
  .leaf-head { padding: 6px 14px 4px 22px; }
  .leaf-title { font-size: var(--fs-lg); }
  .lines { padding: var(--s1) 18px var(--s5) 22px; }
  .line { font-size: 1rem; }

  .deck { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); gap: var(--s2); }
  .listen { flex: 1 1 100%; gap: var(--s2); }
  .play { width: 46px; height: 46px; }
  .mode { margin-left: auto; }
  .mode-opt { padding: 6px 11px; font-size: var(--fs-xs); }
  .now { display: none; }
  .nav { flex: 1 1 100%; min-width: 0; }
  .count { font-size: var(--fs-md); }

  .bookpage { padding: var(--s3) var(--s4) 72px; }
  .book-layout { grid-template-columns: minmax(0, 1fr); gap: var(--s6); margin-top: var(--s3); }
  .book-head { position: static; display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 20px; align-items: start; }
  .book-title { font-size: var(--fs-xl); margin-top: 0; }
  .book-cover .tome-blank { font-size: var(--fs-xs); padding: var(--s2); line-height: 1.2; }
  .book-progress { font-size: var(--fs-sm); }
  .tabs { gap: var(--s5); margin-bottom: var(--s5); }
  .tab { font-size: var(--fs-lg); }
  .tnode { padding-left: 52px; }
  .tnode:not(.k-main) { padding-left: 98px; }
  .tnode-title { font-size: 1.4375rem; }
  .tnode:not(.k-main) .tnode-title { font-size: 1.25rem; }
  .tnode-summary { font-size: var(--fs-sm); }
  .codex-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--s3); }
  .codex-name { font-size: var(--fs-md); }
  .codex-heading { font-size: var(--fs-xl); }
  .lightbox[open] { grid-template-columns: minmax(0, 1fr); }
  .lightbox img { height: min(56vh, 560px); }
  .lb-text { padding: var(--s4) var(--s4) var(--s5); }
  .lb-name { font-size: var(--fs-xl); }
  .choice { padding: var(--s5) 20px var(--s4); }
  .choice-title { font-size: var(--fs-xl); }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 560px) {
  .library { padding: var(--s7) var(--s4) 64px; }
  .library-head { margin-bottom: 40px; }
  .corner { top: -36px; }
  .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 36px 20px; }
  .tome-title { font-size: var(--fs-md); }
  .tome-meta { font-size: var(--fs-xs); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Offline: downloads, badges, banner ---------- */
.offline-banner {
  position: sticky; top: 0; z-index: 30; padding: 10px var(--s4); text-align: center;
  font-size: var(--fs-sm); font-weight: 500; color: var(--leaf-bg); background: var(--text);
}
/* the reader fills the screen: there the bar carries a small Offline pill instead */
body[data-view="reader"] .offline-banner { display: none; }
.offline-pill { display: none; }
body.is-offline .offline-pill {
  display: inline-block; flex: none; align-self: center; padding: 2px 10px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; color: var(--leaf-bg); background: var(--text);
}
.tome-item { display: flex; flex-direction: column; min-width: 0; }
.tome-item .dl { margin-top: var(--s3); }
.offline-veil, .dl-ribbon { display: none; }
/* grey the art, not the label on top of it */
.tome-item.is-unavailable .tome-cover img, .tome-item.is-unavailable .tome-blank { filter: grayscale(1) opacity(.5); }
.tome-item.is-unavailable .offline-veil {
  display: block; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3;
  padding: 6px 14px; border-radius: var(--r-pill); white-space: nowrap;
  font-size: var(--fs-xs); font-weight: 700; color: var(--leaf-bg); background: var(--text);
}
.tome-item.is-unavailable .tome { cursor: not-allowed; }
.tome-item.is-downloaded .dl-ribbon {
  display: block; position: absolute; right: 10px; bottom: 12px; z-index: 2;
  padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700;
  color: var(--text); background: var(--surface); box-shadow: 0 0 0 1px var(--line-strong);
}
.dl { display: flex; align-items: center; flex-wrap: wrap; gap: 6px var(--s3); min-height: 40px; font-size: var(--fs-sm); color: var(--text-2); }
.dl-book { margin-top: var(--s4); }
.dl-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700; color: var(--on-accent); background: var(--accent-fill); }
.dl-badge-missing { color: var(--leaf-bg); background: var(--text); }
.dl-progress { flex: 1 1 120px; min-width: 0; height: 8px; accent-color: var(--accent); }
.dl-text { font-variant-numeric: tabular-nums; }
.rate-foot-end { justify-content: flex-end; }
