/* =============================================================================
   Story Tabletop — portal base stylesheet
   Every value routes through tokens.css custom properties; no re-hardcoded hex.
   Tinted mixes (row hover, chip fills) derive from tokens via color-mix().
   ============================================================================= */

/* ---------- reset & base typography ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  font-weight: var(--weight-regular);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--text);
  margin: 0 0 var(--space-4);
  text-wrap: balance;
}
h1 { font-size: var(--text-h2); line-height: var(--leading-h2); letter-spacing: var(--tracking-h2); font-weight: var(--weight-bold); }
h2 { font-size: var(--text-h3); line-height: var(--leading-h3); letter-spacing: var(--tracking-h3); font-weight: var(--weight-bold); }
h3 { font-size: var(--text-h4); line-height: var(--leading-h4); letter-spacing: var(--tracking-h4); font-weight: var(--weight-semibold); }

p { margin: 0 0 var(--space-4); }

a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--duration-fast) var(--ease-gentle);
}
a:hover { color: var(--link-hover); }
a:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-sm);
}

.muted {
  color: var(--text-muted);
  font-size: var(--text-small);
  line-height: var(--leading-small);
}

.eyebrow {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  margin: 0 0 var(--space-2);
}

/* ---------- layout ---------- */

.container {
  max-width: 62rem;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-12);
}

.page-header { margin-bottom: var(--space-6); }
.page-header p { max-width: 46rem; }

.stack > * + * { margin-top: var(--space-6); }

/* skip link — visible only when focused */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: var(--space-2);
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-1);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-card);
  transform: translateY(-300%);
}
.skip-link:focus-visible { transform: none; }

/* ---------- top bar ---------- */

.topbar {
  position: relative;
  overflow: hidden;
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  position: relative;
  z-index: 1;
  max-width: 62rem;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-6);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--text);
}
.brand:hover { color: var(--text); }
.brand-glyph { display: block; flex: none; }
.brand-name {
  font-family: var(--font-heading);
  font-weight: var(--weight-black);
  font-size: var(--text-h4);
  line-height: var(--leading-h4);
  letter-spacing: var(--tracking-h4);
}
.brand-sub {
  display: block;
  font-family: var(--font-body);
  font-weight: var(--weight-bold);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* nav pills */
.nav-pills {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
  padding: var(--space-1);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.nav-pill {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--text-small);
  line-height: var(--leading-small);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-gentle),
              color var(--duration-fast) var(--ease-gentle);
}
.nav-pill:hover { color: var(--text); background: var(--bg-sunken); }
.nav-pill:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.nav-pill[aria-current="page"] {
  background: var(--secondary);
  color: var(--text-on-color);
}
.nav-pill[aria-current="page"]:hover { background: var(--secondary-hover); color: var(--text-on-color); }

/* drifting header sparks (decorative; hidden from AT; stilled on reduced motion) */
.topbar-spark {
  position: absolute;
  z-index: 0;
  opacity: .18;
  color: var(--accent-strong);
  animation: spark-drift calc(var(--duration-slow) * 14) var(--ease-gentle) infinite alternate;
}
.topbar-spark:nth-child(2) { animation-delay: calc(var(--duration-slow) * -5); }
.topbar-spark:nth-child(3) { animation-delay: calc(var(--duration-slow) * -9); }

@keyframes spark-drift {
  from { transform: translate(0, 0) rotate(0deg); }
  to   { transform: translate(var(--space-6), calc(-1 * var(--space-2))) rotate(18deg); }
}

@media (prefers-reduced-motion: reduce) {
  .topbar-spark { animation: none; }
}

/* ---------- cards ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-6);
  transition: box-shadow var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out);
}
.card:hover {
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
}
.card > :last-child { margin-bottom: 0; }

.card-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  font-weight: var(--weight-bold);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-gentle),
              box-shadow var(--duration-fast) var(--ease-gentle),
              transform var(--duration-fast) var(--ease-gentle);
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-1);
  color: var(--secondary-hover);
  border-color: var(--border-strong);
}
.btn-secondary:hover { border-color: var(--secondary); color: var(--secondary-hover); }

/* ---------- forms ---------- */

.field { margin-bottom: var(--space-4); }
.field label,
.field-label {
  display: block;
  font-size: var(--text-small);
  line-height: var(--leading-small);
  font-weight: var(--weight-bold);
  margin-bottom: var(--space-1);
}
.field-row { display: flex; gap: var(--space-4); flex-wrap: wrap; }
.field-row .field { flex: 1 1 10rem; margin-bottom: var(--space-4); }
.field .hint {
  display: block;
  font-weight: var(--weight-regular);
  color: var(--text-muted);
  font-size: var(--text-small);
  line-height: var(--leading-small);
  margin-top: var(--space-1);
}

/* TEXTAREA AND SELECT WERE NEVER IN THIS LIST. Only text and number inputs were
   styled, so every multi-line box in the portal fell back to the browser
   default of `cols=20` — about 182px — while sitting in a field 894px wide.
   That is the manuscript box, the adventure objective, every gap the author
   fills, the narrator's persona, and what a child said at the table. Typing a
   paragraph into a box the size of a search field, and scrolling inside it to
   re-read it, was the daily experience of using this portal. */
input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  max-width: 20rem;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--text);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-input);
  transition: border-color var(--duration-fast) var(--ease-gentle),
              box-shadow var(--duration-fast) var(--ease-gentle);
}
/* A box for prose is as wide as the thought it holds; 20rem is a field for a
   name. Textareas take the full measure of the form they sit in. */
textarea {
  max-width: none;
  resize: vertical;
  min-height: 4.5rem;
}
select { max-width: 24rem; }

input[type="text"]:hover,
input[type="number"]:hover,
select:hover,
textarea:hover { border-color: var(--accent-strong); }
input[type="text"]:focus-visible,
input[type="number"]:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: var(--shadow-focus);
}

