/* Layout: a sign in screen first, then a script rail on the left, the chosen script on the right, and a full screen black stage with a gold reading line for the prompter. */
:root {
  --bg: #F3F3F1;
  --surface: #FFFFFF;
  --hover: #E9E7E1;
  --ink: #17161A;
  --muted: rgba(23, 22, 26, 0.62);
  --faint: rgba(23, 22, 26, 0.40);
  --line: rgba(23, 22, 26, 0.09);
  --line-strong: rgba(23, 22, 26, 0.18);
  --gold: #9A6E10;
  --gold-text: #7A560A;
  --gold-soft: #F2ECE0;
  --gold-ring: rgba(154, 110, 16, 0.22);
  --on-gold: #FFFFFF;
  --build: #C2410C;
  --running: #15803D;
  --organize: #0B74A8;

  --stage: #000000;
  --stage-ink: #F7F5F0;
  --stage-muted: rgba(247, 245, 240, 0.46);
  --stage-gold: #EFC463;
  --stage-panel: #0E0D0C;

  --font-display: "Plus Jakarta Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-prompt: "Atkinson Hyperlegible", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #100F0D;
    --surface: #1C1A17;
    --hover: #24221E;
    --ink: #FAFAF8;
    --muted: rgba(250, 250, 248, 0.62);
    --faint: rgba(250, 250, 248, 0.38);
    --line: rgba(250, 250, 248, 0.09);
    --line-strong: rgba(250, 250, 248, 0.18);
    --gold: #EFC463;
    --gold-text: #F3D08A;
    --gold-soft: #3A3222;
    --gold-ring: rgba(239, 196, 99, 0.28);
    --on-gold: #17161A;
    --build: #FB923C;
    --running: #4ADE80;
    --organize: #5BC8F3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #100F0D;
  --surface: #1C1A17;
  --hover: #24221E;
  --ink: #FAFAF8;
  --muted: rgba(250, 250, 248, 0.62);
  --faint: rgba(250, 250, 248, 0.38);
  --line: rgba(250, 250, 248, 0.09);
  --line-strong: rgba(250, 250, 248, 0.18);
  --gold: #EFC463;
  --gold-text: #F3D08A;
  --gold-soft: #3A3222;
  --gold-ring: rgba(239, 196, 99, 0.28);
  --on-gold: #17161A;
  --build: #FB923C;
  --running: #4ADE80;
  --organize: #5BC8F3;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html.prompting, html.prompting body { overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.app {
  min-height: 100%;
  padding-inline: clamp(16px, 3vw, 32px);
}

/* Top bar */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 14px;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { flex: none; color: var(--gold); }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg .short { display: none; }
.seg {
  display: inline-flex;
  flex: none;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* Two pane layout */
.layout {
  display: grid;
  grid-template-columns: minmax(230px, 290px) minmax(0, 1fr);
  gap: clamp(20px, 3.5vw, 48px);
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 8px 0;
}
.rail {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 64px);
  align-self: start;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding-bottom: 24px;
}
.rail-heading, .label {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.label { display: block; }
.rail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rail-item {
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.rail-item:hover { background: var(--hover); }
.rail-item[aria-current="true"] { background: var(--surface); box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(16, 16, 20, 0.05); }
.rail-item[aria-current="true"] .rail-title { font-weight: 600; }
.rail-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rail-title { font-size: 14px; line-height: 1.35; }
.rail-select-wrap { display: none; }
.rail-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}

.pillar { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; }
.pillar::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pillar-build { color: var(--build); }
.pillar-running { color: var(--running); }
.pillar-organize { color: var(--organize); }
.status { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--gold-soft); color: var(--gold-text); }

/* Script panel */
.panel { min-width: 0; display: flex; flex-direction: column; }
.eyebrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  margin: 4px 0 6px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.panel h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.022em;
  text-wrap: balance;
}
.notes { margin-top: 14px; }
.notes summary {
  cursor: pointer;
  width: fit-content;
  font-size: 14px;
  font-weight: 500;
  color: var(--gold-text);
  list-style: none;
}
.notes summary::-webkit-details-marker { display: none; }
.notes summary::before { content: "+ "; font-weight: 600; }
.notes[open] summary::before { content: "\2212  "; }
.notes-body {
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 14px;
  max-width: 68ch;
}
.notes-body p { margin: 0 0 8px; }
.notes-body p:last-child, .notes-body ul:last-child { margin-bottom: 0; }
.notes-body ul { margin: 0 0 8px; padding-left: 18px; display: grid; gap: 4px; }
.notes-body code, .hint code { font-size: 0.92em; padding: 0 4px; border-radius: 5px; background: var(--hover); }

