/* Header, brand lockup and status-pill rules live in
   ../shared/chrome.css — do not redefine them here. */
/* Design tokens ---------------------------------------------------------
   Shared Thermalsock Labs house style: kraft-paper chassis, ink text, one
   rust accent thread through every interactive/live element. Matches the
   homepage and every sibling app (oscilloscope, subharmonicon, modulus
   studio). The two working canvases (waveform + grain cloud) stay near-
   black like the oscilloscope's scope well; everything around them is the
   shared warm chrome.
------------------------------------------------------------------------- */

:root {
  --chassis: #0B0D12;
  --panel: #0F1118;
  --panel-raised: #161A22;
  --hairline: rgba(138, 160, 184, 0.16);
  --hairline-strong: rgba(138, 160, 184, 0.30);
  --text: #E7F4FF;
  --text-dim: #8AA0B8;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
  --sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --serif-display: 'Space Grotesk', -apple-system, system-ui, sans-serif;

  --accent: #00C8FF;
  --accent-dim: rgba(0, 200, 255, 0.32);
  --accent-fg: #04222C;
  --danger: #FF5A6E;

  --amber: #FFB454;
  --violet: #A98CFF;
  --teal: #3FD9C4;
  --pink: #FF7BB0;
  --blue: #6FA8FF;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--chassis);
  color: var(--text);
  font-family: var(--sans);
}

/* --- Permission gate ("boot screen") ------------------------------------ */

.gate {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(0, 200, 255, 0.08), transparent 60%),
    var(--chassis);
}

.gate[hidden],
.app[hidden] {
  display: none;
}

.gate-panel {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(138, 160, 184, 0.18);
  margin: 24px 0;
}

.gate-panel h1 {
  font-family: var(--serif-display);
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 2px;
  letter-spacing: 0.005em;
}

.gate-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 0 0 20px;
}

.gate-copy {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
  margin: 0 0 24px;
}




select, input[type="range"], button, input[type="text"], input[type="number"] {
  font-family: var(--sans);
}

select {
  width: 100%;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

input[type="text"], input[type="number"] {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12.5px;
}

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 11px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary { background: var(--accent); color: var(--accent-fg); border: none; }
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  margin-top: 10px;
}
.btn-secondary:hover { border-color: var(--accent-dim); }

.btn-small {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  white-space: nowrap;
}
.btn-small:hover { border-color: var(--accent-dim); }
.btn-small.active { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn-small.danger:hover { border-color: var(--danger); color: var(--danger); }

.gate-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 14px;
  line-height: 1.4;
}

/* --- Main app shell ------------------------------------------------------ */

.app { height: 100%; display: flex; flex-direction: column; }



.page-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: rgba(138, 160, 184, 0.04);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 3px;
}
.page-nav-link {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 3px;
}
.page-nav-link:hover { color: var(--text); }
.page-nav-link.active { color: var(--accent-fg); background: var(--accent); font-weight: 600; }


.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 5px 11px;
  border-radius: 3px;
  border: 1px solid var(--hairline-strong);
  background: rgba(138, 160, 184, 0.04);
  color: var(--text-dim);
  cursor: default;
}
.pill.mode { color: var(--violet); border-color: rgba(106, 90, 156, 0.35); background: rgba(106, 90, 156, 0.08); }
.pill.live { color: var(--text-dim); }
.pill.toggle { cursor: pointer; user-select: none; }
.pill.toggle.on { color: var(--accent-fg); background: var(--accent); border-color: transparent; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); }
.status-dot.live { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.stage {
  flex: 1;
  display: flex;
  gap: 18px;
  padding: 18px 22px 12px 22px;
  min-height: 0;
}

.visual-column { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; padding-right: 2px; }

/* --- Spectrogram display -------------------------------------------------- */

.visual-area { display: flex; gap: 14px; height: 260px; flex-shrink: 0; }
.canvas-wrap {
  flex: 1;
  min-width: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6), inset 0 0 2px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(138, 160, 184, 0.08);
  position: relative;
  background: #000;
}
.canvas-wrap .canvas-label {
  position: absolute;
  top: 8px;
  left: 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  z-index: 3;
  pointer-events: none;
}
.canvas-wrap canvas { width: 100%; height: 100%; display: block; }

/* --- Cards / panel groups (shared shape with sibling apps) -------------- */



.chip.violet { background: rgba(106, 90, 156, 0.15); color: var(--violet); }
.chip.pink { background: rgba(163, 74, 114, 0.15); color: var(--pink); }

.row .row-value { font-family: var(--mono); font-size: 11px; color: var(--accent); width: 52px; text-align: right; flex-shrink: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-2 .row { grid-column: span 1; }


/* --- Grain engine controls card ----------------------------------------- */

.controls-card { flex-shrink: 0; }

/* --- Rack panel: the dark hardware-module surface for the actual grain
   engine and performance knobs, styled after classic granular-synth plugin
   panels (dark chassis, amber section headers, round knobs, dark numeric
   readouts) rather than the site's light kraft-paper chrome around it. --- */

.rack-panel {
  background: #17140f;
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 10px;
  padding: 14px 6px 12px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), inset 0 0 24px rgba(0, 0, 0, 0.4);
}

