:root {
  --ink: #14213d;
  --text: #24344f;
  --muted: #69758c;
  --paper: rgba(255, 255, 255, 0.94);
  --paper-strong: #ffffff;
  --border: rgba(20, 33, 61, 0.13);
  --shadow: 0 22px 60px rgba(16, 28, 52, 0.18);
  --shadow-soft: 0 10px 26px rgba(16, 28, 52, 0.11);
  --blue: #1684ff;
  --blue-deep: #095fc6;
  --blue-soft: #eaf4ff;
  --red: #ff315d;
  --red-deep: #c9153c;
  --red-soft: #fff0f4;
  --purple: #6d4cff;
  --teal: #11b7a5;
  --yellow: #ffd25e;
  --green: #18a957;
  --bad: #d92d42;
  --warning: #f59e0b;
  --radius: 28px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 16%, rgba(22, 132, 255, 0.27), transparent 28rem),
    radial-gradient(circle at 90% 13%, rgba(255, 49, 93, 0.19), transparent 30rem),
    radial-gradient(circle at 48% 92%, rgba(255, 210, 94, 0.42), transparent 36rem),
    linear-gradient(135deg, #eef6ff 0%, #fff8e2 100%);
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 4px solid rgba(255, 210, 94, 0.92);
  outline-offset: 3px;
}

.game-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.2vw, 16px);
  padding: clamp(10px, 1.25vw, 22px);
}

.topbar,
.status-strip,
.team-card,
.centre-stage,
.settings-card,
.winner-card {
  background: var(--paper);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-radius: 24px;
  padding: 12px 14px;
}

.brand-lockup { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.brand-badge {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--purple), var(--teal));
  color: white;
  font-weight: 1000;
  letter-spacing: -0.08em;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.14);
}
.brand-lockup p { margin: 0; font-size: 12px; letter-spacing: .16em; text-transform: uppercase; font-weight: 900; color: var(--purple); }
h1 { margin: -2px 0 0; font-size: clamp(24px, 3vw, 42px); line-height: .95; color: var(--ink); letter-spacing: -0.06em; }

.top-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.mini-button,
.icon-button,
.button,
.small-stage-button {
  border: 0;
  border-radius: 16px;
  min-height: 46px;
  padding: 10px 15px;
  font-weight: 900;
  color: var(--ink);
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(20, 33, 61, 0.13), var(--shadow-soft);
}
.mini-button:hover,
.icon-button:hover,
.button:hover,
.small-stage-button:hover { transform: translateY(-1px); }
.mini-button.danger { color: var(--bad); }
.button.primary { background: var(--purple); color: white; box-shadow: inset 0 -4px 0 rgba(0,0,0,.16); }
.button.secondary { background: white; color: var(--ink); }

.status-strip {
  display: grid;
  grid-template-columns: 1.4fr 1fr .8fr .8fr;
  gap: 10px;
  border-radius: 22px;
  padding: 10px;
}
.status-strip > div {
  min-width: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  padding: 10px 12px;
  border: 1px solid rgba(20, 33, 61, .07);
}
.label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; font-weight: 900; }
.status-strip strong { display: block; margin-top: 2px; color: var(--ink); font-size: clamp(16px, 1.55vw, 22px); line-height: 1.08; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.arena {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(290px, 1fr) minmax(300px, .92fr) minmax(290px, 1fr);
  gap: clamp(10px, 1.2vw, 16px);
  align-items: stretch;
}

.team-card,
.centre-stage {
  border-radius: var(--radius);
  padding: clamp(13px, 1.4vw, 22px);
}
.team-card {
  display: grid;
  grid-template-rows: auto auto auto auto auto 1fr;
  gap: clamp(9px, 1vw, 14px);
  min-width: 0;
  position: relative;
  overflow: hidden;
}
.team-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .6;
}
.team-one::before { background: linear-gradient(180deg, rgba(22,132,255,.14), transparent 30%); }
.team-two::before { background: linear-gradient(180deg, rgba(255,49,93,.13), transparent 30%); }
.team-card > * { position: relative; }

