:root {
  --bg: #0a1633;
  --bg-2: #10224d;
  --tile: #1d4fb8;
  --tile-2: #153c91;
  --tile-hidden: #0f2a66;
  --gold: #f6c544;
  --gold-dim: #b8902a;
  --text: #f3f6ff;
  --muted: #9fb0d6;
  --red: #e5383b;
  --missed: #2a3558;
  --radius: 10px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-2), var(--bg) 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; touch-action: manipulation; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* local test mode */
.dev-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; margin: 0 -4px;
  border: 1px dashed #3a4f8c; border-radius: var(--radius);
  background: rgba(10, 22, 51, 0.6);
}
.dev-label { flex: none; padding: 0 4px; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.dev-bar button, .dev-bar .dev-arrow {
  flex: none; min-height: 38px; padding: 0 12px;
  border: 1px solid #2b3f78; border-radius: 8px;
  background: transparent; color: var(--text); font-weight: 700; cursor: pointer;
}
.dev-bar .dev-arrow { width: 38px; padding: 0; font-size: 1.3rem; line-height: 1; display: grid; place-items: center; text-decoration: none; }
.dev-bar .dev-pick {
  flex: 1; min-width: 0; text-align: left; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: #0b1a40;
}
.dev-bar .dev-pick .muted { color: var(--muted); font-weight: 400; }
.dev-bar button:disabled { opacity: 0.35; cursor: default; }
@media (hover: hover) { .dev-bar button:not(:disabled):hover, .dev-bar .dev-arrow:hover { border-color: var(--gold-dim); } }

/* test-mode board picker */
.picker { width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.picker .modal-head { align-items: center; }
.picker input[type="search"] {
  flex: 1; min-width: 0;
  font-size: 16px; padding: 10px 12px;
  border-radius: 8px; border: 2px solid #2b3f78;
  background: #0b1a40; color: var(--text); outline: none;
}
.picker input[type="search"]:focus { border-color: var(--gold-dim); }
.picker-grid { min-height: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; overflow-y: auto; }
.pick {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  padding: 10px 12px; min-height: 74px;
  border: 1px solid #22356b; border-radius: 8px;
  background: #0b1a40; color: var(--text); cursor: pointer;
}
@media (hover: hover) { .pick:hover { border-color: var(--gold-dim); } }
.pick:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.pick.current { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.pick-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.pick-q { font-weight: 600; font-size: 0.92rem; line-height: 1.3; }
.pick-status.done { color: #8fe3a5; }
.pick-status.started { color: var(--gold); }
.picker-empty { margin: 0; color: var(--muted); }

/* header */
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.top h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.02em; color: var(--gold); font-weight: 800; text-transform: uppercase; }
.meta { display: flex; gap: 10px; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

/* question */
.question-card {
  background: linear-gradient(180deg, #13306f, #0e2457);
  border: 2px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 0 0 4px rgba(246, 197, 68, 0.08), 0 10px 30px rgba(0, 0, 0, 0.35);
}
.question { margin: 0; font-size: clamp(1.15rem, 3.6vw, 1.5rem); font-weight: 700; line-height: 1.3; text-align: center; text-wrap: balance; }

/* board */
.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-flow: column;
  gap: 8px;
  padding: 10px;
  border-radius: calc(var(--radius) + 4px);
  background: #071030;
  border: 2px solid #1a2c5c;
}
@media (max-width: 520px) { .board { grid-template-columns: 1fr; grid-auto-flow: row; } }

.slot { perspective: 800px; height: 54px; }
.slot-inner {
  position: relative;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 450ms var(--ease-out);
}
.slot.revealed .slot-inner { transform: rotateX(-180deg); }

.face {
  position: absolute; inset: 0;
  display: flex; align-items: center;
  border-radius: 6px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.front {
  justify-content: center;
  background: linear-gradient(180deg, var(--tile-hidden), #0b2154);
  border: 1px solid #23408a;
}
.face.front .num {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: #0a1a45; border: 2px solid var(--gold-dim);
  color: var(--gold); font-weight: 800; font-size: 1.05rem;
}
.face.back {
  transform: rotateX(180deg);
  justify-content: space-between;
  padding: 0 0 0 14px;
  background: linear-gradient(180deg, var(--tile), var(--tile-2));
  border: 1px solid #3e6fd8;
  overflow: hidden;
}
.slot.missed .face.back { background: var(--missed); border-color: #3a4775; color: var(--muted); }
.face.back .answer { font-weight: 800; text-transform: uppercase; font-size: 0.98rem; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.face.back .pts {
  align-self: stretch; min-width: 54px;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.25);
  font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums;
}
.slot.missed .face.back .pts { background: rgba(0, 0, 0, 0.15); }

.source { margin: -8px 0 0; color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.source a { color: var(--text); text-underline-offset: 2px; }

/* score + strikes */
.status { display: flex; align-items: center; justify-content: space-between; }
.score { display: flex; align-items: baseline; gap: 8px; }
.score-label { color: var(--muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.06em; }
.score-value { font-size: 1.8rem; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.strikes { display: flex; gap: 6px; }
.strike {
  width: 38px; height: 38px; border-radius: 6px;
  display: grid; place-items: center;
  border: 2px solid #2b3a68; color: #2b3a68;
  font-weight: 900; font-size: 1.4rem; line-height: 1;
}
.strike.on { border-color: var(--red); color: #fff; background: var(--red); animation: strike-in 220ms var(--ease-out); }
@keyframes strike-in { from { transform: scale(0.6); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

/* forms */
.guess-form { display: flex; gap: 8px; }
.guess-form input {
  flex: 1; min-width: 0;
  font-size: 16px; /* no zoom on iOS */
  padding: 14px 14px;
  border-radius: var(--radius);
  border: 2px solid #2b3f78;
  background: #0b1a40;
  color: var(--text);
  outline: none;
}
.guess-form input:focus { border-color: var(--gold-dim); }
.guess-form input:disabled { opacity: 0.5; }
.guess-form button, .result-actions button {
  padding: 0 20px; min-height: 50px;
  border: 0; border-radius: var(--radius);
  background: var(--gold); color: #1a1300;
  font-weight: 800; cursor: pointer;
  transition: transform 120ms ease-out, filter 120ms ease-out;
}
.guess-form button:active, .result-actions button:active { transform: scale(0.97); }
@media (hover: hover) { .guess-form button:hover, .result-actions button:hover { filter: brightness(1.08); } }
.guess-form button:disabled { opacity: 0.5; cursor: default; }

.feedback { margin: -6px 0 0; min-height: 1.3em; color: var(--muted); font-size: 0.95rem; }
.feedback.bad { color: #ff8a8c; }
.feedback.good { color: #8fe3a5; }

/* panels */
.panel {
  background: #0d1d47;
  border: 1px solid #22356b;
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  animation: panel-in 300ms var(--ease-out);
}
@keyframes panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.result-row { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.stat-value { display: block; font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.result-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.next { color: var(--muted); font-size: 0.95rem; }
#countdown { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 700; }

.result-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.result-actions button.secondary { background: transparent; color: var(--text); border: 2px solid #2b3f78; }

/* survey modal */
.modal {
  width: min(480px, calc(100vw - 32px));
  margin: auto;
  padding: 18px;
  border: 1px solid #2b3f78;
  border-radius: calc(var(--radius) + 4px);
  background: #0d1d47;
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  flex-direction: column;
  gap: 14px;
}
.modal[open] { display: flex; animation: modal-in 220ms var(--ease-out); }
.modal::backdrop { background: rgba(3, 8, 24, 0.7); animation: backdrop-in 220ms ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-close {
  flex: none; width: 36px; height: 36px; margin: -6px -6px 0 0;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 1.1rem; cursor: pointer;
}
@media (hover: hover) { .modal-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); } }
.modal .feedback { margin: 0; min-height: 0; }
.modal .feedback:empty { display: none; }

.survey-label { margin: 0; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; line-height: 1.4; }
.survey-question { margin: 0; font-size: 1.25rem; font-weight: 700; line-height: 1.3; }

@media (prefers-reduced-motion: reduce) {
  .slot-inner { transition: none; }
  .strike.on, .panel, .modal[open], .modal::backdrop { animation: none; }
}
