:root {
  --bg: #0f0e0d;
  --panel: #171513;
  --card: #1c1a17;
  --line: #2e2a25;
  --grid: rgba(255, 255, 255, 0.06);
  --text: #ece8e1;
  --muted: #9a9284;
  --accent: #f0b35a;
  --accent-2: #6cc4ff;
  --accent-3: #7ddc9a;
  --warn: #ff6b6b;
  --bar-brown: #7b4a2b;
  --bar-white: #ebe5d8;
  --bar-black: #1b1a19;
  --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, input#registration {
  font: inherit;
  color: var(--text);
  background: #26221d;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover, select:hover { border-color: #4a4239; }
button.primary { background: var(--accent); color: #1a1004; border-color: transparent; font-weight: 600; }
button.primary.running { background: #2c3a26; 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; 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: 310px 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 - 205px);
}
.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 .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; }
input[type=range] { width: 100%; margin: 4px 0 0; accent-color: var(--accent); height: 16px; }

#views {
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(200px, 1fr) minmax(220px, 1fr);
  gap: 12px;
  min-width: 0;
  max-height: calc(100vh - 205px);
  overflow: auto;
}
.row { display: grid; grid-template-columns: 1.35fr 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; }
.muted { color: var(--muted); }
.muted b { color: var(--text); }
.caption { color: var(--muted); font-size: 11px; margin-top: 4px; min-height: 15px; }
canvas { width: 100%; flex: 1; min-height: 0; display: block; }

