:root {
  --bg-1: #0d3a99;
  --bg-2: #1b6eff;
  --bg-3: #58c4ff;
  --surface: rgba(255, 255, 255, 0.97);
  --surface-alt: rgba(243, 248, 255, 0.96);
  --text: #13396d;
  --muted: #5578ac;
  --line: rgba(19, 57, 109, 0.12);
  --primary: #ffd33a;
  --primary-2: #ffb703;
  --accent: #ff5c8a;
  --accent-2: #ff7b2c;
  --ok: #16a34a;
  --danger: #e5484d;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --shadow-lg: 0 20px 48px rgba(12, 66, 155, 0.2);
  --shadow-sm: 0 8px 18px rgba(12, 66, 155, 0.12);
  --title-font: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
  --body-font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 8% 10%, rgba(255,255,255,.28), transparent 18%),
    radial-gradient(circle at 92% 8%, rgba(255,212,58,.22), transparent 16%),
    radial-gradient(circle at 85% 88%, rgba(255,92,138,.16), transparent 16%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2) 54%, var(--bg-3));
  color: var(--text);
  font-family: var(--body-font);
}

button, input, select, textarea {
  font: inherit;
}

button {
  color: inherit;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell {
  width: min(860px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
  position: relative;
}

.app-shell::before,
.app-shell::after {
  content: "";
  position: fixed;
  border-radius: 999px;
  pointer-events: none;
  opacity: .44;
  filter: blur(8px);
}
.app-shell::before {
  left: -30px;
  top: 140px;
  width: 110px;
  height: 110px;
  background: rgba(255, 211, 58, 0.35);
}
.app-shell::after {
  right: -24px;
  bottom: 110px;
  width: 92px;
  height: 92px;
  background: rgba(255, 92, 138, 0.28);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: white;
  font-family: var(--title-font);
  font-weight: 900;
  cursor: pointer;
  text-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 14px;
  color: #114084;
  background: linear-gradient(180deg, #fff6ae, #ffd33a);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.08), 0 10px 20px rgba(255,211,58,.28);
}
.brand-text {
  font-size: 1.02rem;
}

.screen {
  display: none;
  animation: screen-in .22s ease both;
}
.screen.active {
  display: block;
}
.screen.centered.active {
  display: grid;
  min-height: 70vh;
  place-content: center;
  text-align: center;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px) scale(.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hero {
  color: white;
  text-shadow: 0 2px 18px rgba(0,0,0,.12);
  padding: 10px 0 22px;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  margin: 0 0 12px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.88);
  color: #114084;
  font-family: var(--title-font);
  font-size: .74rem;
  font-weight: 900;
  letter-spacing: .11em;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}
h1, h2, p { margin-top: 0; }
h1, h2 {
  font-family: var(--title-font);
}
h1 {
  margin-bottom: 14px;
  font-size: clamp(2.8rem, 13vw, 5rem);
  line-height: .93;
  letter-spacing: -.06em;
}
h2 {
  margin-bottom: 18px;
  font-size: clamp(2rem, 6vw, 2.8rem);
  line-height: 1;
  letter-spacing: -.04em;
  color: #114084;
}
.hero-copy,
.dialog-copy,
.result-subtitle {
  color: rgba(255,255,255,.95);
  line-height: 1.55;
  max-width: 620px;
  font-size: 1rem;
}
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.mode-card,
.panel,
.question-card {
  background: linear-gradient(180deg, var(--surface), var(--surface-alt));
  border: 3px solid rgba(255,255,255,.52);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
}
.mode-card {
  position: relative;
  overflow: hidden;
  min-height: 226px;
  padding: 24px;
  border-radius: var(--radius-xl);
  text-align: left;
  cursor: pointer;
  transition: transform .16s ease;
}
.mode-card:hover {
  transform: translateY(-2px);
}
.mode-card::before,
.mode-card::after {
  content: "";
  position: absolute;
  border-radius: 999px;
}
.mode-card::before {
  right: -20px;
  top: -24px;
  width: 110px;
  height: 110px;
  background: radial-gradient(circle, rgba(255,211,58,.44), rgba(255,211,58,0));
}
.mode-card::after {
  left: -16px;
  bottom: -20px;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, rgba(255,92,138,.18), rgba(255,92,138,0));
}
.mode-card.alt::before {
  background: radial-gradient(circle, rgba(88,196,255,.38), rgba(88,196,255,0));
}
.mode-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 34px;
  place-items: center;
  border-radius: 18px;
  color: #114084;
  background: linear-gradient(180deg, #fff7b8, #ffd33a);
  font-family: var(--title-font);
  font-size: 1.3rem;
  font-weight: 900;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.08), 0 10px 22px rgba(255,211,58,.26);
}
.mode-title, .mode-copy { display: block; }
.mode-title {
  margin-bottom: 8px;
  color: #114084;
  font-family: var(--title-font);
  font-size: 1.4rem;
  font-weight: 900;
}
.mode-copy {
  color: var(--muted);
  line-height: 1.5;
}
.home-features {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}
.home-features span {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.16);
  color: white;
  font-family: var(--title-font);
  font-size: .8rem;
  font-weight: 900;
  border: 2px solid rgba(255,255,255,.18);
}

