:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #6d28d9;
  --brand-2: #8b5cf6;
  --good: #16a34a;
  --bad: #dc2626;
  --gold: #f59e0b;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 320px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.logo { font-size: 34px; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -0.3px; }
.brand-name span { color: var(--brand); }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 8px; }
.nav-btn {
  border: 1px solid var(--line);
  background: #fff;
  padding: 9px 14px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  transition: 0.15s;
}
.nav-btn:hover { border-color: var(--brand-2); color: var(--brand); }

.app {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 26px 18px 50px;
  flex: 1;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 18px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.footer p { margin: 0; }

/* Hero */
.hero {
  text-align: center;
  padding: 18px 0 8px;
}
.hero h1 { font-size: 34px; margin: 6px 0; letter-spacing: -0.5px; }
.hero p { color: var(--muted); margin: 0 auto 6px; max-width: 620px; }
.section-title { font-size: 18px; margin: 26px 0 12px; font-weight: 800; }
.muted { color: var(--muted); }

/* Level pills */
.levels { display: flex; flex-wrap: wrap; gap: 10px; }
.level-pill {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 14px 20px;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  transition: 0.15s;
  min-width: 84px;
  text-align: center;
}
.level-pill small { display: block; font-weight: 600; font-size: 11px; color: var(--muted); margin-top: 2px; }
.level-pill:hover { transform: translateY(-2px); border-color: var(--brand-2); }
.level-pill.active { border-color: var(--brand); background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.level-pill.active small { color: rgba(255,255,255,0.85); }

/* Subject cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.subject-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: 0.18s;
  box-shadow: var(--shadow);
  border-top: 5px solid var(--accent, var(--brand));
}
.subject-card:hover { transform: translateY(-4px); }
.subject-card.disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.subject-icon { font-size: 38px; }
.subject-card h3 { margin: 10px 0 4px; font-size: 20px; }
.subject-card .label { color: var(--muted); font-size: 13px; }
.topic-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { background: #f1f5f9; color: #475569; font-size: 11px; padding: 4px 9px; border-radius: 999px; }

/* Buttons */
.btn {
  border: none;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  padding: 13px 22px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  transition: 0.15s;
}
.btn:hover { background: #5b21b6; }
.btn.secondary { background: #fff; color: var(--brand); border: 2px solid var(--brand); }
.btn.secondary:hover { background: #f5f3ff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }

/* Card / panel */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.back-link { background: none; border: none; color: var(--brand); font-weight: 700; cursor: pointer; padding: 0; margin-bottom: 10px; }

/* Quiz config */
.field { margin: 14px 0; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.input, select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
}
.input:focus, select:focus { outline: none; border-color: var(--brand-2); }
.count-row { display: flex; gap: 8px; }
.count-opt { flex: 1; padding: 12px; border: 2px solid var(--line); border-radius: 12px; text-align: center; font-weight: 700; cursor: pointer; }
.count-opt.active { border-color: var(--brand); background: var(--brand); color: #fff; }

/* Quiz play */
.quiz-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.quiz-meta { font-weight: 700; color: var(--muted); }
.score-badge { font-weight: 800; color: var(--brand); }
.timer {
  font-weight: 800;
  font-size: 18px;
  padding: 6px 14px;
  border-radius: 999px;
  background: #ecfdf5;
  color: var(--good);
  min-width: 70px;
  text-align: center;
}
.timer.warn { background: #fef2f2; color: var(--bad); animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

.progress { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 10px 0 20px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width 0.3s; }

.topic-tag { display: inline-block; font-size: 12px; font-weight: 700; color: var(--brand); background: #f5f3ff; padding: 4px 10px; border-radius: 999px; margin-bottom: 10px; }
.q-prompt { font-size: 22px; font-weight: 700; line-height: 1.4; margin: 6px 0 18px; }

.options { display: grid; gap: 12px; }
.option {
  text-align: left;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 15px 18px;
  font-size: 17px;
  cursor: pointer;
  transition: 0.12s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.option:hover { border-color: var(--brand-2); background: #faf5ff; }
.option .key { width: 28px; height: 28px; border-radius: 8px; background: #f1f5f9; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.option.selected { border-color: var(--brand); background: #f5f3ff; }
.option.correct { border-color: var(--good); background: #ecfdf5; }
.option.wrong { border-color: var(--bad); background: #fef2f2; }
.option.correct .key { background: var(--good); color: #fff; }
.option.wrong .key { background: var(--bad); color: #fff; }

/* Results */
.result-head { text-align: center; }
.result-score { font-size: 64px; font-weight: 900; color: var(--brand); line-height: 1; }
.result-sub { color: var(--muted); font-size: 16px; }
.stats { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 20px 0; }
.stat { background: #f8fafc; border-radius: 14px; padding: 14px 22px; text-align: center; min-width: 120px; }
.stat .big { font-size: 26px; font-weight: 800; }
.stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.review-item { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 10px 0; }
.review-item.ok { border-left: 5px solid var(--good); }
.review-item.no { border-left: 5px solid var(--bad); }
.review-q { font-weight: 700; }
.review-line { font-size: 14px; margin-top: 6px; }
.review-line.ans-correct { color: var(--good); }
.review-line.ans-wrong { color: var(--bad); }
.review-exp { font-size: 13px; color: var(--muted); margin-top: 6px; font-style: italic; }

/* Leaderboard */
.lb-filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.lb-filters select { width: auto; min-width: 150px; }
table.lb { width: 100%; border-collapse: collapse; }
table.lb th, table.lb td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); }
table.lb th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
table.lb td.rank { font-weight: 800; }
.medal { font-size: 18px; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: #f1f5f9; color: #475569; }

.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow); z-index: 50; }

@media (max-width: 560px) {
  .hero h1 { font-size: 26px; }
  .q-prompt { font-size: 19px; }
  .result-score { font-size: 48px; }
}
