:root {
  --bg: oklch(15% 0.012 170);
  --bg-2: oklch(18% 0.014 168);
  --panel: oklch(21% 0.014 170 / 0.88);
  --panel-strong: oklch(25% 0.016 170 / 0.94);
  --line: oklch(37% 0.025 165 / 0.7);
  --text: oklch(91% 0.018 90);
  --muted: oklch(68% 0.018 120);
  --dim: oklch(51% 0.016 135);
  --signal: oklch(74% 0.16 65);
  --signal-soft: oklch(74% 0.16 65 / 0.18);
  --rebuild: oklch(76% 0.13 205);
  --rebuild-soft: oklch(76% 0.13 205 / 0.16);
  --danger: oklch(62% 0.18 28);
  --shadow: 0 24px 90px oklch(4% 0.012 170 / 0.54);
  --radius: 8px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 12% 14%, oklch(42% 0.08 180 / 0.22), transparent 33rem),
    radial-gradient(circle at 86% 10%, oklch(58% 0.12 64 / 0.14), transparent 30rem),
    linear-gradient(145deg, var(--bg), oklch(10% 0.012 160));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

body {
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

#fieldCanvas,
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#fieldCanvas {
  z-index: 0;
  opacity: 0.82;
}

.grain {
  z-index: 1;
  opacity: 0.12;
  background-image:
    linear-gradient(90deg, oklch(100% 0 0 / 0.07) 1px, transparent 1px),
    linear-gradient(0deg, oklch(100% 0 0 / 0.05) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at center, black, transparent 78%);
}

.app-shell {
  position: relative;
  z-index: 2;
  width: min(1520px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  margin-bottom: 16px;
}

.eyebrow,
.mini-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
  font-weight: 760;
}

.topbar-status,
.stage-pulse {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 12px;
  background: oklch(18% 0.012 168 / 0.7);
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 350px) minmax(420px, 1fr) minmax(260px, 320px);
  gap: 14px;
  align-items: stretch;
}

.source-panel,
.spectral-stage,
.output-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  contain: paint;
}

.source-panel,
.output-panel {
  padding: 14px;
}

.spectral-stage {
  display: flex;
  min-width: 0;
  min-height: 720px;
  flex-direction: column;
  overflow: hidden;
}

.mode-tabs,
.compare-tabs,
.quality-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: oklch(13% 0.011 170 / 0.72);
}

.mode-tab,
.compare-tab,
.quality-tab,
.ghost-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    transform 180ms var(--ease),
    background 180ms var(--ease),
    color 180ms var(--ease);
}

.mode-tab:hover,
.compare-tab:hover,
.quality-tab:hover,
.ghost-button:hover:not(:disabled) {
  color: var(--text);
  background: oklch(32% 0.025 170 / 0.54);
}

.mode-tab.is-active,
.compare-tab.is-active,
.quality-tab.is-active {
  color: oklch(18% 0.014 170);
  background: var(--signal);
}

.quality-panel {
  margin-top: 10px;
}

.quality-tabs {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.quality-tab {
  display: grid;
  min-height: 54px;
  align-content: center;
  gap: 2px;
  padding: 0 6px;
}

.quality-tab strong,
.quality-tab span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quality-tab strong {
  font-size: 0.88rem;
}

.quality-tab span {
  font-size: 0.72rem;
}

.mode-section {
  display: none;
  margin-top: 14px;
}

.mode-section.is-active {
  display: block;
}

.dropzone {
  position: relative;
  display: grid;
  min-height: 218px;
  place-items: center;
  align-content: center;
  gap: 7px;
  overflow: hidden;
  border: 1px dashed oklch(61% 0.08 178 / 0.7);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, oklch(17% 0.014 170 / 0.8), oklch(23% 0.02 155 / 0.75)),
    repeating-linear-gradient(90deg, transparent 0 16px, oklch(100% 0 0 / 0.025) 16px 17px);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition:
    transform 180ms var(--ease),
    border-color 180ms var(--ease),
    background 180ms var(--ease);
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dropzone strong {
  color: var(--text);
  font-size: 1.22rem;
}

.drop-kicker {
  color: var(--signal);
  font-size: 0.76rem;
  font-weight: 760;
}

.drop-glow {
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--signal-soft), transparent 68%);
  transform: translate3d(-70px, -42px, 0);
}

.dropzone.is-hover {
  transform: translateY(-2px);
  border-color: var(--signal);
  background:
    linear-gradient(145deg, oklch(20% 0.018 170 / 0.9), oklch(26% 0.025 155 / 0.84)),
    repeating-linear-gradient(90deg, transparent 0 16px, oklch(100% 0 0 / 0.032) 16px 17px);
}

