/*
 * Maths fundamentals: styles.
 * Copyright (C) 2026 Nathan Clisby
 * Produced with the aid of Claude Opus 5.5, an AI model made by Anthropic.
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version. This program is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details. You should have received a copy of the GNU
 * General Public License along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
 */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 16px;
  --radius-sm: 12px;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --border-strong: #c3c9d2;
  --text: #1b2130;
  --text-2: #586172;
  --accent: #2d5bd0;
  --accent-ink: #ffffff;
  --accent-soft: #e9eefb;
  --good: #1d7548;
  --good-soft: #e4f3ea;
  --bad: #b23a2e;
  --bad-soft: #fbeae7;
  --info: #7a5300;
  --info-soft: #fbf1db;
  --warn: #b25a00;
  --gold: #c58f00;
  --warn-soft: #fdeedb;
  --shadow: 0 1px 2px rgba(20, 28, 45, 0.05), 0 2px 8px rgba(20, 28, 45, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a;
    --surface: #1a1f28;
    --surface-2: #222934;
    --border: #2d3542;
    --border-strong: #3d4757;
    --text: #e7eaf0;
    --text-2: #a2abba;
    --accent: #8aa6ff;
    --accent-ink: #0d1322;
    --accent-soft: #1f2a46;
    --good: #67cf9c;
    --good-soft: #15301f;
    --bad: #ff9184;
    --bad-soft: #3a1d1a;
    --info: #e9bb62;
    --info-soft: #33290f;
    --warn: #f3a54a;
    --gold: #f2c14e;
    --warn-soft: #3a2812;
    --shadow: none;
    color-scheme: dark;
  }
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 16px 64px;
}

@media (min-width: 720px) {
  .wrap { padding: 56px 24px 80px; }
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.5rem); letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; }
p { margin: 0; }

.muted { color: var(--text-2); }
.small { font-size: 0.9rem; }
.center { text-align: center; }