/* table-embedded inputs stay compact */
td input[type="number"] { max-width: 8rem; }

/* plain checkbox rows (e.g. the audited acknowledgement) */
.check-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: var(--space-4) 0;
  font-size: var(--text-small);
  line-height: var(--leading-small);
}
.check-row input[type="checkbox"] {
  flex: none;
  width: var(--space-4);
  height: var(--space-4);
  margin-top: 2px;
  accent-color: var(--secondary);
}
.check-row input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-sm);
}

fieldset.fieldset-plain {
  border: none;
  padding: 0;
  margin: 0 0 var(--space-6);
}
fieldset.fieldset-plain legend { padding: 0; }

/* ---------- chip toggles (mode checkboxes) ---------- */

.chip-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  font-size: var(--text-small);
  line-height: var(--leading-small);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-gentle),
              border-color var(--duration-fast) var(--ease-gentle),
              color var(--duration-fast) var(--ease-gentle);
}
.chip input[type="checkbox"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.chip .chip-dot {
  width: var(--space-2);
  height: var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  transition: background var(--duration-fast) var(--ease-gentle);
}
.chip:hover { border-color: var(--secondary); color: var(--text); }
.chip:has(input:checked) {
  background: color-mix(in srgb, var(--secondary) 12%, var(--surface-1));
  border-color: var(--secondary);
  color: var(--secondary-hover);
}
.chip:has(input:checked) .chip-dot { background: var(--secondary); }
.chip:has(input:focus-visible) { box-shadow: var(--shadow-focus); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-small);
  line-height: var(--leading-small);
}
thead th {
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-strong);
}
thead th:first-child { border-top-left-radius: var(--radius-sm); }
thead th:last-child { border-top-right-radius: var(--radius-sm); }
tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr {
  transition: background var(--duration-fast) var(--ease-gentle);
}
tbody tr:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface-1)); }

code, .mono {
  font-family: ui-monospace, Menlo, monospace;
  font-size: var(--text-small);
}

/* ---------- status pills & badges ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  white-space: nowrap;
}
.pill-ok { background: var(--success); color: var(--text-on-color); }
.pill-warning { background: var(--warning); color: var(--on-warning); }
.pill-neutral {
  background: var(--bg-sunken);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
}
.pill-accent { background: var(--accent); color: var(--on-accent); }

.warn { color: var(--primary-strong); font-weight: var(--weight-bold); }

.version-badge {
  font-family: var(--font-body);
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  color: var(--secondary-hover);
  background: color-mix(in srgb, var(--secondary) 12%, var(--surface-1));
  border: 1px solid var(--secondary);
  border-radius: var(--radius-pill);
  padding: 2px var(--space-3);
  white-space: nowrap;
}

/* ---------- empty states ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-small);
  line-height: var(--leading-small);
}
.empty-state svg { color: var(--accent-strong); }
.empty-state strong {
  font-family: var(--font-heading);
  font-size: var(--text-h4);
  line-height: var(--leading-h4);
  font-weight: var(--weight-semibold);
  color: var(--text);
}

.empty-inline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--text-muted);
  white-space: nowrap;
}
.empty-inline svg { color: var(--accent-strong); flex: none; }

/* ---------- warning callout (break-even page) ---------- */

.callout-warning {
  border-left: var(--space-1) solid var(--warning);
  background: color-mix(in srgb, var(--warning) 10%, var(--surface-1));
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.callout-warning ul { margin: 0; padding-left: var(--space-6); }
.callout-warning li { font-weight: var(--weight-semibold); }

/* ---------- entrance animation (driven by portal.js) ---------- */

.js-entrance .will-enter {
  opacity: 0;
  transform: translateY(var(--space-3));
}
.js-entrance .did-enter {
  opacity: 1;
  transform: none;
  transition: opacity var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out);
  transition-delay: var(--enter-delay, 0ms);
}
/* cards keep their hover transition after entering */
.js-entrance .card.did-enter {
  transition: opacity var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
  transition-delay: var(--enter-delay, 0ms), var(--enter-delay, 0ms), 0ms;
}

/* ---------- print / read-friendly (GM prep is a work tool the adult
   narrates from; chrome drops, content flows, the GM-ONLY callout keeps
   its border so it can be folded out of the children's sight) ---------- */
@media print {
  .topbar, .skip-link, .no-print { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
  .card, .callout-warning {
    box-shadow: none;
    border: 1px solid #999;
    break-inside: avoid;
  }
  .js-entrance .will-enter { opacity: 1; transform: none; }
}

/* signed-in account affordance in the top bar: who you are, and a way out */
.signed-in {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-left: var(--space-2);
  border-left: 1px solid var(--border);
}
.signed-in-who {
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-small);
  color: var(--text-muted);
}
.signed-out-button {
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-family: var(--font-body);
}

/* Deliberate-confirmation checkbox (approval steps). Styled as an actual box
   with a tick, not a subtle dot: approving is a one-way, human-only action, and
   the control that arms it must read as one at a glance. */
.confirm {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md, 12px);
  background: var(--surface-1);
  font-size: var(--text-small);
  line-height: var(--leading-small);
  color: var(--text);
  cursor: pointer;
}
.confirm input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.confirm .confirm-box {
  flex: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  position: relative;
}
.confirm:hover { border-color: var(--secondary); }
.confirm:has(input:checked) { border-color: var(--secondary); }
.confirm:has(input:checked) .confirm-box {
  background: var(--secondary);
  border-color: var(--secondary);
}
.confirm:has(input:checked) .confirm-box::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid var(--text-on-color);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.confirm:has(input:focus-visible) { box-shadow: var(--shadow-focus); }

