/* =========================================================================
   Folio — gouache & paper
   Flat, warm colour; every surface carries a visible paper tooth.
   ========================================================================= */

:root {
  /* fine paper tooth: neutral grey noise, applied with overlay so it lightens AND darkens */
  --tooth: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='t'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.15' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23t)'/%3E%3C/svg%3E");
  /* soft blotches, like gouache drying unevenly */
  --mottle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='700' height='700'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012' numOctaves='3' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
  /* long paper fibres */
  --fibers: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .09' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .28 0 0 0 0 .18 0 0 0 .14 -.05'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --grain: var(--tooth);

  --ui: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --ease-paper: cubic-bezier(.3, .7, .2, 1);
  --spring: cubic-bezier(.34, 1.4, .5, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ---- Themes. `desk` sits behind everything; `page` is the paper ---- */
body[data-theme="sage"] {
  --desk: #cddcc2; --desk-2: #bfd0b3;
  --page: #f6eed6; --page-back: #efe4c4;
  --ink: #2f2b22; --ink-2: #5b5545; --ink-3: #868269;
  --rule: rgba(60, 72, 40, .16);
  --accent: #c8553d; --accent-ink: #fff6e6; --accent-2: #e0b046;
  --chip: #e5e7cf; --card: #fbf6e4; --btn: #fffdf5;
  --shadow: 55, 70, 45;
  --tooth-o: .34; --mottle-o: .14; --vignette: .10;
  --plank: #e0b046; --plank-top: #ecc76a; --plank-2: #6f8f6c; --plank-2-top: #86a582;
  --art-wall: #86a47f; --art-floor: #c3d8b6; --art-light: #f6edc8; --art-case: #e0b046; --art-case-dark: #5e7d5b;
  color-scheme: light;
}
body[data-theme="paper"] {
  --desk: #e6e0d4; --desk-2: #ddd6c8;
  --page: #f5f0e6; --page-back: #efe9dd;
  --ink: #2a2620; --ink-2: #5d564b; --ink-3: #958c7e;
  --rule: rgba(60, 48, 30, .14);
  --accent: #8c3b2a; --accent-ink: #fff6ea; --accent-2: #b98a3a;
  --chip: #ebe5d9; --card: #f7f2e9; --btn: #fffcf6;
  --shadow: 40, 30, 15;
  --tooth-o: .3; --mottle-o: .08; --vignette: .10;
  --plank: #b7a891; --plank-top: #cbbda6; --plank-2: #a89880; --plank-2-top: #bdae96;
  --art-wall: #d4c8b2; --art-floor: #e9e1d2; --art-light: #fbf6ea; --art-case: #b7a891; --art-case-dark: #8c7c64;
  color-scheme: light;
}
body[data-theme="aged"] {
  --desk: #d8ccb4; --desk-2: #cdbfa4;
  --page: #ecdfc4; --page-back: #e4d6b8;
  --ink: #33281b; --ink-2: #634f38; --ink-3: #977f61;
  --rule: rgba(80, 55, 25, .2);
  --accent: #7d3420; --accent-ink: #fbf0dc; --accent-2: #a57a35;
  --chip: #e3d5b8; --card: #efe3c9; --btn: #f8efdb;
  --shadow: 60, 40, 15;
  --tooth-o: .42; --mottle-o: .2; --vignette: .24;
  --plank: #8f7556; --plank-top: #a58a69; --plank-2: #7d6548; --plank-2-top: #93795a;
  --art-wall: #b9a27e; --art-floor: #d8c9a8; --art-light: #f0e4c4; --art-case: #8f7556; --art-case-dark: #6a5338;
  color-scheme: light;
}
body[data-theme="night"] {
  --desk: #171816; --desk-2: #1e1f1c;
  --page: #23221f; --page-back: #2a2925;
  --ink: #d6ccb9; --ink-2: #a39a86; --ink-3: #736c5e;
  --rule: rgba(230, 210, 170, .1);
  --accent: #e08463; --accent-ink: #1c1b18; --accent-2: #d8ac55;
  --chip: #2b2b27; --card: #262622; --btn: #2f2f2a;
  --shadow: 0, 0, 0;
  --tooth-o: .22; --mottle-o: .1; --vignette: .28;
  --plank: #3a3a33; --plank-top: #46463e; --plank-2: #2f3a2e; --plank-2-top: #3b4739;
  --art-wall: #2b3329; --art-floor: #22281f; --art-light: #3a3a2c; --art-case: #8b6f2f; --art-case-dark: #26301f;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--desk);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
  transition: background-color .5s ease, color .5s ease;
}
/* the desk itself is gouache on card: mottle + tooth */
body::before, body::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; }
body::before { background-image: var(--mottle); background-size: 700px; mix-blend-mode: soft-light; opacity: calc(var(--mottle-o) * 2.4); }
body::after { background-image: var(--tooth); background-size: 256px; mix-blend-mode: overlay; opacity: var(--tooth-o); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---- buttons: soft, round, slightly raised like painted card ---- */
.btn-ink, .btn-ghost {
  display: inline-flex; align-items: center; gap: 9px;
  height: 48px; padding: 0 22px; border-radius: 999px;
  font-size: 15.5px; font-weight: 700; letter-spacing: .005em;
  transition: transform .25s var(--spring), box-shadow .25s;
}
.btn-ink { background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 0 rgba(var(--shadow), .25), 0 10px 22px -12px rgba(var(--shadow), .6); }
.btn-ghost { background: var(--btn); color: var(--ink); box-shadow: 0 2px 0 rgba(var(--shadow), .12), 0 8px 20px -14px rgba(var(--shadow), .5); }
.btn-ink:active, .btn-ghost:active { transform: scale(.95) translateY(1px); }
.btn-ink svg, .btn-ghost svg { width: 19px; height: 19px; stroke-width: 2; }
.btn-icon, .btn-round {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  transition: background-color .2s, transform .25s var(--spring);
}
.btn-round { background: var(--btn); box-shadow: 0 2px 0 rgba(var(--shadow), .12), 0 8px 18px -12px rgba(var(--shadow), .55); }
.btn-icon:active, .btn-round:active { transform: scale(.9); }

.view { position: fixed; inset: 0; z-index: 1; visibility: hidden; }
.view.is-active { visibility: visible; }

/* =========================================================================
   LIBRARY
   ========================================================================= */
#library {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(22px + var(--safe-t)) clamp(18px, 4.5vw, 60px) calc(60px + var(--safe-b));
}
.lib-hero {
  position: relative; display: grid; grid-template-columns: 1fr minmax(260px, 44%); align-items: stretch;
  border-radius: 28px; overflow: hidden; background: var(--card);
  box-shadow: 0 2px 0 rgba(var(--shadow), .1), 0 24px 50px -36px rgba(var(--shadow), .7);
  min-height: 250px;
}
.lib-hero::after { content: ""; position: absolute; inset: 0; pointer-events: none; background-image: var(--tooth); background-size: 256px; mix-blend-mode: overlay; opacity: calc(var(--tooth-o) * 1.2); }
.lib-intro { padding: clamp(24px, 3.5vw, 40px); display: flex; flex-direction: column; justify-content: center; position: relative; z-index: 1; }
.lib-intro h1 {
  font-family: var(--display); font-weight: 500; font-size: clamp(48px, 6.4vw, 72px);
  font-variation-settings: "opsz" 144; letter-spacing: -.025em; line-height: .9; margin: 0; color: var(--ink);
}
.lib-sub { margin: 10px 0 0; color: var(--ink-2); font-family: var(--display); font-style: italic; font-size: 18px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.stat {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px 0 9px; border-radius: 999px;
  background: var(--chip); font-size: 13.5px; color: var(--ink-2); font-weight: 600;
}
.stat svg { width: 17px; height: 17px; color: var(--accent); stroke-width: 2; }
.stat b { color: var(--ink); font-weight: 800; }
.lib-actions { display: flex; gap: 10px; align-items: center; margin-top: 22px; flex-wrap: wrap; }
.lib-hero { min-height: clamp(300px, 34vw, 380px); padding-bottom: 8px; }
.lib-art { position: relative; min-height: 240px; overflow: hidden; }
.lib-art picture, .lib-art img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.lib-art img { object-fit: cover; object-position: 52% 50%; filter: saturate(.95) contrast(.98); }
/* the picture melts softly into the card on its left */
.lib-art::before { content: ""; position: absolute; inset: 0; z-index: 1; background: linear-gradient(90deg, var(--card) 0%, color-mix(in srgb, var(--card) 40%, transparent) 7%, transparent 22%); }
.lib-art::after { content: ""; position: absolute; inset: 0; z-index: 1; background-image: var(--tooth); background-size: 256px; mix-blend-mode: overlay; opacity: .25; }
body[data-theme="night"] .lib-art img { filter: brightness(.82) saturate(.9); }

/* ---- a woven kente band: gold, green, red and black, with a fine weave ---- */
.kente, .b3d .ribbon {
  --k-gold: #d9a52a; --k-green: #24683f; --k-red: #b7362a; --k-black: #1d1b17;
}
.kente {
  position: absolute; left: 0; right: 0; bottom: 0; height: 8px; z-index: 2;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 1px, transparent 1px 2.5px),
    repeating-linear-gradient(90deg,
      var(--k-gold) 0 18px, var(--k-green) 18px 22px, var(--k-gold) 22px 26px, var(--k-black) 26px 29px,
      var(--k-red) 29px 37px, var(--k-black) 37px 40px, var(--k-gold) 40px 44px, var(--k-green) 44px 48px,
      var(--k-gold) 48px 66px, var(--k-red) 66px 69px, var(--k-green) 69px 77px, var(--k-red) 77px 80px);
  opacity: .92;
}

/* Twi welcome + an Adinkra proverb on the empty shelf */
.akwaaba { margin: 0; font-family: var(--display); font-style: italic; font-size: 19px; color: var(--accent); letter-spacing: .02em; }
.proverb { margin: 30px auto 0; display: flex; flex-direction: column; gap: 3px; align-items: center; color: var(--ink-3); font-size: 13.5px; }
.proverb i { font-family: var(--display); font-size: 17px; color: var(--ink-2); }
.proverb::before { content: ""; width: 54px; height: 5px; margin-bottom: 10px; border-radius: 3px;
  background: repeating-linear-gradient(90deg, #d9a52a 0 10px, #24683f 10px 13px, #b7362a 13px 19px, #1d1b17 19px 21px); }

.continue {
  margin-top: 22px; display: grid; grid-template-columns: 230px 1fr; gap: 36px; align-items: center;
  padding: 28px 36px; border-radius: 28px; background: var(--card);
  box-shadow: 0 2px 0 rgba(var(--shadow), .1), 0 24px 50px -36px rgba(var(--shadow), .7);
  position: relative; overflow: hidden;
}
.continue::after { content: ""; position: absolute; inset: 0; background-image: var(--tooth); background-size: 256px; opacity: var(--tooth-o); mix-blend-mode: overlay; pointer-events: none; }
.continue .eyebrow { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); font-weight: 800; }
.continue h2 { font-family: var(--display); font-weight: 500; font-size: clamp(26px, 3.2vw, 36px); margin: 6px 0 4px; line-height: 1.08; }
.continue .by { color: var(--ink-2); font-family: var(--display); font-style: italic; font-size: 17px; }
.continue .meter { margin: 18px 0 10px; max-width: 380px; height: 6px; }

.meter { height: 4px; background: var(--chip); border-radius: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }

.shelf-tabs {
  display: flex; gap: 10px; align-items: center; margin: 30px 0 8px; flex-wrap: wrap;
}
.seg-tabs { display: flex; padding: 4px; gap: 2px; border-radius: 999px; background: var(--card); box-shadow: inset 0 0 0 1px var(--rule); }
.tab { height: 38px; padding: 0 16px; border-radius: 999px; font-size: 14.5px; font-weight: 700; color: var(--ink-2); white-space: nowrap; transition: background-color .2s, color .2s; }
.tab.is-on { background: var(--ink); color: var(--card); }
.shelf-search {
  flex: 1; min-width: 160px; display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 16px;
  border-radius: 999px; background: var(--card); box-shadow: inset 0 0 0 1px var(--rule); color: var(--ink-3);
}
.shelf-search svg { width: 19px; height: 19px; }
.shelf-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: 600 15px var(--ui); color: var(--ink); }
.shelf-search input::placeholder { color: var(--ink-3); font-weight: 500; }
.tab.sort { color: var(--ink-3); font-style: italic; font-family: var(--display); font-weight: 400; font-size: 16px; }

/* Covers: a physical object, matte varnish, soft contact shadow */
.cover {
  position: relative; aspect-ratio: 2 / 3; width: 100%;
  border-radius: 3px 8px 8px 3px; overflow: hidden;
  background: var(--desk-2);
  box-shadow: 0 1px 1px rgba(var(--shadow), .18), 0 8px 16px -6px rgba(var(--shadow), .3);
}
.cover img, .cover canvas { width: 100%; height: 100%; object-fit: cover; display: block; filter: saturate(.9) contrast(.97); }
.cover::before {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.28) 0, rgba(255,255,255,.18) 2.2%, rgba(0,0,0,.12) 4%, transparent 8%);
}
.cover::after {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background-image: var(--tooth), linear-gradient(160deg, rgba(255,255,255,.08), rgba(0,0,0,.06));
  background-size: 256px, 100%; mix-blend-mode: overlay; opacity: .5;
}
.cloth {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 14% 12% 12%; color: rgba(255, 248, 230, .95); text-align: center;
}
.cloth::before { content: ""; position: absolute; inset: 6%; border: 1.5px solid rgba(255, 240, 210, .4); border-radius: 3px; }
.cloth b { font-family: var(--display); font-weight: 500; font-size: clamp(14px, 1.6vw, 19px); line-height: 1.15; }
.cloth small { font-family: var(--display); font-style: italic; font-size: 12px; opacity: .85; }
.cloth hr { width: 24%; border: 0; border-top: 1.5px solid rgba(255, 240, 210, .5); margin: 0 auto; }

