/*
 * Quill.
 *
 * One rule governs every decision below: THE READING SURFACE STAYS QUIET. The
 * reader is reading a novel, not operating an app, and every affordance that
 * says "chat client" cheapens the object. So the prose gets no motion beyond
 * the caret that shows it is still arriving.
 *
 * The magic goes in the seams instead — the Forge filling in as it is defined,
 * the cover developing as it generates, a beat's title arriving as it
 * lands, the twist dial as a physical instrument. That is where craft is
 * allowed to show.
 *
 * Palette matches docs/architecture.html so the product and its own design doc
 * are recognisably the same object.
 */

/* ── tokens ─────────────────────────────────────────────────────────────── */

:root {
  color-scheme: light;
  --paper: #f4f1f6;
  --surface: #fbfafc;
  --raised: #ffffff;
  --ink: #1b1520;
  --ink2: #4a3f52;
  --ink3: #786c81;
  --rule: #ded6e3;
  --rule2: #ede7f0;
  --gilt: #8a6529;
  --gilt-lit: #b58e45;
  --ok: #3b6650;
  --bad: #93334a;

  --shadow-1: 0 1px 2px rgba(27, 21, 32, 0.05);
  --shadow-2: 0 1px 2px rgba(27, 21, 32, 0.05), 0 8px 24px -12px rgba(27, 21, 32, 0.18);
  --shadow-3: 0 2px 4px rgba(27, 21, 32, 0.08), 0 18px 38px -16px rgba(27, 21, 32, 0.42);

  /* Motion. One easing for entrances, one for exits, two durations. Anything
     needing a third is usually a design problem rather than a timing one. */
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
  --fast: 140ms;
  --slow: 420ms;

  --ring: 0 0 0 2px var(--paper), 0 0 0 4px var(--gilt);
  --measure: 720px;
  --header-h: 54px;

  /* The book is set in the serif. The reader's own words — what they type and
     what they asked for — are set in the system sans, so "your voice" and "the
     book's voice" never blur, the way a chat and a page never do. */
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #141019;
    --surface: #1b1523;
    --raised: #221b2b;
    --ink: #efe9f2;
    --ink2: #b8adc0;
    --ink3: #8c8095;
    --rule: #332b3d;
    --rule2: #282132;
    --gilt: #d3ab68;
    --gilt-lit: #e6c88f;
    --ok: #82b79a;
    --bad: #e27c92;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px -14px rgba(0, 0, 0, 0.7);
    --shadow-3: 0 2px 6px rgba(0, 0, 0, 0.5), 0 20px 44px -18px rgba(0, 0, 0, 0.85);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #141019;
  --surface: #1b1523;
  --raised: #221b2b;
  --ink: #efe9f2;
  --ink2: #b8adc0;
  --ink3: #8c8095;
  --rule: #332b3d;
  --rule2: #282132;
  --gilt: #d3ab68;
  --gilt-lit: #e6c88f;
  --ok: #82b79a;
  --bad: #e27c92;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px -14px rgba(0, 0, 0, 0.7);
  --shadow-3: 0 2px 6px rgba(0, 0, 0, 0.5), 0 20px 44px -18px rgba(0, 0, 0, 0.85);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
    "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--gilt); text-decoration-thickness: 1px; text-underline-offset: 3px; }
h1, h2, h3 { font-weight: 600; line-height: 1.2; text-wrap: balance; margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* One focus treatment everywhere, and it is always visible. */
:where(a, button, input, textarea, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: 4px;
}

/* ── the site header ────────────────────────────────────────────────────────
   Every page is reachable from every other page. Slim, sticky and quiet: it is
   a way out of a page, not a thing to look at. */

.site {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--rule2);
}

.site-inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 24px;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 17.5px;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
}

.wordmark .mark {
  width: 8px;
  height: 8px;
  background: var(--gilt);
  transform: rotate(45deg);
  transition: transform var(--slow) var(--ease);
}

.wordmark:hover .mark { transform: rotate(135deg); }

.site-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: auto; }

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 14.5px;
  color: var(--ink3);
  text-decoration: none;
  border: 1px solid transparent;
  transition: color var(--fast) var(--ease-out), background var(--fast) var(--ease-out),
    border-color var(--fast) var(--ease-out);
}

.site-nav .nav-button {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: none;
  font-size: 14.5px;
  color: var(--ink3);
}

.site-nav a:hover, .site-nav .nav-button:hover:not(:disabled) {
  color: var(--ink);
  background: var(--surface);
  border-color: transparent;
}
.site-nav a.cta { color: var(--gilt); border-color: var(--rule); }
.site-nav a.cta:hover { border-color: var(--gilt); background: var(--raised); }

/* Light or dark. The icon shows what a click switches TO, and which one shows
   is decided by the same three states as the colour tokens — so it is right
   from the first paint, before any script has run. */
.theme-toggle {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  min-height: 38px;
  margin-left: 2px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: none;
  color: var(--ink3);
}

.theme-toggle:hover:not(:disabled) { color: var(--ink); background: var(--surface); border-color: transparent; }
.theme-toggle .icon-sun { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* The switch itself eases; nothing else on the page learns to animate colour. */
@media (prefers-reduced-motion: no-preference) {
  :root.theming,
  :root.theming *,
  :root.theming *::before,
  :root.theming *::after {
    transition: background-color 280ms ease, color 280ms ease, border-color 280ms ease,
      fill 280ms ease, stroke 280ms ease !important;
  }
}

@media (max-width: 560px) {
  :root { --header-h: 48px; }
  .site-inner { padding: 0 18px; gap: 6px; }
  .site-nav a.nav-shelf { display: none; } /* the wordmark is the way home */
  .site-nav a { padding: 0 10px; font-size: 14px; }
}

.wrap { max-width: var(--measure); margin: 0 auto; padding: 0 24px 64px; }

/* A page that ends in a pinned composer ends AT the composer. The old 140-160px
   of bottom padding dated from before the composer was pinned, when it kept the
   last lines out from under it; afterwards it was only scroll with nothing in
   it — a test on a phone found most of a screen of empty page below the box. */
.wrap:has(.composer:not([hidden])) { padding-bottom: 0; }

@media (max-width: 560px) {
  body { font-size: 18px; }
  .wrap { padding: 0 18px 48px; }
}

.mast {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 34px 0 22px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 34px;
}

.mast h1 { font-size: clamp(22px, 4.5vw, 27px); letter-spacing: -0.012em; }
.quiet { color: var(--ink3); font-size: 15px; }

/* A standfirst under a mast: what this page is, in one sentence. */
.lede {
  color: var(--ink2);
  font-size: 17px;
  line-height: 1.55;
  max-width: 42em;
  margin: -16px 0 32px;
}

/* An anchor that has to carry the weight of a primary button. */
.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 5px;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  text-decoration: none;
  font-size: 16px;
  transition: background var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out);
}

