:root {
  color-scheme: dark;
  --bg: #020306;
  --panel: rgba(15, 16, 19, 0.86);
  --panel-solid: #111215;
  --raise: rgba(255, 255, 255, 0.045);
  --raise-2: rgba(255, 255, 255, 0.085);
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.16);
  --ink: #f3f2ee;
  --ink-2: #c3c2b7;
  --ink-3: #8a8983;
  --accent: #ffd38a;
  --accent-ink: #1d1508;
  --focus: #6da7ec;
  --danger: #ef8a8a;
  --good: #5fd18a;
  --radius: 12px;
  --font: "VT323", ui-monospace, monospace;
  --font-pixel: "Press Start 2P", "VT323", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 18px/1.15 var(--font); -webkit-font-smoothing: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

#globe { position: fixed; inset: 0; }
#globe canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- brand ---------- */
#brand { position: fixed; top: 16px; left: 20px; pointer-events: none; }
.brand-title { font: 30px/1.15 "Workbench", var(--font-pixel); letter-spacing: 0; color: var(--accent); text-shadow: 2px 2px 0 #7a3f12, 4px 4px 0 rgba(0, 0, 0, 0.6); }
.brand-sub { color: var(--ink-3); font-size: 17px; letter-spacing: 3.5px; margin-top: 2px; }

/* ---------- panels ---------- */
.panel {
  position: fixed;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}
#layers { top: 86px; left: 16px; bottom: 80px; width: 318px; display: flex; flex-direction: column; }
#listen { top: 16px; right: 16px; bottom: 80px; width: 316px; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 14px 8px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font: 8px/1.6 var(--font-pixel); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); }
.hint-inline { color: var(--ink-3); font-size: 15px; }
.panel-scroll { overflow-y: auto; padding: 6px 10px 12px; flex: 1; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent; }

.group-title { margin: 14px 4px 8px; font: 8px/1.6 var(--font-pixel); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }
.sub-title { margin: 14px 0 6px; font: 8px/1.6 var(--font-pixel); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- layer cards ---------- */
.layer { border-radius: 10px; padding: 4px 4px 6px; margin-bottom: 4px; border: 1px solid transparent; }
.layer.is-visible, .layer.is-audible { background: var(--raise); }
.layer.open { border-color: var(--line); background: var(--raise); }
.layer-head { display: flex; align-items: center; gap: 2px; }
.layer-name { flex: 1; text-align: left; background: none; border: 0; padding: 4px 4px; font-size: 20px; display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.layer.is-visible .layer-name, .layer.is-audible .layer-name { color: var(--ink); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: transparent; flex: none; }
.status-dot.loading { background: var(--accent); animation: blink 1s infinite; }
.status-dot.ready { background: var(--good); opacity: 0.8; }
.status-dot.error { background: var(--danger); }
@keyframes blink { 50% { opacity: 0.25; } }
.meter { display: inline-flex; gap: 1px; align-items: flex-end; height: 10px; flex: none; margin: 0 2px; }
.meter i { width: 3px; height: 100%; background: rgba(255, 255, 255, 0.09); }
.meter i:nth-child(1) { height: 30%; }
.meter i:nth-child(2) { height: 40%; }
.meter i:nth-child(3) { height: 50%; }
.meter i:nth-child(4) { height: 60%; }
.meter i:nth-child(5) { height: 70%; }
.meter i:nth-child(6) { height: 80%; }
.meter i:nth-child(7) { height: 90%; }
.meter i.on { background: var(--good); }
.meter i.on.hot { background: var(--accent); }
.meter i.on.hot:last-child { background: #ec7e7e; }
.meter.idle { opacity: 0.5; }
.r-name .meter { margin-left: 2px; }
.layer-status { font-size: 15px; color: var(--ink-3); padding: 0 6px; }
.layer-status:empty { display: none; }
.layer-status.error { color: var(--danger); }

.icon-btn { background: none; border: 0; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--ink-3); flex: none; }
.icon-btn:hover { background: var(--raise-2); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { color: var(--ink); }
.icon-btn.ear[aria-pressed="true"] { color: var(--accent); }
.icon-btn.chev svg { transition: transform 0.15s; }
.icon-btn.chev[aria-expanded="true"] svg { transform: rotate(90deg); }

.legend { padding: 0 6px 2px 36px; }
.ramp-bar { height: 6px; border-radius: 3px; }
.legend-labels { display: flex; justify-content: space-between; gap: 6px; font-size: 15px; color: var(--ink-3); margin-top: 3px; font-variant-numeric: tabular-nums; }
.legend-labels .unit { text-align: center; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layer-body { padding: 6px 6px 4px; }
.tabs { display: flex; gap: 2px; background: rgba(0, 0, 0, 0.3); padding: 3px; border-radius: 9px; margin-bottom: 6px; }
.tabs button { flex: 1; border: 0; background: none; padding: 5px 0; border-radius: 7px; color: var(--ink-3); font-size: 18px; }
.tabs button[aria-selected="true"] { background: var(--raise-2); color: var(--ink); }
.tab-panel { display: flex; flex-direction: column; gap: 2px; }

/* ---------- controls ---------- */
.ctl { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 5px 0; }
.ctl-label { color: var(--ink-2); }
.ctl-val { color: var(--ink-3); font-size: 17px; font-variant-numeric: tabular-nums; text-align: right; }
.ctl-range input { grid-column: 1 / -1; }
.ctl-select select, .ctl-ramp select { grid-column: 1 / -1; }
.ctl-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink-2); font-size: 16px; }
.ctl-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.ctl-legend i { width: 9px; height: 9px; display: inline-block; }
.ctl-pair { display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px; }
.ctl-pair .ctl { grid-template-columns: 1fr; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--line-2); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 3px; background: var(--line-2); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--ink); margin-top: -5.5px; border: 0; box-shadow: 0 1px 4px rgba(0,0,0,0.5); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 0; }

select {
  width: 100%; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line-2); border-radius: 8px; padding: 5px 8px;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%; background-size: 4px 4px; background-repeat: no-repeat; padding-right: 24px;
}
select option { background: var(--panel-solid); }