.empty { text-align: center; padding: 6vh 20px; max-width: 480px; margin: 0 auto; }
.empty h2 { font-family: var(--display); font-weight: 500; font-size: 32px; margin: 10px 0 8px; }
.empty p { color: var(--ink-2); line-height: 1.6; font-size: 15.5px; }
.empty .hint { font-size: 13.5px; color: var(--ink-3); margin-top: 24px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }

.drop-veil {
  position: fixed; inset: 16px; border-radius: 28px; border: 2.5px dashed var(--accent);
  display: grid; place-items: center; background: color-mix(in srgb, var(--desk) 88%, transparent);
  font-family: var(--display); font-size: 28px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20;
}
.drop-veil.on { opacity: 1; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* =========================================================================
   PAPER — every printed page
   ========================================================================= */
.page {
  position: absolute; inset: 0; overflow: hidden;
  isolation: isolate;
  background-color: var(--page);
  color: var(--ink);
}
/* vignette + fibres (multiply) */
.page::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background-image:
    radial-gradient(130% 110% at 50% 50%, transparent 58%, rgba(var(--shadow), var(--vignette)) 100%),
    var(--fibers);
  background-size: 100% 100%, 600px 600px;
  mix-blend-mode: multiply;
}
/* the paper tooth you can feel: overlay noise, lightens and darkens */
.page::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 6;
  background-image: var(--tooth); background-size: 256px;
  mix-blend-mode: overlay; opacity: calc(var(--tooth-o) * 1.35);
}
body[data-theme="night"] .page::before {
  background-image: radial-gradient(130% 110% at 50% 50%, transparent 55%, rgba(0,0,0,.35) 100%);
  background-size: 100% 100%; mix-blend-mode: normal; opacity: .6;
}
body[data-theme="night"] .page::after { mix-blend-mode: soft-light; opacity: .5; }
/* foxing — the brown speckle of an old page */
body[data-theme="aged"] .page::before {
  background-image:
    radial-gradient(circle at 12% 8%, rgba(140, 90, 30, .14), transparent 9%),
    radial-gradient(circle at 92% 86%, rgba(140, 90, 30, .16), transparent 11%),
    radial-gradient(circle at 78% 14%, rgba(150, 100, 40, .08), transparent 6%),
    radial-gradient(circle at 30% 94%, rgba(130, 80, 30, .1), transparent 7%),
    radial-gradient(130% 110% at 50% 50%, transparent 58%, rgba(var(--shadow), var(--vignette)) 100%),
    var(--fibers);
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 600px 600px;
}