.button-link:hover { background: var(--gilt); border-color: var(--gilt); color: #fff; }

.empty { color: var(--ink3); font-size: 17px; line-height: 1.55; max-width: 36em; margin: 6px 0 0; }

.empty-shelf { padding: 12px 0 80px; max-width: 44em; }
.empty-shelf .opening-sub { margin-bottom: 26px; }

/* ── the prose. No motion here, by design. ──────────────────────────────── */

.prose { font-size: 20px; line-height: 1.75; }
.prose p { margin: 0 0 1.15em; text-wrap: pretty; }
.prose p:first-of-type::first-line { font-variant-caps: small-caps; letter-spacing: 0.04em; }
/* A chapter opens in small caps; a message from the Architect does not. */
.prose.reply p:first-of-type::first-line { font-variant-caps: normal; letter-spacing: 0; }

@media (max-width: 560px) { .prose { font-size: 19px; } }

.prose strong { font-weight: 650; }
.prose ul, .prose ol { margin: 0 0 1.15em; padding-left: 1.3em; }
.prose li { margin: 0 0 0.4em; }
.prose li::marker { color: var(--gilt); }

.scene-break { margin: 0.3em 0 1.45em; text-align: center; color: var(--ink3); }
.scene-break::before { content: "\2042"; font-size: 1.1em; }

.beat + .beat,
.streaming.follows { margin-top: 44px; padding-top: 44px; border-top: 1px solid var(--rule2); }

.beat, .streaming, .exchange { scroll-margin-top: calc(var(--header-h) + 14px); }

/* A beat landing: the prose it streamed stays exactly where it is, and only
   its title arrives. Moving the text the reader is in the middle of — as a
   whole-beat entrance once did — is the one motion the page must never make. */
.beat.landed .beat-head .t { animation: fade-in var(--slow) var(--ease) both; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.beat-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--ink3);
  font-size: 12.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.beat-head .rule { flex: 1; height: 1px; background: var(--rule); }
.beat-head .elapsed { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

/* The text is finished; the page is being saved. Quieter than writing — the
   reader's attention belongs on the last line and on what to do next. */
.streaming.saving .beat-head { color: var(--ink3); }
.streaming.saving .beat-head .spinner { opacity: 0.6; }
#queued { margin-top: 16px; }

.spinner,
.working .spinner {
  flex: none;
  align-self: center;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid var(--rule);
  border-top-color: var(--gilt);
  animation: spin 820ms linear infinite;
}

/* ── the reader's own words ───────────────────────────────────────────────
   Above each beat, what they asked for — right-aligned and in their own
   typeface, like a message they sent, because it is one. */

.asked {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: fit-content;
  max-width: min(88%, 36em);
  margin: 0 0 22px auto;
}

.asked-text {
  margin: 0;
  padding: 9px 14px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink2);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  overflow: hidden;
}

.asked.open .asked-text { display: block; -webkit-line-clamp: unset; line-clamp: unset; }

.asked-more {
  min-height: 0;
  margin-top: 3px;
  padding: 3px 6px;
  border: 0;
  background: none;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink3);
}

.asked-more:hover:not(:disabled) { color: var(--gilt); background: none; }

.hide-asked .reader .asked { display: none; }

/* ── hooks: the Narrator's own invitations ──────────────────────────────── */

.hooks { display: flex; flex-direction: column; gap: 10px; margin: 28px 0 0; }

.hook {
  appearance: none;
  text-align: left;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 13px 16px;
  cursor: pointer;
  transition: border-color var(--fast) var(--ease-out),
    transform var(--fast) var(--ease-out), background var(--fast) var(--ease-out);
  animation: rise var(--slow) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 55ms);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

.hook:hover:not(:disabled) { border-color: var(--gilt); background: var(--raised); transform: translateX(3px); }
.hook:active:not(:disabled) { transform: translateX(1px) scale(0.995); }
.hook::before { content: "—  "; color: var(--gilt); }
.hook:disabled { opacity: 0.45; cursor: default; }

/* ── controls ───────────────────────────────────────────────────────────── */

.composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: linear-gradient(to bottom, transparent, var(--paper) 26px);
  padding: 30px 0 max(14px, env(safe-area-inset-bottom));
  margin-top: 10px; /* the 30px of fade above the card is the gap already */
}

/* One card: what you write on top, how much and when underneath. It replaces
   three rows of separate controls that took a fifth of a phone screen. */
.composer-card {
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow-2);
  transition: border-color var(--fast) var(--ease-out), box-shadow var(--fast) var(--ease-out);
}

.composer-card:focus-within {
  border-color: var(--gilt);
  box-shadow: var(--shadow-2), 0 0 0 3px color-mix(in srgb, var(--gilt) 16%, transparent);
}

.composer-card textarea,
.composer-card textarea:hover,
.composer-card textarea:focus {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 14px 16px 6px;
  border: 0;
  border-radius: 14px 14px 0 0;
  background: transparent;
  resize: none;
  font-family: var(--sans);
  font-size: 16px; /* under 16px, iOS zooms the page on focus */
  line-height: 1.5;
}

.composer-card textarea:focus-visible { box-shadow: none; outline: none; }
.seed-card textarea, .seed-card textarea:focus { min-height: 104px; font-size: 17px; }

.composer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 8px 10px;
}

.composer-bar .send { min-height: 40px; padding: 8px 18px; border-radius: 10px; }
.bar-note { font-family: var(--sans); font-size: 13px; }
.bar-end { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.count {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--ink3);
  font-variant-numeric: tabular-nums;
}

.count[data-full="true"] { color: var(--bad); }

.kbd { font-family: var(--sans); font-size: 12px; color: var(--ink3); white-space: nowrap; }

kbd {
  font: inherit;
  padding: 0 5px;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
}

@media (pointer: coarse) { .kbd { display: none; } }
@media (max-width: 560px) { .bar-note { display: none; } }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea {
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 12px 14px;
  resize: vertical;
  transition: border-color var(--fast) var(--ease-out), background var(--fast) var(--ease-out);
  min-width: 0;
}

input::placeholder, textarea::placeholder { color: var(--ink3); opacity: 0.85; }
input[type="text"]:hover, input[type="email"]:hover, input[type="password"]:hover, input[type="number"]:hover, textarea:hover { border-color: var(--ink3); }
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="number"]:focus, textarea:focus { border-color: var(--gilt); background: var(--raised); }

