:root {
  --bg: #181512;
  --panel: #22201c;
  --face: #36312c;
  --face-light: #4a433c;
  --edge: #0e0c0b;
  --track: #403a34;
  --brass: #cda05a;
  --text: #e8e2d6;
  --muted: #968e82;
  --alarm: #dc4632;
  --cell: 54px;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0 auto;
  max-width: 940px;
  padding: 14px 14px 28px;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}
header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: 0.04em; color: var(--brass); }
.title p { margin: 0; font: 10px ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }
.top-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.preset { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
select, button {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid #3a352f; border-radius: 5px; padding: 5px 9px;
}
select { min-width: 190px; }
button { cursor: pointer; }
button:hover, select:hover { border-color: var(--brass); }
button:focus-visible, select:focus-visible, .ctl:focus-visible, #keyboard:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
#start { background: var(--brass); color: #1a1612; border-color: var(--brass); font-weight: 600; }
#start[disabled] { background: var(--panel); color: var(--muted); border-color: #3a352f; cursor: default; }
.level { width: 44px; height: 8px; background: var(--edge); border-radius: 4px; overflow: hidden; display: inline-block; }
.level i { display: block; height: 100%; width: 0; background: var(--brass); transition: width 60ms linear; }

#top { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
#left { display: flex; flex-direction: column; gap: 10px; }
#controls { display: flex; flex-wrap: wrap; gap: 10px; }
.group { background: var(--panel); border-radius: 6px; padding: 8px 10px 10px; }
.group h2 { margin: 0 0 6px; font: 600 10px ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.06em; color: var(--brass); }
.row { display: flex; gap: 4px; align-items: flex-start; }
.note { margin: 4px 0 0; font-size: 10px; color: var(--muted); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* a control cell: label above, control, value below */
.cell { width: var(--cell); display: flex; flex-direction: column; align-items: center; touch-action: none; cursor: ns-resize; }
.cell.pick, .cell.lever { cursor: pointer; }
.cell .label { height: 13px; font-size: 10px; color: var(--muted); white-space: nowrap; }
.cell .value { height: 14px; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.cell.pick .value { color: var(--brass); }
.cell:hover .value, .cell.active .value { color: var(--text); }
.cell svg { display: block; overflow: visible; }

/* stops grid */
#stops { display: grid; grid-template-columns: 74px repeat(7, 42px); gap: 2px 4px; align-items: center; }
#stops .head { text-align: center; font-size: 11px; color: var(--muted); }
#stops .who { font: 10px ui-monospace, "SF Mono", Menlo, monospace; line-height: 1.2; }
#stops .who small { display: block; color: var(--muted); font: 10px system-ui, sans-serif; }
.mini { width: 42px; height: 44px; display: flex; flex-direction: column; align-items: center; touch-action: none; cursor: ns-resize; }
.mini .value { height: 12px; font-size: 9.5px; color: var(--text); visibility: hidden; }
.mini:hover .value, .mini.active .value { visibility: visible; }

#lamps { display: block; width: 100%; max-width: 372px; height: auto; margin: 0 auto 4px; }
#gauges { display: flex; justify-content: center; gap: 8px; }
#gauges canvas { width: 98px; height: 66px; }

/* keyboard */
#keyboard-area { margin-top: 12px; }
.kb-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.seg { display: inline-flex; align-items: center; gap: 0; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 5px 0 0 5px; margin-left: 0; }
.seg button:last-child { border-radius: 0 5px 5px 0; }
.seg button.on { background: var(--brass); color: #1a1612; border-color: var(--brass); }
.seg span { padding: 5px 8px; min-width: 36px; text-align: center; color: var(--brass); border-top: 1px solid #3a352f; border-bottom: 1px solid #3a352f; background: var(--panel); }
.hint { font-size: 11px; }
#keyboard { position: relative; height: 112px; overflow-x: auto; overflow-y: hidden; background: var(--panel); border-radius: 6px; padding: 6px; touch-action: pan-x; }
#keyboard .keys { position: relative; height: 100%; }
.key { position: absolute; top: 0; border: 1px solid #0a0908; border-radius: 0 0 4px 4px; cursor: pointer; touch-action: none; }
.key.white { background: #e6e0d2; height: 100%; z-index: 1; }
.key.black { background: #2a2622; height: 62%; z-index: 2; }
.key.white.down { background: var(--brass); }
.key.black.down { background: #9a7740; }
.key.manual2.down { box-shadow: inset 0 -6px 0 #5f8fd0; }
.key .nm { position: absolute; bottom: 3px; left: 0; right: 0; text-align: center; font-size: 8.5px; color: #8a8374; pointer-events: none; }

@media (max-width: 760px) {
  #top { grid-template-columns: 1fr; }
}
/* Phones: the stops grid shares the width instead of using fixed columns. */
@media (max-width: 480px) {
  #stops { grid-template-columns: 56px repeat(7, minmax(0, 1fr)); gap: 2px 2px; }
  #stops .who { font-size: 9px; }
  #stops > * { min-width: 0; }
  #stops .head { font-size: 10px; }
  .mini { width: 100%; }
  .mini svg { max-width: 100%; height: auto; }
  body { padding: 10px 10px 24px; }
}
@media (prefers-reduced-motion: reduce) { .level i { transition: none; } }