/* ---------- Hero ---------- */
.hero { margin-bottom: 28px; }
.hero.compact { margin: 8px 0 20px; }
.eyebrow {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.lede { margin-top: 10px; color: var(--text-2); font-size: 1.08rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  margin-bottom: 18px;
}
@media (min-width: 720px) {
  .card { padding: 28px 30px; }
}
.card > h2 + * { margin-top: 10px; }

/* How it works */
.steps { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 12px; }
.how .steps { margin-top: 0; } /* the card has no heading */
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.step-n {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
  display: grid; place-items: center;
  margin-top: 1px;
}
@media (min-width: 720px) {
  .steps { grid-template-columns: repeat(3, 1fr); gap: 20px; }
  .steps li { flex-direction: column; gap: 8px; }
}

/* Topic card */
.topic-head { display: flex; gap: 16px; align-items: flex-start; }
.topic-num {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.15rem;
  display: grid; place-items: center;
}
.topic-head h2 { font-size: 1.35rem; }
.topic-head .muted { margin-top: 2px; }
.stats { margin: 8px 0 16px; font-size: 0.92rem; color: var(--text-2); }
.stats-gap { height: 16px; }

/* Progress: the number badge, a status label, and one dot per question type.
   Orange (not red) for "needs work", so it reads as a nudge, not a failure. */
.progress-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.status-pill {
  font-size: 0.78rem; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
}
.dots { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1.5px var(--border-strong);
}
.dot.good { background: var(--good); box-shadow: none; }
.dot.work { background: var(--warn); box-shadow: none; }

.topic.status-new .topic-num { background: var(--surface-2); color: var(--text-2); }
.topic.status-progress .status-pill { background: var(--accent-soft); color: var(--accent); }
.topic.status-work .topic-num { background: var(--warn); color: #fff; }
.topic.status-work .status-pill { background: var(--warn-soft); color: var(--warn); }
.topic.status-done .topic-num { background: var(--good); color: #fff; }
.topic.status-done .status-pill { background: var(--good-soft); color: var(--good); }
@media (prefers-color-scheme: dark) {
  .topic.status-work .topic-num, .topic.status-done .topic-num { color: #10141b; }
}
.btn.wide { width: 100%; margin-bottom: 12px; }

/* ---------- Buttons ---------- */
button { font: inherit; color: inherit; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  min-height: 48px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn.secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn.danger { background: var(--bad); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .option:focus-visible, .link:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn-row .btn { display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: 14px 16px; }
.btn-title { font-size: 1.05rem; }
.btn-sub { font-weight: 400; font-size: 0.85rem; opacity: 0.85; margin-top: 2px; }
@media (max-width: 420px) {
  .btn-row { grid-template-columns: 1fr; }
}

.link {
  appearance: none;
  background: none;
  border: none;
  padding: 8px 0;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.link.danger { color: var(--bad); }

.actions { margin-top: 22px; display: flex; gap: 12px; }
.actions .btn { min-width: 220px; }
.actions.split { flex-wrap: wrap; }
@media (max-width: 560px) {
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; min-width: 0; }
}

/* ---------- Question screen ---------- */
.bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.pill.quiz { background: var(--info-soft); color: var(--info); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.q-count { margin: 10px 0 14px; font-size: 0.9rem; color: var(--text-2); }

.q-title {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.prompt {
  font-size: 1.35rem;
  margin: 14px 0 6px;
  overflow-x: auto;
  overflow-y: hidden;
}
.prompt .katex { font-size: 1.15em; }
.prompt.small { font-size: 1.05rem; margin: 0 0 10px; }
.instruct { margin-top: 20px; color: var(--text-2); }

/* Answer options */
.options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.option {
  appearance: none;
  position: relative;
  min-height: 72px;
  padding: 14px 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.12s, background 0.12s;
  touch-action: manipulation;
  overflow-x: auto;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.option:disabled { cursor: default; }
.option:disabled:not(.is-correct):not(.is-wrong):not([aria-pressed="true"]) { opacity: 0.55; }
.option.is-correct { border-color: var(--good); background: var(--good-soft); box-shadow: inset 0 0 0 1px var(--good); opacity: 1; }
.option.is-wrong { border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }

.specials { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.option.special {
  min-height: 52px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-2);
  border-style: dashed;
}
.option.special[aria-pressed="true"] { color: var(--text); border-style: solid; }
@media (max-width: 420px) {
  .specials { grid-template-columns: 1fr; }
}

.key-hint {
  display: none;
  position: absolute;
  top: 6px; left: 8px;
  font: 600 0.7rem/1 var(--font);
  color: var(--text-2);
  opacity: 0.7;
}
@media (hover: hover) and (pointer: fine) {
  .key-hint { display: block; }
}

/* Feedback */
.feedback {
  margin-top: 22px;
  padding: 18px 20px;
  border-radius: var(--radius-sm);
  border-left: 5px solid var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.feedback.correct { border-left-color: var(--good); background: var(--good-soft); }
.feedback.wrong { border-left-color: var(--bad); background: var(--bad-soft); }
.feedback.none, .feedback.cant { border-left-color: var(--info); background: var(--info-soft); }
.feedback h3 { font-size: 1.1rem; margin-bottom: 6px; }
.feedback.correct h3 { color: var(--good); }
.feedback.wrong h3 { color: var(--bad); }
.feedback.none h3, .feedback.cant h3 { color: var(--info); }
.feedback p + p { margin-top: 8px; }
.solution {
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 10px;
  overflow-x: auto;
}
.solution h4 {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.solution .katex-display { margin: 8px 0 4px; }

/* ---------- Summary ---------- */
.score { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.score .big { font-size: 3rem; font-weight: 700; line-height: 1; color: var(--accent); }
.score .of { font-size: 1.1rem; color: var(--text-2); }
.note { margin-top: 12px; padding: 10px 14px; border-radius: 10px; background: var(--info-soft); font-size: 0.95rem; }

.mistake-list { list-style: none; padding: 0; margin: 12px 0 0; }
.mistake-list li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.mistake-list li:first-child { border-top: none; }
.count { white-space: nowrap; }
.mistake-list .count { color: var(--text-2); font-variant-numeric: tabular-nums; }

.reviews { margin-top: 12px; }
.review { border-top: 1px solid var(--border); }
.review:first-child { border-top: none; }
.review summary {
  list-style: none;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px;
  cursor: pointer;
  border-radius: 8px;
}
.review summary::-webkit-details-marker { display: none; }
.review summary::after { content: "▾"; color: var(--text-2); margin-left: 4px; transition: transform 0.15s; }
.review[open] summary::after { transform: rotate(180deg); }
.r-num {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-2); color: var(--text-2);
  display: grid; place-items: center; font-size: 0.85rem; font-weight: 600;
}
.r-title { flex: 1; font-weight: 500; }
.tag { font-size: 0.8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.tag.correct { background: var(--good-soft); color: var(--good); }
.tag.wrong { background: var(--bad-soft); color: var(--bad); }
.tag.none, .tag.cant { background: var(--info-soft); color: var(--info); }
.r-body { padding: 4px 0 18px 38px; }
.yours { margin-bottom: 4px; }
.r-body .feedback { margin-top: 12px; }
@media (max-width: 480px) {
  .r-body { padding-left: 0; }
}

/* ---------- Footer & dialog ---------- */
.foot {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.foot-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(10, 14, 22, 0.45); }
dialog h2 { margin-bottom: 8px; }
dialog p { color: var(--text-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Larger screens: give the maths more room ---------- */
@media (min-width: 720px) {
  .prompt { font-size: 1.6rem; margin-top: 18px; }
  .option { min-height: 84px; font-size: 1.4rem; }
  .option.special { min-height: 54px; }
}

/* ---------- Home page: two topics per row on wide screens ---------- */
.topic-grid { display: grid; gap: 18px; margin-bottom: 18px; }
.topic-grid .card { margin-bottom: 0; display: flex; flex-direction: column; }
.topic-grid .btn-row { margin-top: auto; }
@media (min-width: 980px) {
  .wrap.home { max-width: 1040px; }
  .topic-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Keep each answer on one line ---------- */
/* KaTeX allows line breaks after "=" in inline maths, which split answers
   like "t = -5 or t = 7" across lines inside the answer boxes. */
.option .katex { white-space: nowrap; }
.options.wide { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.ans .katex { white-space: nowrap; }
.solution .katex-display + .katex-display { margin-top: 2px; }
@media (max-width: 480px) {
  .solution { padding: 10px 8px; }
  .solution .katex-display > .katex { font-size: 1.04em; }
}

/* Options in words, e.g. "Shifted left by 3" */
.option .opt-text { font-size: 1rem; font-weight: 500; line-height: 1.4; text-align: center; }
@media (min-width: 720px) { .option .opt-text { font-size: 1.05rem; } }

/* "You're improving at": a green accent, to celebrate */
.card.improving { border-left: 5px solid var(--good); }
.card.improving h2 { color: var(--good); }
.card.improving .mistake-list li { align-items: center; }

/* Trophy: a perfect round, or a completed topic */
.trophy { width: 1.15em; height: 1.15em; vertical-align: -0.2em; color: var(--gold); flex: none; }
.status-pill .trophy { width: 1.25em; height: 1.25em; margin-right: 3px; vertical-align: -0.3em; }
.score .perfect {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; color: var(--gold); font-size: 1.1rem;
}
.score .perfect .trophy { width: 1.8em; height: 1.8em; }

/* ---------- "Where should I start?" and "Practise my weak spots" ---------- */
.guide-grid { display: grid; gap: 18px; margin-bottom: 18px; }
.guide-grid .card { margin-bottom: 0; display: flex; flex-direction: column; gap: 10px; }
.guide-grid .card > .btn:last-child { margin-top: auto; align-self: flex-start; }
.guide-grid .card .btn.wide { margin-bottom: 0; }
@media (min-width: 980px) { .guide-grid { grid-template-columns: 1fr 1fr; } .guide-grid.single { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .guide-grid .card > .btn:last-child { align-self: stretch; } }

.start-list { list-style: none; padding: 0; margin: 12px 0 0; }
.start-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.start-list li:first-child { border-top: none; }
.start-list li > span { display: flex; align-items: center; gap: 12px; font-weight: 500; }
.start-list .btn { min-height: 40px; padding: 8px 18px; }
.topic-num.small { width: 30px; height: 30px; border-radius: 8px; font-size: 0.9rem; background: var(--warn-soft); color: var(--warn); }
.solid { margin-top: 12px; }
.r-sub { display: block; font-size: 0.85rem; font-weight: 400; color: var(--text-2); }
.card.improving h2 .trophy { width: 1.2em; height: 1.2em; vertical-align: -0.2em; }

/* Install on a phone */
.install {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.install p { margin-top: 2px; }
.install .btn { min-height: 40px; padding: 8px 18px; flex: none; }
