:root {
  --bg: #1a1218;
  --ink: #f7efe8;
  --muted: #c4b0bc;
  --gold: #e8c36a;
  --gold-dim: #b8893a;
  --mint: #7ec9a4;
  --right: #7ec9a4;
  --wrong: #f07178;
  --curtain: #6b1e2a;
  --panel: rgba(36, 24, 32, 0.96);
  --shadow: 0 18px 50px rgba(0,0,0,.45);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Source Sans 3", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); font-family: var(--sans);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(232,195,106,.18), transparent 55%),
    linear-gradient(180deg, #22151d 0%, var(--bg) 42%, #120d11 100%);
  position: relative; overflow-x: hidden;
}
.curtain {
  position: fixed; top: 0; bottom: 0; width: min(9vw, 88px); z-index: 0; pointer-events: none;
  background: linear-gradient(90deg, #4a1520, var(--curtain) 40%, #3a1018); opacity: .88;
}
.curtain.left { left: 0; box-shadow: inset -12px 0 24px rgba(0,0,0,.35); }
.curtain.right { right: 0; box-shadow: inset 12px 0 24px rgba(0,0,0,.35); }
.topbar, main, .foot { position: relative; z-index: 1; }
.topbar {
  max-width: 980px; margin: 0 auto; padding: 26px 24px 8px;
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
}
.brand { display: flex; gap: 14px; align-items: center; }
.mark {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px;
  background: linear-gradient(145deg, var(--gold), var(--gold-dim)); color: #2a1a10;
  box-shadow: 0 8px 20px rgba(184,137,58,.35);
}
.brand h1 { margin: 0; font-family: var(--display); font-size: 1.55rem; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: .95rem; }
.top-stats { display: flex; gap: 18px; color: var(--muted); font-size: .92rem; }
.top-stats strong { color: var(--gold); font-family: var(--mono); }
main { max-width: 980px; margin: 0 auto; padding: 12px 24px 40px; }
.panel {
  background: var(--panel); border: 1px solid rgba(232,195,106,.16);
  border-radius: 18px; box-shadow: var(--shadow); padding: 28px;
}
.eyebrow {
  margin: 0 0 6px; text-transform: uppercase; letter-spacing: .14em;
  font-size: .72rem; color: var(--gold); font-weight: 700;
}
h2 { font-family: var(--display); margin: 0 0 8px; font-size: 1.75rem; }
h3.section-label { margin: 22px 0 12px; font-size: 1rem; color: var(--muted); font-weight: 600; }
.lede { color: var(--muted); max-width: 58ch; line-height: 1.5; margin: 0 0 18px; }
.controls-row {
  display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: center; margin-bottom: 18px;
}
.control { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.control select {
  font: inherit; color: var(--ink); background: #140f13; border: 1px solid rgba(232,195,106,.28);
  border-radius: 10px; padding: 8px 12px;
}
.control.check { flex-direction: row; align-items: center; gap: 8px; margin-top: 18px; }
.mode-cards { margin-bottom: 8px; }
.mode-card {
  width: 100%; text-align: left; border-radius: 14px; padding: 16px 18px; cursor: pointer;
  border: 1px solid rgba(232,195,106,.35); background: rgba(232,195,106,.08); color: var(--ink); font: inherit;
}
.mode-card strong { display: block; font-family: var(--display); font-size: 1.15rem; margin: 4px 0 6px; }
.mode-card span:last-child { color: var(--muted); font-size: .92rem; }
.lesson-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px;
}
.lesson-card {
  text-align: left; border-radius: 14px; padding: 14px 16px; cursor: pointer; font: inherit;
  border: 1px solid rgba(255,255,255,.08); background: rgba(0,0,0,.2); color: var(--ink);
  transition: transform .15s ease, border-color .15s ease;
}
.lesson-card:hover, .lesson-card:focus-visible {
  transform: translateY(-2px); border-color: rgba(232,195,106,.45); outline: none;
}
.lesson-card .lvl {
  display: inline-block; margin-bottom: 6px; font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--gold-dim); font-weight: 700;
}
.lesson-card h3 { margin: 0 0 6px; font-family: var(--display); font-size: 1.05rem; }
.lesson-card p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.35; }
.lesson-card .score { margin-top: 10px; font-family: var(--mono); font-size: .78rem; color: var(--mint); }
.stage-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px;
}
.scene-meta { text-align: center; flex: 1; }
.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: rgba(0,0,0,.22); border-radius: 12px; padding: 10px 12px; text-align: center;
  border: 1px solid rgba(255,255,255,.05);
}
.stat .label {
  display: block; font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 4px;
}
.stat strong { font-family: var(--mono); font-size: 1.25rem; }
.stat.big strong { font-size: 1.9rem; color: var(--gold); }
.stat.pace-hot strong { color: #f0a878; }
.stat.pace-ok strong { color: var(--mint); }
.script-frame {
  position: relative; background: #140f13; border-radius: 14px;
  border: 1px solid rgba(232,195,106,.2); padding: 26px 22px 34px; min-height: 150px; cursor: text;
}
.script-frame:focus { outline: 2px solid rgba(232,195,106,.55); outline-offset: 2px; }
.script-frame.active .hint { opacity: 0; pointer-events: none; }
#prompt {
  margin: 0; font-family: var(--mono); font-size: clamp(1.05rem, 2.3vw, 1.3rem);
  line-height: 1.75; white-space: pre-wrap; word-break: break-word;
}
#prompt .ok { color: var(--right); }
#prompt .bad { color: var(--wrong); background: rgba(240,113,120,.18); border-radius: 3px; }
#prompt .next { color: var(--ink); border-bottom: 2px solid var(--gold); }
#prompt .todo { color: rgba(247,239,232,.38); }
.hint {
  position: absolute; left: 0; right: 0; bottom: 10px; text-align: center;
  color: var(--muted); font-size: .9rem; transition: opacity .2s;
}
.guide { margin-top: 18px; }
.guide.hidden { display: none; }
.next-key-callout {
  text-align: center; color: var(--muted); margin: 0 0 12px; font-size: .95rem;
}
.next-key-callout strong { color: var(--gold); font-family: var(--mono); }
kbd {
  font-family: var(--mono); font-size: .85em; padding: 1px 6px; border-radius: 6px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12);
}
.hands {
  display: flex; align-items: flex-end; justify-content: center; gap: 18px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.home-label {
  width: 100%; text-align: center; color: var(--muted); font-size: .82rem; order: 3;
}
.hand {
  position: relative; width: 150px; height: 110px;
}
.hand .palm {
  position: absolute; left: 28px; right: 28px; bottom: 8px; height: 42px;
  background: #3a2a32; border-radius: 18px 18px 22px 22px;
}
.hand .finger {
  position: absolute; bottom: 40px; width: 18px; border-radius: 10px 10px 6px 6px;
  background: #4a3842; transition: background .12s ease, transform .12s ease;
}
.hand .finger.active { background: var(--gold); transform: translateY(-6px); }
.left-hand .pinky { left: 18px; height: 38px; }
.left-hand .ring { left: 42px; height: 48px; }
.left-hand .middle { left: 66px; height: 54px; }
.left-hand .index { left: 90px; height: 46px; }
.left-hand .thumb { left: 108px; bottom: 18px; height: 28px; width: 28px; border-radius: 14px; transform: rotate(35deg); }
.right-hand .thumb { right: 108px; bottom: 18px; height: 28px; width: 28px; border-radius: 14px; transform: rotate(-35deg); }
.right-hand .index { right: 90px; height: 46px; }
.right-hand .middle { right: 66px; height: 54px; }
.right-hand .ring { right: 42px; height: 48px; }
.right-hand .pinky { right: 18px; height: 38px; }
.keyboard {
  display: flex; flex-direction: column; gap: 6px; align-items: center; margin-top: 8px;
}
.kb-row { display: flex; gap: 6px; }
.key {
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: 8px;
  display: grid; place-items: center; font-family: var(--mono); font-size: .78rem;
  background: #2a2026; border: 1px solid rgba(255,255,255,.08); color: var(--muted);
  text-transform: uppercase;
}
.key.wide { min-width: 56px; }
.key.space { min-width: 180px; }
.key.target {
  background: rgba(232,195,106,.2); border-color: var(--gold); color: var(--gold);
  box-shadow: 0 0 0 1px rgba(232,195,106,.35);
}
.curtain-call { text-align: center; }
.result-note { color: var(--muted); margin: 0 auto 20px; max-width: 44ch; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
button {
  font: inherit; border-radius: 999px; padding: 11px 18px; cursor: pointer;
  border: 1px solid transparent;
}
.primary {
  background: linear-gradient(145deg, var(--gold), var(--gold-dim));
  color: #2a1a10; font-weight: 700; border: none;
}
.secondary {
  background: rgba(255,255,255,.06); color: var(--ink); border-color: rgba(232,195,106,.35);
}
.ghost { background: transparent; color: var(--muted); border-color: rgba(255,255,255,.12); }
.ghost:hover, .secondary:hover { color: var(--ink); border-color: rgba(232,195,106,.45); }
.foot { text-align: center; color: rgba(196,176,188,.7); font-size: .85rem; padding: 0 24px 28px; }
@media (max-width: 700px) {
  .curtain { display: none; }
  .hud, .result-grid { grid-template-columns: 1fr 1fr; }
  .key.space { min-width: 120px; }
}

/* —— v1.1 pedagogy: locks, posture, badges —— */
.lesson-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.35);
  transform: none;
}
.lesson-card.locked:hover,
.lesson-card.locked:focus-visible {
  transform: none;
  border-color: rgba(255,255,255,.08);
}
.lesson-card.cleared {
  border-color: rgba(126,201,164,.35);
}
.lesson-card .keys {
  display: inline-block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--gold);
  letter-spacing: .02em;
}
.lesson-card .lock-reason {
  margin-top: 10px;
  font-size: .8rem;
  color: #e0a0a8;
}
.lesson-card .muted-score {
  color: var(--muted);
}
.mode-card.locked,
.mode-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.4);
  pointer-events: none;
}
.audition-lock-note {
  margin: 8px 0 0;
  color: #e0a0a8;
  font-size: .88rem;
}
.places-please {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 6, 10, 0.72);
  backdrop-filter: blur(4px);
}
.places-please[hidden] { display: none !important; }
.places-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid rgba(232,195,106,.28);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 26px;
  text-align: center;
}
.places-lede { margin-left: auto; margin-right: auto; }
.places-list {
  text-align: left;
  margin: 0 0 22px;
  padding: 0 0 0 1.1em;
  color: var(--ink);
  line-height: 1.55;
}
.places-list li { margin-bottom: 8px; color: var(--muted); }
.places-list li::marker { color: var(--gold); }
body.posture-blocking .topbar,
body.posture-blocking main,
body.posture-blocking .foot {
  pointer-events: none;
  user-select: none;
}
#nextBtn:disabled,
#nextBtn[hidden] {
  opacity: 0.45;
}

