/* =====================================================================
   Immersive Reader & Chapter Deck
   Theme tokens drive the whole app (shelf, deck, reader) so the OLED /
   Dark / Sepia / Light switch is one source of truth.
   ===================================================================== */

:root {
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-prose: "Fraunces", "Iowan Old Style", Georgia, serif;

  --prose-size: 20px;
  --prose-leading: 1.72;
  --prose-measure: 38rem;
  --reader-gap: 3.5rem;

  --radius: 14px;
  --radius-lg: 22px;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.35), 0 8px 28px rgb(0 0 0 / 0.28);
  --shadow-2: 0 30px 80px rgb(0 0 0 / 0.5);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* ------------------------------------------------------------ themes */
html[data-theme="ink"] {
  --bg: #0d1014;
  --bg-deep: #07090c;
  --panel: #151a21;
  --panel-2: #1c222b;
  --line: #2a323d;
  --text: #e8e6e1;
  --text-dim: #a3a9b4;
  --text-faint: #6d7480;
  --accent: #d9a441;
  --accent-soft: rgba(217, 164, 65, 0.16);
  --accent-text: #12141a;
  --paper: #12161c;
  --paper-text: #e6e3dc;
  --highlight: rgba(217, 164, 65, 0.22);
  --shade: rgb(0 0 0 / 0.45);
  color-scheme: dark;
}
html[data-theme="oled"] {
  --bg: #000000;
  --bg-deep: #000000;
  --panel: #0a0a0b;
  --panel-2: #121214;
  --line: #23242a;
  --text: #ded9d1;
  --text-dim: #8f9099;
  --text-faint: #5d5f68;
  --accent: #c9a15a;
  --accent-soft: rgba(201, 161, 90, 0.14);
  --accent-text: #000;
  --paper: #000000;
  --paper-text: #cfcac2;
  --highlight: rgba(201, 161, 90, 0.2);
  --shade: rgb(0 0 0 / 0.7);
  color-scheme: dark;
}
html[data-theme="sepia"] {
  --bg: #ded2ba;
  --bg-deep: #cbbb9f;
  --panel: #efe6d2;
  --panel-2: #e6d9bf;
  --line: #cbbb9c;
  --text: #33291d;
  --text-dim: #6c5c46;
  --text-faint: #8b7a61;
  --accent: #96591f;
  --accent-soft: rgba(150, 89, 31, 0.14);
  --accent-text: #fdf6e7;
  --paper: #f5ecd8;
  --paper-text: #2f2519;
  --highlight: rgba(150, 89, 31, 0.18);
  --shade: rgb(70 50 25 / 0.28);
  color-scheme: light;
}
html[data-theme="paper"] {
  --bg: #eceef1;
  --bg-deep: #dfe3e8;
  --panel: #ffffff;
  --panel-2: #f4f6f8;
  --line: #d8dde4;
  --text: #14181d;
  --text-dim: #56606d;
  --text-faint: #8b95a2;
  --accent: #1d4ed8;
  --accent-soft: rgba(29, 78, 216, 0.1);
  --accent-text: #fff;
  --paper: #ffffff;
  --paper-text: #14181d;
  --highlight: rgba(29, 78, 216, 0.14);
  --shade: rgb(20 30 45 / 0.25);
  color-scheme: light;
}

/* ------------------------------------------------------------- base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.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;
}
.eyebrow {
  margin: 0; font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
}
.empty { text-align: center; color: var(--text-faint); padding: 4rem 1rem; font-size: 0.95rem; }

.view { display: none; }
.view.is-active { display: block; }
.view--reader.is-active { display: flex; flex-direction: column; height: 100dvh; }

/* ------------------------------------------------------------ buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.66rem 1.1rem;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 550;
  letter-spacing: 0.01em;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease), transform 0.18s var(--ease);
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn--primary:hover { filter: brightness(1.07); }
.btn--ghost { background: transparent; }
.btn--back { display: inline-flex; align-items: center; gap: 0.45rem; padding-left: 0.7rem; }
.btn--back svg { width: 16px; height: 16px; }

.iconbtn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 11px; border: 1px solid transparent; background: transparent;
  color: var(--text-dim); transition: 0.18s var(--ease); flex: none;
}
.iconbtn svg { width: 19px; height: 19px; }
.iconbtn:hover { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.iconbtn.is-on { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.iconbtn--accent { background: var(--accent); color: var(--accent-text); }
.iconbtn--accent svg { fill: currentColor; stroke: none; }
.iconbtn--accent:hover { background: var(--accent); color: var(--accent-text); filter: brightness(1.08); }

.track { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; flex: 1; }
.track > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s var(--ease); }

/* ===================================================================
   SHELF
   =================================================================== */
