:root {
  --paper: #f3f0e6;
  --surface: #fffdf7;
  --ink: #18201c;
  --muted: #626962;
  --line: #d5d1c4;
  --forest: #173f35;
  --forest-dark: #0d2b23;
  --moss: #d9e4c9;
  --sun: #e7ad35;
  --sun-soft: #fff1c9;
  --success: #226443;
  --success-soft: #dfeddf;
  --danger: #9c3d33;
  --danger-soft: #f6e1dc;
  --shadow: 0 12px 34px rgba(21, 39, 31, .09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  line-height: 1.55;
}
button, input, select { font: inherit; }
button, select { color: inherit; }
button { min-height: 44px; }
a { color: var(--forest); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 100; top: -80px; left: 12px; padding: 10px 14px; background: white; color: var(--forest-dark); }
.skip-link:focus { top: 12px; }

.site-header {
  min-height: 74px;
  padding: 10px max(20px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--forest);
  border-bottom: 4px solid var(--sun);
  color: white;
}
.brand { display: flex; align-items: center; gap: 12px; color: white; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; background: var(--sun); color: var(--forest-dark); font-family: "Newsreader", serif; font-size: 23px; font-weight: 700; transform: rotate(-3deg); }
.brand strong, .brand small { display: block; }
.brand strong { font-family: "Newsreader", serif; font-size: 22px; line-height: 1; }
.brand small { margin-top: 3px; color: #d7e3dd; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.board-trigger { padding: 0 16px; border: 1px solid rgba(255,255,255,.5); background: transparent; color: white; font-weight: 700; cursor: pointer; }
.board-trigger:hover { background: rgba(255,255,255,.1); }

main { max-width: 1180px; margin: auto; padding: 0 24px 80px; }
.hero { display: grid; grid-template-columns: 1.35fr .65fr; align-items: end; gap: 64px; padding: 64px 0 44px; }
.eyebrow { margin: 0 0 10px; color: var(--forest); font-size: 11px; font-weight: 700; letter-spacing: .13em; }
.hero h1 { max-width: 820px; margin: 0; font-family: "Newsreader", serif; font-size: clamp(42px, 6vw, 72px); line-height: .98; letter-spacing: -.025em; }
.hero-note { padding-left: 22px; border-left: 3px solid var(--sun); color: #444d47; }
.hero-note p { margin: 0 0 16px; }
.hero-note a { min-height: 44px; display: inline-flex; align-items: center; font-weight: 700; text-underline-offset: 4px; }

.dashboard { display: grid; grid-template-columns: repeat(3, 1fr) 1.5fr; margin-bottom: 70px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.dashboard > div { min-height: 94px; padding: 19px 23px; border-right: 1px solid var(--line); }
.dashboard > div:last-child { border-right: 0; }
.dashboard strong, .dashboard span { display: block; }
.dashboard strong { font-family: "Newsreader", serif; font-size: 32px; line-height: 1; }
.dashboard span { margin-top: 6px; color: var(--muted); font-size: 12px; }
.progress-cell { display: flex; flex-direction: column; justify-content: center; }
.progress-track { height: 7px; margin-top: 10px !important; overflow: hidden; background: #e5e2d8; }
.progress-track span { width: 0; height: 100%; margin: 0; background: var(--sun); transition: width .25s ease; }

.content-section { scroll-margin-top: 20px; margin-bottom: 84px; }
.section-heading { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.section-heading > span { color: var(--forest); font-family: "Newsreader", serif; font-size: 36px; }
.section-heading h2, .section-heading p { margin: 0; }
.section-heading h2 { font-family: "Newsreader", serif; font-size: 30px; line-height: 1.1; }
.section-heading p { color: var(--muted); font-size: 13px; }
.lesson-grid { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.lesson { min-height: 240px; padding: 24px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: rgba(255,253,247,.72); }
.lesson-wide { grid-column: span 2; }
.lesson-number { margin: 0 0 34px; color: var(--forest); font-family: "Newsreader", serif; font-size: 27px; }
.lesson h3 { margin: 0 0 10px; font-family: "Newsreader", serif; font-size: 25px; }
.lesson > p:not(.lesson-number) { max-width: 620px; margin: 0; color: #4d554f; }
.math-note { display: inline-block; max-width: 100%; margin-top: 20px; padding: 7px 11px; overflow-x: auto; border-left: 3px solid var(--forest); background: rgba(23,63,53,.07); }

.quiz-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 28px; align-items: start; }
.mastery { position: sticky; top: 20px; padding-top: 4px; }
.mastery h3 { margin: 0 0 18px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.mastery-row { margin-bottom: 15px; }
.mastery-row div { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.mastery-track { display: block; height: 5px; margin-top: 6px; background: #dbd8cd; }
.mastery-track i { display: block; width: 0; height: 100%; background: var(--forest); transition: width .2s ease; }
.privacy-note { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.question-card { min-width: 0; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.quiz-empty, .quiz-complete { min-height: 430px; padding: 52px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; }
.quiz-empty h3, .quiz-complete h3 { max-width: 620px; margin: 0; font-family: "Newsreader", serif; font-size: clamp(32px, 5vw, 50px); line-height: 1.05; }
.quiz-empty > p:not(.eyebrow), .quiz-complete > p:not(.eyebrow) { max-width: 630px; color: var(--muted); }
.question-meta { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 34px; border-bottom: 1px solid var(--line); color: var(--forest); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.question-prompt { min-height: 155px; padding: 34px 38px 20px; white-space: pre-line; font-size: 19px; overflow-wrap: anywhere; }
.question-prompt .katex-display, #solution .katex-display { overflow-x: auto; overflow-y: hidden; }
#answerForm { padding: 0 38px 38px; }
#answerForm fieldset { margin: 0; padding: 0; border: 0; }
.answer-options { display: grid; gap: 10px; }
.answer-option { position: relative; }
.answer-option input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.answer-option label { min-height: 56px; padding: 11px 15px; display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); background: white; cursor: pointer; overflow-x: auto; }
.option-letter { width: 31px; height: 31px; flex: 0 0 31px; display: grid; place-items: center; background: #edf0e8; font-weight: 700; }
.answer-option label:hover { border-color: #849188; background: #fbfaf4; }
.answer-option input:checked + label { border-color: var(--forest); background: #eef4ec; box-shadow: inset 4px 0 var(--forest); }
.answer-option input:focus-visible + label { outline: 3px solid var(--sun); outline-offset: 3px; }
.answer-option.correct label { border-color: var(--success); background: var(--success-soft); box-shadow: inset 4px 0 var(--success); }
.answer-option.wrong label { border-color: var(--danger); background: var(--danger-soft); box-shadow: inset 4px 0 var(--danger); }
.numeric-answer { width: 100%; min-height: 54px; padding: 10px 14px; border: 1px solid var(--line); background: white; font-size: 18px; }
.answer-warning { margin: 10px 0 0; color: var(--danger); font-size: 13px; }
.primary-button, .secondary-button, .danger-button, .tool-button, .icon-button { border: 1px solid transparent; font-weight: 700; cursor: pointer; }
.primary-button { margin-top: 22px; padding: 11px 22px; background: var(--forest); color: white; }
.primary-button:hover { background: var(--forest-dark); }
.primary-button:active, .tool-button:active, .board-trigger:active { transform: translateY(1px); }
.feedback { margin: 0 38px 38px; padding: 24px; border-left: 5px solid var(--success); background: var(--success-soft); }
.feedback.incorrect { border-color: var(--danger); background: var(--danger-soft); }
.feedback-status { margin: 0 0 12px; font-size: 19px; font-weight: 700; }
.feedback h3 { margin: 18px 0 6px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.feedback p { margin: 0; }

.source-note { max-width: 780px; padding: 24px 0 0 22px; border-left: 3px solid var(--sun); }
.source-note h2 { margin: 0 0 8px; font-family: "Newsreader", serif; font-size: 25px; }
.source-note p { margin: 0 0 8px; color: var(--muted); }

.board-dialog { width: min(1100px, calc(100% - 28px)); height: min(820px, calc(100dvh - 28px)); padding: 0; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 20px 90px rgba(0,0,0,.28); }
.board-dialog::backdrop, .reset-dialog::backdrop { background: rgba(12, 28, 22, .68); }
.board-head { min-height: 74px; padding: 12px 18px 12px 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.board-head p, .board-head h2 { margin: 0; }
.board-head h2 { font-family: "Newsreader", serif; font-size: 27px; line-height: 1; }
.icon-button { width: 46px; padding: 0; background: transparent; font-size: 30px; font-weight: 400; }
.board-tools { min-height: 62px; padding: 8px 20px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; border-bottom: 1px solid var(--line); }
.board-tools label { min-height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 8px; color: var(--muted); font-size: 12px; }
.board-tools input { width: 90px; accent-color: var(--forest); }
.board-tools select { min-height: 38px; border: 1px solid var(--line); background: white; }
.tool-button { padding: 8px 13px; border-color: var(--line); background: white; }
.tool-button:hover { border-color: var(--forest); }
.tool-button.active { border-color: var(--forest); background: var(--forest); color: white; }
.danger-text { color: var(--danger); }
.canvas-wrap { position: relative; height: calc(100% - 172px); min-height: 320px; margin: 0; overflow: hidden; background-color: #fffefa; }
.canvas-wrap.grid-dots { background-image: radial-gradient(#b7beb7 1px, transparent 1px); background-size: 22px 22px; }
.canvas-wrap.grid-squares { background-image: linear-gradient(#e2e3dc 1px, transparent 1px), linear-gradient(90deg, #e2e3dc 1px, transparent 1px); background-size: 24px 24px; }
#whiteboard { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.board-hint { height: 36px; margin: 0; padding: 8px 20px; color: var(--muted); font-size: 11px; }
.reset-dialog { width: min(440px, calc(100% - 32px)); padding: 26px; border: 1px solid var(--line); background: var(--surface); }
.reset-dialog h2 { margin: 0; font-family: "Newsreader", serif; font-size: 28px; }
.dialog-actions { margin-top: 22px; display: flex; justify-content: flex-end; gap: 9px; }
.secondary-button, .danger-button { padding: 10px 16px; }
.secondary-button { border-color: var(--line); background: white; }
.danger-button { background: var(--danger); color: white; }

footer { min-height: 86px; padding: 18px max(20px, calc((100vw - 1180px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 18px; background: var(--forest-dark); color: #d8e4dd; font-size: 13px; }
footer button { border: 0; border-bottom: 1px solid currentColor; background: transparent; color: #f0c76d; cursor: pointer; }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .45; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 28px; }
  .dashboard { grid-template-columns: repeat(3, 1fr); }
  .progress-cell { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .dashboard > div:nth-child(3) { border-right: 0; }
  .quiz-shell { grid-template-columns: 1fr; }
  .mastery { position: static; }
  #masteryList { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
}

@media (max-width: 600px) {
  .site-header { padding: 10px 14px; }
  .brand small { display: none; }
  .board-trigger { padding: 0 11px; font-size: 12px; }
  main { padding: 0 15px 60px; }
  .hero { padding: 42px 0 30px; }
  .hero h1 { font-size: 43px; }
  .dashboard { margin-bottom: 55px; }
  .dashboard > div { min-height: 78px; padding: 14px 8px; text-align: center; }
  .dashboard strong { font-size: 27px; }
  .progress-cell { text-align: left !important; padding: 14px 16px !important; }
  .content-section { margin-bottom: 64px; }
  .lesson-grid { grid-template-columns: 1fr; }
  .lesson-wide { grid-column: auto; }
  .lesson { min-height: 0; padding: 20px; }
  .lesson-number { margin-bottom: 20px; }
  .quiz-empty, .quiz-complete { min-height: 410px; padding: 28px 20px; }
  .question-meta { padding: 10px 18px; }
  .question-prompt { min-height: 130px; padding: 26px 20px 16px; font-size: 17px; }
  #answerForm { padding: 0 20px 26px; }
  .answer-option label { min-height: 60px; }
  .feedback { margin: 0 20px 24px; padding: 18px; }
  .board-dialog { width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border: 0; }
  .board-tools { max-height: 124px; overflow-y: auto; padding: 7px 10px; }
  .canvas-wrap { height: calc(100% - 234px); }
  .board-hint { height: 38px; padding: 8px 12px; }
}

@media (max-width: 360px) {
  .brand strong { font-size: 18px; }
  .board-trigger { width: 112px; line-height: 1.15; }
  .hero h1 { font-size: 38px; }
  #masteryList { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
