:root {
  color-scheme: light;
  --bg: #ece4d2;
  --ink: #1a1612;
  --ink-soft: #2a241e;
  --fade: 2400ms;
  /* Reserved height for the options panel — fits up to 4 options
     without collapsing when fewer are present. Keeps the AI question's
     centered position stable between nodes. */
  --options-reserve: clamp(11.5rem, 32vh, 14rem);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  /* No rubber-band / pull-to-refresh — the page is a fixed contained
     space, so overscroll bounce reads as the room wobbling. */
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background-color var(--fade) cubic-bezier(0.4, 0, 0.2, 1), color 220ms ease;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  /* Typographic refinements — invisible at a glance, felt over time.
     kern    : true kerning pairs
     liga    : standard ligatures (fi, fl, ffi...)
     calt    : contextual alternates
     hanging-punctuation: pulls quotes/dashes into the margin so the
                          left edge of the text block reads optically flush. */
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  font-optical-sizing: auto;
  hanging-punctuation: first last;
}

/* Paper grain — a barely-there fixed-position noise overlay that gives
   the cream background a printed-page feel. SVG turbulence is rasterised
   once by the browser and cached. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10  0 0 0 0 0.09  0 0 0 0 0.07  0 0 0 0.055 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* Soft warm vignette at the edges — frames the page like the corners of
   an aged paperback. Kept very subtle (<6% darkening at the corners). */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(26, 22, 18, 0.055) 100%);
}

#stage {
  position: relative;
  z-index: 3;
  max-width: 36rem;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(2rem, 8vh, 6rem) clamp(1.5rem, 5vw, 2.5rem);
  display: grid;
  /* Reserve a stable height for the options row so the centered question
     doesn't drift when the next node has a different number of choices. */
  grid-template-rows: auto var(--options-reserve);
  align-content: center;
  gap: clamp(1.5rem, 4vh, 3rem);
}

/* AI utterance — the question.
   - align-self: center keeps the block visually centred in its row.
   - min-height of ~2.5 lines means 1-line questions don't snap the
     block smaller (which would shift the centered position) when the
     next node has 2-3 lines.
   - text-wrap: balance distributes line breaks so 2- and 3-line
     questions don't end with a single orphaned word. */
.ai {
  align-self: auto;
  font-family: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  font-weight: 400;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  line-height: 1.28;
  letter-spacing: -0.008em;
  color: var(--ink);
  text-wrap: balance;
}

.ai.align-right { text-align: right; }
.ai.align-center { text-align: center; }

/* Question manifestation — the words don't just appear, they resolve
   from a soft blur into clarity. Gives the reveal a sense of arrival
   rather than animation. (Blur applies to entry only; exits don't
   blur, both for cost and because exits should feel quick.) */
.ai p {
  opacity: 0;
  transform: translateY(5px);
  filter: blur(2.5px);
  transition:
    opacity 720ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 780ms cubic-bezier(0.22, 1, 0.36, 1),
    filter 820ms ease;
  /* Promote the reveal (opacity + transform + blur) to its own
     compositor layer so the manifestation stays off the main thread —
     the blur in particular is far smoother when GPU-composited. The
     paragraph is recreated each node, so the hint never accumulates. */
  will-change: opacity, transform, filter;
}