button {
  appearance: none;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  border-radius: 4px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  padding: 11px 16px;
  min-height: 44px; /* a real touch target */
  transition: border-color var(--fast) var(--ease-out),
    background var(--fast) var(--ease-out), transform var(--fast) var(--ease-out);
}

button:hover:not(:disabled) { border-color: var(--gilt); background: var(--raised); }
button:active:not(:disabled) { transform: scale(0.985); }
button:disabled { opacity: 0.42; cursor: default; }

button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.primary:hover:not(:disabled) { background: var(--gilt); border-color: var(--gilt); color: #fff; }

/* How much to write, as one segmented control. Real radio inputs underneath,
   so arrow keys and screen readers get a radio group for free. */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--rule2);
}

.seg label { position: relative; display: flex; }

.seg input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.seg span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 7px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink3);
  transition: background var(--fast) var(--ease-out), color var(--fast) var(--ease-out),
    box-shadow var(--fast) var(--ease-out);
}

.seg label:hover span { color: var(--ink); }
.seg input:checked + span { color: var(--ink); background: var(--raised); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--rule); }
.seg input:focus-visible + span { box-shadow: var(--ring); }

@media (max-width: 380px) { .seg span { padding: 0 9px; font-size: 13px; } }

/* Under the latest beat: the two moves that act on it. */
.after-beat { display: flex; flex-wrap: wrap; gap: 2px 18px; margin: 26px 0 0; }

.text-button {
  min-height: 36px;
  padding: 6px 2px;
  border: 0;
  background: none;
  font-size: 15px;
  color: var(--ink3);
}

.text-button:hover:not(:disabled) { color: var(--gilt); background: none; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  color: var(--ink3);
  background: none;
  border-color: transparent;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink3);
  cursor: pointer;
}

.switch input { width: 16px; height: 16px; margin: 0; accent-color: var(--gilt); }

/* ── working states ─────────────────────────────────────────────────────────
   A chapter takes the better part of a minute. Silence for that long reads as
   broken, so the page says what it is doing and how long it has been at it. */

.working {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0;
  color: var(--ink2);
  font-size: 16px;
  animation: rise var(--slow) var(--ease) both;
}

.working .spinner {
  flex: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1.5px solid var(--rule);
  border-top-color: var(--gilt);
  animation: spin 820ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.working .elapsed { color: var(--ink3); font-size: 14px; font-variant-numeric: tabular-nums; }

/* The shape of prose about to arrive, so the page has weight before the first
   token lands. */
.skeleton { display: flex; flex-direction: column; gap: 12px; margin: 26px 0; }

.skeleton span {
  height: 13px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--rule2), var(--rule), var(--rule2));
  background-size: 220% 100%;
  animation: sheen 1.5s var(--ease-out) infinite;
}

.skeleton span:nth-child(2) { width: 94%; animation-delay: 120ms; }
.skeleton span:nth-child(3) { width: 76%; animation-delay: 240ms; }

@keyframes sheen {
  from { background-position: 120% 0; }
  to { background-position: -60% 0; }
}

.caret::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.05em;
  background: var(--gilt);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1.1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

/* ── notices ────────────────────────────────────────────────────────────── */

.notice {
  border-left: 2px solid var(--gilt);
  padding: 4px 0 4px 16px;
  color: var(--ink2);
  margin: 24px 0;
  font-size: 17px;
  animation: rise var(--slow) var(--ease) both;
}

.notice.err { border-left-color: var(--bad); color: var(--bad); }

/* A transient failure is a toast, not a permanent red paragraph in the page. */
.toasts {
  position: fixed;
  left: 50%;
  top: calc(var(--header-h) + 12px);
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--raised);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--gilt);
  border-radius: 5px;
  padding: 12px 15px;
  font-size: 15.5px;
  box-shadow: var(--shadow-3);
  animation: toast-in var(--slow) var(--ease) both;
}

.toast.err { border-left-color: var(--bad); }
.toast { display: flex; align-items: flex-start; gap: 10px; }
.toast p { flex: 1; margin: 0; line-height: 1.45; user-select: text; }
.toast-close {
  flex: none;
  width: 30px;
  height: 30px;
  min-height: 30px;
  margin: -5px -8px -5px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--ink3);
}
.toast-close:hover:not(:disabled) { color: var(--ink); background: var(--surface); }
.toast.leaving { animation: toast-out var(--fast) var(--ease-out) both; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ── contents ─────────────────────────────────────────────────────────────
   It navigates; rewinding is a separate control on each entry. The old rail
   rewound the book when you clicked a chapter, hid itself below 1140px, and
   squeezed its entries until their lines overlapped. */

.toc-rail { display: none; }

@media (min-width: 1280px) {
  .toc-rail {
    display: block;
    position: fixed;
    top: calc(var(--header-h) + 28px);
    left: max(20px, calc(50vw - var(--measure) / 2 - 272px));
    width: 236px;
    max-height: calc(100vh - var(--header-h) - 56px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    padding-right: 6px;
  }
  .site-nav .nav-button { display: none; }
}

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink3);
}

.toc-list { list-style: none; margin: 0; padding: 0; }

.toc-item {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  border-left: 2px solid var(--rule);
  transition: border-color var(--fast) var(--ease-out);
}

.toc-item[aria-current="true"] { border-left-color: var(--gilt); }

.toc-link {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1.9em 1fr;
  padding: 7px 6px 7px 10px;
  font-size: 14.5px;
  line-height: 1.35;
  color: var(--ink3);
  text-decoration: none;
  border-radius: 0 6px 6px 0;
  transition: color var(--fast) var(--ease-out), background var(--fast) var(--ease-out);
}

.toc-link:hover { color: var(--ink); background: var(--surface); }
.toc-item[aria-current="true"] .toc-link { color: var(--ink); }
.toc-n { padding-top: 1px; font-size: 12px; font-variant-numeric: tabular-nums; }
.toc-t { overflow-wrap: anywhere; text-wrap: pretty; }
.toc-s { margin-left: 7px; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.7; white-space: nowrap; }

/* Laid over the end of the entry rather than beside it, so a control that is
   invisible until hovered does not narrow every title in the list. */
.toc-rewind {
  position: absolute;
  top: 4px;
  right: 2px;
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 16px;
  color: var(--ink3);
  opacity: 0;
  transition: opacity var(--fast) var(--ease-out), color var(--fast) var(--ease-out);
}

