:root {
  --bg: #05070c;
  --panel-bg: rgba(10, 18, 30, 0.7);
  --panel-border: rgba(77, 243, 255, 0.2);
  --cyan: #4df3ff;
  --cyan-dim: #7fb8c2;
  --text: #e4f6f8;
  --orange: #ff9a52;
  --danger: #ff5252;
  --ok: #6dffb0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100%;
  overflow-x: hidden;
}

.studio-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.studio-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.studio-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.studio-back-link {
  display: block;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  transition: opacity 0.15s ease;
}

.studio-back-link:hover {
  opacity: 0.8;
}

.studio-logo {
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 10px;
}

.studio-title h1 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--cyan);
  text-shadow: 0 0 18px rgba(77, 243, 255, 0.4);
}

.studio-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--orange);
  border: 1px solid rgba(255, 154, 82, 0.4);
  border-radius: 999px;
  padding: 3px 10px;
}

.archetype-picker,
.before-after-toggle {
  display: flex;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 4px;
}

.archetype-btn,
.before-after-toggle button {
  background: none;
  border: none;
  color: var(--cyan-dim);
  padding: 10px 16px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 44px;
}

.archetype-btn.active,
.before-after-toggle button.active {
  background: rgba(77, 243, 255, 0.16);
  color: var(--cyan);
  box-shadow: 0 0 14px rgba(77, 243, 255, 0.2);
}

.dash {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 18px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.dash-readout {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.dash-speed {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 140px;
}

.dash-value {
  font-size: 3.2rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 0 20px rgba(77, 243, 255, 0.35);
}

.dash-unit {
  font-size: 0.9rem;
  color: var(--cyan-dim);
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(70px, 1fr));
  gap: 10px;
  flex: 1;
}

.dash-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dash-label {
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--cyan-dim);
}

.dash-item-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--cyan-dim);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #555;
  flex: 0 0 auto;
}

.status-dot.active {
  background: var(--ok);
  box-shadow: 0 0 10px var(--ok);
}

.driving-sim {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 18px;
}

.driving-sim h2,
.controls-panel h3,
.preset-panel h2 {
  margin: 0 0 12px;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  color: var(--cyan-dim);
  text-transform: uppercase;
}

.speed-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.speed-slider-row label {
  font-size: 0.8rem;
  color: var(--cyan-dim);
  flex: 0 0 auto;
}

.speed-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--cyan);
  height: 44px;
}

.speed-slider-row span {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: right;
  color: var(--cyan);
  font-weight: 600;
}

.driving-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.driving-buttons button {
  background: rgba(77, 243, 255, 0.08);
  border: 1px solid rgba(77, 243, 255, 0.3);
  color: var(--cyan);
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}

.driving-buttons button:active {
  transform: scale(0.97);
}

.emergency-btn {
  background: rgba(255, 82, 82, 0.12) !important;
  border-color: rgba(255, 82, 82, 0.55) !important;
  color: var(--danger) !important;
  margin-left: auto;
}

.emergency-btn.muted {
  background: var(--danger) !important;
  color: #1a0000 !important;
}

