:root {
  --bg: #0e1014;
  --panel: #151820;
  --card: #181c25;
  --line: #262b37;
  --grid: rgba(255, 255, 255, 0.06);
  --text: #e6e8ee;
  --muted: #8d95a8;
  --accent: #5aa9ff;
  --accent-2: #ffa94d;
  --accent-3: #3ddc97;
  --felt: #d8c7a0;
  --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: #222734;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover, select:hover { border-color: #3a4152; }
button.primary { background: var(--accent); color: #07121f; border-color: transparent; font-weight: 600; }
button.primary.running { background: #223a2e; color: var(--accent-3); }

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; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: 0.2px; }
.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: 330px 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 - 230px);
}
.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[hidden] { display: none; }
.param .row { display: flex; justify-content: space-between; gap: 8px; }
.param label { color: var(--text); }
.param .val { color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.param .hint { color: var(--muted); font-size: 11px; margin-top: 2px; }
.param select { width: 100%; margin-top: 3px; }
.param.check { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.param.check .hint { flex-basis: 100%; }

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(330px, 1.1fr);
  gap: 14px;
  min-width: 0;
  max-height: calc(100vh - 230px);
  overflow: auto;
}
.row { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; 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); }
.tools select { margin-left: 4px; }
canvas { width: 100%; flex: 1; min-height: 0; display: block; }
#section { flex: 0 0 110px; height: 110px; }
.muted { color: var(--muted); }
.caption { color: var(--muted); font-size: 11px; margin: -2px 0 4px; }

.tabs { display: flex; gap: 4px; }
.tab { padding: 3px 9px; background: transparent; }
.tab.active { background: #262c3a; border-color: #3a4152; }

.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; }

#info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 6px 0 0;
  font-size: 12px;
  overflow: auto;
  font-variant-numeric: tabular-nums;
}
#info dt { color: var(--muted); }
#info dd { margin: 0; }
#info dd.warn { color: var(--warn); }

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: var(--accent-3); }
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: #1e2230;
}

#keyboard {
  position: relative;
  height: 120px;
  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: #e9e6df; border: 1px solid #9a968d; height: 100%; color: #555; font-size: 10px; padding-bottom: 4px; }
.bk { background: #16181d; border: 1px solid #000; height: 62%; z-index: 2; color: #aaa; font-size: 9px; padding-bottom: 3px; }
.wk.mapped { background: #f6f3ec; }
.wk.mapped::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--accent); opacity: 0.6; }
.bk.mapped { background: #232733; }
.wk.down { background: #9cc8ff; }
.bk.down { background: var(--accent); color: #000; }
.wk.focus { box-shadow: inset 0 -4px 0 var(--accent-2); }
.wk .c-label { position: absolute; bottom: 18px; color: #8a867c; 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: 980px) {
  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: 300px auto; }
  .row { grid-template-columns: 1fr; }
  #spectrum { min-height: 220px; }
}
