:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
/* Layout: an exercise book. Squared paper, a red margin, teacher's red-pen ticks; one column on phones. */
:root {
  --paper: #f7f8f4;
  --grid: #e3e8e1;
  --ink: #1d2a33;
  --muted: #5b6b73;
  --card: #ffffff;
  --line: #d4dbd5;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --pen: #c6312b;
  --good: #2e7d4f;
  --good-bg: #e6f3eb;
  --warn: #9a6400;
  --warn-bg: #fdf1dc;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --tip-bg: #eef4f9;
  --font-display: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --font-body: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-math: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #18211f; --grid: #22302c; --ink: #e8efe9; --muted: #9db0a8; --card: #1f2b28; --line: #33443f;
    --accent: #7cc0ea; --accent-ink: #0f1d26; --pen: #ff7b6e; --good: #7fd3a0; --good-bg: #1d3528;
    --warn: #f0c46b; --warn-bg: #3a2f17; --bad: #ff8a80; --bad-bg: #3a2220; --tip-bg: #1c2c36; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #18211f; --grid: #22302c; --ink: #e8efe9; --muted: #9db0a8; --card: #1f2b28; --line: #33443f;
  --accent: #7cc0ea; --accent-ink: #0f1d26; --pen: #ff7b6e; --good: #7fd3a0; --good-bg: #1d3528;
  --warn: #f0c46b; --warn-bg: #3a2f17; --bad: #ff8a80; --bad-bg: #3a2220; --tip-bg: #1c2c36; color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
}
.wrap {
  max-width: 780px; margin: 0 auto;
  padding-block: 24px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 20px;
}
header { display: grid; gap: 6px; border-left: 3px solid var(--pen); padding-left: 14px; }
.eyebrow { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; line-height: 1.15; }
h1 { font-size: clamp(30px, 6vw, 42px); font-weight: 800; }
h2 { font-size: 24px; font-weight: 800; }
h3 { font-size: 18px; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.stack { display: grid; gap: 20px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spread { justify-content: space-between; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 14px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-variant-numeric: tabular-nums; }
.chip strong { color: var(--accent); }
button {
  font: inherit; cursor: pointer; border-radius: 10px; padding: 11px 18px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); min-height: 44px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.link { background: none; border: none; color: var(--accent); padding: 6px 0; min-height: 0; text-decoration: underline; }
button.danger { color: var(--bad); border-color: var(--bad); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.actions button { text-align: left; display: grid; gap: 2px; padding: 14px 16px; }
.actions button span { font-size: 14px; font-weight: 400; opacity: .85; }
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.topic { text-align: left; display: grid; gap: 6px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.topic .name { font-family: var(--font-display); font-weight: 700; font-size: 17px; }
.topic .meta { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.strong, .pill.start { background: var(--good-bg); color: var(--good); }
.pill.getting { background: var(--warn-bg); color: var(--warn); }
.pill.needs { background: var(--bad-bg); color: var(--bad); }
.pill.none { border: 1px solid var(--line); color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: grid; gap: 14px; min-width: 0; }
.focus-card { border-left: 4px solid var(--pen); }
.lesson ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.note { border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; }
.note.trick { background: var(--tip-bg); }
.note.hook { border: 1px dashed var(--line); }
.note b { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.math { font-family: var(--font-math); overflow-wrap: anywhere; }
.qhead { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.marks { font-family: var(--font-math); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; }
.qtext { font-size: 20px; line-height: 1.45; white-space: pre-line; }
.answer-row { display: flex; gap: 10px; flex-wrap: wrap; }
.answer-row input {
  font: inherit; font-family: var(--font-math); flex: 1 1 180px; min-width: 0; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); min-height: 44px;
}
.choices { display: grid; gap: 8px; }
.choices button { text-align: left; font-family: var(--font-math); }
.choices button.picked { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.result { border-radius: 10px; padding: 14px; display: grid; gap: 8px; }
.result.ok { background: var(--good-bg); }
.result.no { background: var(--bad-bg); }
.verdict { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.pen { font-family: var(--font-display); font-weight: 800; font-size: 28px; color: var(--pen); line-height: 1; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 4px; font-family: var(--font-math); font-size: 15px; }
.hint { font-size: 15px; color: var(--muted); }
.big-score { font-family: var(--font-display); font-weight: 800; font-size: 56px; line-height: 1; color: var(--pen); font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 15px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.list { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
textarea { width: 100%; min-height: 160px; font-family: var(--font-math); font-size: 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 10px; }
.diagram-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.diagram { display: block; width: 100%; max-width: 420px; height: auto; margin: 0 auto; }
.diagram .ink { stroke: var(--ink); stroke-width: 2; }
.diagram .grid { stroke: var(--line); stroke-width: 1; }
.diagram .dot { fill: var(--pen); }
.diagram .match { fill: none; stroke: var(--warn); stroke-width: 3; }
.diagram .bar { fill: var(--accent); }
.diagram .label { fill: var(--ink); font-family: var(--font-body); font-size: 14px; }
.diagram .label.small { font-size: 11px; fill: var(--muted); }
.diagram .label.strong { font-weight: 700; fill: var(--pen); }
.chip.level { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.xpbar { display: inline-block; width: 70px; height: 6px; border-radius: 6px; background: var(--grid); overflow: hidden; }
.xpbar i, .progress i { display: block; height: 100%; background: var(--good); }
.progress { height: 6px; border-radius: 6px; background: var(--grid); overflow: hidden; }
.chip.streak { border-color: var(--pen); }
.chip.streak strong { color: var(--pen); }
.exams { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.exam { display: grid; gap: 2px; text-align: left; padding: 10px 12px; }
.exam span { font-size: 13px; color: var(--muted); }
.exam.done { border-color: var(--warn); }
.exam.ace { border-color: var(--good); background: var(--good-bg); }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { font-size: 13px; padding: 6px 10px; border-radius: 10px; background: var(--tip-bg); border: 1px solid var(--line); }
.note.warn { background: var(--warn-bg); }
.why { font-weight: 700; }
.after-result { margin-top: 12px; }
.cheer { font-weight: 700; color: var(--good); background: var(--good-bg); border-radius: 10px; padding: 8px 12px; }
.welcome h2 { font-size: 28px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 20; background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 700; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
footer { font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
@media (prefers-reduced-motion: no-preference) {
  .card, .result { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(4px); } to { transform: none; } }
}