.block { margin-top: 30px; }
.block-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 10px; }
.block-head .label { margin: 0; }
.stat { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }

.hooks { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.hook {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.hook:hover { border-color: var(--line-strong); }
.hook[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-ring); }
.hook-label { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.hook-label .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.hook[aria-pressed="true"] .hook-label { color: var(--gold-text); }
.hook[aria-pressed="true"] .dot { box-shadow: inset 0 0 0 4px var(--gold); }
.hook-spoken { font-family: var(--font-prompt); font-size: 17px; font-weight: 700; line-height: 1.35; }
.hook-meta { display: grid; gap: 4px; font-size: 13px; color: var(--muted); line-height: 1.4; }
.hook-meta b { font-weight: 600; color: var(--ink); margin-right: 5px; }
.hook-meta i { font-style: normal; color: var(--faint); }

.hint { margin-top: 10px; font-size: 13.5px; color: var(--muted); max-width: 72ch; }
.hint p { margin: 0 0 4px; }
.hint .applied { display: flex; align-items: center; gap: 6px; color: var(--gold-text); font-weight: 500; }
.hint .applied svg { flex: none; }

.chip-btn {
  border: 0;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--gold-soft);
  color: var(--gold-text);
  cursor: pointer;
}
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); }
.ghost {
  border: 1px solid var(--line-strong);
  background: transparent;
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.ghost:hover { background: var(--hover); }

.lines { list-style: none; margin: 0; padding: 0; border-bottom: 1px solid var(--line); }
.lines li { display: grid; gap: 3px; padding: 12px 0 13px; border-top: 1px solid var(--line); }
.lines .shot { font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
.lines .is-hook .shot { color: var(--gold-text); }
.lines .text { font-family: var(--font-prompt); font-size: 18px; line-height: 1.45; max-width: 60ch; }
.lines .is-removed .text { text-decoration: line-through; color: var(--faint); }
.lines .removed-tag { font-size: 12.5px; color: var(--faint); }
mark.fill { background: var(--gold-soft); color: var(--gold-text); border-radius: 4px; padding: 0 0.15em; }

.editor textarea {
  display: block;
  width: 100%;
  min-height: 260px;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-prompt);
  font-size: 17px;
  line-height: 1.5;
  resize: vertical;
}
.editor-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.editor-row p { margin: 0; font-size: 13px; color: var(--muted); }
.editor-row .actions { display: flex; gap: 8px; }

.keys { margin-top: 34px; font-size: 13px; color: var(--muted); }
.keys dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 18px; margin: 0; }
.keys dl div { display: flex; align-items: center; gap: 8px; }
.keys dt { display: flex; gap: 4px; min-width: 58px; }
.keys dd { margin: 0; }
kbd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  background: var(--surface);
  color: var(--ink);
}
.keys .touch { display: none; margin: 0; }
.keys .tip { margin: 12px 0 0; max-width: 72ch; }
@media (hover: none) and (pointer: coarse) {
  .keys dl { display: none; }
  .keys .touch { display: block; }
}
.foot-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 26px; }
.foot { margin: 0; flex: 1 1 260px; font-size: 12.5px; color: var(--faint); }

.startbar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 24px;
  padding-block: 14px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.start {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  padding: 13px 24px 13px 20px;
  background: var(--gold);
  color: var(--on-gold);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 16, 20, 0.08), 0 8px 24px rgba(16, 16, 20, 0.10);
}
.start:hover { filter: brightness(1.05); }
.start-meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .rail { position: static; max-height: none; overflow: visible; padding-bottom: 0; }
  .rail-list { display: none; }
  .rail-select-wrap { display: block; }
}
@media (max-width: 480px) {
  .topbar { gap: 8px; }
  .brand { gap: 8px; }
  .brand-name { font-size: 15px; }
  .top-actions { gap: 8px; }
  .seg button { padding: 6px 10px; }
  .seg .long { display: none; }
  .seg .short { display: inline; }
}

