/* Color Class — static app styles. No build step required. */
:root {
  --blue: #3b5bdb;
  --blue-dark: #2741a8;
  --ink: #1f2a44;
  --paper: #ffffff;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: radial-gradient(circle at 15% 15%, #dbeafe 0%, #eef2ff 45%, #fce7f3 100%);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

body {
  -webkit-touch-callout: none;
}

input {
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

button {
  font: inherit;
  cursor: pointer;
  touch-action: none;
}

button:focus-visible, input:focus-visible {
  outline: 3px solid #ffd43b;
  outline-offset: 2px;
}

#app, .screen {
  width: 100%;
  height: 100%;
}

.screen[hidden], [hidden] {
  display: none !important;
}

/* ---------------- Start screen ---------------- */
#start-screen {
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  overscroll-behavior: contain;
}

.start-card {
  width: min(100%, 460px);
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  border: 4px solid #ffffff;
  border-radius: 28px;
  box-shadow: 0 18px 50px rgba(43, 62, 113, 0.22), 0 0 0 1px #dbe4ff;
  padding: clamp(18px, 4vh, 32px);
  text-align: center;
}

.badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: #e5dbff;
  color: #5f3dc4;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.start-card h1 {
  margin: 12px 0 4px;
  font-size: clamp(32px, 6vh, 46px);
  line-height: 1.1;
  color: var(--blue);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0 0 20px;
  color: #5c6b86;
  font-size: 15px;
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 16px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 800;
  color: #36466b;
}

.field-note {
  font-weight: 500;
  color: #8a97ae;
}

.field input {
  display: block;
  width: 100%;
  padding: 13px 15px;
  border: 2px solid #dbe4ff;
  border-radius: 14px;
  background: #f8faff;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
}

#room-input {
  text-transform: uppercase;
  letter-spacing: 0.35em;
  font-size: 20px;
}

.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 3px solid #ffffff;
  background: var(--swatch);
  box-shadow: 0 0 0 2px #e3e9f7;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.color-swatch.is-selected {
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 0 0 3px var(--blue);
}

.hat-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.hat-btn {
  padding: 7px 10px;
  border: 2px solid #e3e9f7;
  border-radius: 999px;
  background: #f8faff;
  color: #36466b;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.hat-btn.is-selected {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
  box-shadow: 0 2px 0 var(--blue-dark);
}

.warning {
  margin: -4px 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff3bf;
  color: #8a6100;
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
}

.start-actions {
  display: grid;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 16px;
  font-weight: 800;
  color: #2b3c63;
  background: #eef2ff;
  box-shadow: 0 4px 0 #d3dbf5;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #d3dbf5;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  color: #ffffff;
  background: var(--blue);
  box-shadow: 0 4px 0 var(--blue-dark);
  font-size: 17px;
}

.btn-primary:active {
  box-shadow: 0 1px 0 var(--blue-dark);
}

.btn-secondary {
  font-size: 15px;
}

.btn-small {
  padding: 9px 12px;
  border-radius: 11px;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 3px 0 #d3dbf5;
}

.btn-small.btn-primary {
  box-shadow: 0 3px 0 var(--blue-dark);
}

.btn-warn {
  background: #fff3bf;
  box-shadow: 0 3px 0 #f1dd9a;
}

.btn-warn[aria-pressed="true"] {
  background: #ffd8a8;
  box-shadow: 0 3px 0 #efc184;
}

.help-text {
  margin: 16px 0 0;
  color: #8a97ae;
  font-size: 12px;
  line-height: 1.5;
}

