/* ============ AP Math Mastery — styles ============ */
:root {
  --bg: #0b1020;
  --bg-2: #111832;
  --card: #151d3b;
  --card-2: #1b2550;
  --line: #27325f;
  --grid: rgba(120, 140, 255, 0.06);
  --text: #e8ecff;
  --muted: #9aa5d1;
  --accent: #7c9cff;
  --good: #2ecc8f;
  --bad: #ff6b81;
  --warn: #ffc857;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font-head: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}
:root[data-theme="light"] {
  --bg: #f6f7fc;
  --bg-2: #eef0fa;
  --card: #ffffff;
  --card-2: #f3f5ff;
  --line: #dde2f3;
  --grid: rgba(60, 80, 200, 0.06);
  --text: #141a33;
  --muted: #5d6690;
  --accent: #4060e8;
  --shadow: 0 8px 24px rgba(30, 40, 90, 0.08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 99; background: var(--card); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-head); font-size: 24px; font-weight: 800; color: #fff;
  background: conic-gradient(from 210deg, #4f8cff, #a26bff, #18b39b, #f5a524, #4f8cff);
}
.brand-name { font-family: var(--font-head); font-weight: 800; font-size: 19px; letter-spacing: -0.01em; }
.brand-name em { font-style: italic; color: var(--accent); }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--card-2); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.xp-pill { font-family: var(--font-mono); font-size: 13px; padding: 6px 12px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); white-space: nowrap; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.icon-btn:hover { border-color: var(--accent); }

main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 32px) 60px; outline: none; }
main:focus, main:focus-visible { outline: none; }

