:root {
  --bg: #f6f3ec;
  --bg-deep: #eee9df;
  --card: #fffdf9;
  --ink: #14202e;
  --muted: #5f6b78;
  --line: #ded7c9;
  --navy: #12355b;
  --navy-2: #1d4a78;
  --accent: #0b5c8a;
  --gold: #b07d24;
  --green: #1c7a52;
  --green-bg: #e6f4ec;
  --red: #a32c28;
  --red-bg: #fbeceb;
  --shadow: 0 1px 2px rgba(20, 32, 46, 0.06), 0 12px 32px -12px rgba(20, 32, 46, 0.22);
  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 760px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 15% -10%, #fffaf0 0%, rgba(255, 250, 240, 0) 60%),
    radial-gradient(900px 600px at 100% 0%, #e8eef6 0%, rgba(232, 238, 246, 0) 55%),
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 40px 20px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen { display: none; animation: rise 0.35s ease both; }
.screen.is-active { display: block; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- hero */
.hero { margin: 8px 0 26px; }

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--gold);
}

h1 {
  font-size: clamp(38px, 7vw, 58px);
  line-height: 1.02;
  letter-spacing: -0.03em;
  margin: 0 0 14px;
  color: var(--navy);
  font-weight: 800;
}

.lede {
  margin: 0;
  max-width: 56ch;
  color: var(--muted);
  font-size: 16.5px;
}

.lede strong { color: var(--ink); }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.start-card label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
}

.row { display: flex; gap: 10px; align-items: stretch; }
.actions { margin: 6px 0 12px; flex-wrap: wrap; }

input[type="text"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus {
  border-color: var(--navy-2);
  box-shadow: 0 0 0 4px rgba(18, 53, 91, 0.12);
}

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px) scale(0.995); }
.btn:focus-visible { outline: 3px solid rgba(11, 92, 138, 0.35); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  color: #fff;
  box-shadow: 0 10px 20px -10px rgba(18, 53, 91, 0.65);
}

.btn-primary:hover { background: linear-gradient(180deg, #23598c, #16406b); }

.btn-ghost {
  background: transparent;
  color: var(--navy);
  border-color: var(--line);
}

.btn-ghost:hover { background: #f1ece2; }

.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
}

.link-btn:hover { text-decoration: underline; }

.hint {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--red);
  font-weight: 600;
}

/* ---------------------------------------------------------------- leaderboard */
.board {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.board li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.board li + li { border-top: 1px solid #f0ebe1; }
.board li:nth-child(1) .rank { color: var(--gold); }
.board li.is-you { background: #eef4fa; box-shadow: inset 0 0 0 1px #cfe0f0; }

.rank {
  font-weight: 800;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.board .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 800; color: var(--navy); }
.board .pts small { font-weight: 600; color: var(--muted); font-size: 11px; margin-left: 3px; }

.board li.board-empty, .board li.board-loading {
  display: block;
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 14px 0;
  border: 0 !important;
}

.muted { color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- rules */
.rules {
  list-style: none;
  padding: 0;
  margin: 26px 0 0;
  display: grid;
  gap: 10px;
}

.rules li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  color: var(--muted);
  font-size: 14.5px;
}

.rules span {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e8e1d3;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
  margin-top: 1px;
}

/* ---------------------------------------------------------------- game */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.hud-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.pill {
  display: inline-block;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #e9e3d6;
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
}

.strikes { display: inline-flex; gap: 5px; }

.strike {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #d8d1c2;
  transition: background 0.2s, transform 0.2s;
}

.strike.lost { background: var(--red); transform: scale(1.12); }

.hud-right { display: flex; align-items: baseline; gap: 6px; }

.score {
  font-size: 30px;
  font-weight: 800;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.score.bump { animation: bump 0.35s ease; }
@keyframes bump {
  40% { transform: scale(1.22); color: var(--green); }
}

.score-label { color: var(--muted); font-size: 13px; font-weight: 700; }

.progress {
  height: 5px;
  background: #e5dfd2;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 22px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--navy));
  border-radius: 999px;
  transition: width 0.35s ease;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.topic {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.counter { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.question {
  font-size: clamp(21px, 3.4vw, 27px);
  line-height: 1.32;
  letter-spacing: -0.015em;
  margin: 0 0 22px;
  color: var(--ink);
  font-weight: 700;
  text-wrap: balance;
}

.options { display: grid; gap: 10px; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.13s, background 0.13s, transform 0.1s, box-shadow 0.13s;
  box-shadow: 0 1px 0 rgba(20, 32, 46, 0.03);
}

.option:hover:not(:disabled) {
  border-color: var(--navy-2);
  background: #fbfaf6;
  box-shadow: 0 6px 18px -12px rgba(18, 53, 91, 0.5);
  transform: translateY(-1px);
}

.option:disabled { cursor: default; }

.option .key {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  background: #f6f2e9;
  margin-top: 1px;
}

.option.is-correct {
  border-color: var(--green);
  background: var(--green-bg);
}
.option.is-correct .key { border-color: var(--green); background: var(--green); color: #fff; }

.option.is-wrong {
  border-color: var(--red);
  background: var(--red-bg);
}
.option.is-wrong .key { border-color: var(--red); background: var(--red); color: #fff; }

.option.is-dim { opacity: 0.55; }

.kbd-hint {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

kbd {
  display: inline-block;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
}

@media (min-width: 900px) and (min-height: 720px) {
  #screen-game.is-active {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 64vh;
  }
}

/* ---------------------------------------------------------------- over */
.over-hero { text-align: center; margin-bottom: 22px; }
.over-hero h1 { margin-bottom: 10px; }
.over-hero .lede { margin: 0 auto; }

.statgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat span {
  display: block;
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat small {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

/* ---------------------------------------------------------------- modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 21, 32, 0.52);
  backdrop-filter: blur(3px);
  animation: fade 0.2s ease both;
}

.modal[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 30px 80px -20px rgba(8, 16, 26, 0.6);
  border-top: 4px solid var(--red);
  animation: slideup 0.28s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  margin-bottom: env(safe-area-inset-bottom, 0);
}

@keyframes slideup {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-kicker {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--red);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
  color: var(--navy);
  letter-spacing: -0.01em;
}

.modal-answer {
  margin: 0 0 10px;
  font-weight: 700;
  font-size: 17px;
  color: var(--green);
}

.modal-explanation {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 15.5px;
}

.modal-card .btn { width: 100%; }

/* ---------------------------------------------------------------- footer */
.foot {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: 18px 20px 26px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 640px) {
  .modal { place-items: end center; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .shell { padding: 26px 16px 12px; }
  .card { padding: 18px; border-radius: 16px; }
  .row { flex-direction: column; }
  .row .btn { width: 100%; }
  .board li { grid-template-columns: 26px 1fr auto; padding: 8px 4px; }
  .option { font-size: 15.5px; padding: 13px 14px; }
  .question { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