.rack-section {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0 12px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  min-width: 108px;
  flex-shrink: 0;
}
.rack-section:last-child { border-right: none; }

.rack-section-header {
  background: linear-gradient(180deg, #d3a05a, #a9752e);
  color: #2b1a08;
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  text-align: center;
  padding: 4px 6px;
  border-radius: 5px;
  margin-bottom: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
}
.rack-section-header.neutral {
  background: #2a2621;
  color: #c8bfae;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.knob-row { display: flex; gap: 12px; justify-content: center; margin-bottom: 10px; flex-wrap: wrap; }

.rack-select {
  background: #232019;
  color: #e8dcc8;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  font-size: 10px;
  padding: 5px 6px;
  width: 100%;
  margin-bottom: 6px;
}
.rack-select:last-child { margin-bottom: 0; }

.rack-divider-label {
  font-size: 8.5px;
  color: #6f6858;
  text-align: center;
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.rack-toggle-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.rack-pill {
  background: #232019;
  color: #a89a80;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  font-size: 10.5px;
  font-family: var(--sans);
  padding: 6px 10px;
  cursor: pointer;
  text-align: center;
  user-select: none;
}
.rack-pill.on {
  background: linear-gradient(180deg, #d3a05a, #a9752e);
  color: #2b1a08;
  font-weight: 700;
  border-color: transparent;
}
.rack-pill:hover { border-color: rgba(255, 255, 255, 0.22); }
button.rack-pill { font-family: var(--sans); }

/* --- Knob widget (js/knobControl.js) ------------------------------------- */

.knob-wrap { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.knob-label { font-family: var(--sans); font-size: 9px; color: #8f8676; text-transform: uppercase; letter-spacing: 0.05em; }
.knob-svg { cursor: ns-resize; touch-action: none; outline: none; }
.knob-svg:focus .knob-face { stroke: var(--accent); }
.knob-track { fill: none; stroke: rgba(255, 255, 255, 0.09); stroke-width: 4; stroke-linecap: round; }
.knob-fill { fill: none; stroke: #d3a05a; stroke-width: 4; stroke-linecap: round; filter: drop-shadow(0 0 3px rgba(211, 160, 90, 0.45)); }
.knob-face { fill: #221f19; stroke: rgba(0, 0, 0, 0.6); stroke-width: 1; }
.knob-pointer { stroke: #f0e4d0; stroke-width: 2; stroke-linecap: round; }
.knob-value {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  color: #f2e6d3;
  background: #3a2116;
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 2px 6px;
  min-width: 38px;
  text-align: center;
  cursor: text;
}
.knob-value-input {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  color: #f2e6d3;
  background: #3a2116;
  border: 1px solid #d3a05a;
  border-radius: 4px;
  padding: 2px 6px;
  width: 54px;
  text-align: center;
}
.knob-unit { font-size: 8.5px; color: #6f6858; }

/* --- Performance controls: macros + XY pad ------------------------------ */

.performance-card { flex-shrink: 0; }

.xy-pad-wrap { display: flex; flex-direction: column; gap: 6px; }
.xy-pad {
  width: 100%;
  height: 90px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #1d1b16;
  position: relative;
  cursor: crosshair;
  touch-action: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 20px 20px;
}
.xy-pad-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #d3a05a;
  box-shadow: 0 0 8px rgba(211, 160, 90, 0.6);
  pointer-events: none;
}

.xy-axis-selects { display: flex; gap: 6px; }
.xy-axis-selects select { font-size: 10.5px; padding: 4px 6px; }


/* --- Toggle-chip rows for advanced/discrete features --------------------- */

.toggle-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle-chip {
  font-family: var(--sans);
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 3px;
  border: 1px solid var(--hairline-strong);
  background: rgba(138, 160, 184, 0.04);
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.toggle-chip.on { color: var(--accent-fg); background: var(--accent); border-color: transparent; }

/* --- Right sidebar -------------------------------------------------------- */

.panel {
  width: 320px;
  flex-shrink: 0;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  gap: 14px;
}

/* --- MIDI panel ------------------------------------------------------------ */

.midi-device-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.midi-device-list li { list-style: none; font-size: 11.5px; padding: 5px 8px; border-radius: 6px; background: var(--panel-raised); display: flex; justify-content: space-between; }

/* --- Presets ---------------------------------------------------------------- */

.preset-row { display: flex; gap: 6px; margin-bottom: 8px; }
.preset-row input[type="text"] { flex: 1; }
.preset-row select { flex: 1; }
.snapshot-bank { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.snapshot-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 6px; border: 1px solid var(--hairline-strong); background: var(--panel-raised); cursor: pointer; font-size: 10.5px; }
.snapshot-btn:hover { border-color: var(--accent-dim); }
.snapshot-btn .snap-hint { font-size: 9px; color: var(--text-dim); }

/* --- Footer readout strip --------------------------------------------------- */

.secondary-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; flex-shrink: 0; }

.footer-strip {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  padding: 8px 22px 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
  border-top: 1px solid var(--hairline);
}
.footer-strip b { color: var(--accent); font-weight: 600; }

@media (max-width: 980px) {
  .secondary-row { grid-template-columns: 1fr; }
  html, body { overflow-y: auto; height: auto; }
  .stage { flex-direction: column; }
  .panel { width: 100%; padding-bottom: 20px; }
  .visual-area { height: 200px; }
}

/* --- Support widget & legal bar ------------------------------------------ */

#supportWidget { position: fixed; left: 14px; bottom: 34px; z-index: 10; }
#supportWidget img { display: block; }

#legalBar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 5px 12px; font-size: 10.5px; color: var(--text-dim);
  background: rgba(11, 13, 18, 0.9);
  border-top: 1px solid var(--hairline);
  font-family: var(--mono);
}
#legalBar a { color: var(--text-dim); text-decoration: none; }
#legalBar a:hover { color: var(--accent); }

/* --- Signal-chain numbering, per-stage bypass, record, maximised view -----
   The processor runs Freeze -> Shift -> Reverse -> Smear -> Scatter in a
   fixed order, but the rack showed five equal knob clusters with no hint of
   that. Numbering plus connectors teaches the tool. */

.rack-chain { position: relative; }
.rack-chain .rack-section { position: relative; }
/* Connector arrow between consecutive stages. */
.rack-chain .rack-section + .rack-section::before {
  content: '';
  position: absolute;
  left: -13px;
  top: 18px;
  width: 7px; height: 7px;
  border-right: 1.5px solid var(--hairline);
  border-bottom: 1.5px solid var(--hairline);
  transform: rotate(-45deg);
}

.rack-section-header {
  display: flex;
  align-items: center;
  gap: 7px;
}
.stage-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  font-family: var(--mono, var(--mono), monospace);
  font-size: 8.5px;
  color: var(--text-faint);
  flex: none;
}

/* A knob at zero looked identical to an active stage at low depth. Bypass
   makes "this stage is doing nothing" an explicit, visible state. */
.stage-bypass {
  margin-left: auto;
  width: 26px; height: 14px;
  border-radius: 3px;
  border: 1px solid var(--hairline);
  background: transparent;
  cursor: pointer;
  position: relative;
  flex: none;
  transition: background .2s, border-color .2s;
}
.stage-bypass::after {
  content: '';
  position: absolute;
  left: 2px; top: 1.5px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform .2s, background .2s;
}
.stage-bypass[aria-pressed="true"] { background: rgba(138, 160, 184, 0.10); }
.stage-bypass[aria-pressed="true"]::after {
  transform: translateX(11px);
  background: var(--text-faint);
}
.rack-section[data-bypassed="true"] { opacity: 0.42; }
.rack-section[data-bypassed="true"] .knob-row { filter: grayscale(1); }

/* Maximised spectrogram — it's the whole point of the app and it was sharing
   vertical space with a rack of equal visual weight. */
#spectrogramWrap { position: relative; }
.view-expand {
  position: absolute;
  right: 10px; top: 10px;
  z-index: 4;
  font-family: var(--mono, var(--mono), monospace);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: rgba(11, 13, 18, 0.85);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 5px 11px;
  cursor: pointer;
}
.view-expand:hover { color: var(--text); border-color: var(--accent); }
body[data-maximised="true"] .rack-panel,
body[data-maximised="true"] .panel,
body[data-maximised="true"] .rack-toggle-row { display: none; }
body[data-maximised="true"] #spectrogramWrap { height: calc(100vh - 150px); }

.pill.action, .pill.record {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono, var(--mono), monospace);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 6px 13px;
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
}
.pill.action:hover { color: var(--text); border-color: var(--accent); }
.pill.record .rec-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  transition: background .2s;
}
.pill.record[aria-pressed="true"] {
  color: var(--danger, var(--danger));
  border-color: var(--danger, var(--danger));
  background: rgba(255, 90, 110, 0.10);
}
.pill.record[aria-pressed="true"] .rec-dot {
  background: var(--danger, var(--danger));
  animation: ts-rec-pulse 1.4s ease-in-out infinite;
}
@keyframes ts-rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) {
  .pill.record[aria-pressed="true"] .rec-dot { animation: none; }
}

.spaced { margin-top: 6px; }
.spaced-lg { margin-top: 8px; }

.panel-note {
  font-size: 12px;
  color: var(--text-faint);
  margin: 0 0 12px 0;
  line-height: 1.5;
}
.row-divider {
  height: 1px;
  background: var(--hairline);
  margin: 12px 0;
}
