/* MYOA: beauty through simplicity. One quiet column of type on a still pastel wash.
   Only emphasised words (and the dice, briefly) move. Every size and target follows CONNIE:
   text ≥ 16px, targets ≥ 44px, words beside every control. */

@font-face { font-family: "Inter"; src: url(/fonts/inter-roman.woff2) format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Inter"; src: url(/fonts/inter-italic.woff2) format("woff2"); font-weight: 100 900; font-style: italic; font-display: swap; }

/* Registered so the browser can interpolate them smoothly on the compositor-friendly paint path. */
@property --shift { syntax: "<percentage>"; inherits: false; initial-value: 0%; }
@property --sheen { syntax: "<percentage>"; inherits: false; initial-value: -30%; }
@property --veil { syntax: "<number>"; inherits: false; initial-value: 0; }

:root {
  /* Neutral defaults; theme.ts replaces these with the genre palette. */
  --l-bg1: #fbf3ec; --l-bg2: #efeafb; --l-bg3: #e6f5f0; --l-text: #18181a; --l-muted: #4b4a50;
  --l-g1: #5b37b8; --l-g2: #a3346a; --l-g3: #0f6b62; --l-focus: #18181a; --l-glint: rgb(24 24 26 / 0.38);
  --d-bg1: #15131c; --d-bg2: #1b1526; --d-bg3: #0f1d1d; --d-text: #ecebef; --d-muted: #b9b7bf;
  --d-g1: #cbb8ff; --d-g2: #ffb7d5; --d-g3: #a3eed7; --d-focus: #ffffff; --d-glint: rgb(255 255 255 / 0.75);

  --bg1: var(--l-bg1); --bg2: var(--l-bg2); --bg3: var(--l-bg3); --text: var(--l-text); --muted: var(--l-muted);
  --g1: var(--l-g1); --g2: var(--l-g2); --g3: var(--l-g3); --focus: var(--l-focus); --glint: var(--l-glint);
  --on-text: var(--l-bg1);

  --column: 38rem;
  --gutter: max(16px, env(safe-area-inset-left));
  --target: 44px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg1: var(--d-bg1); --bg2: var(--d-bg2); --bg3: var(--d-bg3); --text: var(--d-text); --muted: var(--d-muted);
    --g1: var(--d-g1); --g2: var(--d-g2); --g3: var(--d-g3); --focus: var(--d-focus); --glint: var(--d-glint);
    --on-text: var(--d-bg1);
  }
}