.ai p.in {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

/* Options — your choices */
.options {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  /* Anchor the column to the top of its reserved row so the rules
     line up at the same y-position regardless of option count. */
  align-self: start;
  width: 100%;
}

.option {
  appearance: none;
  background: transparent;
  border: none;
  /* Hairline rule that fades at both ends — feels handwritten in a
     journal rather than stamped by a press. The border itself stays
     1px but its colour gradient drops to transparent at the edges. */
  border-top: 1px solid transparent;
  border-image: linear-gradient(
    90deg,
    transparent 0%,
    currentColor 14%,
    currentColor 86%,
    transparent 100%
  ) 1;
  color: inherit;
  font: inherit;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: clamp(0.95rem, 2.6vw, 1.05rem);
  font-weight: 400;
  letter-spacing: 0.01em;
  text-align: left;
  padding: 1rem 0 0.25rem 0;
  cursor: pointer;
  opacity: 0;
  /* Entrance uses the individual `translate` property; the hover-lean
     below uses `transform`. Keeping them on separate properties lets the
     slow 950ms reveal and the quick ~300ms lean run independently
     without one stomping the other's timing. */
  translate: 0 4px;
  transition:
    opacity 950ms ease,
    translate 950ms ease,
    transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
    color 200ms ease;
  width: 100%;
  display: block;
  position: relative;
  will-change: opacity, transform;
  /* Remove the tap delay and double-tap zoom on touch — the choice
     registers the instant a finger lifts. */
  touch-action: manipulation;
}

/* Slide-in em-dash on hover/focus — a quiet "I see you're considering
   this" affordance. The dash sits in the stage's left margin gutter
   so nothing in the option reflows when it appears. */
.option::before {
  content: '—';
  position: absolute;
  left: -1.2rem;
  top: 1rem;
  opacity: 0;
  transform: translateX(-0.3rem);
  transition: opacity 240ms ease, transform 320ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.option.in {
  opacity: 0.78;
  translate: 0 0;
}

/* Hover/focus lean — the line steps a few pixels toward the reader to
   meet the em-dash sliding in from the gutter. Transform-only, so it
   never reflows; ~3px is felt more than seen. */
@media (hover: hover) {
  .option:hover {
    opacity: 1;
    transform: translateX(3px);
  }
  .option:hover::before {
    opacity: 0.55;
    transform: translateX(0);
  }
}

.option:focus-visible {
  outline: none;
  opacity: 1;
  transform: translateX(3px);
}
.option:focus-visible::before {
  opacity: 0.7;
  transform: translateX(0);
}

/* Press feedback for touch (no hover state to lean on): the em-dash
   appears the moment a finger lands, so the tap feels acknowledged
   before the choice resolves. */
.option:active {
  opacity: 1;
}
.option:active::before {
  opacity: 0.6;
  transform: translateX(0);
}

.option:disabled {
  cursor: default;
  pointer-events: none;
}

/* Exit — quick pull-away. ~400ms feels considered but unblocks the
   next question fast. */
.option.fading-out {
  opacity: 0;
  translate: 0 -2px;
  transition: opacity 400ms ease, translate 400ms ease;
}

/* Click feedback — the chosen option holds visible while siblings
   fade, with its em-dash showing as a quiet "yes, this one"
   acknowledgment. Then it fades fast before the next question
   manifests. */
.option.chosen.fading-out {
  opacity: 1;
  translate: 0 0;
  transition: opacity 260ms ease 140ms;
}
.option.chosen.fading-out::before {
  opacity: 0.7;
  transform: translateX(0);
  transition: opacity 260ms ease 140ms;
}

/* Terminal landing — the closer. We keep the options row's reserved
   height so the AI question doesn't snap upward when its choices
   disappear — preserves the same vertical anchor as every other node. */
body.terminal .options {
  visibility: hidden;
}

/* Restart button — appears at the bottom of the stage. Positioned
   absolutely so it doesn't add a third grid row (which would shift the
   centered question). Initial reveal is a slow 1400ms animation;
   hover uses a fast 280ms transition so it feels responsive. */
.restart {
  appearance: none;
  background: transparent;
  border: none;
  color: inherit;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: clamp(0.8rem, 2.2vw, 0.9rem);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  text-align: right;
  position: absolute;
  right: clamp(1.5rem, 5vw, 2.5rem);
  bottom: clamp(2rem, 8vh, 4rem);
  padding: 0.5rem 0 0.5rem 1.2rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 280ms ease;
}
.restart::before {
  content: '—';
  margin-right: 0.45rem;
  opacity: 0.75;
}
.restart.in {
  animation: restart-reveal 1400ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes restart-reveal {
  from { opacity: 0; }
  to   { opacity: 0.42; }
}
@media (hover: hover) {
  .restart:hover { opacity: 0.85; }
}
.restart:focus-visible {
  outline: none;
  opacity: 0.85;
}

/* Terminal — the closing line. Italic, slightly loosened tracking
   for gravitas, and a very slow breath so the prophecy feels alive
   rather than printed. The opacity drift is ~6% over 7 seconds —
   subliminal at a glance, felt over the wait before "begin again." */
.ai.terminal {
  font-style: italic;
  letter-spacing: 0;
}
.ai.terminal p.in {
  animation: prophecy-breath 7s ease-in-out 1200ms infinite;
}
@keyframes prophecy-breath {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.92; }
}

/* Question text fade-out — quick exit, no blur. The expensive blur
   only earns its cost on the slow manifestation entry; on exit it
   adds nothing visible at this speed. Pairs with the 450ms JS wait
   in renderNode. */
.ai p.fading-out {
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 400ms ease, transform 400ms ease;
}

/* ─── Watermark ─────────────────────────────────────────────────────── */
/* A small mark in the top-right that fades in and out. Non-interactive —
   the story underneath remains tappable from the first frame. */
#intro {
  position: fixed;
  top: clamp(0.9rem, 2.5vw, 1.4rem);
  right: clamp(0.9rem, 2.5vw, 1.4rem);
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  text-align: right;
  /* Autoplaying keyframe lifecycle — fade in, hold, fade out.
     Using an animation rather than a transition + JS class toggle
     avoids a paint-elision bug where the browser would skip the
     opacity 0→1 transition if the .visible class was added on the
     same frame the element was inserted into the DOM. */
  animation: watermark-life 9200ms ease forwards;
}
@keyframes watermark-life {
  0%   { opacity: 0; }
  18%  { opacity: 1; }    /* ~1.65s fade in */
  82%  { opacity: 1; }    /* hold visible until ~7.5s */
  100% { opacity: 0; }    /* ~1.55s fade out */
}
.intro-text {
  font-family: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem);
  font-weight: 400;
  font-style: italic;
  line-height: 1.4;
  letter-spacing: 0;
  color: var(--ink);
}
.intro-text p {
  margin: 0;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 700ms ease, transform 700ms ease;
}
.intro-text p {
  color: color-mix(in srgb, var(--ink) 55%, transparent);
  opacity: 1;
  transform: none;
}