.toc-item:hover .toc-rewind, .toc-rewind:focus-visible { opacity: 1; }
.toc-rewind:hover:not(:disabled) { color: var(--gilt); background: var(--raised); }
.toc-item:hover .toc-link { padding-right: 36px; }
@media (hover: none) { .toc-rewind { opacity: 0.7; } .toc-link { padding-right: 36px; } }

.toc-alt, .toc-restore {
  flex-basis: 100%;
  min-height: 0;
  padding: 1px 10px 7px 2.6em;
  border: 0;
  background: none;
  text-align: left;
  font-size: 13.5px;
  font-style: italic;
  line-height: 1.35;
  color: var(--ink3);
}

.toc-restore { padding: 8px 10px 8px 12px; }
.toc-alt:hover:not(:disabled), .toc-restore:hover:not(:disabled) { color: var(--gilt); background: none; }
.toc-aside { border-left-style: dashed; margin-top: 6px; }
.toc-empty { padding: 6px 12px; font-size: 14px; }

.sheet {
  width: min(420px, calc(100vw - 24px));
  max-height: min(80vh, 760px);
  margin: auto 16px auto auto;
  padding: 0 16px 22px 18px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: var(--shadow-3);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet::backdrop { background: rgb(20 16 25 / 0.36); backdrop-filter: blur(2px); }
.sheet[open] { animation: sheet-in var(--slow) var(--ease) both; }
/* Pinned, so jumping the list to the current beat never carries the close
   button out of reach. */
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -16px 8px -18px;
  padding: 14px 16px 12px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule2);
}

@keyframes sheet-in { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }

.sheet-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-title h2 { font-size: 20px; }

@media (max-width: 560px) {
  .sheet {
    width: 100vw;
    max-width: 100vw;
    max-height: 84vh;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    padding-bottom: max(22px, env(safe-area-inset-bottom));
  }
  .sheet[open] { animation-name: sheet-up; }
}

@keyframes sheet-up { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }

/* ── the shelf ──────────────────────────────────────────────────────────── */

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 34px 24px;
}

@media (max-width: 420px) { .shelf { grid-template-columns: repeat(2, 1fr); gap: 26px 16px; } }

.spine {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  animation: rise var(--slow) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

.jacket {
  display: block;
  text-decoration: none;
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-2);
  transition: transform var(--slow) var(--ease), box-shadow var(--slow) var(--ease);
}

.jacket:hover { transform: translateY(-4px); box-shadow: var(--shadow-3); }
.jacket img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* The cover developing as it generates, rather than snapping in. */
.jacket img.developing, .scene-art.developing { animation: develop 900ms var(--ease) both; }

@keyframes develop {
  from { opacity: 0; filter: blur(14px) saturate(0.4); transform: scale(1.04); }
  to { opacity: 1; filter: none; transform: none; }
}

.unjacketed {
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: 100%;
  padding: 18px 16px;
  background: linear-gradient(160deg, var(--rule2), var(--surface));
}

.unjacketed-title { font-size: 16px; line-height: 1.25; color: var(--ink2); text-wrap: balance; }

.spine-title { font-size: 16.5px; line-height: 1.3; color: var(--ink); text-decoration: none; text-wrap: pretty; }
.spine-title:hover { color: var(--gilt); }
.spine-meta { margin: 0; font-size: 13px; }
.draw-cover { align-self: flex-start; font-size: 13px; padding: 8px 12px; min-height: 38px; }

/* The cover belongs beside the title the way a jacket belongs on a book you
   are already holding: present, small, and not standing between the reader and
   the first line. It used to be 260px centred, which was a splash screen. */
.book-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 30px 0 22px;
  margin-bottom: 34px;
  border-bottom: 1px solid var(--rule);
}

.book-head img {
  flex: none;
  width: 54px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-2);
}

.book-head h1 { font-size: clamp(22px, 4.5vw, 27px); letter-spacing: -0.012em; }
.book-head .quiet { margin: 4px 0 0; font-size: 14px; }

.scene-art {
  display: block;
  width: 100%;
  height: auto;
  /* Space reserved before the picture arrives, so it cannot push the text
     the reader is in the middle of. */
  aspect-ratio: 1216 / 832;
  object-fit: cover;
  background: var(--surface);
  margin: 28px 0 4px;
  border-radius: 4px;
  border: 1px solid var(--rule);
}

.illustrate { font-size: 13px; padding: 8px 13px; min-height: 38px; margin-top: 14px; color: var(--ink3); }
.illustrate:hover { color: var(--ink); }

/* ── the Forge ──────────────────────────────────────────────────────────── */

.opening-prompt {
  font-size: clamp(21px, 3.6vw, 26px);
  line-height: 1.35;
  color: var(--ink);
  text-wrap: balance;
  margin: 8px 0 14px;
  animation: rise var(--slow) var(--ease) both;
}

.opening-sub { color: var(--ink2); font-size: 17px; margin: 0 0 22px; max-width: 40em; }

.from-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

.from-head .quiet { font-size: 13px; }

.exchange + .exchange { margin-top: 44px; padding-top: 40px; border-top: 1px solid var(--rule2); }

.gate { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 40px; }

@media (max-width: 560px) {
  .gate { flex-direction: column; }
  .gate > button { width: 100%; }
}

/* The Forge has no masthead, so its first exchange needs room of its own once
   the opening prompt has gone. */
.forge-layout { padding-top: 26px; }

/* Talk it through, or edit it yourself: one switch, above both. */
.forge-views { margin: 0 0 26px; }

@media (max-width: 560px) {
  .forge-views .seg { display: flex; }
  .forge-views .seg label { flex: 1 1 0; }
  .forge-views .seg span { width: 100%; justify-content: center; }
}

/* ── the Forge, as a making ───────────────────────────────────────────────
   The conversation on the left; the book it is making on the right, editable
   from the first turn. On narrow screens the same panel lives in a sheet. */

.wrap.wide { max-width: var(--measure); }

.forge-layout { display: block; }

.book-panel { display: none; }

@media (min-width: 1180px) {
  .wrap.wide { max-width: 1200px; }
  .forge-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 390px;
    gap: 52px;
    align-items: start;
  }
  .book-panel {
    display: block;
    position: sticky;
    top: calc(var(--header-h) + 20px);
    max-height: calc(100vh - var(--header-h) - 40px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    padding: 0 6px 0 26px;
    border-left: 1px solid var(--rule);
  }
  .site-nav #book-open { display: none; }
  /* The header's edges follow the page's, or the wordmark floats mid-screen. */
  body:has(.wrap.wide) .site-inner { max-width: 1200px; }
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.panel-head h2 {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gilt);
}