* { box-sizing: border-box; }
html {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-optical-sizing: auto; font-feature-settings: "cv11", "ss03"; /* single-storey a, rounder quotes */
  -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased;
}
body {
  margin: 0; min-height: 100dvh; color: var(--text);
  background-color: var(--bg1);
  background-image:
    radial-gradient(60% 55% at 88% 6%, var(--bg3) 0%, transparent 70%),
    radial-gradient(70% 60% at 6% 96%, var(--bg2) 0%, transparent 72%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  font-size: clamp(1.0625rem, 1rem + 0.3vw, 1.25rem); line-height: 1.65; font-weight: 430;
  overflow-wrap: break-word; hyphens: manual;
}
main {
  max-width: calc(var(--column) + 2 * var(--gutter)); margin-inline: auto;
  padding: calc(5rem + env(safe-area-inset-top)) var(--gutter) calc(40vh + env(safe-area-inset-bottom));
  outline: none;
}
p { margin: 0 0 1.05em; }
h1, h2, h3, .scene-title { font-weight: 900; line-height: 1.04; letter-spacing: -0.028em; margin: 2em 0 0.5em; text-wrap: balance; }
h1.brand-mark { padding-bottom: 0.06em; }
h1 { font-size: clamp(3.25rem, 2rem + 7vw, 7rem); font-weight: 900; letter-spacing: -0.045em; margin: 0.2em 0 0.2em; }
h2 { font-size: clamp(1.75rem, 1.35rem + 1.6vw, 2.5rem); }
.scene-title { font-size: clamp(2.25rem, 1.5rem + 3.4vw, 4rem); }
.lede { font-size: 1.15em; color: var(--muted); font-weight: 450; margin-bottom: 2.2em; text-wrap: pretty; }
.muted { color: var(--muted); }
.small { font-size: 1rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: var(--gutter); top: -200px; padding: 10px 14px; background: var(--text); color: var(--on-text); border-radius: 999px; font-weight: 700; }
.skip:focus { top: calc(12px + env(safe-area-inset-top)); }

/* ---- Emphasis: the only continuous motion ------------------------------------------------- */
.em {
  --shift: 0%; --sheen: -30%;
  background-image:
    /* the glint: a narrow band that only ever raises contrast (bright on dark, deep on light) */
    linear-gradient(100deg, transparent calc(var(--sheen) - 9%), var(--glint) var(--sheen), transparent calc(var(--sheen) + 9%)),
    /* the drift: a seamless loop of the genre gradient */
    linear-gradient(100deg,
      var(--g1) calc(var(--shift) - 100%), var(--g2) calc(var(--shift) - 66.6%), var(--g3) calc(var(--shift) - 33.3%),
      var(--g1) var(--shift), var(--g2) calc(var(--shift) + 33.3%), var(--g3) calc(var(--shift) + 66.6%), var(--g1) calc(var(--shift) + 100%));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
  animation:
    em-in 1.1s var(--ease-out) both,
    drift 32s linear infinite,
    sheen 9s cubic-bezier(0.45, 0, 0.2, 1) 1.4s infinite;
}
.em-person { font-weight: 800; }
.em-place  { font-weight: 600; font-style: italic; animation-duration: 1.1s, 44s, 11s; }
.em-item   { font-weight: 800; text-transform: uppercase; font-size: 0.84em; letter-spacing: 0.08em; animation-duration: 1.1s, 32s, 6s; }
.em-speech { font-weight: 300; font-style: italic; animation-duration: 1.4s, 52s, 13s; }
.em-moment { font-weight: 900; font-size: 1.14em; letter-spacing: -0.01em; animation: em-in 1.8s var(--ease-out) both, drift 26s linear infinite, sheen 7s cubic-bezier(0.45, 0, 0.2, 1) 0.6s infinite; }

/* Arrival: words surface from a soft focus, never from transparent text over the page (no contrast dip below AA on settle). */
@keyframes em-in { from { filter: blur(6px); opacity: 0.35; } to { filter: blur(0); opacity: 1; } }
@keyframes drift { to { --shift: 100%; } }
/* One slow pass of light, then rest for most of the cycle. */
@keyframes sheen { 0% { --sheen: -30%; } 22% { --sheen: 130%; } 100% { --sheen: 130%; } }

:root[data-motion="paused"] .em, :root[data-motion="paused"] .die { animation: none; }
@media (prefers-reduced-motion: reduce) { .em, .die { animation: none !important; transition: none !important; } }
@media (forced-colors: active) { .em { color: CanvasText; background: none; } }

/* ---- Controls --------------------------------------------------------------------------- */
button, .link {
  font: inherit; color: inherit; background: none; border: 0; padding: 0.35em 0; margin: 0;
  min-height: var(--target); min-width: var(--target); cursor: pointer; text-align: left;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.24em; text-decoration-color: var(--muted);
  transition: text-decoration-color 120ms ease, color 120ms ease;
}
a { color: inherit; text-underline-offset: 0.24em; text-decoration-thickness: 1px; }
button:hover, .link:hover { text-decoration-color: currentColor; }
button:disabled { cursor: default; opacity: 1; color: var(--muted); }

/* The one main action on a screen: a real, unmistakable button. */
.primary {
  display: inline-flex; align-items: center; gap: 0.5em; min-height: 52px; padding: 0.7em 1.5em; border-radius: 999px;
  background: var(--text); color: var(--on-text); font-weight: 750; letter-spacing: -0.005em; text-decoration: none;
  box-shadow: 0 1px 0 rgb(0 0 0 / 0.04), 0 10px 30px -12px color-mix(in srgb, var(--text) 45%, transparent);
  transition: transform 140ms var(--ease-out), box-shadow 140ms ease;
}
.primary:hover { transform: translateY(-1px); }
.primary:active { transform: translateY(0); }
.primary:disabled { background: var(--muted); color: var(--on-text); transform: none; }

.field { display: block; margin: 1.6em 0 1.4em; }
.field > span:first-child { display: block; font-weight: 650; }
.field .hint { display: block; color: var(--muted); font-size: 1rem; margin-top: 0.15em; }
input[type="text"], input[type="email"], input:not([type]) {
  font: inherit; color: inherit; width: 100%; min-height: var(--target); background: transparent; border: 0;
  border-bottom: 2px solid var(--muted); border-radius: 0; padding: 0.45em 0; margin-top: 0.35em;
  transition: border-color 120ms ease;
}
input::placeholder { color: var(--muted); opacity: 1; }
input:focus, input:focus-visible { outline: none; border-bottom-color: var(--focus); box-shadow: 0 2px 0 0 var(--focus); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 3px; }
main:focus, main:focus-visible, [role="tabpanel"]:focus:not(:focus-visible) { outline: none; }
[hidden] { display: none !important; }
.error { color: var(--text); font-weight: 650; margin-top: 0.5em; }
.error::before { content: "⚠ "; }
.row { display: flex; flex-wrap: wrap; gap: 0.75em 1.5em; align-items: center; margin-top: 1.4em; }

/* ---- Story ------------------------------------------------------------------------------- */
.action { margin: 2.6em 0 1em; font-weight: 650; color: var(--muted); }
.action::before { content: "› "; }
.turn[aria-busy="true"] .waiting { display: block; }
.waiting { display: none; color: var(--muted); }
.status-line { color: var(--muted); font-size: 1rem; margin: 0.4em 0 0; }
.choices { list-style: none; margin: 1.8em 0 0; padding: 0; }
.choices li { margin: 0; }
.choices button { font-weight: 620; width: 100%; padding-block: 0.5em; }
.act form { margin-top: 0.6em; }
h1.story-title { font-size: clamp(2.5rem, 1.6rem + 4.5vw, 4.75rem); margin-bottom: 0.6em; }
.recap { font-style: italic; text-wrap: pretty; }
.undo { color: var(--muted); }
.pause { margin-top: 2em; }
.chapter-end { margin-top: 3em; }
.check { display: flex; align-items: center; gap: 0.7em; min-height: var(--target); margin: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--text); margin: 0; }
.check label { cursor: pointer; }
details.who { margin: 0 0 1.4em; }
details.who summary { cursor: pointer; min-height: var(--target); display: flex; align-items: center; font-weight: 650; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.24em; text-decoration-color: var(--muted); }
details.who .field { margin: 0.9em 0; }