.view--shelf { max-width: 1400px; margin: 0 auto; padding: 2.6rem clamp(1rem, 4vw, 3rem) 4rem; }

/* /tools chrome — back link + the shared share bar */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1.6rem;
}
.toolbar__back {
  display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.82rem;
  font-weight: 500; color: var(--text-dim); text-decoration: none; transition: color 0.15s var(--ease);
}
.toolbar__back:hover { color: var(--accent); }
.toolbar__slot { color: var(--text-dim); }

.shelf-head {
  display: flex; flex-wrap: wrap; gap: 2rem; align-items: flex-end;
  justify-content: space-between; padding-bottom: 1.6rem; border-bottom: 1px solid var(--line);
}
.shelf-head h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 5.4vw, 4.1rem);
  font-weight: 700;
  font-variation-settings: "SOFT" 20, "WONK" 1, "opsz" 100;
  line-height: 0.95;
  margin: 0.5rem 0 0.4rem;
  letter-spacing: -0.02em;
}
.shelf-head__sub { margin: 0; color: var(--text-dim); font-size: 0.95rem; max-width: 46ch; }
.shelf-stats { display: flex; gap: 2.2rem; margin: 0; }
.shelf-stats div { display: flex; flex-direction: column; gap: 0.2rem; }
.shelf-stats dt { order: 2; font-size: 0.66rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-faint); }
.shelf-stats dd {
  order: 1; margin: 0; font-family: var(--font-display); font-size: 1.9rem;
  font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums;
}

.shelf-controls {
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between;
  align-items: center; margin: 1.4rem 0 0.4rem;
}
.shelf-controls__right { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--text-dim);
  padding: 0.45rem 0.95rem; border-radius: 999px; font-size: 0.8rem; font-weight: 500;
  transition: 0.16s var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--text-faint); }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.field {
  display: flex; align-items: center; gap: 0.5rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; padding: 0.4rem 0.9rem;
}
.field:focus-within { border-color: var(--accent); }
.field__icon { width: 15px; height: 15px; color: var(--text-faint); flex: none; }
.field input, .field select {
  background: transparent; border: 0; color: var(--text); font: inherit; font-size: 0.84rem;
  outline: none; min-width: 0;
}
.field--search input { width: min(30vw, 260px); }
.field--select { padding: 0.4rem 0.7rem 0.4rem 0.9rem; }
.field--select select { cursor: pointer; }
.field--select option { background: var(--panel); color: var(--text); }

.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg--wide { width: 100%; border-radius: 12px; }
.seg__btn {
  border: 0; background: transparent; color: var(--text-dim); border-radius: 999px;
  padding: 0.35rem 0.85rem; font-size: 0.78rem; font-weight: 550; flex: 1; transition: 0.16s var(--ease);
}
.seg--wide .seg__btn { border-radius: 9px; padding: 0.5rem 0.6rem; }
.seg__btn.is-on { background: var(--accent); color: var(--accent-text); }

/* resume bar */
.resume {
  display: flex; align-items: center; gap: 1.2rem; margin-top: 1.6rem;
  padding: 0.9rem 1.2rem; background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius);
}
.resume__cover { width: 46px; aspect-ratio: 2/3; border-radius: 6px; overflow: hidden; background: var(--panel-2); flex: none; }
.resume__cover img { width: 100%; height: 100%; object-fit: cover; }
.resume__body { flex: 1; min-width: 0; }
.resume__body h2 { margin: 0.15rem 0 0.15rem; font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }
.resume__body p { margin: 0; font-size: 0.8rem; color: var(--text-dim); }
.resume__track { height: 3px; background: var(--line); border-radius: 99px; margin-top: 0.55rem; overflow: hidden; }
.resume__track span { display: block; height: 100%; background: var(--accent); }