/* ---------------- Teacher Host password gate ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 32, 70, 0.55);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(100%, 380px);
  max-height: 100%;
  overflow: auto;
  padding: clamp(18px, 4vh, 28px);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 22px 60px rgba(20, 32, 70, 0.35), 0 0 0 1px #dbe4ff;
  text-align: left;
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: clamp(21px, 5vw, 26px);
  line-height: 1.15;
  color: var(--blue-dark);
}

.modal-help {
  margin: 0 0 18px;
  color: #5c6b86;
  font-size: 13px;
  line-height: 1.45;
}

.modal-password-input {
  width: 100%;
  border-color: #dbe4ff;
}

.modal-password-input.is-invalid {
  border-color: #e03131;
  background: #fff5f5;
  box-shadow: 0 0 0 3px rgba(224, 49, 49, 0.16);
  animation: password-shake 0.32s ease-in-out;
}

@keyframes password-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.modal-error {
  margin: -6px 0 14px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff5f5;
  color: #c92a2a;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------------- Game screen ---------------- */
#game-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
}

#hud {
  width: 100%;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 5px 18px rgba(43, 62, 113, 0.14);
  flex-wrap: wrap;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* On desktop the row wrappers are transparent: identity pills, then the
   question banner, then status/action controls, then Leave. On phones the
   same wrappers become real full-width flex rows. */
.hud-row-identity {
  display: contents;
}

.hud-left {
  order: 0;
}

.hud-row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  order: 2;
}

.hud-leave {
  order: 3;
}

.pill {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: #36466b;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pill-role {
  background: #d3f9d8;
  color: #2b8a3e;
}

.pill-phase {
  background: #ffe3e3;
  color: #c92a2a;
}

.pill-timer {
  min-width: 44px;
  text-align: center;
  background: #fff3bf;
  color: #8a6100;
  font-variant-numeric: tabular-nums;
}

.pill-score {
  background: #e5dbff;
  color: #5f3dc4;
  font-variant-numeric: tabular-nums;
}

#question-banner {
  flex: 1 1 240px;
  min-width: 0;
  order: 1;
  text-align: center;
  line-height: 1.2;
}

#question-meta {
  display: block;
  color: #7b86a1;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#question-text {
  display: block;
  font-size: clamp(12px, 2vh, 17px);
  color: var(--blue-dark);
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.icon-btn {
  border: 0;
  border-radius: 10px;
  padding: 6px 9px;
  background: #eef2ff;
  color: #36466b;
  font-size: 12px;
  font-weight: 800;
}

#fullscreen-btn {
  min-width: 96px;
}

#stage-wrap {
  position: relative;
  width: 100%;
  height: auto;
  flex: none;
  overflow: hidden;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(43, 62, 113, 0.25);
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: #eef4ff;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

.stage-overlay {
  position: absolute;
  z-index: 2;
}

/* In-canvas touch controls: only visible on mobile / touch screens for students. */
.touch-control {
  display: none;
}

@media (max-width: 899px), (pointer: coarse) {
  .touch-control:not([hidden]) {
    display: flex !important;
  }
}

#app.is-host .touch-control {
  display: none !important;
}

/* Left thumb: virtual analog joystick with a draggable thumb knob. */
#joystick {
  left: 24px;
  bottom: 24px;
  width: 104px;
  height: 104px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  background: rgba(59, 91, 219, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22), 0 4px 14px rgba(20, 32, 70, 0.25);
  opacity: 0.45;
  transition: opacity 0.12s ease, background 0.12s ease;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#joystick.is-active {
  opacity: 0.75;
  background: rgba(59, 91, 219, 0.34);
}

.joystick-knob {
  width: 44px;
  height: 44px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  background: rgba(59, 91, 219, 0.88);
  box-shadow: 0 3px 9px rgba(20, 32, 70, 0.32);
  pointer-events: none;
  will-change: transform;
}

/* Right thumb: circular Hop button. */
.hop-btn {
  right: 24px;
  bottom: 24px;
  width: 74px;
  height: 74px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: rgba(59, 91, 219, 0.6);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  opacity: 0.45;
  transition: opacity 0.12s ease, background 0.12s ease;
  box-shadow: 0 4px 12px rgba(20, 32, 70, 0.3);
  touch-action: none;
}

.hop-btn small {
  font-size: 9px;
  font-weight: 700;
  opacity: 0.85;
}

