/* ==========================================================================
   Tokens
   Six text sizes: 12 meta, 13 small labels, 14 body/controls, 15 headings,
   20 wordmark, 24 title and readouts. One text face; mono only inside <kbd>.
   ========================================================================== */
:root {
  color-scheme: dark;

  --bg: #121614;
  --surface: #181d1a; /* stage and console: one tone step off the page */
  --sunken: #101510;
  --line: #343a32;
  --text: #e6eadf;
  --text-2: #b4bcaa;
  --muted: #8e998a;
  --accent: #deec95;
  --accent-ink: #202617;
  --raised: #3c4432;
  --track: #2c342a;

  --band-low: #e6ba76;
  --band-mid: #c5d185;
  --band-high: #99b4a9;

  --font-ui: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-keys: ui-monospace, "JetBrains Mono", "SF Mono", Consolas, monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --header-h: 72px;
  --console-w: 340px;
  --radius: 5px;
  --thumb: 14px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --fast: 140ms;
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

button, a, input { -webkit-tap-highlight-color: transparent; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease),
    color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

button:active:not(:disabled) { transform: translateY(1px); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

h1, h2, p { margin: 0; }

.plain {
  min-height: 40px;
  padding: 0 var(--space-3);
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 14px;
}
.plain:hover { color: var(--accent); background: rgba(222, 236, 149, 0.07); }

/* A dot in a band colour: legend entries and the peak-frequency tag. */
.swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.swatch[data-band="low"] { background: var(--band-low); }
.swatch[data-band="mid"] { background: var(--band-mid); }
.swatch[data-band="high"] { background: var(--band-high); }

/* ==========================================================================
   Header (sits on the page ground; the tone step to the surfaces below is its edge)
   ========================================================================== */
.topbar {
  height: var(--header-h);
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 3px;
}
.brand-icon { color: var(--accent); }
.top-note { margin-left: auto; color: var(--muted); }

/* ==========================================================================
   Layout (default: stage min height, page may scroll)
   ========================================================================== */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--console-w);
  min-height: calc(100svh - var(--header-h));
}

/* Desktop with enough height: header + main fit the viewport exactly. */
@media (min-width: 701px) and (min-height: 720px) {
  body {
    height: 100svh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }
  .layout { min-height: 0; }
  .stage { min-height: 0; }
  .console { min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
}

/* ==========================================================================
   Stage: a flat ground. Atmosphere comes from the canvas (core glow and rods).
   ========================================================================== */
.stage {
  position: relative;
  min-height: 680px;
  overflow: hidden;
  background: var(--surface);
}

#core {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#core:active { cursor: grabbing; }
#core:focus-visible { outline-offset: -4px; }

/* Title row: above the canvas; only its text blocks catch the pointer. */
.stage-head {
  position: absolute;
  top: 28px;
  left: var(--space-6);
  right: var(--space-5);
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  pointer-events: none;
}
.stage-head > * { pointer-events: auto; }

h1 { font-size: 24px; font-weight: 600; line-height: 1.25; }
.subline { margin-top: 6px; max-width: 46ch; color: var(--muted); font-variant-numeric: tabular-nums; word-break: keep-all; }

.live {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-top: 6px;
  font-size: 13px;
  color: var(--text-2);
}
.live i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.live.is-live i { background: var(--accent); }

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: no-preference) {
  .live.is-live i { animation: live-pulse 1.8s ease-in-out infinite; }
}

/* Band legend sits next to the data it explains. */
.stage-legend {
  position: absolute;
  bottom: 52px;
  left: var(--space-6);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: 13px;
  color: var(--text-2);
}
.legend-note { font-size: 12px; color: var(--muted); }

.stage-bottom {
  position: absolute;
  bottom: var(--space-3);
  left: var(--space-6);
  right: var(--space-3);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  font-size: 12px;
  color: var(--muted);
}
.hint { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-4); line-height: 1.8; }
.touch { display: none; }

kbd {
  display: inline-block;
  min-width: 20px;
  margin-right: 2px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 12px/18px var(--font-keys);
  color: var(--text-2);
  text-align: center;
}

/* Drag-and-drop overlay. */
.drop-hint {
  position: absolute;
  inset: var(--space-4);
  z-index: 4;
  display: grid;
  place-content: center;
  gap: var(--space-2);
  text-align: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(18, 22, 20, 0.85);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms var(--ease), visibility 180ms;
}
.drop-hint strong { font-size: 20px; font-weight: 500; color: var(--accent); }
.drop-hint small { font-size: 12px; color: var(--muted); }
.stage.is-dropping .drop-hint { opacity: 1; visibility: visible; }

/* ==========================================================================
   Console (aside): same surface as the stage, separated from it by one line.
   ========================================================================== */
.console {
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 24px;
}