/* ------------------------------------------------------------ cover flow */
.flow {
  position: relative; margin-top: 1.4rem; padding: 2.4rem 0 1rem;
  perspective: 1600px; user-select: none; overflow: hidden;
  /* pan-y keeps vertical page scroll native while horizontal pulls stay
     with the pointer handlers — without it mobile swipes get cancelled */
  touch-action: pan-y;
  -webkit-user-select: none;
}
.flow::before {
  content: ""; position: absolute; left: 50%; top: 40%;
  width: min(560px, 82vw); height: 62%; transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, var(--accent-soft), transparent 72%);
  pointer-events: none;
}
.flow__stage {
  position: relative; height: clamp(260px, 34vh, 400px);
  transform-style: preserve-3d; outline: none;
}
/* Height-driven so a card can never grow past the stage and collide with the caption. */
.flow__card {
  position: absolute; top: 0; left: 50%; height: 100%; width: auto;
  aspect-ratio: 2/3; max-width: clamp(190px, 20vw, 250px);
  border-radius: 10px; overflow: hidden; background: var(--panel-2);
  box-shadow: var(--shadow-2); cursor: pointer;
  transition: transform 0.55s var(--ease), opacity 0.45s var(--ease), filter 0.45s var(--ease);
  will-change: transform;
}
.flow__card img { width: 100%; height: 100%; object-fit: cover; }
.flow__card::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, rgb(255 255 255 / 0.16), transparent 42%), var(--card-shade, transparent);
  transition: background 0.4s var(--ease);
}
.flow__card--ghost {
  display: grid; place-content: center; text-align: center; padding: 1rem;
  font-family: var(--font-display); font-size: 1.1rem; color: var(--text-dim);
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
}
.flow__card.is-center { box-shadow: 0 40px 90px rgb(0 0 0 / 0.55), 0 0 0 1px var(--accent-soft); }
.flow__reflect {
  position: absolute; inset: auto 0 -46% 0; height: 46%;
  background: inherit; opacity: 0.16; transform: scaleY(-1);
  -webkit-mask-image: linear-gradient(to bottom, rgb(0 0 0 / 0.8), transparent 72%);
  mask-image: linear-gradient(to bottom, rgb(0 0 0 / 0.8), transparent 72%);
}
.flow__nav {
  position: absolute; top: 50%; z-index: 5; width: 44px; height: 44px;
  transform: translateY(-50%); border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--text-dim); display: grid; place-items: center;
  transition: 0.18s var(--ease);
}
.flow__nav:hover { color: var(--text); border-color: var(--accent); }
.flow__nav svg { width: 18px; height: 18px; }
.flow__nav--prev { left: clamp(0px, 3vw, 40px); }
.flow__nav--next { right: clamp(0px, 3vw, 40px); }
.flow__caption { text-align: center; margin-top: 1.8rem; min-height: 118px; }
.flow__caption .eyebrow { margin-bottom: 0.4rem; }
.flow__caption h2 {
  font-family: var(--font-display); font-size: clamp(1.5rem, 3.2vw, 2.3rem);
  font-weight: 600; margin: 0 0 0.4rem; letter-spacing: -0.01em;
}
.flow__caption p { margin: 0 auto; max-width: 62ch; color: var(--text-dim); font-size: 0.9rem; line-height: 1.6; }
.flow__caption .flow__meta {
  display: flex; justify-content: center; gap: 1.2rem; flex-wrap: wrap;
  margin-top: 0.8rem; font-size: 0.74rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-faint);
}
.flow__caption .btn { margin-top: 1rem; }

