:root {
  --paper: #fbf8f2;
  --paper-2: #f3eee4;
  --page: #e7e1d6;
  --ink: #1c1915;
  --muted: #6e675c;
  --line: #ddd4c4;
  --navy: #1b2836;
  --teal: #0f6e6b;
  --coral: #d4532b;
  --gold: #a67914;
  --good: #e5f3ee;
  --warn: #f8e1d8;
  --note: #f3e6cf;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background-color: var(--page);
  background-image: radial-gradient(rgba(28, 25, 21, 0.04) 0.7px, transparent 0.7px);
  background-size: 15px 15px;
  color: var(--ink);
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}

::selection { background: #f0c7b8; }

h1, h2, h3, .note-title {
  font-family: Fraunces, Palatino, "Palatino Linotype", Georgia, serif;
  font-weight: 560;
  letter-spacing: -0.02em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.hidden { display: none !important; }

#boot {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--page);
  color: var(--ink);
  font-family: Fraunces, Palatino, Georgia, serif;
  font-size: 28px;
}

.app-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  padding: 18px 22px 16px;
  background: var(--navy);
  color: #f6f1e7;
}

.eyebrow {
  margin: 0;
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #d7b56a;
}

.app-head h1 {
  margin: 3px 0 0;
  font-size: 34px;
  line-height: 0.95;
  color: #f6f1e7;
}

.tagline {
  margin: 8px 0 0;
  color: #c9c0b2;
  font-size: 14px;
}

.backend {
  margin: 0;
  color: #c9c0b2;
  font-size: 13px;
  text-align: right;
}

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 6;
  background: #efeae0;
  border-bottom: 1px solid var(--line);
}

.step-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
}

.step-btn .num {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e4ddd0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}

.step-btn.is-done .num { background: var(--teal); color: white; }
.step-btn.is-warn .num { background: var(--coral); color: white; }

.step-btn.is-active {
  background: var(--navy);
  color: #f6f1e7;
}

.step-btn.is-active .num { background: var(--coral); color: white; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  gap: 14px;
  align-items: start;
  padding: 14px;
}

.stage, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.stage { min-width: 0; }

.stage-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 14px 0;
}

.stage-bar h2 { margin: 0; font-size: 26px; }

.stage-meta, #stage-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.stage-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: 460px;
}

.chip {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--paper-2);
  color: #8a8175;
}

.chip-done { background: #e5f2f1; color: var(--teal); }
.chip-warn { background: var(--warn); color: #9a3412; }

.canvas-wrap {
  position: relative;
  height: min(64vh, 700px);
  min-height: 440px;
  margin-top: 8px;
  overflow: hidden;
}

#plot {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

#loss-card {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 230px;
  height: 118px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
  background: rgba(251, 248, 242, 0.94);
}

#loss-card canvas { width: 100%; height: 100%; display: block; }

#hover-dot {
  position: absolute;
  width: 11px;
  height: 11px;
  margin: -6px 0 0 -6px;
  border: 1.5px solid var(--navy);
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
}

.tooltip {
  position: absolute;
  z-index: 4;
  max-width: 230px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--navy);
  color: #f6f1e7;
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 4px 14px 12px;
  color: var(--muted);
  font-size: 12px;
}

.lg { display: inline-flex; align-items: center; gap: 6px; }

.swatch {
  width: 10px;
  height: 10px;
  display: inline-block;
  flex: none;
}

.swatch.circle { border-radius: 50%; background: currentColor; }
.swatch.square { border-radius: 2px; background: currentColor; }
.swatch.triangle {
  width: 0;
  height: 0;
  background: none;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 11px solid currentColor;
}
.swatch.fill { border-radius: 50%; background: var(--navy); }
.swatch.pale {
  border-radius: 50%;
  background: rgba(27, 40, 54, 0.28);
  box-shadow: inset 0 0 0 1.4px var(--navy);
}
.swatch.hollow {
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 1.6px var(--navy);
}
.swatch.curve { width: 16px; height: 3px; border-radius: 2px; background: var(--coral); }
.swatch.ring {
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--navy);
}

