:root {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e5e7eb;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-fg: #ffffff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --ring: rgba(99, 102, 241, 0.35);
  --shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.15);
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0b1020;
  --bg-elev: #131a2e;
  --text: #e6e9f2;
  --muted: #94a3b8;
  --border: #1f2a44;
  --primary: #818cf8;
  --primary-2: #a78bfa;
  --ring: rgba(129, 140, 248, 0.4);
  --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
  --grad: linear-gradient(135deg, #818cf8 0%, #a78bfa 50%, #f472b6 100%);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .3s ease, color .3s ease;
  background-image:
    radial-gradient(1000px 500px at 10% -10%, rgba(99,102,241,.12), transparent 60%),
    radial-gradient(800px 400px at 100% 0%, rgba(236,72,153,.10), transparent 60%);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--grad); color: white;
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px;
  box-shadow: var(--shadow);
}
.brand-text h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.brand-text span { font-size: 12px; color: var(--muted); }

.theme-toggle {
  position: relative;
  width: 56px; height: 32px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border);
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px;
  transition: background .3s;
}
.theme-toggle .theme-icon { font-size: 14px; opacity: .5; transition: opacity .2s; }
[data-theme="light"] .theme-toggle .light { opacity: 1; }
[data-theme="dark"] .theme-toggle .dark { opacity: 1; }

/* Stage */
.stage { flex: 1; display: flex; align-items: center; justify-content: center; }
.screen { width: 100%; display: none; animation: fadeUp .5s ease; }
.screen.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pop {
  0% { transform: scale(.96); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Hero */
.hero { text-align: center; max-width: 680px; margin: 0 auto; padding: 20px 0; }
.hero-badge {
  display: inline-block; padding: 6px 12px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border);
  font-size: 12px; color: var(--muted); margin-bottom: 20px;
}
.hero-title {
  font-size: clamp(32px, 6vw, 56px);
  line-height: 1.05; margin: 0 0 16px;
  font-weight: 800; letter-spacing: -.02em;
}
.hero-title .grad {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { color: var(--muted); font-size: 17px; margin: 0 auto 28px; max-width: 520px; }
.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  max-width: 480px; margin: 0 auto 28px;
}
.stat {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 8px;
}
.stat b { display: block; font-size: 22px; font-weight: 800; }
.stat span { font-size: 12px; color: var(--muted); }
.credit { color: var(--muted); font-size: 13px; margin-top: 22px; }
.credit b { color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: 12px; cursor: pointer;
  font-weight: 600; font-size: 15px; border: 1px solid transparent;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, opacity .2s;
  font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--grad); color: white;
  box-shadow: 0 8px 20px -8px var(--ring);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 14px 28px -10px var(--ring); }
.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-elev); }
.btn-lg { padding: 16px 32px; font-size: 17px; }
.arrow { transition: transform .2s; }
.btn:hover .arrow { transform: translateX(4px); }

/* Card */
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px;
  box-shadow: var(--shadow);
  animation: pop .3s ease;
}

/* Quiz */
.quiz-header { margin-bottom: 20px; }
.q-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.pill {
  padding: 6px 12px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.timer { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.timer .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); animation: pulse 1s infinite;
}
.timer.warn .dot { background: var(--warning); }
.timer.danger { color: var(--danger); }
.timer.danger .dot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.progress {
  height: 8px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border);
  overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%;
  background: var(--grad);
  border-radius: 999px;
  transition: width .4s cubic-bezier(.4,0,.2,1);
}

.question-text { font-size: clamp(20px, 3vw, 26px); font-weight: 700; margin: 0 0 22px; line-height: 1.35; }
.options { display: grid; gap: 12px; }
.option {
  text-align: left; padding: 16px 18px; border-radius: 14px;
  background: transparent; border: 2px solid var(--border);
  cursor: pointer; font-size: 15px; font-weight: 500; color: var(--text);
  transition: all .2s; font-family: inherit;
  display: flex; align-items: center; gap: 12px;
}
.option:hover:not(:disabled) { border-color: var(--primary); transform: translateX(4px); }
.option .letter {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--border);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.option.selected { border-color: var(--primary); background: rgba(99,102,241,.06); }
.option.correct { border-color: var(--success); background: rgba(16,185,129,.08); color: var(--text); }
.option.correct .letter { background: var(--success); color: white; border-color: var(--success); }
.option.wrong { border-color: var(--danger); background: rgba(239,68,68,.08); }
.option.wrong .letter { background: var(--danger); color: white; border-color: var(--danger); }
.option:disabled { cursor: not-allowed; }

.quiz-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap;
}
.score-inline { color: var(--muted); font-size: 14px; }
.score-inline b { color: var(--text); font-size: 18px; font-weight: 800; }

/* Result */
.result-card { text-align: center; max-width: 520px; margin: 0 auto; }
.result-emoji { font-size: 64px; margin-bottom: 8px; animation: pop .5s ease; }
.result-card h2 { font-size: 28px; margin: 0 0 8px; font-weight: 800; }
.result-msg { color: var(--muted); margin: 0 0 24px; }
.score-ring {
  position: relative; width: 180px; height: 180px; margin: 0 auto 24px;
}
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--border); }
.ring-fg {
  stroke: url(#grad); stroke-linecap: round;
  stroke-dasharray: 327; stroke-dashoffset: 327;
  transition: stroke-dashoffset 1.2s cubic-bezier(.4,0,.2,1);
}
.ring-fg { stroke: var(--primary); }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-center b { font-size: 44px; font-weight: 800; line-height: 1; }
.ring-center span { color: var(--muted); font-size: 14px; margin-top: 4px; }

.breakdown {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin: 0 0 24px;
}
.breakdown > div {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 8px;
}
.breakdown b { display: block; font-size: 20px; font-weight: 800; }
.breakdown span { font-size: 12px; color: var(--muted); }

.result-actions {
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}

/* Footer */
.footer {
  margin-top: 32px; padding-top: 20px;
  text-align: center; font-size: 13px; color: var(--muted);
  border-top: 1px solid var(--border);
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.footer .sep { opacity: .5; }

/* Responsive */
@media (max-width: 560px) {
  .app { padding: 16px 14px 24px; }
  .card { padding: 20px; }
  .brand-text h1 { font-size: 16px; }
  .hero-title { font-size: 34px; }
  .stat b { font-size: 18px; }
  .btn-lg { padding: 14px 24px; font-size: 15px; width: 100%; justify-content: center; }
  .option { padding: 14px; font-size: 14px; }
  .breakdown b { font-size: 16px; }
}
