:root {
  --bg: #f5f2ec;
  --panel: #fffdf9;
  --line: #d9d2c3;
  --text: #22252b;
  --muted: #605d55;
  --accent: #1d4ed8;
  --board: #fffdf9;
  --peg: #5b5648;
  --wall: #b9b09d;
  --bar: #c9b98f;
  --exact: #1d4ed8;
  --normal: #c2410c;
  --ball: #2f2b24;
  --guide: #ece6d8;
  --tilt: #15803d;
  --button: #ebe6da;
  --button-hover: #ded7c7;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --panel: #1b1e24;
    --line: #2f343d;
    --text: #e8e9ec;
    --muted: #a5a9b2;
    --accent: #93c5fd;
    --board: #171a1f;
    --peg: #9aa1ad;
    --wall: #3d434e;
    --bar: #6b5f45;
    --exact: #93c5fd;
    --normal: #fb923c;
    --ball: #f1e6cf;
    --guide: #252a31;
    --tilt: #4ade80;
    --button: #252a32;
    --button-hover: #30363f;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

header,
footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

h1 {
  margin: 8px 0 4px;
  font-size: 1.8rem;
  letter-spacing: 0.02em;
}

.subtitle,
footer {
  color: var(--muted);
  max-width: 72ch;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  main {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

canvas {
  display: block;
  width: 100%;
  height: min(72vh, 680px);
  min-height: 360px;
  border-radius: 6px;
  background: var(--board);
}

.legend {
  margin: 8px 2px 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.key {
  display: inline-block;
  width: 18px;
  height: 10px;
  margin: 0 4px 0 12px;
  vertical-align: middle;
  border-radius: 2px;
}

.key:first-child {
  margin-left: 0;
}

.key.bar {
  background: var(--bar);
}

.key.exact {
  height: 3px;
  background: var(--exact);
}

.key.normal {
  height: 3px;
  background: var(--normal);
}

.key.tilt {
  width: 3px;
  height: 12px;
  background: var(--tilt);
}

.key[hidden],
[hidden] {
  display: none;
}

canvas.painting {
  cursor: crosshair;
  touch-action: none;
}

select {
  display: block;
  width: 100%;
  margin-top: 4px;
  font: inherit;
  color: var(--text);
  background: var(--button);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

fieldset {
  border: 0;
  border-bottom: 1px solid var(--line);
  margin: 0 0 12px;
  padding: 0 0 12px;
}

legend {
  font-weight: 600;
  padding: 0;
  margin-bottom: 6px;
}

label {
  display: block;
  margin: 8px 0;
  font-size: 0.92rem;
}

label output {
  float: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

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

label.check {
  display: flex;
  gap: 8px;
  align-items: center;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--button);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}

button:hover {
  background: var(--button-hover);
}

button[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

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

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  margin: 0;
  font-size: 0.92rem;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats small {
  color: var(--muted);
}

.conv svg {
  display: block;
  width: 100%;
  height: auto;
}

.conv .grid {
  stroke: var(--line);
  stroke-width: 1;
}

.conv .tick {
  fill: var(--muted);
  font-size: 10px;
}

.conv .expected {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.conv .observed {
  fill: none;
  stroke: var(--exact);
  stroke-width: 2;
}

.conv .observed-dot {
  fill: var(--exact);
}

.key.observed {
  height: 3px;
  margin-left: 0;
  background: var(--exact);
}

.key.expected {
  height: 0;
  border-top: 2px dashed var(--muted);
  border-radius: 0;
}

.hint,
.status {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 6px 0 0;
  min-height: 1.2em;
}

kbd {
  font: 0.85em ui-monospace, monospace;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  background: var(--panel);
}

a {
  color: var(--accent);
}