.panel {
  padding: 26px 20px;
  border-radius: var(--radius-xl);
}
.panel.compact {
  max-width: 580px;
  margin: 26px auto 0;
}
.lobby-panel {
  max-width: 620px;
  margin: 20px auto 0;
}
.back-link {
  padding: 10px 0;
  border: 0;
  background: transparent;
  color: white;
  font-family: var(--title-font);
  cursor: pointer;
  text-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.field {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}
.field > span,
.field legend {
  color: var(--muted);
  font-size: .84rem;
  font-family: var(--title-font);
  font-weight: 900;
}
fieldset.field {
  border: 0;
  padding: 0;
}
input, select, textarea {
  width: 100%;
  border: 2px solid #d9e8fb;
  border-radius: 15px;
  outline: none;
  color: var(--text);
  background: white;
}
input, select {
  height: 54px;
  padding: 0 15px;
}
textarea {
  min-height: 180px;
  padding: 14px 15px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .85rem;
}
input:focus, select:focus, textarea:focus {
  border-color: #7cc5ff;
  box-shadow: 0 0 0 4px rgba(88,196,255,.18);
}
.room-input {
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 900;
}
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.segmented label {
  cursor: pointer;
}
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented span {
  display: grid;
  height: 50px;
  place-items: center;
  border: 2px solid #d9e8fb;
  border-radius: 16px;
  color: #4c73ad;
  background: #fff;
  font-family: var(--title-font);
  font-weight: 900;
  box-shadow: 0 6px 14px rgba(0,67,170,.06);
}
.segmented input:checked + span {
  border-color: #ffd33a;
  color: #114084;
  background: linear-gradient(180deg, #fff7b8, #ffd33a);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.07), 0 12px 20px rgba(255,211,58,.18);
}
.primary-button,
.secondary-button,
.ghost-button {
  width: 100%;
  min-height: 54px;
  padding: 0 18px;
  border-radius: 17px;
  font-family: var(--title-font);
  font-weight: 900;
  cursor: pointer;
}
.primary-button {
  border: 0;
  color: #114084;
  background: linear-gradient(180deg, #fff6ae, #ffd33a);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.08), 0 14px 24px rgba(255,211,58,.24);
}
.secondary-button {
  border: 2px solid #a7c8ff;
  color: #114084;
  background: white;
  box-shadow: var(--shadow-sm);
}
.ghost-button {
  border: 2px solid #d9e8fb;
  color: #4469a4;
  background: white;
  box-shadow: var(--shadow-sm);
}
.ghost-button.small {
  width: auto;
  min-height: 40px;
  padding: 0 14px;
  font-size: .8rem;
}
.ghost-button.danger {
  color: var(--danger);
}
button:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none !important;
}
.online-actions {
  display: grid;
  gap: 14px;
}
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.room-code-card {
  display: grid;
  width: 100%;
  margin-bottom: 24px;
  padding: 18px;
  border: 2px dashed #9bc2ff;
  border-radius: 20px;
  color: var(--muted);
  background: linear-gradient(180deg, #f5faff, #edf6ff);
  cursor: pointer;
}
.room-code-card strong {
  margin: 4px 0;
  color: #114084;
  font-family: var(--title-font);
  font-size: 2.4rem;
  letter-spacing: .14em;
}
.players-list {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}
.player-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 2px solid #e1eefc;
  border-radius: 18px;
  background: rgba(255,255,255,.7);
}
.player-slot div {
  display: grid;
  gap: 3px;
}
.player-slot small {
  color: var(--muted);
}
.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #8ca0bf;
  box-shadow: 0 0 0 5px rgba(140,160,191,.16);
}
.status-dot.online {
  background: #16a34a;
  box-shadow: 0 0 0 5px rgba(22,163,74,.16);
}
.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .83rem;
  line-height: 1.45;
}