.hop-btn.is-active {
  opacity: 0.75;
  background: rgba(39, 65, 168, 0.75);
}

/* Student reaction: small translucent thumbs-up above Hop. */
.emote-btn {
  right: 28px;
  bottom: 108px;
  width: 54px;
  height: 54px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  background: rgba(59, 91, 219, 0.45);
  color: #ffffff;
  font-size: 26px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.12s ease, background 0.12s ease, transform 0.12s ease;
  box-shadow: 0 3px 10px rgba(20, 32, 70, 0.26);
  touch-action: none;
}

.emote-btn.is-active {
  opacity: 0.75;
  background: rgba(39, 65, 168, 0.7);
  transform: scale(1.08);
}

#freeze-banner {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  padding: 12px 22px;
  border-radius: 16px;
  background: rgba(33, 48, 84, 0.85);
  color: white;
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}

.vocab-banner {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 10px 18px;
  border: 3px solid #ffd166;
  border-radius: 16px;
  background: rgba(27, 32, 58, 0.92);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
  white-space: pre-line;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

#announcement-banner {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: min(92%, 620px);
  padding: 10px 16px;
  border: 2px solid #f59f00;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff3bf, #ffd43b);
  color: #2b2a00;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  pointer-events: none;
}

#announcement-banner[hidden] {
  display: none !important;
}

.announcement-icon {
  font-size: 18px;
  line-height: 1;
  flex: 0 0 auto;
}

/* Teacher Host map controls. */
.fit-map-btn {
  position: absolute;
  z-index: 6;
  top: 12px;
  left: 12px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: #2741a8;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 3px 12px rgba(20, 32, 70, 0.28);
  backdrop-filter: blur(8px);
  touch-action: none;
}

.fit-map-btn:hover {
  background: #ffffff;
}

.fit-map-btn:active {
  background: var(--blue);
  color: #ffffff;
}

#stage.host-map #game-canvas {
  cursor: grab;
}

#stage.host-map #game-canvas:active {
  cursor: grabbing;
}

/* ---------------- Leaderboard drawer ---------------- */
.leaderboard-toggle {
  position: absolute;
  z-index: 5;
  top: 14px;
  right: 14px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: #2741a8;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 3px 10px rgba(43, 62, 113, 0.22);
  backdrop-filter: blur(6px);
}

.leaderboard-toggle[aria-expanded="true"] {
  background: var(--blue);
  color: #ffffff;
}

/* Teacher Host right-sidebar drawer toggle (also bound to the H key). */
.drawer-toggle {
  display: none;
  position: absolute;
  z-index: 6;
  top: 14px;
  right: 14px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #2741a8;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(43, 62, 113, 0.22);
  backdrop-filter: blur(6px);
  touch-action: none;
}

.drawer-toggle[aria-expanded="false"] {
  background: var(--blue);
  color: #ffffff;
}

.leaderboard {
  position: absolute;
  z-index: 5;
  top: 52px;
  right: 14px;
  width: 232px;
  max-height: calc(100% - 66px);
  overflow: auto;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 30px rgba(20, 32, 70, 0.28);
  backdrop-filter: blur(9px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(26px);
  transition: opacity 0.2s ease, transform 0.22s ease, visibility 0.22s;
}

.leaderboard.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 8px;
  color: var(--blue-dark);
  font-size: 13px;
}