.team-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.team-label { margin: 0 0 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .14em; font-weight: 1000; }
.team-head h2 { margin: 0; color: var(--ink); font-size: clamp(26px, 2.8vw, 42px); line-height: 1; letter-spacing: -0.06em; overflow-wrap: anywhere; }
.score-pill {
  min-width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  font-size: clamp(28px, 3vw, 40px);
  font-weight: 1000;
  color: white;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.16);
}
.team-one .score-pill { background: var(--blue); }
.team-two .score-pill { background: var(--red); }

.team-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.team-stats span {
  flex: 1;
  min-width: 112px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255,255,255,.82);
  border: 1px solid rgba(20,33,61,.08);
  color: var(--muted);
}
.team-stats strong { color: var(--ink); font-size: 18px; }

.question-box {
  min-height: clamp(130px, 18vh, 182px);
  display: grid;
  align-content: center;
  border-radius: 24px;
  padding: 14px;
  color: white;
  text-align: center;
  box-shadow: inset 0 -12px 30px rgba(0, 0, 0, .12);
}
.team-one .question-box { background: linear-gradient(135deg, var(--blue), var(--blue-deep)); }
.team-two .question-box { background: linear-gradient(135deg, var(--red), var(--red-deep)); }
.question-label { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .16em; font-weight: 1000; opacity: .88; }
.question-text { font-size: clamp(42px, 6vw, 78px); line-height: 1; font-weight: 1000; letter-spacing: -0.06em; overflow-wrap: anywhere; }
.question-box.correct { animation: correctPulse .48s ease-out; }
.question-box.incorrect { animation: incorrectWiggle .38s ease-out; }
.question-box.bonus { animation: bonusGlow .65s ease-out; }

.answer-display {
  min-height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.83);
  border: 2px solid rgba(20, 33, 61, 0.1);
}
.answer-text { font-size: clamp(28px, 3.3vw, 46px); font-weight: 1000; color: var(--ink); min-width: 1ch; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  min-height: clamp(48px, 7vh, 76px);
  border: 0;
  border-radius: 18px;
  background: white;
  color: var(--ink);
  font-size: clamp(20px, 2.7vw, 34px);
  font-weight: 1000;
  box-shadow: inset 0 -4px 0 rgba(20, 33, 61, .12), 0 5px 12px rgba(20, 33, 61, .08);
}
.key:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(20, 33, 61, .12); }
.key.action { font-size: clamp(16px, 1.7vw, 22px); }
.team-one .key.enter { background: var(--blue); color: white; box-shadow: inset 0 -4px 0 var(--blue-deep); }
.team-two .key.enter { background: var(--red); color: white; box-shadow: inset 0 -4px 0 var(--red-deep); }
.feedback { margin: 0; min-height: 30px; font-weight: 900; text-align: center; color: var(--muted); line-height: 1.25; }
.feedback.good { color: #087a39; }
.feedback.bad { color: var(--bad); }
.feedback.bonus { color: var(--purple); }

.centre-stage {
  display: grid;
  grid-template-rows: auto auto minmax(150px, 1fr) auto auto auto;
  gap: 13px;
  align-items: center;
  position: relative;
  overflow: hidden;
}
.stage-top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.team-chip,
.round-chip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 9px 12px;
  border-radius: 999px;
  color: white;
  font-weight: 1000;
  font-size: 13px;
  text-align: center;
}
.chip-one { background: var(--blue); }
.chip-two { background: var(--red); }
.round-chip { background: var(--ink); min-width: 86px; }

.countdown {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  font-size: clamp(74px, 14vw, 160px);
  font-weight: 1000;
  color: white;
  text-shadow: 0 8px 28px rgba(20, 33, 61, .42);
  background: rgba(20, 33, 61, .28);
}
.countdown.show { display: grid; animation: countdownPop .55s ease-out; }

