@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #9a7cff;
}

:root {
  color-scheme: dark;
  --bg: #06080d;
  --bg-deep: #020409;
  --panel: rgba(15, 19, 28, 0.92);
  --panel-soft: rgba(17, 22, 32, 0.76);
  --line: rgba(154, 174, 211, 0.12);
  --line-strong: rgba(171, 190, 225, 0.2);
  --text: #eef2fb;
  --muted: #8e99ad;
  --faint: #657085;
  --accent: #9a7cff;
  --accent-rgb: 154, 124, 255;
  --stage-ratio: 1.7777778;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -30%, rgba(67, 82, 118, 0.16), transparent 44rem),
    linear-gradient(145deg, #090c13 0%, var(--bg) 52%, #05070b 100%);
  font-size: 13px;
  overflow-x: hidden;
}

button, select, input { font: inherit; }
button, select { color: inherit; }
button { border: 0; }

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 82%, white);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) 108px;
  position: relative;
  transition: --accent 1.8s ease;
}

.app-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 12, 18, 0.78);
  backdrop-filter: blur(24px);
  z-index: 20;
}

.brand {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: max-content;
}

.brand > span:last-child { display: flex; align-items: baseline; gap: 16px; }
.brand strong { font-size: 19px; font-weight: 560; letter-spacing: -0.02em; }
.brand small, .eyebrow { color: #9da9c1; font-size: 9px; letter-spacing: 0.22em; text-transform: uppercase; }

.brand-mark { display: flex; gap: 5px; }
.brand-mark i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px rgba(var(--accent-rgb), .6); }
.brand-mark i:nth-child(2) { opacity: .65; }
.brand-mark i:nth-child(3) { opacity: .35; }

.ratio-control {
  margin: 0;
  padding: 3px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(23, 28, 39, .74);
}

.ratio-button {
  min-width: 62px;
  height: 32px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .25s, background .25s, box-shadow .25s;
}

.ratio-button.is-active {
  color: white;
  background: rgba(var(--accent-rgb), .15);
  box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), .75), 0 0 18px rgba(var(--accent-rgb), .13);
}

.mic-cluster { justify-self: end; display: flex; align-items: center; gap: 14px; }
.mic-state { display: flex; align-items: center; gap: 9px; min-width: 150px; }
.mic-state > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.mic-state strong { font-size: 11px; font-weight: 520; }
.mic-state small { color: var(--muted); font-size: 9px; }
.status-orb { width: 26px; height: 26px; border-radius: 50%; background: rgba(136, 150, 174, .12); border: 1px solid var(--line-strong); position: relative; }
.status-orb::after { content: ""; position: absolute; inset: 7px 10px 6px; border: 1.5px solid #8e99ad; border-radius: 6px; }
.mic-state.is-live .status-orb { background: rgba(var(--accent-rgb), .14); box-shadow: 0 0 18px rgba(var(--accent-rgb), .17); }
.mic-state.is-live .status-orb::after { border-color: var(--accent); }

.level-meter { height: 24px; display: flex; align-items: center; gap: 3px; }
.level-meter i { display: block; width: 3px; height: 5px; border-radius: 2px; background: #29303c; transition: height 80ms, background 120ms; }
.level-meter i.is-lit { background: var(--accent); box-shadow: 0 0 6px rgba(var(--accent-rgb), .42); }

.button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 0 14px;
  background: rgba(27, 33, 45, .82);
  color: #dfe5f2;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .2s;
}
.button:hover { border-color: rgba(var(--accent-rgb), .65); background: rgba(var(--accent-rgb), .11); }
.button:active { transform: translateY(1px); }
.button-primary { border-color: rgba(var(--accent-rgb), .5); background: rgba(var(--accent-rgb), .13); }

.instrument-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 244px minmax(480px, 1120px) 244px;
  justify-content: center;
  align-items: stretch;
  gap: 14px;
  padding: 14px 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 19px 17px;
  background:
    linear-gradient(145deg, rgba(21, 26, 37, .93), rgba(11, 15, 22, .94));
  box-shadow: 0 18px 48px rgba(0, 0, 0, .18), inset 0 1px rgba(255, 255, 255, .015);
  min-width: 0;
}

.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel > .eyebrow { display: block; margin-bottom: 20px; }