.ctl-toggle { grid-template-columns: auto 1fr; gap: 10px; cursor: pointer; }
.ctl-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 28px; height: 16px; border-radius: 8px; background: var(--line-2); position: relative; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--ink-2); transition: transform 0.15s; }
.ctl-toggle input:checked + .switch { background: var(--accent); }
.ctl-toggle input:checked + .switch::after { transform: translateX(12px); background: var(--accent-ink); }
.ctl-toggle input:focus-visible + .switch { outline: 2px solid var(--focus); outline-offset: 2px; }

.ctl-seg { grid-template-columns: 1fr; }
.segmented { display: flex; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line-2); border-radius: 8px; padding: 2px; gap: 2px; }
.segmented button { flex: 1; border: 0; background: none; border-radius: 6px; padding: 4px 6px; color: var(--ink-3); white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: var(--raise-2); color: var(--ink); }

.ramp-row { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; }
.ramp-swatch { grid-column: 1 / -1; height: 8px; border-radius: 4px; }
.mini-btn { border: 1px solid var(--line-2); background: rgba(0, 0, 0, 0.35); border-radius: 8px; padding: 4px 9px; color: var(--ink-3); }
.mini-btn[aria-pressed="true"] { color: var(--accent); border-color: rgba(255, 211, 138, 0.4); }

.text-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: none; border-radius: 8px; padding: 5px 10px; color: var(--ink-2); margin-top: 8px; align-self: flex-start; }
.text-btn:hover { background: var(--raise-2); color: var(--ink); }
.text-btn svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; display: block; }
.text-btn[aria-pressed="true"] { color: var(--accent); border-color: rgba(255, 211, 138, 0.45); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.help { margin: 0 0 4px; color: var(--ink-3); font-size: 16px; }
.note { margin: 4px 0; color: var(--ink-3); font-size: 16px; }
.about { margin: 4px 0 8px; color: var(--ink-2); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 16px; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; color: var(--ink-2); }

.globe-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 6px; }
.globe-box summary, .mix-box summary { cursor: pointer; padding: 6px 4px; color: var(--ink-2); list-style: none; }
.globe-box summary::before, .mix-box summary::before { content: "▸"; display: inline-block; width: 14px; color: var(--ink-3); transition: transform 0.15s; }
.globe-box[open] summary::before, .mix-box[open] summary::before { transform: rotate(90deg); }
.globe-settings { padding: 0 4px; }

/* ---------- listen panel ---------- */
#listen section { padding: 6px 4px; }
.loc-name { font: 10px/1.6 var(--font-pixel); color: var(--ink); margin-bottom: 2px; }
.loc-coords { color: var(--ink-3); font-variant-numeric: tabular-nums; margin-bottom: 8px; }
.search { display: flex; gap: 4px; align-items: center; }
.search input { flex: 1; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 9px; min-width: 0; }
.search-results { background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: 8px; margin-top: 4px; overflow: hidden; }
.search-hit { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: none; padding: 6px 10px; text-align: left; }
.search-hit:hover { background: var(--raise-2); }
.search-hit small { color: var(--ink-3); }
.search-empty { padding: 8px 10px; color: var(--ink-3); }

