:root {
  --bg: #0b0c10;
  --bg2: #12141a;
  --panel: #161923;
  --line: #242832;
  --text: #d7dae0;
  --muted: #7a8493;
  --accent: #00d4ff;
  --rec: #e0433a;
}

/* light theme — chrome only; the spectrogram canvases stay dark on purpose */
body.light {
  --bg: #eef0f4;
  --bg2: #ffffff;
  --panel: #ffffff;
  --line: #d7dbe2;
  --text: #1b1e24;
  --muted: #5c6675;
  --accent: #0a7fb8;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
/* soften theme switching */
body, .bar, .exbar, .side, .panel, .statusbar, .menu, .btn, .drawer {
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

/* toolbar */
.bar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: #384154; }
.btn.primary { border-color: #2a5f6e; }
.btn.rec { background: var(--rec); border-color: var(--rec); color: #fff; }
.btn.small { padding: 3px 8px; }
.btn.icon { padding: 6px 9px; font-size: 15px; line-height: 1; }
.btn.file { display: inline-flex; align-items: center; }

/* split button: primary action + caret dropdown */
.split { position: relative; display: inline-flex; }
.split .btn { border-radius: 7px; }
.split #btnSave { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split .caret { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: none; padding: 6px 8px; }
.menu { position: absolute; top: calc(100% + 4px); right: 0; z-index: 30; min-width: 240px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); display: flex; flex-direction: column; }
.menu[hidden] { display: none; }
.menu button { background: none; border: none; color: var(--text); text-align: left; padding: 8px 10px;
  border-radius: 6px; cursor: pointer; font-size: 13px; }
.menu button:hover { background: rgba(120,150,210,0.15); }

/* Fixed gradient on the TRACK; the cover (from the right) hides the un-reached
   part, so a louder level reveals more of the same fixed green→yellow→red scale.
   Stops line up with the dBFS→% map in setLevel: ~52% ≈ -30 dB, ~66% ≈ -20 dB,
   red from ~90% ≈ -6 dB (clipping / "creak" risk). */
.level {
  position: relative; width: 100px; height: 9px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 5px;
  background: linear-gradient(90deg, #2ecc71 0%, #2ecc71 52%, #e0c020 66%, #e0c020 82%, #e0433a 92%, #e0433a 100%);
}
.level-cover { position: absolute; top: 0; right: 0; height: 100%; width: 100%; background: var(--bg2); transition: width .05s linear; }

/* exercise bar */
.exbar {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 8px 14px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.select { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; font-size: 13px; min-width: 240px; }
.exText { font-size: 13px; }
.exHint { color: var(--text); }
.exText details { margin-top: 3px; }
.exText summary { color: var(--accent); cursor: pointer; font-size: 12px; }
.exDetail { color: var(--muted); margin-top: 4px; max-width: 780px; }

/* stage */
.stage { flex: 1; display: flex; min-height: 0; }
.view { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 10px; gap: 6px; }
.live-wrap { position: relative; flex: 1; min-height: 0; }
.canvas-live { position: absolute; inset: 0; width: 100%; height: 100%; background: #440154; border: 1px solid var(--line); border-radius: 8px; image-rendering: auto; }
.fmt-trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.grid-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.grid-overlay line { stroke: rgba(255,255,255,0.16); stroke-width: 1; }
.grid-overlay text { fill: #fff; font: 10px system-ui; paint-order: stroke; stroke: rgba(0,0,0,0.55); stroke-width: 3px; }

/* Live formant read-out: a dashed line at the current formant frequency plus a
   pill badge with the value, tracking the newest column at the right edge. */
.fmt-line { position: absolute; left: 0; right: 0; height: 0; border-top: 1.5px dashed; opacity: 0.85; pointer-events: none; transition: top .05s linear; }
.fmt-badge { position: absolute; right: 6px; transform: translateY(-50%); padding: 0 4px; border-radius: 7px; font: 700 14px/1.35 ui-monospace, monospace; color: #fff; white-space: nowrap; pointer-events: none; box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: top .05s linear; }
.fmt-hidden { display: none; }

.readout { color: var(--text); font: 12px ui-monospace, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.readout .r-f0 { color: #00d4ff; } .readout .r-f1 { color: #e6194B; }
.readout .r-f2 { color: #d13fd1; } .readout .r-f3 { color: #c8a400; }
.readout .r-time { display: inline-block; min-width: 3.4em; text-align: right; }
.readout .r-num { display: inline-block; min-width: 2.6em; text-align: right; }
.canvas-timeline { width: 100%; flex: 1; min-height: 0; background: #0e0f13; border: 1px solid var(--line); border-radius: 8px; cursor: crosshair; touch-action: none; }
.viewFoot { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.tag { color: var(--accent); }
.hintline { color: #5a6472; }

/* sidebar */
.side { width: 300px; border-left: 1px solid var(--line); background: var(--bg2); padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.panel-h { padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; padding: 10px; }
.tg { font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; }

.metrics { padding: 10px; }
.metrics-empty { color: var(--muted); font-size: 13px; }
.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.metric { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted #22262f; padding-bottom: 3px; }
.m-label { color: var(--muted); font-size: 12px; }
.m-val { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.metrics-sub { margin: 10px 0 6px; color: #6a7382; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border-top: 1px dotted #22262f; padding-top: 8px; }
.metrics-note { margin-top: 10px; color: var(--muted); font-size: 11.5px; line-height: 1.4; }

/* status */
.statusbar { padding: 5px 14px; background: var(--bg2); border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }

/* help drawer */
.drawer {
  position: fixed; top: 0; right: -460px; width: 440px; max-width: 92vw; height: 100%;
  background: var(--bg2); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.4);
  transition: right .22s ease; z-index: 20; display: flex; flex-direction: column;
}
.drawer.open { right: 0; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 4px 16px 24px; overflow-y: auto; }
.drawer-body section { border-bottom: 1px solid var(--line); padding: 12px 0; }
.drawer-body h3 { font-size: 14px; margin: 0 0 6px; color: var(--accent); }
.drawer-body p, .drawer-body li { font-size: 13px; color: var(--text); }
.drawer-body ul { margin: 6px 0; padding-left: 18px; }

@media (max-width: 760px) {
  .stage { flex-direction: column; }
  .side { width: auto; border-left: none; border-top: 1px solid var(--line); }
  .toggles { grid-template-columns: 1fr 1fr 1fr; }
}
