/* The Ghoul Society theme — aged-paper ground, dark ink, moss accent.
   The page is BRIGHT so the near-black cover art reads like dark paintings
   in a lit gallery; the brand bands (topbar/bottomnav/footbar) and the
   splash stay dark so the identity holds.
   Mobile-first; desktop centers the column at >=720px. */

/* ================================================================
   == BRAND — swap when Gio ships art ==
   Every brand color lives in this block. Change these variables and
   the whole site reskins — nothing below hardcodes a hue.
   (Exception by design: the dark brand bands + splash, scoped below.)
   ================================================================ */
:root {
  /* Light gallery palette (2026-09-02): aged-paper ground, dark green-black
     ink, moss/thorn accent deep enough to carry white text. */
  --ground: #efe9da;        /* page — aged paper */
  --ground-2: #faf6ec;      /* raised surfaces: cards, sheets */
  --ground-3: #e2dbc6;      /* pressed / inset surfaces */
  --bone: #211f15;          /* primary text — dark ink (name kept for churn-free swap) */
  --bone-soft: #59543f;     /* secondary text */
  --bone-faint: #8b8468;    /* hints, placeholders */
  --blood: #4d6428;         /* accent — thorn moss, dark enough for white text */
  --blood-bright: #6a8a38;  /* accent hover/glow */
  --line: #d9d1b9;          /* faint UI lines */
  --good: #2e7d54;
  --warn: #a06f14;          /* dark amber — readable on paper */
  --bad: #b23a2e;
  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --radius: 14px;
  --nav-h: 60px;
  --top-h: 56px;
  --foot-h: 26px;

  /* Aliases: the screen files style themselves with these names (with stale
     hex fallbacks baked in), so they MUST resolve here or the fallbacks win —
     that is exactly how the retired blood-red leaked back onto the live site. */
  --accent: var(--blood);
  --bg: var(--ground);
  --card: var(--ground-2);
  --ink: var(--bone);
  --ink-soft: var(--bone-soft);
  --ink-faint: var(--bone-faint);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--ground); color: var(--bone);
  overscroll-behavior: none;
  color-scheme: light;
}
::selection { background: var(--blood); color: #fff; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea {
  font: inherit; color: var(--bone); background: var(--ground-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--bone-faint); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blood); border-color: var(--blood); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--bone-soft); margin: 12px 0 4px; }
a { color: var(--bone); }
a:hover { color: var(--blood-bright); }