/* Per-title navigation: the author's four screens for the title they are in. */
.title-nav {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4) var(--space-6);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--border);
}
.title-nav-id {
  flex-basis: 100%;
  font-family: var(--font-heading);
  font-size: var(--text-small);
  color: var(--text-muted);
}
.title-nav-group { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.title-nav-group-label {
  font-size: var(--text-small);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
/* Tabs: a row that scrolls sideways on a phone rather than wrapping into a
   pile, so a tab is always where it was the last time. */
.title-nav-tabs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  max-width: 100%;
}
.title-nav-link {
  flex: none;
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-md, 12px) var(--radius-md, 12px) 0 0;
  margin-bottom: -1px;
  font-size: var(--text-small);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.title-nav-link:hover { background: var(--bg-sunken); color: var(--text); }
/* The open tab joins the page below it: same surface, a border on three sides
   and a heavier top edge — position and shape, not colour alone. */
.title-nav-link[aria-current="page"] {
  background: var(--surface-1);
  color: var(--text);
  border-color: var(--border);
  border-top: 3px solid var(--secondary);
}

/* "What just happened" banner. A POST that returns to its own page is
   indistinguishable from one that did nothing, and people click again. */
.callout-done {
  margin: 0 0 var(--space-6);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--secondary);
  border-left-width: 4px;
  border-radius: var(--radius-md, 12px);
  background: color-mix(in srgb, var(--secondary) 10%, var(--surface-1));
  color: var(--text);
  font-size: var(--text-small);
}

/* Gap report: each gap is a small brief for the author, not a row of schema. */
.gap-list { list-style: none; margin: 0; padding: 0; }
.gap {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
}
.gap:first-child { border-top: none; }
.gap-where {
  margin: 0 0 var(--space-1);
  font-size: var(--text-small);
  color: var(--text-muted);
}
.gap-field {
  margin: 0 0 var(--space-2);
  font-size: var(--text-body);
  line-height: var(--leading-body);
}
.gap-what { margin: 0 0 var(--space-2); }
.gap-example {
  margin: 0 0 var(--space-2);
  padding-left: var(--space-3);
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
  font-style: italic;
}
.gap-reason {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-small);
  color: var(--text-muted);
}
.gap-path { margin-top: var(--space-2); font-size: var(--text-small); }
.gap-path summary { color: var(--text-muted); cursor: pointer; }

/* The table: an adult reads this aloud, at arm's length, with children waiting. */
.read-aloud { border-left: 4px solid var(--secondary); }
.read-aloud-text {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  line-height: 1.65;
  color: var(--text);
  margin: 0 0 var(--space-4);
}
.scene-direction {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-sunken);
  border-radius: var(--radius-md, 12px);
  font-size: var(--text-small);
  color: var(--text-muted);
}
.choice-buttons { display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.choice-buttons .btn { text-align: left; white-space: normal; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* A form that is waiting on the server says so. Resolving a turn takes about
   four seconds (rules + a model writing the next moment); with no visible
   change the screen reads as broken, and the adult taps again — which used to
   play a second real turn. */
.btn[aria-disabled="true"],
.btn:disabled {
  opacity: 0.72;
  cursor: progress;
}
/* "Hold to talk" off is not "working": it waits for a step the adult has not
   taken yet, and the status line says which. */
.btn[data-voice-talk]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

[data-busy] [data-busy-note] {
  color: var(--ink-muted, #6b6257);
}

/* Where the story is: the moments of the adventure, and which are played.
   An adult at a table needs to know how much is left and when the ending has
   arrived — the screen used to show one moment and nothing else. */
.moment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.moment {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-1) var(--space-3);
  align-items: baseline;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}
.moment-name { font-weight: var(--weight-bold); }
.moment-goal { grid-column: 2; color: var(--text-muted); font-size: var(--text-small); }
.moment-done .moment-name { color: var(--text-muted); font-weight: var(--weight-regular); }
.moment-current { background: var(--bg-sunken); border-radius: var(--radius-md); padding: var(--space-2); }

/* The dice, shown. Three outcomes, not six numbers — so a face is a word, and
   the one the rules kept is the one that must read as chosen, not as louder. */
.roll-dice {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
}
.roll-die {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 7.5rem;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 2px solid var(--border-strong);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-weight: var(--weight-bold);
  text-align: center;
}
/* A discarded die stays legible: the child rolled it and will look for it. */
.roll-kept {
  border-color: var(--secondary);
  background: var(--surface-1);
  color: var(--text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--secondary) 22%, transparent);
}
.roll-good.roll-kept { border-color: var(--success); }
.roll-outcome { font-size: var(--text-body-lg); margin: 0; }

/* The author's notes: present, and closed by default. An adult glancing at the
   screen while reading aloud must not catch the solution out of the corner of
   their eye — and neither must a child leaning over. */
.gm-notes {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-sunken);
}
.gm-notes > summary {
  cursor: pointer;
  font-weight: var(--weight-bold);
  color: var(--text-muted);
}
.gm-notes ul { margin: var(--space-2) 0 0; padding-left: var(--space-4); }

/* Who is speaking, and the held microphone. Both states have to read from
   across a table, by an adult who is also reading a story out loud. */
.btn.is-chosen {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--secondary) 22%, transparent);
}
.btn[data-live-talk] { min-width: 12rem; touch-action: none; }
.btn[data-live-talk].is-talking {
  background: var(--success);
  color: var(--text-on-color);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 30%, transparent);
}
/* Held, not tapped: the label must not be selectable or a long press turns
   into a text selection on a phone. */
.btn[data-live-talk] { user-select: none; -webkit-user-select: none; }

/* ===== The table screen, arranged around one job ==========================
   An adult at this screen is PERFORMING: reading aloud to small children while
   watching their faces. Spare attention is near zero, so the screen may ask
   for almost none. Everything below follows from that.                      */

