:root {
  color-scheme: light dark;
  --bg: #fbf6ec;
  --bg-shade: #f3eadc;
  --panel: #fffaf3;
  --line: #8d735c;
  --text: #2a2118;
  --muted: #5c4638;
  --teal: #0f4a4e;
  --mint: #d7f2df;
  --gold: #a07a3a;
  --gold-soft: #c4a15a;
  --coral: #8a3010;
  --walnut: #3a2418;
  --ivory: #fffaf3;
  --on-accent: #fffaf3;
  --cyan: var(--teal);
  --violet: var(--walnut);
  --green: #14633c;
  --yellow: #6a4a12;
  --red: var(--coral);
  --focus: var(--teal);
  --mark-clash: rgba(138, 48, 16, 0.22);
  --mark-color: rgba(160, 122, 58, 0.28);
  --staff: rgba(160, 122, 58, 0.35);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-family: var(--sans);
  accent-color: var(--teal);
}

* { box-sizing: border-box; }

body {
  min-height: 100dvh;
  margin: 0;
  background: linear-gradient(var(--bg), var(--bg-shade));
  color: var(--text);
}

button, input, summary { font: inherit; }

button {
  min-block-size: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  color: var(--text);
  background: var(--ivory);
  box-shadow: 0 1px 0 rgba(160, 122, 58, 0.35);
  cursor: pointer;
}

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

:where(a, button, input, summary):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 5;
  padding: 0.5rem 0.75rem;
  background: var(--teal);
  color: var(--on-accent);
}

.skip-link:not(:focus) {
  position: absolute;
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.ambient-pulse {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
}

body[data-status="green"] .ambient-pulse { background: rgba(20, 99, 60, 0.08); }
body[data-status="yellow"] .ambient-pulse { background: rgba(160, 122, 58, 0.1); }
body[data-status="red"] .ambient-pulse { background: rgba(138, 48, 16, 0.1); }

.ambient-pulse.flash { opacity: 1; }

.top-nav, .app-shell {
  width: min(1120px, calc(100% - 1.25rem));
  margin-inline: auto;
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding-block: 0.65rem 0.55rem;
  border-bottom: 1px solid var(--gold);
}

.brand {
  display: flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}

.brand img {
  display: block;
  height: 3.25rem;
  width: auto;
  padding: 0.15rem;
  border: 1px solid var(--gold);
  border-radius: 0.85rem;
  background: #fbf6ec;
  box-shadow: 0 8px 22px rgba(42, 33, 24, 0.16);
}

.theme-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
  margin: 0;
  min-inline-size: 0;
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0.15rem;
}

.theme-switch label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-block-size: 2.25rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
}

.theme-switch label:has(:checked) {
  background: var(--teal);
  color: var(--on-accent, var(--ivory));
}

.theme-switch input {
  margin: 0;
}

.theme-switch input:focus-visible {
  outline: none;
}

.theme-switch label:has(:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.auth-status {
  margin: 0;
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell {
  container-name: app;
  container-type: inline-size;
  padding-block: 0.4rem 2rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--cyan);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.02em;
}

h1 {
  max-width: 100%;
  font-size: clamp(1.7rem, 1rem + 3.2vw, 3.15rem);
  line-height: 1.05;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

h2 { font-size: clamp(1rem, 0.9rem + 0.6vw, 1.35rem); }

.hero-copy, .active-detection, .project-state small, .metric-card small, .empty, .fix-flow, #statusDetail {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.hero-copy { max-width: 42rem; margin: 0.55rem 0 0; }

.active-detection {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.7rem;
  margin: 0.7rem 0;
}

.active-detection strong { color: var(--text); overflow-wrap: anywhere; }

.hero-actions, .transport, .export-controls, .action-grid, .dialog-actions, .chip-lane {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
  max-width: 100%;
}

.primary-button {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--on-accent);
}

.control-panel, .metric-card, .timeline-panel, .coach-panel, .theory-grid article, .saved-panel, dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  box-shadow: 0 10px 28px rgba(58, 36, 24, 0.06);
}

.control-panel, .dashboard, .studio-grid, .theory-grid, .saved-panel { margin-top: 0.8rem; }

.control-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.7rem;
  padding: 0.75rem;
  min-width: 0;
}

.file-drop {
  display: grid;
  gap: 0.35rem;
  padding: 0.7rem;
  border: 1px dashed var(--gold);
  border-radius: 12px;
  background:
    linear-gradient(90deg, transparent 0 0.7rem, rgba(160, 122, 58, 0.18) 0.7rem 0.78rem, transparent 0.78rem) 0 0.45rem / 100% 0.35rem no-repeat;
}

