: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: 1.7rem;
  font-weight: 900;
}

.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);
}

.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-flex;
  align-items: center;
  gap: 0.18em;
  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;
}

.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); }

.spring-lab {
  position: relative;
  height: 260px;
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(15, 159, 154, 0.1) 0 1px, transparent 1px 100%),
    repeating-linear-gradient(0deg, rgba(30, 64, 175, 0.08) 0 1px, transparent 1px 32px),
    linear-gradient(180deg, #edf5ff, #fff);
}

.support {
  position: absolute;
  top: 24px;
  left: 50%;
  width: min(340px, 70%);
  height: 14px;
  border-radius: 8px;
  background: #172033;
  transform: translateX(-50%);
}

.spring {
  position: absolute;
  top: 38px;
  left: 50%;
  width: 72px;
  height: 92px;
  transform: translateX(-50%);
  background:
    repeating-linear-gradient(180deg, transparent 0 9px, var(--teal) 9px 13px, transparent 13px 22px);
  border-left: 3px solid var(--teal);
  border-right: 3px solid var(--teal);
  border-radius: 20px;
  transition: height 180ms ease;
}

.mass {
  position: absolute;
  left: 50%;
  top: 128px;
  display: grid;
  place-items: center;
  width: 92px;
  height: 58px;
  color: white;
  background: var(--coral);
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(239, 106, 91, 0.28);
  font-weight: 900;
  transform: translateX(-50%);
  transition: top 180ms ease;
}

.force-arrow {
  position: absolute;
  left: calc(50% + 72px);
  top: 124px;
  color: var(--blue);
  font-weight: 900;
  transition: top 180ms ease;
}

.force-arrow::before {
  content: "";
  position: absolute;
  left: 14px;
  bottom: 22px;
  width: 4px;
  height: 44px;
  background: var(--blue);
}

.force-arrow::after {
  content: "";
  position: absolute;
  left: 7px;
  bottom: 62px;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 14px solid var(--blue);
}

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; }
  .spring-lab { height: 230px; }
  .force-arrow { left: calc(50% + 54px); }
}

.lesson-band {
  border-left-color: var(--green);
}

.card-icon {
  background: #f0fbf4;
  color: var(--green);
  font-size: 1.45rem;
}

.formula-info {
  border-left-color: var(--green);
}

.energy-lab {
  position: relative;
  height: 260px;
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, rgba(30, 64, 175, 0.08) 0 2px, transparent 2px 52px),
    #ffffff;
}

.ground-line {
  position: absolute;
  left: 30px;
  right: 30px;
  bottom: 42px;
  height: 4px;
  background: #172033;
  border-radius: 8px;
}

.height-scale {
  position: absolute;
  left: 58px;
  bottom: 42px;
  width: 34px;
  height: var(--height-px, 120px);
  border-left: 4px solid var(--green);
  color: var(--green);
  font-weight: 900;
  transition: height 180ms ease;
}

.height-scale::before,
.height-scale::after {
  content: "";
  position: absolute;
  left: -10px;
  width: 16px;
  height: 4px;
  background: currentColor;
}

.height-scale::before { top: 0; }
.height-scale::after { bottom: 0; }

.height-scale span {
  position: absolute;
  top: 50%;
  left: 10px;
  transform: translateY(-50%);
}

.energy-body {
  position: absolute;
  left: 38%;
  bottom: calc(42px + var(--height-px, 120px));
  display: grid;
  place-items: center;
  width: 92px;
  height: 58px;
  color: white;
  background: var(--coral);
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(239, 106, 91, 0.28);
  font-weight: 900;
  transform: translate(-50%, 0);
  transition: bottom 180ms ease, width 180ms ease;
}

.velocity-arrow {
  position: absolute;
  left: calc(38% + 54px);
  bottom: calc(42px + var(--height-px, 120px) + 23px);
  min-width: 80px;
  padding-left: calc(var(--velocity-width, 58px) + 22px);
  color: var(--blue);
  font-weight: 900;
  transition: bottom 180ms ease;
}

.velocity-arrow::before {
  content: "";
  position: absolute;
  left: 0;
  top: 11px;
  width: var(--velocity-width, 58px);
  height: 4px;
  background: currentColor;
}