/* ------------------------------------------------------------ grid */
.grid {
  display: grid; gap: 1.6rem; margin-top: 2rem;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.gcard { text-align: left; background: none; border: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.gcard__art {
  aspect-ratio: 2/3; border-radius: 10px; overflow: hidden; background: var(--panel-2);
  box-shadow: var(--shadow-1); position: relative;
  transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.gcard:hover .gcard__art { transform: translateY(-6px); box-shadow: var(--shadow-2); }
.gcard__art img { width: 100%; height: 100%; object-fit: cover; }
.gcard__badge {
  position: absolute; top: 8px; left: 8px; font-size: 0.6rem; letter-spacing: 0.12em;
  text-transform: uppercase; background: var(--shade); backdrop-filter: blur(6px);
  color: #fff; padding: 0.25rem 0.5rem; border-radius: 999px;
}
.gcard__pill {
  position: absolute; bottom: 8px; right: 8px; font-size: 0.62rem; font-weight: 600;
  background: var(--accent); color: var(--accent-text); padding: 0.2rem 0.45rem; border-radius: 6px;
}
.gcard h3 {
  margin: 0; font-family: var(--font-display); font-size: 1.02rem; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.gcard p { margin: 0; font-size: 0.74rem; color: var(--text-faint); letter-spacing: 0.04em; }

/* ===================================================================
   DECK
   =================================================================== */
.deck-hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.deck-hero__bg {
  position: absolute; inset: -18% -6%; background-size: cover; background-position: center;
  filter: blur(46px) saturate(1.25); opacity: 0.42; transform: scale(1.1);
}
.deck-hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, var(--shade), var(--bg) 88%);
}
.deck-hero__inner {
  position: relative; z-index: 2; max-width: 1200px; margin: 0 auto;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 2.8rem;
}
.deck-hero__grid {
  display: grid; grid-template-columns: minmax(150px, 230px) 1fr; gap: clamp(1.4rem, 4vw, 3rem);
  margin-top: 1.4rem; align-items: start;
}
.deck-hero__cover {
  aspect-ratio: 2/3; border-radius: 12px; overflow: hidden; background: var(--panel-2);
  box-shadow: var(--shadow-2);
}
.deck-hero__cover img { width: 100%; height: 100%; object-fit: cover; }
.deck-hero__meta h2 {
  font-family: var(--font-display); font-size: clamp(2rem, 4.6vw, 3.3rem); font-weight: 700;
  margin: 0.4rem 0 0.7rem; line-height: 1; letter-spacing: -0.02em;
}
.deck-hero__synopsis { margin: 0 0 1.1rem; max-width: 68ch; color: var(--text-dim); line-height: 1.65; font-size: 0.97rem; }
.deck-hero__facts { list-style: none; display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0; margin: 0 0 1.4rem; }
.deck-hero__facts li {
  font-size: 0.73rem; letter-spacing: 0.06em; padding: 0.32rem 0.7rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text-dim);
}
.deck-hero__facts li b { color: var(--text); font-weight: 600; }
.deck-hero__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.deck-hero__progress { display: flex; align-items: center; gap: 0.8rem; margin-top: 1.2rem; max-width: 420px; }
.deck-hero__progress span:last-child { font-size: 0.75rem; color: var(--text-faint); white-space: nowrap; }

.tabs {
  display: flex; gap: 0.3rem; max-width: 1200px; margin: 0 auto;
  padding: 1.2rem clamp(1rem, 4vw, 3rem) 0; border-bottom: 1px solid var(--line);
}
.tab {
  border: 0; background: transparent; color: var(--text-faint); padding: 0.6rem 0.9rem;
  font-size: 0.84rem; font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: 0.16s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.is-on { color: var(--accent); border-bottom-color: var(--accent); }

.tabpane { display: none; max-width: 1200px; margin: 0 auto; padding: 2rem clamp(1rem, 4vw, 3rem) 4rem; }
.tabpane.is-active { display: block; }

.cards { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); }
.ccard {
  position: relative; text-align: left; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; padding: 0; transition: 0.22s var(--ease);
}
.ccard:hover { transform: translateY(-4px); border-color: var(--accent); box-shadow: var(--shadow-1); }
.ccard__art { aspect-ratio: 16/10; background: var(--panel-2); overflow: hidden; position: relative; }
.ccard__art img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s var(--ease); }
.ccard:hover .ccard__art img { transform: scale(1.045); }
.ccard__num {
  position: absolute; top: 10px; left: 10px; font-family: var(--font-display);
  font-size: 0.78rem; font-weight: 700; background: var(--shade); backdrop-filter: blur(8px);
  color: #fff; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px;
}
.ccard__art--none { display: grid; place-items: center; aspect-ratio: 16/6; }
.ccard__art--none span { font-family: var(--font-display); font-size: 2.2rem; color: var(--text-faint); }
.ccard__body { padding: 0.9rem 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.4rem; flex: 1; }
.ccard__body h4 { margin: 0; font-family: var(--font-display); font-size: 1.04rem; font-weight: 600; line-height: 1.3; }
.ccard__body p { margin: 0; font-size: 0.82rem; color: var(--text-dim); line-height: 1.5; flex: 1; }
.ccard__foot {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint);
}
.ccard__ring { display: flex; align-items: center; gap: 0.4rem; color: var(--accent); }
.ccard__ring i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: block; }
.ccard.is-current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.ccard.is-read .ccard__art { filter: saturate(0.55) brightness(0.85); }