/* console */
#console { flex-direction: row; gap: 22px; align-items: stretch; flex-wrap: wrap; padding: 12px 16px; }
.drawbar-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#drawbars { display: flex; gap: 7px; padding: 0 4px; }
.drawbar { width: 30px; display: flex; flex-direction: column; align-items: center; cursor: ns-resize; touch-action: none; outline: none; }
.drawbar .slot {
  position: relative;
  width: 30px;
  height: 150px;
  background: linear-gradient(#0b0a09, #15130f);
  border-radius: 4px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}
.drawbar .rod {
  position: absolute;
  left: 4px; right: 4px; top: 0;
  height: calc(14px + var(--v) * 15px);
  border-radius: 0 0 5px 5px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  transition: height 0.06s linear;
  background-image: repeating-linear-gradient(to bottom, transparent 0 14px, rgba(0, 0, 0, 0.18) 14px 15px);
}
.drawbar .rod span { font-size: 10px; font-weight: 700; padding-bottom: 2px; }
.drawbar.brown .rod { background-color: var(--bar-brown); color: #f3dcc8; }
.drawbar.white .rod { background-color: var(--bar-white); color: #3b342b; }
.drawbar.black .rod { background-color: var(--bar-black); color: #d6d0c6; border: 1px solid #3a3530; }
.drawbar:focus-visible .slot { box-shadow: 0 0 0 2px var(--accent); }
.drawbar .ft { margin-top: 5px; font-size: 11px; color: var(--muted); white-space: nowrap; }
#registration { width: 130px; text-align: center; font: 600 14px ui-monospace, Menlo, monospace; letter-spacing: 1px; cursor: text; }

/* expression (swell) pedal: the on-screen stand-in for ↑ ↓ and MIDI CC 11 */
.swell-wrap { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.swell { --e: 0.85; width: 40px; cursor: ns-resize; touch-action: none; outline: none; }
.swell .track {
  position: relative;
  width: 40px;
  height: 150px;
  background: linear-gradient(#0b0a09, #15130f);
  border-radius: 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}
.swell .fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--e) * 100%);
  background: linear-gradient(to top, rgba(240, 179, 90, 0.12), rgba(240, 179, 90, 0.42));
}
.swell .shoe {
  position: absolute; left: 3px; right: 3px; height: 16px;
  bottom: calc(var(--e) * (100% - 16px));
  border: 1px solid #6b5c49;
  border-radius: 4px;
  background: repeating-linear-gradient(to bottom, #2c2722 0 2px, #3a332b 2px 4px);
}
.swell:focus-visible .track { box-shadow: 0 0 0 2px var(--accent); }
.swell-wrap .ft { font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; line-height: 1.3; }
.swell-wrap .ft b { color: var(--text); font-weight: 600; }

.sw-group { display: flex; flex-direction: column; gap: 5px; margin: 0 0 12px; } /* heads its group in the Controls panel */
.sw-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; }
/* the console as the B-3 has it (shared/faces.js draws the vibrato knob): ivory tilt tabs, each
   with both its legends, the lit one pressed; the Leslie's half-moon, rocked left for slow and right
   for fast; the generator's Run switch */
.tilts { display: flex; gap: 4px; flex-wrap: wrap; }
body[data-instrument] .tilt {
  box-sizing: border-box; width: 50px; height: 74px; min-height: 0; padding: 6px 2px 8px; border-radius: 4px 4px 10px 10px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  font: 600 10px/1.05 var(--engrave); letter-spacing: 0.4px; text-transform: uppercase; color: #3b2f22; text-align: center;
  background: linear-gradient(#cfc4ad, #f6efdf 38%, #fffaf0 62%, #e9dfca); border: 1px solid #1b140c;
  box-shadow: 0 3px 0 #0d0905, 0 5px 6px rgba(0, 0, 0, 0.6); transition: background 0.12s, transform 0.12s;
}
body[data-instrument] .tilt.on { background: linear-gradient(#fffaf0, #e8dec8 38%, #f4ecdb 62%, #c9bea6); transform: translateY(1px); }
.tilt span { opacity: 0.4; }
.tilt.on span:first-child, .tilt:not(.on) span:last-child { opacity: 1; }
body[data-instrument] .tilt.dark { background: linear-gradient(#211915, #3a2c22 38%, #4c3a2d 62%, #2b2019); color: #e9dccb; }
body[data-instrument] .tilt.dark.on { background: linear-gradient(#4c3a2d, #2e231b 38%, #3c2e24 62%, #1d1612); }
.vib-console, .leslie-console { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
#vib { border-radius: 8px; }
#vib:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.moon { --tilt: 0deg; position: relative; width: 132px; height: 86px; flex: none; }
.moon-body {
  position: absolute; left: 50%; bottom: 22px; width: 88px; height: 44px; margin-left: -44px; border-radius: 44px 44px 4px 4px;
  transform-origin: 50% 100%; transform: rotate(var(--tilt)); transition: transform 0.16s cubic-bezier(0.4, 1.5, 0.5, 1);
  background: linear-gradient(#f2f3f5, #a7aab1 55%, #6b6e74); box-shadow: 0 0 0 1px #2a2a2e, 0 4px 6px rgba(0, 0, 0, 0.6); pointer-events: none;
}
.moon-body::after { content: ""; position: absolute; left: 50%; top: 6px; width: 3px; height: 28px; margin-left: -1.5px; background: #3a3a40; border-radius: 2px; }
.moon-base { position: absolute; left: 14px; right: 14px; bottom: 16px; height: 8px; border-radius: 3px; background: linear-gradient(#262629, #121214); pointer-events: none; }
.moon.bypassed .moon-body { opacity: 0.55; }
/* each legend's button reaches up over its third of the switch, so the switch itself is pressed */
body[data-instrument] .moon button {
  position: absolute; bottom: 0; width: 33.3%; height: 100%; min-height: 0; padding: 0 0 1px; border: 0; background: none;
  display: flex; align-items: flex-end; justify-content: center; font: 600 11px/1 var(--engrave); letter-spacing: 1px; text-transform: uppercase; color: #7b7b86;
}
body[data-instrument] .moon button.on { color: var(--accent); }
.moon button:nth-of-type(1) { left: 0; } .moon button:nth-of-type(2) { left: 33.3%; } .moon button:nth-of-type(3) { right: 0; }
#scanner { height: 34px; flex: none; }
.motor-row { display: flex; align-items: center; gap: 12px; }
body[data-instrument] .motor { min-height: 0; padding: 0; border: 0; background: none; }
.motor .forte-toggle .on-l { color: #7b7b86; }
.motor.on .forte-toggle .on-l { color: var(--text); }
.motor.on .forte-toggle .off-l { color: #7b7b86; }
.motor.on .forte-toggle .bat { transform: scaleY(1); }
.motor.on .forte-toggle .lamp { background: radial-gradient(circle at 40% 35%, #fff, var(--accent) 55%); box-shadow: 0 0 0 1.5px #2c2c32, 0 0 10px var(--accent); }
.motor:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.readout { font-variant-numeric: tabular-nums; color: var(--muted); }

#analysis { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12px; }
#analysis th, #analysis td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--line); }
#analysis th { color: var(--muted); font-weight: 500; }
#analysis td:first-child, #analysis th:first-child { text-align: left; }
#analysis td.pos { color: var(--accent); }
#analysis td.neg { color: var(--accent-2); }
#analysis td.fold { color: var(--warn); }
#analysis tr.off td { opacity: 0.45; }

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; }
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: #241f1a;
}
#keyboard { position: relative; height: 110px; 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: #ece6d8; border: 1px solid #958d7e; height: 100%; color: #5a5245; font-size: 10px; padding-bottom: 4px; }
.bk { background: #161412; 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: #26211c; }
.wk.down { background: #f6c97f; }
.bk.down { background: var(--accent); color: #000; }
.wk .c-label { position: absolute; bottom: 18px; color: #8a8273; font-size: 9px; }

#toast {
  position: fixed; bottom: 150px; 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: 1100px) {
  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 260px auto; }
  .row { grid-template-columns: 1fr; }
  #output { min-height: 220px; }
}
/* phones: narrower drawbars, so the swell pedal stays beside them */
@media (max-width: 600px) {
  #console { gap: 14px; padding: 12px; }
  #drawbars { gap: 4px; padding: 0; }
  .drawbar, .drawbar .slot { width: 26px; }
}