.rope-track {
  position: relative;
  min-height: clamp(155px, 25vh, 250px);
  display: grid;
  place-items: center;
}
.rope-line {
  width: 96%;
  height: 20px;
  border-radius: 999px;
  background: repeating-linear-gradient(45deg, #9b6a3b 0 13px, #c08a51 13px 26px);
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.16), 0 10px 30px rgba(20, 33, 61, .14);
}
.energy-orb {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: clamp(78px, 10.5vw, 126px);
  height: clamp(78px, 10.5vw, 126px);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, white 0 10%, transparent 11%),
    radial-gradient(circle, #fff08f 0%, #ffbd15 55%, #ff7900 100%);
  box-shadow: 0 0 0 8px rgba(255, 210, 94, .25), 0 0 42px rgba(255, 180, 0, .82), 0 18px 50px rgba(20, 33, 61, .18);
  transition: transform .48s cubic-bezier(.2, .8, .2, 1), left .48s cubic-bezier(.2, .8, .2, 1);
}
.energy-orb span { font-size: clamp(36px, 6vw, 68px); filter: drop-shadow(0 4px 0 rgba(0,0,0,.12)); }
.energy-orb.bump { animation: orbBump .42s ease-out; }
.finish {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  padding: 8px 10px;
  border-radius: 999px;
  color: white;
  font-weight: 1000;
  font-size: 12px;
  letter-spacing: .12em;
}
.finish-left { left: 0; background: var(--blue); }
.finish-right { right: 0; background: var(--red); }

.mascot-row { display: grid; grid-template-columns: 74px 1fr 74px; gap: 8px; align-items: end; }
.mascot {
  height: 84px;
  position: relative;
  filter: drop-shadow(0 8px 10px rgba(20,33,61,.14));
}
.mascot span { position: absolute; display: block; }
.mascot .head { width: 28px; height: 28px; border-radius: 50%; top: 4px; left: 23px; }
.mascot .body { width: 20px; height: 40px; border-radius: 999px; top: 30px; left: 27px; transform: rotate(-8deg); }
.mascot .arm { width: 12px; height: 34px; border-radius: 999px; top: 31px; }
.mascot .arm.a { left: 18px; transform: rotate(58deg); }
.mascot .arm.b { left: 43px; transform: rotate(-58deg); }
.mascot .leg { width: 13px; height: 32px; border-radius: 999px; top: 61px; }
.mascot .leg.a { left: 24px; transform: rotate(22deg); }
.mascot .leg.b { left: 38px; transform: rotate(-18deg); }
.mascot-left .head, .mascot-left .body, .mascot-left .arm, .mascot-left .leg { background: var(--blue); }
.mascot-right .head, .mascot-right .body, .mascot-right .arm, .mascot-right .leg { background: var(--red); }
.mascot-right { transform: scaleX(-1); }
.game-shell[data-started="true"] .mascot-left,
.game-shell[data-started="true"] .mascot-right { animation: teamPull .8s infinite ease-in-out; }

.arena-title { text-align: center; align-self: center; }
.arena-title p { margin: 0 0 5px; color: var(--muted); font-weight: 800; }
.arena-title strong { color: var(--ink); font-size: clamp(22px, 3vw, 34px); letter-spacing: -0.05em; }
.centre-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.start-button {
  border: 0;
  border-radius: 22px;
  min-height: 66px;
  width: 100%;
  background: linear-gradient(135deg, var(--purple), var(--teal));
  color: white;
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 1000;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.16), 0 16px 34px rgba(70, 68, 220, .24);
}
.small-stage-button { min-width: 98px; }
.start-button:active,
.small-stage-button:active { transform: translateY(2px); }
.teacher-note {
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(20,33,61,.08);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.35;
}
.teacher-note.hidden { display: none; }

.settings-panel,
.winner-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(12, 20, 36, 0.58);
  z-index: 20;
}
.settings-panel.open,
.winner-modal.open { display: flex; }
.settings-card,
.winner-card {
  width: min(840px, 100%);
  max-height: min(92vh, 920px);
  overflow: auto;
  border-radius: 30px;
  padding: clamp(18px, 2.5vw, 28px);
}
.settings-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.eyebrow { margin: 0 0 4px; color: var(--purple); font-size: 12px; text-transform: uppercase; letter-spacing: .16em; font-weight: 1000; }
.settings-head h2,
.winner-card h2 { margin: 0; color: var(--ink); font-size: clamp(32px, 4vw, 54px); line-height: 1; letter-spacing: -0.06em; }
.icon-button { width: 48px; padding: 0; font-size: 30px; }
.settings-form { display: grid; gap: 14px; margin-top: 18px; }
.settings-form label { display: grid; gap: 7px; font-size: 14px; font-weight: 900; color: var(--ink); }
.settings-form input,
.settings-form select,
.settings-form textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border-radius: 16px;
  border: 1px solid rgba(20, 33, 61, .18);
  background: white;
  color: var(--ink);
}
.settings-form textarea { resize: vertical; line-height: 1.5; min-height: 126px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.three { grid-template-columns: 1.2fr .8fr 1fr; }
.toggle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.toggle-row { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 10px !important; }
.toggle-row input { width: 22px; min-height: 22px; }
.hint { display: block; color: var(--muted); font-weight: 700; font-size: 12px; }
.question-info {
  border-radius: 16px;
  border: 1px solid rgba(109, 76, 255, .18);
  background: rgba(109, 76, 255, .07);
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  font-weight: 750;
}
.settings-actions,
.winner-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.settings-message { margin: 0; color: var(--muted); font-weight: 800; min-height: 24px; }

.winner-card { text-align: center; }
.winner-card p:not(.eyebrow) { font-size: 19px; line-height: 1.45; }
.winner-actions { justify-content: center; }
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px auto;
  max-width: 520px;
}
.result-grid div {
  border-radius: 20px;
  background: white;
  border: 1px solid rgba(20, 33, 61, .1);
  padding: 14px;
}
.result-grid span { display: block; color: var(--muted); font-weight: 900; }
.result-grid strong { display: block; color: var(--ink); font-size: 46px; font-weight: 1000; }

