/*
 * SPLash — Raccoon Sound.
 *
 * Brand ID: Signal Chain System RS_2026.
 *   Bus Black #0A0D09 — base, never pure #000
 *   Daysheet White #EDEFE8 — type
 *   Signal Green #6FC23D — signal present: live states, CTAs, active meters
 *   Peak Amber #F2A33C — peak: hover, warnings, the moment before clip (~5% max)
 * Archivo Black for headings, Inter Light for body, JetBrains Mono for labels.
 *
 * The measurement traces stay Smaart cyan: they are data, not brand surface,
 * and green is reserved for live/interactive chrome.
 */

/* ── bundled brand faces (SIL OFL) ───────────────────────── */

@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 100%;
  font-display: block;
  src: url(../fonts/Archivo.woff2) format('woff2-variations');
}
@font-face {
  font-family: 'Archivo';
  font-style: italic;
  font-weight: 100 900;
  font-stretch: 100%;
  font-display: block;
  src: url(../fonts/Archivo-Italic.woff2) format('woff2-variations');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: block;
  src: url(../fonts/Inter.woff2) format('woff2-variations');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: block;
  src: url(../fonts/JetBrainsMono.woff2) format('woff2-variations');
}

:root {
  /* brand */
  --bus-black: #0a0d09;
  --daysheet: #edefe8;
  --signal: #6fc23d;
  --peak: #f2a33c;
  --signal-grad: linear-gradient(105deg, #9ade57 0%, #6fc23d 48%, #3e7c26 100%);

  /* green-cast surfaces stepped up from Bus Black */
  --bg: #0a0d09;
  --panel: #12160f;
  --panel-hd: #191e15;
  --panel-hd-sub: #151a12;
  --field: #080b07;
  --line: #2b3524;
  --line-soft: #1e2619;

  --ink: var(--daysheet);
  --ink-dim: #939b8d;
  --ink-faint: #636c5d;

  /* functional only, not a brand colour: hard overload */
  --clip: #d8402a;

  --disp: 'Archivo', 'Helvetica Neue', Arial, sans-serif;
  --body: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

/*
 * The hidden attribute only sets display:none at user-agent priority, so any
 * component rule that sets a display (.grp, .panel-hd, .notice are all flex)
 * silently defeats it. Without this, dismissed notices and the generator's
 * conditional groups keep taking up space.
 */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 300 12px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── top bar ─────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  height: 48px;
  flex: 0 0 auto;
  background: #12160f;
  border-bottom: 1px solid var(--line);
}

/* wordmark follows the RACCOON SOUND. lockup: upright + italic gradient */
.brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}
.brand .mark {
  font-family: var(--disp);
  font-size: 19px;
  letter-spacing: -0.02em;
}
.brand .mark b {
  font-weight: 900;
  color: var(--daysheet);
}
.brand .mark i {
  font-weight: 900;
  font-style: italic;
  background: var(--signal-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand .by {
  font: 500 8px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  margin-top: 3px;
}
.brand .by em { font-style: normal; color: var(--ink-dim); }

.spacer { flex: 1 1 auto; }

/* ── control groups ──────────────────────────────────────── */

.grp {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

label {
  font: 500 9px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  user-select: none;
}

label.chk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: var(--ink-dim);
  font: 300 11px var(--body);
  text-transform: none;
  letter-spacing: 0;
}
label.chk input { margin: 0; accent-color: var(--signal); }

.unit, .hint {
  font: 500 9px var(--mono);
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

select, input[type=number], input[type=text], input[type=file] {
  background: var(--field);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  font: 400 11px var(--body);
  padding: 3px 5px;
  height: 23px;
}
select { padding-right: 2px; }
select.wide { max-width: 190px; }
input[type=number] {
  width: 58px;
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
input[type=file] { padding: 2px; font-size: 10px; max-width: 220px; }
select:focus, input:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 1px rgba(111, 194, 61, 0.35);
}

input[type=range] { width: 120px; accent-color: var(--signal); }

/* calibration trim: wide enough to nudge by tenths, narrow enough for the bar */
.cal-slider { width: 150px; }
@media (max-width: 900px) {
  .cal-slider { flex: 1 1 140px; width: auto; min-width: 120px; height: 32px; }
}

.btn {
  background: #1c2218;
  color: var(--ink-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  font: 500 10px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  height: 25px;
  padding: 0 14px;
  cursor: pointer;
  transition: color 120ms, border-color 120ms, background 120ms;
}
.btn:hover { color: var(--peak); border-color: var(--peak); }
.btn:active { background: #232b1e; }
.btn.sm { height: 20px; padding: 0 9px; font-size: 9px; }
.btn.wide { width: 100%; margin-top: 8px; }

/* live = green, per the brand system */
.btn.primary {
  background: var(--signal);
  border-color: var(--signal);
  color: #0a0d09;
  font-weight: 800;
}
.btn.primary:hover {
  background: #7fd44a;
  border-color: #7fd44a;
  color: #0a0d09;
}
.btn.primary.running {
  background: transparent;
  border-color: var(--peak);
  color: var(--peak);
}

.seg { display: inline-flex; }
.seg button {
  background: #161b13;
  color: var(--ink-faint);
  border: 1px solid var(--line);
  border-right-width: 0;
  font: 500 10px var(--mono);
  letter-spacing: 0.08em;
  height: 23px;
  padding: 0 9px;
  cursor: pointer;
}
.seg button:first-child { border-radius: 3px 0 0 3px; }
.seg button:last-child { border-right-width: 1px; border-radius: 0 3px 3px 0; }
.seg button:hover { background: #1e2519; color: var(--ink); }
.seg button.on {
  background: var(--signal);
  color: #0a0d09;
  border-color: var(--signal);
  font-weight: 700;
}
.seg.sm button { height: 20px; padding: 0 7px; font-size: 9px; }

.pill {
  font: 500 9px var(--mono);
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  background: var(--field);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 3px 9px;
}
.pill.warn {
  background: var(--clip);
  border-color: var(--clip);
  color: #fff;
  font-weight: 700;
}
/* amber = attention, per the brand system; used for the uncalibrated state */
.pill.amber {
  background: transparent;
  border-color: var(--peak);
  color: var(--peak);
}

/* ── first-run notice ────────────────────────────────────── */

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 6px 0;
  padding: 9px 12px;
  background: #14180f;
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--peak);
  border-radius: 6px;
  flex: 0 0 auto;
}
.notice-key {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--peak);
  flex: 0 0 auto;
}
.notice-body {
  flex: 1 1 auto;
  font: 300 11.5px/1.55 var(--body);
  color: var(--ink-dim);
}
.notice-body b { color: var(--daysheet); font-weight: 600; }
.notice-body em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--peak);
}
.notice-sep { color: var(--ink-faint); margin: 0 4px; }
.notice .btn { flex: 0 0 auto; }

/* ── layout ──────────────────────────────────────────────── */

main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  gap: 6px;
  padding: 6px;
}

