:root {
  --ink: #1d2430; --muted: #5d6675; --line: #d7dce3; --bg: #f5f7fa; --card: #fff;
  --accent: #2f6fdd; --ok: #1e8f4e; --bad: #c8322b; --okbg: #e8f7ee; --badbg: #fdeceb;
  --grid: #cfd6df; --axis: #333;
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
header.top { padding: 20px 16px 4px; max-width: 900px; margin: 0 auto; }
header h1 { margin: 0; font-size: 26px; }
header .sub { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; max-width: 900px; margin: 16px auto; }
.row { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; margin: 8px 0; }
.row label { display: inline-flex; gap: 6px; align-items: center; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:hover { filter: brightness(0.96); }
select, input[type=text] { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
input[type=text] { min-width: 180px; }
input[type=text].wide { min-width: 260px; }
.hidden { display: none !important; }

#test { max-width: 900px; margin: 16px auto; padding: 0 16px 40px; }
.test-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; }
.test-head h2 { margin: 0; }
.meta { color: var(--muted); }
.blank { display: inline-block; min-width: 140px; border-bottom: 1px solid var(--ink); padding: 0 4px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar.bottom { justify-content: center; margin-top: 20px; }
.score { margin: 12px 0; padding: 12px 16px; border-radius: 10px; background: #eef3fc; font-weight: 600; }

.questions { list-style: none; padding: 0; margin: 16px 0 0; counter-reset: q; }
.q { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 16px 12px 16px; margin: 0 0 14px; counter-increment: q; position: relative; }
.q .qnum { font-weight: 700; color: var(--accent); margin-right: 6px; }
.q .prompt { margin: 0 0 10px; }
.q .prompt .eq, .eq { font-family: "Cambria Math", Cambria, "Times New Roman", serif; font-size: 1.15em; white-space: nowrap; }
.q .lesson { position: absolute; top: 10px; right: 12px; font-size: 12px; color: var(--muted); }
.parts { display: flex; flex-direction: column; gap: 10px; }
.part { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.part .plabel { min-width: 160px; }
.part .result { font-weight: 600; }
.part.ok input, .part.ok .choices { outline: 2px solid var(--ok); border-radius: 6px; }
.part.bad input { outline: 2px solid var(--bad); }
.part .expect { color: var(--bad); font-size: 14px; }
.part.ok .expect { display: none; }
.choices { display: flex; flex-direction: column; gap: 4px; padding: 4px 6px; }
.choices label { display: flex; gap: 8px; align-items: baseline; cursor: pointer; }
.choices.inline { flex-direction: row; flex-wrap: wrap; gap: 6px 18px; }
.frac { display: inline-flex; flex-direction: column; text-align: center; vertical-align: middle; font-size: 0.85em; line-height: 1.1; margin: 0 2px; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 3px; }
.frac > span:last-child { padding: 0 3px; }
table.tbl { border-collapse: collapse; margin: 6px 0 10px; }
table.tbl td, table.tbl th { border: 1px solid #555; padding: 4px 12px; text-align: center; min-width: 44px; }
table.tbl th { background: #eee; }
.graphs { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; margin: 6px 0 10px; }
.graph-wrap { text-align: center; }
.graph-wrap .glabel { font-weight: 700; margin-bottom: 4px; }
svg.graph { background: #fff; border: 1px solid var(--line); touch-action: manipulation; max-width: 100%; height: auto; }
svg.graph.clickable { cursor: crosshair; }
.graph-note { font-size: 13px; color: var(--muted); }
.key { display: none; margin-top: 8px; padding: 8px 10px; background: #fff8e1; border-left: 4px solid #e0a800; font-size: 15px; }
body.show-key .key { display: block; }
.answer-line { display: none; }
body.show-key .answer-line { display: block; }
.work { display: none; }
.footer { text-align: center; color: var(--muted); }
.print-only { display: none; }

@media (max-width: 600px) {
  .part .plabel { min-width: 0; width: 100%; }
  input[type=text], input[type=text].wide { min-width: 0; width: 100%; }
}

@media print {
  @page { margin: 0.6in; }
  body { background: #fff; font-size: 12.5px; }
  .no-print { display: none !important; }
  .print-only { display: block; }
  span.print-only { display: inline; }
  #test { max-width: none; padding: 0; margin: 0; }
  .q { break-inside: avoid; border: 1px solid #999; border-radius: 4px; padding: 8px 10px; margin: 0 0 8px; }
  .q .lesson { display: none; }
  .parts { gap: 4px; }
  .part input[type=text] { border: none; border-bottom: 1px solid #333; border-radius: 0; min-width: 200px; background: #fff; color: #000; }
  .part .result, .part .expect { display: none; }
  .work { display: block; min-height: 70px; }
  .q.has-graph .work { min-height: 20px; }
  .choices input[type=radio] { -webkit-appearance: none; appearance: none; width: 12px; height: 12px; border: 1px solid #333; border-radius: 50%; margin: 0 2px 0 0; vertical-align: middle; }
  svg.graph { border: 1px solid #333; width: 200px !important; height: auto !important; }
  .graphs { gap: 10px; margin: 4px 0 6px; }
  .part input::placeholder { color: transparent; }
  .q .prompt { margin-bottom: 6px; }
  .score { display: none; }
  body.show-key .key { display: block; break-inside: avoid; }
  body.show-key .work { display: none; }
  body.show-key .part input[type=text] { display: none; }
}
