:root {
  --bg: #0f1226;
  --bg2: #1a1f3d;
  --card: #20264a;
  --accent: #ffd166;
  --accent2: #06d6a0;
  --wrong: #ef476f;
  --text: #f0f2ff;
  --muted: #9aa0c7;
  --border: #2e3566;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at top, var(--bg2), var(--bg));
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 24px 16px;
}

/* Decorative world-of-money backdrop — kept very faint and non-interactive
   so it never distracts from the quiz. */
.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.bg span {
  position: absolute;
  user-select: none;
  line-height: 1;
}
.bg img {
  position: absolute;
  height: auto;
  border-radius: 2px;
}

.app { position: relative; z-index: 1; width: 100%; max-width: 640px; }

header { text-align: center; margin-bottom: 24px; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.coin {
  width: 46px;
  height: 46px;
  display: inline-block;
  filter: drop-shadow(0 4px 10px rgba(255, 184, 0, .35));
  animation: coin-float 4s ease-in-out infinite;
}
@keyframes coin-float {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-5px) rotate(4deg); }
}
.wordmark {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -1.5px;
  background: linear-gradient(95deg, var(--accent) 0%, var(--accent2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--muted); margin-top: 8px; }
.center-link { display: block; margin: 18px auto 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}

.hidden { display: none !important; }

h2 { font-size: 1.3rem; margin-bottom: 20px; text-align: center; }

/* Mode buttons */
.mode-buttons { display: flex; flex-direction: column; gap: 16px; }
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform .12s, border-color .12s;
}
@media (hover: hover) {
  .mode-btn:hover { border-color: var(--accent); transform: translateY(-2px); }
}
.mode-icon { width: 52px; height: 52px; line-height: 0; margin-bottom: 2px; }
.mode-icon svg { display: block; filter: drop-shadow(0 3px 6px rgba(0,0,0,.3)); }
.mode-title { font-size: 1.15rem; font-weight: 700; }
.mode-desc { color: var(--muted); font-size: .92rem; }
.mode-best { color: var(--accent); font-size: .85rem; font-weight: 700; margin-top: 4px; }

/* Scorebar */
.scorebar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px 10px;
  font-size: .95rem;
  color: var(--muted);
  margin-bottom: 22px;
}
.stat strong { color: var(--text); font-size: 1.05rem; }

/* "New High Score!" celebration on the Score stat */
.score-stat { display: inline-block; transform-origin: left center; white-space: nowrap; }
.score-stat.record #score-label { color: var(--accent); font-weight: 800; text-shadow: 0 0 10px rgba(255,209,102,.85); }
.score-stat.record strong { color: var(--accent); }
.score-stat.celebrate { animation: highscorePop .75s ease; }
@keyframes highscorePop {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.32); }
  45%  { transform: scale(1.12) rotate(-3deg); }
  65%  { transform: scale(1.24) rotate(3deg); }
  100% { transform: scale(1); }
}
/* Streak glow once the player beats their personal-best streak */
.stat.glow strong { color: var(--accent); animation: streakGlow 1.1s ease-in-out infinite; }
@keyframes streakGlow {
  0%, 100% { text-shadow: 0 0 4px rgba(255,209,102,.5); }
  50% { text-shadow: 0 0 12px rgba(255,209,102,1), 0 0 22px rgba(255,209,102,.7); }
}
.lives { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; }