/* ─── Dev panel — hidden until unlocked by 5 taps ──────────────────── */
#dev-panel {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 100;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: currentColor;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
  text-align: right;
}
#dev-panel.visible {
  opacity: 0.55;
  pointer-events: auto;
}
#dev-panel.visible:hover { opacity: 1; }

.dev-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-end;
}
.dev-tag {
  font-size: 0.62rem;
  text-transform: uppercase;
  opacity: 0.6;
  letter-spacing: 0.12em;
}
.dev-vote {
  appearance: none;
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  font: inherit;
  font-size: 0.7rem;
  width: 1.4rem;
  height: 1.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 999px;
  opacity: 0.75;
  transition: opacity 150ms ease, transform 200ms ease, background 200ms ease;
}
.dev-vote:hover { opacity: 1; }
.dev-vote.voted {
  background: currentColor;
  transform: scale(1.15);
}
.dev-vote.voted::after { content: ''; }
.dev-vote[data-vote="up"].voted { color: inherit; }
.dev-link {
  color: inherit;
  text-decoration: none;
  opacity: 0.6;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
}
.dev-link:hover { opacity: 1; text-decoration: underline; }
.dev-meta {
  margin-top: 0.35rem;
  font-size: 0.65rem;
  opacity: 0.55;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.dev-meta code { font: inherit; }

/* ─── Votes summary view (?votes) ──────────────────────────────────── */
body.summary { background: var(--bg); color: var(--ink); }
body.summary #stage {
  display: block;
  max-width: 60rem;
}
.summary-wrap {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 0.9rem;
}
.summary-wrap h1 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 400;
  font-size: 2rem;
  margin-bottom: 1.5rem;
  letter-spacing: 0.02em;
}
.summary-empty { opacity: 0.6; }
.summary-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
}
.summary-table th,
.summary-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  vertical-align: top;
}
.summary-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.55;
  font-weight: 500;
}
.summary-table td.mono {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.78rem;
  white-space: nowrap;
  opacity: 0.7;
}
.summary-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  width: 3rem;
}
.summary-table tr.pos td.num:first-of-type { color: #1c6e2a; font-weight: 600; }
.summary-table tr.neg td.num:last-of-type { color: #9b2222; font-weight: 600; }
.summary-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}
.summary-actions button,
.summary-actions a {
  appearance: none;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font: inherit;
  font-size: 0.78rem;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 150ms ease;
}
.summary-actions button:hover,
.summary-actions a:hover { opacity: 1; }

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  body { transition: background-color 200ms linear, color 100ms ease; }
  .ai p, .option, .restart, .ai p.fading-out, .option::before {
    transition-duration: 200ms !important;
    transition-delay: 0ms !important;
  }
  #intro, .intro-text p {
    transition-duration: 100ms !important;
    transition-delay: 0ms !important;
  }
  /* Drop the grain texture entirely — it's decorative and can be
     visually fatiguing for motion-sensitive readers. */
  body::before { display: none; }
  /* No breathing animation on the prophecy line — keep it still. */
  .ai.terminal p.in { animation: none; }
  /* Blur on transitions can trigger nausea for some — keep it off. */
  .ai p, .ai p.fading-out { filter: none !important; }
}