.listen-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 11px; background: var(--accent); color: var(--accent-ink); font: 11px/1.4 var(--font-pixel);
}
.listen-btn svg { width: 16px; height: 16px; }
.listen-btn.on { background: rgba(255, 211, 138, 0.14); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(255, 211, 138, 0.5); }
.mix-box { margin-top: 6px; }
.dice-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.dice-btn { display: flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-2); background: rgba(0, 0, 0, 0.35); border-radius: 8px; padding: 5px 4px; color: var(--ink-2); font-size: 17px; }
.dice-btn:hover { background: var(--raise-2); color: var(--ink); }
.dice-btn:active { transform: translateY(1px) rotate(-3deg); }
.dice-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; display: block; }
.preset-save { display: flex; gap: 6px; margin: 4px 0 8px; }
.preset-save input { flex: 1; min-width: 0; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line-2); border-radius: 8px; padding: 5px 9px; }
.preset-list { display: flex; flex-direction: column; gap: 4px; }
.preset-row { display: flex; gap: 6px; }
.preset-load { flex: 1; text-align: left; border: 0; background: var(--raise); border-radius: 8px; padding: 5px 9px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-load:hover { background: var(--raise-2); }
.preset-status { color: var(--accent); font-size: 15px; min-height: 18px; margin-top: 4px; }
.transport-ctls { padding: 0 4px; }

.radar-box { display: flex; flex-direction: column; align-items: center; }
.radar { width: 240px; height: 240px; max-width: 100%; }
.radar-caption { color: var(--ink-3); font-size: 15px; margin-top: 2px; }

.readouts { display: flex; flex-direction: column; gap: 4px; }
.readout { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: var(--raise); border-radius: 9px; padding: 7px 9px; }
.readout:hover { background: var(--raise-2); }
.readout.focus { border-color: rgba(255, 211, 138, 0.45); }
.readout.muted { opacity: 0.6; }
.r-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.r-name { font-size: 18px; display: flex; align-items: center; gap: 6px; }
.r-tag { font-size: 14px; color: var(--ink-3); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 4px; }
.r-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.r-val small { color: var(--ink-3); }
.r-bar { position: relative; height: 10px; margin: 6px 0 4px; }
.r-track { position: absolute; left: 0; right: 0; top: 3px; height: 4px; border-radius: 2px; opacity: 0.55; }
.r-span { position: absolute; top: 1px; height: 8px; border: 1.5px solid var(--ink); border-radius: 3px; }
.r-mean { position: absolute; top: -1px; width: 2px; height: 12px; margin-left: -1px; background: var(--accent); border-radius: 1px; }
.r-sub { color: var(--ink-3); font-size: 15px; font-variant-numeric: tabular-nums; }

/* ---------- time bar ---------- */
#timebar { bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 7px 10px 7px 14px; white-space: nowrap; }
.clock-wrap { display: flex; align-items: center; gap: 8px; }
.clock { min-width: 150px; font-size: 19px; }
.live-badge { font: 7px/1.6 var(--font-pixel); letter-spacing: 0.04em; padding: 2px 6px; border-radius: 4px; color: var(--ink-3); border: 1px solid var(--line-2); }
.live-badge.on { color: #ffb4b4; border-color: rgba(255, 120, 120, 0.5); }
.time-btns { display: flex; align-items: center; gap: 4px; }
.chip { border: 1px solid var(--line-2); background: none; border-radius: 7px; padding: 3px 8px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chip:hover { background: var(--raise-2); color: var(--ink); }
.chip.now { color: var(--accent); border-color: rgba(255, 211, 138, 0.4); }
#timebar .speed { padding: 0; display: block; }
#timebar .speed .ctl-label { display: none; }
#timebar .speed select { width: 116px; }

/* ---------- misc ---------- */
#hint {
  position: fixed; bottom: 72px; left: 50%; transform: translateX(-50%); padding: 7px 14px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55); color: var(--ink-2); font-size: 17px; pointer-events: none; transition: opacity 0.6s; white-space: nowrap;
}
#hint.gone { opacity: 0; }
#tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--panel-solid); border: 1px solid var(--line-2);
  border-radius: 9px; padding: 7px 9px; min-width: 170px; max-width: 300px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.tt-title { color: var(--ink-3); font-size: 15px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tt-row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.tt-swatch { width: 10px; height: 4px; border-radius: 2px; flex: none; }
.tt-name { color: var(--ink-2); flex: 1; }
.tt-val { font-variant-numeric: tabular-nums; text-align: right; }
.fatal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #3a1414; color: #ffd0d0; padding: 16px 20px; border-radius: 10px; }

#mobile-tabs { display: none; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  #brand { top: 12px; left: 16px; }
  .brand-sub { font-size: 15px; letter-spacing: 4px; margin-top: 0; }
  #mobile-tabs { display: flex; position: fixed; top: 10px; right: 16px; gap: 6px; z-index: 5; }
  #mobile-tabs button { background: var(--panel); border: 1px solid var(--line-2); border-radius: 999px; padding: 6px 14px; backdrop-filter: blur(10px); }
  #mobile-tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  #layers, #listen { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62vh; display: none; z-index: 6; }
  #layers.open, #listen.open { display: flex; }
  #timebar { top: 72px; bottom: auto; left: 16px; right: 16px; transform: none; flex-wrap: wrap; justify-content: center; gap: 6px 10px; }
  .clock { min-width: 0; }
  #hint { bottom: 16px; white-space: normal; text-align: center; width: calc(100% - 32px); }
}
@media (max-width: 1180px) and (min-width: 901px) {
  #timebar { left: 350px; right: 348px; transform: none; flex-wrap: wrap; justify-content: center; }
}
