:root {
  --bg: #020617;
  --panel-top-a: #0f766e;
  --panel-top-b: #115e59;
  --panel-bottom-a: #1d4ed8;
  --panel-bottom-b: #1e3a8a;
  --divider-bg: #0b1220;
  --text: #f8fafc;
  --muted: #cbd5e1;
  --btn-bg: rgba(255, 255, 255, 0.13);
  --btn-border: rgba(255, 255, 255, 0.4);
  --btn-wrong: #ef4444;
  --correct-reveal-ms: 750ms;
  --winner: rgba(34, 197, 94, 0.45);
  --loser: rgba(239, 68, 68, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  background: radial-gradient(circle at 20% 0%, #1e293b 0%, var(--bg) 62%);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
}

.panel {
  position: relative;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.panel-top {
  background: linear-gradient(140deg, var(--panel-top-a), var(--panel-top-b));
}

.panel-bottom {
  background: linear-gradient(220deg, var(--panel-bottom-a), var(--panel-bottom-b));
}

.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.18), transparent 55%);
}

.panel-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 0.9fr) minmax(0, 1.25fr) auto;
  gap: 8px;
}

.rotated {
  transform: rotate(180deg);
  transform-origin: center;
}

.score-row {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.score {
  font-size: clamp(1rem, 2.9vw, 1.25rem);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.prompt-frame {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
  display: grid;
  place-items: center;
  min-height: 0;
  max-height: clamp(54px, 16vh, 126px);
  padding: clamp(6px, 1.2vh, 10px);
}

.prompt-text {
  margin: 0;
  color: #f8fafc;
  text-align: center;
  font-size: clamp(1rem, 3.2vw, 1.5rem);
  font-weight: 800;
  line-height: 1.15;
  text-wrap: balance;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  min-height: 0;
  align-content: stretch;
  gap: 8px;
}

.answer-btn {
  appearance: none;
  border: 1px solid var(--btn-border);
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--text);
  min-height: clamp(30px, 5.8vh, 52px);
  height: 100%;
  padding: clamp(4px, 0.9vh, 8px) 8px;
  font-size: clamp(0.78rem, 2.2vw, 0.95rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-align: center;
  line-height: 1.1;
}

.answer-btn:disabled {
  opacity: 0.6;
}

.answer-btn.wrong {
  animation: wrongFlash 0.35s ease-out;
}

.answer-btn.correct-reveal {
  animation: correctReveal var(--correct-reveal-ms) ease-in-out;
  border-color: rgba(134, 239, 172, 0.95);
  color: #dcfce7;
  opacity: 1;
}

.answer-btn.correct-reveal:disabled {
  opacity: 1;
}

.lock-indicator {
  margin: 0;
  min-height: 0;
  font-size: 0.86rem;
  line-height: 1.05;
  color: #fef08a;
  font-weight: 700;
}

.divider {
  border-top: 2px solid rgba(255, 255, 255, 0.3);
  border-bottom: 2px solid rgba(255, 255, 255, 0.3);
  background: linear-gradient(90deg, #0f172a, var(--divider-bg), #0f172a);
  display: grid;
  gap: 6px;
  align-items: center;
  justify-items: center;
  padding: 6px 10px;
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.target-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--muted);
}

#targetScore {
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  font-weight: 700;
  height: 32px;
  min-width: 62px;
  text-align: center;
}

.control-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  background: rgba(248, 250, 252, 0.14);
  color: var(--text);
  min-height: 32px;
  padding: 4px 10px;
  font-weight: 700;
}

.control-link {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  background: rgba(248, 250, 252, 0.14);
  color: var(--text);
  min-height: 32px;
  padding: 6px 10px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.status-text {
  margin: 0;
  color: #e2e8f0;
  font-size: clamp(0.82rem, 2.4vw, 0.95rem);
  letter-spacing: 0.01em;
}

.round-result-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  width: min(92%, 330px);
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(2px);
  text-align: center;
  color: #e2e8f0;
  font-size: clamp(0.84rem, 2.45vw, 0.98rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: pre-line;
  line-height: 1.15;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.96);
  transition: opacity 120ms ease-out, transform 160ms ease-out;
}

.round-result-banner.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.round-result-banner.is-win {
  border-color: rgba(74, 222, 128, 0.9);
  background: rgba(20, 83, 45, 0.72);
  color: #dcfce7;
}

.round-result-banner.is-loss {
  border-color: rgba(248, 113, 113, 0.9);
  background: rgba(127, 29, 29, 0.72);
  color: #fee2e2;
}

.panel.winner {
  box-shadow: inset 0 0 0 200vmax var(--winner);
}

.panel.loser {
  box-shadow: inset 0 0 0 200vmax var(--loser);
}

.panel.locked .answers {
  opacity: 0.75;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 10;
}

.overlay-card {
  width: min(88vw, 360px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 16px;
  background: linear-gradient(170deg, #0f172a, #1e293b);
  text-align: center;
  padding: 18px 16px;
}

.overlay-card h2 {
  margin-top: 0;
  margin-bottom: 10px;
}

.overlay-card p {
  margin-top: 0;
  margin-bottom: 16px;
  color: var(--muted);
}

.play-again {
  border: 0;
  border-radius: 12px;
  background: linear-gradient(120deg, #f59e0b, #f97316);
  color: white;
  min-height: 44px;
  min-width: 160px;
  font-size: 1rem;
  font-weight: 800;
}

.hidden {
  display: none;
}

@keyframes wrongFlash {
  0% {
    background: rgba(239, 68, 68, 0.15);
  }
  60% {
    background: var(--btn-wrong);
  }
  100% {
    background: var(--btn-bg);
  }
}

@keyframes correctReveal {
  0% {
    background: var(--btn-bg);
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
    transform: scale(1);
  }
  45% {
    background: rgba(34, 197, 94, 0.45);
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.65);
    transform: scale(1.03);
  }
  100% {
    background: var(--btn-bg);
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
    transform: scale(1);
  }
}

@media (max-height: 760px) {
  .panel-inner {
    grid-template-rows: auto minmax(0, 0.8fr) minmax(0, 1.35fr) auto;
    gap: 6px;
  }

  .prompt-frame {
    max-height: clamp(44px, 13vh, 90px);
  }

  .answer-btn {
    min-height: clamp(26px, 5.2vh, 40px);
    font-size: 0.76rem;
  }

  .prompt-text {
    font-size: clamp(0.9rem, 2.7vw, 1.15rem);
  }
}

@media (max-height: 640px) {
  .panel {
    padding: 6px 8px;
  }

  .panel-inner {
    gap: 5px;
    grid-template-rows: auto minmax(0, 0.7fr) minmax(0, 1.5fr) auto;
  }

  .prompt-frame {
    max-height: clamp(38px, 10vh, 64px);
    border-radius: 9px;
  }

  .answer-btn {
    min-height: clamp(24px, 4.8vh, 34px);
    padding: 4px 6px;
    font-size: 0.72rem;
  }

  .lock-indicator {
    font-size: 0.72rem;
  }

  .round-result-banner {
    width: min(94%, 280px);
    font-size: 0.74rem;
    padding: 6px 10px;
  }
}
