/* Best Quiz App — mobile-first, portrait phone. */
:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent2: #7c3aed;
  --ok: #16a34a;
  --bad: #dc2626;
  --gold: #f59e0b;
  --radius: 16px;
  --tap: 48px;
  --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(160deg, var(--bg), var(--bg2));
  color: #e2e8f0;
  font: 16px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 var(--pad);
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + 72px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 2px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(160deg, var(--bg), transparent);
}
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar .me-wrap { display: flex; align-items: center; gap: 8px; }
.topbar .me { font-size: 13px; color: var(--muted); }
.topbar .me b { color: var(--gold); }
.topbar .logout-btn {
  width: 34px; height: 34px; margin: 0; padding: 0; border-radius: 8px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
  color: #e2e8f0; font-size: 16px; line-height: 1; cursor: pointer;
}
.topbar .logout-btn:active { transform: scale(.95); }

main { flex: 1; padding-bottom: 8px; }

/* cards / inputs */
.card {
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 18px;
  margin: 8px 0;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin: 12px 0 6px;
}
/* Ensure the `hidden` attribute always wins over `label{display:block}` etc.
   so login/register mode can show/hide the full_name + confirm fields. */
[hidden] { display: none !important; }
input, select {
  width: 100%;
  height: var(--tap);
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 0 14px;
  font-size: 16px;
  background: #f8fafc;
  color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

button {
  width: 100%;
  height: var(--tap);
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 16px;
}
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
}
button.ghost {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
button:active { transform: translateY(1px); }

h1 { margin: 0 0 8px; font-size: 24px; }
h2 { margin: 8px 0; font-size: 18px; }

.auth .switch { text-align: center; margin-top: 14px; font-size: 14px; color: var(--muted); }
.auth .switch a { color: var(--accent); font-weight: 700; text-decoration: none; }
.auth .links { text-align: center; margin-top: 10px; font-size: 14px; }
.auth .links a { color: var(--accent); font-weight: 700; text-decoration: none; }
.muted { color: var(--muted); font-size: 14px; margin: 4px 0 14px; }
.ok-box { background: #ecfdf5; color: #047857; border-radius: 12px; padding: 12px; margin-top: 12px; text-align: center; font-size: 14px; }
input:disabled { background: #f1f5f9; color: var(--muted); opacity: .8; }
.err { color: var(--bad); text-align: center; margin-top: 8px; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 10px; }
.stat {
  background: #f1f5f9; border-radius: 12px; padding: 12px;
}
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 20px; font-weight: 800; color: var(--ink); }
.stat .v.gold { color: var(--gold); }

/* tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 9;
  max-width: 480px; margin: 0 auto;
  display: flex; background: rgba(15,23,42,.96);
  padding: 6px 6px calc(6px + var(--safe-bottom));
  border-top: 1px solid rgba(255,255,255,.08);
}
.tabbar button {
  flex: 1; height: 44px; margin: 0 4px;
  background: transparent; color: #94a3b8; font-weight: 700; font-size: 13px;
  border-radius: 10px;
}
.tabbar button.active { background: var(--accent); color: #fff; }

/* game */
.game { background: var(--card); color: var(--ink); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.hud { display: flex; justify-content: space-between; align-items: center; }
.lives { font-size: 18px; letter-spacing: 2px; }
.progress { font-size: 13px; font-weight: 700; color: var(--accent); }
.streak-line { font-size: 13px; color: var(--muted); margin: 2px 0 8px; min-height: 16px; }
.score { font-weight: 800; font-size: 20px; color: var(--gold); }
.timer { height: 8px; background: #e2e8f0; border-radius: 8px; overflow: hidden; margin: 12px 0 6px; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--ok), var(--gold), var(--bad)); transition: width .1s linear; }
.qmeta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.pts { font-weight: 700; color: var(--accent); }
.question { font-size: 18px; line-height: 1.45; margin: 6px 0 14px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 12px 14px;
  background: #f1f5f9; border: 2px solid #e2e8f0; border-radius: 12px;
  font-size: 15px; text-align: left; color: var(--ink); font-weight: 600;
  margin: 0; width: 100%;
}
.option .key { font-weight: 800; color: var(--accent); flex: 0 0 22px; }
.option:active { transform: scale(.99); }
.option.correct { background: #dcfce7; border-color: var(--ok); }
.option.wrong  { background: #fee2e2; border-color: var(--bad); }
.option.disabled { opacity: .6; }
.option.faded { opacity: .5; }

.feedback { margin-top: 14px; padding: 12px; border-radius: 12px; font-size: 14px; }
.feedback.good { background: #dcfce7; color: #166534; }
.feedback.bad  { background: #fee2e2; color: #991b1b; }
.feedback .ans { font-weight: 800; display: block; margin-top: 4px; }
.feedback .ref { display: block; font-style: italic; margin-top: 4px; }
.feedback .gain { float: right; font-weight: 800; }
.feedback .next-btn { margin-top: 14px; }

/* result */
.result { text-align: center; }
.result-score { font-size: 44px; font-weight: 900; color: var(--gold); margin: 4px 0; }
.result-stats { color: var(--muted); margin-bottom: 8px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
.badge {
  background: #f1f5f9; border-radius: 12px; padding: 8px 12px;
  font-size: 12px; font-weight: 700; color: var(--ink);
}
.badge.new { background: var(--gold); color: #1e1b0f; }

/* leaderboard */
.myrank { background: var(--accent); color: #fff; border-radius: 12px; padding: 12px; margin-bottom: 12px; text-align: center; font-weight: 700; }
.board { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.board li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-radius: 12px; background: #f1f5f9; margin-bottom: 8px;
  counter-increment: r; font-weight: 600;
}
.board li::before { content: counter(r) "."; color: var(--muted); width: 28px; font-weight: 800; }
.board li.me { background: #ddd6fe; }
.board li .pts { color: var(--gold); }

/* achievements grid */
.badges-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.ach { background: #f1f5f9; border-radius: 14px; padding: 14px; text-align: center; }
.ach .emoji { font-size: 30px; display: block; filter: grayscale(1); opacity: .4; }
.ach.earned { background: #ecfccb; }
.ach.earned .emoji { filter: none; opacity: 1; }
.ach .name { font-weight: 800; font-size: 14px; margin-top: 4px; }
.ach .desc { font-size: 11px; color: var(--muted); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + var(--safe-bottom)); transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 50; max-width: 90%; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* report button + modal */
.report-btn {
  width: 100%; margin-top: 14px; height: 40px; background: transparent;
  color: var(--bad); border: 1px solid #fecaca; font-size: 13px; font-weight: 700;
  border-radius: 10px;
}
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15,23,42,.6); display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff; color: var(--ink); border-radius: 16px; padding: 18px;
  width: 100%; max-width: 440px; max-height: 90vh; overflow: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.4);
}
.modal-card h3 { margin: 0 0 8px; font-size: 18px; }
.rp-details {
  background: #f1f5f9; border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.5;
  margin-bottom: 10px;
}
.rp-q { font-weight: 700; margin: 4px 0; }
textarea { width: 100%; min-height: 90px; border: 2px solid #e2e8f0; border-radius: 10px; padding: 10px; font: inherit; resize: vertical; }
textarea:focus { outline: none; border-color: var(--accent); }
.modal-card button { margin-top: 10px; }

/* bigger screens: keep phone width, center */
@media (min-width: 600px) { #app { box-shadow: 0 0 60px rgba(0,0,0,.4); min-height: 100vh; border-radius: 0; } }