/* Where the story is, as a line in the header rather than the first card. */
.now-strip {
  margin: var(--space-2) 0 0;
  color: var(--text-muted);
  font-size: var(--text-body);
}

/* The passage is the one thing the eye should find without looking for it. */
.read-aloud {
  border-left-width: 6px;
  background: var(--surface-1);
}
.read-aloud-text {
  /* A capped measure, because this text is READ OUT LOUD. On a long line the
     eye loses the start of the next one on the return sweep — the reader
     stumbles, and a stumble in front of children costs more than it would on
     a page nobody hears. ~60 characters is the old typographic answer and it
     is the right one here. */
  max-width: 34em;
  font-size: clamp(1.25rem, 1.05rem + 0.9vw, 1.6rem);
  line-height: 1.7;
  text-wrap: pretty;
}

/* The dice sit with the passage they explain — same event, lighter voice. */
.roll { border-left: 4px solid var(--border-strong); }
.roll .roll-outcome { font-size: var(--text-body-lg); }

/* Folded by default and quiet when closed: consulted, never competed with. */
details.card > summary {
  cursor: pointer;
  font-weight: var(--weight-bold);
  color: var(--text-muted);
}
details.card[open] > summary { margin-bottom: var(--space-3); }
.ending { background: none; box-shadow: none; border-style: dashed; }

/* ===== Reachable without a mouse ========================================= */
/* A visible focus ring is not decoration: without it, keyboard and switch
   users navigate blind. It is drawn outside the element so it never changes
   layout, which is what makes it safe to apply everywhere. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--secondary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ===== Movement is a preference, not a given ============================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* What the child said, with room to hold it. The box opens at the size of a
   sentence rather than a search field: `rows` alone loses to any rule that
   sets a height, so the floor is stated here and cannot collapse under one. */
.action-box {
  min-height: 6.5rem;
  resize: vertical;
  line-height: var(--leading-body);
}

/* Tale or adventure. Two games, not two flavours of one — so the badge is
   readable as a WORD first and a colour second: an author who cannot separate
   the greens from the ambers still reads which is which. */
.pill-kind { letter-spacing: var(--tracking-caption); }
.pill-tale {
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.pill-adventure {
  background: color-mix(in srgb, var(--secondary) 14%, var(--surface-1));
  color: var(--secondary-hover);
  border: 1px solid var(--secondary);
}
.kinds { margin: 0; }
.kinds dt { margin-top: var(--space-3); }
.kinds dd {
  margin: var(--space-1) 0 0;
  color: var(--text-muted);
  font-size: var(--text-small);
  line-height: var(--leading-small);
}

/* One person or one place, as a block you can see the edges of — an author
   scanning a long canon needs to know where one ends and the next begins. */
.canon-row {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  background: var(--surface-1);
}
.canon-row > legend {
  padding: 0 var(--space-2);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
}

/* ---- the author's pictures, inside a person or a place ---- */
.pictures {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
}
.pictures-title {
  font-size: var(--text-small);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 var(--space-2);
}
.picture-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
}
.picture-strip li { display: flex; flex-direction: column; gap: var(--space-1); width: 120px; }
.picture-strip img {
  width: 120px;
  height: 120px;
  object-fit: cover;          /* a drawing of any shape reads as one tile */
  border-radius: var(--radius-md, 12px);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
}
.picture-remove { padding: var(--space-1) var(--space-2); font-size: var(--text-small); }
.picture-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
/* Present for submission, absent from the layout — never `display: none`,
   which would take its controls out of the accessibility tree too. */
.offscreen-form { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* The dice, tumbling. Sized so the cubes read at arm's length across a table,
   and hidden until the script knows WebGL works — the words below it are the
   answer, and a blank rectangle above them would look like a failure. */
.dice-stage {
  display: block;
  width: 100%;
  max-width: 480px;
  height: auto;
  margin: 0 auto var(--space-3);
}
.own-dice { margin-top: var(--space-3); display: grid; gap: var(--space-3); }

/* ---- reading dice with the camera ---- */
.camera-stage { background: var(--bg-sunken); border-radius: var(--radius-md, 12px); overflow: hidden; }
.camera-stage video { display: block; width: 100%; max-height: 420px; object-fit: contain; }
.camera-readout {
  font-family: var(--font-heading);
  font-size: 2.4rem;
  text-align: center;
  margin: var(--space-3) 0 0;
  color: var(--text-muted);
}
/* Settled is said in weight and colour AND in the status line below it, never
   by colour alone. */
.camera-readout[data-settled="yes"] { color: var(--text); font-weight: var(--weight-semibold); }

/* `hidden` means hidden, including on things this sheet gives a `display` to.
   The browser's own rule for [hidden] is `display: none` at the same weight as
   any class here, so `.btn { display: inline-flex }` quietly beat it and every
   button marked hidden in markup was on screen anyway — the dictation button,
   the camera's stop button, "not this child after all". This is the one place
   !important earns its keep: hidden is not a suggestion. */
[hidden] { display: none !important; }

/* The story so far: consulted, so quieter than the moment being read. */
.history-moment { border-top: 1px solid var(--border, var(--surface-2)); padding-top: var(--space-3); }
.history-moment:first-of-type { border-top: 0; }
.history-call { color: var(--text-muted); }

/* A title's drawn scene and its playable table: sandboxed frames that keep the
   drawing's own proportions (16:9) and give the table the whole screen. */
.scene-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #0f1d33;
}
.scene-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.board-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #1f3b35;
}
/* The scene is the stage: beside the board when the screen lies down, on top
   (half the screen) when it stands up. Each part scrolls on its own, never
   the page. */