/* cast */
.cast { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(240px, 0.85fr); gap: 1.6rem; align-items: start; }
.cast__graph {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 0.5rem; position: relative; overflow: hidden;
}
.cast__graph svg { width: 100%; height: clamp(380px, 56vh, 560px); display: block; stroke: none; }
.cast__hint {
  position: absolute; left: 1rem; bottom: 0.7rem; margin: 0; font-size: 0.68rem;
  color: var(--text-faint); letter-spacing: 0.04em;
}
.node-circle { cursor: grab; transition: opacity 0.2s var(--ease); }
.node-circle:active { cursor: grabbing; }
.cast__list { display: flex; flex-direction: column; gap: 0.5rem; }
.cast__member {
  text-align: left; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 0.7rem 0.85rem; transition: 0.16s var(--ease);
}
.cast__member:hover, .cast__member.is-on { border-color: var(--accent); background: var(--accent-soft); }
.cast__member strong { display: block; font-family: var(--font-display); font-size: 0.96rem; font-weight: 600; }
.cast__member span { font-size: 0.78rem; color: var(--text-dim); line-height: 1.45; }
.cast__member em { display: block; margin-top: 0.35rem; font-style: normal; font-size: 0.68rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-faint); }

/* details */
.details { display: grid; gap: 1.6rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.detail-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; }
.detail-card h4 {
  margin: 0 0 0.8rem; font-size: 0.68rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent);
}
.detail-card p { margin: 0 0 0.7rem; font-size: 0.9rem; line-height: 1.62; color: var(--text-dim); }
.detail-card dl { display: grid; grid-template-columns: auto 1fr; gap: 0.45rem 1rem; margin: 0; font-size: 0.85rem; }
.detail-card dt { color: var(--text-faint); }
.detail-card dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.taglist { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.taglist span {
  font-size: 0.74rem; padding: 0.28rem 0.6rem; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text-dim);
}

/* ===================================================================
   READER
   =================================================================== */
.view--reader { background: var(--paper); position: relative; }
.reader-bg {
  position: absolute; inset: 0; background-size: cover; background-position: center;
  filter: blur(70px) saturate(1.3); opacity: 0; transition: opacity 0.8s var(--ease); pointer-events: none;
}
.view--reader.has-ambience .reader-bg { opacity: 0.2; }
.view--reader.has-ambience .reader-bg { animation: drift 46s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: scale(1.08) translate3d(-2%, -1%, 0); }
  to { transform: scale(1.2) translate3d(2%, 2%, 0); }
}

