:root {
  --bg-top: #08121d;
  --bg-bottom: #04070f;
  --panel: rgba(8, 18, 31, 0.82);
  --panel-strong: rgba(12, 26, 44, 0.96);
  --line: rgba(142, 178, 219, 0.16);
  --line-strong: rgba(219, 232, 255, 0.18);
  --text: #eff6ff;
  --muted: #9ab1c9;
  --accent: #f3b55c;
  --accent-strong: #ffd18c;
  --shadow: 0 30px 70px rgba(0, 0, 0, 0.38);
  --radius: 28px;
  --app-brand-top-space: max(18px, env(safe-area-inset-top));
  --app-brand-left-space: max(18px, env(safe-area-inset-left));
  --app-brand-height: 46px;
  --app-brand-streak-gap: 10px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Futura", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(120, 212, 255, 0.12), transparent 34%),
    radial-gradient(circle at 85% 16%, rgba(243, 181, 92, 0.2), transparent 28%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at center, black 24%, transparent 90%);
  pointer-events: none;
}

.app-shell {
  width: 100%;
  margin: 0;
  min-height: 100dvh;
  padding: 0;
}

.card {
  position: relative;
  background: linear-gradient(180deg, rgba(15, 30, 49, 0.98), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), transparent 45%);
  pointer-events: none;
}

.visualizer {
  animation: panel-rise 700ms ease both;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.floating-row {
  justify-content: end;
}

button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  transition:
    transform 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 2px solid rgba(120, 212, 255, 0.65);
  outline-offset: 3px;
}

#toggle-audio {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
}

.button-label {
  display: inline-block;
}

.button-icon {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
}

.button-icon-mic {
  width: 13px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 7px;
}

.button-icon-mic::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 6px;
  background: currentColor;
  transform: translateX(-50%);
}

.button-icon-mic::after {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% + 6px);
  width: 12px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
  transform: translateX(-50%);
}

.primary-button,
.secondary-button {
  padding: 13px 18px;
  font-weight: 650;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #f58e56);
  color: #1b1308;
  box-shadow: 0 12px 24px rgba(243, 181, 92, 0.24);
}

.secondary-button {
  background: rgba(10, 20, 36, 0.72);
  color: var(--text);
  border: 1px solid var(--line);
}

#toggle-test-mode.is-active {
  background: linear-gradient(135deg, rgba(243, 181, 92, 0.2), rgba(120, 212, 255, 0.14));
  color: var(--accent-strong);
  border-color: rgba(243, 181, 92, 0.48);
  box-shadow: 0 10px 28px rgba(243, 181, 92, 0.14);
}

.visualizer.is-test-mode .spectrogram-frame {
  box-shadow:
    inset 0 0 0 1px rgba(243, 181, 92, 0.22),
    0 0 0 1px rgba(120, 212, 255, 0.08);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.88fr);
  gap: 22px;
  margin-top: 0;
}

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

.visualizer {
  padding: 22px;
}

.visualizer.visualizer-immersive {
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  background: transparent;
}

.visualizer.visualizer-immersive::after {
  display: none;
}

.visualizer-immersive {
  height: 100dvh;
  min-height: 100svh;
}

.visualizer-body {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  height: 100%;
}