.board-shell {
  display: grid;
  height: 100%;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
@media (orientation: portrait) {
  /* the drawing is wide: its row is as tall as it needs, at most half the screen */
  .board-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: min(50%, 56.25vw) minmax(0, 1fr); }
}
.board-page.no-scene .board-shell,
.board-page[data-role="narrator"] .board-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.board-play {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
}
.board-scene {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #1f3b35;
}
.board-scene[hidden] { display: none; }
/* A moment that takes the whole screen — the cover, the dice, a hero's
   cards, the narrator's drawer: the board covers the scene until it closes. */
.board-page.board-expanded .board-play { position: fixed; inset: 0; z-index: 3; }
.board-start {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: rgba(20, 15, 10, 0.62);
  color: #f2dfb0;
  font-size: 18px;
}
.board-start[hidden] { display: none; }
/* On the table, the tap lands on the board's own cover, seen through this. */
.board-start-cover { background: transparent; border: 0; padding: 0; cursor: pointer; }
.board-start-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.1;
  padding: 22px 40px;
  min-height: 84px;
  border: 6px solid #f2dfb0;
  border-radius: 14px;
  background: #ee5a36;
  color: #f2dfb0;
  cursor: pointer;
}
.board-start-btn:focus-visible { outline: 4px solid #f4be42; outline-offset: 4px; }

/* =============================================================================
   THE AUTHOR'S JOURNEY
   A title is made in seven steps. Inside a title the page is a workspace: a
   rail that is the path, and the step's own page beside it. Everything under
   #main reads the title's theme tokens, so the workspace wears the title's
   look; the bar above stays the platform's.
   ============================================================================= */

.topbar-inner { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.in-title .topbar-inner { max-width: 82rem; }
a.brand { text-decoration: none; }
a.brand:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: var(--radius-sm); }

.workspace {
  min-height: calc(100vh - 4.5rem);
  background: var(--bg);
  color: var(--text);
}
/* The spine: the title's three colours, as a book shows them on a shelf.
   Decorative only — it carries no text and no meaning a reader needs. */
.workspace-spine { display: flex; height: 6px; }
.workspace-spine span { flex: 1; }
.workspace-spine span:nth-child(1) { background: var(--primary); flex: 3; }
.workspace-spine span:nth-child(2) { background: var(--secondary); flex: 2; }
.workspace-spine span:nth-child(3) { background: var(--accent); }

.workspace-inner {
  max-width: 82rem;
  margin: 0 auto;
  padding: var(--space-6) var(--space-6) var(--space-12);
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  gap: var(--space-8);
  align-items: start;
}
.workspace-main { min-width: 0; max-width: 58rem; }

/* ---------- the rail ---------- */

.rail {
  position: sticky;
  top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-height: calc(100vh - var(--space-8));
  overflow-y: auto;
  padding: 2px;                       /* room for focus rings inside a scroller */
}
.rail-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  align-self: flex-start;
  padding: var(--space-1) var(--space-2) var(--space-1) 0;
  font-size: var(--text-small);
  line-height: var(--leading-small);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  text-decoration: none;
}
.rail-back:hover { color: var(--text); }

.rail-title {
  display: block;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
  color: var(--text);
  text-decoration: none;
}
.rail-title:hover { border-color: var(--secondary); color: var(--text); }
.rail-title[aria-current="page"] { border-color: var(--secondary); border-left-width: 4px; }
.rail-title-name {
  display: block;
  font-family: var(--font-heading);
  font-weight: var(--weight-black);
  font-size: var(--text-h4);
  line-height: var(--leading-h4);
  overflow-wrap: anywhere;
}
.rail-title-meta {
  display: block;
  margin-top: 2px;
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  color: var(--text-muted);
}

.progress { display: flex; align-items: center; gap: var(--space-3); }
.progress-bar {
  flex: 1;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-bar > span {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: var(--radius-pill);
  background: var(--success);
  transition: width var(--duration-base) var(--ease-gentle);
}
.progress-words {
  flex: none;
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  white-space: nowrap;
}

.rail-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rail-step-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: var(--text-small);
  line-height: var(--leading-small);
  font-weight: var(--weight-semibold);
  color: var(--text);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-gentle);
}
.rail-step-link:hover { background: var(--bg-sunken); color: var(--text); }
.rail-step-link:focus-visible,
.rail-page:focus-visible,
.rail-title:focus-visible,
.rail-back:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
/* Where you are: a card with a heavier edge and bolder words — shape and
   weight, not colour alone. */
.rail-step.is-current > .rail-step-link {
  background: var(--surface-1);
  border-color: var(--border);
  border-left: 4px solid var(--primary);
  padding-left: calc(var(--space-3) - 3px);
  font-weight: var(--weight-bold);
  box-shadow: var(--shadow-card);
}

/* The mark beside a step. A tick, or the step's number; the state is also
   said in words wherever the mark appears.

   "Done" and "in progress" are the platform's own green and amber, NOT the
   title's colours: a title whose second colour is red would otherwise tick
   its finished steps in red, and say the opposite of what it means. */
.step-mark {
  flex: none;
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1;
  font-weight: var(--weight-extra);
}
.step-mark-doing {
  border-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 22%, var(--surface-1));
  color: var(--text);
}
.step-mark-done {
  border-color: var(--success);
  background: var(--success);
  color: var(--text-on-color);
}

.rail-pages {
  list-style: none;
  margin: 2px 0 var(--space-2) calc(13px + var(--space-3));
  padding: 0 0 0 calc(13px + var(--space-2));
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rail-page {
  display: block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-small);
  line-height: var(--leading-small);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-decoration: none;
}
.rail-page:hover { background: var(--bg-sunken); color: var(--text); }
.rail-page[aria-current="page"] {
  background: var(--bg-sunken);
  color: var(--text);
  font-weight: var(--weight-extra);
  box-shadow: inset 3px 0 0 var(--secondary);
}

/* ---------- where this page sits in the journey ---------- */

