:root {
  --bg: #0b0e14;
  --panel: #141922;
  --panel-2: #1b2230;
  --line: #2a3342;
  --ink: #e8edf4;
  --muted: #93a0b4;
  --accent: #57e0c8;
  --accent-2: #9fb6ff;
  --warm: #f2b96b;
  --danger: #ef8fb0;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

body { min-height: 100vh; }

#app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100vh;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: linear-gradient(180deg, #171d28, #10151d);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark {
  font-size: 22px; color: var(--accent);
  filter: drop-shadow(0 0 8px rgba(87, 224, 200, 0.6));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { letter-spacing: 0.16em; font-size: 15px; }
.brand-text em { color: var(--muted); font-style: normal; font-size: 11px; letter-spacing: 0.04em; }

.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.clock { display: flex; align-items: center; gap: 8px; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }
.clock #clockTime { font-size: 18px; font-weight: 700; letter-spacing: 0.05em; }
.clock .sub { color: var(--muted); font-size: 12px; }
.pill {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--accent);
  padding: 3px 10px; border-radius: 999px; font-size: 12px; letter-spacing: 0.06em;
}

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  min-height: 44px;
  padding: 0 14px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: #232c3c; border-color: #3a465a; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .chip:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: linear-gradient(180deg, #2ad0b6, #17a894); border-color: #2ad0b6; color: #05201c; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.icon { min-width: 44px; padding: 0; font-size: 18px; }
.btn[aria-pressed="false"] { color: var(--muted); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 0;
  min-height: 0;
}

.stage-wrap { min-width: 0; min-height: 0; display: flex; }
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  background: #0b0e14;
  overflow: hidden;
}
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.overlay-top {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  pointer-events: none;
}
.overlay-top > * { pointer-events: auto; }
.layer-switch, .zoom-group { display: flex; gap: 6px; flex-wrap: wrap; }
.zoom-group { margin-left: auto; }
.chip {
  min-height: 44px; padding: 0 12px;
  background: rgba(20, 25, 34, 0.82);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  font: inherit; font-size: 12px; cursor: pointer;
  backdrop-filter: blur(6px);
}
.chip[aria-pressed="true"] { color: #05201c; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.zoom-group .btn { background: rgba(20, 25, 34, 0.82); backdrop-filter: blur(6px); }

.legend {
  position: absolute; left: 10px; bottom: 44px;
  background: rgba(15, 19, 27, 0.82);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 11px; color: var(--muted);
  max-width: 62%; backdrop-filter: blur(6px);
}
.legend .bar { height: 8px; border-radius: 4px; margin: 4px 0; }
.legend .ends { display: flex; justify-content: space-between; gap: 8px; }

.hint {
  position: absolute; left: 10px; bottom: 10px; right: 10px;
  font-size: 11px; color: #9aa7ba; pointer-events: none;
  background: rgba(9, 12, 18, 0.6); border-radius: 8px; padding: 4px 8px;
  max-width: 78%;
}

/* ---------- controls ---------- */
.controls {
  border-left: 1px solid var(--line);
  background: #0e131b;
  overflow-y: auto;
  min-width: 0;
  max-height: calc(100vh - 128px);
}
.panel { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel h2 {
  margin: 0 0 10px; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent-2); display: flex; justify-content: space-between; align-items: baseline;
}
.panel .count { color: var(--muted); letter-spacing: 0; text-transform: none; font-size: 11px; }
.mapping-note { color: var(--muted); font-size: 11px; margin: 8px 0 0; line-height: 1.4; }

/* gauges */
.gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gauge { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.gauge .g-label { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.gauge .g-val { font-family: ui-monospace, monospace; font-size: 17px; font-weight: 700; margin-top: 2px; }
.gauge .g-bar { height: 4px; border-radius: 2px; background: #232c3c; margin-top: 6px; overflow: hidden; }
.gauge .g-bar i { display: block; height: 100%; background: var(--accent); width: 0%; transition: width 0.25s; }

/* hearing */
.hearing { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.hearing li { display: flex; gap: 8px; align-items: baseline; font-size: 12px; }
.hearing .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.hearing .h-name { font-weight: 600; }
.hearing .h-map { color: var(--muted); }
.hearing .h-live { margin-left: auto; font-family: ui-monospace, monospace; color: var(--accent); white-space: nowrap; }

/* palette + voices */
.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pal-btn {
  min-height: 44px; padding: 0 12px; font-size: 12px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; cursor: pointer; font-family: inherit;
}
.pal-btn[aria-pressed="true"] { color: #05201c; font-weight: 700; }
.voices { display: flex; flex-direction: column; gap: 8px; }
.voice {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.voice.sel { border-color: var(--accent); }
.voice-head { display: flex; align-items: center; gap: 8px; }
.voice-head .v-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.voice-head .v-name { font-size: 12px; font-weight: 600; }
.voice-head .v-drive { font-size: 10px; color: var(--muted); margin-left: auto; text-align: right; }
.voice-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.voice-row input[type="range"] { flex: 1; }
.v-btn {
  min-width: 42px; min-height: 44px; padding: 0 8px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 7px; cursor: pointer; font-family: inherit;
}
.v-btn[aria-pressed="true"] { color: #05201c; background: var(--accent); border-color: var(--accent); }
.v-btn.mute[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); }

/* field rows */
.field-row { display: grid; grid-template-columns: 104px 1fr 54px; align-items: center; gap: 8px; margin-bottom: 8px; }
.field-row label { font-size: 12px; color: var(--muted); }
.field-row output { font-family: ui-monospace, monospace; font-size: 12px; text-align: right; color: var(--ink); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 44px; background: transparent; cursor: pointer; width: 100%;
}
input[type="range"]::-webkit-slider-runnable-track { height: 5px; background: #2a3342; border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px;
  background: var(--accent); border-radius: 50%; border: 2px solid #0b0e14;
}
input[type="range"]::-moz-range-track { height: 5px; background: #2a3342; border-radius: 3px; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; background: var(--accent); border: 2px solid #0b0e14; border-radius: 50%; }

/* foot */
.foot {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted);
  font-size: 11px; background: #0e131b;
}

/* veil */
.veil {
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(1200px 700px at 50% 30%, rgba(30, 42, 60, 0.9), rgba(6, 8, 12, 0.97));
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.veil.hidden { display: none; }
.veil-card {
  max-width: 560px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; text-align: center;
}
.veil-card h1 { margin: 0 0 10px; letter-spacing: 0.22em; font-size: 26px; color: var(--accent); }
.veil-card p { color: var(--muted); line-height: 1.55; font-size: 14px; }
.veil-actions { display: flex; gap: 10px; justify-content: center; margin: 18px 0 10px; flex-wrap: wrap; }
.veil-card .tiny { font-size: 11px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .controls { border-left: none; border-top: 1px solid var(--line); max-height: none; }
  .stage { min-height: 58vh; }
  .overlay-top { top: 8px; left: 8px; right: 8px; }
  .legend { bottom: 40px; max-width: 74%; }
  .gauges { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 420px) {
  .brand-text em { display: none; }
  .clock #clockTime { font-size: 15px; }
  .field-row { grid-template-columns: 88px 1fr 48px; }
}
