:root {
  color-scheme: dark;
  --bg: #111111;
  --panel: #1d1d1b;
  --panel-2: #24231f;
  --line: #3b3931;
  --text: #eeeeea;
  --muted: #aaa79d;
  --accent: #78d7a4;
  --accent-2: #e7b85e;
  --danger: #ef7770;
  --model-pitch: #ff4bd8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 0 14px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0;
}

h2 {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
}

#status,
.meta,
.metrics {
  color: var(--muted);
  font-size: 12px;
}

.stage,
.controls {
  margin-top: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.stage {
  padding: 12px;
}

.mediaHeader {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.mediaRow {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: stretch;
  gap: 10px;
}

.playButton,
.toolButton,
.primaryButton {
  border: 1px solid var(--line);
  background: #20201d;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.playButton {
  width: 44px;
  min-height: 132px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 19px;
}

.playButton:disabled,
.toolButton:disabled,
.primaryButton:disabled {
  cursor: wait;
  opacity: 0.58;
}

.toolButton,
.primaryButton {
  padding: 8px 12px;
  min-height: 36px;
}

.toolButton:hover,
.playButton:hover:not(:disabled) {
  border-color: #615e51;
  background: #292822;
}

.primaryButton {
  background: #1e3a2a;
  border-color: #376f4d;
  color: #eafff1;
  font-weight: 650;
}

.primaryButton:hover:not(:disabled) {
  background: #254a35;
}

.spectrogram {
  position: relative;
  min-height: 132px;
  overflow: hidden;
  border: 1px solid #2f2d28;
  border-radius: 6px;
  background: #0a0a0a;
}

.spectrogram img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 132px;
  object-fit: cover;
}

.spectrogram.empty img {
  opacity: 0;
}

.spectrogram.empty::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent),
    repeating-linear-gradient(90deg, #131313 0 32px, #171611 32px 64px);
}

.pitchOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.pitchOverlay path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.pitchSource {
  stroke: #69d6ff;
  stroke-width: 2.25;
  filter: drop-shadow(0 0 3px rgba(105,214,255,0.45));
}

.pitchUsed {
  stroke: #78d7a4;
  stroke-width: 3;
  filter: drop-shadow(0 0 3px rgba(120,215,164,0.45));
}

.pitchModel {
  stroke: var(--model-pitch);
  stroke-width: 4;
  filter:
    drop-shadow(0 0 2px rgba(0,0,0,0.95))
    drop-shadow(0 0 7px rgba(255,75,216,0.85));
}

.soft {
  opacity: 0.62;
}

.latentDiag {
  display: block;
  width: 100%;
  height: 240px;
  margin-top: 10px;
  background: #0f0f0d;
  border-top: 1px solid #2f2d28;
}

.latentDiag path,
.latentDiag line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.chartGrid {
  stroke: rgba(255,255,255,0.16);
  stroke-width: 1;
}

.chartGrid.faint {
  stroke: rgba(255,255,255,0.08);
}

.chartThreshold {
  stroke: rgba(231,184,94,0.52);
  stroke-width: 1.2;
  stroke-dasharray: 4 4;
}

.chartLabel {
  fill: rgba(238,238,234,0.72);
  font-size: 11px;
  font-weight: 650;
}

.energyModel {
  stroke: #e7b85e;
  stroke-width: 2.4;
}

.contentModel {
  stroke: #caa2ff;
  stroke-width: 2.4;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 10px rgba(231,184,94,0.72);
  pointer-events: none;
  z-index: 3;
}

.controls {
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 14px;
}

.promptBlock,
.sliderGrid label {
  display: grid;
  gap: 7px;
}

.promptBlock > span,
.controlLabel {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.controlLabel > span:first-child {
  min-width: 0;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hintWrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--muted);
  outline: none;
  cursor: help;
}

.hintIcon {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border: 1px solid #5b584e;
  border-radius: 50%;
  background: #151512;
  color: #d4d0c4;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.hintBubble {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(330px, calc(100vw - 40px));
  padding: 10px 11px;
  border: 1px solid #5d594d;
  border-radius: 6px;
  background: #12120f;
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
  font-size: 12px;
  line-height: 1.38;
  white-space: normal;
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-3px);
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
  pointer-events: none;
}

.hintWrap:hover .hintBubble,
.hintWrap:focus .hintBubble,
.hintWrap:focus-within .hintBubble {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.promptBlock input[type="text"] {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: #151512;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

.promptBlock input[type="text"]:focus {
  border-color: #5b876d;
}

.sliderGrid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.toggleGrid {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toggleGrid label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #171713;
  color: var(--text);
}

.toggleText {
  white-space: nowrap;
}

.toggleGrid input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.actionRow {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
}

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.metrics b {
  color: var(--text);
  font-weight: 600;
}

.metrics .legendSource {
  color: #69d6ff;
}

.metrics .legendUsed {
  color: #78d7a4;
}

.metrics .legendModel {
  color: var(--model-pitch);
}

.resultStage {
  background: var(--panel-2);
}

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

@media (max-width: 920px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .sliderGrid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100vw - 18px, 1280px);
    padding-top: 10px;
  }

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

  .mediaRow {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 8px;
  }

  .playButton {
    width: 40px;
  }

  .sliderGrid {
    grid-template-columns: 1fr;
  }
}