.leaderboard-close {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 8px;
  background: #eef2ff;
  color: #36466b;
  font-size: 18px;
  line-height: 1;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 5px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 7px;
  border-radius: 10px;
  background: #f8faff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.lb-row[data-rank="1"] { background: #fff3bf; }
.lb-row[data-rank="2"] { background: #e9ecef; }
.lb-row[data-rank="3"] { background: #ffe8cc; }
.lb-row.is-ghost { opacity: 0.55; }

.lb-badge {
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #dee2e6;
  font-size: 12px;
}

[data-rank="1"] .lb-badge { background: #ffd43b; color: #7a4f01; }
[data-rank="2"] .lb-badge { background: #ced4da; color: #495057; }
[data-rank="3"] .lb-badge { background: #e8894a; color: #ffffff; }

.lb-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  flex: none;
  color: var(--blue-dark);
  font-variant-numeric: tabular-nums;
}

.lb-empty {
  padding: 18px 8px;
  color: #8a97ae;
  font-size: 12px;
  text-align: center;
}

/* Canvas draws the animated podium; this layer only hosts the title/close UI. */
.podium-overlay {
  position: absolute;
  z-index: 6;
  inset: 0;
  pointer-events: none;
}

.podium-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 5px 16px rgba(20, 32, 70, 0.3);
  color: var(--blue-dark);
  font-size: 15px;
  white-space: nowrap;
  pointer-events: auto;
}

.podium-close-btn {
  width: auto;
  height: 26px;
  padding: 0 10px;
  background: var(--blue-dark);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
}

.podium-overlay [hidden] {
  display: none !important;
}

.podium-empty {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  color: #5c6b86;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

#teacher-bar {
  width: 100%;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 5px 18px rgba(43, 62, 113, 0.14);
}

.broadcast-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  padding: 2px 4px;
  border-radius: 10px;
  background: #eef2ff;
}

.broadcast-controls input {
  width: min(230px, 34vw);
  min-width: 120px;
  padding: 6px 8px;
  border: 1px solid #c5cdee;
  border-radius: 8px;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 600;
}

.teacher-label {
  font-size: 11px;
  font-weight: 800;
  color: #8a97ae;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
}

#game-type-select { min-width: 210px; }

.obby-mode #question-banner {
  border-color: #ffd43b;
  background: linear-gradient(135deg, rgba(255, 243, 191, 0.97), rgba(255, 212, 59, 0.97));
}

.obby-mode #question-meta { color: #6b4e00; }
.obby-mode #question-text { color: #2b2a00; }

/* Authoritative rule selector: points (default) or elimination. */
.mode-controls {
  display: flex;
  gap: 4px;
  padding: 3px 5px;
  border-radius: 12px;
  background: #f1edff;
}

.mode-btn {
  padding: 6px 8px;
  border: 1px solid #d0c4f5;
  border-radius: 8px;
  background: #ffffff;
  color: #5f3dc4;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.15;
  white-space: normal;
}

.mode-btn.is-active {
  border-color: #7048e8;
  background: #7048e8;
  color: #ffffff;
  box-shadow: 0 2px 0 #5f3dc4;
}

.mode-btn[data-mode="points"].is-active {
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: 0 2px 0 var(--blue-dark);
}

/* Countdown duration presets + custom value + start action. */
.timer-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 5px;
  border-radius: 12px;
  background: #e9eefc;
}

.timer-controls.hide-duration {
  background: transparent;
  padding: 0;
}

.timer-controls.hide-duration .preset-btn,
.timer-controls.hide-duration .custom-time {
  display: none;
}

.timer-controls.hide-duration #start-btn {
  min-width: 158px;
}

.preset-btn {
  min-width: 32px;
  padding: 6px 8px;
  border: 1px solid #c7d7f5;
  border-radius: 8px;
  background: #ffffff;
  color: #36466b;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.preset-btn.is-active {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
  box-shadow: 0 2px 0 var(--blue-dark);
}

.custom-time {
  display: flex;
  align-items: center;
  gap: 2px;
  color: #36466b;
  font-size: 12px;
  font-weight: 800;
}

#duration-input {
  width: 44px;
  padding: 5px 4px;
  border: 2px solid #dbe4ff;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}

#duration-input::-webkit-outer-spin-button,
#duration-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Question sets, map theme, sheet loader and Web Speech controls. */
.question-set-controls,
.map-theme-controls,
.game-type-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 5px;
  border-radius: 12px;
  background: #fff4e6;
}