.reader-bar {
  position: relative; z-index: 3; display: flex; align-items: center; gap: 0.8rem;
  padding: 0.55rem clamp(0.6rem, 2.5vw, 1.6rem);
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px); flex: none;
}
.reader-bar__title { flex: 1; min-width: 0; text-align: center; line-height: 1.25; }
.reader-bar__title strong {
  display: block; font-family: var(--font-display); font-size: 0.94rem; font-weight: 600;
  color: var(--paper-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-bar__title span { font-size: 0.72rem; color: var(--text-faint); letter-spacing: 0.06em; }
.reader-bar__tools { display: flex; gap: 0.15rem; }

.reader-stage { position: relative; z-index: 2; flex: 1; min-height: 0; display: flex; }
.pagezone {
  border: 0; background: transparent; width: clamp(44px, 8vw, 110px); flex: none;
  opacity: 0; transition: opacity 0.2s var(--ease); position: relative;
}
.pagezone::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 10px; height: 10px;
  border-top: 2px solid var(--text-faint); border-right: 2px solid var(--text-faint);
}
.pagezone--prev::after { transform: translate(-50%, -50%) rotate(-135deg); }
.pagezone--next::after { transform: translate(-50%, -50%) rotate(45deg); }
.pagezone:hover { opacity: 1; }
.reader-stage[data-mode="scroll"] .pagezone { display: none; }

.reader-scroll { flex: 1; min-width: 0; position: relative; overflow: hidden; display: flex; }
.reader-stage[data-mode="scroll"] .reader-scroll { overflow-y: auto; scroll-behavior: smooth; display: block; }

/* The clip box is exactly one page wide; overflowing columns are hidden here.
   In paginated modes it is a flex item so it shrinks to the space left by the
   tap zones instead of overflowing past them. */
.prose-clip { width: 100%; margin: 0 auto; min-width: 0; }
.reader-stage[data-mode="page"] .prose-clip,
.reader-stage[data-mode="spread"] .prose-clip {
  overflow: hidden; height: 100%; position: relative;
  flex: 0 1 var(--page-w); width: auto;
}
.reader-stage[data-mode="page"] { --page-w: var(--prose-measure); }
.reader-stage[data-mode="spread"] { --page-w: calc(var(--prose-measure) * 2 + var(--reader-gap, 3.5rem)); }

.prose {
  color: var(--paper-text);
  font-family: var(--font-prose);
  font-size: var(--prose-size);
  line-height: var(--prose-leading);
  max-width: var(--prose-measure);
  margin: 0 auto;
  padding: clamp(1.4rem, 4vh, 3rem) clamp(1rem, 3vw, 2rem) 4rem;
}
.reader-stage[data-mode="page"] .prose,
.reader-stage[data-mode="spread"] .prose {
  height: 100%; width: 100%; max-width: none;
  padding: clamp(1.2rem, 3.4vh, 2.4rem) 0 1.6rem;
  column-fill: auto; column-gap: var(--reader-gap, 3.5rem);
  transition: transform 0.42s var(--ease);
}
.reader-stage[data-mode="spread"] .prose { column-count: 2; }
.reader-stage[data-mode="page"] .prose { column-count: 1; }
.reader-stage[data-mode="spread"] .prose-clip::before {
  /* faint gutter rule between the two columns of a spread */
  content: ""; position: absolute; top: 14%; bottom: 14%; left: 50%; width: 1px; z-index: 2;
  background: linear-gradient(transparent, var(--line), transparent); opacity: 0.7; pointer-events: none;
}

html[data-face="sans"] { --font-prose: "Inter", system-ui, sans-serif; }
html[data-face="mono"] { --font-prose: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, monospace; }

.prose h2.chapter-title {
  font-family: var(--font-display); font-weight: 700; font-size: 1.9em;
  line-height: 1.05; margin: 0 0 0.15em; letter-spacing: -0.02em;
  break-after: avoid;
}
.prose .chapter-kicker {
  font-family: var(--font-ui); font-size: 0.62em; letter-spacing: 0.24em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 0.5em; font-weight: 600;
}
.prose .chapter-rule { width: 3.4em; height: 2px; background: var(--accent); opacity: 0.6; margin: 0 0 1.6em; }
.prose p { margin: 0 0 1.05em; }
.prose[data-hyphens="on"] p { text-align: justify; hyphens: auto; }
.prose.has-dropcap p.lead::first-letter {
  float: left; font-family: var(--font-display); font-size: 3.1em; line-height: 0.82;
  padding: 0.06em 0.1em 0 0; font-weight: 700; color: var(--accent);
}
.prose h3 { font-family: var(--font-display); font-size: 1.2em; margin: 1.6em 0 0.6em; break-after: avoid; }
.prose blockquote {
  margin: 1.4em 0; padding-left: 1.1em; border-left: 2px solid var(--accent);
  font-style: italic; color: var(--text-dim);
}
.prose hr {
  border: 0; margin: 2em auto; width: 40%; text-align: center; overflow: visible; height: 0;
}
.prose hr::after {
  content: "· · ·"; display: block; letter-spacing: 0.6em; color: var(--text-faint); font-size: 0.9em;
}
.prose figure { margin: 1.6em 0; break-inside: avoid; }
.prose figure img { border-radius: 10px; box-shadow: var(--shadow-1); width: 100%; }
.prose figcaption {
  font-family: var(--font-ui); font-size: 0.62em; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-faint); margin-top: 0.6em; text-align: center;
}
.prose .end-note {
  font-family: var(--font-ui); font-size: 0.72em; color: var(--text-faint);
  border-top: 1px solid var(--line); padding-top: 1.2em; margin-top: 2.4em; break-inside: avoid;
}
.sent { transition: background 0.25s var(--ease), color 0.25s var(--ease); border-radius: 3px; }
.sent.is-speaking { background: var(--highlight); box-shadow: 0 0 0 3px var(--highlight); }