.velocity-arrow::after {
  content: "";
  position: absolute;
  left: var(--velocity-width, 58px);
  top: 4px;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 14px solid currentColor;
}

.energy-bars {
  position: absolute;
  right: 28px;
  bottom: 42px;
  display: grid;
  grid-template-columns: 78px 78px;
  gap: 12px;
  align-items: end;
  height: 176px;
}

.energy-bar {
  position: relative;
  display: grid;
  align-items: end;
  min-height: 28px;
  height: var(--bar-height, 40px);
  padding: 8px;
  border-radius: 8px 8px 0 0;
  color: white;
  font-weight: 900;
  transition: height 180ms ease;
}

.energy-bar.ep { background: var(--green); }
.energy-bar.ek { background: var(--blue); }

.energy-bar span {
  position: absolute;
  top: -28px;
  left: 0;
  color: #172033;
}

.energy-bar b {
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  .energy-lab { height: 310px; }
  .energy-body { left: 44%; }
  .velocity-arrow { left: calc(44% + 48px); }
  .energy-bars {
    right: 16px;
    grid-template-columns: 62px 62px;
  }
}

.kinetic-lab .energy-body {
  bottom: 46px;
}

.energy-bar.dimmed {
  opacity: 0.28;
}

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

.rule-strip div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf7;
  padding: 14px;
  display: grid;
  gap: 6px;
}

.rule-strip strong {
  color: #7c2d12;
}

.rule-strip span {
  color: var(--muted);
  font-size: 0.95rem;
}

.conservation-lab {
  position: relative;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(124, 45, 18, 0.08) 1px, transparent 1px) 0 0 / 56px 56px,
    linear-gradient(180deg, rgba(15, 118, 110, 0.08) 1px, transparent 1px) 0 0 / 56px 56px,
    #ffffff;
  overflow: hidden;
  --cart-x: 44%;
  --cart-y: 120px;
  --speed-width: 72px;
}

.track {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 44px;
  height: 150px;
  border-bottom: 5px solid #1f2937;
  border-left: 5px solid #1f2937;
  transform: skewY(-15deg);
  transform-origin: left bottom;
}

.start-marker,
.current-marker {
  position: absolute;
  font-weight: 850;
  color: #7c2d12;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
}

.start-marker {
  left: 8%;
  top: 32px;
}

.current-marker {
  left: calc(var(--cart-x) - 12px);
  top: calc(var(--cart-y) - 44px);
  color: #0f766e;
}

.cart {
  position: absolute;
  left: var(--cart-x);
  top: var(--cart-y);
  width: 78px;
  height: 48px;
  border-radius: 8px;
  background: #f97316;
  color: #fff;
  font-weight: 850;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 18px rgba(249, 115, 22, 0.24);
}

.cart::before,
.cart::after {
  content: "";
  position: absolute;
  bottom: -9px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #111827;
}

.cart::before { left: 12px; }
.cart::after { right: 12px; }

.speed-arrow {
  position: absolute;
  left: calc(var(--cart-x) + 82px);
  top: calc(var(--cart-y) + 16px);
  width: var(--speed-width);
  height: 4px;
  background: #1e40af;
  color: #1e40af;
  font-weight: 850;
  line-height: 1;
  padding-left: calc(var(--speed-width) + 14px);
}

.speed-arrow::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -7px;
  border-left: 16px solid #1e40af;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

.energy-stack {
  margin: 14px 0;
  display: grid;
  gap: 9px;
}

.stack-row {
  display: grid;
  grid-template-columns: 72px 1fr 76px;
  gap: 10px;
  align-items: center;
  font-weight: 800;
}

.stack-row span {
  color: var(--ink);
}

.stack-row div {
  height: 18px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
  border: 1px solid var(--line);
}

.stack-row i {
  display: block;
  height: 100%;
  width: 0%;
  background: #258a4b;
}

.stack-row:nth-child(2) i { background: #1e40af; }
.stack-row.loss i { background: #dc2626; }

.stack-row.loss {
  color: #991b1b;
}

@media (max-width: 760px) {
  .rule-strip {
    grid-template-columns: 1fr;
  }

  .conservation-lab {
    min-height: 230px;
  }

  .stack-row {
    grid-template-columns: 58px 1fr 64px;
    font-size: 0.9rem;
  }
}