.panel-seal { font-size: 13.5px; min-height: 30px; }
.book-sheet .panel-head h2 { display: none; }
.book-sheet .panel-head:has(.panel-seal[hidden]) { display: none; }

.panel-empty { color: var(--ink3); font-size: 15px; line-height: 1.55; margin: 8px 0 0; }

/* Inside the panel every field stacks: label over control, whatever the
   viewport says, because the panel is narrow even on a wide screen. */
.panel .spread { gap: 6px; margin: 4px 0 0; }
.panel .field { grid-template-columns: 1fr; gap: 6px; padding: 12px 0; }
.panel .field > label { padding-top: 0; font-size: 14px; }
.panel .field .help { grid-column: 1; font-size: 13px; }
.panel .field input[type="text"], .panel .field textarea { font-size: 15px; padding: 9px 12px; }
.panel .field textarea { min-height: 64px; }

.panel-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 0 16px;
  background: var(--paper);
  border-top: 1px solid var(--rule2);
}

/* How much of the plan to see — asked first, because a spoiler cannot be unseen. */
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 26px 0 0;
  padding: 0;
  border: 0;
}

.modes legend {
  padding: 0;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--ink3);
}

.mode {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px 15px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease-out), background var(--fast) var(--ease-out),
    box-shadow var(--fast) var(--ease-out);
}

.mode input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.mode-title { font-size: 17px; color: var(--ink); }
.mode-detail { font-size: 14px; line-height: 1.45; color: var(--ink3); }
.mode:hover { border-color: var(--ink3); }
.mode:has(input:checked) { border-color: var(--gilt); background: var(--raised); box-shadow: var(--shadow-1); }
.mode:has(input:checked) .mode-title::before { content: "\25C6  "; color: var(--gilt); font-size: 12px; }
.mode:has(input:focus-visible) { box-shadow: var(--ring); }

@media (max-width: 560px) { .modes { grid-template-columns: 1fr; } }

/* The decision each turn puts to the reader, as cards to take with a tap. */
.choices { display: flex; flex-direction: column; gap: 10px; margin: 26px 0 0; }

.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  width: 100%;
  min-height: 0;
  padding: 15px 18px 16px;
  text-align: left;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--surface);
  animation: rise var(--slow) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 70ms);
  transition: border-color var(--fast) var(--ease-out), background var(--fast) var(--ease-out),
    transform var(--fast) var(--ease-out), box-shadow var(--fast) var(--ease-out), opacity var(--fast) var(--ease-out);
}

.choice-label { font-size: 17.5px; line-height: 1.3; color: var(--ink); }
.choice-detail { font-size: 15px; line-height: 1.5; color: var(--ink2); }

.choice:hover:not(:disabled) {
  border-color: var(--gilt);
  background: var(--raised);
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}

.choice.chosen { border-color: var(--gilt); background: var(--raised); opacity: 1; }
.choice:disabled:not(.chosen) { opacity: 0.35; }

.choice-extras { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice.ghost { border-style: dashed; background: transparent; padding: 11px 16px 12px; }
.choice.ghost .choice-label { font-size: 15.5px; }
.choice.ghost .choice-detail { font-size: 13.5px; color: var(--ink3); }

.rework { margin: 22px 0 0; }

.queued-note {
  margin: 2px 0 0;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--gilt);
  animation: rise var(--slow) var(--ease) both;
}

@keyframes flash {
  0% { color: var(--gilt); }
  100% { color: var(--ink); }
}

/* ── the Codex spread ───────────────────────────────────────────────────── */

.spread { display: flex; flex-direction: column; gap: 28px; margin: 8px 0 40px; }

.spread-group > h3,
.spread-group > summary {
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gilt);
  margin: 0 0 12px;
}

/* In the panel the groups fold, so a forty-field book reads as seven headings. */
.spread-group > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 13px 0;
  cursor: pointer;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.spread-group > summary::-webkit-details-marker { display: none; }

.spread-group > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid var(--ink3);
  border-bottom: 1.5px solid var(--ink3);
  transform: rotate(-45deg);
  transition: transform var(--fast) var(--ease-out);
}

.spread-group[open] > summary::after { transform: rotate(45deg); }
.spread-group > summary:hover { color: var(--gilt-lit); }
.spread-group.pointed > summary { animation: flash 1.6s var(--ease-out) both; }

.group-peek {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink2);
}

.spread-group[open] > summary .group-peek { display: none; }

.group-mine {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--ink3);
}

/* Something the reader set, and the Architect now keeps. */
.yours {
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--gilt);
  border: 1px solid color-mix(in srgb, var(--gilt) 45%, transparent);
  vertical-align: 1px;
}

/* What the Architect just changed, flashed once. */
.field.fresh > label { animation: flash 1.6s var(--ease-out) both; }
.field.fresh input[type="text"], .field.fresh textarea { animation: fresh-bg 1.8s var(--ease-out) both; }

@keyframes fresh-bg {
  0% { background: color-mix(in srgb, var(--gilt) 14%, var(--surface)); }
  100% { background: var(--surface); }
}

.sealed-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin: 6px 0 10px;
  padding: 12px 14px;
  border: 1px dashed var(--rule);
  border-radius: 10px;
  color: var(--ink3);
}

.sealed-note p { flex: 1 1 200px; margin: 0; font-size: 14px; line-height: 1.45; }
.sealed-icon { display: inline-flex; color: var(--gilt); }
.sealed-note .text-button { min-height: 32px; font-size: 14px; }
.text-button.danger { color: var(--bad); }

/* One of a few, or several at once: pronouns, a type, a personality. */
.picks { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.pick {
  min-height: 34px;
  padding: 5px 12px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink3);
  background: transparent;
}

.pick[aria-pressed="true"] {
  color: var(--ink);
  border-color: var(--gilt);
  background: var(--raised);
  box-shadow: var(--shadow-1);
}

.traits .pick[aria-pressed="true"]::after { content: " \00D7"; color: var(--ink3); }
.picks .pick-other { flex: 1 1 120px; min-width: 110px; font-size: 14px; padding: 7px 12px; }
/* Pronouns: three picks and a short box, all on one line where it fits. */
.picks:not(.traits):has(> .pick:nth-of-type(3):last-of-type) .pick-other { flex: 0 1 130px; }

.field {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  padding: 15px 0;
  border-top: 1px solid var(--rule2);
}

@media (min-width: 720px) {
  .field { grid-template-columns: 200px minmax(0, 1fr); gap: 7px 24px; align-items: start; }
  .field .help { grid-column: 2; }
}