.analysis-screen {
  position: fixed;
  inset: 0;
  z-index: 12;
  padding: 18px;
  background:
    radial-gradient(circle at top left, rgba(120, 212, 255, 0.12), transparent 34%),
    radial-gradient(circle at 85% 16%, rgba(243, 181, 92, 0.2), transparent 28%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.analysis-screen-shell {
  width: min(1320px, 100%);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 18px;
}

.analysis-screen-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.analysis-screen-copy {
  min-width: 0;
}

.analysis-screen-kicker {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.analysis-screen-title {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.1;
}

.analysis-screen-status {
  margin: 0;
  max-width: 72ch;
  color: var(--muted);
  font-size: 0.97rem;
  line-height: 1.6;
}

.analysis-screen-status.is-loading {
  color: var(--accent-strong);
}

.analysis-screen-status.is-error {
  color: #ffb1a0;
}

.analysis-screen-content {
  min-height: 0;
  overflow: auto;
  padding: 0 6px 18px 0;
}

.analysis-screen-content::-webkit-scrollbar {
  width: 10px;
}

.analysis-screen-content::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

body.analysis-screen-open {
  overflow: hidden;
}

.analysis-empty,
.analysis-error {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.analysis-report {
  display: grid;
  gap: 18px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.analysis-section {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
}

.analysis-section h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.analysis-section p,
.analysis-section li {
  margin: 0;
  color: var(--text);
  font-size: 0.93rem;
  line-height: 1.6;
}

.analysis-section p.analysis-section-body,
.analysis-section p.analysis-section-note,
.analysis-section li.analysis-muted {
  color: var(--muted);
}

.analysis-list,
.analysis-metric-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.analysis-list strong,
.analysis-metric-list strong {
  color: var(--text);
}

.analysis-inline-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.analysis-confidence {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(243, 181, 92, 0.14);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.analysis-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.analysis-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.2;
}

.perf-hud {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;
  min-width: min(360px, calc(100vw - 32px));
  max-width: min(440px, calc(100vw - 32px));
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(6, 12, 18, 0.88);
  color: rgba(245, 250, 255, 0.94);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.34);
  font-family: "SFMono-Regular", "SF Mono", Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.45;
  white-space: pre-wrap;
  pointer-events: none;
}

.visualizer-immersive .visualizer-shell,
.visualizer-body .visualizer-shell {
  height: 100%;
  min-height: 0;
}

.panel-button {
  padding: 10px 16px;
}

.fiume-brand-link {
  position: absolute;
  top: var(--app-brand-top-space);
  left: var(--app-brand-left-space);
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: var(--app-brand-height);
  padding: 4px 14px 4px 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(9, 18, 30, 0.84);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
  color: var(--text);
  text-decoration: none;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease;
}

.fiume-brand-link:hover,
.fiume-brand-link:focus-visible {
  border-color: rgba(243, 181, 92, 0.48);
  background: rgba(18, 30, 48, 0.94);
  color: var(--accent-strong);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.28);
  outline: none;
  transform: translateY(-1px);
}

.fiume-brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--accent-strong);
  background: linear-gradient(180deg, rgba(243, 181, 92, 0.18), rgba(120, 212, 255, 0.08));
  border: 1px solid rgba(255, 222, 173, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.fiume-brand-mark svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.floating-controls {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 4;
  display: grid;
  gap: 10px;
  justify-items: end;
}

.visualizer.is-audio-setup .floating-controls {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.visualizer.is-audio-setup .floating-row {
  justify-content: center;
}

.visualizer.is-audio-setup .floating-row > button {
  flex: 0 0 auto;
}

.visualizer.is-audio-setup #toggle-audio {
  min-height: 54px;
  padding: 0 26px;
  box-shadow: 0 18px 36px rgba(243, 181, 92, 0.22);
}

.record-chip {
  position: absolute;
  left: 24px;
  right: auto;
  bottom: 98px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border-radius: 999px;
  background: rgba(14, 20, 31, 0.84);
  border: 1px solid rgba(255, 98, 98, 0.24);
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.record-chip-label {
  color: #ff7c7c;
}

.mode-fab-link {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 72px);
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(9, 18, 30, 0.84);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
  color: var(--text);
  text-decoration: none;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease;
}

.mode-fab-link:hover,
.mode-fab-link:focus-visible {
  border-color: rgba(243, 181, 92, 0.48);
  background: rgba(18, 30, 48, 0.94);
  color: var(--accent-strong);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.28);
}

.visualizer.is-recording .mode-fab-link {
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 120px);
}

.visualizer.has-take .mode-fab-link {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
}

.record-fab {
  position: absolute;
  left: 22px;
  right: auto;
  bottom: 22px;
  z-index: 4;
  width: 62px;
  height: 62px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, #ff8d8d, #ff4d4d 58%, #c82e2e 100%);
  box-shadow:
    0 24px 38px rgba(14, 0, 0, 0.42),
    0 0 0 1px rgba(255, 215, 215, 0.12) inset;
}

.record-fab:hover {
  transform: translateY(-1px) scale(1.02);
}

.record-fab-shape {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 248, 248, 0.96);
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.28);
  transition:
    width 160ms ease,
    height 160ms ease,
    border-radius 160ms ease;
}

.record-fab-label {
  display: none;
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
}

.visualizer.is-recording .record-fab-shape {
  width: 18px;
  height: 18px;
  border-radius: 4px;
}

.visualizer.has-take .record-fab {
  left: 22px;
  right: auto;
  bottom: 22px;
  width: auto;
  height: 48px;
  min-width: 124px;
  padding: 0 18px 0 16px;
  justify-content: flex-start;
  background: rgba(9, 18, 30, 0.84);
  border: 1px solid rgba(255, 120, 120, 0.22);
  box-shadow:
    0 16px 28px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.visualizer.has-take .record-fab-shape {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #ff6565;
  box-shadow: 0 0 18px rgba(255, 101, 101, 0.35);
}

.visualizer.has-take .record-fab-label {
  display: inline-block;
}

.visualizer-shell {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
  min-height: 0;
  touch-action: none;
}

.axis-canvas,
.spectrogram-frame {
  height: min(72vh, 780px);
  min-height: 440px;
}

.visualizer-immersive .axis-canvas,
.visualizer-immersive .spectrogram-frame {
  height: 100%;
  min-height: 0;
}

.axis-canvas {
  width: 46px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(23, 23, 23, 0.98), rgba(16, 16, 16, 0.96));
  touch-action: none;
}

.spectrogram-frame {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(20, 20, 20, 0.98), rgba(14, 14, 14, 1));
  touch-action: none;
  overscroll-behavior: none;
}