.reader-foot {
  position: relative; z-index: 3; display: flex; align-items: center; gap: 1rem; flex: none;
  padding: 0.5rem clamp(0.6rem, 2.5vw, 1.6rem) calc(0.5rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px);
}
.reader-foot__track { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.reader-foot__track p {
  margin: 0; font-size: 0.7rem; color: var(--text-faint); letter-spacing: 0.06em;
  display: flex; justify-content: space-between; gap: 1rem;
}
/* Page vs chapter navigation is spelled out — the page buttons move within the
   current chapter, the chapter buttons jump between them. */
.navgroup { display: flex; gap: 0.35rem; flex: none; }
.navbtn {
  display: inline-flex; align-items: center; gap: 0.32rem;
  border: 1px solid var(--line); background: transparent; color: var(--text-dim);
  border-radius: 999px; padding: 0.4rem 0.8rem; font-size: 0.75rem; white-space: nowrap;
  transition: 0.16s var(--ease);
}
.navbtn b { font-weight: 600; }
.navbtn span { font-size: 0.95rem; line-height: 1; opacity: 0.75; }
.navbtn:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.navbtn:disabled { opacity: 0.3; cursor: default; }
.navbtn--page {
  background: var(--panel-2); color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}
.navbtn--page:hover:not(:disabled) { background: var(--accent-soft); }
.reader-stage[data-mode="scroll"] ~ .reader-foot .navbtn--page { display: none; }

/* read-aloud dock */
.tts-dock {
  position: fixed; z-index: 40; left: 50%; bottom: calc(4.4rem + env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; align-items: center; gap: 0.4rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 0.4rem 0.6rem; box-shadow: var(--shadow-2); max-width: calc(100vw - 2rem);
}
.tts-dock__rate { display: flex; align-items: center; gap: 0.45rem; font-size: 0.7rem; color: var(--text-faint); }
.tts-dock__rate span { letter-spacing: 0.1em; text-transform: uppercase; }
.tts-dock__rate b { color: var(--text); font-variant-numeric: tabular-nums; min-width: 2.6em; }
.tts-dock input[type="range"] { width: 82px; }
.tts-dock select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 0.3rem 0.6rem; font: inherit; font-size: 0.74rem; max-width: 150px;
}

/* ===================================================================
   DRAWERS
   =================================================================== */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.5); z-index: 45; backdrop-filter: blur(2px); }