.field > label { font-size: 15px; color: var(--ink2); padding-top: 11px; }
.field .help { font-size: 13.5px; color: var(--ink3); line-height: 1.45; margin: 0; }
.field input[type="text"], .field textarea { width: 100%; font-size: 16px; }
.field textarea { min-height: 74px; }

.heat { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.heat button {
  font-size: 12.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 9px 13px;
  min-height: 40px;
  color: var(--ink3);
}

.heat button[aria-pressed="true"] { color: var(--ink); border-color: var(--gilt); background: var(--raised); }
.heat .derived { font-size: 14px; color: var(--gilt); margin-left: 4px; }

.dial { display: flex; flex-direction: column; gap: 9px; }

.dial input[type="range"] {
  width: 100%;
  appearance: none;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--rule), var(--gilt));
  outline: none;
}

.dial input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--raised);
  border: 2px solid var(--gilt);
  cursor: grab;
  box-shadow: var(--shadow-2);
  transition: transform var(--fast) var(--ease-out);
}

.dial input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.12); cursor: grabbing; }

.dial input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--raised);
  border: 2px solid var(--gilt);
  cursor: grab;
}

.bands {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink3);
  gap: 6px;
}

.bands span { transition: color var(--fast) var(--ease-out); }
.bands span[data-on="true"] { color: var(--gilt); }

.dial-reading { font-size: 15px; color: var(--ink2); margin: 0; }
.dial-reading b { color: var(--ink); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.chip {
  font-size: 14px;
  padding: 6px 11px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink2);
  display: inline-flex;
  gap: 8px;
  align-items: center;
  animation: rise var(--fast) var(--ease) both;
}

.chip button { border: none; background: none; padding: 0; min-height: 0; font-size: 16px; line-height: 1; color: var(--ink3); }
.chip button:hover { color: var(--bad); background: none; }
.chips input[type="text"] { flex: 1 1 160px; font-size: 15px; padding: 8px 12px; }

.toggle { display: inline-flex; gap: 10px; align-items: center; font-size: 15px; color: var(--ink2); cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--gilt); }

/* Solid, with a rule above it. It used to fade in from transparent, which let
   the spread scroll up underneath the note field and read as half-erased. */
.spread-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  gap: 14px 20px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 16px 0 20px;
  background: var(--paper);
  border-top: 1px solid var(--rule);
}

.note-field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 260px; min-width: 0; }
.note-field > span { font-size: 13px; color: var(--ink3); }
.note-field input[type="text"] { width: 100%; font-size: 15px; }

.note-buttons { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.spread-actions:not([hidden]) { animation: rise var(--slow) var(--ease) both; }

@media (max-width: 560px) {
  .spread-actions { gap: 10px; padding: 12px 0 max(14px, env(safe-area-inset-bottom)); }
  .note-field > span { display: none; }
  .note-buttons { width: 100%; justify-content: space-between; }
}

/* The admin demo says what it is, once, above everything. */
.demo-banner {
  margin: 22px 0 0;
  padding: 10px 14px;
  border: 1px dashed var(--gilt);
  border-radius: 10px;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink2);
  background: var(--surface);
}

.demo-banner b { color: var(--gilt); }

/* ── small shared pieces ─────────────────────────────────────────────────── */

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gilt);
}

.text-link { font-size: 15px; }

/* ── how the Forge works: a real sequence, so it is numbered ─────────────── */

.how {
  list-style: none;
  counter-reset: how;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 24px;
  padding: 0;
}

.how li {
  counter-increment: how;
  position: relative;
  padding: 11px 13px 12px 40px;
  border: 1px solid var(--rule2);
  border-radius: 12px;
  background: var(--surface);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink3);
}

.how li::before {
  content: counter(how);
  position: absolute;
  left: 13px;
  top: 12px;
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--paper);
  background: var(--gilt);
}

.how b { display: block; margin-bottom: 1px; font-weight: 600; color: var(--ink); }

@media (max-width: 760px) {
  .how { grid-template-columns: 1fr; gap: 6px; }
  .how li { padding: 8px 12px 9px 38px; }
  .how li::before { top: 9px; }
  .how b { display: inline; }
}

/* A Forge picked up again. */
.resumed-note {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 14px;
  margin: 0 0 18px;
  padding: 10px 12px;
  border-left: 2px solid var(--gilt);
  background: var(--surface);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink2);
}

.resumed-note span { flex: 1 1 260px; }
.resumed-note .text-button { min-height: 30px; padding: 2px; font-size: 14.5px; }

/* ── writing it yourself ──────────────────────────────────────────────────── */

.from-scratch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--rule2);
}

.from-scratch p { flex: 1 1 300px; margin: 0; font-size: 15px; line-height: 1.5; color: var(--ink3); }
.from-scratch b { font-weight: 600; color: var(--ink); }

/* Back on the opening with things already set by hand. */
.opening-pins {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 14px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-left: 2px solid var(--gilt);
  background: var(--surface);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink2);
}

.opening-pins .text-button { min-height: 32px; padding: 2px; font-size: 14.5px; color: var(--gilt); }

/* Your book as the whole page. The column matches the conversation's, so
   switching views does not move the reader's eye. */
.forge-edit { min-width: 0; }

.edit-intro { margin: 0 0 20px; max-width: 40em; font-size: 16px; line-height: 1.6; color: var(--ink2); }
.edit-intro .needed-tag { margin-left: 0; }

/* Room for a label column here, the way the Codex page lays out the same form. */
@media (min-width: 720px) {
  .forge-edit .panel .field { grid-template-columns: 190px minmax(0, 1fr); gap: 7px 24px; padding: 14px 0; }
  .forge-edit .panel .field > label { padding-top: 10px; font-size: 15px; }
  .forge-edit .panel .field .help { grid-column: 2; }
}

/* ── the gate: what a book cannot start without ─────────────────────────── */

/* Dashed, like an empty slot: something still to fill, never an error. */
.needed-tag {
  margin-left: 8px;
  padding: 1px 7px;
  border: 1px dashed var(--ink3);
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink3);
  white-space: nowrap;
  vertical-align: 1px;
}

.field[data-required]:not(.needed) .needed-tag { display: none; }

.group-needed {
  padding: 0 6px;
  border: 1px dashed currentColor;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink3);
  white-space: nowrap;
}

/* Where "Still needed" takes the reader. */
.field.jumped > label { animation: flash 1.6s var(--ease-out) both; }
.field.jumped input[type="text"], .field.jumped textarea { animation: fresh-bg 1.8s var(--ease-out) both; }

.gate-missing {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 12px;
  margin: 0;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink3);
}