.file-drop.dragging { border-color: var(--cyan); }

.file-drop label { font-weight: 800; }

.control-help {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.compare-label {
  align-self: center;
  color: var(--muted);
  font-size: 0.85rem;
}

#compareFile,
.file-drop input {
  max-width: 100%;
  min-width: 0;
}

.file-drop input {
  width: 100%;
}

#fileError:empty { display: none; }

#fileError, #authError { color: var(--red); margin: 0; }

fieldset {
  margin: 0;
  min-width: 0;
  min-inline-size: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem;
}

legend { padding-inline: 0.3rem; color: var(--muted); font-size: 0.85rem; }

.fx-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.fx-control { display: grid; gap: 0.25rem; }

.fx-control label { color: var(--muted); font-size: 0.8rem; }

.file-drop,
.fx-controls,
.fx-control {
  min-width: 0;
  max-width: 100%;
}

.fx-control input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.project-state { display: grid; gap: 0.25rem; min-width: 0; }

.project-state span, #savedScope, .marker-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#progressWrap { display: flex; align-items: center; gap: 0.5rem; }

#progressWrap[hidden] { display: none; }

progress { width: min(100%, 12rem); height: 0.7rem; }

.dashboard, .studio-grid, .theory-grid, .confidence-matrix {
  display: grid;
  gap: 0.7rem;
}

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

.metric-card, .timeline-panel, .coach-panel, .theory-grid article { padding: 0.75rem; min-width: 0; }

.metric-card h2 { margin-bottom: 0.35rem; color: var(--muted); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; }

.metric-card strong { display: block; font-size: clamp(1.3rem, 1rem + 1vw, 2rem); overflow-wrap: anywhere; }

.studio-grid { grid-template-columns: minmax(0, 1.6fr) minmax(16rem, 0.8fr); }

.theory-grid { grid-template-columns: 1.3fr 0.7fr; }

.panel-heading, .confidence-matrix { display: flex; justify-content: space-between; gap: 0.7rem; align-items: end; }

.confidence-matrix { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0.7rem; }

.matrix-card { padding: 0.45rem 0.55rem; border-radius: 10px; background: var(--bg-shade); min-width: 0; }

.matrix-card span { display: block; color: var(--muted); font-size: 0.75rem; }

.matrix-card.green strong { color: var(--green); }
.matrix-card.yellow strong { color: var(--yellow); }
.matrix-card.red strong { color: var(--red); }

#waveformCanvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 16 / 5;
  border-radius: 12px;
  border: 1px solid var(--gold);
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0 22%,
      var(--staff) 22% calc(22% + 1px),
      transparent calc(22% + 1px) 44%
    ),
    var(--ivory);
  cursor: pointer;
}

.chip-lane { margin-top: 0.55rem; }

.chip-lane button { min-width: 0; }

.marker-list, .suggestion-stack, .chip-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.marker-list { margin-top: 0.7rem; }

.marker-card, .progression-card, .chip, .muted-chip {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-shade);
}

.marker-card { width: min(100%, 16rem); padding: 0.45rem 0.6rem; text-align: start; border-radius: 10px; }

.marker-card small {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marker-card.red { border-color: var(--red); }
.marker-card.yellow { border-color: var(--yellow); }
.marker-card.style { border-color: var(--violet); }
.marker-card.selected { box-shadow: inset 0 0 0 1px var(--cyan); }

.chip, .muted-chip { padding: 0.2rem 0.5rem; }

.coach-panel { display: grid; grid-template-rows: auto minmax(12rem, 1fr) auto auto; min-height: 28rem; }

.coach-log { overflow: auto; display: flex; flex-direction: column; gap: 0.45rem; min-height: 0; }

.message { padding: 0.55rem 0.7rem; border-radius: 10px; background: var(--bg-shade); overflow-wrap: anywhere; }

.message.user { align-self: end; max-width: 90%; background: var(--mint); color: var(--text); }

.coach-mood { color: var(--cyan); font-size: 0.8rem; }

.coach-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.45rem; }

.coach-form input, .auth-form input, dialog input {
  width: 100%;
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  color: var(--text);
  background: var(--ivory);
}

.fix-flow { margin: 0; padding-left: 1.1rem; }

.progression-card { width: 100%; padding: 0.55rem 0.65rem; }