/* —— v1.2 FUN: packs, roles, ovation, skins, duet, custom script —— */
.pack-picker {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px;
}
.pack-chip {
  flex: 1 1 140px; text-align: left; border-radius: 14px; padding: 12px 14px;
  cursor: pointer; font: inherit; color: var(--ink);
  border: 1px solid rgba(255,255,255,.1); background: rgba(0,0,0,.22);
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.pack-chip:hover, .pack-chip:focus-visible {
  border-color: rgba(232,195,106,.45); outline: none; transform: translateY(-1px);
}
.pack-chip.active {
  border-color: var(--gold); background: rgba(232,195,106,.12);
  box-shadow: 0 0 0 1px rgba(232,195,106,.25);
}
.pack-chip .pack-label {
  display: block; font-family: var(--display); font-size: 1.05rem; margin-bottom: 4px;
}
.pack-chip .pack-blurb { display: block; color: var(--muted); font-size: .82rem; line-height: 1.35; }

.custom-script-card {
  margin: 16px 0 8px; padding: 16px 18px; border-radius: 14px;
  border: 1px dashed rgba(232,195,106,.35); background: rgba(232,195,106,.05);
}
.custom-script-card h3 { margin: 0 0 6px; font-family: var(--display); font-size: 1.15rem; }
.custom-hint { margin: 0 0 10px; color: var(--muted); font-size: .88rem; }
#customScriptText {
  width: 100%; resize: vertical; min-height: 72px; font: inherit; font-family: var(--mono);
  color: var(--ink); background: #140f13; border: 1px solid rgba(232,195,106,.28);
  border-radius: 10px; padding: 10px 12px; line-height: 1.45;
}
.custom-script-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px;
}
.char-count { color: var(--muted); font-family: var(--mono); font-size: .82rem; }

