:root {
  color-scheme: light;
  --ink: #182433;
  --muted: #5c6878;
  --paper: #f4f7fa;
  --panel: #ffffff;
  --line: #d8e1ea;
  --blue: #28536b;
  --cyan: #78a1bb;
  --green: #2f6f73;
  --coral: #df7657;
  --red: #c9413a;
  --gold: #c69c43;
  --shadow: 0 18px 44px rgba(24, 36, 51, 0.1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 250, 0.92);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  letter-spacing: 0;
}

.eyebrow, .step {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 750;
}

nav a:hover {
  color: var(--blue);
}

main {
  width: min(1540px, 100%);
  margin: 0 auto;
}

section {
  scroll-margin-top: 88px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(310px, 0.38fr) minmax(760px, 1fr);
  gap: clamp(22px, 3vw, 40px);
  align-items: center;
  min-height: calc(100vh - 72px);
  padding: clamp(28px, 5vw, 58px) clamp(14px, 3vw, 40px);
}

.hero-copy h2,
.story-section h2,
.finish h2 {
  margin: 0 0 16px;
  font-size: clamp(1.85rem, 3vw, 3.25rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.story-section h2,
.finish h2 {
  font-size: clamp(1.55rem, 2.35vw, 2.65rem);
}

p {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.62;
}

.hero-copy p {
  max-width: 34rem;
}

.equation {
  margin: 18px 0;
  padding: 13px 15px;
  overflow-x: auto;
  color: var(--blue);
  background: #eaf3f7;
  border: 1px solid #d0e2ea;
  border-radius: 8px;
}

.story-section article .equation {
  font-size: 0.9rem;
}

.formula-card {
  display: grid;
  gap: 5px;
  margin: 18px 0;
  padding: 14px 15px;
  color: var(--blue);
  background: #eaf3f7;
  border: 1px solid #d0e2ea;
  border-radius: 8px;
}

.formula-card strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.formula-card span {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.workbench,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workbench {
  overflow: hidden;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr 0.72fr minmax(190px, 1.2fr);
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.toolbar.compact {
  grid-template-columns: 170px 130px 1fr;
  align-items: center;
  border: 0;
}

button,
select,
input[type="range"] {
  min-height: 42px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  font: inherit;
  font-size: 0.93rem;
}

input[type="range"] {
  min-height: 0;
  accent-color: var(--green);
}

button {
  cursor: pointer;
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
  font-weight: 850;
}

button.secondary {
  color: var(--ink);
  background: #fff;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

select {
  color: var(--ink);
  background: #fff;
  padding-inline: 10px;
}

.slice-grid {
  display: grid;
  grid-template-columns: minmax(440px, 1fr) minmax(360px, 0.58fr);
  gap: 0;
}

.visual-stage {
  min-width: 0;
  border-right: 1px solid var(--line);
}

.stage-caption {
  padding: 12px 16px 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.stage-caption strong {
  color: var(--ink);
}

.inspector {
  display: grid;
  grid-template-rows: auto 205px 145px auto 105px;
  gap: 8px;
  min-width: 0;
  padding: 12px;
}

.phase-card {
  min-height: 112px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.phase-card h3 {
  margin: 0 0 8px;
  font-size: clamp(1.16rem, 1.8vw, 1.56rem);
  letter-spacing: 0;
}

.phase-card p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
}

.plot {
  width: 100%;
  min-width: 0;
}

.plot.gaussian { height: min(58vh, 560px); }
.plot.projection { height: 205px; }
.plot.medium { height: 360px; }
.plot.small { height: 320px; }
.plot.lab { height: 330px; }

.chart {
  display: block;
  width: 100%;
  min-width: 0;
}

.chart.shadow { height: 145px; }
.chart.bars { height: 105px; }
.chart.medium { height: 360px; }
.chart.lab { height: 330px; }

.loss-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.loss-row div,
.score-card {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfcfd;
}

.loss-row span,
.score-card p {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.loss-row strong,
.score-card strong {
  color: var(--red);
  font-size: clamp(1.24rem, 2.3vw, 2rem);
}

.story-section {
  display: grid;
  grid-template-columns: minmax(290px, 0.36fr) minmax(620px, 1fr);
  gap: clamp(22px, 3vw, 42px);
  align-items: start;
  padding: clamp(38px, 7vw, 78px) clamp(14px, 3vw, 40px);
  border-top: 1px solid var(--line);
}

.story-section article {
  position: sticky;
  top: 96px;
}

.panel {
  padding: 16px;
  overflow: hidden;
}

.notice {
  margin-top: 18px;
  padding: 15px 16px;
  background: #eef7f4;
  border: 1px solid #cfe6dd;
  border-radius: 8px;
  line-height: 1.55;
}

.takeaway {
  margin-top: 18px;
  padding: 15px 16px;
  color: var(--muted);
  background: #fff7ea;
  border: 1px solid #ead8b8;
  border-radius: 8px;
  line-height: 1.5;
}

.takeaway strong {
  color: var(--ink);
}

.movie-label {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 4px 12px;
  color: var(--muted);
  font-weight: 850;
}

.two-panel,
.contrast-panel,
.test-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.gaussian-panel {
  display: grid;
  gap: 14px;
}

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

.why-cards div {
  padding: 13px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.why-cards span {
  display: block;
  margin-bottom: 8px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.why-cards strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  line-height: 1.28;
}

.why-cards p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

.compact-equation {
  margin: 0;
  text-align: center;
}

.contrast-panel h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.test-grid {
  grid-template-columns: 1fr 1.15fr 0.52fr;
}

.ep-controls {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) 160px minmax(320px, 1.4fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ep-controls p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.42;
}

.t-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.t-presets button {
  min-height: 30px;
  padding: 0 6px;
  color: var(--blue);
  background: #fff;
  border-color: var(--line);
  font-size: 0.78rem;
  font-weight: 850;
}

.t-presets button:hover {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.phasor-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(180px, 0.35fr);
  gap: 14px;
  margin-bottom: 14px;
}

.chart.phasor {
  height: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.phasor-card {
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.phasor-card span {
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.phasor-card strong {
  color: var(--red);
  font-size: 1.35rem;
}

.phasor-card p {
  margin: 0;
  font-size: 0.92rem;
}

.phasor-card b {
  color: var(--ink);
}

.score-card {
  display: grid;
  align-content: center;
  min-height: 330px;
}

.metric {
  margin: 0;
  justify-self: end;
  align-self: center;
  font-weight: 750;
}

.finish {
  padding: clamp(38px, 7vw, 88px) clamp(14px, 3vw, 40px);
  text-align: center;
  border-top: 1px solid var(--line);
}

.finish p {
  max-width: 780px;
  margin: 0 auto 24px;
}

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

.flow span {
  display: grid;
  align-items: center;
  min-height: 84px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 850;
}

@media (max-width: 1180px) {
  .hero,
  .story-section {
    grid-template-columns: 1fr;
  }

  .story-section article {
    position: static;
  }
}

@media (max-width: 900px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  nav {
    justify-content: flex-start;
  }

  .toolbar,
  .toolbar.compact,
  .slice-grid,
  .two-panel,
  .contrast-panel,
  .why-cards,
  .ep-controls,
  .phasor-grid,
  .test-grid,
  .flow {
    grid-template-columns: 1fr;
  }

  .visual-stage {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .inspector {
    grid-template-rows: auto;
  }

  .plot.gaussian { height: 470px; }
  .metric { justify-self: start; }
}

@media (max-width: 560px) {
  .hero,
  .story-section,
  .finish {
    padding-inline: 10px;
  }

  .hero-copy h2 {
    font-size: 1.9rem;
  }

  .panel,
  .inspector {
    padding: 10px;
  }

  .plot.gaussian,
  .plot.medium,
  .plot.lab,
  .plot.small {
    height: 330px;
  }

  .chart.medium,
  .chart.lab {
    height: 280px;
  }
}
