:root {
  --navy: #173a73;
  --navy-dark: #102b59;
  --ink: #18304f;
  --muted: #64748b;
  --paper: #f7fbff;
  --white: #ffffff;
  --cyan: #24c8d8;
  --purple: #8b5cf6;
  --pink: #ef4f84;
  --green: #16a36a;
  --red: #e94357;
  --yellow: #ffc83d;
  --shadow: 0 18px 55px rgba(27, 62, 107, .15);
  --soft-shadow: 0 8px 24px rgba(27, 62, 107, .11);
  --radius: 26px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-width: 320px;
  background: #e9f3fc;
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 4px solid rgba(36, 200, 216, .38);
  outline-offset: 3px;
}

.app-shell { min-height: 100vh; position: relative; overflow: hidden; }
body.questions-page .app-shell { overflow: visible; }
.screen {
  display: none;
  min-height: 100vh;
  padding: clamp(22px, 3.2vw, 48px);
  background:
    radial-gradient(circle at 8% 4%, rgba(36, 200, 216, .13), transparent 30%),
    radial-gradient(circle at 92% 90%, rgba(139, 92, 246, .12), transparent 32%),
    linear-gradient(145deg, #f8fcff 0%, #edf6ff 100%);
}
.screen--active { display: block; animation: screenIn .35s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1, h2 { font-family: "Lobster", "Trebuchet MS", cursive; color: var(--navy); margin: 0; line-height: .98; font-weight: 400; }
h1 { font-size: clamp(4rem, 9vw, 8.5rem); letter-spacing: -.04em; }
h2 { font-size: clamp(2.6rem, 5vw, 5.4rem); }
h3 { margin: 0; font-size: 1.05rem; color: var(--navy); }
p { line-height: 1.6; }
.eyebrow { margin: 0 0 10px; color: #4b69a0; font-size: .78rem; font-weight: 800; letter-spacing: .2em; text-transform: uppercase; }

.button {
  border: 0;
  min-height: 54px;
  border-radius: 18px;
  padding: 14px 24px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.button:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.03); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button--primary { color: white; background: linear-gradient(135deg, #225aa7, var(--navy)); box-shadow: 0 12px 26px rgba(23, 58, 115, .25); }
.button--secondary { color: white; background: linear-gradient(135deg, #17a99f, #107d8e); }
.button--quiet { color: var(--navy); background: #e7f0f9; }
.button--ai { color: #6336aa; background: #f1eaff; }
.button--wide { width: 100%; }
.button--hero { min-width: 210px; min-height: 66px; font-size: 1.1rem; border-radius: 22px; }

/* Intro */
.intro-screen { position: relative; overflow: hidden; padding: 0; background: linear-gradient(130deg, #fdfefe 0 52%, #e9f9fb 100%); }
.intro-screen.screen--active { display: grid; grid-template-columns: 48% 52%; align-items: center; }
.intro-copy { position: relative; z-index: 4; padding: clamp(34px, 7vw, 110px); padding-right: 10px; }
.intro-copy h1 { max-width: 720px; text-shadow: 0 5px 0 rgba(255,255,255,.7); }
.intro-lead { max-width: 570px; margin: 28px 0 36px; color: #536984; font-size: clamp(1rem, 1.6vw, 1.35rem); }
.keep-together { display: block; white-space: nowrap; }
.intro-stage { align-self: stretch; position: relative; min-height: 600px; overflow: hidden; }
.intro-steps { position: absolute; inset: 5% -2% 0 8%; transform: rotate(-7deg); opacity: .34; }
.intro-steps span { position: absolute; right: -4%; height: 7.5%; border-radius: 20px; box-shadow: inset 0 -7px 0 rgba(0,0,0,.12); }
.intro-steps span:nth-child(1) { bottom: 2%; width: 100%; background: #ee4564; }
.intro-steps span:nth-child(2) { bottom: 14%; width: 91%; background: #24c8d8; }
.intro-steps span:nth-child(3) { bottom: 26%; width: 82%; background: #ffc83d; }
.intro-steps span:nth-child(4) { bottom: 38%; width: 73%; background: #8b5cf6; }
.intro-steps span:nth-child(5) { bottom: 50%; width: 64%; background: #20bc78; }
.intro-steps span:nth-child(6) { bottom: 62%; width: 55%; background: #ef78b1; }
.intro-steps span:nth-child(7) { bottom: 74%; width: 46%; background: #55d3b5; }
.intro-characters { position: absolute; inset: 4% 7% 5% 1%; z-index: 2; }
.intro-characters img { position: absolute; width: clamp(108px, 11.5vw, 190px); filter: drop-shadow(0 18px 16px rgba(23,58,115,.2)); animation: introFloat 3.5s ease-in-out infinite; }
.intro-characters img:nth-child(1) { left: 2%; bottom: 5%; }
.intro-characters img:nth-child(2) { left: 28%; bottom: 20%; animation-delay: -.7s; }
.intro-characters img:nth-child(3) { left: 56%; bottom: 35%; animation-delay: -1.4s; }
.intro-characters img:nth-child(4) { left: 73%; bottom: 50%; animation-delay: -2.1s; }
.intro-characters img:nth-child(5) { left: 51%; bottom: 65%; animation-delay: -2.8s; }
@keyframes introFloat { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-10px) rotate(1deg); } }
.intro-orb { position: absolute; border-radius: 50%; filter: blur(1px); opacity: .38; }
.intro-orb--one { width: 280px; height: 280px; background: #ffe480; left: -110px; bottom: -100px; }
.intro-orb--two { width: 180px; height: 180px; background: #e6c8ff; left: 38%; top: -70px; }

/* Setup */
.setup-screen, .questions-screen { overflow: auto; }
.screen-header { max-width: 1380px; margin: 0 auto 28px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.screen-header h2 { font-size: clamp(2.8rem, 4.2vw, 4.7rem); }
.header-note { color: var(--muted); margin: 0 0 5px; }
.setup-grid { max-width: 1380px; margin: auto; display: grid; grid-template-columns: 1.05fr .95fr; gap: 24px; align-items: start; }
.settings-column { display: grid; gap: 20px; }
.panel { background: rgba(255,255,255,.93); border: 1px solid rgba(157,185,214,.38); border-radius: var(--radius); box-shadow: var(--soft-shadow); padding: clamp(20px, 2.1vw, 30px); }
.field-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.value-badge { border-radius: 999px; padding: 7px 12px; background: #e9f8fa; color: #127484; font-size: .8rem; font-weight: 800; }
.choice-row { display: flex; gap: 10px; margin-top: 17px; }
.choice-row input, .mode-card input { position: absolute; opacity: 0; pointer-events: none; }
.choice-row label { flex: 1; }
.choice-row span { display: grid; place-items: center; min-height: 49px; border: 2px solid #dce7f2; border-radius: 15px; font-weight: 800; cursor: pointer; background: #fff; }
.choice-row input:checked + span { color: #fff; border-color: var(--navy); background: var(--navy); box-shadow: 0 7px 16px rgba(23,58,115,.2); }
.team-names { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; margin-top: 16px; }
.team-name-row { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; }
.team-name-row img { width: 44px; height: 44px; object-fit: contain; }
.team-name-row input { width: 100%; border: 2px solid #dce7f2; border-radius: 14px; padding: 12px 14px; color: var(--ink); background: #fbfdff; }
.compact-fields { display: grid; grid-template-columns: .7fr 1.3fr; gap: 16px; }
.select-field { display: grid; gap: 8px; color: var(--navy); font-size: .86rem; font-weight: 800; }
select { min-height: 48px; padding: 0 14px; color: var(--ink); border: 2px solid #dce7f2; border-radius: 14px; background: #fff; }
.mode-cards { display: grid; gap: 10px; margin-top: 16px; }
.mode-card { position: relative; display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: center; padding: 13px; border: 2px solid #e1eaf3; border-radius: 17px; cursor: pointer; transition: .18s ease; }
.mode-card:has(input:checked) { border-color: #7258d7; background: #f4f0ff; box-shadow: 0 6px 18px rgba(114,88,215,.12); }
.mode-letter { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; color: #fff; background: linear-gradient(135deg, #9a78f5, #6249c7); font-weight: 900; }
.mode-card strong, .mode-card small { display: block; }
.mode-card small { margin-top: 3px; color: var(--muted); }
.options-panel { display: grid; gap: 14px; }
.order-row { display: grid; grid-template-columns: minmax(145px, .85fr) minmax(250px, 1.15fr); align-items: center; gap: 12px; cursor: pointer; }
.order-row > strong { color: var(--ink); font-size: .86rem; }
.order-choice { display: grid; grid-template-columns: 1fr 52px 1fr; align-items: center; gap: 9px; min-height: 39px; padding: 4px 10px; border-radius: 14px; background: #edf3f9; }
.order-choice input { position: absolute; opacity: 0; pointer-events: none; }
.order-option { color: #66798f; font-size: .8rem; font-weight: 700; text-align: center; transition: color .2s ease, font-weight .2s ease; }
.order-option.is-selected { color: var(--navy); font-weight: 900; }
.order-switch { position: relative; width: 52px; height: 27px; border-radius: 999px; background: linear-gradient(135deg, #e24ca7, #a73ca8); box-shadow: inset 0 1px 3px rgba(74,21,87,.18); }
.order-switch i { position: absolute; width: 21px; height: 21px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 2px 7px rgba(44,24,75,.28); transition: transform .22s ease; }
.order-choice input:checked + .order-switch i { transform: translateX(25px); }
.sound-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.sound-panel h3 { grid-column: 1 / -1; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding-top: 13px; border-top: 1px solid #e4edf5; cursor: pointer; }
.switch-row strong, .switch-row small { display: block; }
.switch-row small { color: var(--muted); margin-top: 3px; }
.switch-row input { position: absolute; opacity: 0; }
.switch { position: relative; flex: 0 0 auto; width: 54px; height: 30px; border-radius: 999px; background: #cad7e4; transition: .2s; }
.switch::after { content: ""; position: absolute; width: 22px; height: 22px; left: 4px; top: 4px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: .2s; }
.switch-row input:checked + .switch { background: #22b6a9; }
.switch-row input:checked + .switch::after { transform: translateX(24px); }
.about-link { justify-self: start; min-height: 38px; border: 1px solid #d6e3ef; border-radius: 12px; padding: 8px 13px; color: var(--navy); background: #fff; box-shadow: 0 3px 10px rgba(23,58,115,.07); font-weight: 750; cursor: pointer; transition: color .18s ease, background .18s ease, box-shadow .18s ease, transform .18s ease; }
.about-link:hover, .about-link:focus-visible { color: #fff; background: linear-gradient(135deg, #225aa7, var(--navy)); box-shadow: 0 8px 18px rgba(23,58,115,.22); transform: translateY(-1px); }

.field-heading-copy h3 { margin-bottom: 2px; }
.field-heading-copy p { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.2; }

/* Question import */
.questions-screen.screen--active { display: flex; flex-direction: column; min-height: 100vh; height: auto; overflow: visible; }
.questions-screen .screen-header { width: 100%; margin-bottom: 16px; }
.questions-mode-note { text-transform: none; letter-spacing: .12em; }
.questions-layout { flex: 0 0 auto; min-height: 0; width: 100%; max-width: 1380px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); }
.question-import-panel { min-height: auto; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(410px, .9fr); grid-template-areas: "requirement requirement" "ai-guide ai-actions" "save-guide save-package" "method-divider method-divider" "package-guide package-actions" ". editor-start"; gap: 11px clamp(22px, 2.8vw, 40px); align-items: start; }
.ai-guide { grid-area: ai-guide; align-self: start; padding-top: 6px; }
.ai-guide h3, .package-guide h3 { margin-bottom: 12px; font-family: "Lobster", cursive; font-size: clamp(1.8rem, 2.55vw, 2.75rem); font-weight: 400; line-height: 1.05; white-space: nowrap; }
.ai-guide ol, .package-guide ol { margin: 0; padding-left: 24px; font-size: 1rem; line-height: 1.42; }
.ai-guide li, .package-guide li { margin-bottom: 5px; padding-left: 3px; }
.question-import-actions { grid-area: ai-actions; align-self: center; display: grid; gap: 9px; align-content: center; }
.question-import-actions .button { min-height: 44px; padding-top: 10px; padding-bottom: 10px; border-radius: 15px; }
.question-requirement { grid-area: requirement; padding: 10px 15px; border: 1px solid #b8dfef; border-radius: 15px; color: #175a78; background: #e7f5fb; font-weight: 750; line-height: 1.38; }
.import-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.import-divider::before, .import-divider::after { content: ""; flex: 1; height: 1px; background: #dce7f2; }
.paste-button.is-success { background: linear-gradient(135deg, #16a36a, #087a4c); }
.paste-button.is-success::after { content: "  ✓"; font-size: 1.05rem; }
.button--repair { justify-self: start; color: #6a4500; border: 1px solid #e3be53; background: #fff0bd; box-shadow: 0 5px 15px rgba(132,91,0,.1); }
.button--repair[hidden], .repair-prompt-help[hidden], .save-package-wrap[hidden], #save-guide-step[hidden] { display: none; }
.repair-prompt-help { margin: -1px 0 2px; padding: 10px 12px; border-radius: 12px; color: #704c00; background: #fff8e5; font-size: .84rem; line-height: 1.45; }
.manual-paste { display: grid; gap: 10px; padding: 13px; border: 1px solid #e7c96f; border-radius: 16px; background: #fffaf0; }
.manual-paste[hidden] { display: none; }
.manual-paste-help { color: #704c00; }
.manual-paste-help strong { display: block; }
.manual-paste-help p { margin: 5px 0 0; font-size: .88rem; line-height: 1.45; }
.manual-paste label { color: var(--navy); font-size: .84rem; font-weight: 800; }
.manual-paste textarea { min-height: 125px; width: 100%; resize: vertical; border: 2px solid #d9e6f2; border-radius: 14px; padding: 14px; color: #203650; background: #fff; font: 500 .9rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.method-divider { grid-area: method-divider; display: flex; align-items: center; gap: 12px; margin: 2px 0; color: var(--muted); font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.method-divider::before, .method-divider::after { content: ""; flex: 1; height: 1px; background: #dce7f2; }
.package-guide { grid-area: package-guide; padding-top: 5px; }
.package-actions { grid-area: package-actions; align-self: center; }
.button--package { min-width: 205px; color: #fff; background: linear-gradient(135deg, #1fa89e, #157d91); }
.save-guide-step { grid-area: save-guide; align-self: center; margin: 0; padding-left: 24px; color: var(--ink); font-size: 1rem; line-height: 1.42; }
.save-guide-step li { padding-left: 3px; }
.save-package-wrap { grid-area: save-package; display: grid; align-self: center; }
.save-package { justify-self: start; width: 100%; }
.editor-start { grid-area: editor-start; min-width: 210px; }
.status-message { display: none; margin: 0 0 12px; padding: 12px 14px; border-radius: 13px; font-weight: 700; }
.status-message.is-visible { display: block; }
.question-import-actions .status-message { margin: 0; white-space: pre-line; line-height: 1.45; }
.status-message.is-info { color: #175a78; background: #e7f5fb; border: 1px solid #b8dfef; }
.status-message.is-success { color: #08774a; background: #e6f8ef; }
.status-message.is-warning { color: #704600; background: #fff5d8; font-weight: 500; }
.status-message.is-warning strong { color: inherit; font-weight: 800; }
.question-import-actions .status-message.is-warning { padding-top: 10px; padding-bottom: 10px; }
.status-message.is-error { color: #a72838; background: #ffeaed; }

/* Game */
.game-screen { padding: 0; background: #eff7fd; }
.game-screen.screen--active { display: flex; flex-direction: column; }
.game-topbar { min-height: 62px; display: flex; align-items: center; justify-content: space-between; padding: 10px 24px; color: #f2f8ff; background: var(--navy-dark); box-shadow: 0 4px 15px rgba(11,37,74,.22); z-index: 5; }
.game-progress { font-weight: 800; letter-spacing: .02em; }
.dot { margin: 0 10px; color: #70d7df; }
.game-tools { display: flex; gap: 8px; }
.icon-button { width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.2); border-radius: 13px; color: white; background: rgba(255,255,255,.1); cursor: pointer; font-size: 1.1rem; }
.icon-button.is-off { opacity: .45; text-decoration: line-through; }
.game-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(360px, 40%) minmax(560px, 60%); }
.game-screen.is-mode-c .game-layout { grid-template-columns: minmax(560px, 54%) minmax(460px, 46%); }
.game-control-panel { position: relative; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: clamp(22px, 3vw, 50px); text-align: center; background: rgba(255,255,255,.92); box-shadow: 12px 0 35px rgba(38,75,114,.09); }
.game-screen.is-mode-c .game-control-panel { padding: clamp(16px, 2vw, 28px); }
.game-screen.has-stacked-answers .game-control-panel { justify-content: flex-start; padding-top: clamp(15px, 2.2vh, 24px); }
.turn-label { margin: 0 0 5px; color: var(--muted); font-weight: 800; letter-spacing: .16em; text-transform: uppercase; font-size: .76rem; }
#active-team-name { font-family: "Lobster", cursive; font-size: clamp(2rem, 3.4vw, 4rem); font-weight: 400; line-height: 1.05; }
.question-area { width: min(100%, 760px); margin: clamp(18px, 2.5vh, 32px) auto 0; }
.game-screen.is-mode-c .question-area { margin-top: clamp(13px, 2vh, 22px); }
.oral-prompt { padding: 22px; border-radius: 22px; color: var(--navy); background: #eff5fb; font-size: clamp(1.05rem, 1.5vw, 1.35rem); font-weight: 800; }
.question-text { margin: 0; color: var(--ink); font-size: clamp(1.15rem, 1.8vw, 1.8rem); font-weight: 800; line-height: 1.35; }
.question-text.is-long { font-size: clamp(1.08rem, 1.62vw, 1.55rem); }
.answers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.game-screen.is-mode-c .answers-grid { margin-top: clamp(13px, 2vh, 20px); }
.answers-grid.answers-grid--stacked { grid-template-columns: 1fr; gap: 8px; }
.choice-button { position: relative; min-height: 70px; display: grid; grid-template-columns: 42px 1fr; gap: 10px; align-items: center; border: 2px solid #dbe7f1; border-radius: 18px; padding: 10px 14px; color: var(--ink); background: #fff; text-align: left; font-weight: 700; cursor: pointer; transition: .18s ease; }
.choice-text { min-width: 0; line-height: 1.28; }
.answers-grid--stacked .choice-button { min-height: 54px; padding-top: 8px; padding-bottom: 8px; }
.choice-button:hover:not(:disabled) { border-color: #87a9cc; transform: translateY(-2px); box-shadow: var(--soft-shadow); }
.choice-letter { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: white; background: var(--navy); font-weight: 900; }
.choice-button.is-correct, .choice-button.is-wrong { padding-right: 52px; }
.choice-button.is-correct { color: #075a39; border-color: #24aa72; background: #e6faef; }
.choice-button.is-correct::after { content: "✓"; position: absolute; width: 28px; right: 12px; top: 50%; transform: translateY(-50%); text-align: center; font-size: 1.2rem; color: #0a8b55; }
.choice-button.is-wrong { color: #8e2430; border-color: #ee5b6c; background: #ffeaed; }
.choice-button.is-wrong::after { content: "×"; position: absolute; width: 28px; right: 12px; top: 50%; transform: translateY(-50%); text-align: center; font-size: 1.5rem; color: #cf3346; }
.go-stop { display: flex; justify-content: center; gap: clamp(20px, 3vw, 48px); margin-top: clamp(28px, 4vh, 48px); }
.answer-orb { width: clamp(118px, 10vw, 164px); aspect-ratio: 1; border: 8px solid rgba(255,255,255,.6); border-radius: 50%; color: #fff; cursor: pointer; box-shadow: 0 15px 26px rgba(23,58,115,.2), inset 0 -10px 0 rgba(0,0,0,.12); transition: transform .17s ease, filter .17s ease; }
.answer-orb:hover:not(:disabled) { transform: translateY(-5px) scale(1.02); filter: brightness(1.05); }
.answer-orb:disabled { opacity: .5; cursor: wait; }
.answer-orb span, .answer-orb small { display: block; }
.answer-orb span { font-size: clamp(1.8rem, 2.6vw, 2.7rem); font-weight: 900; }
.answer-orb small { margin-top: 2px; font-weight: 700; }
.answer-orb--go { background: linear-gradient(145deg, #30cf82, #098c54); }
.answer-orb--stop { background: linear-gradient(145deg, #ff6675, #cf263c); }
.feedback-banner { min-height: 42px; margin-top: 20px; font-size: 1.05rem; font-weight: 900; }
.feedback-banner.is-correct { color: #08864f; }
.feedback-banner.is-wrong { color: #c5283c; }
.feedback-timer { width: min(100%, 650px); height: 4px; margin-top: 16px; overflow: hidden; border-radius: 999px; background: #e5edf5; box-shadow: inset 0 1px 2px rgba(23,58,115,.1); }
.feedback-timer span { display: block; width: 100%; height: 100%; border-radius: inherit; transform-origin: left center; background: linear-gradient(90deg, #ef4f84 0%, #ff9f3d 20%, #ffd43b 40%, #27c579 60%, #24c8d8 80%, #8b5cf6 100%); }
.feedback-timer.is-running span { animation: feedbackTimer var(--feedback-duration, 4000ms) linear forwards; }
@keyframes feedbackTimer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.race-panel { position: relative; min-height: 0; overflow: hidden; padding: 24px 30px 18px; background:
  radial-gradient(circle at 50% -10%, rgba(255,255,255,.98), transparent 45%),
  linear-gradient(180deg, #dff4f7 0%, #eef9f6 55%, #e2f1fd 100%); }
.race-panel::before { content: ""; position: absolute; inset: 0; opacity: .32; background-image: radial-gradient(#7bbcc8 1px, transparent 1px); background-size: 22px 22px; }
.finish-label { position: absolute; left: 50%; bottom: var(--finish-bottom, 72%); transform: translateX(-50%); z-index: 3; padding: 7px 22px 9px; border: 2px solid rgba(255,255,255,.9); border-radius: 999px; color: #fff; background: linear-gradient(135deg, #2b65b1, var(--navy-dark)); box-shadow: 0 8px 20px rgba(23,58,115,.28); font-family: "Lobster", cursive; font-size: clamp(1.8rem, 3vw, 2.8rem); line-height: 1; }
.track { --racer-unit: 12.4%; position: relative; height: 100%; max-width: 1040px; margin: auto; }
.steps { position: absolute; inset: 0; z-index: 1; }
.step { position: absolute; left: 50%; bottom: var(--step-bottom); width: var(--w); height: var(--step-height); transform: translateX(-50%); }
.step img { width: 100%; height: 100%; object-fit: fill; display: block; filter: drop-shadow(0 5px 3px rgba(30,59,92,.14)); }
.racers { position: absolute; inset: 0; z-index: 2; }
.racer { position: absolute; left: var(--x); bottom: calc(var(--level) * var(--racer-unit) + 1%); width: var(--racer-size); transform: translateX(-50%); transition: bottom .7s cubic-bezier(.25,1.5,.5,1), left .5s ease; }
.racer img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 9px 7px rgba(23,58,115,.24)); }
.racer.is-active img { animation: activeBounce 1.15s ease-in-out infinite; filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 17px var(--team-color)) drop-shadow(0 10px 7px rgba(23,58,115,.22)); }
.racer.just-scored img { animation: scorePop .7s ease both; }
@keyframes activeBounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@keyframes scorePop { 0% { transform: scale(1); } 45% { transform: scale(1.18) rotate(-4deg); } 100% { transform: scale(1); } }

/* Results */
.results-screen { text-align: center; overflow: auto; }
.results-screen.screen--active { display: grid; place-items: center; }
.results-wrap { position: relative; z-index: 2; width: min(720px, 100%); margin: auto; padding: clamp(26px, 4vw, 50px); border: 1px solid rgba(157,185,214,.4); border-radius: 34px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.results-wrap h2 { margin-bottom: 26px; }
.podium-list { display: grid; gap: 10px; text-align: left; }
.rank-row { display: grid; grid-template-columns: 48px 44px 1fr auto; gap: 12px; align-items: center; min-height: 68px; padding: 8px 16px; border: 2px solid #e2ebf4; border-radius: 18px; background: #fbfdff; }
.rank-row:first-child { border-color: #f0c448; background: #fff9df; }
.rank-number { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: #fff; background: var(--navy); font-weight: 900; }
.rank-row:first-child .rank-number { color: #74520a; background: #ffd85a; }
.rank-row img { width: 44px; height: 44px; object-fit: contain; }
.rank-name { font-weight: 900; color: var(--navy); }
.rank-points { text-align: right; font-weight: 900; }
.rank-points small { display: block; margin-top: 3px; color: var(--muted); font-size: .7rem; font-weight: 600; }
#next-round { min-height: 50px; margin-top: 18px; padding-top: 10px; padding-bottom: 10px; align-items: center; justify-content: center; }
.countdown { display: none; min-height: 150px; place-items: center; color: var(--navy); font-family: "Lobster", cursive; font-size: 8rem; font-weight: 400; }
.countdown.is-visible { display: grid; animation: countPulse .78s ease both; }
@keyframes countPulse { from { transform: scale(.5); opacity: 0; } 45% { transform: scale(1.12); opacity: 1; } to { transform: scale(1); } }
.final-screen { padding: clamp(18px, 2.4vw, 34px); }
.final-wrap { width: min(1180px, 100%); max-width: none; display: grid; grid-template-columns: minmax(300px, .85fr) minmax(420px, 1.15fr); gap: clamp(24px, 4vw, 56px); align-items: center; text-align: left; padding: clamp(24px, 3vw, 42px); }
.final-winner-column { min-width: 0; text-align: center; }
.final-winner-column h2 { font-size: clamp(3rem, 5vw, 5.2rem); }
.winner-message { margin: 5px 0 6px; color: #5e7189; font-size: 1.05rem; font-weight: 700; }
.winner-characters { display: flex; justify-content: center; min-height: 190px; align-items: center; margin: 0 auto 4px; }
.winner-characters img { width: clamp(72px, calc(90% / var(--winner-count, 1)), 190px); margin: 0 -7px; filter: drop-shadow(0 15px 12px rgba(23,58,115,.2)); animation: winnerDance 1.2s ease-in-out infinite; }
.winner-characters img:nth-child(even) { animation-delay: -.55s; }
@keyframes winnerDance { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-15px) rotate(3deg); } }
.final-ranking-column h3 { margin: 0 0 14px; font-family: "Lobster", cursive; font-size: clamp(2rem, 3vw, 3rem); font-weight: 400; }
.final-ranking { max-height: min(66vh, 520px); overflow: auto; }
.final-actions { display: flex; justify-content: center; gap: 12px; margin-top: 22px; }
.confetti { position: fixed; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -8vh; left: var(--x); width: var(--size); height: calc(var(--size) * .55); border-radius: 3px; background: var(--color); animation: confettiFall var(--speed) linear var(--delay) infinite; }
@keyframes confettiFall { to { transform: translate3d(var(--drift), 115vh, 0) rotate(720deg); } }

/* Dialog and toast */
.modal { width: min(720px, calc(100% - 28px)); max-height: calc(100vh - 40px); overflow: auto; padding: 30px; border: 0; border-radius: 28px; color: var(--ink); box-shadow: 0 30px 90px rgba(15,42,79,.32); }
.modal::backdrop { background: rgba(13,35,67,.63); backdrop-filter: blur(4px); }
.modal-header { display: flex; justify-content: space-between; gap: 20px; }
.modal-header h2 { font-size: clamp(1.75rem, 3.1vw, 2.55rem); line-height: 1.08; }
.modal-close { flex: 0 0 auto; width: 45px; height: 45px; border: 0; border-radius: 14px; color: var(--navy); background: #eaf1f8; font-size: 1.8rem; cursor: pointer; }
.modal ol { padding-left: 24px; line-height: 1.55; }
.modal li { margin-bottom: 7px; }
.modal-tip { padding: 13px 15px; border-radius: 14px; background: #fff4d6; }
.about-modal { width: min(690px, calc(100% - 28px)); }
.about-list { display: grid; gap: 0; margin: 24px 0 18px; }
.about-list div { display: grid; grid-template-columns: minmax(190px, .9fr) minmax(240px, 1.1fr); gap: 18px; padding: 12px 0; border-bottom: 1px solid #e5edf5; }
.about-list dt { color: var(--navy); font-weight: 800; }
.about-list dd { margin: 0; line-height: 1.45; }
.about-version { margin: 18px 0 0; color: var(--muted); text-align: center; font-size: .86rem; line-height: 1.6; }
.button--copy { color: #fff; background: linear-gradient(135deg, #7447d8, #3c55b9); box-shadow: 0 13px 28px rgba(77,62,175,.34); font-size: 1.05rem; border: 2px solid rgba(255,255,255,.55); }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; max-width: min(90vw, 560px); padding: 13px 18px; border-radius: 14px; color: #fff; background: #173a73; box-shadow: var(--shadow); font-weight: 800; text-align: center; transition: .25s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 1060px) {
  .setup-screen { height: 100dvh; overflow: auto; padding: 12px clamp(24px, 3.4vw, 48px) 16px; }
  .setup-screen .screen-header { max-width: 1280px; margin-bottom: 9px; }
  .setup-screen .screen-header h2 { font-size: clamp(2.7rem, 3.4vw, 3.7rem); }
  .setup-screen .eyebrow { margin-bottom: 5px; }
  .setup-grid { max-width: 1280px; gap: 14px; }
  .settings-column { gap: 11px; }
  .setup-screen .panel { padding: 13px 17px; border-radius: 20px; }
  .setup-screen .choice-row { margin-top: 8px; }
  .setup-screen .choice-row span { min-height: 38px; border-radius: 12px; }
  .setup-screen .team-names { gap: 6px 12px; margin-top: 9px; }
  .setup-screen .team-name-row { grid-template-columns: 34px 1fr; gap: 8px; }
  .setup-screen .team-name-row img { width: 34px; height: 34px; }
  .setup-screen .team-name-row input { min-height: 37px; padding: 7px 10px; border-radius: 11px; }
  .setup-screen .value-badge { padding: 5px 9px; }
  .setup-screen .select-field { gap: 5px; }
  .setup-screen select { min-height: 40px; border-radius: 11px; }
  .setup-screen .options-panel { gap: 8px; }
  .setup-screen .order-row { gap: 8px; }
  .setup-screen .order-choice { min-height: 34px; padding-top: 3px; padding-bottom: 3px; }
  .setup-screen .mode-cards { gap: 6px; margin-top: 9px; }
  .setup-screen .mode-card { grid-template-columns: 35px 1fr; gap: 9px; padding: 7px 9px; border-radius: 13px; }
  .setup-screen .mode-letter { width: 33px; height: 33px; border-radius: 10px; }
  .setup-screen .mode-card small { margin-top: 1px; }
  .setup-screen .sound-panel { gap: 8px 14px; }
  .setup-screen .switch-row { gap: 10px; padding-top: 8px; }
  .setup-screen .switch { width: 48px; height: 27px; }
  .setup-screen .switch::after { width: 19px; height: 19px; }
  .setup-screen .switch-row input:checked + .switch::after { transform: translateX(21px); }
  .setup-screen .about-link { min-height: 34px; padding-top: 6px; padding-bottom: 6px; }
  #setup-submit { min-height: 46px; padding-top: 10px; padding-bottom: 10px; border-radius: 15px; }
  .questions-screen { padding: 9px clamp(24px, 3vw, 42px) 12px; }
  .questions-screen .screen-header { margin-bottom: 7px; }
  .questions-screen .screen-header h2 { font-size: clamp(2.6rem, 3.2vw, 3.45rem); }
  .questions-screen .eyebrow { margin-bottom: 4px; }
  .questions-screen .panel { padding: 13px 20px; border-radius: 21px; }
  .questions-screen .question-import-panel { gap: 8px clamp(22px, 2.8vw, 38px); }
  .questions-screen .ai-guide h3, .questions-screen .package-guide h3 { font-size: clamp(1.7rem, 2.05vw, 2.1rem); margin-bottom: 7px; }
  .questions-screen .ai-guide ol, .questions-screen .package-guide ol { font-size: .94rem; line-height: 1.32; }
  .questions-screen .ai-guide li, .questions-screen .package-guide li { margin-bottom: 3px; }
  .questions-screen .question-requirement { padding-top: 8px; padding-bottom: 8px; }
  .questions-screen .question-import-actions .button { min-height: 42px; padding-top: 8px; padding-bottom: 8px; }
  .questions-screen .editor-start { min-height: 44px; padding-top: 9px; padding-bottom: 9px; }
}

@media (max-width: 1050px) {
  .intro-screen.screen--active { grid-template-columns: 1fr; align-content: center; text-align: center; }
  .intro-copy { padding: 50px 30px 20px; }
  .intro-lead { margin-left: auto; margin-right: auto; }
  .intro-stage { min-height: 340px; }
  .intro-characters img { width: clamp(96px, 15vw, 140px); }
  .intro-characters { inset: 0 9% 3%; }
  .intro-characters img:nth-child(1) { left: 5%; bottom: 2%; }
  .intro-characters img:nth-child(2) { left: 25%; bottom: 14%; }
  .intro-characters img:nth-child(3) { left: 50%; bottom: 26%; }
  .intro-characters img:nth-child(4) { left: 70%; bottom: 38%; }
  .intro-characters img:nth-child(5) { left: 58%; bottom: 52%; }
  .setup-grid { grid-template-columns: 1fr; }
  .sound-panel { grid-template-columns: 1fr; }
  .sound-panel h3 { grid-column: auto; }
  .game-layout { grid-template-columns: 42% 58%; }
  .game-screen.is-mode-c .game-layout { grid-template-columns: 54% 46%; }
  .race-panel { padding-left: 10px; padding-right: 10px; }
  .final-wrap { grid-template-columns: minmax(280px, .85fr) minmax(360px, 1.15fr); gap: 22px; }
}

@media (max-width: 760px) {
  .screen { padding: 18px 14px 28px; }
  .screen-header { align-items: flex-start; }
  .header-note { display: none; }
  .setup-grid { gap: 15px; }
  .panel { border-radius: 20px; padding: 18px; }
  .compact-fields { grid-template-columns: 1fr; }
  .team-names { grid-template-columns: 1fr; }
  .order-row { grid-template-columns: 1fr; }
  .game-screen { overflow: auto; }
  .game-screen.screen--active { display: block; }
  .game-topbar { position: sticky; top: 0; }
  .game-layout { display: flex; flex-direction: column; }
  .game-control-panel { min-height: 500px; padding: 28px 16px; }
  .race-panel { min-height: 590px; padding-top: 35px; }
  .track { height: 540px; }
  .answers-grid { grid-template-columns: 1fr; }
  .choice-button { min-height: 62px; }
  .answer-orb { width: 125px; }
  .rank-row { grid-template-columns: 40px 40px 1fr auto; padding: 7px 10px; }
  .questions-screen.screen--active { height: auto; min-height: 100dvh; overflow: visible; }
  .question-import-panel { grid-template-columns: 1fr; grid-template-areas: "requirement" "ai-guide" "ai-actions" "save-guide" "save-package" "method-divider" "package-guide" "package-actions" "editor-start"; align-items: start; }
  .save-guide-step { padding-left: 24px; }
  .ai-guide h3, .package-guide h3 { white-space: normal; }
  .button--package { width: 100%; }
  .manual-paste textarea { min-height: 260px; }
  .final-wrap { grid-template-columns: 1fr; text-align: center; }
  .final-ranking-column { order: 2; }
  .final-actions { flex-direction: column; }
}

@media (max-width: 480px) {
  .intro-stage { min-height: 290px; }
  .intro-copy h1 { font-size: 3.8rem; }
  .intro-characters img { width: 112px; }
  .intro-characters img:nth-child(5) { left: 57%; }
  .screen-header { display: block; }
  .screen-header .button { margin-top: 14px; }
  .team-name-row { grid-template-columns: 38px 1fr; }
  .team-name-row img { width: 38px; height: 38px; }
  .editor-actions .button { width: 100%; }
  .game-progress { font-size: .76rem; }
  .dot { margin: 0 5px; }
  .game-control-panel { min-height: 470px; }
  .go-stop { gap: 12px; }
  .answer-orb { width: 112px; border-width: 6px; }
  .race-panel { min-height: 530px; }
  .track { height: 490px; }
  .rank-row { grid-template-columns: 36px 1fr auto; }
  .rank-row img { display: none; }
  .about-list div { grid-template-columns: 1fr; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .feedback-timer.is-running span { animation-duration: var(--feedback-duration, 4000ms) !important; }
}
