:root {
  color-scheme: light;
  --bg: #eef3f7;
  --ink: #162436;
  --muted: #5b6b7c;
  --line: #ccd8e6;
  --panel: #ffffff;
  --blue: #245b8f;
  --green: #35785e;
  --gold: #d79b28;
  --red: #b24a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button,
.primary-link,
.secondary-link {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.secondary-link {
  background: #dfe8f2;
  color: var(--ink);
}

.control-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 8px;
  padding: 12px 18px;
  background: #dfe8f2;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.control-link.disabled {
  pointer-events: none;
  opacity: 0.48;
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0;
}

.front,
.join-layout,
.play-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.teacher-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 18px 44px rgba(22, 36, 54, 0.1);
}

.intro-panel,
.join-panel,
.play-panel {
  width: min(620px, 100%);
}

.kicker {
  margin: 0 0 8px;
  color: var(--blue);
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

.lead {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.front-actions,
.teacher-controls,
.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.toggle-row {
  margin-top: 0;
}

.quiz-form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.quiz-form label,
fieldset {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

fieldset label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.category-picker {
  display: grid;
  gap: 12px;
}

.category-picker-head {
  display: grid;
  gap: 10px;
}

.category-picker h2 {
  margin: 0;
  font-size: 1rem;
  color: #174072;
}

.subject-list {
  display: grid;
  gap: 14px;
}

.subject-group {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.subject-group h3 {
  margin: 0;
  font-size: 1rem;
  color: #174072;
}

.subject-group-list {
  display: grid;
  gap: 8px;
}

.subject-option {
  display: flex !important;
  flex-direction: row !important;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  padding: 9px 10px;
  border: 1px solid #dde6f4;
  border-radius: 12px;
  background: #f4f7fb;
  font-weight: 400;
  color: var(--ink);
}

.subject-option input {
  flex: 0 0 auto;
  inline-size: 18px;
  block-size: 18px;
}

.subject-option span {
  min-width: 0;
  font-weight: 600;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.status,
.feedback,
.answer-host {
  min-height: 24px;
  margin-top: 14px;
  color: var(--muted);
  font-weight: 700;
}

.status.error,
.feedback.wrong {
  color: var(--red);
}

.status.ok,
.feedback.correct {
  color: var(--green);
}

.room-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.room-code span {
  color: var(--muted);
  font-weight: 700;
}

.room-code strong {
  font-size: 2.6rem;
  letter-spacing: 0.08em;
}

.question-host {
  margin-top: 20px;
}

.question-prompt {
  font-size: clamp(1.45rem, 4vw, 2.6rem);
  line-height: 1.15;
}

.pretty-fraction {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  min-width: 1.45em;
  margin: 0 0.08em;
  line-height: 1;
  vertical-align: middle;
}

.pretty-fraction > span {
  display: block;
  width: 100%;
  min-width: max-content;
  text-align: center;
}

.pretty-fraction > span:first-child {
  width: 100%;
  padding: 0 0.12em 0.08em;
  border-bottom: 0.08em solid currentColor;
}

.pretty-fraction > span:last-child {
  padding-top: 0.08em;
}

.mixed-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.05em;
  flex-wrap: wrap;
}

.question-canvas {
  display: block;
  width: min(100%, 340px);
  height: auto;
  margin: 18px auto 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.function-table {
  width: min(520px, 100%);
  margin-top: 18px;
  border-collapse: collapse;
  font-size: 1.4rem;
}

.function-table th,
.function-table td {
  border: 1px solid var(--line);
  padding: 14px;
  text-align: center;
}

.line-graph {
  display: block;
  width: min(100%, 380px);
  height: auto;
  margin: 18px auto 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.grid-line {
  stroke: #d8e1ec;
  stroke-width: 1;
}

.axis-line {
  stroke: #17283b;
  stroke-width: 2;
}

.graph-line {
  stroke: #e21b3c;
  stroke-width: 5;
  stroke-linecap: round;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.choice {
  min-height: 70px;
  background: #e8f0f8;
  color: #fff;
  border: 0;
  text-align: left;
}

.letter-choice {
  min-height: 110px;
  display: grid;
  place-items: center;
  text-align: center;
}

.letter-choice strong {
  font-size: clamp(2.8rem, 18vw, 5rem);
}

.choice-a {
  background: #e21b3c;
}

.choice-b {
  background: #1368ce;
}

.choice-c {
  background: #d89e00;
}

.choice-d {
  background: #26890c;
}

.choice.selected {
  outline: 6px solid rgba(255, 255, 255, 0.9);
  outline-offset: -8px;
  color: #fff;
}

.choice.correct {
  background: var(--green);
  color: #fff;
}

.choice.wrong {
  background: var(--red);
  color: #fff;
}

.play-topline,
.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.phase-text {
  margin-top: 12px;
  color: var(--muted);
  font-weight: 700;
}

.rank-text {
  margin-top: 8px;
  color: var(--blue);
  font-weight: 800;
}

.player-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.player-row,
.player-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #e8f0f8;
}

.player-chip.is-offline {
  background: #f1f3f6;
  color: #667485;
  border-style: dashed;
}

.player-chip span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.player-chip .player-state {
  color: var(--red);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.kick-player-btn {
  display: inline-grid;
  place-items: center;
  width: auto;
  min-width: 48px;
  height: 28px;
  min-height: 28px;
  margin-left: 2px;
  padding: 0 9px;
  border-radius: 999px;
  background: #dbe5f1;
  color: #31465d;
  font-size: 0.82rem;
  line-height: 1;
}

.kick-player-btn:hover {
  background: var(--red);
  color: #fff;
}

.empty-state {
  color: var(--muted);
}

.screen-body {
  min-height: 100vh;
  background: #102236;
  color: #fff;
  overflow: hidden;
}

.screen-shell {
  width: min(1500px, calc(100vw - 48px));
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 18px;
}

.screen-topbar {
  position: relative;
  z-index: 24;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.screen-topbar h1 {
  font-size: clamp(1.8rem, 3vw, 3.2rem);
}

.screen-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.screen-code,
.screen-timer {
  min-width: 112px;
  height: 52px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.1);
  text-align: center;
}

.screen-code,
.screen-timer {
  display: grid;
  place-items: center;
}

.screen-code span {
  display: block;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.72);
}

.screen-code strong,
.screen-timer {
  font-size: clamp(1.55rem, 2.7vw, 2.7rem);
  font-weight: 900;
}

.screen-code strong {
  transform: translateY(-2px);
  line-height: 1;
}

.screen-timer {
  transform: translateY(-2px);
  line-height: 1;
}

.fullscreen-btn,
.sound-btn {
  height: 52px;
  min-height: 52px;
  border-radius: 8px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.icon-btn {
  min-width: 52px;
  width: 52px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
}

.screen-question {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 0;
  overflow: hidden;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.screen-question .question-prompt {
  text-align: center;
  font-size: calc(clamp(2rem, 4.5vw, 5.1rem) * var(--question-scale, 1));
}

.screen-question .question-canvas {
  width: min(calc(46vw * var(--question-scale, 1)), 520px);
  max-height: calc(42vh * var(--question-scale, 1));
  object-fit: contain;
}

.screen-question .function-table {
  width: min(calc(760px * var(--question-scale, 1)), 70vw);
  font-size: calc(clamp(1.5rem, 2.7vw, 2.8rem) * var(--question-scale, 1));
}

.screen-question .line-graph {
  width: min(calc(49vh * var(--question-scale, 1)), 500px);
  max-height: calc(46vh * var(--question-scale, 1));
}

.screen-question.is-fit-tight {
  padding: 14px;
}

.screen-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.screen-choice {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 18px;
  min-height: clamp(82px, 13vh, 112px);
  border-radius: 8px;
  padding: 18px 22px;
  background: #e8f0f8;
  color: #fff;
  border: 4px solid transparent;
}

.screen-choice.choice-a {
  background: #e21b3c;
}

.screen-choice.choice-b {
  background: #1368ce;
}

.screen-choice.choice-c {
  background: #d89e00;
}

.screen-choice.choice-d {
  background: #26890c;
}

.screen-choice strong {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 2.3rem;
}

.screen-choice > span {
  font-size: clamp(1.35rem, 2.45vw, 2.8rem);
  font-weight: 800;
  line-height: 1.12;
}

.screen-choice.correct {
  background: #21a65b !important;
  color: #fff;
}

.screen-choice.correct strong {
  background: rgba(255, 255, 255, 0.22);
}

.screen-choice.dimmed {
  background: #d8dee8 !important;
  color: #526071;
  opacity: 0.72;
}

.screen-choice.dimmed strong {
  background: #9aa6b5;
  color: #fff;
}

.screen-choice.selected-answer {
  border-color: #e21b3c;
  box-shadow: 0 0 0 7px rgba(226, 27, 60, 0.36), 0 0 34px rgba(226, 27, 60, 0.5);
}

.podium-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(16, 34, 54, 0.58);
  backdrop-filter: blur(6px);
  overflow: hidden;
}

.podium-modal.is-visible {
  display: grid;
}

.battle-intro-modal {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: none;
  place-items: center;
  padding: 32px;
  background: rgba(16, 34, 54, 0.72);
  color: #fff;
  font-size: clamp(3rem, 8vw, 8rem);
  font-weight: 900;
  line-height: 1.08;
  text-align: center;
  text-transform: none;
}

.battle-intro-modal.is-visible {
  display: grid;
}

.podium-card {
  position: relative;
  z-index: 2;
  width: min(720px, 100%);
  display: grid;
  gap: 12px;
  border-radius: 8px;
  padding: 28px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
}

.fireworks-canvas {
  position: fixed;
  inset: 0;
  z-index: 21;
  display: none;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.fireworks-canvas.is-visible {
  display: block;
}

.podium-card h2 {
  font-size: clamp(2.2rem, 5vw, 4rem);
  text-align: center;
}

.podium-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  border-radius: 8px;
  padding: 16px 20px;
  background: #e8f0f8;
  font-size: clamp(1.5rem, 2.4vw, 2.4rem);
  font-weight: 800;
}

.podium-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.podium-row em {
  color: var(--muted);
  font-size: 0.8em;
  font-style: normal;
  white-space: nowrap;
}

.podium-modal.is-final .podium-card {
  width: min(900px, 100%);
}

.screen-lobby {
  font-size: clamp(2rem, 4vw, 4rem);
  font-weight: 900;
  text-align: center;
}

.screen-lobby-error {
  color: var(--red);
  font-size: clamp(1.5rem, 3.2vw, 3rem);
}

@media (max-width: 760px) {
  .teacher-layout {
    grid-template-columns: 1fr;
  }

  .choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .room-code {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 900px) {
  .screen-body {
    overflow: auto;
  }

  .screen-shell {
    height: auto;
    min-height: 100vh;
  }

  .screen-topbar {
    grid-template-columns: 1fr;
  }

  .screen-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .screen-choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-height: 760px) {
  .screen-shell {
    gap: 10px;
    padding: 12px 0;
  }

  .screen-topbar,
  .screen-actions {
    gap: 10px;
  }

  .screen-topbar h1 {
    font-size: clamp(1.35rem, 2.8vw, 2.2rem);
  }

  .screen-code,
  .screen-timer,
  .fullscreen-btn,
  .sound-btn {
    height: 44px;
    min-height: 44px;
    padding: 8px 12px;
  }

  .icon-btn {
    min-width: 44px;
    width: 44px;
    padding: 0;
  }

  .screen-code strong,
  .screen-timer {
    font-size: clamp(1.6rem, 3vw, 2.7rem);
  }

  .screen-question {
    padding: 14px;
  }

  .screen-choice {
    min-height: 72px;
    padding: 12px 16px;
  }

  .screen-choice strong {
    width: 56px;
    height: 56px;
    font-size: 1.8rem;
  }
}

.battle-screen-body {
  background: #0e2234;
}

.battle-screen-shell {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.battle-scorebar {
  position: relative;
  z-index: 24;
  display: flex;
  gap: 10px;
  min-height: 62px;
  overflow: hidden;
}

.battle-score {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  gap: 2px;
  align-content: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.1);
}

.battle-score strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-score span {
  justify-self: start;
  color: #f9c74f;
  font-size: 1.45rem;
  font-weight: 900;
}

.battle-score.is-turn {
  border-color: #f9c74f;
  box-shadow: inset 0 0 0 2px rgba(249, 199, 79, 0.42);
}

.battle-score.is-correct-result {
  border-color: #21a65b;
}

.battle-score.is-wrong-result {
  border-color: #e21b3c;
}

.battle-score.is-score-flash {
  animation: battle-result-blink 0.42s ease-in-out 0s 5 alternate;
}

.score-flyer {
  position: fixed;
  z-index: 30;
  left: 50vw;
  top: 50vh;
  transform: translate(0, 0) scale(1);
  transform-origin: center;
  pointer-events: none;
  color: #fff;
  font-size: clamp(4rem, 11vw, 10rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  transition: transform 1.9s cubic-bezier(0.12, 0.82, 0.16, 1), opacity 0.25s ease 1.95s;
}

.score-flyer.is-positive {
  color: #65e695;
}

.score-flyer.is-negative {
  color: #ff6f61;
}

@keyframes battle-result-blink {
  from {
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }

  to {
    transform: translateY(-2px) scale(1.04);
    filter: brightness(1.3);
  }
}

.battle-board-screen {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  min-height: 0;
}

.battle-board-column {
  display: grid;
  grid-template-rows: minmax(78px, auto) repeat(5, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.battle-board-column h2 {
  display: grid;
  place-items: center;
  min-height: 78px;
  border-radius: 8px;
  padding: 10px;
  background: #17395a;
  color: #fff;
  font-size: clamp(1rem, 1.45vw, 1.7rem);
  text-align: center;
  overflow-wrap: anywhere;
}

.battle-cell {
  display: grid;
  place-items: center;
  min-height: 72px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #1f5c8f;
  color: #f9c74f;
  font-size: clamp(1.6rem, 3vw, 3.3rem);
  font-weight: 900;
}

.battle-cell.is-used,
.battle-cell:disabled {
  background: #273646;
  color: #718094;
  opacity: 0.72;
}

.battle-cell.is-active {
  outline: 5px solid #f9c74f;
  outline-offset: -5px;
}

.battle-question-panel {
  position: fixed;
  inset: 176px 24px 24px;
  z-index: 15;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  border-radius: 8px;
  padding: 18px;
  background: #102236;
}

.battle-question-panel.is-figure-question {
  grid-template-rows: auto auto;
  align-content: center;
}

.battle-question-panel.is-figure-question .screen-question {
  align-self: center;
  min-height: 0;
}

.battle-question-panel[hidden] {
  display: none;
}

.battle-question-meta {
  color: #f9c74f;
  font-size: clamp(1.5rem, 2.4vw, 2.6rem);
  font-weight: 900;
  text-align: center;
}

.phone-board {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.phone-choice-row {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 12px 14px;
  background: #1f5c8f;
  color: #fff;
  font-size: 1.08rem;
  font-weight: 900;
  text-align: center;
}

.phone-choice-row:disabled {
  background: #d8dee8;
  color: #697789;
  opacity: 0.78;
}

.points-choice-row {
  min-height: 66px;
  background: #245b8f;
  color: #f9c74f;
  font-size: 1.45rem;
}

.secondary-choice-row {
  min-height: 46px;
  background: #dfe8f2;
  color: var(--ink);
  font-size: 0.95rem;
}

.phone-board-column {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) repeat(5, minmax(0, 58px));
  gap: 6px;
  align-items: stretch;
}

.phone-board-column h2 {
  display: flex;
  align-items: center;
  margin: 0;
  min-width: 0;
  border-radius: 8px;
  padding: 8px;
  background: #e8f0f8;
  color: var(--ink);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.phone-cell {
  min-height: 48px;
  padding: 0;
  font-size: 0.95rem;
}

.battle-phone .letter-choice {
  min-height: 118px;
  gap: 4px;
}

.battle-phone .letter-choice strong {
  font-size: clamp(3rem, 18vw, 5rem);
}

.battle-phone .letter-choice span {
  display: none;
}

@media (max-width: 900px) {
  .battle-board-screen {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .phone-board-column {
    grid-template-columns: 1fr repeat(5, minmax(0, 44px));
  }
}