.step-crumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-4);
  font-size: var(--text-small);
  line-height: var(--leading-small);
  color: var(--text-muted);
}
.step-crumb-where {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
}
.step-crumb-name { font-weight: var(--weight-bold); color: var(--text); }

.state {
  display: inline-block;
  padding: 1px var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  font-size: var(--text-caption);
  line-height: 20px;
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  white-space: nowrap;
}
.state-doing {
  border-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 18%, var(--surface-1));
  color: var(--text);
}
.state-done {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 14%, var(--surface-1));
  color: var(--text);
}

.step-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}
.step-nav-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--duration-fast) var(--ease-gentle),
              box-shadow var(--duration-fast) var(--ease-gentle);
}
.step-nav-link:hover { border-color: var(--secondary); box-shadow: var(--shadow-card); color: var(--text); }
.step-nav-link:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.step-nav-next { align-items: flex-end; text-align: right; }
.step-nav-dir {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: var(--tracking-caption);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  color: var(--text-muted);
}
.step-nav-name {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  font-size: var(--text-h4);
  line-height: var(--leading-h4);
}

/* A live table: the whole screen belongs to the story. One quiet way back. */
.focus-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  font-size: var(--text-small);
  font-weight: var(--weight-bold);
  color: var(--text-muted);
  text-decoration: none;
}
.focus-back:hover { color: var(--text); }

/* ---------- the guide: a title's home ---------- */

.guide-head { margin-bottom: var(--space-6); }
.guide-head h1 {
  font-size: var(--text-h1);
  line-height: var(--leading-h1);
  letter-spacing: var(--tracking-h1);
  font-weight: var(--weight-black);
  margin-bottom: var(--space-2);
}
.guide-meta { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 0; }

.next-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-4) var(--space-6);
  align-items: center;
  border-left: 6px solid var(--primary);
}
.next-card h2 { margin-bottom: var(--space-1); }
.next-card p { margin: 0; max-width: 40rem; }
.next-card .btn { white-space: nowrap; }

.guide-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.guide-step {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
}
.guide-step:first-child { border-top: none; }
.guide-step .step-mark { width: 36px; height: 36px; font-size: 15px; }
.guide-step .step-mark svg { width: 18px; height: 18px; }
.guide-step h3 { margin: 0; }
.guide-step h3 a { color: inherit; text-decoration: none; }
.guide-step h3 a:hover { text-decoration: underline; }
.guide-step-blurb {
  margin: 2px 0 0;
  max-width: 40rem;
  color: var(--text-muted);
  font-size: var(--text-small);
  line-height: var(--leading-small);
}
.guide-step-detail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-2) 0 0;
  font-size: var(--text-small);
  line-height: var(--leading-small);
}
/* The step to do now stands out by a band and a filled button — the others
   keep a quiet outline button, so there is one obvious thing to press. */
.guide-step.is-next {
  background: color-mix(in srgb, var(--primary) 7%, var(--surface-1));
  box-shadow: inset 6px 0 0 var(--primary);
}
.guide-step .btn { white-space: nowrap; }

/* ---------- the titles list: a shelf, not a table ---------- */

.title-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  gap: var(--space-6);
}
.title-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform var(--duration-fast) var(--ease-gentle),
              box-shadow var(--duration-fast) var(--ease-gentle);
}
.title-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.title-card:focus-within { box-shadow: var(--shadow-focus); }
/* The cover wears the title's own colours once it has a look; until then, the
   platform's paper. The initial is decoration — the name is in the body. */
.title-card-cover {
  position: relative;
  height: 96px;
  background: linear-gradient(135deg,
    var(--cover-1, var(--forest-200)) 0%,
    var(--cover-2, var(--gold-200)) 100%);
}
.title-card-cover::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 6px;
  background: var(--cover-3, var(--persimmon-400));
}
.title-card-initial {
  position: absolute;
  left: var(--space-6);
  bottom: -18px;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
  font-family: var(--font-heading);
  font-weight: var(--weight-black);
  font-size: 26px;
  color: var(--text);
  z-index: 1;
}
.title-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-6) var(--space-6);
}
.title-card-name { margin: 0; font-size: var(--text-h3); line-height: var(--leading-h3); overflow-wrap: anywhere; }
.title-card-name a { color: inherit; text-decoration: none; }
/* The whole card opens the title; the link's hit area is stretched over it. */
.title-card-name a::after { content: ""; position: absolute; inset: 0; }
.title-card { position: relative; }
.title-card-name a:focus-visible { outline: none; }
.title-card-meta { margin: 0; color: var(--text-muted); font-size: var(--text-small); line-height: var(--leading-small); }
.title-card-next {
  margin: var(--space-2) 0 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: var(--text-small);
  line-height: var(--leading-small);
}
.title-card-next strong { display: block; font-size: var(--text-body); line-height: var(--leading-body); }

.start-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: var(--space-4);
}
.start-option {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6);
  border: 2px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
}
.start-option h3 { margin: 0; }
.start-option p { margin: 0; color: var(--text-muted); font-size: var(--text-small); line-height: var(--leading-small); }
.start-option .btn { align-self: flex-start; margin-top: var(--space-2); }
.start-option-recommended { border-color: var(--secondary); }
.start-option > summary { cursor: pointer; list-style: none; }
.start-option > summary::-webkit-details-marker { display: none; }
.start-option[open] > summary { margin-bottom: var(--space-4); }
.start-option[open] > summary .btn { display: none; }
.start-option > summary > * + * { margin-top: var(--space-2); }
.start-option > summary .btn { display: inline-block; margin-top: var(--space-4); }
.start-option > summary:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: var(--radius-sm); }

/* ---------- the look ---------- */

