:root {
  --paper: #f4f1e8;
  --surface: #fffdf8;
  --ink: #17211b;
  --muted: #667067;
  --line: #d8d3c6;
  --forest: #245642;
  --forest-dark: #143b2c;
  --moss: #76915c;
  --sage: #dce5d4;
  --amber: #e6a844;
  --amber-soft: #f9ebcb;
  --blue: #3f6f7a;
  --blue-soft: #dce9eb;
  --danger: #a34137;
  --ok: #2f7651;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }

html { min-width: 320px; scroll-behavior: smooth; }

body { margin: 0; min-height: 100vh; overflow-x: hidden; background: var(--paper); }

button, input { font: inherit; }

button { cursor: pointer; }

.skip-link {
  position: fixed;
  left: 16px;
  top: -60px;
  z-index: 10;
  padding: 10px 14px;
  background: var(--ink);
  color: white;
}

.skip-link:focus { top: 12px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand-block { display: flex; align-items: center; gap: 13px; min-width: 0; }

.course-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  background: var(--forest);
  color: white;
  font-family: Georgia, serif;
  font-weight: 700;
}

.eyebrow, .nav-label {
  margin: 0 0 4px;
  color: var(--forest);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(22px, 2.5vw, 31px); }

.header-progress { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }

.progress-track { width: 118px; height: 5px; background: #e5e1d8; }

.progress-track span { display: block; width: 25%; height: 100%; background: var(--forest); transition: width .25s ease; }

.app-layout {
  display: grid;
  grid-template-columns: 210px minmax(480px, 1fr) 370px;
  min-height: calc(100vh - 82px);
}

.lesson-nav, .control-room { background: var(--surface); }

.lesson-nav { padding: 30px 18px; border-right: 1px solid var(--line); }

.nav-label { padding-left: 10px; margin-bottom: 14px; }

#lessonNav { display: grid; gap: 5px; }

.nav-button {
  display: grid;
  grid-template-columns: 27px 1fr;
  gap: 8px;
  width: 100%;
  padding: 12px 10px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-button:hover { background: #f5f3ec; color: var(--ink); }

.nav-button.active { border-left-color: var(--forest); background: var(--sage); color: var(--forest-dark); font-weight: 750; }

.nav-index { font-variant-numeric: tabular-nums; color: var(--moss); }

.source-note { margin: 30px 10px 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.45; }

.source-number { display: block; color: var(--forest-dark); font-family: Georgia, serif; font-size: 30px; font-weight: 700; }

.lesson { width: 100%; min-width: 0; padding: clamp(28px, 4vw, 58px); overflow: hidden; }

.lesson-inner { max-width: 850px; min-width: 0; margin: 0 auto; }

.lesson-kicker { margin-bottom: 8px; color: var(--moss); font-size: 13px; font-weight: 800; }

.lesson h2 { max-width: 760px; margin-bottom: 14px; font-family: Georgia, serif; font-size: clamp(31px, 4vw, 50px); line-height: 1.05; letter-spacing: -.02em; }

.lead { max-width: 720px; color: #4f5a52; font-size: 17px; line-height: 1.65; }

.concept-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 28px 0; }

.concept-card { min-width: 0; padding: 18px; border-top: 4px solid var(--moss); background: var(--surface); box-shadow: 0 8px 26px rgba(31, 45, 35, .07); overflow-wrap: anywhere; }

.concept-card:nth-child(2) { border-color: var(--amber); }
.concept-card:nth-child(3) { border-color: var(--blue); }
.concept-card h3 { margin-bottom: 7px; font-size: 16px; }
.concept-card p { margin-bottom: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.visual-panel { max-width: 100%; margin-top: 28px; padding: 22px; border: 1px solid var(--line); background: var(--surface); overflow: hidden; }

.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.panel-head > * { min-width: 0; }
.panel-head h3 { margin-bottom: 4px; font-family: Georgia, serif; font-size: 21px; }
.panel-head p { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.secondary-button, .primary-button, .reset-button, .choice-button {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}

.secondary-button { min-height: 38px; padding: 0 12px; white-space: nowrap; }
.secondary-button:hover, .reset-button:hover { border-color: var(--forest); }

.age-chart { display: grid; grid-template-columns: repeat(10, 1fr); align-items: end; gap: 7px; height: 210px; padding-top: 20px; border-bottom: 2px solid var(--ink); }

.age-column { display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; height: 100%; min-width: 0; }
.age-bar { position: relative; min-height: 8px; background: var(--moss); transition: height .35s ease, background .25s ease; }
.age-column:first-child .age-bar { background: var(--amber); }
.age-value { margin-bottom: 5px; color: var(--muted); font-size: 10px; text-align: center; }
.age-label { padding-top: 7px; color: var(--muted); font-size: 10px; text-align: center; white-space: nowrap; }

.chart-caption { display: flex; justify-content: space-between; gap: 16px; margin-top: 12px; color: var(--muted); font-size: 12px; }

.formula-stage { display: grid; grid-template-columns: 1.1fr .9fr; gap: 20px; margin-top: 28px; }
.formula-card, .result-card { padding: 22px; border: 1px solid var(--line); background: var(--surface); }
.formula-card { border-top: 4px solid var(--amber); }
.result-card { border-top: 4px solid var(--forest); }
.equation { margin: 16px 0; font-family: Georgia, serif; font-size: clamp(20px, 3vw, 30px); line-height: 1.4; }
.fraction { display: inline-grid; vertical-align: middle; text-align: center; }
.fraction span:first-child { padding: 0 8px 3px; border-bottom: 1px solid currentColor; }
.fraction span:last-child { padding-top: 3px; }
.result-number { color: var(--forest); font-family: Georgia, serif; font-size: clamp(40px, 6vw, 64px); line-height: 1; }
.result-unit { color: var(--muted); font-size: 14px; }

.input-row { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 10px; margin: 12px 0; }
.input-row label { color: var(--muted); font-size: 13px; }
.input-row input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.input-row input:focus { outline: 2px solid var(--amber); outline-offset: 1px; }

.inventory-table { width: 100%; margin-top: 20px; border-collapse: collapse; font-size: 13px; }
.inventory-table th, .inventory-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: right; }
.inventory-table th:first-child, .inventory-table td:first-child { text-align: left; }
.inventory-table thead { color: var(--muted); }
.inventory-table tfoot { font-weight: 800; }

.yield-example-button {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 3px 5px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.yield-example-button span { color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; }
.yield-example-button:hover, .yield-example-button.active { border-bottom-color: var(--blue); color: var(--blue); }

.yield-explainer {
  margin-top: 20px;
  padding: 20px;
  border-left: 4px solid var(--blue);
  background: var(--blue-soft);
}

.yield-explainer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.yield-explainer-head h4 { margin: 0; font-family: Georgia, serif; font-size: 21px; }
.yield-badge { padding: 7px 9px; border: 1px solid #9bb9bf; color: #285866; font-size: 12px; font-weight: 800; white-space: nowrap; }
.yield-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 17px; }
.yield-steps > div { display: grid; grid-template-columns: 24px 1fr; gap: 8px; min-width: 0; }
.yield-steps p { margin: 0; color: #43575b; font-size: 11px; line-height: 1.45; }
.yield-steps strong, .yield-steps code { display: block; }
.yield-steps strong { margin-bottom: 6px; color: var(--ink); }
.yield-steps code { color: #24525d; font-family: "Segoe UI Symbol", "Cambria Math", Georgia, serif; font-size: 12px; white-space: normal; }
.step-number { display: grid; place-items: center; width: 24px; height: 24px; background: var(--blue); color: white; font-size: 11px; font-weight: 800; }
.yield-why { margin: 17px 0 0; padding-top: 13px; border-top: 1px solid #b9cfd3; color: #43575b; font-size: 11px; line-height: 1.55; }

.flow-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 18px; }
.flow-block { padding: 12px 7px; background: var(--blue-soft); text-align: center; }
.flow-block strong, .flow-block span { display: block; }
.flow-block strong { color: var(--blue); font-size: 15px; }
.flow-block span { margin-top: 3px; color: var(--muted); font-size: 10px; }

.comparison-table { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 28px 0; }
.comparison-card { padding: 22px; border: 1px solid var(--line); background: var(--surface); }
.comparison-card.area { border-top: 5px solid var(--amber); }
.comparison-card.volume { border-top: 5px solid var(--blue); }
.comparison-card h3 { font-family: Georgia, serif; font-size: 24px; }
.comparison-card dl { margin: 0; }
.comparison-card dl div { display: grid; grid-template-columns: 90px 1fr; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.comparison-card dt { color: var(--muted); font-size: 12px; }
.comparison-card dd { margin: 0; font-size: 13px; line-height: 1.45; }

.problem-ribbon {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 28px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.problem-ribbon div { padding: 15px 12px; }
.problem-ribbon div + div { border-left: 1px solid var(--line); }
.problem-ribbon span, .problem-ribbon strong { display: block; }
.problem-ribbon span { margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.problem-ribbon strong { color: var(--forest-dark); font-family: Georgia, serif; font-size: 18px; }

.variable-definition {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--sage);
}

.variable-definition strong { color: var(--forest-dark); font-family: Georgia, serif; font-size: 31px; }
.variable-definition span { color: #3f4d43; font-size: 14px; }

.decision-matrix {
  display: grid;
  grid-template-columns: 52px repeat(5, minmax(52px, 1fr));
  gap: 1px;
  margin-top: 16px;
  background: var(--line);
  border: 1px solid var(--line);
}

.decision-matrix > * { display: grid; place-items: center; min-height: 40px; background: var(--surface); font-size: 12px; }
.decision-matrix b { background: #f0ede5; color: var(--muted); }
.decision-matrix span { color: var(--forest-dark); font-family: Georgia, serif; font-size: 15px; }
.model-note { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.lp-browser { margin-top: 28px; padding: 22px; background: var(--forest-dark); color: white; }
.lp-browser .panel-head p { color: #b9c9bf; }
.lp-tabs { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid #527062; }
.lp-tabs button { min-height: 58px; padding: 8px 6px; border: 0; background: transparent; color: #d7e2db; font-size: 11px; font-weight: 800; }
.lp-tabs button + button { border-left: 1px solid #527062; }
.lp-tabs button span { display: block; margin-bottom: 3px; color: #9fb4a8; font-size: 9px; text-transform: uppercase; }
.lp-tabs button:hover { background: rgba(255,255,255,.06); }
.lp-tabs button.active { background: var(--surface); color: var(--forest-dark); }
.lp-tabs button.active span { color: var(--moss); }

.lp-equation-panel {
  display: grid;
  grid-template-columns: .85fr 1.15fr;
  gap: 24px;
  min-height: 215px;
  padding: 24px 4px 4px;
}

.lp-equation-panel h3 { margin-bottom: 8px; font-family: Georgia, serif; font-size: 23px; }
.lp-equation-panel p:not(.eyebrow) { margin-bottom: 0; color: #c6d4cb; font-size: 13px; line-height: 1.55; }
.equation-stack { display: grid; align-content: center; gap: 12px; }
.equation-stack code { padding: 19px; border-left: 4px solid var(--amber); background: rgba(255,255,255,.08); color: white; font-family: Georgia, serif; font-size: clamp(18px, 2.2vw, 25px); line-height: 1.45; white-space: normal; }
.equation-stack span { color: #f0d99f; font-size: 12px; }
.full-model { margin-top: 18px; border-top: 1px solid #527062; }
.full-model summary { padding: 15px 2px 2px; color: #f0d99f; font-size: 12px; font-weight: 800; cursor: pointer; }
.full-model-body { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 18px 0 5px; }
.full-model-body section { min-width: 0; padding: 16px; background: rgba(255,255,255,.06); }
.full-model-body h4 { margin: 0 0 10px; font-family: Georgia, serif; font-size: 16px; }
.full-model-body code { display: block; color: #e5eee8; font-family: "Segoe UI Symbol", "Cambria Math", Georgia, serif; font-size: 11px; line-height: 1.65; white-space: normal; }
.yield-matrix th:not(:first-child), .yield-matrix td:not(:first-child) { text-align: center; }
.lp-check { margin-top: 28px; }

.quiz-card { padding: 22px; background: var(--forest-dark); color: white; }
.quiz-card p { color: #dce7df; }
.quiz-options { display: grid; gap: 8px; }
.choice-button { padding: 11px 13px; border-color: #5d796a; background: transparent; color: white; text-align: left; }
.choice-button:hover { background: rgba(255,255,255,.08); }
.choice-button.correct { border-color: #9ed1af; background: #2f6a4a; }
.choice-button.incorrect { border-color: #ef9f8f; background: #713a34; }
.quiz-feedback { min-height: 24px; margin: 12px 0 0; color: #f4e2aa !important; font-size: 13px; }

.control-room { padding: 26px 22px; border-left: 1px solid var(--line); }
.control-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.control-heading h2 { margin-bottom: 0; font-family: Georgia, serif; font-size: 22px; }
.reset-button { padding: 7px 10px; color: var(--muted); }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; margin: 22px 0 16px; border: 1px solid var(--line); }
.mode-switch button { min-height: 42px; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 800; }
.mode-switch button + button { border-left: 1px solid var(--line); }
.mode-switch button.active[data-mode="area"] { background: var(--amber-soft); color: #714d10; }
.mode-switch button.active[data-mode="volume"] { background: var(--blue-soft); color: #25545e; }

.workspace-callout { padding: 14px; border-left: 4px solid var(--amber); background: #f7f3e9; color: var(--muted); font-size: 12px; line-height: 1.5; }
.workspace-callout strong { display: block; color: var(--ink); font-size: 15px; }

.period-planner { margin-top: 18px; }
.planner-legend { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.planner-legend strong { color: var(--ink); text-align: right; }
.period-row { display: grid; grid-template-columns: 27px 1fr 118px; align-items: center; gap: 9px; margin: 13px 0; }
.period-row label { color: var(--muted); font-size: 12px; }
.period-row input { width: 100%; accent-color: var(--forest); }
.period-output { font-variant-numeric: tabular-nums; font-size: 10px; line-height: 1.25; text-align: right; }

.workspace-summary { margin: 20px 0 14px; border-top: 1px solid var(--line); }
.summary-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.summary-row strong { font-variant-numeric: tabular-nums; }
.summary-row.pass strong { color: var(--ok); }
.summary-row.fail strong { color: var(--danger); }
.primary-button { width: 100%; min-height: 44px; border-color: var(--forest); background: var(--forest); color: white; }
.primary-button:hover { background: var(--forest-dark); }

.next-row { display: flex; justify-content: flex-end; margin-top: 28px; }
.next-button { padding: 11px 17px; border: 0; background: var(--ink); color: white; font-weight: 800; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 14px 28px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

@media (max-width: 1120px) {
  .app-layout { grid-template-columns: 180px minmax(460px, 1fr); }
  .control-room { grid-column: 1 / -1; border-top: 1px solid var(--line); border-left: 0; }
  .period-planner { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
  .planner-legend { grid-column: 1 / -1; }
  .period-row { grid-template-columns: 1fr; }
  .period-row input { width: 100%; }
}

@media (max-width: 720px) {
  .topbar { align-items: flex-start; padding: 15px 16px; }
  .header-progress { display: none; }
  .app-layout { display: block; }
  .lesson-nav { position: sticky; top: 0; z-index: 5; width: 100vw; max-width: 100vw; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .nav-label, .source-note { display: none; }
  #lessonNav { display: flex; width: max-content; }
  .nav-button { grid-template-columns: auto auto; width: auto; padding: 9px 11px; border-left: 0; border-bottom: 3px solid transparent; }
  .nav-button.active { border-left-color: transparent; border-bottom-color: var(--forest); }
  .lesson { width: 100vw; max-width: 100vw; padding: 30px 17px; }
  .lesson-inner, .concept-grid { width: 100%; max-width: 100%; }
  .lesson h2 { font-size: 32px; }
  .concept-grid, .formula-stage, .comparison-table { grid-template-columns: 1fr; }
  .yield-steps { grid-template-columns: 1fr; }
  .yield-explainer-head { display: block; }
  .yield-badge { display: inline-block; margin-top: 10px; }
  .problem-ribbon { grid-template-columns: 1fr 1fr; }
  .problem-ribbon div + div { border-left: 0; }
  .problem-ribbon div:nth-child(even) { border-left: 1px solid var(--line); }
  .problem-ribbon div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .variable-definition { align-items: flex-start; }
  .decision-matrix { grid-template-columns: 38px repeat(5, minmax(42px, 1fr)); overflow-x: auto; }
  .lp-tabs { grid-template-columns: 1fr; }
  .lp-tabs button { min-height: 42px; text-align: left; padding: 8px 12px; }
  .lp-tabs button + button { border-top: 1px solid #527062; border-left: 0; }
  .lp-tabs button span { display: inline; margin-right: 8px; }
  .lp-equation-panel { grid-template-columns: 1fr; min-height: 0; }
  .full-model-body { grid-template-columns: 1fr; }
  .age-chart { gap: 3px; height: 170px; }
  .age-value { display: none; }
  .age-label { font-size: 8px; }
  .panel-head { display: block; }
  .panel-head .secondary-button { margin-top: 14px; }
  .control-room { width: 100vw; max-width: 100vw; padding: 24px 17px; }
  .period-planner { display: block; }
  .period-row { grid-template-columns: 27px 1fr 118px; }
  footer { display: block; padding: 14px 17px; }
  footer span { display: block; margin: 4px 0; }
}

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