.confetti-piece,
.spark-piece {
  position: fixed;
  pointer-events: none;
  z-index: 30;
}
.confetti-piece {
  width: 12px;
  height: 18px;
  border-radius: 4px;
  animation: confettiFall 1.8s ease-out forwards;
}
.spark-piece {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  animation: sparkFly .78s ease-out forwards;
}

body.display-mode .topbar {
  position: fixed;
  top: 10px;
  right: 10px;
  left: auto;
  z-index: 10;
  padding: 8px;
  border-radius: 18px;
  background: rgba(255,255,255,.72);
}
body.display-mode .brand-lockup { display: none; }
body.display-mode .status-strip { display: none; }
body.display-mode .top-actions { gap: 6px; }
body.display-mode .mini-button { min-height: 42px; padding: 9px 11px; font-size: 13px; }
body.display-mode .game-shell { padding-top: 10px; }
body.display-mode .arena { min-height: calc(100vh - 20px); }

@keyframes correctPulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.035); filter: brightness(1.16); }
  100% { transform: scale(1); }
}
@keyframes incorrectWiggle {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-5px); }
}
@keyframes bonusGlow {
  0% { box-shadow: 0 0 0 rgba(255,210,94,0); }
  40% { box-shadow: 0 0 0 9px rgba(255,210,94,.42), inset 0 -12px 30px rgba(0, 0, 0, .12); }
  100% { box-shadow: 0 0 0 rgba(255,210,94,0), inset 0 -12px 30px rgba(0, 0, 0, .12); }
}
@keyframes orbBump {
  0% { scale: 1; }
  50% { scale: 1.12; }
  100% { scale: 1; }
}
@keyframes confettiFall {
  0% { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}
@keyframes sparkFly {
  0% { transform: translate(0,0) scale(1); opacity: .95; }
  100% { transform: translate(var(--x), var(--y)) scale(.2); opacity: 0; }
}
@keyframes countdownPop {
  0% { transform: scale(.72); opacity: 0; }
  35% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes teamPull {
  0%, 100% { translate: 0 0; }
  50% { translate: 4px 0; }
}

@media (max-width: 1180px) {
  .arena { grid-template-columns: 1fr; }
  .centre-stage { order: -1; min-height: 390px; }
  .status-strip { grid-template-columns: 1fr 1fr; }
  .question-text { font-size: clamp(42px, 9vw, 84px); }
}
@media (max-width: 720px) {
  .game-shell { padding: 8px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .brand-lockup { min-width: 0; }
  .top-actions { justify-content: stretch; }
  .top-actions button { flex: 1 1 40%; }
  .status-strip { grid-template-columns: 1fr; }
  .form-row,
  .form-row.three,
  .toggle-grid { grid-template-columns: 1fr; }
  .mascot-row { grid-template-columns: 42px 1fr 42px; }
  .mascot { transform: scale(.82); transform-origin: bottom center; }
  .mascot-right { transform: scaleX(-1) scale(.82); }
  .question-box { min-height: 124px; }
  .centre-actions { grid-template-columns: 1fr; }
  body.display-mode .topbar { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
