:root {
  --bg: #f7f9fc;
  --paper: #ffffff;
  --ink: #172033;
  --muted: #5d6b82;
  --line: #d8e0ec;
  --blue: #1e40af;
  --teal: #0f9f9a;
  --yellow: #f4b740;
  --coral: #ef6a5b;
  --green: #258a4b;
  --red: #be3434;
  --shadow: 0 18px 45px rgba(33, 50, 82, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #eef6ff 0, var(--bg) 360px),
    var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
}

button, input { font: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(18px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

nav a {
  color: var(--ink);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 650;
  font-size: 0.95rem;
}

nav a:hover, nav a.active {
  border-color: #bfd0eb;
  background: #edf4ff;
  color: var(--blue);
}

.home-grid, .lesson-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.home-grid {
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 28px;
  align-items: stretch;
  padding: 54px 0;
}

.intro-panel, .lesson-band, .panel, .lesson-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-panel {
  padding: clamp(28px, 5vw, 54px);
}

.small-label {
  margin: 0 0 12px;
  color: var(--teal);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 1.02;
  margin-bottom: 20px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.25rem, 2vw, 1.65rem);
}

p {
  color: var(--muted);
  line-height: 1.6;
}

.lesson-picker {
  display: grid;
  gap: 18px;
}

.lesson-card {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 18px;
  align-content: start;
  padding: 26px;
  color: inherit;
  text-decoration: none;
  transition: transform 180ms ease, border-color 180ms ease;
}

.lesson-card-copy {
  display: grid;
  gap: 10px;
}

.lesson-card-copy h2,
.lesson-card-copy p {
  margin-bottom: 0;
}

.unit-line span {
  white-space: nowrap;
  font-weight: 750;
  color: #31506f;
}

.lesson-card:hover {
  transform: translateY(-3px);
  border-color: #9eb8df;
}

.card-icon {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 8px;
  background: #e8f7f6;
  color: var(--teal);
  font-size: 2rem;
  font-weight: 900;
}

.accelerated .card-icon {
  background: #fff3dc;
  color: #b87300;
}

.reaction .card-icon {
  background: #fff0ee;
  color: var(--coral);
}

.card-action {
  grid-column: 2;
  color: var(--blue);
  font-weight: 800;
}

.lesson-band {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 390px);
  gap: 24px;
  align-items: center;
  margin: 28px 0;
  padding: clamp(24px, 4vw, 42px);
  border-left: 8px solid var(--teal);
}

.accelerated-band { border-left-color: var(--yellow); }
.reaction-band { border-left-color: var(--coral); }

.formula-spotlight {
  display: grid;
  gap: 10px;
  padding: 24px;
  border-radius: 8px;
  color: white;
  background: linear-gradient(135deg, var(--blue), #13276d);
}

.formula-spotlight > span {
  font-size: clamp(1.75rem, 4vw, 2.55rem);
  font-weight: 900;
}

.formula-spotlight small {
  color: #d8e4ff;
  font-weight: 700;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding-bottom: 46px;
}

.panel {
  padding: 22px;
}

.wide { grid-column: 1 / -1; }

.formula-list, .target-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.formula-pill, .target-buttons button, .primary, .secondary {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 750;
}

.math-inline, .math-display {
  display: inline;
  white-space: nowrap;
}

.math-display {
  font-size: clamp(1.75rem, 4vw, 2.55rem);
  font-weight: 900;
}

.frac {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  min-width: 1.15em;
  margin: 0 0.08em;
  line-height: 1.05;
  vertical-align: middle;
}

.frac > span {
  display: block;
  width: 100%;
  padding: 0 0.16em;
  text-align: center;
}

.frac > span:first-child {
  border-bottom: 0.09em solid currentColor;
  padding-bottom: 0.08em;
}

.frac > span:last-child {
  padding-top: 0.08em;
}

.root {
  display: inline-block;
  border-top: 0.08em solid currentColor;
  margin-left: 0.08em;
  padding: 0.04em 0 0 0.12em;
}

.unit-frac {
  font-size: 0.82em;
  font-weight: 850;
  color: inherit;
  transform: translateY(0.06em);
}

.formula-pill .frac,
.formula-info .frac,
.step .frac,
.answer .frac {
  font-size: 0.9em;
}

.formula-pill:hover, .target-buttons button:hover, .secondary:hover {
  border-color: #95add1;
  background: #f4f8ff;
}

.formula-pill.selected, .target-buttons button.selected {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.formula-info {
  display: grid;
  gap: 7px;
  margin: -4px 0 18px;
  padding: 14px;
  border: 1px solid #bcd0ef;
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  background: #f6faff;
  color: var(--ink);
  line-height: 1.45;
}

.formula-info strong {
  color: var(--blue);
  font-size: 1.25rem;
}

.formula-info span {
  color: var(--muted);
}

.formula-info em {
  color: #31506f;
  font-style: normal;
  font-weight: 750;
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.unit-grid.four { grid-template-columns: repeat(4, 1fr); }

.unit-grid div, .steps, .answer {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f9fbff;
}

.unit-grid div {
  display: grid;
  gap: 5px;
  padding: 14px;
}

.unit-grid strong {
  color: var(--blue);
  font-size: 1.6rem;
}

.unit-grid span {
  color: var(--muted);
  font-size: 0.9rem;
}

.hint {
  margin: 16px 0 0;
  padding-left: 12px;
  border-left: 4px solid var(--yellow);
}

.steps {
  display: grid;
  gap: 10px;
  padding: 15px;
}

.step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.step-number {
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  height: 28px;
  border-radius: 50%;
  background: #e8f7f6;
  color: #08716d;
  font-weight: 900;
}

.panel-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

output {
  color: var(--blue);
  font-weight: 800;
}

.sim-layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 20px;
  align-items: start;
}

.controls {
  display: grid;
  gap: 15px;
}

.control {
  display: grid;
  gap: 8px;
}

.control label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 750;
}

input[type="range"] { width: 100%; accent-color: var(--blue); }

.track {
  position: relative;
  height: 54px;
  margin-bottom: 14px;
  border-radius: 8px;
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, rgba(30,64,175,0.12) 0 2px, transparent 2px 64px),
    linear-gradient(180deg, #edf5ff, #fff);
  border: 1px solid var(--line);
}

.runner {
  position: absolute;
  top: 12px;
  left: 8px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--coral);
  box-shadow: 0 7px 16px rgba(239, 106, 91, 0.35);
  transition: left 180ms ease;
}

.two-bodies .runner {
  display: grid;
  place-items: center;
  width: 64px;
  color: white;
  font-size: 0.85rem;
  font-weight: 900;
}

.two-bodies .body-b {
  right: 8px;
  left: auto;
  background: var(--teal);
  box-shadow: 0 7px 16px rgba(15, 159, 154, 0.28);
}

canvas {
  width: 100%;
  min-height: 230px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.calc-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 750;
}

.calc-grid input, .practice-row input {
  width: 100%;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid #c5d1e1;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
}

.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.primary:hover { background: #163487; }

.secondary {
  background: #edf4ff;
}

.answer {
  margin-top: 14px;
  padding: 14px;
  min-height: 52px;
  line-height: 1.55;
}

.answer.good {
  border-color: #a5d8b7;
  background: #f0fbf4;
  color: var(--green);
}

.answer.bad {
  border-color: #f0b5b5;
  background: #fff4f4;
  color: var(--red);
}

.practice-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
}

@media (max-width: 860px) {
  .site-header, .home-grid, .lesson-band, .content-grid, .sim-layout {
    grid-template-columns: 1fr;
  }

  .site-header {
    display: grid;
    align-items: start;
  }

  .content-grid, .home-grid { gap: 14px; }
  .unit-grid, .unit-grid.four, .calc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .practice-row { grid-template-columns: 1fr auto; }
}

@media (max-width: 520px) {
  .unit-grid, .unit-grid.four, .calc-grid, .practice-row { grid-template-columns: 1fr; }
  .lesson-card { grid-template-columns: 1fr; }
  .card-action { grid-column: 1; }
  h1 { font-size: 2.15rem; }
}