.ref-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: var(--space-4);
  list-style: none;
  margin: 0;
  padding: 0;
}
.ref-tile {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  overflow: hidden;
}
.ref-tile-art { position: relative; aspect-ratio: 1; overflow: hidden; background: var(--bg-sunken); }
/* Pinned to the square, never stretching its tile past the others — and shown
   WHOLE. Cropping to fill took a tall cut-out figure down to its hat; a
   reference is looked at to see all of it. */
.ref-tile-art img { position: absolute; inset: var(--space-2); width: calc(100% - 2 * var(--space-2)); height: calc(100% - 2 * var(--space-2)); object-fit: contain; object-position: center; display: block; }
.ref-tile-count {
  position: absolute;
  right: var(--space-2);
  bottom: var(--space-2);
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  border: 1px solid var(--border);
  font-size: var(--text-caption);
  line-height: 20px;
  font-weight: var(--weight-bold);
}
.ref-tile-empty {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border: 2px dashed var(--border-strong);
  border-radius: 10px 10px 0 0;
  color: var(--text-muted);
  font-size: var(--text-small);
  text-align: center;
  padding: var(--space-3);
}
.ref-tile-body { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-2) var(--space-3) var(--space-3); }
.ref-tile-name { font-weight: var(--weight-bold); font-size: var(--text-small); line-height: var(--leading-small); overflow-wrap: anywhere; }
.ref-tile-kind { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: var(--weight-bold); }
.ref-tile .btn { padding: var(--space-1) var(--space-3); font-size: var(--text-small); align-self: flex-start; }
.file-button { position: relative; overflow: hidden; cursor: pointer; }
.file-button input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-button:focus-within { box-shadow: var(--shadow-focus); }

.look-grid {
  display: grid;
  grid-template-columns: minmax(0, 21rem) minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}
.look-preview { position: sticky; top: var(--space-4); }
.swatch-list { list-style: none; margin: 0; padding: 0; }
.swatch-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 6.5rem;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}
.swatch-row:first-child { border-top: none; }
.swatch-row label { font-weight: var(--weight-bold); font-size: var(--text-small); line-height: var(--leading-small); }
.swatch-row small { display: block; font-weight: var(--weight-regular); color: var(--text-muted); }
.swatch-row input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface-1);
  cursor: pointer;
}
.swatch-row input[type="text"] { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--text-small); padding: var(--space-2); text-transform: uppercase; }
.found-swatches { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0 0; padding: 0; list-style: none; }
.found-swatches li {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
}

/* The preview is a small piece of the real workspace: it reads the same
   tokens, set on this element by the editor, so what it shows is what the
   components will actually do with those colours. */
.look-stage {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-lift);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}
.look-stage-body { padding: var(--space-6); display: grid; gap: var(--space-4); }
.look-stage h3 { font-family: var(--font-heading); font-size: var(--text-h2); line-height: var(--leading-h2); margin: 0; color: var(--text); }
.look-stage p { margin: 0; }
.look-stage .card:hover { transform: none; }
.look-stage-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.look-check { display: grid; gap: var(--space-1); margin: var(--space-3) 0 0; font-size: var(--text-small); line-height: var(--leading-small); }

/* ---------- screens & board ---------- */

.scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: var(--space-4);
  list-style: none;
  margin: 0;
  padding: 0;
}
.scene-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  overflow: hidden;
}
.scene-tile iframe { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; background: var(--bg-sunken); }
.scene-tile-play {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: var(--bg-sunken);
  cursor: pointer;
}
.scene-tile-play img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.scene-tile-play-badge {
  position: absolute;
  right: var(--space-2);
  bottom: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);       /* white on this ≥ 10:1 over any picture */
  color: #FFFFFF;
  font-size: var(--text-caption);
  font-weight: 700;
}
.scene-tile-play:hover .scene-tile-play-badge,
.scene-tile-play:focus-visible .scene-tile-play-badge { background: #000000; }
.scene-tile-play:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.scene-player {
  width: min(64rem, 94vw);
  padding: var(--space-4);
  border: 0;
  border-radius: var(--radius-card);
  background: var(--surface-1);
  color: var(--text);
}
.scene-player::backdrop { background: rgba(0, 0, 0, 0.6); }
.scene-player-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.scene-player-head h3 { margin: 0; }
.scene-player-frame iframe { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 8px; background: #000; }
.scene-tile-caption { padding: var(--space-2) var(--space-3) var(--space-3); }
.scene-tile-caption strong { display: block; font-size: var(--text-small); line-height: var(--leading-small); overflow-wrap: anywhere; }
.scene-tile-caption span { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--text-muted); }

.soon {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-card);
  padding: var(--space-6);
  background: transparent;
}
.soon h2 { margin-bottom: var(--space-2); }
.soon p:last-child { margin-bottom: 0; }

/* ---------- narrow screens: the rail lies down ---------- */

@media (max-width: 62rem) {
  .workspace-inner { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); padding: var(--space-4) var(--space-4) var(--space-12); }
  .rail { position: static; max-height: none; overflow: visible; }
  .rail-steps { flex-direction: row; overflow-x: auto; gap: var(--space-1); padding-bottom: var(--space-1); }
  .rail-step { flex: none; }
  .rail-step-link { white-space: nowrap; }
  .rail-step.is-current { display: flex; align-items: center; gap: var(--space-1); }
  .rail-pages { flex-direction: row; margin: 0; padding: 0; border-left: none; }
  .rail-page { white-space: nowrap; }
  .look-grid { grid-template-columns: minmax(0, 1fr); }
  .ref-board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .look-preview { position: static; }
  .next-card { grid-template-columns: minmax(0, 1fr); }
  .guide-step { grid-template-columns: auto minmax(0, 1fr); padding: var(--space-4); }
  .guide-step .btn { grid-column: 2; justify-self: start; }
  .step-nav { grid-template-columns: minmax(0, 1fr); }
  .step-nav-next { align-items: flex-start; text-align: left; }
}

