/* ── Design tokens (from Algebra Practice design) ─────────── */
:root {
  --bg:#f6f8f7; --paper:#ffffff; --ink:#18231f; --muted:#5b6a64; --faint:#8a9791;
  --line:#dde5e1; --grid:#e9efec; --accent:#1d6b54; --accent-soft:#e3f1ec; --accent-ink:#135040;
  --field:#fbfcfb; --sym:#f1f4fa; --sym-line:#d3dbe9; --sym-ink:#2d4c7c;
  --warn:#9a5b00; --warn-soft:#fdf3e2;
  --serif:"Newsreader", Georgia, "Times New Roman", serif;
  --sans:"IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:"IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:#111715; --paper:#171f1c; --ink:#e4ece8; --muted:#a3b2ab; --faint:#7d8c86;
    --line:#2a3632; --grid:#1a2320; --accent:#5cc5a2; --accent-soft:#1c2f28; --accent-ink:#8fdcc1;
    --field:#121916; --sym:#1b2230; --sym-line:#2e3a4e; --sym-ink:#a9c2ea;
    --warn:#f0b35c; --warn-soft:#2e2412;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:#111715; --paper:#171f1c; --ink:#e4ece8; --muted:#a3b2ab; --faint:#7d8c86;
  --line:#2a3632; --grid:#1a2320; --accent:#5cc5a2; --accent-soft:#1c2f28; --accent-ink:#8fdcc1;
  --field:#121916; --sym:#1b2230; --sym-line:#2e3a4e; --sym-ink:#a9c2ea;
  --warn:#f0b35c; --warn-soft:#2e2412;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}
a { color: var(--accent-ink); }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Sticky header ────────────────────────────────────────── */
.top {
  position: sticky;
  top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.top-in {
  max-width: 900px; margin: 0 auto;
  padding: 10px 16px;
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
}
.brand { margin-right: auto; text-decoration: none; color: inherit; }
.brand h1 { font: 650 21px/1.15 var(--serif); margin: 0; }
.nav-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who { font-size: 12.5px; color: var(--muted); }
.btn {
  font: 500 13px var(--sans);
  padding: 5px 11px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.btn.primary:hover { background: var(--accent-ink); color: var(--paper); }

/* ── Main content ─────────────────────────────────────────── */
main { max-width: 900px; margin: 0 auto; padding: 14px 16px 60px; }

/* ── Breadcrumbs ──────────────────────────────────────────── */
.crumbs {
  font-size: 13px; color: var(--faint);
  margin-bottom: 6px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent-ink); text-decoration: underline; }
.crumbs b { font-weight: 500; color: var(--ink); }

/* ── Page heading ─────────────────────────────────────────── */
.vt { font: 650 28px/1.15 var(--serif); margin: 0 0 4px; text-wrap: balance; }
.vsub { color: var(--muted); margin: 0 0 14px; max-width: 62ch; }
.ccode { font: 500 14px var(--mono); color: var(--accent-ink); }

/* ── Card grid (home / subject / chapter) ─────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.card {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px;
  text-decoration: none; color: inherit;
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.cname { font: 600 17px/1.3 var(--serif); }
.cmeta { font-size: 13px; color: var(--muted); }
.kps { font-size: 12.5px; color: var(--faint); line-height: 1.45; }
.bar { display: block; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); }

/* ── KP list (chapter page) ───────────────────────────────── */
.sg-section { margin-bottom: 28px; }
.sg-title { font: 600 11.5px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 18px 0 8px; }
.kp-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 6px;
  text-decoration: none; color: inherit; font-size: 14px;
}
.kp-row:hover { border-color: var(--accent); text-decoration: none; }
.kp-count { font-size: 12.5px; color: var(--faint); white-space: nowrap; margin-left: 10px; }

/* ── Problem cards ────────────────────────────────────────── */
.pinfo { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-bottom: 12px; }
.prob {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 12px;
}
.prob.done { border-left: 4px solid var(--accent); }
.ptop { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.pnum {
  font: 650 15px var(--serif);
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: 6px; padding: 0 8px;
}
.lvl { font-size: 12px; color: var(--muted); }
.lvl span[aria-hidden] { font-size: 10px; letter-spacing: 1.5px; color: var(--accent); margin-left: 3px; }
.status { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.status.ok   { color: var(--accent-ink); }
.status.edit { color: var(--warn); }
.badge { font: 500 11px var(--mono); background: var(--accent-soft); color: var(--accent-ink); border-radius: 4px; padding: 1px 6px; }

/* Question text */
.q { margin: 10px 0; line-height: 1.9; }
.q i, .ot i { font-family: var(--serif); font-size: 1.08em; }
.part { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 10px; }
.plabel { font-weight: 600; color: var(--accent-ink); }

/* Figure */
.fig { margin: 0 0 10px; }
.fig img { max-width: min(100%, 420px); height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.figlink { font-size: 13.5px; color: var(--muted); margin: 0 0 10px; }
.figreview {
  margin: 0 0 12px; padding: 8px 10px 10px;
  border: 1.5px dashed var(--warn); border-radius: 8px;
  background: var(--warn-soft);
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start;
}

/* Answer boxes */
.ans { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.plab { font-size: 12.5px; color: var(--muted); }
.ans textarea {
  width: 100%; min-height: 78px; resize: vertical;
  font: 15px/1.5 var(--sans); padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--field); color: var(--ink);
}
.ans textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Multiple choice */
fieldset.mc { border: 0; margin: 6px 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
fieldset.mc legend { font-size: 12.5px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.opt {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; background: var(--field);
}
.opt:hover { border-color: var(--accent); }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.ol {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--accent); display: grid; place-items: center;
  font: 600 13px var(--sans); color: var(--accent-ink);
}
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt:has(input:checked) .ol { background: var(--accent); color: var(--paper); }

/* Actions row */
.actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--faint); }
.submit {
  font: 600 13px var(--sans); padding: 6px 16px; border-radius: 7px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--paper); cursor: pointer;
}
.submit:hover { background: var(--accent-ink); }

/* Symbols */
.symbtn {
  font: 500 13px var(--sans); padding: 6px 12px; border-radius: 7px;
  border: 1px solid var(--sym-line); background: var(--sym); color: var(--sym-ink); cursor: pointer;
}
.symbtn[aria-expanded="true"] { background: var(--sym-ink); color: var(--paper); }
.sympanel {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
  padding: 8px; border: 1px solid var(--sym-line);
  background: var(--sym); border-radius: 8px;
}
.sym {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 64px; padding: 6px 8px; border-radius: 7px;
  border: 1px solid var(--sym-line); background: var(--paper); color: var(--ink); cursor: pointer;
}
.sym .sg { font: 500 19px/1 var(--serif); }
.sym .sn { font: 500 10.5px/1.1 var(--sans); color: var(--muted); white-space: nowrap; }
.sym:hover { border-color: var(--sym-ink); }

/* ── Pagination ───────────────────────────────────────────── */
.pager {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-top: 18px;
}
.pbtn {
  font: 600 13.5px var(--sans); padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  text-decoration: none; cursor: pointer; max-width: 45%;
}
.pbtn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); text-decoration: none; }
.pbtn.next { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.pbtn.next:hover { background: var(--accent-ink); }
.pbtn:empty { visibility: hidden; }
.pinfo-center { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── Search ───────────────────────────────────────────────── */
.search-box {
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 16px;
}
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row input[type=search] {
  flex: 1; font: inherit; font-size: 15px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink);
}
.search-row input[type=search]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-row label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.filter-row select {
  font: inherit; font-size: 13px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--paper); color: var(--ink);
}
.result-count { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.search-result .q {
  max-height: 4.5em; overflow: hidden; position: relative;
}
.search-result .q::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1.5em;
  background: linear-gradient(transparent, var(--paper));
}

