/* ---------- Theme tokens (three-state: system / light / dark) ---------- */
:root {
  --paper: #f6f4ef;
  --surface: #fffdf8;
  --surface-2: #f1eee5;
  --ink: #23252b;
  --muted: #6f6b61;
  --line: #e3ded1;
  --gold: #b0741c;
  --gold-ink: #7a4f11;
  --gold-soft: #f2e6cd;
  --teal: #1f6b63;
  --teal-soft: #dcece8;
  --danger: #b23a2e;
  --shadow: 0 1px 2px rgba(40, 33, 20, 0.06), 0 8px 24px rgba(40, 33, 20, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
}
:root:not([data-theme="light"]) {
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131417;
    --surface: #1b1d21;
    --surface-2: #232529;
    --ink: #ece9e2;
    --muted: #a29d90;
    --line: #2d2f34;
    --gold: #e0a54a;
    --gold-ink: #f0c883;
    --gold-soft: #37301f;
    --teal: #5cc3b6;
    --teal-soft: #163330;
    --danger: #e8897d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #131417;
  --surface: #1b1d21;
  --surface-2: #232529;
  --ink: #ece9e2;
  --muted: #a29d90;
  --line: #2d2f34;
  --gold: #e0a54a;
  --gold-ink: #f0c883;
  --gold-soft: #37301f;
  --teal: #5cc3b6;
  --teal-soft: #163330;
  --danger: #e8897d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(14px, 4vw, 28px);
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--gold), var(--teal));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--surface) 60%, transparent);
}
.brand-name {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: 0.2px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.66rem;
}
.legend-chip {
  padding: 3px 7px;
  border-radius: 20px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.legend-chip.prep { color: var(--gold-ink); background: var(--gold-soft); border-color: transparent; }
.legend-chip.present { color: var(--teal); background: var(--teal-soft); border-color: transparent; }
.legend-arrow { color: var(--muted); }
.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: grid;
  place-items: center;
}
.icon-btn:hover { border-color: var(--gold); }
.icon-btn.signed-in { border-color: var(--teal); background: var(--teal-soft); color: var(--teal); }

.text-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
}
.text-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.sync-line {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 16px;
}
.linkbtn {
  background: none;
  border: none;
  padding: 0;
  color: var(--teal);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- Progress: mini "Ready, Set, Go!" sheet ---------- */
.progress {
  padding: 12px clamp(14px, 4vw, 28px) 0;
}
.sheetmap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 620px;
  margin: 0 auto;
}
.sm-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.sm-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 9px;
  font: inherit;
  font-size: 0.72rem;
  line-height: 1.1;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.sm-cell.wide { width: 100%; }
.sm-cell.small { min-width: 30px; padding: 5px 7px; flex: 1; }
.sm-cell:hover:not(:disabled) { border-color: var(--gold); }
.sm-cell:disabled { opacity: 0.5; cursor: default; }
.sm-cell.done { color: var(--ink); background: var(--surface-2); }
.sm-cell.active {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--ink);
  font-weight: 600;
}
.sm-num {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.6rem;
  background: var(--teal-soft);
  color: var(--teal);
  border-radius: 10px;
  padding: 1px 5px;
}
.sm-cell.active .sm-num { background: var(--gold); color: #1c1408; }
.sm-lane {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sm-lane-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 88px;
  font-size: 0.7rem;
  color: var(--muted);
}
.sm-cells { display: flex; gap: 4px; flex: 1; }
.pnode {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.74rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.pnode .pnum {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.66rem;
  color: var(--gold-ink);
}
.pnode.done { color: var(--ink); }
.pnode.done .pnum { color: var(--teal); }
.pnode.active {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--ink);
  font-weight: 600;
}
.pnode.active .pnum { color: var(--gold-ink); }

/* ---------- Stage / cards ---------- */
.stage {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 30px);
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 32px);
  animation: rise 0.28s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.eyebrow .seq {
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--teal-soft);
  color: var(--teal);
}
.eyebrow .seq.prep { background: var(--gold-soft); color: var(--gold-ink); }

.step-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.6rem, 5vw, 2.1rem);
  line-height: 1.12;
  margin: 0 0 10px;
  text-wrap: balance;
}
.step-help {
  color: var(--muted);
  margin: 0 0 20px;
  max-width: 58ch;
}

.field-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
  display: block;
}

