:root {
  --bg: #0d0f14;
  --bg-2: #141821;
  --ink: #e9e2d3;
  --ink-soft: #b9b2a3;
  --ink-faint: #7d7768;
  --accent: #d8b46a;
  --accent-ink: #1a1408;
  --line: #2a2f3a;
  --you: #8fb3d9;
  --term: #7cf0a4;
  --term-bg: #07130c;
  --danger: #e07a6a;
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --mono: 'IBM Plex Mono', Consolas, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(ellipse at 50% -10%, #1c2333 0%, transparent 60%),
    radial-gradient(1px 1px at 20% 30%, #ffffff22 50%, transparent 51%),
    radial-gradient(1px 1px at 80% 60%, #ffffff1a 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 85%, #ffffff14 50%, transparent 51%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.65;
  min-height: 100vh;
}

button { font: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar-title { font-variant: small-caps; letter-spacing: .12em; color: var(--ink-soft); font-size: 17px; flex: 1; text-align: center; }
.library .bar-title { text-align: left; }
.bar-back { color: var(--ink-faint); text-decoration: none; font-size: 15px; }
.bar-back:hover { color: var(--ink); }
a.ghost { text-decoration: none; }
.ghost {
  background: transparent; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 14px; font-size: 15px;
}
.ghost:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ---------- page ---------- */
.page { max-width: 680px; margin: 0 auto; padding: 24px 20px 220px; }

.cover { text-align: center; padding: 12vh 0 6vh; }
.cover h1 { font-size: clamp(44px, 9vw, 72px); font-weight: 500; letter-spacing: .04em; margin: 8px 0 4px; line-height: 1.1; }
.ornament { color: var(--accent); font-size: 22px; }
.byline { color: var(--ink-faint); font-style: italic; margin: 0; }
.rule { width: 80px; height: 1px; background: var(--accent); margin: 32px auto 0; opacity: .6; }

.entry { animation: rise .6s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.chapter {
  text-align: center; margin: 64px 0 28px;
  font-variant: small-caps; letter-spacing: .14em; font-size: 24px; color: var(--accent);
}
.chapter::before, .chapter::after { content: '—'; margin: 0 .6em; opacity: .5; }

.prose p { margin: 0 0 1em; text-indent: 1.4em; }
/* the big first letter (and no indent) only where a chapter begins */
.chapter + .prose p:first-child { text-indent: 0; }
.chapter + .prose p:first-child::first-letter { font-size: 2.6em; float: left; line-height: .9; padding: 6px 8px 0 0; color: var(--accent); }

.note { color: var(--ink-soft); font-style: italic; margin: 1.2em 0; padding-left: 14px; border-left: 2px solid var(--line); }
.choice-made { color: var(--ink-faint); font-size: 16px; letter-spacing: .06em; margin: 1.6em 0; text-align: center; }
.choice-made::before { content: '› '; color: var(--accent); }

.theend { text-align: center; margin: 56px 0 24px; }
.theend-line { font-variant: small-caps; letter-spacing: .3em; color: var(--accent); font-size: 26px; }
.theend-btn { display: inline-block; margin-top: 28px; text-decoration: none; }

/* ---------- "book was updated" notice ---------- */
.updated {
  margin: 0 0 36px; padding: 16px 20px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--accent);
  font-size: 17px; color: var(--ink-soft);
}
.updated p { margin: 0 0 12px; }
.updated strong { color: var(--accent); font-weight: 600; }
.updated-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.updated .primary { font-size: 16px; padding: 8px 20px; }

/* ---------- dialogue ---------- */
.line { margin: 18px 0; }
.who { font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 2px; font-family: var(--mono); }
.npc .say { color: var(--ink); white-space: pre-line; }
.npc .say em { color: var(--ink-soft); }
.you { text-align: right; }
.you .say { color: var(--you); font-style: italic; display: inline-block; max-width: 85%; text-align: left; }
.you.pending .say { opacity: .55; }

.npc.terminal {
  font-family: var(--mono); font-size: 15px; line-height: 1.6;
  background: var(--term-bg); border: 1px solid #12301e; border-radius: 6px; padding: 10px 14px;
}
.npc.terminal .who { color: #3d8a5c; }
.npc.terminal .say { color: var(--term); text-shadow: 0 0 6px #7cf0a455; }

.thinking { color: var(--ink-faint); font-style: italic; font-size: 17px; margin: 18px 0; }
.thinking span { animation: blink 1.4s infinite both; }
.thinking span:nth-child(2) { animation-delay: .2s; }
.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* ---------- action dock ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  padding: 28px 20px 20px;
}
.dock-inner { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; align-items: center; }

.primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 10px 28px; font-size: 18px; font-weight: 600; letter-spacing: .03em;
}
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.option {
  width: 100%; text-align: left;
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 18px; font-size: 18px;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option::before { content: '› '; color: var(--accent); }

.composer { width: 100%; }
.composer-box {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 8px 8px 8px 16px;
}
.composer-box:focus-within { border-color: var(--ink-faint); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 18px; line-height: 1.45; max-height: 160px; padding: 6px 0;
}
.composer textarea::placeholder { color: var(--ink-faint); font-style: italic; }
.send { padding: 8px 18px; font-size: 16px; }
.composer-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 14px; color: var(--ink-faint); }
.linkish { background: none; border: 0; color: var(--ink-faint); text-decoration: underline; text-underline-offset: 3px; padding: 0; font-size: 14px; }
.linkish:hover { color: var(--ink); }

/* ---------- toast & dialog ---------- */
.toast {
  position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); z-index: 10;
  background: #2a1714; color: #f3d2cb; border: 1px solid #5a2c25; border-radius: 10px;
  padding: 10px 16px; font-size: 16px; max-width: calc(100% - 32px);
}
dialog {
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px 26px; max-width: 420px; width: calc(100% - 32px);
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 8px; font-weight: 500; }
dialog p { margin: 0 0 20px; color: var(--ink-soft); font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- library ---------- */
/* The landing page is a little lighter than the reading page, so the logo sits well on it. */
body.library {
  --bg: #1b1f28;
  --bg-2: #252a36;
  --line: #363c4a;
  background:
    radial-gradient(ellipse at 50% -10%, #2c3447 0%, transparent 60%),
    radial-gradient(1px 1px at 20% 30%, #ffffff22 50%, transparent 51%),
    radial-gradient(1px 1px at 80% 60%, #ffffff1a 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 85%, #ffffff14 50%, transparent 51%),
    var(--bg);
  background-attachment: fixed;
}
.site-logo { display: block; width: min(440px, 80vw); height: auto; margin: 0 auto 28px; }
.shelf-page { max-width: 1040px; margin: 0 auto; padding: 0 20px 80px; }
.shelf-hero { text-align: center; padding: 6vh 0 6vh; }
.shelf-hero h1 { font-size: clamp(40px, 7vw, 64px); font-weight: 500; margin: 6px 0 8px; letter-spacing: .03em; }
.shelf-hero p { color: var(--ink-soft); font-style: italic; max-width: 520px; margin: 0 auto; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 36px; }
.shelf-book {
  display: grid; grid-template-columns: 170px 1fr; gap: 24px; align-items: start;
  color: inherit; text-decoration: none; padding: 18px; border-radius: 16px; border: 1px solid transparent;
  transition: background .2s, border-color .2s;
}
.shelf-book:hover { background: var(--bg-2); border-color: var(--line); }
.shelf-book .cover-card { transition: transform .3s; }
.shelf-book:hover .cover-card { transform: translateY(-4px) rotate(-1deg); }
.shelf-info h2 { margin: 6px 0 2px; font-weight: 500; font-size: 28px; line-height: 1.15; }
.shelf-author { margin: 0 0 12px; color: var(--ink-faint); font-style: italic; }
.shelf-blurb { margin: 0 0 14px; color: var(--ink-soft); font-size: 18px; }
.shelf-status { display: block; font-size: 14px; color: var(--accent); letter-spacing: .04em; margin-bottom: 14px; }
.shelf-cta { display: inline-block; font-size: 16px; padding: 8px 20px; }
.shelf-empty { text-align: center; color: var(--ink-soft); grid-column: 1 / -1; }
.shelf-empty a { color: var(--accent); }

@media (max-width: 520px) {
  .shelf { grid-template-columns: 1fr; }
  .shelf-book { grid-template-columns: 110px 1fr; gap: 16px; padding: 10px; }
  .shelf-info h2 { font-size: 22px; }
  body { font-size: 18px; }
  .bar { padding: 8px 16px; }
  .page { padding: 16px 16px 220px; }
  .dock { padding: 24px 16px 14px; }
  .ghost { font-size: 13px; padding: 4px 10px; }
}

/* ---------- reading: one page at a time ---------- */
body.reading { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
body.reading .bar { position: static; flex: none; }
.reader { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: 16px 14px 0; }
.stage { flex: 1; min-height: 0; width: 100%; display: flex; justify-content: center; touch-action: pan-y; }
/* a page shaped like a book's (3:4), as tall as fits; narrower screens get the full width */
.book { position: relative; height: 100%; aspect-ratio: 3 / 4; max-width: 100%; perspective: 2400px; }
.sheet {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: 34px 42px 10px;
  background:
    linear-gradient(to right, #00000055, transparent 26px),
    linear-gradient(160deg, #1b202b, #151922 70%);
  border: 1px solid var(--line); border-left-color: #0a0c10;
  border-radius: 3px 12px 12px 3px;
  box-shadow: 0 18px 40px #0008, 4px 0 0 -1px #1d222d, 7px 1px 0 -2px #181c25;
}
.clip { flex: 1; min-height: 0; overflow: hidden; position: relative; }
.flow { column-fill: auto; will-change: transform; }
.folio { flex: none; height: 26px; line-height: 26px; display: flex; justify-content: center; font-size: 14px; color: var(--ink-faint); font-variant-numeric: oldstyle-nums; }
.folio-r { display: none; }

/* two pages side by side: an open book with a spine in the middle */
.book.spread { aspect-ratio: 3 / 2; }
.book.spread .sheet {
  padding: 34px 46px 10px;
  border-radius: 6px; border-left-color: var(--line);
  background:
    linear-gradient(to right, #0000 calc(50% - 34px), #0000004d calc(50% - 2px), #000000a0 50%, #0000004d calc(50% + 2px), #0000 calc(50% + 34px)),
    linear-gradient(to right, #00000040, #0000 22px calc(100% - 22px), #00000040),
    linear-gradient(170deg, #1b202b, #151922 70%);
  box-shadow: 0 18px 40px #0008, -4px 0 0 -1px #1d222d, 4px 0 0 -1px #1d222d, -7px 1px 0 -2px #181c25, 7px 1px 0 -2px #181c25;
}
.book.spread .folio { justify-content: space-between; padding: 0 22%; }
.book.spread .folio-r { display: inline; }

/* text size */
.bar-tools { display: flex; align-items: center; gap: 10px; }
.text-size { display: flex; gap: 4px; }
.text-size .ghost { padding: 3px 10px; line-height: 1.2; min-width: 38px; }
.text-size #fontDown { font-size: 14px; }
.text-size #fontUp { font-size: 19px; }
.text-size small { font-size: .75em; margin-left: 1px; }
.bar .short { display: none; }
@media (max-width: 560px) { .bar .long { display: none; } .bar .short { display: inline; } .reading .bar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; font-size: 15px; } .reading .bar { gap: 8px; padding: 8px 10px; } .reading .bar-back { white-space: nowrap; } }
.pager { flex: none; display: flex; align-items: center; gap: 18px; padding: 6px 0 0; font-size: 15px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.pg { background: none; border: 1px solid var(--line); color: var(--ink-soft); border-radius: 999px; width: 34px; height: 30px; font-size: 20px; line-height: 1; padding: 0 0 3px; }
.pg:hover:not(:disabled) { color: var(--ink); border-color: var(--ink-faint); }
.pg:disabled { opacity: .3; }
/* the way on: a larger gold arrow (gold buttons below the page mean it is the reader's turn) */
#nextBtn { width: 46px; height: 40px; font-size: 28px; padding: 0 0 4px 2px; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
#nextBtn:hover:not(:disabled) { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
#nextBtn:disabled { color: var(--ink-soft); border-color: var(--line); }

/* what may and may not be split between pages */
.reading .cover { min-height: 100%; padding: 0; display: flex; flex-direction: column; break-after: column; }
.reading .cover > .ornament { margin-top: auto; }
.reading .cover > .rule { margin-bottom: auto; }
.reading .cover > .updated { margin-bottom: auto; }
.reading .updated { margin: 36px 0 0; text-align: left; }
.reading .chapter { break-before: column; break-after: avoid; margin: 8px 0 28px; }
.reading .prose p { orphans: 2; widows: 2; }
.reading .prose img { max-width: 100%; max-height: 60vh; }
.reading .line, .reading .note, .reading .choice-made, .reading .theend, .reading .thinking { break-inside: avoid; }
.reading .who { break-after: avoid; }
#endMark { height: 0; }
/* No fade-in for new text here: browsers can fail to draw an animated block that is split across pages. */
.reading .entry { animation: none; }

/* the page turning over: still copies of pages ("snaps"), and a leaf that turns */
.snap, .leaf { position: absolute; top: 0; bottom: 0; pointer-events: none; }
.at-full { left: 0; right: 0; }
.at-left { left: 0; width: 50%; }
.at-right { left: 50%; width: 50%; }
.snap { overflow: hidden; }
.under { z-index: 2; }
.leaf > .snap { left: 0; right: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.leaf > .snap.backface { transform: rotateY(180deg); }
.snap > .sheet { left: 0; width: 100%; }
.show-left > .sheet, .show-right > .sheet { width: 200%; }
.show-right > .sheet { left: -100%; }
.leaf { z-index: 3; transform-style: preserve-3d; transform-origin: left center; }
.leaf > .snap::after { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0; animation: leaf-shade .56s ease-in both; }
.leaf > .snap:first-child::after { background: linear-gradient(to left, #0000, #0009); }
.leaf > .snap.backface::after { background: linear-gradient(to right, #0000, #0009); animation-direction: reverse; }
.leaf.turn-away { animation: turn-away .56s cubic-bezier(.4, .1, .3, 1) both; }
.leaf.turn-in { animation: turn-in .56s cubic-bezier(.4, .1, .3, 1) both; }
.leaf.turn-in > .snap::after { animation-direction: reverse; }
.leaf.turn-over-left { animation: turn-away .56s cubic-bezier(.4, .1, .3, 1) both; }
.leaf.turn-over-right { transform-origin: right center; animation: turn-over-right .56s cubic-bezier(.4, .1, .3, 1) both; }
.leaf.turn-over-right > .snap:first-child::after { background: linear-gradient(to right, #0000, #0009); }
.leaf.turn-over-right > .snap.backface::after { background: linear-gradient(to left, #0000, #0009); }
@keyframes turn-away { from { transform: rotateY(0); } to { transform: rotateY(-180deg); } }
@keyframes turn-in { from { transform: rotateY(-180deg); } to { transform: rotateY(0); } }
@keyframes turn-over-right { from { transform: rotateY(0); } to { transform: rotateY(180deg); } }
@keyframes leaf-shade { from { opacity: 0; } to { opacity: 1; } }
.clip.fade .flow { animation: page-fade .18s ease both; }
@keyframes page-fade { from { opacity: 0; } to { opacity: 1; } }

/* the dock under the page */
body.reading .dock { position: static; flex: none; background: none; padding: 12px 20px 16px; }
.reading .dock-inner { display: grid; }
.actions { grid-area: 1 / 1; width: 100%; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.actions.veiled { visibility: hidden; }
.turn { grid-area: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px; }
.turn.off, .turn .off { visibility: hidden; }
.reading .toast { bottom: auto; top: 64px; }

@media (max-width: 520px) {
  .reader { padding: 10px 8px 0; }
  .sheet { padding: 22px 22px 6px; }
  body.reading .dock { padding: 10px 12px 12px; }
}

/* ---------- footer & privacy page ---------- */
.site-foot { text-align: center; color: var(--ink-faint); font-size: 14px; padding: 0 20px 40px; }
.site-foot a { color: var(--ink-soft); }
.privacy { padding-bottom: 80px; }
.privacy h1 { font-weight: 500; font-size: 40px; margin: 24px 0 8px; }
.privacy h2 { font-weight: 500; font-size: 24px; margin: 32px 0 8px; color: var(--accent); }
.privacy p, .privacy li { color: var(--ink-soft); }
.privacy li { margin-bottom: 10px; }
.privacy strong { color: var(--ink); font-weight: 600; }
.privacy-lead { font-style: italic; }