/* ── Teacher table ────────────────────────────────────────── */
.tbl { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
tr.pick { cursor: pointer; }
tr.pick:hover td { background: var(--accent-soft); }
td.work { white-space: pre-wrap; max-width: 46ch; }
.dq { color: var(--muted); font-size: 12.5px; max-width: 52ch; }
.subj-head { font: 700 16px var(--serif); color: var(--accent-ink); margin: 22px 0 6px; }
.ch-head   { font: 600 13px var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 6px; }
.ans-card { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 8px; }
.ans-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.ans-work { white-space: pre-wrap; font-size: 13.5px; background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; margin-top: 6px; }

/* ── Login ────────────────────────────────────────────────── */
.login-wrap { max-width: 400px; margin: 40px auto; }
.login-card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 28px 28px 24px; }
.login-card h2 { font: 650 22px/1.2 var(--serif); margin: 0 0 6px; }
.login-card p { font-size: 14px; color: var(--muted); margin: 0 0 18px; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
.login-card input[type=text],
.login-card input[type=password] {
  width: 100%; font: 15px var(--sans); padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink);
  margin-bottom: 14px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.err { font-size: 13px; color: var(--warn); margin-bottom: 10px; }

/* ── Alert ────────────────────────────────────────────────── */
.notice { margin-bottom: 12px; }
.notice p {
  margin: 0; background: var(--warn-soft); color: var(--warn);
  border-radius: 8px; padding: 8px 12px; font-size: 13.5px;
}
.notice.info p { background: var(--accent-soft); color: var(--accent-ink); }

/* ── Math typography ──────────────────────────────────────── */
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 2px; line-height: 1.15; font-size: .92em; }
.frac .num { border-bottom: 1.3px solid currentColor; padding: 0 3px 1px; }
.frac .den { padding: 1px 3px 0; }
.rad { white-space: nowrap; }
.rad .rc { border-top: 1.3px solid currentColor; padding: 0 2px; margin-left: 1px; }
.rad .idx { font-size: .62em; vertical-align: .95em; margin-right: -.3em; }
.rep { text-decoration: overline; }
sup { font-size: .72em; }

/* ── Footer ───────────────────────────────────────────────── */
.foot { text-align: center; color: var(--faint); font-size: 12px; padding: 24px 0 32px; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 700px) {
  .top { position: static; }
  .vt { font-size: 24px; }
  .filter-row { flex-direction: column; }
}