.spectrogram-canvas,
.tuning-overlay,
.waveform-canvas,
.overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.tuning-overlay {
  --tuning-overlay-opacity: 0;
  --tuning-overlay-core: rgba(100, 228, 156, 0.16);
  --tuning-overlay-mid: rgba(100, 228, 156, 0.09);
  --tuning-overlay-top: rgba(100, 228, 156, 0.07);
  --tuning-overlay-bottom: rgba(100, 228, 156, 0.11);
  --tuning-overlay-left: rgba(255, 255, 255, 0.022);
  --tuning-overlay-right: rgba(255, 255, 255, 0.016);
  --tuning-overlay-saturation: 1.06;
  z-index: 1;
  border-radius: inherit;
  pointer-events: none;
  opacity: var(--tuning-overlay-opacity);
  background:
    radial-gradient(140% 110% at 50% 48%, var(--tuning-overlay-core) 0%, var(--tuning-overlay-mid) 42%, transparent 78%),
    linear-gradient(180deg, var(--tuning-overlay-top) 0%, transparent 34%, transparent 68%, var(--tuning-overlay-bottom) 100%),
    linear-gradient(135deg, var(--tuning-overlay-left) 0%, transparent 36%, transparent 64%, var(--tuning-overlay-right) 100%);
  mix-blend-mode: screen;
  filter: saturate(var(--tuning-overlay-saturation));
  will-change: opacity;
  transition:
    opacity 140ms ease,
    filter 160ms ease;
}

.waveform-canvas {
  z-index: 3;
  cursor: ew-resize;
  pointer-events: none;
  touch-action: none;
}

.visualizer.has-take .waveform-canvas {
  pointer-events: auto;
}

.overlay-canvas {
  z-index: 4;
  pointer-events: none;
}

.waveform-playback {
  position: absolute;
  right: 22px;
  bottom: 22px;
  z-index: 3;
  width: 40px;
  height: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(10, 18, 29, 0.78);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.playback-fab {
  width: 52px;
  height: 52px;
  min-height: 52px;
  box-shadow:
    0 20px 34px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.waveform-playback-icon {
  position: relative;
  display: block;
  width: 15px;
  height: 16px;
  margin-left: 2px;
}

.waveform-playback-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  background: rgba(255, 249, 240, 0.96);
}

.waveform-playback.is-playing .waveform-playback-icon {
  width: 14px;
  height: 16px;
  margin-left: 0;
}

.waveform-playback.is-playing .waveform-playback-icon::before {
  clip-path: none;
  background:
    linear-gradient(
      90deg,
      rgba(255, 249, 240, 0.96) 0 4px,
      transparent 4px 9px,
      rgba(255, 249, 240, 0.96) 9px 13px
    );
}

code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  color: var(--text);
}

@keyframes panel-rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 760px) {
  :root {
    --app-brand-top-space: max(12px, env(safe-area-inset-top));
    --app-brand-left-space: max(12px, env(safe-area-inset-left));
    --app-brand-height: 40px;
  }

  .app-shell {
    width: 100%;
    min-height: 100dvh;
    padding: 0;
  }

  .workspace {
    gap: 0;
  }

  .visualizer.visualizer-immersive {
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    background: transparent;
  }

  .visualizer.visualizer-immersive::after {
    display: none;
  }

  .fiume-brand-link {
    gap: 10px;
    padding: 4px 12px 4px 4px;
    font-size: 0.7rem;
  }

  .fiume-brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .floating-controls {
    top: calc(var(--app-brand-top-space) + var(--app-brand-height) + 14px);
    right: 12px;
    left: 12px;
    justify-items: stretch;
  }

  .floating-row {
    justify-content: stretch;
  }

  .floating-row > button {
    flex: 1 1 auto;
  }

  .visualizer-shell {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 4px;
  }

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

  .analysis-screen {
    padding: 12px;
  }

  .analysis-screen-header {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .analysis-screen-header > button {
    width: fit-content;
  }

  .perf-hud {
    top: 12px;
    right: 12px;
    left: 12px;
    min-width: 0;
    max-width: none;
    font-size: 0.7rem;
  }

  .axis-canvas {
    width: 34px;
  }

  .axis-canvas,
  .spectrogram-frame {
    height: min(66vh, 620px);
    min-height: 360px;
  }

  .visualizer-immersive {
    height: 100dvh;
    min-height: 100svh;
  }

  .visualizer-body {
    gap: 0;
  }

  .record-fab {
    left: 16px;
    right: auto;
    bottom: 16px;
    width: 58px;
    height: 58px;
  }

  .mode-fab-link {
    left: max(16px, env(safe-area-inset-left));
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 68px);
    min-height: 32px;
    padding: 0 11px;
    font-size: 0.72rem;
  }

  .visualizer.is-recording .mode-fab-link {
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 112px);
  }

  .visualizer.has-take .record-fab {
    left: 16px;
    right: auto;
    bottom: 16px;
    height: 46px;
    min-width: 114px;
    padding: 0 16px 0 14px;
  }

  .record-chip {
    left: 16px;
    right: auto;
    bottom: 86px;
  }

  .waveform-playback {
    right: 16px;
    bottom: 16px;
  }

  .playback-fab {
    width: 48px;
    height: 48px;
    min-height: 48px;
  }
}