/* ---------- generic ---------- */
h1, h2, h3 { font-family: var(--font-head); letter-spacing: -0.015em; line-height: 1.15; }
h1 { font-size: clamp(30px, 5vw, 52px); margin: 0 0 12px; }
h2 { font-size: clamp(22px, 3vw, 30px); margin: 0 0 14px; }
h3 { font-size: 19px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.section { margin-top: 34px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.chip.E { color: var(--good); } .chip.M { color: var(--warn); } .chip.H { color: var(--bad); }
.chip.calc { color: var(--accent); }
.select, .textarea {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font: inherit;
}
.textarea { width: 100%; min-height: 110px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---------- hero ---------- */
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; align-items: center; margin-bottom: 30px; }
.hero p.lead { font-size: 18px; color: var(--muted); max-width: 56ch; }
.hero-eq {
  font-family: var(--font-mono); font-size: 13px; color: var(--muted);
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; position: relative; overflow: hidden;
}
.hero-eq .board { font-size: 20px; color: var(--text); line-height: 2.1; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-family: var(--font-mono); font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- subject cards ---------- */
.subject-card { position: relative; overflow: hidden; text-decoration: none; color: var(--text); display: flex; flex-direction: column; gap: 10px; transition: transform .15s ease, border-color .15s ease; }
.subject-card:hover { transform: translateY(-3px); border-color: var(--c); }
.subject-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c); }
.subject-card .emoji { font-size: 32px; }
.subject-card .meta { font-size: 13px; color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 99px; transition: width .5s ease; }

/* ---------- subject page ---------- */
.subject-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.subject-head .big-emoji { font-size: 44px; width: 72px; height: 72px; display: grid; place-items: center; border-radius: 18px; background: color-mix(in srgb, var(--c) 18%, transparent); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); }
.mode-cards .card { display: flex; flex-direction: column; gap: 8px; }
.mode-cards .card .ico { font-size: 26px; }
.official-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.official-table th, .official-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.official-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
details.unit { border: 1px solid var(--line); border-radius: 12px; background: var(--card); margin-bottom: 10px; }
details.unit summary { cursor: pointer; padding: 14px 16px; font-weight: 600; display: flex; gap: 10px; align-items: center; list-style: none; }
details.unit summary::-webkit-details-marker { display: none; }
details.unit summary .num { font-family: var(--font-mono); color: var(--c); min-width: 28px; }
details.unit summary .acc { margin-left: auto; font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
details.unit[open] summary { border-bottom: 1px solid var(--line); }
details.unit .body { padding: 12px 16px 16px; }
details.unit ul { margin: 0 0 12px; padding-left: 20px; }
details.unit li { margin: 6px 0; }
.format-row { display: grid; grid-template-columns: 170px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.format-row:last-child { border-bottom: none; }

/* ---------- practice ---------- */
.practice-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.progress-line { flex: 1; min-width: 160px; }
.qcard { padding: 26px; }
.qtext { font-size: 18px; margin: 8px 0 18px; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  padding: 14px 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg-2); cursor: pointer;
  transition: border-color .12s ease, background .12s ease, transform .12s ease;
}
.choice:hover:not([disabled]) { border-color: var(--accent); transform: translateX(2px); }
.choice .letter { font-family: var(--font-mono); font-weight: 700; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--card-2); flex: none; }
.choice.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg-2)); }
.choice.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--bg-2)); }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--bg-2)); }
.choice[disabled] { cursor: default; }
.explain { margin-top: 16px; padding: 14px 16px; border-radius: 12px; border-left: 4px solid var(--good); background: var(--bg-2); animation: rise .25s ease; }
.explain.bad { border-left-color: var(--bad); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pop { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(1.025); } }
.shake { animation: shake .35s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- FRQ ---------- */
.frq-list .card { display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: var(--text); }
.frq-list .card:hover { border-color: var(--accent); }
.frq-stem { font-size: 17px; }
.frq-part { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.frq-part .plabel { font-family: var(--font-mono); font-weight: 700; color: var(--accent); margin-right: 6px; }
.solution { margin-top: 12px; padding: 14px 16px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); animation: rise .25s ease; }
.rubric { margin-top: 10px; display: grid; gap: 6px; }
.rubric label { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.rubric input { margin-top: 3px; accent-color: var(--good); width: 16px; height: 16px; }
.data-table { border-collapse: collapse; margin: 14px 0; font-family: var(--font-mono); font-size: 14px; overflow-x: auto; display: block; max-width: 100%; }
.data-table th, .data-table td { border: 1px solid var(--line); padding: 8px 14px; text-align: center; }
.data-table th { background: var(--card-2); }
.graph-wrap { margin: 14px 0; max-width: 520px; }
.graph-wrap svg { width: 100%; height: auto; background: var(--bg-2); border-radius: 12px; border: 1px solid var(--line); }
.score-box { position: sticky; bottom: 14px; margin-top: 20px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.score-big { font-family: var(--font-mono); font-size: 26px; font-weight: 700; }

/* ---------- exam ---------- */
.exam-layout { display: grid; grid-template-columns: 1fr 260px; gap: 16px; align-items: start; }
.timer { font-family: var(--font-mono); font-size: 28px; font-weight: 700; }
.timer.low { color: var(--bad); }
.nav-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 10px; }
.nav-grid button { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; font-family: var(--font-mono); font-size: 12px; position: relative; }
.nav-grid button.answered { background: color-mix(in srgb, var(--accent) 30%, var(--bg-2)); }
.nav-grid button.current { outline: 2px solid var(--accent); }
.nav-grid button.flagged::after { content: "⚑"; position: absolute; top: -6px; right: -4px; font-size: 11px; color: var(--warn); }
.ap-score { font-family: var(--font-head); font-size: 88px; line-height: 1; font-weight: 800; color: var(--c, var(--accent)); }
.review-item { border-left: 4px solid var(--good); padding: 10px 14px; margin: 10px 0; background: var(--bg-2); border-radius: 8px; }
.review-item.bad { border-left-color: var(--bad); }

/* ---------- progress ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge { text-align: center; padding: 14px 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }
.badge .b-ico { font-size: 30px; display: block; }
.badge.locked { opacity: .35; filter: grayscale(1); }
.badge small { color: var(--muted); display: block; font-size: 12px; }
.chart svg { width: 100%; height: auto; }
.chart text { fill: var(--muted); font-family: var(--font-mono); font-size: 11px; }

/* ---------- toast & confetti ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 220%); opacity: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; box-shadow: var(--shadow);
  font-weight: 600; transition: transform .3s ease, opacity .3s ease; z-index: 50;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.confetti { position: fixed; width: 8px; height: 12px; top: -10px; z-index: 60; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

.footer { border-top: 1px solid var(--line); padding: 22px clamp(16px, 4vw, 40px); font-size: 13px; color: var(--muted); text-align: center; }
.footer p { max-width: 900px; margin: 0 auto; }
.katex { font-size: 1.06em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .exam-layout { grid-template-columns: 1fr; }
  .exam-side { order: -1; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .format-row { grid-template-columns: 1fr; gap: 4px; }
}
@media (max-width: 560px) {
  .nav { display: none; }
  .xp-pill { display: none; }
  .brand-name { font-size: 16px; }
  .qcard { padding: 18px; }
  .qtext { font-size: 16px; }
  .nav-grid { grid-template-columns: repeat(9, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