.duet-turn {
  margin: 6px 0 0; font-size: .88rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--gold);
}
.duet-turn.understudy { color: #9ec8f0; }
#prompt .seg-you { box-shadow: inset 0 -2px 0 rgba(232,195,106,.35); }
#prompt .seg-understudy { box-shadow: inset 0 -2px 0 rgba(158,200,240,.35); }
#prompt .seg-active-you.next,
#prompt .seg-active-you.todo { background: rgba(232,195,106,.12); }
#prompt .seg-active-under.next,
#prompt .seg-active-under.todo { background: rgba(158,200,240,.14); }

/* Ovation overlay */
.ovation-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(10, 6, 10, 0.55); backdrop-filter: blur(3px);
  animation: ovation-in .35s ease-out;
  pointer-events: none;
}
.ovation-overlay[hidden] { display: none !important; }
.ovation-burst {
  position: absolute; inset: 12% 10% auto; display: flex; justify-content: center; gap: 18px;
  font-size: clamp(1.6rem, 4vw, 2.4rem); animation: rose-fall 2.4s ease-in forwards;
}
.ovation-stamp {
  margin: 0; font-family: var(--display); font-size: clamp(2.4rem, 7vw, 3.6rem);
  color: var(--gold); letter-spacing: .06em; text-transform: uppercase;
  transform: rotate(-6deg); text-shadow: 0 8px 30px rgba(232,195,106,.45);
  animation: stamp-pop .45s cubic-bezier(.2,1.4,.4,1) both;
}
.ovation-headline {
  margin: 8px 0 4px; font-family: var(--display); font-size: clamp(1.6rem, 4vw, 2.2rem);
}
.ovation-sub { margin: 0; color: var(--muted); }
@keyframes ovation-in {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes stamp-pop {
  0% { transform: rotate(-6deg) scale(.4); opacity: 0; }
  70% { transform: rotate(-6deg) scale(1.08); opacity: 1; }
  100% { transform: rotate(-6deg) scale(1); }
}
@keyframes rose-fall {
  0% { transform: translateY(-20px); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(40px); opacity: .85; }
}

/* Pack theming via body[data-pack] */
body[data-pack="broadway"] {
  --gold: #e8c36a; --gold-dim: #b8893a; --curtain: #6b1e2a;
}
body[data-pack="comedy"] {
  --gold: #f0a0c8; --gold-dim: #c45a90; --curtain: #7a2450;
  --mint: #f5b8d4;
}
body[data-pack="comedy"] {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(240,160,200,.2), transparent 55%),
    linear-gradient(180deg, #2a1524 0%, #1a1218 42%, #120d11 100%);
}
body[data-pack="fairytale"] {
  --gold: #a8d47a; --gold-dim: #6a9a40; --curtain: #2a4a28;
  --mint: #9ed47a;
}
body[data-pack="fairytale"] {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(168,212,122,.18), transparent 55%),
    linear-gradient(180deg, #152218 0%, #121816 42%, #0d110e 100%);
}

/* Costume skins — guide / finger / key accents */
body[data-skin="spotlight"] .hand .finger.active,
#guide[data-skin="spotlight"] .hand .finger.active { background: var(--gold); }
body[data-skin="spotlight"] .key.target { border-color: var(--gold); color: var(--gold); }

body[data-skin="swamp-lantern"] {
  --skin-accent: #c8e07a;
}
body[data-skin="swamp-lantern"] .hand .finger.active {
  background: #c8e07a; box-shadow: 0 0 12px rgba(200,224,122,.55);
}
body[data-skin="swamp-lantern"] .key.target {
  background: rgba(200,224,122,.22); border-color: #c8e07a; color: #c8e07a;
  box-shadow: 0 0 0 1px rgba(200,224,122,.4);
}
body[data-skin="swamp-lantern"] .next-key-callout strong { color: #c8e07a; }
body[data-skin="swamp-lantern"] .hand .palm { background: #2a3a28; }

body[data-skin="pink-glitter"] {
  --skin-accent: #f5a0d0;
}
body[data-skin="pink-glitter"] .hand .finger.active {
  background: linear-gradient(180deg, #ffe0f0, #f5a0d0);
  box-shadow: 0 0 14px rgba(245,160,208,.65);
}
body[data-skin="pink-glitter"] .key.target {
  background: rgba(245,160,208,.22); border-color: #f5a0d0; color: #f5a0d0;
  box-shadow: 0 0 0 1px rgba(245,160,208,.45), 0 0 10px rgba(245,160,208,.25);
}
body[data-skin="pink-glitter"] .next-key-callout strong { color: #f5a0d0; }
body[data-skin="pink-glitter"] .hand .palm { background: #3a2a36; }

body[data-skin="colonial-blue"] {
  --skin-accent: #7eb0e8;
}
body[data-skin="colonial-blue"] .hand .finger.active {
  background: #7eb0e8; box-shadow: 0 0 12px rgba(126,176,232,.5);
}
body[data-skin="colonial-blue"] .key.target {
  background: rgba(126,176,232,.22); border-color: #7eb0e8; color: #9ec8f0;
  box-shadow: 0 0 0 1px rgba(126,176,232,.4);
}
body[data-skin="colonial-blue"] .next-key-callout strong { color: #9ec8f0; }
body[data-skin="colonial-blue"] .hand .palm { background: #243040; }

#roleBadge {
  color: var(--gold); font-family: var(--mono);
}

@media (max-width: 700px) {
  .top-stats { flex-wrap: wrap; justify-content: flex-end; gap: 10px 14px; }
  .pack-chip { flex: 1 1 100%; }
}

/* --- Cloud save / auth (v1.3) --- */
.auth-modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(10, 6, 10, .72);
  padding: 20px;
}
.auth-modal[hidden] { display: none !important; }
.auth-card { max-width: 420px; width: 100%; }
.auth-tabs {
  display: flex; gap: 8px; margin: 0 0 16px;
}
.auth-tab {
  flex: 1; font: inherit; cursor: pointer;
  border-radius: 10px; padding: 10px 12px;
  border: 1px solid rgba(232,195,106,.28);
  background: rgba(0,0,0,.25); color: var(--muted);
}
.auth-tab.active {
  color: #2a1a10; background: linear-gradient(145deg, var(--gold), var(--gold-dim));
  border-color: transparent; font-weight: 700;
}
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form .control input {
  font: inherit; color: var(--ink); background: #140f13;
  border: 1px solid rgba(232,195,106,.28); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
.auth-form .control input:focus {
  outline: 2px solid rgba(232,195,106,.55); outline-offset: 1px;
}
.auth-error {
  margin: 0; color: var(--wrong); font-size: .92rem;
}
.auth-error[hidden] { display: none !important; }
.auth-skip { width: 100%; margin-top: 10px; }
.auth-footnote {
  margin: 14px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.4;
}
.sync-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 999px;
  background: rgba(232,195,106,.1); border: 1px solid rgba(232,195,106,.25);
}
.sync-status {
  font-family: var(--mono); font-size: .78rem; color: var(--mint);
}
.sync-status.is-saving { color: var(--gold); }
.sync-status.is-offline, .sync-status.is-error { color: var(--wrong); }
.ghost.tiny, button.ghost.tiny {
  font-size: .78rem; padding: 4px 8px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12); background: transparent;
  color: var(--muted); cursor: pointer; font: inherit;
}
.ghost.tiny:hover { color: var(--ink); border-color: rgba(232,195,106,.45); }
body.auth-blocking .topbar,
body.auth-blocking main,
body.auth-blocking .foot { pointer-events: none; user-select: none; }