.teacher-field {
  color: #8a6100;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#question-set-select,
#map-theme-select,
#game-type-select {
  max-width: 168px;
  padding: 5px 6px;
  border: 2px solid #ffd8a8;
  border-radius: 8px;
  background: #ffffff;
  color: #8a6100;
  font-size: 11px;
  font-weight: 800;
}

#question-set-select:focus-visible,
#map-theme-select:focus-visible,
#game-type-select:focus-visible,
#sheet-url-input:focus-visible {
  outline: 3px solid #ffd43b;
  outline-offset: 1px;
}

.sheet-details {
  position: relative;
}

.sheet-details summary {
  list-style: none;
  padding: 6px 8px;
  border: 1px solid #dbe4ff;
  border-radius: 8px;
  background: #f8faff;
  color: #36466b;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.sheet-details summary::-webkit-details-marker { display: none; }
.sheet-details summary::after { content: " ▾"; }
.sheet-details[open] summary::after { content: " ▴"; }

.sheet-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 360px;
  max-width: 80vw;
  padding: 10px;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(43, 62, 113, 0.24);
}

#sheet-url-input {
  width: 100%;
  padding: 7px 8px;
  border: 2px solid #dbe4ff;
  border-radius: 8px;
  color: var(--ink);
  font-size: 11px;
  touch-action: manipulation;
}

.sheet-status {
  color: #2b8a3e;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.3;
}

.sheet-status.is-error { color: #c92a2a; }

.speech-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 5px;
  border-radius: 12px;
  background: #e6fcf5;
}

.speech-controls .btn-small.is-active {
  border-color: #0ca678;
  background: #0ca678;
  color: #ffffff;
  box-shadow: 0 2px 0 #087f5b;
}

.speech-controls .btn-small.is-speaking {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

#question-text.is-listening {
  color: #7048e8;
  font-style: italic;
}

#question-text.is-listening::before { content: "🎧 "; }

/* Desktop/laptop: students get a full-width arena; hosts get a control rail. */
@media (min-width: 900px) {
  #game-screen {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "hud"
      "stage";
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  #hud {
    grid-area: hud;
    z-index: 3;
    width: 100%;
    max-width: none;
    min-height: 44px;
    margin: 0;
    padding: 6px 12px;
    border-radius: 0;
    box-shadow: 0 2px 10px rgba(43, 62, 113, 0.18);
  }

  #stage-wrap {
    grid-area: stage;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    margin: 0;
    justify-self: stretch;
    align-self: stretch;
    border-radius: 0;
    box-shadow: none;
  }

  #stage {
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    border-radius: 0;
  }

  /* Students always own the full viewport: one column, no sidebar gutter. */
  body.is-student #game-screen,
  body:not(.is-host) #game-screen {
    width: 100vw;
    max-width: none;
    margin: 0;
    padding: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "hud"
      "stage";
  }

  body.is-student #hud,
  body.is-student #stage-wrap,
  body.is-student #stage,
  body:not(.is-host) #hud,
  body:not(.is-host) #stage-wrap,
  body:not(.is-host) #stage {
    width: 100%;
    max-width: none;
  }

  /* The 2-column sidebar exists ONLY while Teacher Host is active. */
  body.is-host #game-screen {
    width: 96vw;
    margin: 0 auto;
    grid-template-columns: minmax(0, 1fr) clamp(260px, 20vw, 340px);
    grid-template-areas:
      "hud hud"
      "stage controls";
    gap: 8px;
    padding: 8px 12px 10px;
    justify-content: stretch;
  }

  body.is-host #teacher-bar {
    grid-area: controls;
    width: 100%;
    max-width: none;
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: min-content;
    align-content: start;
    align-items: center;
    gap: 6px;
    padding: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #teacher-bar > .teacher-label,
  #teacher-bar > .mode-controls,
  #teacher-bar > .speech-controls,
  #teacher-bar > .broadcast-controls,
  #teacher-bar > #timer-controls,
  #teacher-bar > .sheet-details {
    grid-column: 1 / -1;
  }

  #teacher-bar > .btn { width: 100%; }

  .game-type-controls,
  .question-set-controls,
  .map-theme-controls {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 0;
  }

  #game-type-select,
  #question-set-select,
  #map-theme-select {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .mode-controls,
  .speech-controls,
  .timer-controls,
  .broadcast-controls {
    width: 100%;
    min-width: 0;
  }

  .mode-btn { flex: 1 1 0; }
  .broadcast-controls { flex-wrap: wrap; }
  .broadcast-controls input { flex: 1 1 120px; width: auto; min-width: 110px; }
  .sheet-panel { width: min(320px, 92%); max-width: none; }
}