@media print {
  .rail, .step-nav, .workspace-spine { display: none !important; }
  .workspace-inner { display: block; padding: 0; }
}

/* The bar on a phone: one line, and the account's address gives way first. */
.nav-pill { white-space: nowrap; }
@media (max-width: 40rem) {
  .topbar-inner { gap: var(--space-3); padding-left: var(--space-4); padding-right: var(--space-4); }
  .nav-pills { margin-left: 0; max-width: 100%; overflow-x: auto; }
  .signed-in-who { display: none; }
}

/* A word the AI suggested and the author has not saved yet. Dashed, like
   everything provisional here — and said in a word, not by colour alone. */
.pill-suggested {
  background: color-mix(in srgb, var(--warning) 16%, var(--surface-1));
  border: 1px dashed var(--warning);
  color: var(--text);
}

/* Thirty voices to compare by ear: a grid to scan, not a column to scroll. */
.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  align-items: stretch;
}
.voice-grid .btn { text-align: center; }

/* A drawing the AI made for the author says so on the picture itself. */
.ref-tile-badge {
  position: absolute;
  left: var(--space-2);
  top: var(--space-2);
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  border: 1px dashed var(--border-strong);
  background: var(--surface-1);
  color: var(--text);
  font-size: var(--text-caption);
  line-height: 20px;
  font-weight: var(--weight-bold);
}
.ref-tile-body .btn { margin-top: var(--space-1); }
.ref-tile-note { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--text-muted); }

/* =============================================================================
   NUMBERS — an author's results and the owner's finances.
   Figures line up on the right in tabular digits; a state is never said by
   colour alone (a loss carries a minus sign and the word).
   ============================================================================= */

.rail-results {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
  border-radius: 0 0 12px 12px;
  font-size: var(--text-small);
  line-height: var(--leading-small);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-decoration: none;
}
.rail-results svg { flex: none; width: 26px; }
.rail-results:hover { color: var(--text); background: var(--bg-sunken); }
.rail-results:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.rail-results[aria-current="page"] {
  color: var(--text);
  font-weight: var(--weight-bold);
  background: var(--surface-1);
  box-shadow: inset 4px 0 0 var(--primary);
}

.month-nav {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.month-nav .btn { padding: var(--space-1) var(--space-4); font-size: var(--text-small); }
.month-nav-label {
  min-width: 11rem;
  text-align: center;
  font-family: var(--font-heading);
  font-size: var(--text-h4);
  line-height: var(--leading-h4);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: var(--space-3);
  margin: 0;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
}
.stat dt {
  font-size: var(--text-caption);
  line-height: var(--leading-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  color: var(--text-muted);
}
.stat dd {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: var(--weight-black);
  font-size: var(--text-h4);
  line-height: var(--leading-h3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-note { font-size: var(--text-caption); line-height: var(--leading-caption); color: var(--text-muted); }
.stat-strong { border-color: var(--secondary); border-left-width: 4px; }

/* Dense on purpose: these are tables to read across, and every column has to
   be on screen at once — a figure scrolled out of sight is a figure unread. */
table.numbers tbody th, table.numbers tbody td { font-size: var(--text-small); line-height: var(--leading-small); padding: var(--space-3) var(--space-2); }
table.numbers thead th { padding: var(--space-2); letter-spacing: 0.04em; white-space: normal; vertical-align: bottom; }
table.numbers .when { white-space: nowrap; }
table.numbers tbody th[scope="row"] { font-weight: var(--weight-semibold); text-align: left; border-bottom: 1px solid var(--border); }
table.numbers tbody tr:last-child th { border-bottom: none; }
table.numbers td.who { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
table.numbers .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.numbers thead th.num { text-align: right; }
table.statement { max-width: 34rem; }
table.statement th.less { font-weight: var(--weight-regular); color: var(--text-muted); padding-left: var(--space-6); }
table.statement tr.subtotal th, table.statement tr.subtotal td { border-top: 1px solid var(--border-strong); font-weight: var(--weight-bold); }
table.statement tr.total th, table.statement tr.total td {
  border-top: 2px solid var(--text);
  font-family: var(--font-heading);
  font-size: var(--text-body-lg);
  font-weight: var(--weight-black);
}

/* ---- the Look page: a title's own design, and more characters ---- */
.title-look-offer { border-left: 4px solid var(--primary); }
.title-look-sample { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.title-look-swatch {
  width: 2rem; height: 2rem; border-radius: 999px;
  border: 1px solid var(--border-strong);
}
.title-look-fonts { margin-left: var(--space-2); color: var(--text-muted); font-size: 0.9rem; }
.more-people { margin-top: var(--space-6); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.more-people-ways { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-4); }
.more-people-ask { flex: 1 1 18rem; max-width: 34rem; }
/* A card the AI proposed: plainly not saved yet. */
.canon-row-proposed { border: 2px dashed var(--primary); }
.canon-row-proposed > legend { color: var(--text); }

/* Drawings the AI writes as code: the picture beside what to do with it. */
.check { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-small); }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--primary); }
.drawing-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.drawing-card {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
}
.drawing-card-proposed { border: 2px dashed var(--primary); }
.drawing-art { align-self: start; border-radius: 8px; overflow: hidden; background: var(--bg-sunken); }
.drawing-player { width: 100%; }
.drawing-art-character .drawing-player { max-height: 26rem; margin-inline: auto; }
.drawing-player img { display: block; width: 100%; height: 100%; object-fit: contain; }
/* the frames are one picture moved behind this window, one frame at a time */
.drawing-frames { width: 100%; height: 100%; background-repeat: no-repeat; }
.drawing-title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; }
.drawing-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.drawing-actions form { margin: 0; }
@media (max-width: 720px) {
  .drawing-card { grid-template-columns: 1fr; }
}