.before-after {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.before-after-label {
  font-size: 0.8rem;
  color: var(--cyan-dim);
}

.controls-and-presets {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 18px;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-group {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
}

.control-row {
  padding: 10px 0;
  border-bottom: 1px solid rgba(77, 243, 255, 0.08);
}

.control-row:last-child {
  border-bottom: none;
}

.control-top-line {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.82rem;
}

.control-label {
  color: var(--text);
}

.control-value {
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.control-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--cyan);
  height: 44px;
}

.control-reset-btn {
  flex: 0 0 auto;
  background: none;
  border: 1px solid rgba(77, 243, 255, 0.3);
  color: var(--cyan-dim);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.68rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

.preset-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  align-self: start;
  position: sticky;
  top: 16px;
}

.preset-actions-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.preset-actions-row input[type="text"] {
  flex: 1;
  min-width: 0;
  background: rgba(77, 243, 255, 0.06);
  border: 1px solid rgba(77, 243, 255, 0.3);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.8rem;
  min-height: 44px;
}

.preset-actions-row button {
  flex: 0 0 auto;
  background: rgba(77, 243, 255, 0.1);
  border: 1px solid rgba(77, 243, 255, 0.35);
  color: var(--cyan);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.preset-actions-row button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.preset-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: rgba(77, 243, 255, 0.05);
  border: 1px solid rgba(77, 243, 255, 0.15);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  min-height: 44px;
}

.preset-item.active {
  border-color: var(--cyan);
  background: rgba(77, 243, 255, 0.12);
}

.preset-item-name {
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-item-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.preset-item-actions button {
  background: none;
  border: 1px solid rgba(77, 243, 255, 0.25);
  color: var(--cyan-dim);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.62rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

.preset-hint {
  font-size: 0.7rem;
  color: var(--cyan-dim);
  min-height: 1.2em;
  margin: 0;
}

.preset-hint.ok { color: var(--ok); }
.preset-hint.error { color: var(--danger); }

.studio-footer {
  margin-top: 24px;
  font-size: 0.68rem;
  color: var(--cyan-dim);
  text-align: center;
}

@media (max-width: 820px) {
  .controls-and-presets {
    grid-template-columns: 1fr;
  }
  .preset-panel {
    position: static;
  }
  .dash-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 480px) {
  .dash-value { font-size: 2.4rem; }
  .driving-buttons button { flex: 1 1 45%; }
  .emergency-btn { margin-left: 0; flex: 1 1 100%; }
}


/* ---------------------------------------------------------------------------
   Studio toolbar, Simple view, and not-applicable controls
   ------------------------------------------------------------------------- */
.studio-toolbar {
  display: flex;
  gap: 8px;
  margin: 0 0 14px;
  flex-wrap: wrap;
}

.studio-toolbar-btn {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(150, 178, 196, 0.32);
  background: rgba(27, 34, 44, 0.92);
  color: #e6edf2;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.studio-toolbar-btn:hover,
.studio-toolbar-btn:focus-visible {
  border-color: #5fd3e4;
  color: #5fd3e4;
}

.studio-toolbar-btn[aria-pressed="true"] {
  border-color: #5fd3e4;
}

/* Simple view: only the handful of controls that decide the character.
   The rest stay in the DOM so their values are preserved. */
body.studio-simple .control-row:not([data-essential]) {
  display: none;
}

/* A control that does nothing on this engine layout. Shown but clearly
   inert, so it reads as "not applicable" rather than "broken". */
/* A control that does nothing on this layout is removed, not greyed. A
   visible control you cannot move reads as broken; an absent one does not. */
.control-row.control-hidden-na {
  display: none;
}

.na-note {
  margin: 10px 0 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: #7c909d;
  font-style: italic;
}

.na-note[hidden] { display: none; }

/* ---------------------------------------------------------------------------
   Engine Layout picker
   Nine named buttons instead of a numbered slider track — the layout decides
   more about the sound than everything else combined, so the options should
   be visible rather than discovered by dragging.
   ------------------------------------------------------------------------- */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.picker-btn {
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(150, 178, 196, 0.28);
  background: rgba(20, 26, 34, 0.85);
  color: #b6c4cf;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.picker-btn:hover,
.picker-btn:focus-visible {
  border-color: #5fd3e4;
  color: #e6edf2;
}

.picker-btn.active {
  border-color: #5fd3e4;
  background: rgba(95, 211, 228, 0.14);
  color: #5fd3e4;
  font-weight: 600;
}

/* The range input still carries the value for presets/reset; it is not shown. */
.picker-hidden-input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------------------
   A/B slots
   ------------------------------------------------------------------------- */
.ab-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 0;
}

.ab-label {
  font-size: 0.78rem;
  color: #93a4b2;
}

.ab-group { display: inline-flex; gap: 4px; }

.ab-btn {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid rgba(150, 178, 196, 0.28);
  background: rgba(20, 26, 34, 0.85);
  color: #b6c4cf;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.ab-btn:hover:not(:disabled) { border-color: #5fd3e4; color: #e6edf2; }
.ab-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ab-store.filled { border-color: rgba(95, 211, 228, 0.5); }
.ab-recall { min-width: 44px; font-weight: 600; }
.ab-recall.active {
  border-color: #5fd3e4;
  background: rgba(95, 211, 228, 0.16);
  color: #5fd3e4;
}

/* ---------------------------------------------------------------------------
   Live spectrum
   ------------------------------------------------------------------------- */
.spectrum-wrap {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(150, 178, 196, 0.16);
  border-radius: 12px;
  background: rgba(12, 16, 22, 0.6);
}

.spectrum-label {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #647686;
  margin-bottom: 6px;
}

#studioSpectrum {
  display: block;
  width: 100%;
  height: 110px;
}

/* ---------------------------------------------------------------------------
   Load-your-own-recording
   ------------------------------------------------------------------------- */
.recording-loader {
  margin: 10px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recording-status {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: #93a4b2;
}

/* ---------------------------------------------------------------------------
   Phone layout and touch hardening
   ------------------------------------------------------------------------- */
button,
a,
input,
select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  .studio-shell {
    padding:
      calc(12px + env(safe-area-inset-top, 0px))
      max(12px, env(safe-area-inset-right, 0px))
      calc(40px + env(safe-area-inset-bottom, 0px))
      max(12px, env(safe-area-inset-left, 0px));
  }

  .studio-header {
    align-items: stretch;
    gap: 14px;
  }

  .studio-title { width: 100%; }
  .studio-title h1 { font-size: 1.2rem; }

  .archetype-picker {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .archetype-btn {
    min-width: 0;
    padding: 10px 4px;
    font-size: 0.74rem;
  }

  .dash,
  .driving-sim,
  .control-group,
  .preset-panel {
    padding: 14px;
    border-radius: 12px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .dash-readout { gap: 12px; }
  .dash-speed { min-width: 100px; }
  .dash-grid { gap: 8px; }

  .speed-slider-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
  }

  .speed-slider-row input[type="range"] {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .speed-slider-row span {
    min-width: 0;
    grid-column: 2;
    grid-row: 1;
  }

  .before-after {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .before-after-toggle { width: 100%; }
  .before-after-toggle button { flex: 1; }

  .preset-actions-row { flex-wrap: wrap; }
  .preset-actions-row input[type="text"] {
    flex-basis: 150px;
    font-size: 16px; /* avoids focus zoom on iOS */
  }
  .preset-actions-row button { flex: 1 1 120px; }

  .picker-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #studioSpectrum { height: 84px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .studio-shell {
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .studio-header { margin-bottom: 12px; }
  .dash,
  .driving-sim { margin-bottom: 12px; }
  #studioSpectrum { height: 72px; }
}