/* ---- Dice: a short, typographic roll ------------------------------------------------------ */
.roll { display: flex; align-items: baseline; gap: 0.35em 0.7em; flex-wrap: wrap; margin: 1.8em 0 1.3em; }
.roll-dice { display: inline-flex; gap: 0.18em; }
.die.em { animation: drift 32s linear infinite, sheen 9s cubic-bezier(0.45, 0, 0.2, 1) 1.4s infinite; } /* no soft-focus arrival: the tumble must read */
.die { display: inline-block; min-width: 0.7em; font-size: 2.6em; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.03em;
       transition: transform 140ms var(--ease-out); }
.roll-text { color: var(--muted); font-weight: 520; font-size: 1rem; }
.roll-text strong { color: var(--text); font-weight: 800; }

/* ---- Tools bar and drawer ---------------------------------------------------------------- */
.tools {
  position: fixed; inset: 0 0 auto 0; z-index: 2; display: flex; justify-content: flex-end; gap: 0.25em 1.4em;
  padding: calc(4px + env(safe-area-inset-top)) var(--gutter) 4px; font-size: 1rem;
  background: linear-gradient(to bottom, var(--bg1) 78%, color-mix(in srgb, var(--bg1) 0%, transparent));
  padding-bottom: 14px;
}
.tools:empty { display: none; }
.tools > a, .tools > button { white-space: nowrap; display: inline-flex; align-items: center; min-height: var(--target); padding: 0; }
.tools .brand { margin-right: auto; font-weight: 900; font-size: 1.15rem; letter-spacing: -0.03em; text-decoration: none; display: inline-flex; align-items: center; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(28rem, 100vw); overflow-y: auto; z-index: 3;
  padding: calc(1rem + env(safe-area-inset-top)) var(--gutter) calc(3rem + env(safe-area-inset-bottom));
  background: linear-gradient(160deg, var(--bg1), var(--bg2)); font-size: 1.0625rem;
  box-shadow: -1px 0 0 color-mix(in srgb, var(--text) 10%, transparent);
}
#drawer h2 { margin-top: 0.6em; }
.drawer-close { display: block; margin: 0 0 0 auto; }
#drawer h3 { font-size: 1.15rem; font-weight: 900; margin: 1.6em 0 0.4em; letter-spacing: -0.01em; }
#drawer [role="tablist"] { display: flex; gap: 0 1.2em; flex-wrap: wrap; margin: 0.4em 0 1em; }
#drawer [role="tab"][aria-selected="true"] { font-weight: 800; text-decoration-color: currentColor; text-decoration-thickness: 2px; }
#drawer ul { list-style: none; padding: 0; margin: 0; }
#drawer li { margin: 0 0 0.6em; }
.stat { display: flex; justify-content: space-between; gap: 1em; padding: 0.2em 0; margin: 0; }
.stat b { font-weight: 800; font-variant-numeric: tabular-nums; }
.done-item { text-decoration: line-through; color: var(--muted); }
@media (min-width: 1100px) {
  body.drawer-open main { margin-left: max(var(--gutter), calc((100vw - 28rem - var(--column)) / 2 - 1rem)); margin-right: calc(28rem + 1rem); }
}
@media (max-width: 1099.98px) { body.drawer-open main, body.drawer-open .tools { display: none; } }

