:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #6f7b84;
  --line: #dce2e5;
  --paper: #ffffff;
  --wash: #f3f5f4;
  --blue: #1769aa;
  --blue-soft: #e2effa;
  --orange: #ef8d32;
  --orange-soft: #fff0df;
  --red: #d85a4a;
  --red-soft: #fbe6e2;
  --mono: "Source Code Pro", ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: "Source Sans 3", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--wash); font-family: var(--sans); }
button, input { font: inherit; }
code { font-family: var(--mono); }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .38; }
main { width: min(1280px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 28px; }

.masthead { display: flex; justify-content: space-between; gap: 32px; align-items: flex-end; margin-bottom: 28px; }
.eyebrow { margin: 0 0 5px; color: var(--blue); font-size: .69rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
h1 { max-width: 780px; margin: 0; font-size: clamp(2rem, 4.3vw, 4rem); line-height: 1.02; letter-spacing: -.055em; }
.lede { margin: 14px 0 0; color: var(--muted); font-size: 1rem; }
.complexity { flex: none; padding: 12px 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); text-align: right; box-shadow: 0 2px 8px #17212b08; }
.complexity span { display: block; color: var(--muted); font: 500 .67rem var(--mono); text-transform: uppercase; }
.complexity strong { color: var(--blue); font: 600 1.35rem var(--mono); }

.setup { margin-bottom: 18px; }
.setup > label, .control-label { display: block; margin-bottom: 7px; font-size: .72rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.input-row { display: flex; gap: 8px; }
input { min-width: 0; flex: 1; height: 44px; padding: 0 14px; border: 1px solid #cbd3d7; border-radius: 6px; outline: none; background: var(--paper); font: .86rem var(--mono); box-shadow: inset 0 1px 1px #17212b06; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #1769aa20; }
button { min-height: 38px; padding: 0 15px; border: 1px solid #cbd3d7; border-radius: 6px; color: var(--ink); background: var(--paper); font-size: .76rem; font-weight: 600; box-shadow: 0 1px 2px #17212b08; }
button:hover:not(:disabled) { border-color: #9da9ae; background: #f8faf9; }
button.primary { border-color: var(--blue); color: white; background: var(--blue); }
button.primary:hover:not(:disabled) { background: #12558a; }
.input-row button { min-width: 150px; }
.under-input { display: flex; justify-content: space-between; min-height: 20px; padding: 5px 2px 0; color: var(--muted); }
#error { color: var(--red); }

.controls { display: flex; align-items: center; gap: 22px; margin-bottom: 18px; padding: 15px 18px; border: 1px solid var(--line); border-radius: 8px; background: #e9eeec; }
.control-block { display: flex; align-items: center; gap: 14px; }
.control-label { min-width: 72px; margin: 0; }
.control-label small { display: block; margin-top: 2px; color: var(--muted); font-size: .62rem; font-weight: 500; letter-spacing: 0; text-transform: none; }
.button-pair { display: flex; gap: 6px; }
.button-pair.compact button { width: 43px; padding: 0; font: 600 1rem var(--mono); }
.shortcut-hint { display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: .65rem; white-space: nowrap; }
.divider { width: 1px; height: 42px; background: #cbd4d0; }

.visual-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: 0 8px 28px #17212b0a; }
.card-heading { display: flex; min-height: 73px; justify-content: space-between; align-items: center; gap: 20px; padding: 13px 20px; border-bottom: 1px solid var(--line); }
.phase { display: inline-block; padding: 3px 7px; border-radius: 3px; color: var(--blue); background: var(--blue-soft); font: 600 .63rem var(--mono); letter-spacing: .05em; }
#message { margin: 7px 0 0; font-size: .86rem; }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 16px; color: var(--muted); font-size: .7rem; }
.legend span { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--blue); }
.swatch.current { background: var(--orange); }
.swatch.removed { background: var(--red); }
.stage { overflow-x: auto; min-height: 420px; padding: 14px 16px 2px; outline: none; }
.chart { display: block; margin: 0 auto; }
.chart text { font-family: var(--mono); }
.chart .grid { stroke: #e8ecee; stroke-dasharray: 3 5; }
.chart .bar { fill: #e4e9e8; stroke: #cbd3d3; stroke-width: 1; transition: fill .15s; }
.chart .bar.processed { fill: #d7dedd; }
.chart .bar.in-stack { fill: var(--blue); stroke: #12558a; }
.chart .bar.current { fill: var(--orange); stroke: #c76c1c; }
.chart .bar.popped { fill: var(--red); stroke: #b64235; }
.chart .bar.compare { stroke: var(--orange); stroke-width: 3; }
.chart .value { fill: white; font-size: 12px; font-weight: 600; text-anchor: middle; }
.chart .value.outside { fill: var(--ink); }
.chart .index { fill: #8b959b; font-size: 10px; text-anchor: middle; }
.chart .row-label { fill: var(--muted); font: 600 11px var(--sans); letter-spacing: .04em; text-anchor: end; }
.chart .cell { fill: #f7f9f8; stroke: var(--line); }
.chart .cell.current { fill: var(--orange-soft); stroke: var(--orange); stroke-width: 1.5; }
.chart .cell.done { fill: #f1f6fb; }
.chart .cell-text { fill: var(--ink); font-size: 12px; font-weight: 500; text-anchor: middle; dominant-baseline: central; }
.chart .unknown { fill: #a9b1b5; }
.chart .sweep { stroke: var(--blue); stroke-width: 2.5; stroke-dasharray: 7 5; }
.chart .horizon { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .horizon-shadow { fill: none; stroke: white; stroke-width: 7; stroke-linejoin: round; stroke-linecap: round; opacity: .8; }

.work-grid { display: grid; grid-template-columns: 165px minmax(0, 1fr) 285px; grid-template-areas: "stack visual code"; align-items: stretch; gap: 18px; }
.stack-card, .code-card { padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: 0 4px 18px #17212b08; }
.stack-card { display: flex; min-height: 0; flex-direction: column; grid-area: stack; }
.visual-card { grid-area: visual; }
.code-card { min-width: 0; align-self: start; grid-area: code; }
.stack-card header { display: block; }
.stack-card .eyebrow { margin-bottom: 7px; }
h2 { margin: 0; font-size: 1.05rem; letter-spacing: -.02em; }
.direction { color: var(--muted); font: .65rem var(--mono); }
.direction b { color: var(--blue); }
.stack-list { display: flex; min-height: 0; flex: 1; flex-direction: column; align-items: center; gap: 7px; margin-top: 14px; padding: 12px 8px 8px; overflow-y: auto; border-radius: 6px; background: #f2f5f3; }
.stack-item { position: relative; flex: none; width: max-content; max-width: 100%; padding: 7px 9px; border: 1px solid #91b5d4; border-radius: 5px; color: var(--blue); background: var(--blue-soft); font: 600 .85rem var(--mono); text-align: center; }
.stack-item:first-child, .empty-stack { margin-top: auto; }
.empty-stack { color: #9aa4a8; font: .75rem var(--mono); }
.code-card pre { margin: 15px -6px -5px; overflow-x: auto; font: .7rem/1.3 var(--mono); }
.code-card pre span { display: block; padding: 0 7px; border-left: 2px solid transparent; white-space: pre; }
.code-card pre span.active { border-color: var(--orange); color: #8b4508; background: var(--orange-soft); }
kbd { padding: 2px 5px; border: 1px solid #cbd3d7; border-bottom-width: 2px; border-radius: 4px; color: #536068; background: white; font: .62rem var(--mono); }

@media (max-width: 1100px) {
  .work-grid { grid-template-columns: 150px minmax(0, 1fr); grid-template-areas: "stack visual" "code code"; }
}

@media (max-width: 820px) {
  main { width: min(100% - 24px, 1280px); padding-top: 22px; }
  .masthead { align-items: flex-start; }
  .complexity { display: none; }
  .controls { flex-wrap: wrap; gap: 13px; }
  .legend { display: none; }
}

@media (max-width: 560px) {
  h1 { font-size: 2.15rem; }
  .input-row { flex-direction: column; }
  .input-row button { height: 42px; }
  .controls { padding: 12px; }
  .control-block { flex: 1 1 100%; justify-content: space-between; }
  .shortcut-hint { margin-left: auto; }
  .button-pair:not(.compact) { flex: 1; }
  .button-pair:not(.compact) button { flex: 1; padding-inline: 7px; }
  .divider { display: none; }
  .work-grid { grid-template-columns: 1fr; grid-template-areas: "visual" "stack" "code"; }
  .stack-card { min-height: 220px; }
  .card-heading { align-items: flex-start; }
  .stage { padding-inline: 4px; }
}