.recap {
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 0 0 20px;
}
.recap-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--teal);
  margin-bottom: 6px;
}
.recap-list { margin: 0; padding-left: 20px; }
.recap-list li { margin: 3px 0; line-height: 1.45; }
.recap-empty {
  color: var(--muted);
  font-size: 0.86rem;
  font-style: italic;
}
.input-wrap { position: relative; }
textarea.answer {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  padding: 14px 52px 14px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}
textarea.answer:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.mic-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
}
.mic-btn:hover { border-color: var(--gold); }
.mic-btn.listening {
  border-color: var(--danger);
  color: var(--danger);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}
.mic-note { font-size: 0.74rem; color: var(--muted); margin-top: 6px; }

/* ---------- Ideas ---------- */
.ideas-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 0 12px;
}
.ideas-head h3 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: 1.05rem;
  margin: 0;
}
.ideas { display: flex; flex-direction: column; gap: 10px; }
.idea {
  text-align: left;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  line-height: 1.45;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  transition: border-color 0.15s, background 0.15s;
}
.idea:hover { border-color: var(--gold); }
.idea-rank {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  margin-top: 1px;
}
.idea-rank.best {
  background: var(--gold);
  border-color: var(--gold);
  color: #1c1408;
}
.idea .tick {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  color: transparent;
  margin-top: 1px;
}
.idea.picked {
  border-color: var(--gold);
  background: var(--gold-soft);
}
.idea.picked .tick {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
}

.hint { font-size: 0.78rem; color: var(--muted); }
.seed-wrap { margin: 0 0 12px; }
.seed-input { border-style: dashed; }
.seed-input:focus { border-style: solid; }
.seed-note { font-size: 0.72rem; color: var(--muted); margin: 5px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #1c1408; }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--gold) 88%, #000); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover:not(:disabled) { border-color: var(--gold); }
.btn.teal { background: var(--teal); color: #fff; }
.btn.block { width: 100%; justify-content: center; }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  color: var(--danger);
  font-size: 0.84rem;
  margin-top: 10px;
}

/* ---------- Nav ---------- */
.navbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(14px, 4vw, 28px);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
}
.step-count {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  color: var(--muted);
}

/* ---------- Assemble / final ---------- */
.assemble-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.7rem, 5vw, 2.2rem);
  margin: 0 0 6px;
}
.assemble-sub { color: var(--muted); margin: 0 0 22px; }
.script-block { margin-bottom: 22px; }
.script-block .sb-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.script-block .sb-seq {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--teal);
  border: 1px solid var(--teal-soft);
  background: var(--teal-soft);
  border-radius: 20px;
  padding: 2px 8px;
}
.script-block h4 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.15rem;
  margin: 0;
}
.script-block ul { margin: 4px 0 0; padding-left: 20px; }
.script-block li { margin: 3px 0; }
.script-block p.body { margin: 4px 0 0; }
.script-block p.topic-name { margin: 12px 0 0; color: var(--gold-ink); }
.script-block p.topic-name:first-of-type { margin-top: 4px; }
.script-block .empty { color: var(--muted); font-style: italic; }
.notes-box {
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 22px;
  background: var(--surface-2);
}
.notes-box h4 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.prep-sub {
  font-weight: 600;
  font-size: 0.82rem;
  margin: 12px 0 4px;
  color: var(--teal);
}
.audience-notes .pair {
  margin: 8px 0 0;
  padding-left: 12px;
  border-left: 2px solid var(--line);
}
.final-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.edit-hint {
  font-size: 0.82rem;
  color: var(--muted);
  border-left: 3px solid var(--gold);
  padding: 4px 0 4px 12px;
  margin: 4px 0 18px;
}

/* Library */
.lib-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.icon-btn.sm { width: 32px; height: 32px; font-size: 0.9rem; }
.story-list { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 22px; }
.story-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 6px 8px 6px 4px;
}
.story-row.current { border-color: var(--gold); background: var(--gold-soft); }
.story-open {
  flex: 1;
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-radius: 8px;
}
.story-open:hover { background: color-mix(in srgb, var(--gold) 12%, transparent); }
.story-name {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1.08rem;
  line-height: 1.2;
}
.story-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--muted);
}
.story-actions { display: flex; align-items: center; gap: 6px; padding-right: 4px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.84rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 30;
}
.toast.show { opacity: 1; }

@media print {
  .topbar, .progress, .navbar, .final-actions, #themeToggle { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: none; }
}
