:root {
  color-scheme: dark;
  font-family:
    Inter, ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --ink: #f7f8fc;
  --muted: #a7b0c3;
  --panel: rgba(23, 30, 48, 0.92);
  --panel-soft: rgba(32, 41, 64, 0.78);
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --red: #ff4f64;
  --blue: #2789f5;
  --gold: #f8bd28;
  --green: #42c477;
  --purple: #a96df4;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(39, 137, 245, 0.2), transparent 36rem),
    radial-gradient(circle at 90% 90%, rgba(169, 109, 244, 0.16), transparent 34rem),
    #0b1020;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: '';
  opacity: 0.18;
  background-image:
    linear-gradient(30deg, #24304a 12%, transparent 12.5%, transparent 87%, #24304a 87.5%),
    linear-gradient(150deg, #24304a 12%, transparent 12.5%, transparent 87%, #24304a 87.5%);
  background-position: 0 0, 0 0;
  background-size: 72px 126px;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[data-hex]:focus-visible {
  outline: 4px solid rgba(248, 189, 40, 0.8);
  outline-offset: 3px;
}

.connection-banner {
  position: fixed;
  z-index: 100;
  top: 0;
  right: 0;
  left: 0;
  padding: 0.65rem 1rem;
  color: #16100a;
  font-weight: 800;
  text-align: center;
  background: var(--gold);
}

.toast {
  position: fixed;
  z-index: 110;
  right: 1rem;
  bottom: 1rem;
  max-width: min(30rem, calc(100vw - 2rem));
  padding: 0.9rem 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  color: white;
  font-weight: 700;
  background: #b92d45;
  box-shadow: var(--shadow);
}

.screen {
  min-height: 100vh;
}

.landing {
  display: grid;
  align-items: center;
  width: min(1120px, calc(100% - 2rem));
  min-height: 100vh;
  margin: auto;
  padding: 3rem 0;
  grid-template-columns: 1.08fr 0.92fr;
  gap: clamp(2rem, 6vw, 6rem);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 950;
  letter-spacing: -0.04em;
}

.brand-hex {
  display: grid;
  width: 2.7rem;
  height: 3rem;
  place-items: center;
  color: #15120c;
  font-size: 1.35rem;
  background: linear-gradient(140deg, var(--gold), #ff754b);
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%);
}

.hero h1 {
  max-width: 12ch;
  margin: 2.4rem 0 1.2rem;
  font-size: clamp(3.4rem, 8vw, 7rem);
  line-height: 0.9;
  letter-spacing: -0.075em;
}

.hero h1 span {
  color: var(--gold);
}

.hero-copy {
  max-width: 39rem;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  line-height: 1.65;
}

.feature-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 2rem;
}

.feature-pill {
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #cbd3e4;
  background: rgba(255, 255, 255, 0.04);
}

.join-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.join-card {
  padding: clamp(1.4rem, 4vw, 2.3rem);
}

.join-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.6rem;
}

.join-card > p {
  margin: 0 0 1.35rem;
  color: var(--muted);
}

.form-stack {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field label {
  color: #c7cede;
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input,
.field select,
.team-select {
  width: 100%;
  min-height: 3.25rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  color: white;
  background: rgba(6, 10, 22, 0.72);
}

.code-input {
  font-size: 1.25rem !important;
  font-weight: 900 !important;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.button {
  display: inline-flex;
  min-height: 3.15rem;
  align-items: center;
  justify-content: center;
  padding: 0.72rem 1.15rem;
  border: 0;
  border-radius: 12px;
  font-weight: 900;
  background: #303b58;
  transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease;
}

.button:hover:not(:disabled) {
  filter: brightness(1.12);
  transform: translateY(-2px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.button-primary {
  color: #15120c;
  background: linear-gradient(135deg, var(--gold), #ff7a4d);
}

.button-secondary {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
}

.button-danger {
  background: #8e263a;
}

.button-small {
  min-height: 2.3rem;
  padding: 0.45rem 0.75rem;
  border-radius: 9px;
  font-size: 0.85rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 1.45rem 0;
  color: #778198;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.divider::before,
.divider::after {
  height: 1px;
  content: '';
  background: var(--line);
  flex: 1;
}

.loading-screen,
.message-screen {
  display: grid;
  min-height: 100vh;
  padding: 2rem;
  place-items: center;
  text-align: center;
}

.loader {
  width: 4.4rem;
  height: 4.4rem;
  margin: 0 auto 1.5rem;
  border: 7px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

.topbar {
  display: flex;
  min-height: 4.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem clamp(1rem, 3vw, 2.3rem);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 13, 27, 0.85);
  backdrop-filter: blur(15px);
}

.topbar-actions,
.code-cluster,
.phase-line {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.game-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.join-code {
  font-size: clamp(1.3rem, 2.5vw, 2rem);
  font-weight: 950;
  letter-spacing: 0.16em;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.teacher-lobby {
  display: grid;
  width: min(1160px, calc(100% - 2rem));
  margin: 2rem auto;
  grid-template-columns: minmax(0, 1.2fr) minmax(18rem, 0.8fr);
  gap: 1.5rem;
}

.teacher-screen {
  position: fixed;
  inset: 0;
  display: flex;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.teacher-screen > .topbar {
  flex: 0 0 auto;
}

.teacher-screen .teacher-lobby {
  min-height: 0;
  overflow: auto;
  flex: 1 1 auto;
}

.lobby-code-panel {
  display: grid;
  min-height: 28rem;
  padding: 2.5rem;
  place-items: center;
  text-align: center;
}

.giant-code {
  margin: 0.6rem 0;
  font-size: clamp(4rem, 11vw, 8.5rem);
  line-height: 1;
  font-weight: 950;
  letter-spacing: 0.12em;
}

.join-address {
  max-width: 100%;
  margin: 0.6rem 0 1.5rem;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(0.9rem, 2vw, 1.15rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-controls {
  padding: 1.5rem;
}

.lobby-controls h2 {
  margin-top: 0;
}

.timing-settings {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.timing-settings h3,
.timing-panel h3 {
  margin: 0 0 0.7rem;
}

.timing-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.timing-grid label {
  display: grid;
  min-width: 0;
  gap: 0.25rem;
  color: #c7cede;
  font-size: 0.76rem;
  font-weight: 800;
}

.timing-input {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.timing-input input {
  width: 100%;
  min-width: 0;
  height: 2.45rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 9px;
  color: white;
  font-weight: 900;
  background: rgba(6, 10, 22, 0.72);
}

.timing-input small {
  color: var(--muted);
}

.timing-panel {
  padding: 1rem;
}

.roster {
  display: grid;
  max-height: 20rem;
  margin: 1rem 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  gap: 0.5rem;
}

.roster li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.online-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(66, 196, 119, 0.12);
}

.offline .online-dot {
  background: #6c758a;
  box-shadow: none;
}

.teacher-game {
  display: grid;
  min-height: 0;
  height: 100%;
  padding: clamp(0.8rem, 2vw, 1.5rem);
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 23vw);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 1rem;
  overflow: hidden;
  flex: 1 1 0;
}

.team-scoreboard {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(var(--team-count, 2), minmax(0, 1fr));
  gap: 0.65rem;
}

.team-scoreboard.count-2 {
  --team-count: 2;
}

.team-scoreboard.count-3 {
  --team-count: 3;
}

.team-scoreboard.count-4 {
  --team-count: 4;
}

.team-scoreboard.count-5 {
  --team-count: 5;
}

.team-card {
  position: relative;
  min-width: 0;
  padding: 0.8rem 1rem;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  color: white;
  background: rgba(255, 255, 255, 0.08);
}

.team-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0.4rem;
  content: '';
  background: var(--team-color);
}

.team-card strong {
  display: block;
  overflow: hidden;
  font-size: clamp(1rem, 2vw, 1.35rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 0.28rem;
  color: #c4ccda;
  font-size: 0.83rem;
}

.loss-streak {
  margin-top: 0.3rem;
  color: #aeb8ca;
  font-size: 0.72rem;
}

.team-0 {
  --team-color: var(--red);
}

.team-1 {
  --team-color: var(--blue);
}

.team-2 {
  --team-color: var(--gold);
}

.team-3 {
  --team-color: var(--green);
}

.team-4 {
  --team-color: var(--purple);
}

.board-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    radial-gradient(circle at center, rgba(55, 69, 101, 0.52), transparent 70%),
    rgba(10, 16, 31, 0.72);
}

.hex-board {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: visible;
}

.hex-cell polygon {
  fill: var(--team-color);
  stroke: rgba(7, 11, 23, 0.92);
  stroke-width: 2.2;
  transition: filter 180ms ease, opacity 180ms ease, stroke-width 180ms ease;
}

.hex-cell {
  cursor: default;
}

.hex-cell.is-legal {
  cursor: pointer;
}

.hex-cell.is-legal polygon {
  stroke: white;
  stroke-width: 3.5;
  animation: legal-pulse 1.4s ease-in-out infinite;
}

.hex-cell.is-legal:hover polygon {
  filter: brightness(1.35);
}

.hex-cell.is-position polygon {
  stroke: white;
  stroke-width: 4.5;
  filter: brightness(1.15);
}

.hex-cell.is-target polygon {
  stroke: #fff3a6;
  stroke-width: 4.5;
}

.hex-cell.is-tug-center polygon {
  stroke: white;
  stroke-width: 5;
  filter: brightness(1.2);
}

@keyframes legal-pulse {
  50% {
    filter: brightness(1.22);
  }
}

.flag {
  fill: white;
  font-size: 26px;
  font-weight: 950;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.48);
  stroke-width: 3px;
  text-anchor: middle;
}

.occupants {
  fill: white;
  font-size: 16px;
  font-weight: 950;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(0, 0, 0, 0.72);
  stroke-width: 3px;
  text-anchor: middle;
}

.tug-center {
  fill: white;
  font-size: 32px;
  font-weight: 950;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(0, 0, 0, 0.72);
  stroke-width: 4px;
  text-anchor: middle;
}

.attack-line {
  opacity: 0.8;
  stroke: white;
  stroke-linecap: round;
  stroke-width: 4;
  marker-end: url('#arrowhead');
}

.game-sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

.phase-card {
  padding: 1.3rem;
}

.phase-card h2 {
  margin: 0.2rem 0 0.45rem;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
}

.phase-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.timer-number {
  min-width: 2.2ch;
  color: var(--gold);
  font-size: clamp(2rem, 5vw, 4.3rem);
  line-height: 1;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.timer-progress {
  width: 100%;
  height: 0.65rem;
  margin-top: 1rem;
  overflow: hidden;
  border: 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
}

.timer-progress::-webkit-progress-bar {
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
}

.timer-progress::-webkit-progress-value {
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), #ff6a4c);
}

.timer-progress::-moz-progress-bar {
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), #ff6a4c);
}

.mini-roster {
  min-height: 0;
  padding: 1rem;
  overflow-y: auto;
  flex: 1 1 auto;
}

.paused-card {
  border-color: rgba(248, 189, 40, 0.42);
}

.mini-roster h3 {
  margin: 0 0 0.65rem;
}

.mini-player {
  display: grid;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  grid-template-columns: 0.65rem 1fr auto;
  gap: 0.55rem;
}

.mini-player:last-child {
  border-bottom: 0;
}

.mini-player-score {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.student-shell {
  width: min(900px, 100%);
  min-height: 100vh;
  margin: auto;
  background: rgba(8, 13, 27, 0.44);
}

.student-topbar {
  position: sticky;
  z-index: 10;
  top: 0;
}

.student-main {
  padding: clamp(1rem, 4vw, 2rem);
}

.student-team {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 900;
}

.team-swatch {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  background: var(--team-color);
}

.instruction-card {
  margin-bottom: 1rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
}

.instruction-card h1,
.instruction-card h2 {
  margin: 0.15rem 0 0.35rem;
}

.instruction-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.student-board {
  height: min(64vh, 42rem);
  min-height: 24rem;
}

.waiting-card {
  display: grid;
  min-height: 65vh;
  padding: 2rem;
  place-items: center;
  text-align: center;
}

.waiting-card h1 {
  margin: 0.8rem 0 0.45rem;
  font-size: clamp(2rem, 8vw, 4rem);
}

.waiting-card p {
  max-width: 32rem;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.55;
}

.waiting-hexes {
  display: flex;
  align-items: center;
}

.waiting-hex {
  width: 3.5rem;
  height: 4rem;
  margin-left: -0.45rem;
  background: var(--team-color);
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%);
  animation: float 1.8s ease-in-out infinite alternate;
}

.waiting-hex:nth-child(2) {
  animation-delay: 200ms;
}

.waiting-hex:nth-child(3) {
  animation-delay: 400ms;
}

@keyframes float {
  to {
    transform: translateY(-0.7rem);
  }
}

.battle-screen {
  display: grid;
  min-height: calc(100vh - 4.5rem);
  padding: 1.2rem;
  place-items: center;
}

.battle-card {
  width: min(42rem, 100%);
  padding: clamp(1.3rem, 5vw, 2.7rem);
  border: 1px solid var(--line);
  border-radius: 28px;
  text-align: center;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.battle-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.battle-score {
  font-size: 1.15rem;
  font-weight: 900;
}

.problem {
  margin: clamp(2rem, 8vh, 4rem) 0;
  font-size: clamp(4.5rem, 20vw, 9rem);
  line-height: 0.9;
  font-weight: 950;
  letter-spacing: -0.07em;
}

.problem.three-factor {
  font-size: clamp(3.1rem, 12vw, 6.5rem);
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
}

.answer-input {
  min-width: 0;
  min-height: 4.4rem;
  padding: 0.6rem 1rem;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-radius: 15px;
  color: white;
  font-size: 2rem;
  font-weight: 950;
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
}

.answer-button {
  min-width: 7rem;
}

.answer-flash {
  min-height: 1.7rem;
  margin-top: 0.7rem;
  font-weight: 900;
}

.answer-flash.correct {
  color: #72e6a1;
}

.answer-flash.wrong {
  color: #ff8292;
}

.results-list {
  display: grid;
  margin-top: 1rem;
  gap: 0.6rem;
}

.powerup-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.powerup-card {
  display: grid;
  min-height: 10rem;
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: white;
  text-align: left;
  background: var(--panel);
  gap: 0.65rem;
}

.powerup-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.powerup-card strong {
  color: var(--gold);
  font-size: 1.1rem;
}

.powerup-card span {
  color: var(--muted);
  line-height: 1.45;
}

.powerup-target-form {
  display: grid;
  max-width: 38rem;
  margin: 1rem auto;
  padding: 1.3rem;
  gap: 1rem;
}

.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-left: 5px solid var(--team-color);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.04);
}

.winner-title {
  margin: 0;
  font-size: clamp(3rem, 10vw, 7rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.winner-team {
  color: var(--team-color);
}

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

.center {
  text-align: center;
}

.empty-state {
  padding: 1.5rem;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 820px) {
  .landing,
  .teacher-lobby {
    grid-template-columns: 1fr;
  }

  .powerup-options {
    grid-template-columns: 1fr;
  }

  .landing {
    padding: 2rem 0;
  }

  .hero h1 {
    margin-top: 1.5rem;
  }

  .teacher-game {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

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

  .game-sidebar {
    grid-row: 2;
  }

  .teacher-game > .board-panel {
    grid-row: 3;
    min-height: 0;
  }

  .mini-roster {
    display: none;
  }

  .topbar .brand-mark {
    font-size: 1.1rem;
  }

  .topbar .brand-hex {
    width: 2rem;
    height: 2.3rem;
    font-size: 1rem;
  }
}

@media (max-width: 520px) {
  .topbar {
    min-height: 4rem;
  }

  .topbar-actions .button-danger,
  .teacher-game .mini-roster {
    display: none;
  }

  .giant-code {
    font-size: 18vw;
  }

  .lobby-code-panel {
    min-height: 20rem;
    padding: 1.3rem;
  }

  .answer-row {
    grid-template-columns: 1fr;
  }

  .answer-button {
    width: 100%;
  }

  .student-main {
    padding: 0.75rem;
  }

  .student-board {
    min-height: 20rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
