:root {
  --primary: #3366FF;
  --primary-dark: #2547b8;
  --accent: #0066FF;
  --success: #34C759;
  --warning: #FF9500;
  --error: #FF3B30;
  --text: #1c1c1e;
  --text-2: #6b6b70;
  --bg: #ffffff;
  --bg-soft: #f4f5f9;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(20, 30, 80, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 20px; }

.site-header {
  border-bottom: 1px solid #e8eaf0;
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 14px; padding-bottom: 14px;
}
.brand { font-weight: 800; font-size: 1.25rem; color: var(--text); text-decoration: none; }
.brand span { color: var(--primary); }
.site-header nav a {
  margin-left: 20px; text-decoration: none; color: var(--text-2); font-weight: 600;
}
.site-header nav a:hover { color: var(--primary); }

main { padding: 48px 0 64px; }
h1 { font-size: 2.4rem; line-height: 1.2; margin-bottom: 16px; letter-spacing: -0.02em; }
h2 { font-size: 1.6rem; margin-bottom: 12px; }
.lede { font-size: 1.15rem; color: var(--text-2); max-width: 640px; margin-bottom: 28px; }

.cta-row { display: flex; gap: 12px; margin-bottom: 40px; flex-wrap: wrap; }
.btn {
  display: inline-block; padding: 12px 24px; border-radius: var(--radius);
  border: 2px solid var(--primary); color: var(--primary);
  font-weight: 700; text-decoration: none; transition: all .15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn:hover:not(.primary) { background: #eef2ff; }
.btn.text {
  border: none; padding: 12px 12px; color: var(--text-2);
  font-weight: 600; text-decoration: underline;
}
.btn.text:hover { background: none; color: var(--text-1); }

/* Unfinished-quiz resume banner on the practice setup card. */
#quiz-resume { margin-bottom: 16px; }
.resume-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  background: #eef2ff; border: 2px solid var(--primary);
  border-radius: var(--radius); padding: 12px 16px;
}
.resume-actions { display: flex; gap: 8px; align-items: center; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px; margin-bottom: 32px;
}
.stat {
  background: var(--bg-soft); border-radius: var(--radius); padding: 20px;
  text-align: center;
}
.stat strong { display: block; font-size: 1.8rem; color: var(--primary); }
.stat span { color: var(--text-2); font-size: 0.9rem; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; margin-top: 20px;
}
.disclaimer { color: var(--text-2); font-size: 0.85rem; }

.view.hidden { display: none; }

.site-footer { border-top: 1px solid #e8eaf0; padding: 24px 0; color: var(--text-2); font-size: 0.9rem; }

.question-text { font-weight: 600; margin-bottom: 16px; }
.question-text, .solution, .solution-text, .study-item .answer-line {
  font-family: Georgia, "Times New Roman", "Nimbus Roman", serif;
}
.question-text { font-size: 1.12rem; }
.q-diagram {
  display: block; max-width: 100%; width: min(560px, 100%); height: auto;
  margin: 4px auto 18px; border: 1px solid #e0e3ec; border-radius: 10px;
  background: #ffffff; padding: 6px;
}
.choices { list-style: none; }
.choices li {
  padding: 10px 14px; border: 1px solid #e0e3ec; border-radius: 8px;
  margin-bottom: 8px; cursor: pointer;
}
.choices li:hover { border-color: var(--primary); background: #f5f8ff; }
.solution { margin-top: 16px; padding-top: 16px; border-top: 1px dashed #dfe2ec; color: var(--text); }
.explain-head { font-weight: 800; font-size: 1.05rem; margin: 14px 0 4px; }
.explain-body p { margin: 0 0 10px; }
.explain-body p:last-child { margin-bottom: 0; }
.math-display { margin: 16px 0; overflow-x: auto; overflow-y: hidden; }
.math-display.left > .katex-display { text-align: left; }
.solution code, .study-item code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9em;
  background: #f5f7fc; padding: 1px 5px; border-radius: 4px;
}

.form-row { margin-bottom: 18px; }
.form-row label { display: block; font-weight: 700; margin-bottom: 8px; }
.form-row select {
  width: 100%; max-width: 420px; padding: 10px 12px; font-size: 1rem;
  border: 1px solid #e0e3ec; border-radius: 8px; background: #fff;
}
.length-row { display: flex; gap: 8px; flex-wrap: wrap; }
.length-btn {
  padding: 10px 20px; border: 2px solid #e0e3ec; border-radius: 8px;
  background: #fff; font-weight: 700; font-size: 1rem; cursor: pointer; color: var(--text);
}
.length-btn.selected { border-color: var(--primary); color: var(--primary); background: #eef2ff; }
.streak { margin-left: 12px; font-weight: 700; color: var(--warning); }

.quiz-progress { color: var(--text-2); font-size: 0.9rem; margin-bottom: 4px; }
.quiz-meta { color: var(--text-2); font-size: 0.85rem; margin-bottom: 16px; }
.quiz-nav { margin-top: 20px; }
.result-score { font-size: 2.2rem; font-weight: 800; color: var(--primary); margin: 12px 0 20px; }
.result-score span { font-size: 1.2rem; color: var(--text-2); font-weight: 600; }

.topic-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.topic-name { flex: 0 0 220px; font-weight: 600; }
.topic-name small { color: var(--text-2); font-weight: 400; }
.bar { flex: 1; height: 10px; background: #eef0f6; border-radius: 5px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--primary); border-radius: 5px; }
.topic-pct { flex: 0 0 48px; text-align: right; font-weight: 700; }

@media (max-width: 640px) {
  h1 { font-size: 1.8rem; }
  .site-header nav a { margin-left: 12px; font-size: 0.9rem; }
  .topic-name { flex-basis: 140px; font-size: 0.85rem; }
}

.form-row input[type="search"] {
  width: 100%; max-width: 420px; padding: 10px 12px; font-size: 1rem;
  border: 1px solid #e0e3ec; border-radius: 8px; background: #fff;
}
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  padding: 8px 14px; border: 1px solid #e0e3ec; border-radius: 999px;
  background: #fff; font-size: 0.85rem; font-weight: 600; cursor: pointer; color: var(--text-2);
}
.chip.selected { border-color: var(--primary); color: var(--primary); background: #eef2ff; }
.formula-card h3 { margin: 4px 0 10px; }
.formula-topic { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
.formula-expr {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 1.05rem;
  background: #f5f7fc; border: 1px solid #e6e9f2; border-radius: 8px;
  padding: 12px 14px; margin: 0 0 10px; overflow-x: auto; white-space: nowrap;
}
.formula-symbols { font-size: 0.88rem; color: var(--text-2); margin-bottom: 6px; }
.formula-notes { font-size: 0.92rem; color: var(--text); }

/* ---- results dashboard ---- */
.chart {
  display: flex; align-items: flex-end; gap: 8px;
  height: 210px; overflow-x: auto; padding: 30px 4px 0;
  border-bottom: 1px solid #e8eaf0;
}
.cbar-wrap {
  flex: 0 0 36px; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
.cbar-val { font-size: 0.72rem; font-weight: 700; margin-bottom: 4px; }
.cbar { width: 24px; border-radius: 5px 5px 0 0; min-height: 4px; }
.cbar.good { background: var(--success); }
.cbar.mid { background: var(--warning); }
.cbar.bad { background: var(--error); }
.cbar-x { font-size: 0.7rem; color: var(--text-2); margin-top: 6px; }

.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 20px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; border-left: 5px solid var(--success);
}
.stat-card.mid { border-left-color: var(--warning); }
.stat-card.bad { border-left-color: var(--error); }
.stat-card .k { font-weight: 700; margin-bottom: 2px; }
.stat-card .v { font-size: 1.9rem; font-weight: 800; }
.stat-card .v.good { color: var(--success); }
.stat-card .v.mid { color: var(--warning); }
.stat-card .v.bad { color: var(--error); }

.list-btn {
  display: block; width: 100%; margin-top: 20px; padding: 18px;
  background: var(--card); border: none; border-radius: var(--radius);
  box-shadow: var(--shadow); font-size: 1.05rem; font-weight: 600;
  cursor: pointer; color: var(--text); text-align: center;
}
.list-btn:hover { background: var(--bg-soft); }

details.card summary {
  font-size: 1.05rem; font-weight: 600; cursor: pointer; list-style: none;
  display: flex; justify-content: space-between; align-items: center;
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "\203A"; font-size: 1.4rem; color: var(--text-2); }
details.card[open] summary::after { content: "\2304"; }
details.card summary + div { margin-top: 16px; }

.bar .fill.good { background: var(--success); }
.bar .fill.mid { background: var(--warning); }
.bar .fill.bad { background: var(--error); }

.cat-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.cat-row .pct { font-weight: 700; white-space: nowrap; }
.cat-row .pct.good { color: var(--success); }
.cat-row .pct.mid { color: var(--warning); }
.cat-row .pct.bad { color: var(--error); }

.study-item { margin-top: 12px; }
.study-item .answer-line { margin: 8px 0; }
.study-item .solution-text { color: var(--text-2); font-size: 0.92rem; }

.muted { color: var(--text-2); }

@media (max-width: 640px) {
  .stat-card { padding: 14px; }
  .stat-card .v { font-size: 1.4rem; }
}

/* ---------- Flashcards ---------- */
.fc-controls { display: flex; gap: 10px; align-items: center; margin: 14px 0 6px; flex-wrap: wrap; }
.fc-controls select { font-size: 1rem; padding: 8px 10px; border: 1px solid #d8d2c4; border-radius: 8px; background: #fff; max-width: 100%; }
.fc-progress { color: #6b6455; font-size: .95rem; margin: 6px 0 12px; }
.fc-scene { perspective: 1200px; margin: 0 auto; max-width: 640px; }
.fc-card { position: relative; min-height: 320px; transform-style: preserve-3d; transition: transform .45s ease; cursor: pointer; }
.fc-card.flipped { transform: rotateY(180deg); }
.fc-face { backface-visibility: hidden; -webkit-backface-visibility: hidden; background: #fffdf8; border: 1px solid #e4ddcc; border-radius: 14px; padding: 26px 24px; box-shadow: 0 4px 14px rgba(60,50,30,.08); overflow-y: auto; max-height: 60vh; }
.fc-front { position: relative; }
.fc-back { position: absolute; inset: 0; transform: rotateY(180deg); }
.fc-q { font-size: 1.15rem; line-height: 1.55; margin-top: 12px; }
.fc-hint { color: #8a8272; font-size: .9rem; margin-top: 18px; font-style: italic; }
.fc-answer-label { text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; color: #8a8272; margin: 0 0 6px; }
.fc-a { font-size: 1.15rem; font-weight: 700; color: #1d6b3c; line-height: 1.5; }
.fc-sol { margin-top: 14px; font-size: 1rem; line-height: 1.6; border-top: 1px solid #e4ddcc; padding-top: 12px; }
.fc-nav { display: flex; gap: 10px; justify-content: center; margin: 18px 0 8px; }
@media (max-width: 560px) {
  .fc-face { padding: 20px 18px; }
  .fc-q { font-size: 1.05rem; }
}

/* ---------- Share score ---------- */
#share-toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: #1b2a4a; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: .95rem; opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease;
  max-width: 90vw; text-align: center; z-index: 9999; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
#share-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