.stack {
  display: grid;
  gap: 10px;
}

label {
  color: var(--muted);
  font-size: 0.85rem;
}

input[type="url"],
input[type="search"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  outline: none;
  background: oklch(12% 0.012 170 / 0.86);
  color: var(--text);
  transition:
    border-color 180ms var(--ease),
    box-shadow 180ms var(--ease);
}

input:focus {
  border-color: var(--rebuild);
  box-shadow: 0 0 0 3px var(--rebuild-soft);
}

.primary-action,
.download-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: var(--signal);
  color: oklch(16% 0.015 170);
  font-weight: 780;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 180ms var(--ease),
    filter 180ms var(--ease),
    opacity 180ms var(--ease);
}

.primary-action:hover,
.download-link:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.search-results {
  display: grid;
  gap: 8px;
  max-height: 360px;
  margin-top: 12px;
  overflow: auto;
}

.search-result {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: oklch(15% 0.012 170 / 0.7);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.search-result:hover {
  border-color: oklch(55% 0.07 190);
}

.search-result span {
  color: var(--muted);
  font-size: 0.82rem;
}

.timeline {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: oklch(13% 0.011 170 / 0.66);
}

.timeline-head,
.stage-toolbar,
.wave-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.timeline-head {
  color: var(--muted);
  font-size: 0.86rem;
}

.timeline-head strong {
  color: var(--text);
}

.progress-rail {
  height: 8px;
  margin: 12px 0;
  overflow: hidden;
  border-radius: 999px;
  background: oklch(9% 0.01 170 / 0.9);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--signal), var(--rebuild));
  transition: width 320ms var(--ease);
}

#stageMessage {
  min-height: 42px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.stage-toolbar {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: oklch(17% 0.012 170 / 0.72);
}

.stage-toolbar strong {
  display: block;
  max-width: 52ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spectrogram-frame {
  position: relative;
  min-height: 470px;
  flex: 1;
  overflow: hidden;
  background:
    linear-gradient(180deg, oklch(10% 0.011 170 / 0.24), oklch(8% 0.012 170 / 0.62)),
    repeating-linear-gradient(0deg, transparent 0 39px, oklch(100% 0 0 / 0.045) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 63px, oklch(100% 0 0 / 0.035) 63px 64px);
}

#spectrogramCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.crosshair {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent var(--x), oklch(92% 0.02 90 / 0.46) var(--x), transparent calc(var(--x) + 1px)),
    linear-gradient(0deg, transparent var(--y), oklch(92% 0.02 90 / 0.32) var(--y), transparent calc(var(--y) + 1px));
}

.spectrogram-frame:hover .crosshair {
  display: block;
}

.readout {
  position: absolute;
  right: 12px;
  bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  background: oklch(10% 0.012 170 / 0.78);
  color: var(--muted);
  font-size: 0.78rem;
}

.wave-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: oklch(14% 0.012 170 / 0.7);
}

.wave-strip {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: oklch(10% 0.011 170 / 0.62);
}

.wave-meta {
  min-height: 38px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.ghost-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  font-size: 0.78rem;
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.wave-strip canvas {
  display: block;
  width: 100%;
  height: 110px;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metrics div,
.compare-box,
.notes {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: oklch(13% 0.011 170 / 0.68);
}

.metrics div {
  min-height: 78px;
  padding: 12px;
}

.metrics span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

.metrics strong {
  font-size: 1.12rem;
}

.compare-box,
.notes {
  margin-top: 10px;
  padding: 12px;
}

.compare-tabs {
  grid-template-columns: 1fr 1fr;
  margin: 8px 0 10px;
}

audio {
  width: 100%;
  min-height: 38px;
  accent-color: var(--rebuild);
}

.download-link {
  width: 100%;
  margin-top: 10px;
  background: var(--rebuild);
}

.download-link.is-disabled {
  pointer-events: none;
  opacity: 0.45;
}

.notes span {
  color: var(--signal);
  font-size: 0.76rem;
  font-weight: 760;
  text-transform: uppercase;
}

.notes p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.is-error {
  color: var(--danger) !important;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 320px 1fr;
  }

  .output-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding: 14px 0;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .workspace,
  .wave-grid {
    grid-template-columns: 1fr;
  }

  .spectral-stage {
    min-height: 620px;
  }

  .spectrogram-frame {
    min-height: 360px;
  }

  .source-panel,
  .spectral-stage,
  .output-panel {
    backdrop-filter: none;
  }
}

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

  #fieldCanvas {
    opacity: 0.38;
  }
}