aside {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.panel { padding: 14px; }

.panel h3 { margin: 0 0 6px; font-size: 22px; }
.panel h3.section-next { margin-top: 16px; }
.panel h4 { margin: 14px 0 4px; font-size: 14px; }

.split-explain {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.split-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
}

.split-pct {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 18px;
  line-height: 1.15;
}

.split-row p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.lead { margin: 0 0 10px; color: #5c564c; font-size: 14px; }
.fine { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }
.meta-line { color: var(--muted); font-size: 12.5px; }

.choice-list { display: flex; flex-direction: column; gap: 8px; }

.choice {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  align-items: center;
}

.choice.norm-choice { grid-template-columns: 1fr; }

.choice.is-selected {
  border-color: var(--navy);
  background: white;
  box-shadow: inset 3px 0 0 var(--coral);
}

.norm-choice.is-selected { box-shadow: inset 3px 0 0 var(--teal); }

.choice-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.choice-top em {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a8175;
}

.blurb {
  display: block;
  margin-top: 2px;
  color: #5c564c;
  font-size: 13px;
  line-height: 1.35;
}

canvas.thumb {
  width: 76px;
  height: 58px;
  border-radius: 8px;
  display: block;
  background: var(--paper-2);
}

.btn-row, .presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.btn-primary, .btn-ghost, .btn-stop {
  border-radius: 999px;
  padding: 9px 14px;
}

.btn-primary {
  background: var(--navy);
  color: #f6f1e7;
  border: 0;
  font-weight: 600;
}

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

.btn-stop {
  background: var(--coral);
  color: white;
  border: 0;
  font-weight: 600;
}

.text-btn {
  background: none;
  border: 0;
  padding: 0 0 0 4px;
  color: var(--navy);
  font-weight: 600;
  text-decoration: underline;
}

button:disabled, input:disabled, select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.banner {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--note);
  font-size: 13px;
  line-height: 1.4;
}

.banner.warn { background: var(--warn); }
.banner.good { background: var(--good); }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
  font-size: 14px;
}

.field-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="number"], select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fffdf8;
}

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

.layer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.layer-name { font-weight: 600; min-width: 72px; }
.layer label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; min-width: 120px; }
.layer select, .layer input[type="range"] { min-width: 0; }
.add-layer { margin-bottom: 8px; }
.output-layer { background: #f7f3eb; }
.input-layer { background: #f7f3eb; }

.formula {
  margin: 8px 0 0;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

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

.metric {
  background: var(--paper-2);
  border-radius: 10px;
  padding: 8px 10px;
}

.metric span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.metric small { color: var(--muted); font-size: 12px; }

.progress {
  height: 8px;
  margin: 10px 0 4px;
  border-radius: 99px;
  background: #e7e1d6;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0;
  background: var(--teal);
}

.stats, .cm {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.stats th, .stats td, .cm th, .cm td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

.stats th:first-child, .stats td:first-child,
.cm th:first-child, .cm td:first-child { text-align: left; }
.stats td.fn, .stats th.fn { text-align: left; white-space: normal; }

.tag { font-weight: 600; }
.tag-under { color: #8a6410; }
.tag-fit { color: #0f6e6b; }
.tag-over { color: #d4532b; }

.cm td.hit { background: rgba(15, 110, 107, 0.16); }
.cm td.miss { background: rgba(212, 83, 43, 0.14); }

#net {
  width: 100%;
  height: 300px;
  display: block;
  margin-top: 8px;
  background: #f3eee4;
  border-radius: 10px;
}

.code-fold summary { cursor: pointer; font-weight: 600; }

.code-fold pre {
  margin: 10px 0 0;
  max-height: 280px;
  overflow: auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: #1e2430;
  color: #f3efe6;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.lab-note {
  margin: 0 14px 18px;
  padding: 14px 16px 16px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-left: 4px solid var(--coral);
  border-radius: 0 12px 12px 0;
}

.note-title { margin: 4px 0; font-size: 22px; }
#note-body { margin: 0; max-width: 78ch; }

.spark { display: block; }

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
  .app-head { flex-direction: column; align-items: flex-start; }
  .app-head h1 { font-size: 28px; }
  .backend { text-align: left; }
  .stage-bar { flex-direction: column; }
  .stage-actions, .chips { align-items: flex-start; justify-content: flex-start; }
  .canvas-wrap { height: 70vh; }
}