/* ---------------------------------------------------------------- topbar */
/* BRAND BAND — stays dark on the light page (the logo.svg is bone-colored
   and needs the dark bar). Hardcoded so light tokens cannot leak in. */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h); z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  background: #0f120c; border-bottom: 1px solid #232a1d; padding: 0 12px;
}
.topbar-logo { height: 26px; width: auto; cursor: pointer; display: block; }
.iconbtn { position: relative; padding: 8px; color: #cfc7ae; border-radius: 10px; }
.iconbtn:active { background: #181f12; }
.badge {
  position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; border-radius: 8px;
  background: #8fae5a; color: #0f120c; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ---------------------------------------------------------------- screen */
.screen {
  position: fixed; top: var(--top-h); bottom: calc(var(--nav-h) + var(--foot-h)); left: 0; right: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.screen.noscroll { overflow: hidden; }
.pad { padding: 16px; }

/* ------------------------------------------------------------- bottomnav */
/* BRAND BAND — stays dark; aged-bone icons, moss glow on the active one. */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h); z-index: 30;
  display: flex; align-items: stretch; background: #0f120c; border-top: 1px solid #232a1d;
  padding-bottom: env(safe-area-inset-bottom);
}
.navbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10.5px; font-weight: 600; color: #736f5e; min-height: 44px;
}
.navbtn.active { color: #cfc7ae; }
.navbtn.active svg { stroke: #8fae5a; }

/* Persistent owner/legal strip: sits between the screen and the bottom nav.
   The router renders inside #screen only, so this never moves or unmounts.
   BRAND BAND — dark, so it reads as one block with the bottomnav. */
.footbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 29;
  height: var(--foot-h); display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 10.5px; color: #736f5e; text-align: center; padding: 0 10px;
  background: #0f120c; border-top: 1px solid #232a1d;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.footbar a { color: #cfc7ae; font-weight: 600; text-decoration: none; }
.footbar a:hover { color: #8fae5a; }

/* ------------------------------------------------------ cards + buttons */
.card {
  background: var(--ground-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--blood); color: #fff; font-weight: 700; border-radius: 12px;
  padding: 13px 18px; width: 100%; margin-top: 14px;
}
.btn:active { opacity: .85; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.blood { background: var(--blood); }        /* explicit alias for the accent */
.btn.bone { background: var(--bone); color: var(--ground-2); }  /* dark ink bg, paper text */
.btn.ghost { background: transparent; color: var(--bone); border: 1.5px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn.small { width: auto; padding: 8px 14px; font-size: 13.5px; margin-top: 0; }

.chip {
  display: inline-block; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--ground-2); color: var(--bone-soft); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.on { background: var(--blood); color: #fff; border-color: var(--blood); }
.chip.good { background: #dfecdd; color: var(--good); border-color: #b7d4b3; }
.chip.warn { background: #f4e9cd; color: var(--warn); border-color: #e0cb92; }
.chip.bad { background: #f4ded8; color: var(--bad); border-color: #e3b3a8; }
.chiprow { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; scrollbar-width: none; }
.chiprow::-webkit-scrollbar { display: none; }

/* --------------------------------------------------------- sheet + toast */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--ground-2); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(46, 42, 25, .25); max-height: 80vh; overflow-y: auto;
  animation: sheetup .18s ease-out;
}
@keyframes sheetup { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet h3 { margin: 0 0 6px; font-family: var(--serif); }
.sheet-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 14px 10px; border-radius: 12px; font-weight: 600; font-size: 15px;
}
.sheet-item:active { background: var(--ground-3); }
.sheet-item .ico { width: 38px; height: 38px; border-radius: 10px; background: var(--ground-3); display: flex; align-items: center; justify-content: center; color: var(--blood); flex: none; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(23, 21, 13, .45); z-index: 39; }

/* Dark pill on the light page — deliberate, it pops. */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + var(--foot-h) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--bone); color: var(--ground-2); padding: 10px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; z-index: 60; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 20px rgba(46, 42, 25, .3);
}
.hidden { display: none !important; }

.empty { text-align: center; color: var(--bone-faint); padding: 48px 24px; }
.empty img, .empty svg { height: 56px; opacity: .5; margin-bottom: 10px; }

/* ------------------------------------------------------------ typography */
h1 { font-size: 24px; margin: 0 0 12px; color: var(--bone); font-family: var(--serif); font-weight: 700; letter-spacing: .01em; }
h2 { font-size: 18px; margin: 0 0 10px; color: var(--bone); font-family: var(--serif); }
.muted { color: var(--bone-soft); font-size: 13.5px; }
.faint { color: var(--bone-faint); font-size: 12.5px; }
.price { color: var(--bone); font-weight: 800; font-size: 18px; }
.price.free { color: var(--good); }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------------------------------------------------- book grid + covers */
.book-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px 14px; padding: 16px;
}
.book-card { display: block; text-align: left; padding: 0; }
/* Dark covers float on the paper — a grounded two-layer shadow. */
.book-cover {
  aspect-ratio: 2 / 3; width: 100%; object-fit: cover; display: block;
  border-radius: 10px; border: 1px solid var(--line); background: var(--ground-2);
  box-shadow: 0 8px 20px rgba(46, 42, 25, .28), 0 2px 6px rgba(46, 42, 25, .18);
}
.book-card:active .book-cover { opacity: .85; }
.book-title {
  font-family: var(--serif); font-size: 14.5px; font-weight: 700; color: var(--bone);
  margin: 8px 0 1px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-author { color: var(--bone-faint); font-size: 12px; }
.book-price { color: var(--bone-soft); font-size: 12.5px; font-weight: 700; margin-top: 2px; }

/* Big cover on the book detail screen */
.cover-hero {
  width: min(58vw, 260px); aspect-ratio: 2 / 3; object-fit: cover; display: block;
  margin: 18px auto 14px; border-radius: 12px; border: 1px solid var(--line);
  box-shadow: 0 16px 36px rgba(46, 42, 25, .32), 0 4px 10px rgba(46, 42, 25, .2);
}

/* ------------------------------------------------------------- reading view */
/* Long-form typography: serif, generous leading, a narrow measure.
   Dark ink on paper — the natural reading direction. */
.reader {
  font-family: var(--serif); font-size: 18px; line-height: 1.8; color: var(--bone);
  max-width: 620px; margin: 0 auto; padding: 26px 20px 72px;
}
.reader p { margin: 0 0 1.15em; }
.reader h1, .reader h2, .reader h3 { font-family: var(--serif); color: var(--bone); }
.reader h2 { font-size: 21px; margin: 1.6em 0 .7em; }
.reader-chapter { font-size: 12px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--blood); margin: 0 0 6px; font-family: 'Segoe UI', system-ui, sans-serif; }
.reader hr { border: none; border-top: 1px solid var(--line); margin: 2em auto; width: 40%; }

/* ------------------------------------------------------------------ splash */
/* Full-screen brand cover shown on real page loads (markup in index.html,
   behaviour in /js/splash.js). Static dark art — layered gradients, no video.
   Sits above the sheet (40) and toast (60).
   THE SPLASH STAYS DARK: every color here is a hardcoded night literal
   (ground #0a0d09, card #10140d, bone #cfc7ae, soft #a29a82, line #232a1d,
   moss #5c7337, glow #8fae5a) so the light tokens cannot leak in. */
.splash {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(90% 55% at 50% 34%, rgba(179, 18, 47, .16) 0%, rgba(179, 18, 47, 0) 60%),
    radial-gradient(130% 100% at 50% 30%, #16161f 0%, #0a0d09 55%, #050508 100%);
  opacity: 1; transition: opacity .38s ease;
  /* Failsafe: if splash.js never runs, the cover still lifts on its own.
     splash.js sets style.animation='none' the moment it boots. */
  animation: splash-failsafe .5s ease 8s forwards;
}
@keyframes splash-failsafe { to { opacity: 0; visibility: hidden; pointer-events: none; } }
.splash.splash-out { opacity: 0; pointer-events: none; }
.splash ::selection { background: #5c7337; color: #fff; }

.splash-inner {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 460px; padding: 0 28px;
}
.splash-logo {
  position: relative; width: min(38vw, 150px);
  touch-action: none; -webkit-touch-callout: none;
  user-select: none; -webkit-user-select: none;
}
.splash-logo img {
  display: block; width: 100%; height: auto; pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 0 26px rgba(179, 18, 47, .35));
  animation: splash-in .6s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes splash-in { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }

/* Hold feedback — deliberately invisible until ~1.5s into a hold. */
.splash-hold {
  position: absolute; left: 8%; right: 8%; bottom: -26px; height: 3px;
  border-radius: 3px; background: rgba(232, 226, 208, .12);
  opacity: 0; transition: opacity .25s ease; pointer-events: none;
}
.splash.splash-holding .splash-hold { opacity: 1; }
.splash-hold i {
  display: block; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, #5c7337, #8fae5a);
  box-shadow: 0 0 10px rgba(214, 27, 61, .8);
  transform: scaleX(0); transform-origin: left center;
}

.splash-tag {
  margin-top: 40px; font-family: var(--serif); font-size: 15px; letter-spacing: .34em;
  text-transform: uppercase; color: #a29a82; text-align: center;
  animation: splash-fade .5s ease .35s both;
}
@keyframes splash-fade { from { opacity: 0; } to { opacity: 1; } }

.splash-skip {
  position: absolute; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom));
  padding: 7px 16px; border-radius: 999px; font-size: 12.5px; font-weight: 700; letter-spacing: .04em;
  color: #cfc7ae; background: rgba(232, 226, 208, .1); border: 1px solid #232a1d;
  opacity: 0; transition: opacity .4s ease; z-index: 2; pointer-events: none;
}
.splash-skip.show { opacity: 1; pointer-events: auto; }

/* Developer-access card (built by splash.js after a 5s hold). */
.splash-unlock {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(5, 5, 8, .7); backdrop-filter: blur(3px);
  animation: splash-fade .18s ease both;
  /* Above .splash-inner (z1, the emblem hold-target) and .splash-skip (z2) —
     without this the emblem paints OVER the card and swallows the taps on the
     code input and Unlock button. Bit Gio on his phone 2026-09-02. */
  z-index: 5;
}
.splash-card {
  width: 100%; max-width: 340px; background: #10140d;
  border: 1px solid #232a1d; border-radius: 18px; padding: 20px 18px 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .7);
}
.splash-card h2 { margin: 0 0 4px; font-size: 18px; color: #cfc7ae; }
.splash-card p { margin: 0 0 12px; font-size: 13px; color: #a29a82; }
.splash-card input { letter-spacing: .1em; }
.splash-card .btn { margin-top: 10px; }
.splash-err { margin-top: 10px; font-size: 13px; font-weight: 700; color: #cf5044; text-align: center; }
.splash-card.shake { animation: splash-shake .42s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes splash-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* Splash dev-card form controls: pin the night palette so the light
   base input/button rules above cannot bleach the card. */
.splash input {
  background: #181f12; color: #cfc7ae; border: 1px solid #232a1d;
}
.splash input::placeholder { color: #736f5e; }
.splash input:focus { outline: 2px solid #5c7337; border-color: #5c7337; }
.splash .btn.blood { background: #5c7337; color: #fff; }
.splash .btn.ghost { background: transparent; color: #cfc7ae; border: 1.5px solid #232a1d; }

/* Reduced motion: no drift, no shake — just the mark and a quick fade. */
@media (prefers-reduced-motion: reduce) {
  .splash { transition: opacity .15s ease; }
  .splash-logo img, .splash-tag, .splash-unlock { animation: none; opacity: 1; }
  .splash-card.shake { animation: none; }
  .sheet { animation: none; }
}
.splash.splash-still .splash-logo img { animation: none; opacity: 1; }
@supports (height: 100dvh) {
  .splash { height: 100dvh; }
}

/* ------------------------------------------------------------- desktop */
@media (min-width: 720px) {
  .screen { max-width: 680px; margin: 0 auto; left: 50%; transform: translateX(-50%); }
  .topbar, .bottomnav, .footbar { max-width: 680px; left: 50%; transform: translateX(-50%); }
  .topbar { border-left: 1px solid #232a1d; border-right: 1px solid #232a1d; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (min-width: 1100px) {
  .screen, .topbar, .bottomnav, .footbar { max-width: 860px; }
}

/* ------------------------------------------------------- center plus (nav) */
/* PadLaser-style [+]: a raised moss circle in the middle nav slot.
   Lives ON the dark band, so its colors are band literals — the current
   dark-theme look, glow included. */
.plusbtn { flex: 1; }
.plus-circle {
  width: 46px; height: 46px; border-radius: 50%;
  background: #5c7337; color: #0f120c;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 14px rgba(143, 174, 90, .35);
  transform: translateY(-6px);
}
.plusbtn:active .plus-circle { background: #8fae5a; }

/* ------------------------------------------------------------- read screen */
.read-head { margin: 4px 2px 12px; font-family: var(--serif); font-weight: 600; }
.read-row {
  display: flex; align-items: center; gap: 12px; padding: 10px;
  margin-bottom: 10px; cursor: pointer;
}
.read-cover {
  width: 52px; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--line); flex: none;
  box-shadow: 0 3px 8px rgba(46, 42, 25, .22);
}
.read-meta { flex: 1; min-width: 0; }
.read-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.read-author { font-size: 12.5px; color: var(--bone-faint); }

/* --------------------------------------------------------- splash film */
/* The splash stays DARK by design (the film + emblem are night pieces),
   independent of the app theme around it. */
.splash-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #0a0d09; pointer-events: none;
}
.splash-inner { position: relative; z-index: 1; }

/* ------------------------------------------- light-ground screen overrides */
/* The screen modules inject their own <style> AFTER this sheet, so the two
   fixes below need !important. Both retint hardcoded dark-era shadows. */
/* account.js .devcard glows old blood-red rgba(179,18,47,.14) — retint moss. */
.devcard { box-shadow: 0 0 0 3px rgba(77, 100, 40, .16) !important; }
/* _shared.js hover shadow is rgba(0,0,0,.5) black — too heavy on paper. */
.tgs-bookcard:hover .bc-cover { box-shadow: 0 12px 26px rgba(46, 42, 25, .32) !important; }
/* Resting float for the shared book cards (they declare none of their own),
   matching .book-cover so dark covers lift off the paper everywhere. */
.tgs-bookcard .bc-cover { box-shadow: 0 8px 20px rgba(46, 42, 25, .28), 0 2px 6px rgba(46, 42, 25, .18); }