/* Compact phones: keep every button reachable without shrinking the arena. */
@media (max-width: 560px) {
  #game-screen { gap: 4px; padding-left: 4px; padding-right: 4px; }
  .hat-btn { padding: 5px 7px; font-size: 10px; }
  .podium-toast { top: 8px; font-size: 12px; padding: 6px 8px 6px 11px; }
  .podium-close-btn { height: 22px; padding: 0 7px; font-size: 10px; }
  #announcement-banner { top: 6px; max-width: 96%; padding: 7px 10px; font-size: 12px; border-width: 1px; }
  .announcement-icon { font-size: 15px; }
  .broadcast-controls input { width: min(180px, 46vw); min-width: 100px; font-size: 11px; }
  #hud { padding: 4px 6px; gap: 4px; }
  .pill { font-size: 10px; padding: 4px 6px; }
  .icon-btn { font-size: 11px; padding: 5px 6px; }
  #question-banner { flex: 1 1 100%; max-width: 100%; order: 3; }
  #question-text { font-size: 12px; line-height: 1.2; }
  #question-meta { font-size: 9px; }
  .teacher-label { display: none; }
  #teacher-bar { gap: 4px; padding: 4px; }
  .mode-controls { gap: 3px; padding: 2px 3px; }
  .mode-btn { padding: 5px 6px; font-size: 10px; }
  .leaderboard-toggle { top: 8px; right: 8px; padding: 5px 8px; font-size: 10px; }
  .leaderboard { top: 40px; right: 8px; width: 208px; max-height: calc(100% - 48px); }
  .lb-row { font-size: 11px; padding: 5px 6px; }
  .timer-controls { gap: 3px; padding: 2px 3px; }
  .preset-btn { min-width: 26px; padding: 5px 6px; font-size: 10px; }
  #duration-input { width: 36px; font-size: 11px; padding: 4px 2px; }
  .custom-time { font-size: 10px; }
  .question-set-controls, .map-theme-controls, .game-type-controls, .speech-controls { gap: 3px; padding: 2px 3px; }
  .teacher-field { display: none; }
  #game-type-select { min-width: 0; width: 100%; font-size: 11px; }
  #question-set-select, #map-theme-select, #game-type-select { max-width: 126px; padding: 4px; font-size: 10px; }
  .sheet-details summary { padding: 5px 6px; font-size: 10px; }
  .speech-controls .btn-small { padding: 6px; font-size: 10px; }
  .btn-small { font-size: 11px; padding: 7px 8px; }
}

@media (max-height: 520px) {
  #hud { padding-top: 3px; padding-bottom: 3px; }
  #teacher-bar { padding-top: 3px; padding-bottom: 3px; }
}

/* Host-only extra-wide layout with a wrapping horizontal control row. */
@media (min-width: 900px) {
  #app.is-host #game-screen,
  #app.is-host #teacher-bar {
    max-width: 1280px;
  }

  #app.is-host #game-screen {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "hud"
      "stage"
      "controls";
  }

  #app.is-host #hud {
    position: relative;
    z-index: 2;
  }

  #app.is-host #stage-wrap {
    width: auto !important;
    max-width: 100%;
    height: 100% !important;
    max-height: 56vh;
    aspect-ratio: 16 / 9;
    margin: 0 auto;
    justify-self: center;
    align-self: stretch;
  }

  #app.is-host #teacher-bar {
    position: relative;
    z-index: 2;
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    overflow: visible;
  }

  #app.is-host #teacher-bar > .btn {
    width: auto;
  }
}