.saved-panel { padding: 0.7rem 0.85rem; }

.saved-panel summary { cursor: pointer; font-weight: 800; }

#savedList { margin: 0.6rem 0; padding-left: 1.1rem; }

#savedList li { margin: 0.25rem 0; overflow-wrap: anywhere; }

dialog {
  width: min(26rem, calc(100% - 1.5rem));
  max-width: calc(100vw - 1.5rem);
  color: var(--text);
  padding: 1rem;
  box-sizing: border-box;
}

dialog::backdrop { background: rgba(42, 33, 24, 0.46); }

.auth-form, #authFields { display: grid; gap: 0.45rem; }

#passwordHint, #authNotice { margin: 0; color: var(--muted); }

#authFields[hidden] { display: none; }

body[data-status="green"] .status-card strong { color: var(--green); }
body[data-status="yellow"] .status-card strong { color: var(--yellow); }
body[data-status="red"] .status-card strong { color: var(--red); }

@container app (max-width: 860px) {
  .dashboard, .studio-grid, .theory-grid { grid-template-columns: 1fr 1fr; }
  .studio-grid, .theory-grid { grid-template-columns: 1fr; }
  .fx-controls { grid-template-columns: 1fr 1fr; }
  .coach-panel { min-height: 0; }
}

@container app (max-width: 560px) {
  .dashboard { grid-template-columns: 1fr; }
  .fx-controls, .confidence-matrix { grid-template-columns: 1fr; }
  h1 { font-size: clamp(1.55rem, 0.7rem + 6vw, 2.2rem); }
}

@media (pointer: coarse), (max-width: 640px) {
  button, input[type="range"] { min-block-size: 2.75rem; }
  #audioFile,
  #compareFile,
  #savedPanel > summary,
  .theme-switch label {
    min-block-size: 44px;
  }
  input[type="file"]::file-selector-button {
    min-block-size: 44px;
    padding-inline: 0.8rem;
  }
  #savedPanel > summary {
    display: flex;
    align-items: center;
  }
}

@media (min-width: 900px) {
  .brand img { height: 5.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .ambient-pulse { display: none; }
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@supports not (accent-color: #0f4a4e) {
  progress { background: var(--bg-shade); }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #102628;
    --bg-shade: #173437;
    --panel: #1c3c40;
    --line: #c4a15a;
    --text: #fbf6ec;
    --muted: #e4d3bc;
    --teal: #9ed9c4;
    --mint: #1e4f4c;
    --gold: #d4b36a;
    --gold-soft: #e0c27a;
    --coral: #ffc2a8;
    --walnut: #fbf6ec;
    --ivory: #1c3c40;
    --on-accent: #102628;
    --green: #9ed9b0;
    --yellow: #e0c27a;
    --focus: #f0d48a;
    --mark-clash: rgba(255, 194, 168, 0.32);
    --mark-color: rgba(224, 194, 122, 0.3);
    --staff: rgba(212, 179, 106, 0.45);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #fbf6ec;
  --bg-shade: #f3eadc;
  --panel: #fffaf3;
  --line: #8d735c;
  --text: #2a2118;
  --muted: #5c4638;
  --teal: #0f4a4e;
  --mint: #d7f2df;
  --gold: #a07a3a;
  --gold-soft: #c4a15a;
  --coral: #8a3010;
  --walnut: #3a2418;
  --ivory: #fffaf3;
  --on-accent: #fffaf3;
  --green: #14633c;
  --yellow: #6a4a12;
  --red: #8a3010;
  --focus: #0f4a4e;
  --mark-clash: rgba(138, 48, 16, 0.22);
  --mark-color: rgba(160, 122, 58, 0.28);
  --staff: rgba(160, 122, 58, 0.35);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #102628;
  --bg-shade: #173437;
  --panel: #1c3c40;
  --line: #c4a15a;
  --text: #fbf6ec;
  --muted: #e4d3bc;
  --teal: #9ed9c4;
  --mint: #1e4f4c;
  --gold: #d4b36a;
  --gold-soft: #e0c27a;
  --coral: #ffc2a8;
  --walnut: #fbf6ec;
  --ivory: #1c3c40;
  --on-accent: #102628;
  --green: #9ed9b0;
  --yellow: #e0c27a;
  --red: #ffc2a8;
  --focus: #f0d48a;
  --mark-clash: rgba(255, 194, 168, 0.32);
  --mark-color: rgba(224, 194, 122, 0.3);
  --staff: rgba(212, 179, 106, 0.45);
}