.drawer {
  position: fixed; top: 0; bottom: 0; z-index: 50; width: min(370px, 88vw);
  background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; box-shadow: var(--shadow-2);
  animation: slideIn 0.28s var(--ease);
}
.drawer--left { left: 0; border-left: 0; border-right: 1px solid var(--line); animation-name: slideInLeft; }
.drawer--right { right: 0; }
@keyframes slideIn { from { transform: translateX(100%); } }
@keyframes slideInLeft { from { transform: translateX(-100%); } }
.drawer__head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 0.8rem 1rem 1.3rem; border-bottom: 1px solid var(--line); flex: none;
}
.drawer__head h3 { margin: 0; font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; }
.drawer__body { overflow-y: auto; padding: 1.2rem 1.3rem 3rem; display: flex; flex-direction: column; gap: 1.5rem; }

.pref { display: flex; flex-direction: column; gap: 0.6rem; }
.pref__label { margin: 0; font-size: 0.66rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-faint); }
.pref__row { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.84rem; }
.pref__row b { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 0.8rem; }
.pref input[type="range"] { width: 100%; accent-color: var(--accent); }

.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.45rem; }
.swatches button {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px;
  padding: 0.55rem 0.2rem 0.45rem; font-size: 0.66rem; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 0.35rem; transition: 0.16s var(--ease);
}
.swatches button i { width: 100%; height: 22px; border-radius: 5px; border: 1px solid var(--line); }
.swatches button[data-theme-set="oled"] i { background: #000; }
.swatches button[data-theme-set="ink"] i { background: linear-gradient(#151a21, #0d1014); }
.swatches button[data-theme-set="sepia"] i { background: #f5ecd8; }
.swatches button[data-theme-set="paper"] i { background: #fff; }
.swatches button.is-on { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }

.toggle { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--text-dim); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.pref--keys ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; font-size: 0.78rem; color: var(--text-dim); }
.pref--keys li { display: flex; align-items: center; gap: 0.3rem; }
kbd {
  font: inherit; font-size: 0.7rem; background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px; padding: 0.1rem 0.4rem; color: var(--text);
}

.toc { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; counter-reset: toc; }
.toc button {
  width: 100%; text-align: left; border: 0; background: transparent; border-radius: 9px;
  padding: 0.6rem 0.7rem; display: flex; gap: 0.7rem; align-items: baseline; transition: 0.14s var(--ease);
}
.toc button:hover { background: var(--panel-2); }
.toc button.is-on { background: var(--accent-soft); color: var(--accent); }
.toc button.is-read span.toc__n { color: var(--accent); }
.toc__n { font-family: var(--font-display); font-size: 0.78rem; color: var(--text-faint); min-width: 1.6em; font-variant-numeric: tabular-nums; }
.toc__t { font-size: 0.88rem; line-height: 1.35; flex: 1; }
.toc__w { font-size: 0.68rem; color: var(--text-faint); }

/* ===================================================================
   RESPONSIVE
   =================================================================== */
@media (max-width: 900px) {
  .cast { grid-template-columns: 1fr; }
  .deck-hero__grid { grid-template-columns: minmax(0, 150px) 1fr; }
  .shelf-stats { gap: 1.4rem; }
  .shelf-stats dd { font-size: 1.5rem; }
}
@media (max-width: 720px) {
  /* Touch swipe + edge taps replace the side tap zones, so the page gets the full width. */
  .pagezone { display: none; }
  .reader-stage[data-mode="spread"] .prose { column-count: 1; max-width: 100%; }
  .reader-stage[data-mode="spread"] .prose-clip::before { display: none; }
  .flow__nav { display: none; }
  .view--shelf { padding-top: 1.6rem; }
  .shelf-controls__right { width: 100%; }
  .field--search { flex: 1; }
  .field--search input { width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
  .tts-dock__rate, .tts-dock select { display: none; }
  .reader-foot { flex-wrap: wrap; gap: 0.5rem; }
  .reader-foot__track { order: -1; flex-basis: 100%; }
  .navgroup { flex: 1; }
  .navgroup:last-child { justify-content: flex-end; }
  .navbtn { padding: 0.45rem 0.7rem; }
  .deck-hero__grid { grid-template-columns: 1fr; }
  .deck-hero__cover { max-width: 180px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.05ms !important; }
}
