:root {
  color-scheme: light;
  --bg: #f8f6f1;
  --panel: #fffefb;
  --inner: #f3f0e9;
  --ink: #202b33;
  --soft: #66737d;
  --faint: #8a949b;
  --line: #d8dee2;
  --violet: #6557a7;
  --blue: #39708c;
  --teal: #2d7a70;
  --rust: #a95736;
  --accent: var(--rust);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 94% 2%, rgba(236, 233, 247, .8), transparent 22rem), var(--bg);
  color: var(--ink);
}

button,
input { font: inherit; }

button,
input { accent-color: var(--accent); }

.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 420px;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  background: transparent;
}

.control-panel {
  min-width: 0;
  padding: 14px 13px 11px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 254, 251, .98), rgba(247, 243, 236, .98));
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #c9c3ba transparent;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font: 800 9px/1.2 'SFMono-Regular', Consolas, monospace;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.control-panel h1 {
  margin: 0 0 5px;
  font: 700 20px/1.08 Georgia, 'Times New Roman', serif;
  letter-spacing: -.02em;
}

.intro {
  margin: 0 0 10px;
  color: var(--soft);
  font-size: 11px;
  line-height: 1.38;
}

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

.control {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 3px 10px rgba(70, 65, 54, .035);
}

.control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.control label,
.control-head label {
  color: var(--soft);
  font-size: 10px;
  font-weight: 750;
}

.control output {
  color: var(--accent);
  font: 800 10px/1 'SFMono-Regular', Consolas, monospace;
  white-space: nowrap;
}

.control-hint {
  margin: 3px 0 0;
  color: var(--faint);
  font-size: 8.5px;
  line-height: 1.3;
}

input[type='range'] {
  width: 100%;
  height: 13px;
  margin: 0;
  cursor: pointer;
}

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

button {
  min-height: 31px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--inner);
  font-size: 10.5px;
  font-weight: 750;
  cursor: pointer;
}

button.primary,
button:not(:disabled):hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, white);
}

button:disabled {
  color: var(--faint);
  cursor: not-allowed;
  opacity: .52;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.step-formulas {
  min-height: 67px;
  margin-top: 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 48%, var(--line));
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 7%, white);
  overflow: hidden;
}

.step-formula {
  height: 65px;
  padding: 7px 8px 5px;
  color: var(--ink);
}

.step-formula > span:first-child {
  display: block;
  color: var(--accent);
  font: 900 8px/1.2 'SFMono-Regular', Consolas, monospace;
  letter-spacing: .1em;
}

.step-formula .math-display {
  height: 39px;
  font-size: 12px;
}

.keyboard-hint {
  margin: 8px 0 0;
  color: var(--faint);
  font: 700 8px/1.35 'SFMono-Regular', Consolas, monospace;
  text-align: center;
}

.stage-panel {
  min-width: 0;
  min-height: 0;
  padding: 12px 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 9px;
  overflow: hidden;
}

.stage-bar {
  min-width: 0;
  min-height: 39px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 254, 251, .94);
  box-shadow: 0 4px 14px rgba(70, 65, 54, .04);
}

.stage-k {
  display: block;
  margin-bottom: 2px;
  color: var(--faint);
  font: 800 7px/1.1 'SFMono-Regular', Consolas, monospace;
  letter-spacing: .1em;
}

.stage-bar strong { font-size: 13px; }

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--soft);
  font: 800 9px/1.2 'SFMono-Regular', Consolas, monospace;
  white-space: nowrap;
}

.status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 14%, transparent);
}

.stage-body {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 202px;
  gap: 10px;
  overflow: hidden;
}

.visual-card {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  box-shadow: 0 7px 22px rgba(70, 65, 54, .055);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.legend {
  position: absolute;
  left: 12px;
  top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 5px 7px;
  border: 1px solid rgba(216, 222, 226, .92);
  border-radius: 7px;
  background: rgba(255, 254, 251, .9);
  color: var(--soft);
  font: 800 8px/1.2 'SFMono-Regular', Consolas, monospace;
  box-shadow: 0 3px 12px rgba(70, 65, 54, .06);
}

.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 11px; height: 3px; border-radius: 2px; background: currentColor; }
.legend .component-one { color: var(--blue); }
.legend .component-two { color: var(--rust); }
.legend .ambiguous { color: var(--violet); }

.metric-rail {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 7px;
  overflow: auto;
  scrollbar-width: thin;
}

.metric-card {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--inner);
}

.metric-card.accent {
  border-color: color-mix(in srgb, var(--accent) 54%, var(--line));
  background: color-mix(in srgb, var(--accent) 9%, white);
}

.metric-k {
  display: block;
  margin-bottom: 4px;
  color: var(--faint);
  font: 800 8px/1.2 'SFMono-Regular', Consolas, monospace;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.metric-v {
  color: var(--ink);
  font: 800 11px/1.28 'SFMono-Regular', Consolas, monospace;
  white-space: pre-line;
  word-break: break-word;
}

.metric-copy {
  margin: 4px 0 0;
  color: var(--soft);
  font-size: 8.5px;
  line-height: 1.28;
}

.parameter-list { display: grid; gap: 3px; }
.parameter-list span { display: flex; justify-content: space-between; gap: 8px; color: var(--soft); font-size: 9px; }
.parameter-list code { color: var(--ink); font: 800 9px/1.2 'SFMono-Regular', Consolas, monospace; }
.action-card { border-color: color-mix(in srgb, var(--teal) 36%, var(--line)); }
.action-copy { margin: 0; color: var(--soft); font-size: 8.5px; line-height: 1.33; }

.noscript-card {
  max-width: 36rem;
  margin: 4rem auto;
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.noscript-card a { color: var(--violet); }

@media (max-width: 760px) {
  html,
  body { height: auto; min-height: 100%; overflow: auto; }
  .app-shell { height: auto; min-height: 100dvh; grid-template-columns: 1fr; grid-template-rows: auto auto; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .stage-panel { min-height: 700px; overflow: visible; }
  .stage-body { min-height: 730px; grid-template-columns: 1fr; grid-template-rows: 520px auto; overflow: visible; }
  .visual-card { min-height: 520px; }
  .metric-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .action-card { grid-column: 1 / -1; }
  button { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