/* Phones and tablets: full-height top-to-bottom layout with in-canvas controls. */
@media (max-width: 1023px) {
  html,
  body,
  #app {
    height: 100%;
    height: 100dvh;
  }

  body,
  #app {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow: hidden;
  }

  #app {
    flex: 1 1 auto;
    min-height: 0;
  }

  #game-screen {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-width: none;
    margin: 0;
    min-height: 0;
    align-items: stretch;
    justify-content: flex-start;
    gap: 4px;
    padding: calc(env(safe-area-inset-top) + 2px) 6px 2px;
  }

  #hud {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    padding: 4px 6px;
    gap: 4px;
    border-radius: 12px;
  }

  #question-banner {
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
    order: 3;
  }

  #question-meta {
    font-size: 10px;
  }

  #question-text {
    font-size: clamp(14px, 3.8vw, 18px);
    line-height: 1.25;
  }

  #stage-wrap {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0;
    max-width: 100%;
    max-height: none;
    aspect-ratio: auto;
    margin: 0;
  }

  #stage {
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
  }

  #teacher-bar {
    flex: 0 1 auto;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: 30dvh;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #teacher-bar > .btn,
  #teacher-bar select,
  #teacher-bar input {
    width: 100%;
    max-width: none;
  }
}

/* Small screens: full-height arena with floating overlay controls. */
@media (max-width: 899px) {
  #game-screen {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100dvh;
    padding-left: 6px;
    padding-right: 6px;
    padding-bottom: 0;
  }

  #hud {
    flex: 0 0 auto;
    position: relative;
    z-index: 3;
  }

  #stage-wrap {
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    margin: 0 0 10px;
  }

  #stage {
    width: 100%;
    height: 100%;
  }

  #game-canvas {
    width: 100%;
    height: 100%;
    display: block;
  }
}

/* Mobile HUD: three stacked full-width rows — identity + Leave, status +
   Sound / Fullscreen, then the question banner. */
@media (max-width: 899px) {
  #hud {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
  }

  /* Row 1: identity pills left, full-label Leave pinned to the far right. */
  .hud-row-identity {
    display: flex;
    flex: 0 0 auto;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
  }

  .hud-left {
    flex: 0 1 auto;
    flex-wrap: nowrap;
    min-width: 0;
  }

  .hud-leave {
    flex: 0 0 auto;
    order: 0;
    margin-left: auto;
  }

  /* Row 2: score, phase, timer and the two compact emoji buttons. */
  .hud-row-actions {
    display: flex;
    flex: 0 0 auto;
    justify-content: center;
    align-items: center;
    gap: 6px;
    width: 100%;
    flex-wrap: nowrap;
    min-width: 0;
  }

  /* Row 3: question banner directly below the two HUD rows. */
  #question-banner {
    flex: 0 0 auto;
    width: 100%;
    order: 2;
  }

  #mute-btn,
  #fullscreen-btn,
  #leave-btn {
    height: 30px;
    padding: 0 9px;
    line-height: 1;
    white-space: nowrap;
  }

  /* sound.js / game.js write the button labels; hide the words visually and
     show only the emoji. aria-pressed carries the on/off state. */
  #mute-btn,
  #fullscreen-btn {
    min-width: 0;
    font-size: 0;
  }

  #mute-btn::before,
  #fullscreen-btn::before {
    font-size: 17px;
    line-height: 1;
  }

  #mute-btn::before { content: "🔊"; }
  #mute-btn[aria-pressed="true"]::before { content: "🔇"; }
  #fullscreen-btn::before { content: "⛶"; }
  #fullscreen-btn[aria-pressed="true"]::before { content: "🗗"; }

  #leave-btn {
    font-size: 12px;
  }
}