.gate-missing button {
  min-height: 30px;
  padding: 2px 0;
  border: 0;
  background: none;
  font-size: 13.5px;
}

.gate-missing .needed-link {
  color: var(--ink);
  text-decoration: underline dotted var(--ink3);
  text-underline-offset: 3px;
}

.gate-missing .needed-link:hover:not(:disabled) { color: var(--gilt); text-decoration-color: var(--gilt); background: none; }
.gate-missing .fill-missing { color: var(--gilt); }
.exchange.loaded .gate-missing { margin-top: 12px; }
/* In the foot it is one line, and sits beside Start wherever there is room. */
.panel-foot .gate-missing { flex: 1 1 260px; }
.gate .gate-missing { margin-top: 2px; }

/* ── starting from a Codex ───────────────────────────────────────────────── */

.from-codex { margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--rule2); }

.import-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }

.import-row input[type="text"] {
  flex: 1 1 220px;
  min-width: 0;
  font-family: var(--sans);
  font-size: 15px;
  padding: 10px 13px;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px dashed var(--rule);
  border-radius: 4px;
  font-size: 15px;
  color: var(--ink2);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease-out), color var(--fast) var(--ease-out);
}

.file-button:hover { border-color: var(--gilt); color: var(--ink); }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-button:focus-within { box-shadow: var(--ring); }

/* The Codex a reader is starting from, in the conversation column. */
.exchange.loaded {
  padding: 22px 22px 20px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  animation: rise var(--slow) var(--ease) both;
}

.exchange.loaded + .exchange { border-top: 0; }
.loaded h2 { margin: 4px 0 12px; font-size: clamp(22px, 3.6vw, 28px); letter-spacing: -0.012em; }
.loaded p:not(.eyebrow) { margin: 0 0 10px; font-size: 16px; line-height: 1.55; color: var(--ink2); }
.loaded-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 16px; }

.lines-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  margin-top: 16px;
  padding: 10px 12px;
  border-left: 2px solid var(--gilt);
  background: var(--paper);
  font-size: 14.5px;
  color: var(--ink2);
}

/* ── the share sheet ─────────────────────────────────────────────────────── */

.share-intro { margin: 0 0 16px; font-size: 15px; line-height: 1.5; color: var(--ink2); }

.share-code {
  margin: 0 0 12px;
  padding: 14px;
  border: 1px dashed var(--rule);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 28px;
  letter-spacing: 0.14em;
  color: var(--ink);
  user-select: all;
}

.share-link { display: flex; gap: 8px; margin-bottom: 14px; }
.share-link input[type="text"] { flex: 1; min-width: 0; font-family: var(--sans); font-size: 14px; padding: 10px 12px; }
.share-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; font-size: 15px; }

/* ── the Codex page's own actions ────────────────────────────────────────── */

.codex-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin: -12px 0 30px; }

/* ── a shared Codex, as a public page ────────────────────────────────────── */

.shared-card {
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
  padding: 34px 0 26px;
  border-bottom: 1px solid var(--rule);
}

.shared-jacket {
  width: 100%;
  height: auto;
  aspect-ratio: 832 / 1216;
  border-radius: 4px;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-3);
  animation: develop 900ms var(--ease) both;
}

.shared-text h1 { margin: 6px 0 12px; font-size: clamp(28px, 5vw, 40px); letter-spacing: -0.015em; }
.shared-back { margin: 0 0 14px; font-size: 18px; line-height: 1.6; color: var(--ink2); text-wrap: pretty; }
.shared-facts { margin: 0 0 12px; font-family: var(--sans); font-size: 13.5px; color: var(--ink3); }

.shared-tropes,
.lead-traits { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }

.shared-tropes li,
.lead-traits li {
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink2);
}

.shared-leads { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 26px 0 20px; }
.lead-card { padding: 16px 18px; border: 1px solid var(--rule2); border-radius: 14px; background: var(--surface); }
.lead-card h2 { margin: 0 0 3px; font-size: 21px; }
.lead-line { margin: 0 0 8px; font-family: var(--sans); font-size: 13.5px; color: var(--gilt); }
.lead-role { margin: 0 0 10px; font-size: 15px; line-height: 1.5; color: var(--ink2); }
.shared-where { margin: 0 0 22px; font-size: 16px; color: var(--ink2); }
.shared-where .eyebrow { margin-right: 8px; }
.shared-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin: 6px 0 14px; }
.shared-actions a.text-button { display: inline-flex; align-items: center; text-decoration: none; }
.shared-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.08em; color: var(--ink2); }

/* On a phone the jacket and the title share the top row, and the back cover
   gets the full width below. A narrow text column beside the jacket turned
   the back cover into a long, skinny strip. */
@media (max-width: 620px) {
  .shared-card {
    grid-template-columns: 96px minmax(0, 1fr);
    grid-template-areas: "jacket eyebrow" "jacket title" "back back" "facts facts" "tropes tropes";
    gap: 0 16px;
    padding-top: 24px;
  }
  .shared-text { display: contents; }
  .shared-jacket { grid-area: jacket; align-self: start; }
  .shared-text .eyebrow { grid-area: eyebrow; align-self: end; }
  .shared-text h1 { grid-area: title; align-self: start; font-size: 26px; }
  .shared-back { grid-area: back; margin-top: 18px; font-size: 16.5px; }
  .shared-facts { grid-area: facts; }
  .shared-tropes { grid-area: tropes; }
  .shared-leads { grid-template-columns: 1fr; }
}

/* ── signing in ──────────────────────────────────────────────────────────── */

.signin { padding-top: 48px; }

.landing-title {
  margin: 6px 0 14px;
  font-size: clamp(28px, 5.4vw, 40px);
  line-height: 1.12;
  letter-spacing: -0.018em;
  color: var(--ink);
}

.signin .eyebrow { margin-top: 8px; }

.signin-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 420px;
  margin-top: 30px;
  padding: 24px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.signin-card .notice { margin: 0; font-size: 15px; }

.google-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--raised);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  text-decoration: none;
  transition: border-color var(--fast) var(--ease-out);
}

.google-button:hover { border-color: var(--ink3); }
.google-button:focus-visible { box-shadow: var(--ring); outline: none; }

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}

.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

.signin-form { display: flex; flex-direction: column; gap: 8px; }
.signin-form label { font-family: var(--sans); font-size: 13.5px; color: var(--ink2); }
.signin-form input { font-family: var(--sans); font-size: 16px; padding: 11px 13px; }
.signin-form #code { font-size: 22px; letter-spacing: 0.3em; font-variant-numeric: tabular-nums; }
.signin-form .primary { margin-top: 4px; }
.signin-form .sent { margin: 0 0 4px; font-size: 15.5px; line-height: 1.5; color: var(--ink2); }
.signin-again { display: flex; flex-wrap: wrap; gap: 0 16px; }
.signin-again .text-button { font-size: 14px; min-height: 32px; }
.signin-small { margin-top: 18px; font-size: 14px; }

