:root,
html[data-theme="light"] {
  --bg: #e7e1d4;
  --paper: #f7f3ea;
  --sidebar: #efe9dc;
  --ink: #1c242e;
  --muted: #5c564c;
  --line: #cfc6b6;
  --line-strong: #b7ad9b;
  --s: #2c6b4a;
  --s-soft: rgba(44, 107, 74, 0.18);
  --s-fill: rgba(44, 107, 74, 0.22);
  --ns: #b1342c;
  --ns-soft: rgba(177, 52, 44, 0.16);
  --ns-fill: rgba(177, 52, 44, 0.18);
  --navy: #1e3f66;
  --navy-soft: rgba(30, 63, 102, 0.12);
  --on-navy: #f7f3ea;
  --gold: #b0893a;
  --band: rgba(30, 63, 102, 0.14);
  --grid: rgba(183, 173, 155, 0.55);
  --hist-0: rgba(144, 186, 217, 0.75);
  --hist-1: rgba(21, 101, 192, 0.72);
  --input-bg: #fff;
  --shadow: 0 10px 30px rgba(28, 36, 46, 0.08);
  --explain-bg: rgba(28, 36, 46, 0.04);
  --sidebar-width: 360px;
  --radius: 14px;
  color-scheme: light;
  font-synthesis: none;
}

html[data-theme="dark"] {
  --bg: #141210;
  --paper: #1e1b17;
  --sidebar: #1a1814;
  --ink: #eee6d8;
  --muted: #a79e90;
  --line: #3a342c;
  --line-strong: #524a40;
  --s: #7ec59a;
  --s-soft: rgba(126, 197, 154, 0.16);
  --s-fill: rgba(126, 197, 154, 0.22);
  --ns: #e07a72;
  --ns-soft: rgba(224, 122, 114, 0.16);
  --ns-fill: rgba(224, 122, 114, 0.2);
  --navy: #8eb4d4;
  --navy-soft: rgba(142, 180, 212, 0.14);
  --on-navy: #141210;
  --gold: #d4b36a;
  --band: rgba(142, 180, 212, 0.2);
  --grid: rgba(82, 74, 64, 0.8);
  --hist-0: rgba(144, 186, 217, 0.45);
  --hist-1: rgba(125, 186, 232, 0.85);
  --input-bg: #2a261f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --explain-bg: rgba(238, 230, 216, 0.04);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", "Times New Roman", serif;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

button,
input,
select {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 28px 22px 16px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
}

main {
  padding: 28px 32px 48px;
  min-width: 0;
}

.kicker {
  margin: 0 0 6px;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.lede {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.lede .s-label {
  color: var(--s);
  font-weight: 600;
}

.lede .ns-label {
  color: var(--ns);
  font-weight: 600;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

.chip.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--on-navy);
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-bottom: 2px;
}

.brand-row .kicker {
  margin: 0;
}

.theme-switch {
  display: flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.theme-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 9px;
  cursor: pointer;
}

.theme-switch button + button {
  border-left: 1px solid var(--line);
}

.theme-switch button.active {
  background: var(--navy);
  color: var(--on-navy);
}

.group {
  margin: 0 0 16px;
  padding: 12px 12px 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.group h2 {
  margin: 0 0 10px;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.field {
  margin-bottom: 10px;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
}

.field-head span {
  color: var(--ink);
}

.field-head code {
  font-size: 10.5px;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 8px;
  align-items: center;
}

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

input[type="number"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 8px;
  padding: 5px 6px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 3px 0 0;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.total-students {
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--explain-bg);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.explain {
  margin: 6px 0 4px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--explain-bg);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
}

.explain summary {
  cursor: pointer;
  color: var(--ink);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.explain p {
  margin: 8px 0 0;
}

.explain p:last-child {
  margin-bottom: 2px;
}

.theory {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0 6px;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 12px;
}

.theory b {
  display: block;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.theory .s b { color: var(--s); }
.theory .ns b { color: var(--ns); }

#gauss {
  width: 100%;
  height: 132px;
  display: block;
  margin-top: 4px;
}

.dock {
  position: sticky;
  bottom: 0;
  z-index: 3;
  margin-top: 8px;
  padding-top: 12px;
  background: linear-gradient(to bottom, transparent, var(--sidebar) 10px, var(--sidebar));
}

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

.primary,
.ghost {
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  cursor: pointer;
}

.primary {
  border: 0;
  background: var(--navy);
  color: var(--on-navy);
}

.primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.progress {
  margin-top: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress[hidden] {
  display: none;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--navy);
  transition: width 0.15s linear;
}

.ghost {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
}

.error {
  display: none;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--ns-soft);
  color: var(--ns);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 12.5px;
}

.error.show {
  display: block;
}

.main-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.main-head p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 62ch;
  font-size: 15px;
  line-height: 1.45;
}

.status {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 16rem;
  max-width: 22rem;
  padding: 12px 14px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.snapshot {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr 0.7fr;
  gap: 8px;
  margin-bottom: 8px;
}

.snapshot-val {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1.1;
}

.snapshot-lbl {
  margin-top: 2px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.status-progress {
  margin-top: 8px;
  height: 8px;
  width: 100%;
}

.spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid var(--line-strong);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner[hidden] {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: pulse 1s ease-in-out infinite;
    border-top-color: var(--line-strong);
    background: var(--navy);
    border-width: 0;
    opacity: 0.7;
  }

  @keyframes pulse {
    50% {
      opacity: 0.25;
    }
  }
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.kpi .lbl {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi .val {
  margin-top: 6px;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.kpi .delta {
  margin-top: 2px;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 12px;
}

.delta.up { color: var(--s); }
.delta.down { color: var(--ns); }
.delta.flat { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.card canvas {
  width: 100%;
  height: 240px;
  display: block;
}

.footnote {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  max-width: 72ch;
}

.concepts {
  margin-top: 22px;
  padding: 18px 18px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.concepts h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.concepts-lede {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.45;
  max-width: 72ch;
}

.concept-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

.concept-grid article h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.concept-grid article p {
  margin: 0 0 8px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink);
}

.concept-grid .live {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--explain-bg);
  color: var(--muted);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 12.5px;
  line-height: 1.4;
}

@media (max-width: 1100px) {
  .kpis,
  .grid {
    grid-template-columns: 1fr 1fr;
  }

  .concept-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  aside {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-bottom: 130px;
  }

  .dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 12px 22px 18px;
    border-top: 1px solid var(--line);
    background: var(--sidebar);
  }

  .kpis,
  .grid,
  .theory,
  .concept-grid {
    grid-template-columns: 1fr;
  }

  .main-head {
    flex-direction: column;
    align-items: start;
  }

  .status {
    text-align: left;
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .status-line {
    justify-content: flex-start;
  }

  .status {
    align-items: flex-start;
  }
}