.col-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 0;
}

.col-side {
  flex: 0 0 272px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel.grow { flex: 1 1 0; }
.panel.hist { flex: 0 0 152px; }

.panel-hd {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 5px 10px;
  background: var(--panel-hd);
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
  min-height: 30px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.panel-hd.sub { background: var(--panel-hd-sub); }
.panel-hd .title {
  font: 900 11px var(--disp);
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--daysheet);
  white-space: nowrap;
}
/* the small signal dot marks a live panel */
.panel-hd .title::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--signal);
  margin-right: 7px;
  vertical-align: 2px;
}
.panel-hd .ctls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: nowrap;
}

canvas {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: block;
}

.legend { gap: 4px; color: var(--ink-faint); }
.legend .key { width: 12px; height: 2px; display: inline-block; margin-right: 2px; }
.legend .key.fast { background: #3fd0e8; }
.legend .key.leq { background: var(--signal); }

/* ── SPL sidebar ─────────────────────────────────────────── */

.panel.spl { flex: 0 0 auto; padding-bottom: 10px; }

.metric-pick {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 8px 4px;
}

.readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
  padding: 2px 8px 4px;
}
.readout .value {
  font: 900 54px/1 var(--disp);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--signal);
  transition: color 120ms linear;
}
.readout .value.amber { color: var(--peak); }
.readout .value.red { color: var(--clip); }
.readout .units {
  font: 500 10px var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.readout .units i { font-style: normal; color: var(--ink-dim); }

#meter { height: 34px; flex: 0 0 34px; padding: 0 8px; }
#meter2 { height: 26px; flex: 0 0 26px; padding: 0 8px; }

.metric-pick.second {
  align-items: center;
  gap: 7px;
  padding: 12px 8px 2px;
  border-top: 1px solid var(--line-soft);
  margin: 8px 0 0;
}
.metric-pick.second select { flex: 1 1 auto; min-width: 0; }
.readout.second { padding: 0 8px 2px; }
.readout.second .value { font-size: 34px; }
.readout.second .units { font-size: 9px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line-soft);
  margin: 10px 8px 0;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  overflow: hidden;
}
.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  background: #0e120c;
  padding: 4px 7px;
}
.stat .k {
  font: 500 8.5px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  white-space: nowrap;
}
.stat .v {
  font: 400 12px var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.cfg {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px 8px 0;
}
.cfg .grp > label:first-child { width: 36px; flex: 0 0 36px; }
.cfg input[type=number] { width: 48px; }
.cfg select { flex: 1 1 auto; min-width: 0; }
.panel.spl > .btn.wide { width: calc(100% - 16px); margin: 12px 8px 0; }

/* ── generator drawer ────────────────────────────────────── */

.drawer {
  flex: 0 0 auto;
  background: var(--panel);
  margin: 0 6px 6px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}
.drawer .panel-hd { border-bottom: none; border-radius: 6px; }
.presets { gap: 3px; }
.presets button {
  width: 21px;
  height: 21px;
  background: #161b13;
  border: 1px solid var(--line);
  color: var(--ink-faint);
  font: 500 9px var(--mono);
  border-radius: 4px;
  cursor: pointer;
}
.presets button.filled { color: var(--signal); border-color: var(--signal); }
.presets button:hover { background: #1e2519; }

/* ── status bar ──────────────────────────────────────────── */

.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 24px;
  padding: 0 12px;
  background: #0d110b;
  border-top: 1px solid var(--line-soft);
  font: 500 9px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.statusbar .err { color: var(--clip); }
.statusbar .tagline { color: #3c4636; }
.statusbar .tagline b { color: var(--signal); font-weight: 500; }

/* ── scrollbars ──────────────────────────────────────────── */

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--field); }
::-webkit-scrollbar-thumb { background: #2b3524; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4630; }

/* control rows scroll sideways when they overflow; keep the bar unobtrusive */
.panel-hd::-webkit-scrollbar { height: 4px; }
.panel-hd::-webkit-scrollbar-track { background: transparent; }
.panel-hd::-webkit-scrollbar-thumb { background: #2b3524; border-radius: 2px; }

.warn-text { color: var(--peak); }

/* ── touch and small screens ─────────────────────────────── */

button, select, input, label.chk {
  touch-action: manipulation;          /* no 300 ms delay, no double-tap zoom */
}

@media (max-width: 1180px) {
  .col-side { flex-basis: 236px; }
  .readout .value { font-size: 44px; }
}

/*
 * Tablets and phones. The desktop layout pins everything to the viewport;
 * below this width it becomes a single scrolling column with the SPL readout
 * first, because on a handheld that is what people came for.
 */
@media (max-width: 900px) {
  html, body { height: auto; }
  body {
    overflow-y: auto;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: contain;
  }

  .topbar {
    height: auto;
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .topbar .grp { flex: 0 1 auto; }
  .brand { flex: 1 0 100%; }
  .spacer { display: none; }
  #run, #genToggle { flex: 1 1 auto; }

  main {
    flex-direction: column;
    padding: 6px;
    padding-left: calc(6px + env(safe-area-inset-left));
    padding-right: calc(6px + env(safe-area-inset-right));
  }
  .col-side { flex: 0 0 auto; order: -1; overflow: visible; }
  .col-main { order: 1; }

  /* canvases need explicit heights once the column stops filling the viewport */
  .panel.grow { flex: 0 0 auto; }
  #rta { height: 300px; }
  #spectrograph { height: 260px; }
  .panel.hist { flex: 0 0 auto; }
  #history { height: 150px; }

  .panel-hd { min-height: 36px; }
  .seg button, .btn { min-height: 32px; }
  select, input[type=number] { height: 30px; font-size: 13px; }
  input[type=number] { width: 64px; }

  .statusbar {
    height: auto;
    padding: 6px 10px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
    row-gap: 3px;
  }
  .statusbar .tagline { display: none; }

  .notice { margin: 6px; }
  .notice-body { font-size: 12px; }
}

/* Phones. Bigger hit targets, and the readout carries the screen. */
@media (max-width: 620px) {
  .readout .value { font-size: 56px; }
  .readout.second .value { font-size: 34px; }
  .col-side { flex-basis: auto; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .k { font-size: 9px; }
  .stat .v { font-size: 13px; }

  #rta { height: 240px; }
  #spectrograph { height: 200px; }
  #history { height: 130px; }
  #meter { height: 40px; flex-basis: 40px; }
  #meter2 { height: 30px; flex-basis: 30px; }

  .seg button, .btn { min-height: 36px; padding: 0 11px; }
  select, input[type=number] { height: 34px; }
  .metric-pick { flex-wrap: wrap; }

  /* headers scroll horizontally rather than squeezing controls */
  .panel-hd { gap: 12px; }
  .panel-hd::-webkit-scrollbar { height: 3px; }

  .notice { flex-wrap: wrap; }
  .notice .btn { width: 100%; }
}

/* Landscape phone: reclaim vertical space */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .readout .value { font-size: 40px; }
  #rta { height: 200px; }
  #spectrograph { height: 160px; }
  #history { height: 110px; }
}