.notice.ok { border-left-color: var(--ok); }
.notice.welcome a { color: var(--gilt); }

/* ── the account: the one place ink is shown ──────────────────────────────── */

.account section { margin-top: 36px; }
.account h2 { font-size: 19px; margin-bottom: 10px; }

.ink-well {
  padding: 22px 24px 20px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
}

.ink-amount {
  margin: 4px 0 2px;
  font-size: 56px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.ink-refill { margin: 6px 0 16px; color: var(--ink2); font-size: 16px; }

.ink-costs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 20px;
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--rule2);
  font-family: var(--sans);
  font-size: 13.5px;
}

.ink-costs div { display: flex; justify-content: space-between; gap: 12px; }
.ink-costs dt { color: var(--ink3); }
.ink-costs dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }

.plan-now p { margin: 0 0 12px; color: var(--ink2); }
.plan-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 12px; }

.ledger-list { list-style: none; margin: 0; padding: 0; }

.ledger-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: baseline;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule2);
  font-size: 15.5px;
}

.ledger-when { font-family: var(--sans); font-size: 13px; white-space: nowrap; }
.ledger-delta { min-width: 3.5ch; text-align: right; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.ledger-delta.plus { color: var(--ok); }
.ledger-delta.minus { color: var(--ink2); }

.signout { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-top: 36px; }
.signout .version { flex-basis: 100%; margin: 12px 0 0; font-family: var(--sans); font-size: 12.5px; }

/* ── password forms ───────────────────────────────────────────────────────── */

.signin-modes { display: flex; }
.signin-modes label { flex: 1 1 0; }
.signin-modes span { width: 100%; justify-content: center; }
.password-label { display: flex; align-items: baseline; justify-content: space-between; }
.password-label .text-button { min-height: 28px; padding: 0; font-size: 13.5px; }
.password-field { position: relative; display: flex; }
.password-field input { flex: 1; padding-right: 64px; }
.reveal-password {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  min-height: 32px;
  padding: 0 8px;
  font-family: var(--sans);
  font-size: 13px;
}
.field-hint { margin: 0; font-family: var(--sans); font-size: 13px; color: var(--ink3); }
.form-error {
  margin: 2px 0 0;
  padding: 8px 10px;
  border-left: 2px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 7%, transparent);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--bad);
}
.form-error .text-button { min-height: 0; padding: 0; font-size: 14px; color: var(--gilt); }
#check-email .text-button, #reset-form .text-button { align-self: flex-start; }

/* ── plans ─────────────────────────────────────────────────────────────────── */

.plans { padding-top: 40px; }
.plans-head { max-width: 40em; }
.plans-head .seg { margin-top: 8px; }

.tiers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-top: 26px;
}

.tier {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 20px 20px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
}

.tier-featured { border-color: var(--gilt); box-shadow: var(--shadow-2); background: var(--raised); }
.tier h2 { font-size: 22px; }
.tier .eyebrow { margin-bottom: -2px; }

.tier-price { margin: 2px 0 0; font-size: 30px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tier-price small { display: block; margin-top: 2px; font-family: var(--sans); font-size: 13px; letter-spacing: 0; color: var(--ink3); }
.tier-ink { margin: 4px 0 0; font-size: 16px; }
.tier .quiet { flex: 1; margin: 0 0 8px; font-size: 14.5px; line-height: 1.5; }
.tier button { width: 100%; }
.tier-current { margin: 0; padding: 11px 0; text-align: center; font-family: var(--sans); font-size: 14px; color: var(--gilt); }

.topup {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px dashed var(--rule);
  border-radius: 16px;
}

.topup h2 { font-size: 18px; }
.topup p { margin: 4px 0 0; }
.plans-small { max-width: 44em; margin-top: 26px; font-size: 14.5px; line-height: 1.55; }
.plans-small p { margin: 0 0 8px; }

/* ── ink, where a beat is chosen, and the offer when it runs out ──────────── */

.ink-cost {
  margin-left: 6px;
  font-style: normal;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink3);
  opacity: 0.85;
}

.seg input:checked + span .ink-cost { color: var(--gilt); opacity: 1; }

.ink-ask {
  position: relative;
  margin: 28px 0 8px;
  padding: 18px 20px 18px;
  border: 1px solid var(--gilt);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  animation: rise var(--slow) var(--ease) both;
}

.ink-ask p { margin: 0 0 8px; font-size: 16.5px; line-height: 1.5; color: var(--ink2); }
.ink-ask .eyebrow { margin-bottom: 6px; }
.ink-ask .quiet { font-size: 14.5px; }
.ink-ask-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ink-ask-close { position: absolute; top: 6px; right: 6px; }

/* A phone has no Ctrl+Enter, and the costs need the room. */
.composer-bar .send { white-space: nowrap; }
@media (max-width: 440px) { .composer-bar .kbd { display: none; } }

/* ── admin: spend ──────────────────────────────────────────────────────────── */

.admin-spend h2 { margin: 34px 0 12px; font-size: 19px; }

.spend-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-top: 24px;
}

.spend-totals > div { padding: 16px 18px; border: 1px solid var(--rule); border-radius: 12px; background: var(--surface); }
.spend-figure { margin: 4px 0 0; font-size: 30px; font-variant-numeric: tabular-nums; }
.spend-plans { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 8px 0 0; font-family: var(--sans); font-size: 14px; color: var(--ink2); }

.table-scroll { overflow-x: auto; }
.spend-table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 14px; }
.spend-table th, .spend-table td { padding: 9px 8px; border-bottom: 1px solid var(--rule2); text-align: left; }
.spend-table th { font-weight: 500; color: var(--ink3); }
.spend-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.grant-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.grant-form label { display: flex; flex-direction: column; gap: 6px; font-family: var(--sans); font-size: 13.5px; color: var(--ink2); }
.grant-form input { font-family: var(--sans); font-size: 15px; padding: 10px 12px; }
.grant-form input[type="number"] { width: 110px; }

/* ── reduced motion: keep the information, drop the movement ────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton span { animation: none !important; background: var(--rule2); }
  .spinner, .working .spinner { animation: none !important; border-top-color: var(--rule); }
  .wordmark:hover .mark { transform: rotate(45deg); }
}