/* ---- Start: worlds and the hero ---------------------------------------------------------- */
.genres { list-style: none; padding: 0; margin: 1.2em 0 0.4em; }
.genres li { margin: 0; }
.genres button {
  font-size: clamp(2.1rem, 1.4rem + 3.4vw, 3.6rem); font-weight: 900; letter-spacing: -0.03em; line-height: 1.12;
  text-decoration: none; padding: 0.06em 0; width: 100%;
}
.genres button[aria-pressed="true"] { text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 0.12em; text-decoration-color: currentColor; }
.genres button[aria-pressed="false"]:hover { text-decoration: underline; text-decoration-thickness: 2px; }
.tagline { min-height: 1.65em; color: var(--muted); }

@media (max-width: 480px) {
  .kbd-hint { display: none; }
  .tools { gap: 0.25em 1em; }
  body { font-size: 1.0625rem; line-height: 1.62; }
  main { padding-top: calc(4.25rem + env(safe-area-inset-top)); }
  .primary { width: 100%; justify-content: center; }
}

/* ---- GM view ----------------------------------------------------------------------------- */
.gm-list { list-style: none; padding: 0; margin: 0 0 1em; }
.gm-list li { margin: 0 0 0.5em; }
.gm-issue { font-weight: 700; }
main h3 { font-size: 1.15rem; margin: 1.6em 0 0.4em; letter-spacing: -0.01em; }

.passkey-offer { margin: 0 0 2em; }
.passkey-offer .row { margin-top: 0.4em; }
.saved { font-weight: 700; }
.story-so-far .narration { font-size: 1.08em; text-wrap: pretty; }
.welcome { margin: 0; }

/* ---- Writing your story: live progress ------------------------------------------------------- */
.making-title { font-size: clamp(2.5rem, 1.6rem + 4.5vw, 4.75rem); margin-bottom: 0.5em; }
.making-steps { list-style: none; padding: 0; margin: 1.2em 0 1.6em; }
.making-steps li { margin: 0 0 0.55em; animation: step-in 150ms ease-out both; }
.making-steps li.done { color: var(--muted); }
.making-steps li.done .making-text::before { content: "✓ "; color: var(--text); font-weight: 700; }
.making-steps li.active { font-weight: 750; font-size: 1.12em; }
.making-steps li.active .making-text {
  background-image: linear-gradient(100deg, var(--g1) calc(var(--shift) - 100%), var(--g2) calc(var(--shift) - 66.6%), var(--g3) calc(var(--shift) - 33.3%),
    var(--g1) var(--shift), var(--g2) calc(var(--shift) + 33.3%), var(--g3) calc(var(--shift) + 66.6%), var(--g1) calc(var(--shift) + 100%));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: drift 12s linear infinite;
}
.making-clock { font-weight: 500; font-size: 0.85em; font-variant-numeric: tabular-nums; }
.making-note { margin-top: 1.4em; }
@keyframes step-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
:root[data-motion="paused"] .making-steps li, :root[data-motion="paused"] .making-steps li.active .making-text { animation: none; }
@media (prefers-reduced-motion: reduce) { .making-steps li, .making-steps li.active .making-text { animation: none !important; } }
@media (forced-colors: active) { .making-steps li.active .making-text { color: CanvasText; background: none; } }