.countdown {
  color: white;
  font-family: var(--title-font);
  font-size: clamp(7rem, 32vw, 13rem);
  font-weight: 900;
  line-height: .88;
  letter-spacing: -.08em;
  text-shadow: 0 14px 38px rgba(0,0,0,.18);
}
#countdownMessage {
  color: white;
  font-family: var(--title-font);
  text-shadow: 0 2px 12px rgba(0,0,0,.12);
}

.game-header {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.score-chip,
.opponent-badge {
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 2px solid rgba(255,255,255,.24);
  border-radius: 18px;
  background: rgba(255,255,255,.14);
  color: white;
  box-shadow: 0 10px 24px rgba(0,0,0,.08);
}
.score-chip small,
.opponent-badge {
  font-family: var(--title-font);
}
.score-chip small {
  color: rgba(255,255,255,.84);
  font-size: .67rem;
  font-weight: 900;
  letter-spacing: .1em;
}
.score-chip strong {
  font-family: var(--title-font);
  font-size: 1.24rem;
}
.opponent-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-size: .86rem;
}
.hidden { display: none !important; }

.timer-track {
  height: 14px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 2px solid rgba(255,255,255,.32);
  border-radius: 999px;
  background: rgba(255,255,255,.22);
}
.timer-bar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #42e5a7, #ffd33a 56%, #ff8f4f);
  transform-origin: left center;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
}