.icon-button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.icon-button:hover { color: white; background: rgba(var(--accent-rgb), .1); }
.icon-button svg, .privacy-note svg, .performance-exit svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.select-field { display: grid; gap: 8px; margin-bottom: 17px; color: #dce2ef; }
.select-field > span:first-child { font-size: 11px; color: #c8d0df; }
select {
  width: 100%;
  height: 42px;
  padding: 0 32px 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #151a24;
  color: #e8edf8;
  cursor: pointer;
}
.select-with-swatches { position: relative; display: block; }
.select-with-swatches select { padding-left: 73px; }
.mini-swatches { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); z-index: 1; display: flex; }
.mini-swatches i { width: 22px; height: 22px; margin-right: -8px; border-radius: 50%; border: 1px solid rgba(255,255,255,.18); }

.control-divider { height: 1px; background: var(--line); margin: 21px 0; }
.slider-list { display: grid; gap: 18px; }
.slider-field { display: grid; gap: 8px; }
.slider-field > span { display: flex; align-items: center; justify-content: space-between; color: #cad2e1; font-size: 11px; }
.slider-field output { color: var(--muted); font-variant-numeric: tabular-nums; }
input[type="range"] {
  appearance: none;
  width: 100%;
  height: 15px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 4px; background: linear-gradient(to right, var(--accent) 0 var(--range, 50%), #2b3240 var(--range, 50%) 100%); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 13px; height: 13px; margin-top: -5px; border-radius: 50%; background: #dce7ff; border: 1px solid white; box-shadow: 0 1px 8px rgba(0,0,0,.5); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 4px; background: #2b3240; }
input[type="range"]::-moz-range-progress { height: 3px; border-radius: 4px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border: 0; border-radius: 50%; background: #dce7ff; }

.stage-column { min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; }
.stage-wrap {
  position: relative;
  width: min(100%, calc((100vh - 228px) * var(--stage-ratio)));
  max-width: 1120px;
  max-height: calc(100vh - 228px);
  aspect-ratio: var(--stage-ratio);
  transition: width .55s cubic-bezier(.22,.8,.24,1), max-width .55s, aspect-ratio .55s;
}
.stage-wrap::before {
  content: "";
  position: absolute;
  inset: -22px;
  background: radial-gradient(ellipse, rgba(var(--accent-rgb), .08), transparent 68%);
  filter: blur(18px);
  pointer-events: none;
}
.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid rgba(176, 197, 229, .2);
  background: #03050a;
  box-shadow: 0 26px 80px rgba(0,0,0,.48), inset 0 0 50px rgba(0,0,0,.2);
  isolation: isolate;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#trace-canvas { z-index: 2; pointer-events: none; }
.stage-vignette { position: absolute; inset: 0; z-index: 3; pointer-events: none; box-shadow: inset 0 0 80px rgba(0,0,0,.38); }
.stage.is-fallback::before,
.stage.is-fallback::after {
  content: "";
  position: absolute;
  width: 64%;
  aspect-ratio: 1.6;
  left: 18%;
  top: 23%;
  border-radius: 50%;
  filter: blur(35px);
  background: conic-gradient(from 120deg, transparent, rgba(var(--accent-rgb), .55), #64a8ff99, transparent 68%);
  animation: fallback-drift 9s ease-in-out infinite alternate;
  z-index: 1;
}
.stage.is-fallback::after { animation-duration: 13s; animation-direction: alternate-reverse; opacity: .45; transform: rotate(50deg); }
@keyframes fallback-drift { to { transform: translate(5%, -6%) rotate(16deg) scale(1.12); } }

.stage-guidance { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 10px; }
.stage-guidance strong { color: #dfe5f1; font-weight: 520; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px rgba(var(--accent-rgb), .6); }
.compatibility-notice { width: min(100%, 620px); padding: 10px 13px; border: 1px solid #6e5835; border-radius: 9px; background: #1b160f; color: #d6c7aa; font-size: 11px; }
.compatibility-notice strong { margin-right: 8px; color: #f0d6a0; }

.reactive-panel .slider-list { gap: 22px; }
.toggle-field { display: flex; align-items: center; justify-content: space-between; margin-bottom: 17px; color: #d8deea; font-size: 11px; cursor: pointer; }
.toggle-field input { position: absolute; opacity: 0; pointer-events: none; }
.toggle { width: 34px; height: 19px; padding: 2px; border-radius: 12px; background: #29313f; transition: background .2s; }
.toggle::after { content: ""; display: block; width: 15px; height: 15px; border-radius: 50%; background: #eef4ff; transition: transform .2s; }
.toggle-field input:checked + .toggle { background: var(--accent); box-shadow: 0 0 12px rgba(var(--accent-rgb), .25); }
.toggle-field input:checked + .toggle::after { transform: translateX(15px); }
.compact-select { grid-template-columns: 1fr 108px; align-items: center; }
.compact-select select { height: 36px; }
.trace-slider { margin-top: 14px; }
.privacy-note { margin-top: 23px; display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.018); color: var(--accent); }
.privacy-note > span { display: flex; flex-direction: column; gap: 3px; }
.privacy-note strong { color: #dfe5ef; font-size: 10px; font-weight: 520; }
.privacy-note small { color: var(--muted); font-size: 9px; line-height: 1.35; }

.wide-panel { display: none; }
.preset-list { display: grid; gap: 6px; }
.preset-card { min-height: 51px; display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 9px; padding: 5px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.015); text-align: left; cursor: pointer; }
.preset-card:hover { background: rgba(var(--accent-rgb), .06); }
.preset-card.is-active { border-color: rgba(var(--accent-rgb), .78); background: rgba(var(--accent-rgb), .08); box-shadow: 0 0 15px rgba(var(--accent-rgb), .08); }
.preset-thumb { height: 36px; border-radius: 5px; background: radial-gradient(circle at 55% 44%, var(--thumb-b), transparent 38%), linear-gradient(145deg, var(--thumb-a), #06080e 70%); position: relative; overflow: hidden; }
.preset-thumb::after { content: ""; position: absolute; inset: 8px -5px; border: 1px solid var(--thumb-c); border-radius: 50%; transform: rotate(-12deg); filter: blur(.2px); }
.preset-card span:last-child { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.preset-card strong { font-size: 10px; font-weight: 520; color: #e5eaf4; }
.preset-card small { font-size: 8px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.readout-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 10px; color: var(--muted); }
.readout-row strong { color: #cfd6e4; font-weight: 520; }
.advanced-panel .compact-select { margin-top: 18px; }
.feature-readouts { display: grid; gap: 13px; }
.feature-readouts span { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 8px; color: var(--muted); font-size: 9px; }
.feature-readouts i { display: block; height: 3px; border-radius: 3px; background: linear-gradient(to right, var(--accent) 0 var(--feature, 0%), #29303c var(--feature, 0%) 100%); transition: background 80ms; }

.palette-tray {
  min-width: 0;
  display: grid;
  grid-template-columns: 300px auto minmax(0, 1fr);
  align-items: center;
  gap: 26px;
  padding: 12px 28px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16,21,30,.9), rgba(10,13,20,.94));
  backdrop-filter: blur(20px);
}
.live-summary { display: flex; align-items: center; gap: 14px; }
.live-summary > span:last-child { display: flex; flex-direction: column; gap: 4px; }
.live-summary strong { font-size: 11px; font-weight: 520; }
.live-summary small { color: var(--muted); font-size: 9px; }
.live-ring { width: 50px; height: 50px; border: 1px solid var(--accent); border-radius: 50%; box-shadow: 0 0 22px rgba(var(--accent-rgb), .25), inset 0 0 18px rgba(var(--accent-rgb), .08); position: relative; }
.live-ring::after { content: ""; position: absolute; left: 20px; top: 16px; border-left: 12px solid #eaf0ff; border-top: 8px solid transparent; border-bottom: 8px solid transparent; }
.palette-list { display: flex; justify-content: center; gap: 9px; overflow: hidden; }
.palette-chip { width: 70px; min-width: 0; padding: 7px 4px 5px; display: grid; justify-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.012); cursor: pointer; }
.palette-chip:hover { background: rgba(var(--accent-rgb), .06); }
.palette-chip.is-active { border-color: rgba(var(--accent-rgb), .82); background: rgba(var(--accent-rgb), .07); }
.palette-chip > span:first-child { display: flex; height: 20px; }
.palette-chip i { width: 20px; height: 20px; margin-right: -7px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); }
.palette-chip small { color: var(--muted); font-size: 8px; max-width: 62px; overflow: hidden; text-overflow: ellipsis; }

.mobile-performance-button, .performance-exit { display: none; }

@media (min-width: 2140px) {
  .instrument-grid { grid-template-columns: 210px 238px minmax(720px, 1040px) 238px 210px; gap: 9px; }
  .wide-panel { display: block; }
  .preset-panel { grid-column: 2; }
  .stage-column { grid-column: 3; }
  .reactive-panel { grid-column: 4; }
  .advanced-panel { grid-column: 5; }
  .stage-wrap { max-width: 1040px; }
  .panel { padding-left: 15px; padding-right: 15px; }
}

@media (min-width: 761px) and (max-width: 1379px) {
  .app-shell { grid-template-rows: 60px minmax(0, 1fr); }
  .app-header { grid-template-columns: 1fr auto auto; padding: 0 14px; }
  .brand small, .level-meter, .palette-tray { display: none; }
  .mic-state { min-width: 0; }
  .mic-state > span:last-child { display: none; }
  .instrument-grid { grid-template-columns: 218px minmax(420px, 1fr); grid-template-areas: "primary stage" "reactive stage"; align-items: start; overflow: auto; }
  .primary-panel { grid-area: primary; }
  .reactive-panel { grid-area: reactive; }
  .stage-column { grid-area: stage; position: sticky; top: 14px; min-height: calc(100vh - 88px); }
  .stage-wrap { width: min(100%, calc((100vh - 136px) * var(--stage-ratio))); max-height: calc(100vh - 136px); }
  .panel { padding: 15px 14px; }
  .detail-control, .trace-slider:last-of-type, .privacy-note { display: none; }
}

@media (max-width: 760px) {
  body { min-height: 100dvh; }
  .app-shell { min-height: 100dvh; display: block; padding-bottom: env(safe-area-inset-bottom); }
  .app-header {
    min-height: 58px;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 8px 12px;
    position: sticky;
    top: 0;
  }
  .brand > span:last-child small, .brand-mark, .mic-state, .level-meter { display: none; }
  .brand strong { font-size: 16px; }
  .ratio-control { grid-row: 2; grid-column: 1 / -1; justify-self: stretch; }
  .ratio-button { flex: 1; min-width: 0; height: 29px; }
  .mic-cluster { grid-column: 2; }
  .mic-cluster .button { min-height: 30px; padding-inline: 10px; }
  .instrument-grid { display: flex; flex-direction: column; gap: 10px; padding: 10px; }
  .stage-column { order: 1; min-height: 0; }
  .primary-panel { order: 2; }
  .reactive-panel { order: 3; }
  .wide-panel { display: none; }
  .stage-wrap { width: min(100%, calc(52dvh * var(--stage-ratio))); max-width: 100%; max-height: 52dvh; }
  .stage-guidance { width: 100%; justify-content: center; }
  .stage-guidance span:last-child { display: none; }
  .panel { padding: 17px; }
  .style-field { display: none; }
  .mobile-performance-button { display: block; width: 100%; margin-top: 22px; border-color: rgba(var(--accent-rgb), .55); }
  .palette-tray { display: none; }
  .primary-panel .slider-list, .reactive-panel .slider-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .primary-panel .detail-control { grid-column: 1 / -1; }

  .app-shell[data-mobile-mode="performance"] { height: 100dvh; overflow: hidden; padding: 0; background: #020308; }
  .app-shell[data-mobile-mode="performance"] .app-header,
  .app-shell[data-mobile-mode="performance"] .primary-panel,
  .app-shell[data-mobile-mode="performance"] .reactive-panel,
  .app-shell[data-mobile-mode="performance"] .stage-guidance,
  .app-shell[data-mobile-mode="performance"] .compatibility-notice { display: none; }
  .app-shell[data-mobile-mode="performance"] .instrument-grid { height: 100dvh; padding: 0; display: grid; grid-template-columns: 1fr; grid-template-areas: none; place-items: center; }
  .app-shell[data-mobile-mode="performance"] .stage-column { display: grid; grid-column: 1; grid-row: 1; place-items: center; width: 100%; height: 100%; }
  .app-shell[data-mobile-mode="performance"] .stage-wrap { width: min(100vw, calc(100dvh * var(--stage-ratio))); max-width: 100vw; max-height: 100dvh; }
  .app-shell[data-mobile-mode="performance"] .stage { border-radius: 0; border-color: transparent; }
  .app-shell[data-mobile-mode="performance"] .performance-exit { display: flex; }
}

.performance-exit {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  top: max(12px, env(safe-area-inset-top));
  z-index: 40;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 9px 0 5px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 18px;
  background: rgba(5,7,12,.48);
  color: rgba(255,255,255,.72);
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s;
}
.performance-exit.is-visible { opacity: 1; pointer-events: auto; }
.performance-exit span { font-size: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