/* Prompter: always a black stage, whatever the page theme */
.prompter {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--stage);
  color: var(--stage-ink);
  color-scheme: dark;
}
.prompter:focus { outline: none; }
.stage { position: relative; flex: 1; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.mirror-wrap { position: absolute; inset: 0; display: flex; justify-content: center; }
.mirror-wrap.is-mirrored { transform: scaleX(-1); }
.column { position: relative; height: 100%; }
.track { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.content { position: relative; font-family: var(--font-prompt); font-weight: 700; line-height: 1.3; padding-bottom: 70vh; }
.para { padding-bottom: 0.75em; }
.pshot {
  margin-bottom: 0.35em;
  font-family: var(--font-body);
  font-size: max(12px, 0.3em);
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-transform: uppercase;
  color: var(--stage-muted);
}
.para.is-hook .pshot { color: var(--stage-gold); }
.ptext { margin: 0; }
.ptext mark.fill { background: rgba(239, 196, 99, 0.18); color: var(--stage-gold); }
.fade-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, var(--stage) 0%, rgba(0, 0, 0, 0.82) 45%, rgba(0, 0, 0, 0) 100%);
}
.reading-line { position: absolute; left: 0; right: 0; height: 0; pointer-events: none; }
.reading-line::before {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  top: 0;
  border-top: 1px solid rgba(239, 196, 99, 0.22);
}
.reading-line svg { position: absolute; top: -9px; color: var(--stage-gold); }
.reading-line .left { left: 6px; }
.reading-line .right { right: 6px; transform: scaleX(-1); }
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(96px, 22vmin, 240px);
  color: var(--stage-gold);
  background: rgba(0, 0, 0, 0.55);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.countdown.tick { animation: pop 0.8s ease-out; }
@keyframes pop { from { transform: scale(1.18); opacity: 0.4; } 30% { opacity: 1; } to { transform: scale(1); } }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, 0.07); pointer-events: none; }
.progress-bar { height: 100%; background: var(--stage-gold); transform-origin: left center; transform: scaleX(0); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 22px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--stage-panel);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  transition: opacity 0.25s ease;
}
.prompter.is-idle .controls { opacity: 0; pointer-events: none; }
.prompter.is-idle .stage { cursor: none; }
.cgroup { display: flex; align-items: center; gap: 6px; }
.cgroup-label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--stage-muted); margin-right: 2px; }
.cbtn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--stage-ink);
  cursor: pointer;
  font-weight: 700;
}
.cbtn:hover { background: rgba(255, 255, 255, 0.13); }
.cbtn[aria-pressed="true"] { background: rgba(239, 196, 99, 0.2); color: var(--stage-gold); }
.cbtn:focus-visible { outline: 2px solid var(--stage-gold); outline-offset: 2px; }
.cbtn.play { width: 54px; height: 54px; border-radius: 50%; background: var(--stage-gold); color: #17161A; }
.cbtn.play:hover { background: #F4D17F; }
.cval { min-width: 64px; text-align: center; font-size: 13px; color: rgba(247, 245, 240, 0.8); font-variant-numeric: tabular-nums; }
.time { min-width: 44px; font-size: 14px; color: rgba(247, 245, 240, 0.7); font-variant-numeric: tabular-nums; text-align: right; }
.a-small { font-size: 13px; }
.a-big { font-size: 19px; }

@media (max-width: 560px) {
  .controls { gap: 8px 12px; }
  .cgroup-label { display: none; }
  .cbtn { width: 40px; height: 40px; }
  .cval { min-width: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  .countdown.tick { animation: none; }
  .controls, .hook { transition: none; }
}

/* Sign in and status screens */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.gate-card { display: grid; justify-items: center; gap: 14px; width: min(100%, 440px); text-align: center; }
.gate-card h1 { margin: 0; font-family: var(--font-display); font-size: 26px; letter-spacing: -0.02em; }
.gate-card p { margin: 0; color: var(--muted); max-width: 40ch; }
.gate-card svg { color: var(--gold); }
#signIn:empty { display: none; }
.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.top-actions { display: flex; align-items: center; gap: 12px; flex: none; }
.user-slot { display: flex; align-items: center; min-width: 28px; min-height: 28px; }
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.rail-head .rail-heading { margin: 0; }
.ghost.small { padding: 4px 11px; font-size: 12.5px; }
.ghost:disabled { opacity: 0.55; cursor: progress; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.empty { display: none; max-width: 52ch; padding-block: 24px; }
.empty h1 { margin-bottom: 10px; }
.empty p { margin: 0 0 16px; color: var(--muted); }
.panel.is-empty > * { display: none; }
.panel.is-empty > .empty { display: block; }

.save-state { font-size: 12px; color: var(--faint); }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 70;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 8px 28px rgba(16, 16, 20, 0.22);
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}
