:root {
  --ink: #08090a;
  --muted: #555b65;
  --line: #cfd3d8;
  --soft: #f1f2f4;
  --blue: #246fd8;
  --blue-soft: #eaf2ff;
  --cyan: #6dcbf4;
  --green: #176b45;
  --red: #a63232;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: #fff; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; line-height: 1.5; }
a { color: var(--blue); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #8bb8ff; outline-offset: 3px; }

.module-nav { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 11px 24px; border-bottom: 1px solid var(--line); background: #fff; }
.module-nav a { font-weight: 800; }
.course-brand-link { flex: 0 0 auto; color: var(--ink); font-size: 16px; font-weight: 900 !important; line-height: 1.1; text-decoration: none; }
.module-context { min-width: 0; display: grid; gap: 7px; }
.breadcrumbs { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; margin: 0; padding: 0; color: var(--muted); font-size: 12px; list-style: none; }
.breadcrumbs li + li::before { margin-right: 5px; color: #8c929a; content: "/"; }
.breadcrumbs a { color: var(--muted); font-weight: 700; }
.breadcrumbs [aria-current="page"] { color: var(--ink); font-weight: 800; }
.module-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px 16px; font-size: 14px; }
.module-links a { white-space: nowrap; }
.module-main { width: min(1040px, calc(100% - 32px)); margin: 0 auto; padding: 58px 0 90px; }
.eyebrow { margin: 0 0 10px; color: var(--blue); font-size: 13px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
h1, h2, h3 { line-height: 1.06; letter-spacing: -.025em; }
h1 { max-width: 900px; margin: 0; font-size: clamp(42px, 6vw, 68px); }
h2 { margin: 56px 0 18px; font-size: clamp(29px, 4vw, 42px); }
h3 { margin: 0 0 9px; font-size: 23px; }
.lede { max-width: 800px; margin: 20px 0 0; color: var(--muted); font-size: 21px; }
.module-sequence { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin: 34px 0 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.module-sequence a { min-height: 110px; padding: 16px; border-right: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.module-sequence a:last-child { border-right: 0; }
.module-sequence span { display: block; color: var(--blue); font-size: 12px; font-weight: 800; }
.module-sequence strong { display: block; margin-top: 18px; line-height: 1.15; }

.workbench { margin-top: 38px; padding: clamp(20px, 4vw, 38px); border: 1px solid var(--line); background: #fff; }
.workbench-grid { display: grid; grid-template-columns: minmax(250px, .72fr) minmax(0, 1.28fr); gap: 34px; align-items: start; }
.workbench-grid > *, .result { min-width: 0; }
.controls { display: grid; gap: 18px; }
.control { display: grid; gap: 7px; }
.control > span, .control > label { font-weight: 800; }
.control output { color: var(--blue); font-weight: 800; }
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--blue); }
select, textarea, input[type="text"] { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid #9ba1a9; border-radius: 0; background: #fff; color: var(--ink); }
textarea { min-height: 135px; resize: vertical; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
button { min-height: 44px; padding: 9px 13px; border: 1px solid var(--ink); border-radius: 0; background: var(--ink); color: #fff; cursor: pointer; font-weight: 800; }
button.secondary { background: #fff; color: var(--ink); }

.result { min-height: 320px; padding: 24px; background: var(--soft); }
.result-label { margin: 0; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.big-result { margin: 14px 0 0; font-size: clamp(32px, 6vw, 66px); font-weight: 800; letter-spacing: -.04em; line-height: 1; }
.equation { margin: 28px 0 0; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: clamp(16px, 2.2vw, 24px); overflow-wrap: anywhere; }
.probability-track { height: 18px; margin-top: 24px; background: #d9dde2; }
.probability-fill { height: 100%; width: 50%; background: var(--blue); transition: width 140ms ease; }
.result-note { color: var(--muted); }
.chart-wrap { width: 100%; min-height: 380px; }
canvas { display: block; width: 100%; height: 380px; }
.metric-row { display: flex; flex-wrap: wrap; gap: 10px 24px; margin: 18px 0 0; }
.metric-row span { white-space: nowrap; }
.metric-row strong { color: var(--blue); }

.shape-flow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-top: 22px; background: var(--line); border: 1px solid var(--line); }
.shape-flow div { min-height: 132px; padding: 18px; background: #fff; }
.shape-flow span { display: block; color: var(--muted); font-size: 13px; }
.shape-flow strong { display: block; margin-top: 18px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px; }
.quiz-list { display: grid; gap: 10px; margin-top: 22px; }
.quiz-option { display: grid; grid-template-columns: 24px 1fr; gap: 8px; align-items: start; padding: 14px; border: 1px solid var(--line); background: #fff; }
.feedback { min-height: 28px; margin: 16px 0 0; font-weight: 800; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }

.tutor-card { margin-top: 42px; padding: clamp(20px, 4vw, 38px); border: 2px solid var(--ink); background: var(--blue-soft); }
.tutor-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.tutor-heading h2 { margin: 0; font-size: clamp(29px, 4vw, 42px); }
.mastery-chip { flex: 0 0 auto; padding: 6px 9px; border: 1px solid var(--ink); background: #fff; font-size: 12px; font-weight: 800; }
.mastery-chip.pass { border-color: var(--green); background: #eaf7f0; color: var(--green); }
.mastery-chip.revise { border-color: #87621d; background: #fffaf0; color: #765115; }
.tutor-prompt { max-width: 760px; margin: 24px 0; font-size: 18px; }
.tutor-rubric { display: grid; gap: 8px; max-width: 800px; margin: 12px 0 24px; padding-left: 22px; }
.tutor-standard { max-width: 800px; margin: -6px 0 24px; padding: 12px 14px; border-left: 4px solid var(--blue); background: #fff; color: var(--muted); }
.tutor-standard strong { color: var(--ink); }
.tutor-response { display: grid; gap: 8px; font-weight: 800; }
.tutor-response textarea { min-height: 164px; background: #fff; font-weight: 400; }
.draft-row { display: flex; justify-content: space-between; gap: 20px; margin-top: 8px; color: var(--muted); font-size: 13px; }
.tutor-actions { position: sticky; bottom: 0; z-index: 2; display: flex; flex-wrap: wrap; gap: 10px; margin: 20px -8px 0; padding: 10px 8px; background: color-mix(in srgb, var(--blue-soft) 92%, transparent); }
.tutor-actions button:disabled { cursor: not-allowed; opacity: .5; }
.tutor-status { min-height: 24px; margin: 10px 0 0; color: var(--muted); font-weight: 700; }
.tutor-feedback { position: relative; margin-top: 22px; padding: 22px; border: 1px solid var(--line); border-top: 3px solid var(--blue); background: #fff; }
.tutor-feedback[data-outcome="pass"] { border-top-color: var(--green); background: linear-gradient(135deg, #f2faf5, #fff 65%); }
.tutor-feedback[data-outcome="pass"] .feedback-kicker { color: var(--green); }
.tutor-feedback[data-outcome="near-miss"] { border-top-color: #87621d; }
.tutor-feedback[data-outcome="near-miss"] .feedback-kicker { color: #765115; }
.tutor-feedback-next-step { margin: 18px 0 0; padding: 12px 14px; border-left: 3px solid var(--line); background: #f6f7f8; font-size: 15px; line-height: 1.55; }
.tutor-feedback[data-outcome="pass"] .tutor-feedback-next-step { border-left-color: var(--green); background: #eaf7f0; }
.feedback-kicker { margin: 0 0 7px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.tutor-feedback h3 { margin: 0; }
.criterion-list { display: grid; gap: 8px; margin: 20px 0 0; padding: 0; list-style: none; }
.tutor-criteria-details { margin-top: 18px; border-top: 1px solid var(--line); }
.tutor-criteria-details > summary { min-height: 44px; padding: 12px 0; cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 700; }
.tutor-criteria-details > summary:focus-visible { outline: 3px solid #8bb8ff; outline-offset: 3px; }
.tutor-criteria-details[open] > summary { color: var(--ink); }
.tutor-criteria-details .criterion-list { margin-top: 4px; }
.criterion-list li { display: grid; grid-template-columns: 24px 1fr; gap: 8px; align-items: start; }
.criterion-list li strong, .criterion-list li small { display: block; }
.criterion-list li small { margin-top: 3px; color: var(--muted); }
.criterion-status { display: inline-block; margin-top: 2px; color: #765115; font-size: 12px; font-weight: 700; }
.criterion-status.met { color: var(--green); }
.criterion-status.contradicted { color: var(--red); }
.criterion-mark { width: 20px; height: 20px; display: inline-grid; place-items: center; border-radius: 50%; color: #fff; background: var(--red); font-size: 12px; font-weight: 900; }
.criterion-mark.met { background: var(--green); }
.criterion-mark.partial { background: #8a6116; }
.tutor-next-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px; margin-top: 24px; }
.next-lesson-link { display: inline-flex; min-height: 44px; align-items: center; padding: 9px 13px; border: 1px solid var(--ink); background: var(--ink); color: #fff; font-weight: 800; text-decoration: none; }
.next-lesson-link[aria-disabled="true"] { cursor: not-allowed; opacity: .45; }
.tutor-confetti { position: absolute; top: 0; right: 0; width: 160px; height: 125px; overflow: hidden; pointer-events: none; }
.tutor-confetti span { position: absolute; top: 4px; left: 78px; width: 5px; height: 9px; background: #328965; opacity: 0; animation: tutor-confetti-fall 900ms ease-out var(--confetti-delay) both; }
.tutor-confetti span:nth-child(3n) { background: #246fd8; }
.tutor-confetti span:nth-child(3n + 1) { background: #bf933b; }
@keyframes tutor-confetti-fall {
  0% { opacity: 0; transform: translate(0, -8px) rotate(0); }
  15% { opacity: .9; }
  100% { opacity: 0; transform: translate(var(--confetti-x), var(--confetti-y)) rotate(var(--confetti-turn)); }
}

.table-wrap { max-width: 100%; overflow-x: auto; margin-top: 22px; border: 1px solid var(--line); }
table { width: 100%; min-width: 580px; border-collapse: collapse; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--ink); color: #fff; }
tr:last-child td { border-bottom: 0; }
.token-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 24px; }
.token { min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 700; }
.token { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.token small { color: var(--muted); font-size: 11px; }
.token.visible { border-color: var(--blue); background: var(--blue-soft); }
.token.unavailable { color: #7a8088; background: #f4f5f6; text-decoration: line-through; }
.token.attended { background: linear-gradient(90deg, #bcd8ff calc(var(--attention) * 100%), var(--blue-soft) calc(var(--attention) * 100%)); }
.token.selected { border-color: var(--ink); background: var(--ink); color: #fff; }
.token.target { border-color: var(--cyan); background: var(--blue-soft); color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 12px 20px; margin-top: 18px; color: var(--muted); font-size: 14px; }
.legend span::before { width: 13px; height: 13px; display: inline-block; margin-right: 7px; border: 1px solid var(--line); content: ""; vertical-align: -2px; }
.legend .seen::before { background: var(--blue-soft); border-color: var(--blue); }
.legend .chosen::before { background: var(--ink); border-color: var(--ink); }
.legend .answer::before { background: var(--blue-soft); border-color: var(--cyan); }
.module-footer { padding: 22px 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

.index-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 42px; }
.index-card { min-height: 240px; display: grid; align-content: start; padding: 24px; border-top: 3px solid var(--blue); background: var(--soft); }
.index-card > span { color: var(--blue); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.index-card h2 { margin: 22px 0 10px; font-size: 29px; }
.index-card p { color: var(--muted); }
.index-card a { align-self: end; font-weight: 800; }

.lesson-map { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin: 36px 0 0; border: 1px solid var(--line); background: var(--line); }
.lesson-map div { min-width: 0; padding: 16px; background: #fff; }
.lesson-map span { display: block; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.lesson-map strong { display: block; margin-top: 7px; line-height: 1.2; }

.lesson-step { margin-top: 58px; padding-top: 26px; border-top: 3px solid var(--ink); }
.step-kicker, .example-label, .check-label, .production-label { margin: 0 0 8px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.lesson-step > h2 { max-width: 820px; margin: 0 0 18px; }
.lesson-step > p, .concept-copy { max-width: 780px; font-size: 18px; }
.concept-copy p { margin: 0 0 14px; }
.concept-copy strong { color: var(--ink); }

.definition-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin-top: 24px; border: 1px solid var(--line); background: var(--line); }
.definition-grid > div { min-width: 0; padding: 18px; background: #fff; }
.definition-grid dt { font-weight: 800; }
.definition-grid dd { margin: 6px 0 0; color: var(--muted); }
.symbol { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--blue); }

.worked-example { margin-top: 24px; padding: clamp(18px, 3vw, 28px); border-left: 5px solid var(--blue); background: var(--soft); }
.worked-example h3 { margin: 0 0 12px; }
.worked-example p:last-child { margin-bottom: 0; }
.formula-line { margin: 15px 0; padding: 14px; border: 1px solid var(--line); background: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: clamp(15px, 2vw, 20px); overflow-x: auto; }
.trace-list { display: grid; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.trace-list li { display: grid; grid-template-columns: minmax(92px, .35fr) minmax(0, 1fr); gap: 14px; padding-top: 8px; border-top: 1px solid var(--line); }
.trace-list strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.quick-check { margin-top: 24px; padding: clamp(18px, 3vw, 26px); border: 1px solid var(--line); background: #fff; }
.quick-check h3 { margin: 0 0 10px; }
.quick-check > p:not(.check-label):not(.feedback) { max-width: 760px; }
.quick-check .button-row { margin-top: 16px; }
.quick-check.is-correct { border-color: var(--green); background: #f4fbf7; }
.quick-check.is-incorrect { border-color: #bd8b2c; background: #fffaf0; }
.feedback.neutral { color: var(--muted); }

.production-note { margin-top: 24px; padding: clamp(18px, 3vw, 26px); border: 1px solid var(--ink); background: var(--ink); color: #fff; }
.production-note .production-label { color: var(--cyan); }
.production-note h3 { color: #fff; }
.production-note p { max-width: 800px; margin-bottom: 0; color: #e8ebef; }
.production-note code { color: #fff; }

.code-bridge { margin-top: 24px; border: 1px solid var(--line); }
.code-bridge header { padding: 10px 14px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 800; }
.code-bridge pre { max-width: 100%; margin: 0; padding: 18px; overflow-x: auto; background: #f7f8f9; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.55; }
.code-bridge p { margin: 0; padding: 13px 18px; border-top: 1px solid var(--line); color: var(--muted); }

.lesson-summary { margin-top: 54px; padding: clamp(20px, 4vw, 34px); background: var(--soft); }
.lesson-summary h2 { margin: 0 0 15px; }
.lesson-summary ul { margin-bottom: 0; }
.next-step-card { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-top: 34px; padding: 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.next-step-card p { margin: 0; color: var(--muted); }
.next-step-card .step-kicker { margin-bottom: 7px; color: var(--blue); }
.next-step-card strong { display: block; font-size: 22px; line-height: 1.15; }
.next-step-card div > p:last-child { margin-top: 7px; }
.next-step-card a { flex: 0 0 auto; font-weight: 800; }
.quiet-note { color: var(--muted); font-size: 14px; }

@media (max-width: 760px) {
  .module-nav { align-items: flex-start; flex-direction: column; padding-right: max(16px, env(safe-area-inset-right)); padding-left: max(16px, env(safe-area-inset-left)); }
  .module-context { width: 100%; }
  .breadcrumbs, .module-links { justify-content: flex-start; }
  .module-main { padding-top: 42px; }
  .workbench-grid, .index-grid, .definition-grid { grid-template-columns: minmax(0, 1fr); }
  .lesson-map { grid-template-columns: 1fr; }
  .module-sequence { grid-template-columns: 1fr; }
  .module-sequence a { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .module-sequence a:last-child { border-bottom: 0; }
  .module-sequence strong { margin-top: 5px; }
  .shape-flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .module-links { gap: 10px 14px; font-size: 13px; }
  .tutor-heading { display: grid; }
  .mastery-chip { justify-self: start; }
  .tutor-actions button { flex: 1 1 150px; }
  .tutor-actions { position: static; }
  .tutor-next-row { align-items: stretch; }
  .tutor-next-row > * { width: 100%; justify-content: center; text-align: center; }
  .trace-list li { grid-template-columns: 1fr; gap: 3px; }
  .next-step-card { align-items: flex-start; flex-direction: column; }
  .next-step-card a { width: 100%; min-height: 44px; display: inline-flex; align-items: center; }
  table { min-width: 520px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .tutor-confetti { display: none; }
  .tutor-confetti span { animation: none; }
}