.pg-head, .pg-foot {
  position: absolute; left: 0; right: 0; z-index: 2;
  display: flex; justify-content: center; align-items: center;
  font-family: var(--book-font, Literata), serif; color: var(--ink-3);
  font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pg-head { top: calc(var(--safe-t) + 24px); padding: 0 64px; }
.pg-foot { bottom: calc(var(--safe-b) + 20px); letter-spacing: .06em; font-size: 13px; text-transform: none; font-variant-numeric: oldstyle-nums; }
/* in a spread, folios sit at the outer corners like a printed book */
.page.side-l .pg-foot { justify-content: flex-start; padding-left: 9%; }
.page.side-r .pg-foot { justify-content: flex-end; padding-right: 9%; }
.pg-body { position: absolute; overflow: hidden; z-index: 1; }

/* ---- the flowed book text ---- */
.flow {
  height: 100%;
  column-fill: auto;
  font-family: var(--book-font, Literata), Georgia, serif;
  font-size: var(--book-size, 19px);
  line-height: var(--book-lead, 1.6);
  color: var(--ink);
  hyphens: auto; -webkit-hyphens: auto;
  text-rendering: optimizeLegibility;
  font-kerning: normal; font-variant-ligatures: common-ligatures oldstyle-nums;
  overflow-wrap: break-word;
}
.flow p { margin: 0; text-align: justify; text-indent: 1.4em; orphans: 2; widows: 2; }
.flow p:first-child, .flow h1 + p, .flow h2 + p, .flow h3 + p, .flow h4 + p, .flow hr + p, .flow .no-indent,
.flow blockquote p, .flow li p, .flow div > p:first-child { text-indent: 0; }
.flow h1, .flow h2, .flow h3, .flow h4, .flow h5, .flow h6 {
  font-family: var(--display); font-weight: 400; line-height: 1.2; text-align: center;
  break-after: avoid; text-indent: 0; letter-spacing: .005em; hyphens: none;
}
.flow h1 { font-size: 1.65em; margin: 2.2em 0 1.4em; }
.flow h2 { font-size: 1.4em; margin: 2em 0 1.2em; }
.flow h3 { font-size: 1.15em; margin: 1.6em 0 .8em; font-style: italic; }
.flow h4, .flow h5, .flow h6 { font-size: 1em; margin: 1.4em 0 .6em; font-variant: small-caps; letter-spacing: .06em; }
.flow > *:first-child h1:first-child, .flow > h1:first-child, .flow > h2:first-child { margin-top: .6em; }
.flow h1 + p::first-letter, .flow h2 + p::first-letter, .flow .dropcap::first-letter {
  float: left; font-family: var(--display); font-size: 3.35em; line-height: .82; padding: .06em .08em 0 0; color: var(--accent);
  font-variation-settings: "opsz" 144;
}
.flow img, .flow svg { max-width: 100%; max-height: var(--page-h, 80vh); height: auto; display: block; margin: 1em auto; break-inside: avoid; object-fit: contain; }
.flow svg { fill: currentColor; color: var(--ink); }
.flow figure { margin: 1em 0; break-inside: avoid; text-align: center; }
.flow figcaption { font-size: .85em; color: var(--ink-2); font-style: italic; }
.flow blockquote { margin: 1em 1.5em; font-style: italic; color: var(--ink-2); }
.flow hr { border: 0; text-align: center; margin: 1.4em 0; height: 1em; }
.flow hr::after { content: "⁂"; color: var(--ink-3); letter-spacing: .4em; }
.flow a { color: inherit; text-decoration-color: var(--ink-3); text-underline-offset: .18em; }
.flow sup a, .flow a.noteref { color: var(--accent); text-decoration: none; }
.flow ul, .flow ol { padding-left: 1.4em; }
.flow table { border-collapse: collapse; font-size: .9em; margin: 1em 0; max-width: 100%; }
.flow td, .flow th { padding: .25em .5em; border-bottom: 1px solid var(--rule); }
.flow pre, .flow code { font-size: .85em; white-space: pre-wrap; }
.flow .center { text-align: center; text-indent: 0; }
.flow small { font-size: .82em; }
.flow .smcap, .flow .smallcaps, .flow abbr { font-variant: small-caps; letter-spacing: .03em; }
.flow .poem, .flow .stanza, .flow .verse { margin: 1em 0 1em 1.4em; text-align: left; }
.flow .poem p, .flow .stanza p, .flow .verse p, .flow .poem span { text-align: left; text-indent: -1em; padding-left: 1em; }
body[data-theme="night"] .flow img { filter: brightness(.85) contrast(1.05); }
.page.is-solo .pg-head, .page.is-solo .pg-foot { display: none; }
.page.is-solo .flow img, .page.is-solo .flow svg { height: var(--page-h); width: auto; max-width: 100%; margin: 0 auto; box-shadow: 0 8px 24px -12px rgba(var(--shadow), .5); }

/* comic / pdf pages */
.pic { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; }
.pic .media { position: relative; }
.pic .media > img, .pic .media > canvas { display: block; }
.page.is-pic::before { opacity: .45; }
.page.is-pic::after { opacity: calc(var(--tooth-o) * .9); }
body[data-theme="night"] .page.is-pic .media > img, body[data-theme="night"] .page.is-pic .media > canvas { filter: brightness(.9); }

/* =========================================================================
   SETTINGS SHEET
   ========================================================================= */
.sheet {
  position: absolute; left: 50%; bottom: 0; z-index: 40; width: min(600px, 100%);
  max-height: 86vh; overflow-y: auto; overscroll-behavior: contain;
  transform: translate(-50%, 104%); transition: transform .45s var(--ease-paper);
  background: var(--card); color: var(--ink); border-radius: 28px 28px 0 0;
  padding: 10px 26px calc(var(--safe-b) + 26px);
  box-shadow: 0 -18px 50px -20px rgba(var(--shadow), .5);
}
.sheet::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background-image: var(--tooth); background-size: 256px; opacity: var(--tooth-o); mix-blend-mode: overlay; pointer-events: none; }
.sheet.open { transform: translate(-50%, 0); }
.sheet-grip { width: 40px; height: 5px; border-radius: 5px; background: var(--rule); margin: 0 auto 14px; }
.set-row { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 12px; padding: 8px 0; position: relative; z-index: 1; }
.set-row > label { font-size: 13px; color: var(--ink-3); font-weight: 700; letter-spacing: .03em; }
#reader.is-comic .only-text, #reader.is-pdf .only-text, #reader:not(.is-comic) .only-comic { display: none !important; }
.seg { display: flex; background: var(--chip); border-radius: 14px; padding: 4px; gap: 2px; }
.seg button { flex: 1; min-height: 40px; border-radius: 11px; font-size: 14px; font-weight: 700; color: var(--ink-2); padding: 0 8px; transition: background-color .2s, color .2s, transform .2s var(--spring); }
.seg button.on { background: var(--btn); color: var(--ink); box-shadow: 0 1px 0 rgba(var(--shadow), .15), 0 4px 10px -6px rgba(var(--shadow), .5); }
.seg button:active { transform: scale(.96); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 42px; height: 42px; border-radius: 12px; background: var(--chip); font-family: var(--display); }
.swatches { display: flex; gap: 10px; }
.swatches button { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--ink-3); flex: 1; }
.swatches i { width: 100%; max-width: 76px; height: 48px; border-radius: 14px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); position: relative; overflow: hidden; }
.swatches i::after { content: "Aa"; position: absolute; inset: 0; display: grid; place-items: center; font-family: Literata, serif; font-size: 17px; font-style: normal; }
.swatches [data-theme="sage"] i  { background: linear-gradient(135deg, #f6eed6 55%, #cddcc2 55%); color: #2f2b22; }
.swatches [data-theme="paper"] i { background: #f5f0e6; color: #2a2620; }
.swatches [data-theme="aged"] i  { background: #ecdfc4; color: #33281b; }
.swatches [data-theme="night"] i { background: #23221f; color: #d6ccb9; }
.swatches button.on i { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }
.swatches button.on { color: var(--ink); }

input[type="range"] { -webkit-appearance: none; appearance: none; flex: 1; height: 30px; background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--chip) var(--fill, 50%)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; margin-top: -9px; background: var(--btn); box-shadow: 0 0 0 1px var(--rule), 0 3px 8px rgba(var(--shadow), .3); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--chip); }
input[type="range"]::-moz-range-progress { height: 4px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--btn); box-shadow: 0 0 0 1px var(--rule), 0 3px 8px rgba(var(--shadow), .3); }

/* =========================================================================
   DISCOVER
   ========================================================================= */
.overlay {
  position: fixed; inset: 0; z-index: 60; background: var(--desk);
  transform: translateY(100%); transition: transform .55s var(--ease-paper); visibility: hidden;
}
.overlay.open { transform: none; visibility: visible; }
.overlay::after { content: ""; position: absolute; inset: 0; background-image: var(--tooth); background-size: 256px; opacity: var(--tooth-o); mix-blend-mode: overlay; pointer-events: none; }
.disc-panel { position: relative; height: 100%; overflow-y: auto; padding: calc(var(--safe-t) + 16px) clamp(16px, 4.5vw, 60px) 60px; }
.disc-head { display: flex; gap: 10px; align-items: center; position: sticky; top: 0; z-index: 2; padding: 4px 0 12px; background: var(--desk); }
.disc-search { flex: 1; display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 20px; border-radius: 999px; background: var(--card); box-shadow: 0 2px 0 rgba(var(--shadow), .08), 0 10px 24px -18px rgba(var(--shadow), .6); }
.disc-search svg { color: var(--ink-3); }
.disc-search input { flex: 1; border: 0; background: none; outline: none; font: 600 16.5px var(--ui); color: var(--ink); min-width: 0; }
.disc-search input::placeholder { color: var(--ink-3); font-weight: 500; }
.disc-shelves { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 6px 0 4px; }
.disc-shelves button { height: 38px; padding: 0 16px; border-radius: 999px; background: var(--card); font-size: 14px; font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.disc-shelves button.on { background: var(--accent); color: var(--accent-ink); }
.disc-note { font-size: 13.5px; color: var(--ink-3); margin: 14px 0 24px; line-height: 1.5; max-width: 720px; }
.disc-grid { display: grid; gap: 30px 22px; grid-template-columns: repeat(auto-fill, minmax(clamp(124px, 15vw, 156px), 1fr)); }
.disc-item { display: flex; flex-direction: column; gap: 8px; text-align: left; animation: rise .45s var(--ease-paper) both; }
.disc-item .cover { border-radius: 4px 10px 10px 4px; }
.disc-item .t { font-family: var(--display); font-size: 15.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.disc-item .a { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.disc-item .get { align-self: flex-start; font-size: 13px; font-weight: 800; padding: 7px 14px; border-radius: 999px; background: var(--btn); color: var(--ink); box-shadow: 0 1px 0 rgba(var(--shadow), .12), 0 6px 14px -10px rgba(var(--shadow), .6); }
.disc-item .get.done { background: var(--accent); color: var(--accent-ink); }
.disc-item .get[disabled] { opacity: .6; }
.disc-more { margin: 32px auto 0; display: flex; }
.disc-status { grid-column: 1 / -1; text-align: center; color: var(--ink-3); font-family: var(--display); font-style: italic; padding: 40px 0; font-size: 17px; }

/* =========================================================================
   MENU + TOAST
   ========================================================================= */
.menu {
  position: fixed; z-index: 70; min-width: 230px; padding: 6px; border-radius: 18px;
  background: var(--card); box-shadow: 0 18px 40px -12px rgba(var(--shadow), .5), 0 0 0 1px var(--rule);
  animation: pop .22s var(--spring);
}
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
.menu button { display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 12px; font-size: 15px; font-weight: 600; }
.menu button:active { background: var(--chip); }
.menu .danger { color: #b23c28; }
body[data-theme="night"] .menu .danger { color: #e08a75; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; transition: all .4s var(--spring);
  background: var(--ink); color: var(--card); padding: 12px 20px; border-radius: 999px; font-size: 14px; font-weight: 700;
  pointer-events: none; max-width: calc(100vw - 32px); text-align: center;
}
.toast.on { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 760px) {
  .lib-hero { grid-template-columns: 1fr; }
  .lib-art { min-height: 260px; order: -1; }
  .lib-art img { object-position: 50% 58%; }
  .lib-art::before { background: linear-gradient(0deg, var(--card) 0%, color-mix(in srgb, var(--card) 40%, transparent) 8%, transparent 26%); }
  .continue { grid-template-columns: 1fr; text-align: center; padding: 24px; }
  .continue .meter { margin-inline: auto; }
  .set-row { grid-template-columns: 1fr; gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* =========================================================================
   DESIGNED COVERS — for books that arrive without artwork
   ========================================================================= */
.cover, .cv { container-type: inline-size; }
.gc { position: absolute; inset: 0; overflow: hidden; background: var(--bg); color: var(--fg); text-align: left; }
.gc-title { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
/* 1. banded paperback */
.gc-band .gc-top, .gc-band .gc-bot {
  position: absolute; left: 0; right: 0; height: 17%; display: flex; align-items: center; justify-content: center;
  padding: 0 8%; text-align: center; font: 700 5.4cqw/1.1 "Plus Jakarta Sans", sans-serif; letter-spacing: .14em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gc-band .gc-top { top: 0; }
.gc-band .gc-bot { bottom: 0; font-weight: 600; letter-spacing: .2em; opacity: .9; }
.gc-band .gc-top .gc-author { overflow: hidden; text-overflow: ellipsis; }
.gc-band .gc-mid {
  position: absolute; top: 17%; bottom: 17%; left: 0; right: 0; padding: 0 10%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4cqw; text-align: center;
  background: var(--fg); color: var(--bg); border-top: 1.6cqw solid var(--ac); border-bottom: 1.6cqw solid var(--ac);
}
.gc-band .gc-title { font: 500 12.5cqw/1.04 "Fraunces", Georgia, serif; letter-spacing: -.01em; -webkit-line-clamp: 4; }
.gc-band .gc-sub { font: italic 400 5.6cqw/1.25 "Fraunces", Georgia, serif; opacity: .8; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
/* 2. Swiss typographic */
.gc-swiss { padding: 10cqw 10cqw 9cqw; display: flex; flex-direction: column; }
.gc-swiss .gc-disc { position: absolute; width: 86cqw; height: 86cqw; right: -34cqw; bottom: -22cqw; border-radius: 50%; background: var(--ac); opacity: .92; }
.gc-swiss .gc-num { position: relative; font: 700 6cqw "Plus Jakarta Sans", sans-serif; letter-spacing: .06em; opacity: .75; min-height: 1em; }
.gc-swiss .gc-title { position: relative; margin-top: 7cqw; font: 800 14.5cqw/.94 "Plus Jakarta Sans", sans-serif; letter-spacing: -.045em; -webkit-line-clamp: 5; }
.gc-swiss .gc-author { position: relative; margin-top: auto; font: 600 6cqw/1.2 "Plus Jakarta Sans", sans-serif; max-width: 60%; }
/* 3. cloth library binding */
.gc-cloth { background: repeating-linear-gradient(45deg, rgba(255,255,255,.035) 0 1.5px, transparent 1.5px 4px), repeating-linear-gradient(-45deg, rgba(0,0,0,.06) 0 1.5px, transparent 1.5px 4px), var(--bg); }
.gc-cloth::before, .gc-cloth::after { content: ""; position: absolute; left: 0; right: 0; height: 1.2cqw; background: var(--ac); opacity: .85; }
.gc-cloth::before { top: 8%; box-shadow: 0 2.6cqw 0 -0.2cqw var(--ac); }
.gc-cloth::after { bottom: 8%; box-shadow: 0 -2.6cqw 0 -0.2cqw var(--ac); }
.gc-cloth .gc-label {
  position: absolute; left: 14%; right: 14%; top: 30%; padding: 7cqw 6cqw; text-align: center;
  display: flex; flex-direction: column; gap: 4cqw; align-items: center;
  border: .9cqw solid var(--ac); outline: .5cqw solid var(--ac); outline-offset: 1.6cqw; background: rgba(0,0,0,.14);
}
.gc-cloth .gc-title { color: var(--ac); font: 600 9.5cqw/1.12 "Fraunces", Georgia, serif; font-variant: small-caps; letter-spacing: .03em; -webkit-line-clamp: 4; }
.gc-cloth .gc-author { color: var(--ac); font: italic 400 5.4cqw/1.2 "Fraunces", Georgia, serif; opacity: .9; }
