:root {
  --bg: #12233a;
  --bg-2: #0d1b2a;
  --paper: #f7f3e8;
  --ink: #1a1a1a;
  --card: #1b3350;
  --card-2: #21406a;
  --line: rgba(255, 255, 255, .1);
  --muted: #9db4d0;
  --cream: #f4ead2;
  --red: #d84c3a;
  --green: #37d67a;
  --gold: #ffd23f;
  --lake: #4cc3ff;
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--cream);
  background:
    radial-gradient(900px 500px at 50% -10%, #1c3f66 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.hidden { display: none !important; }

/* ---------- masthead ---------- */
header { text-align: center; padding: 26px 16px 8px; }
.kicker {
  font-family: system-ui, sans-serif; font-weight: 800; letter-spacing: 3px;
  font-size: 11px; color: var(--gold);
}
h1 {
  margin: 6px 0 4px; font-size: clamp(30px, 9vw, 52px); font-weight: 900;
  letter-spacing: 1px; line-height: .95; color: var(--cream);
  font-family: Georgia, serif; text-transform: uppercase;
}
h1 span { color: var(--gold); }
.rule {
  width: min(560px, 90%); height: 3px; margin: 10px auto 0;
  background: var(--cream); position: relative; opacity: .8;
}
.rule::after {
  content: ""; position: absolute; left: 0; right: 0; top: 5px; height: 1px; background: var(--cream); opacity: .6;
}

/* ---------- layout ---------- */
main { flex: 1; width: 100%; max-width: 620px; margin: 0 auto; padding: 14px 16px 30px; }
.screen { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- intro ---------- */
.paper {
  background: var(--paper); color: var(--ink);
  border-radius: 6px; padding: 22px 20px; box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
  border: 1px solid #e5dcc4;
}
.lede { font-size: 20px; margin: 0 0 14px; font-weight: 700; }
.lede em { color: var(--red); font-style: italic; }
.rules { list-style: none; margin: 0; padding: 0; font-family: system-ui, sans-serif; }
.rules li { font-size: 14.5px; line-height: 1.5; padding: 6px 0; border-top: 1px dashed #d9cfb4; color: #333; }
.rules li:first-child { border-top: none; }
.rules strong { color: #111; }
.load-err { text-align: center; color: var(--muted); font-family: system-ui, sans-serif; padding: 30px 10px; }

.btn-primary {
  display: block; width: 100%; margin: 18px auto 0; padding: 15px;
  font-family: system-ui, sans-serif; font-weight: 800; font-size: 17px; letter-spacing: .3px;
  color: #10233a; background: linear-gradient(180deg, var(--gold), #f2b21e);
  border: none; border-radius: 12px; cursor: pointer;
  box-shadow: 0 5px 0 #b8860b; transition: transform .08s ease, box-shadow .08s ease;
}
.btn-primary:active { transform: translateY(4px); box-shadow: 0 1px 0 #b8860b; }

/* ---------- game ---------- */
.timerbar { height: 8px; background: rgba(255, 255, 255, .1); border-radius: 999px; overflow: hidden; }
#timerFill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), var(--lake)); transition: width .1s linear; }
#timerFill.hurry { background: linear-gradient(90deg, #ff8a3d, var(--red)); }
.qmeta {
  display: flex; justify-content: space-between; align-items: center;
  font-family: system-ui, sans-serif; font-weight: 800; font-size: 13px;
  color: var(--muted); margin: 10px 2px;
}
.clock-wrap { color: var(--gold); font-variant-numeric: tabular-nums; }
.qcard {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: 14px; padding: 20px 18px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .35);
}
#qText { font-size: 19px; line-height: 1.35; margin: 0 0 16px; font-weight: 700; }
#choices { display: grid; gap: 10px; }
.choice {
  font-family: system-ui, sans-serif; font-size: 15.5px; text-align: left;
  padding: 14px 16px; border-radius: 11px; cursor: pointer;
  background: #16304d; color: var(--cream); border: 1px solid var(--line);
  transition: background .12s ease, transform .06s ease;
}
.choice:hover:not(:disabled) { background: #1d3d61; }
.choice:active:not(:disabled) { transform: scale(.99); }
.choice:disabled { cursor: default; }
.choice.correct { background: #14663c; border-color: var(--green); color: #eafff2; }
.choice.wrong { background: #6a231b; border-color: var(--red); color: #ffe9e6; }
.choice.dim { opacity: .45; }

.reveal { margin-top: 16px; text-align: center; font-family: system-ui, sans-serif; }
#revealHead { font-size: 18px; font-weight: 800; margin: 0 0 4px; }
#revealHead.good { color: var(--green); }
#revealHead.bad { color: #ff8a7a; }
#revealAns { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

/* ---------- results ---------- */
#verdict { text-align: center; font-size: clamp(20px, 5.5vw, 27px); margin: 6px 0 4px; }
.scoreline { text-align: center; }
#finalScore { font-family: system-ui, sans-serif; font-size: 60px; font-weight: 900; color: var(--gold); }
.scoreline .pts { font-family: system-ui, sans-serif; color: var(--muted); font-weight: 700; margin-left: 6px; }
.score-detail { text-align: center; color: var(--muted); font-family: system-ui, sans-serif; font-size: 14px; }
.squares { text-align: center; font-size: 28px; letter-spacing: 4px; margin: 10px 0 4px; }

.share-row { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 14px; }
.share-done { color: var(--green); font-family: system-ui, sans-serif; font-size: 13px; }
.next-note { text-align: center; color: var(--muted); font-family: system-ui, sans-serif; font-size: 13px; margin-top: 12px; }

/* ---------- leaderboard ---------- */
.lb {
  margin-top: 22px; background: rgba(0, 0, 0, .2); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px; font-family: system-ui, sans-serif;
}
.lb-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.chip {
  font-family: system-ui, sans-serif; font-weight: 700; font-size: 13px;
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  background: #16304d; color: var(--cream); border: 1px solid var(--line);
}
.chip.sel { background: var(--gold); color: #10233a; border-color: var(--gold); }
.lb-status { text-align: center; color: var(--muted); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
#lbList { list-style: none; margin: 0; padding: 0; }
#lbList li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; font-size: 15px; }
#lbList li:nth-child(odd) { background: rgba(255, 255, 255, .03); }
#lbList li.me { background: rgba(255, 210, 63, .16); font-weight: 800; }
#lbList .rank { width: 34px; color: var(--muted); font-weight: 700; }
#lbList .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lbList .sc { font-weight: 800; color: var(--gold); }
.lb-form { display: flex; gap: 8px; margin-top: 10px; }
.lb-form input {
  flex: 1; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: #0d1b2a; color: var(--cream); font-size: 15px; font-family: system-ui, sans-serif;
}
.lb-rename { display: block; margin: 10px auto 0; }

.cta {
  display: block; text-align: center; margin: 22px auto 0; text-decoration: none;
  font-family: system-ui, sans-serif; font-weight: 800; font-size: 15px;
  color: #10233a; background: linear-gradient(90deg, var(--gold), #ff8a3d);
  padding: 13px 18px; border-radius: 12px; box-shadow: 0 5px 16px rgba(255, 140, 60, .3);
}

footer {
  text-align: center; padding: 20px 16px 30px; color: var(--muted);
  font-family: system-ui, sans-serif; font-size: 13px;
}
footer a { color: var(--lake); text-decoration: none; }

@media (prefers-reduced-motion: reduce) { .screen { animation: none; } .btn-primary { transition: none; } }