/* Custom SVG hearts */
.heart { position: relative; width: 21px; height: 21px; display: inline-block; }
.heart svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.h-outline path { fill: none; stroke: #7a2e44; stroke-width: 2.5; }
.h-outline { opacity: 0; transition: opacity .3s; }
.h-half path { fill: url(#heartGrad); }
.h-half { filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
.h-left { clip-path: inset(0 50% 0 0); }
.h-right { clip-path: inset(0 0 0 50%); }

.heart.empty .h-outline { opacity: .6; }
.heart.empty .h-half { opacity: 0; }

/* Heartbreak: pop + glow, then the two halves shatter apart. */
.heart.breaking { animation: heart-pop .55s ease; }
.heart.breaking .h-outline { opacity: .6; }
.heart.breaking .h-left { animation: shard-l .55s ease-in forwards; }
.heart.breaking .h-right { animation: shard-r .55s ease-in forwards; }

@keyframes heart-pop {
  0%   { transform: scale(1); filter: none; }
  25%  { transform: scale(1.35); filter: drop-shadow(0 0 6px rgba(255,77,109,.9)); }
  45%  { transform: scale(1.1) rotate(-6deg); }
  60%  { transform: scale(1.15) rotate(6deg); }
  100% { transform: scale(1); filter: none; }
}
@keyframes shard-l {
  0%, 28% { transform: translate(0,0) rotate(0); opacity: 1; }
  100%    { transform: translate(-7px, 11px) rotate(-42deg); opacity: 0; }
}
@keyframes shard-r {
  0%, 28% { transform: translate(0,0) rotate(0); opacity: 1; }
  100%    { transform: translate(7px, 11px) rotate(42deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .heart.breaking, .heart.breaking .h-left, .heart.breaking .h-right { animation: none; }
}
.link-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; text-decoration: underline; font-size: .9rem;
}
@media (hover: hover) {
  .link-btn:hover { color: var(--wrong); }
}

/* Timer: a left→right gradient from red (1 pt, slow) to green (3 pts, fast).
   A "spent time" overlay eats from the right (green side) as the clock runs,
   so the live edge shows your current points tier. */
.timer {
  position: relative;
  height: 8px;
  margin-top: 22px;
  border-radius: 999px;
  overflow: hidden;
}
.timer-track {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    #ef476f 0%, #ff6b6b 16%, #ff9f45 40%, #ffd166 62%, #46e6a8 100%);
}
.timer-spent {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 0%;
  background: rgba(15, 18, 38, .82);
}

/* Prompt */
.prompt { text-align: center; margin-bottom: 24px; }
.prompt-label {
  display: inline-block;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 8px;
}
.prompt h2 { font-size: 1.9rem; margin: 0; }
.prompt-flag {
  height: 1.5rem;
  width: auto;
  border-radius: 4px;
  vertical-align: -0.18em;
  margin-right: 12px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.3);
}

/* Helpers (50:50) */
.helpers { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.help-btn {
  background: rgba(6, 214, 160, .12);
  border: 2px solid var(--accent2);
  color: var(--accent2);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter .12s, opacity .12s;
}
.help-btn:disabled { opacity: .4; cursor: default; border-color: var(--border); color: var(--muted); background: none; }

/* Choices — 2x2 grid */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice.removed { opacity: .22; }
.choice {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 62px;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: border-color .12s, background .12s;
}
@media (max-width: 380px) { .choice { font-size: .92rem; min-height: 58px; } }
@media (hover: hover) {
  .choice:hover:not(:disabled) { border-color: var(--accent); }
}
.choice:disabled { cursor: default; }
.choice.correct {
  border-color: var(--accent2);
  background: rgba(6,214,160,.15);
  animation: correctPop .4s ease;
}
.choice.wrong { border-color: var(--wrong); background: rgba(239,71,111,.15); }
@keyframes correctPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.05); box-shadow: 0 0 18px rgba(6,214,160,.55); }
  100% { transform: scale(1); }
}

/* Feedback bar — also acts as the "next question" button */
.feedback {
  position: relative;
  overflow: hidden;
  display: none; /* hidden state — JS removes hidden class to show */
  align-items: center;
  margin-top: 20px;
  width: 100%;
  padding: 15px 52px 15px 18px; /* right padding leaves room for the ▶| icon */
  border-radius: 12px;
  border: none;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  background: transparent;
  color: inherit;
  box-sizing: border-box;
}
.feedback:not(.hidden) { display: flex; }
.feedback.right { background: rgba(6,214,160,.15); color: var(--accent2); }
.feedback.nope  { background: rgba(239,71,111,.15); color: var(--wrong); }

/* ▶| skip icon — always present, right-aligned */
.next-skip {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  opacity: .65;
  z-index: 1;
  letter-spacing: -1px;
}

/* Text content of the feedback */
.feedback-text { position: relative; z-index: 1; flex: 1; }

/* Auto-advance fill sweeps left-to-right behind the text */
.next-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  background: rgba(255,255,255,.08);
  pointer-events: none;
}

/* "Click to pause" hint — two bars on the left while auto-advancing */
.next-pause {
  display: none;
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 11px;
  height: 15px;
  z-index: 2;
}
.feedback.advancing .next-pause { display: block; }
.next-pause::before,
.next-pause::after {
  content: "";
  position: absolute;
  top: 0;
  width: 3.5px;
  height: 15px;
  background: currentColor;
  opacity: .55;
  border-radius: 2px;
}
.next-pause::before { left: 0; }
.next-pause::after  { right: 0; }

/* Play again / Back to menu buttons */
.primary-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 16px;
  background: var(--accent);
  color: #1a1f3d;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}
@media (hover: hover) { .primary-btn:hover { filter: brightness(1.05); } }

/* Game over + leaderboards */
.go-summary { text-align: center; color: var(--muted); margin-bottom: 20px; }
.go-summary strong { color: var(--text); }
.go-best { color: var(--muted); font-size: .85rem; }

.name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 22px;
}
.name-label { color: var(--muted); font-size: .9rem; }
.name-input {
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
  padding: 8px 12px;
  width: 200px;
  text-align: center;
}
.name-input:focus { outline: none; border-color: var(--accent); }
.name-hint { color: var(--muted); font-size: .78rem; width: 100%; text-align: center; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.mode-tabs { margin-bottom: 8px; }
.mode-tabs .tab { font-size: .82rem; padding: 8px; }
.tab {
  flex: 1;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  padding: 10px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .12s, color .12s;
}
.tab.active { border-color: var(--accent); color: var(--text); }

.leaderboard { list-style: none; margin: 0 0 8px; padding: 0; }
.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.leaderboard li:nth-child(odd) { background: rgba(255,255,255,.03); }
.leaderboard li.lb-empty {
  justify-content: center;
  color: var(--muted);
  padding: 22px 14px;
  background: none;
}
.leaderboard li.you {
  border-color: var(--accent);
  background: rgba(255, 209, 102, .12);
}
.lb-rank { width: 28px; color: var(--muted); font-weight: 700; text-align: right; }
.lb-flag { width: 24px; display: inline-flex; justify-content: center; flex: 0 0 auto; }
.lb-flag img { width: 22px; height: auto; border-radius: 2px; display: block; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.lb-name { flex: 1; font-weight: 600; }
.lb-name .you-tag { color: var(--accent); font-size: .75rem; margin-left: 6px; }
.lb-value { font-weight: 800; color: var(--accent2); }

footer { text-align: center; margin-top: 20px; color: var(--muted); font-size: .85rem; }
