:root {
  --bg: #0d0c0f;
  --panel: #141318;
  --card: #19171e;
  --line: #2b2833;
  --grid: rgba(255, 255, 255, 0.06);
  --text: #ebebef;
  --muted: #9393a0;
  --accent: #ff8a3d;
  --accent-2: #6fd3ff;
  --brass: #d4a94e;
  --steel: #c8ccd4;
  --warn: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

button, select {
  font: inherit;
  color: var(--text);
  background: #24242a;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover, select:hover { border-color: #44444e; }
button.primary { background: var(--accent); color: #1c0a00; border-color: transparent; font-weight: 600; }
button.primary.running { background: #24352a; color: #7ddc9a; }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand h1 { font-size: 17px; margin: 0; }
.brand .sub { color: var(--muted); }
.brand .nav { color: var(--accent-2); text-decoration: none; font-size: 12px; }
.brand .nav:hover { text-decoration: underline; }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill { color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill.hot { color: var(--warn); border-color: var(--warn); }

main { display: grid; grid-template-columns: 320px 1fr; min-height: 0; }
#controls {
  border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto;
  padding: 12px 14px 24px; max-height: calc(100vh - 215px);
}
.preset-row { display: flex; gap: 8px; margin-bottom: 10px; }
.preset-row select { flex: 1; min-width: 0; }
details.group { border-top: 1px solid var(--line); padding: 6px 0 8px; }
details.group summary { cursor: pointer; font-weight: 600; padding: 4px 0; list-style: none; display: flex; justify-content: space-between; }
details.group summary::after { content: "▾"; color: var(--muted); }
details.group:not([open]) summary::after { content: "▸"; }
.param { margin: 7px 0 9px; }
.param .row { display: flex; justify-content: space-between; gap: 8px; }
.param .val { color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.param .hint { color: var(--muted); font-size: 11px; margin-top: 2px; }
input[type=range] { width: 100%; margin: 4px 0 0; accent-color: var(--accent); height: 16px; }

#views {
  padding: 14px; display: grid; grid-template-rows: minmax(230px, 0.9fr) minmax(300px, 1.1fr);
  gap: 12px; min-width: 0; max-height: calc(100vh - 215px); overflow: auto;
}
.row { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; min-height: 0; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.card-head h2 { font-size: 13px; margin: 0; font-weight: 600; }
.tools { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.muted { color: var(--muted); }
.muted b { color: var(--text); }
.caption { color: var(--muted); font-size: 11px; margin-top: 4px; }
canvas { width: 100%; flex: 1; min-height: 0; display: block; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; padding-top: 4px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

#notes, #pairs { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; margin-bottom: 8px; }
#notes th, #notes td, #pairs th, #pairs td { padding: 2px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
#notes th, #pairs th { color: var(--muted); font-weight: 500; }
#notes td:first-child, #pairs td:first-child, #notes th:first-child, #pairs th:first-child { text-align: left; }
td.locked { color: #7ddc9a; font-weight: 600; }
td.free { color: var(--muted); }
.meter { position: relative; width: 120px; height: 10px; background: rgba(255,255,255,0.06); border-radius: 3px; display: inline-block; vertical-align: middle; }
.meter i { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1px; background: var(--accent); border-radius: 1px; }
.meter b { position: absolute; top: -2px; bottom: -2px; width: 1px; left: 50%; background: rgba(255,255,255,0.35); }
.meter u { position: absolute; top: -3px; width: 2px; height: 16px; margin-left: -1px; background: var(--accent-2); text-decoration: none; }
#stair-card canvas { min-height: 260px; }
.card { overflow: hidden; }
.param.check { display: flex; align-items: center; gap: 8px; }
.param select { width: 100%; margin-top: 3px; }
.param[hidden] { display: none; }

footer { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 14px 12px; }
.kb-help { display: flex; gap: 18px; color: var(--muted); flex-wrap: wrap; margin-bottom: 7px; }
.kb-help b { color: var(--text); font-weight: 600; }
.kb-help b.off { color: var(--muted); }
.kb-help b.on { color: #7ddc9a; }
kbd { font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; margin: 0 1px; color: var(--text); background: #222228; }
#keyboard { position: relative; height: 115px; user-select: none; touch-action: none; }
.wk, .bk { position: absolute; top: 0; border-radius: 0 0 4px 4px; display: flex; align-items: flex-end; justify-content: center; }
.wk { background: #eeeeec; border: 1px solid #94948f; height: 100%; color: #555; font-size: 10px; padding-bottom: 4px; }
.bk { background: #151517; border: 1px solid #000; height: 62%; z-index: 2; color: #aaa; font-size: 9px; padding-bottom: 3px; }
.wk.mapped::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--accent); opacity: 0.7; }
.bk.mapped { background: #26262c; }
.wk.down { background: #ffc79f; }
.bk.down { background: var(--accent); color: #000; }
.wk.focus { box-shadow: inset 0 -4px 0 var(--brass); }
.wk .c-label { position: absolute; bottom: 18px; color: #8a8a85; font-size: 9px; }

#toast { position: fixed; bottom: 160px; left: 50%; transform: translateX(-50%); background: #2a1d1d; border: 1px solid var(--warn); color: var(--text); padding: 8px 14px; border-radius: 8px; z-index: 10; }

@media (max-width: 1050px) {
  main { grid-template-columns: 1fr; min-height: auto; }
  #controls { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  #views { max-height: none; grid-template-rows: auto auto; }
  .row { grid-template-columns: 1fr; }
  canvas { min-height: 230px; }
}
