:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --good: #22c55e;
  --bad: #ef4444;
  --gold: #fbbf24;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(160deg, #0b1220, #0f172a 40%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

.app { max-width: 760px; margin: 0 auto; padding: 16px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px 16px; }
.brand { font-size: 20px; font-weight: 700; cursor: pointer; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0 8px; }
main { flex: 1; }

.loader { text-align: center; color: var(--muted); padding: 60px 0; }

.user-box { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.user-box img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.user-box .uname { color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  margin-bottom: 16px;
}
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card h2 { margin: 0 0 14px; font-size: 18px; }
.lead { color: var(--muted); margin: 0 0 18px; line-height: 1.5; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent-2); color: #04222f; border: none;
  padding: 12px 18px; border-radius: 12px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: transform .05s, background .15s; width: 100%;
}
.btn:hover { background: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { width: auto; flex: 1; }

.subject-grid { display: grid; gap: 12px; }
.subject {
  text-align: left; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px; cursor: pointer; color: var(--text);
  display: flex; justify-content: space-between; align-items: center; transition: border-color .15s;
}
.subject:hover { border-color: var(--accent); }
.subject .s-title { font-size: 17px; font-weight: 600; }
.subject .s-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.subject .arrow { font-size: 22px; color: var(--accent); }

/* progress */
.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin-bottom: 6px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s; }
.qcount { color: var(--muted); font-size: 13px; margin-bottom: 16px; display: flex; justify-content: space-between; }

/* quiz header with quit button */
.quiz-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.quiz-head .quiz-subj { flex: 1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quiz-head .quiz-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.quit-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 9px; padding: 5px 10px; font-size: 13px; cursor: pointer; transition: color .12s, border-color .12s;
}
.quit-btn:hover { color: var(--bad); border-color: var(--bad); }

/* modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(2, 6, 18, .7);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 1000;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; max-width: 380px; width: 100%;
}
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 18px; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.danger:hover { background: #dc2626; }

/* per-question timer */
.timer { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin: 14px 0 4px; }
.timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--good), var(--gold) 60%, var(--bad)); }
.timer-num { text-align: right; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; min-height: 18px; }

.qtext { font-size: 18px; font-weight: 600; line-height: 1.5; margin: 6px 0 18px; }

/* instant feedback after answering */
.option:disabled { cursor: default; }
.option.correct { border-color: var(--good); background: #103021; }
.option.wrong { border-color: var(--bad); background: #361618; }

.advance { margin-top: 14px; }
.feedback { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
.feedback.good { background: #103021; color: #86efac; }
.feedback.wrong { background: #361618; color: #fca5a5; }
.feedback.timeout { background: #3a2e10; color: #fcd34d; }

/* "Keyingi" button: depleting auto-advance fill; tap = advance, hold = pause */
.next-countdown {
  position: relative; overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
.next-countdown .cd-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: rgba(255,255,255,.28); }
.next-countdown.paused .cd-fill { background: rgba(255,255,255,.12); }
.next-countdown .cd-text { position: relative; z-index: 1; }
.cd-hint { margin-top: 6px; }

/* confetti overlay */
.confetti-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 9999; }

.options { display: grid; gap: 10px; }
.option {
  text-align: left; background: var(--panel-2); border: 2px solid var(--line);
  border-radius: 12px; padding: 14px 16px; cursor: pointer; color: var(--text);
  font-size: 15px; line-height: 1.45; transition: border-color .12s, background .12s; width: 100%;
}
.option:hover { border-color: var(--accent); }
.option.selected { border-color: var(--accent); background: #1d3344; }
.option .tag { display: inline-block; font-weight: 700; color: var(--accent); margin-right: 10px; }

/* review states */
.option.correct { border-color: var(--good); background: #103021; }
.option.wrong { border-color: var(--bad); background: #361618; }
.option .mark { float: right; font-weight: 700; }

/* result */
.score-big { font-size: 52px; font-weight: 800; text-align: center; margin: 6px 0; }
.score-big.good { color: var(--good); }
.score-big.mid { color: var(--gold); }
.score-big.bad { color: var(--bad); }
.score-sub { text-align: center; color: var(--muted); margin-bottom: 20px; }

.review-q { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.review-q .qn { color: var(--muted); font-size: 13px; }

/* leaderboard */
.lb-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.lb-tab { flex: 1; padding: 10px; text-align: center; border-radius: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.lb-tab.active { color: var(--text); border-color: var(--accent); }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.lb-rank { width: 32px; text-align: center; font-weight: 700; font-size: 16px; }
.lb-rank.top1 { color: var(--gold); } .lb-rank.top2 { color: #cbd5e1; } .lb-rank.top3 { color: #d97706; }
.lb-name { flex: 1; }
.lb-name .lb-sub { color: var(--muted); font-size: 12px; }
.lb-score { font-weight: 700; }
.lb-score .lb-pct { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.lb-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); object-fit: cover; }
.lb-empty { color: var(--muted); text-align: center; padding: 28px 0; }

.input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 15px; margin-bottom: 12px;
}
.error { color: var(--bad); font-size: 14px; margin-top: 8px; }
.center { text-align: center; }
.spacer { height: 12px; }
.tg-wrap { display: flex; justify-content: center; margin: 8px 0; min-height: 48px; }
.muted { color: var(--muted); font-size: 13px; }