.question-card {
  min-height: 540px;
  padding: 24px 18px;
  border-radius: var(--radius-xl);
}
.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.category-chip,
.type-chip {
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 999px;
  font-family: var(--title-font);
  font-size: .73rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.category-chip {
  color: #114084;
  background: linear-gradient(180deg, #fff7b8, #ffe070);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.06);
}
.type-chip {
  color: white;
  background: linear-gradient(180deg, #ff719c, #ff5c8a);
}
.question-card h2 {
  margin: 18px 0 14px;
  color: #114084;
  font-size: clamp(1.65rem, 6vw, 2.3rem);
  line-height: 1.12;
  letter-spacing: -.035em;
}
.question-support {
  margin-bottom: 16px;
  color: var(--muted);
  line-height: 1.5;
}
.question-image-wrap {
  margin-bottom: 18px;
  overflow: hidden;
  border-radius: 22px;
  border: 2px solid #d9e8fb;
  background: #fff;
}
.question-image-wrap img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}
.answers-stack {
  display: grid;
  gap: 12px;
}
.answer-button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 12px 14px;
  border: 2px solid #d7e8fc;
  border-radius: 18px;
  color: var(--text);
  background: linear-gradient(180deg, #ffffff, #f7fbff);
  box-shadow: var(--shadow-sm);
  text-align: left;
  cursor: pointer;
}
.answer-button:hover:not(:disabled) {
  transform: translateX(2px);
}
.answer-letter {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(180deg, #eaf5ff, #d4e9ff);
  color: #114084;
  font-family: var(--title-font);
  font-size: .82rem;
  font-weight: 900;
}
.answer-button.correct {
  border-color: rgba(22,163,74,.46);
  background: linear-gradient(180deg, rgba(22,163,74,.12), rgba(22,163,74,.06));
}
.answer-button.wrong {
  border-color: rgba(229,72,77,.42);
  background: linear-gradient(180deg, rgba(229,72,77,.13), rgba(229,72,77,.07));
}

.input-card,
.match-card {
  padding: 18px;
  border: 2px solid #e1eefc;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff, #f6fbff);
  box-shadow: var(--shadow-sm);
}
.input-card p,
.match-card p {
  margin-bottom: 14px;
  color: var(--muted);
}
.submit-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.submit-row .primary-button,
.submit-row .ghost-button {
  min-height: 48px;
}
.match-rows {
  display: grid;
  gap: 12px;
}
.match-row {
  display: grid;
  gap: 10px;
}
.match-left {
  padding: 12px 14px;
  border-radius: 14px;
  background: #eaf5ff;
  color: #114084;
  font-family: var(--title-font);
  font-weight: 900;
}
.match-row select {
  height: 50px;
}
.feedback-banner {
  min-height: 60px;
  margin-top: 14px;
  text-align: center;
  color: white;
  font-family: var(--title-font);
  font-weight: 900;
  line-height: 1.4;
  text-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.feedback-banner.good {
  color: #c9ffd9;
}
.feedback-banner.bad {
  color: #ffe5ea;
}

.results-panel {
  max-width: 640px;
  margin: 30px auto 0;
  text-align: center;
}
.results-panel .result-subtitle {
  color: var(--muted);
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0 4px;
}
.stats-grid > div {
  display: grid;
  gap: 5px;
  padding: 18px 14px;
  border: 2px solid #e1eefc;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff, #f3f9ff);
  box-shadow: var(--shadow-sm);
}
.stats-grid small {
  color: var(--muted);
  font-family: var(--title-font);
  font-weight: 900;
}
.stats-grid strong {
  color: #114084;
  font-family: var(--title-font);
  font-size: 1.55rem;
  line-height: 1;
}
.scoreboard {
  display: grid;
  gap: 10px;
  margin: 24px 0;
}
.score-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 15px;
  border: 2px solid #e1eefc;
  border-radius: 18px;
  text-align: left;
  background: linear-gradient(180deg, #ffffff, #f6fbff);
  box-shadow: var(--shadow-sm);
}
.score-row.winner {
  border-color: rgba(22,163,74,.46);
  background: linear-gradient(180deg, rgba(22,163,74,.12), rgba(22,163,74,.05));
}
.score-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.score-row span {
  color: var(--muted);
  font-size: .86rem;
}

dialog {
  width: min(620px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: auto;
  border: 2px solid rgba(255,255,255,.4);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, var(--surface), var(--surface-alt));
  box-shadow: var(--shadow-lg);
}
dialog::backdrop {
  background: rgba(3,5,13,.7);
  backdrop-filter: blur(6px);
}
.dialog-card {
  position: relative;
  padding: 24px;
}
.dialog-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border: 2px solid #d9e8fb;
  border-radius: 12px;
  color: var(--muted);
  background: white;
  cursor: pointer;
}
code {
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(255,255,255,.8);
}
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 40px));
  padding: 13px 16px;
  border: 2px solid rgba(255,255,255,.32);
  border-radius: 14px;
  background: #13396d;
  color: white;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 680px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
  .question-card {
    min-height: 520px;
  }
  .game-header {
    flex-wrap: wrap;
  }
  .score-chip,
  .opponent-badge {
    flex: 1 1 calc(50% - 6px);
  }
  .score-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