.block {
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.readings { margin-bottom: var(--space-3); padding-bottom: 0; border-bottom: 0; }

.caption {
  margin-bottom: var(--space-3);
  font-size: 15px;
  font-weight: 600;
}

/* Source tabs + upload */
.source-tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--sunken);
  border-radius: var(--radius);
}
.source-tabs button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
}
.source-tabs button:hover { color: var(--text); }
.source-tabs button.selected { background: var(--raised); color: var(--text); }

.upload {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 2px 10px;
  width: 100%;
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: 1px dashed #535d44;
  border-radius: var(--radius);
  text-align: left;
}
.upload:hover { border-color: var(--accent); }
.upload-icon { grid-row: 1 / 3; align-self: center; font-size: 20px; color: var(--muted); }
.upload strong { font-size: 14px; font-weight: 500; }
.upload small { font-size: 12px; color: var(--muted); }

/* Track + transport */
.track { display: flex; align-items: center; gap: var(--space-3); min-width: 0; margin: var(--space-4) 0 var(--space-2); }
.track-text { flex: 1; min-width: 0; }
.track strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.track small { display: block; font-size: 12px; color: var(--muted); }

#play {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
}
#play:hover { background: #eaf4b0; }
#play.is-playing { background: var(--raised); color: var(--accent); border-color: var(--accent); }
#play.is-playing:hover { background: #475139; }

.timeline-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* Sliders: the fill is a layered element, so no gradient is needed. */
.slider-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
}
.slider-title output { font-variant-numeric: tabular-nums; color: var(--text); }

.range {
  --p: 0;
  position: relative;
  height: 24px;
  margin: 2px 0;
}
.range::before,
.range::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  height: 4px;
  margin-top: -2px;
  border-radius: 2px;
}
.range::before { right: 0; background: var(--track); }
.range::after {
  width: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--p));
  background: var(--accent);
}
.range:has(:disabled) { opacity: 0.4; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]:disabled { cursor: default; }
input[type="range"]:focus-visible { outline: none; }

input[type="range"]::-webkit-slider-runnable-track { height: 100%; background: transparent; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((24px - var(--thumb)) / 2);
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  transition: transform var(--fast) var(--ease);
}
input[type="range"]:not(:disabled):hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 3px; }

input[type="range"]::-moz-range-track { height: 100%; background: transparent; }
input[type="range"]::-moz-range-thumb {
  width: calc(var(--thumb) - 4px);
  height: calc(var(--thumb) - 4px);
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
}
input[type="range"]:focus-visible::-moz-range-thumb { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Readouts */
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
}
.band-tag { display: inline-flex; align-items: center; font-size: 12px; color: var(--text-2); }
.band-tag .swatch { margin-right: 5px; }
.meters strong {
  display: block;
  margin: var(--space-1) 0 var(--space-2);
  font-size: 24px;
  font-weight: 500;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.meters small { margin-left: 4px; font-size: 12px; font-weight: 400; color: var(--muted); }
#spectrum { display: block; width: 100%; height: 48px; }

.notes { font-size: 12px; line-height: 1.6; color: var(--muted); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (min-width: 1500px) {
  :root { --console-w: 370px; }
  .console { padding: 28px; }
}

@media (max-width: 1000px) {
  :root { --console-w: 300px; }
  .keys { display: none; }
  .stage-head { flex-direction: column; gap: var(--space-1); }
  .live { padding-top: 0; }
  .console { padding: 20px; }
}

/* Shorter desktop windows: tighten the console so it fits without scrolling. */
@media (min-width: 701px) and (max-height: 960px) {
  .console { padding-top: 20px; padding-bottom: var(--space-3); }
  .block { padding-bottom: 14px; margin-bottom: 14px; }
  .caption { margin-bottom: var(--space-2); }
  .upload { margin-top: var(--space-2); padding: 10px var(--space-4); }
  .track { margin: 12px 0 var(--space-1); }
  .slider-title { margin-top: var(--space-2); }
  .meters strong { margin: 2px 0 var(--space-1); }
  #spectrum { height: 40px; }
  .readings { margin-bottom: var(--space-1); }
}

@media (pointer: coarse) {
  .keys { display: none; }
}

@media (max-width: 700px) {
  :root { --header-h: 64px; }
  .topbar { padding: 0 20px; }
  .top-note { display: none; }
  .topbar > .plain { margin-left: auto; }
  .plain, .source-tabs button { min-height: 44px; }
  .layout { display: block; min-height: 0; }
  .stage { height: 65svh; min-height: 450px; }
  .stage-head { top: 20px; left: 20px; right: 20px; flex-direction: column; gap: var(--space-2); }
  .stage-legend { left: 20px; bottom: 56px; gap: var(--space-3); }
  .stage-bottom { left: 20px; right: 8px; }
  .desktop { display: none; }
  .touch { display: inline; }
  .console { padding: 24px 20px; border-left: 0; border-top: 1px solid var(--line); }
  .range { height: 44px; margin: 0; }
  input[type="range"]::-webkit-slider-thumb { margin-top: calc((44px - var(--thumb)) / 2); }
  .slider-title { margin-top: var(--space-4); }
  .upload { padding: var(--space-4); }
}