/* Full-screen Teacher Host desktop: arena left, scrollable controls right. */
@media (min-width: 1024px) {
  html,
  body,
  #app {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }

  #app {
    display: block;
  }

  /* Students: compact HUD pinned at the top, canvas fills the rest. */
  #game-screen {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "hud"
      "stage";
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  /* Teacher Host is the only mode with the 360px control sidebar. */
  body.is-host #app.is-host #game-screen {
    grid-template-columns: minmax(0, 1fr) 360px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "hud controls"
      "stage controls";
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  #hud {
    grid-area: hud;
    z-index: 3;
    width: 100%;
    max-width: none;
    min-height: 44px;
    margin: 0;
    padding: 6px 12px;
    border-radius: 0;
    box-shadow: 0 2px 10px rgba(43, 62, 113, 0.18);
  }

  #stage-wrap {
    grid-area: stage;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }

  #stage {
    width: 100% !important;
    height: 100% !important;
    border-radius: 0;
  }

  /* Undo the 900px host-only stacked layout at full desktop widths. */
  #app.is-host #stage-wrap {
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    margin: 0;
    justify-self: stretch;
    align-self: stretch;
    border-radius: 0;
    box-shadow: none;
  }

  #app.is-host #hud {
    z-index: 3;
  }

  body.is-host #app.is-host #teacher-bar {
    grid-area: controls;
    position: static;
    width: 360px;
    max-width: 360px;
    height: 100vh;
    max-height: none;
    margin: 0;
    padding: 10px 12px 18px;
    border-radius: 0;
    box-shadow: -4px 0 18px rgba(43, 62, 113, 0.18);
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #teacher-bar > .teacher-label {
    display: block;
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.72;
  }

  #teacher-bar > .btn {
    width: 100%;
    flex: 0 0 auto;
  }

  #teacher-bar > .mode-controls,
  #teacher-bar > .speech-controls,
  #teacher-bar > .timer-controls,
  #teacher-bar > .broadcast-controls,
  #teacher-bar > .game-type-controls,
  #teacher-bar > .question-set-controls,
  #teacher-bar > .map-theme-controls,
  #teacher-bar > .sheet-details {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
  }

  #teacher-bar select,
  #teacher-bar input {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  #teacher-bar .sheet-panel {
    width: 100%;
  }
}

/* ---------------- Collapsible Teacher Host sidebar ---------------- */
@media (min-width: 1024px) {
  .drawer-toggle:not([hidden]) {
    display: block;
  }

  /* Keep the leaderboard out from under the drawer button. */
  #app.is-host #leaderboard-toggle {
    right: 168px;
  }

  #app.is-host #game-screen {
    transition: grid-template-columns 0.25s ease;
  }

  #app.is-host #teacher-bar {
    min-width: 0;
    transition:
      width 0.25s ease,
      max-width 0.25s ease,
      opacity 0.25s ease,
      padding 0.25s ease;
  }

  /* Collapsed: remove the controls track completely. !important is required
     because the full-screen host grid above has higher specificity. */
  #app.is-host.sidebar-collapsed #game-screen,
  #game-screen.sidebar-collapsed {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
    grid-template-areas:
      "hud"
      "stage" !important;
    width: 100vw !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
    overflow: hidden !important;
  }

  #app.is-host.sidebar-collapsed #hud,
  #app.is-host.sidebar-collapsed #stage-wrap,
  #game-screen.sidebar-collapsed #hud,
  #game-screen.sidebar-collapsed #stage-wrap {
    width: 100% !important;
    max-width: none !important;
  }

  /* The drawer reserves zero horizontal space; the toggle lives in the HUD. */
  #app.is-host.sidebar-collapsed #teacher-bar,
  #game-screen.sidebar-collapsed #teacher-bar {
    display: none !important;
  }

  #app.is-host.sidebar-collapsed #leaderboard-toggle,
  #game-screen.sidebar-collapsed #leaderboard-toggle {
    right: 14px;
  }
}
