:root {
  --ink: #171815;
  --ink-soft: #242621;
  --paper: #f2f1ec;
  --surface: #fffefa;
  --surface-2: #e9e8e1;
  --line: #d6d6ce;
  --line-strong: #b6b7ad;
  --muted: #686c63;
  --quiet: #92958c;
  --signal: #b9f12f;
  --signal-dark: #638800;
  --cyan: #63cbd0;
  --coral: #ee704f;
  --amber: #d99a31;
  --red: #b54439;
  --green: #377b50;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(99, 203, 208, .45); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar {
  min-height: 68px;
  padding: 0 max(1rem, calc((100% - 1220px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid rgba(104, 108, 99, .22);
  background: rgba(242, 241, 236, .92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: .7rem; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  background: var(--signal);
  font-family: var(--mono);
  font-size: .7rem;
  font-weight: 800;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: .92rem; }
.brand small { margin-top: .08rem; color: var(--muted); font-family: var(--mono); font-size: .58rem; }
.privacy-state { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-family: var(--mono); font-size: .65rem; }
.privacy-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

main { width: min(1220px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 5rem; }
.workbench { padding-bottom: 3rem; }
.workbench-head, .results-head, .section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
}
.workbench-head { margin: 1.4rem 0 1.5rem; }
.kicker {
  margin: 0 0 .45rem;
  color: var(--signal-dark);
  font-family: var(--mono);
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
h1, h2, h3, p { letter-spacing: 0; }
h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 3rem); line-height: 1.02; font-weight: 750; }
.workbench-head > p { max-width: 360px; margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.55; text-align: right; }

.source-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.source-panel { min-width: 0; padding: 1rem; border: 1px solid var(--line); background: var(--surface); }
.source-panel.ready { border-color: var(--green); }
.source-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: .8rem; }
.source-head > div { display: flex; align-items: center; gap: .65rem; }
.source-head span, .direction-title > span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: var(--ink);
  background: var(--signal);
  font-family: var(--mono);
  font-size: .6rem;
  font-weight: 800;
}
.source-head h2, .direction-title h2 { margin: 0; font-size: .96rem; }
.source-head > strong { color: var(--quiet); font-family: var(--mono); font-size: .58rem; text-transform: uppercase; }
.ready .source-head > strong { color: var(--green); }
.drop-zone {
  height: 150px;
  position: relative;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  background: var(--paper);
  transition: border-color .15s, background .15s;
}
.drop-zone.dragging { border-color: var(--cyan); background: #e5f4f3; }
.drop-zone canvas { display: block; width: 100%; height: 100%; opacity: 0; }
.drop-zone.has-audio canvas { opacity: 1; }
.drop-copy { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: .3rem; padding: 1rem; text-align: center; }
.drop-copy b { font-size: .84rem; }
.drop-copy small { color: var(--muted); font-size: .68rem; }
.has-audio .drop-copy { display: none; }
.source-actions { display: flex; gap: .5rem; margin-top: .75rem; }
.button {
  min-height: 42px;
  padding: .68rem .9rem;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 750;
  font-size: .75rem;
  transition: transform .12s, filter .15s, background .15s;
}
.button:hover { filter: brightness(1.04); }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .42; cursor: not-allowed; }
.button-dark { color: white; background: var(--ink); }
.button-quiet { color: var(--ink); border-color: var(--line-strong); background: transparent; }
.button-accent { min-width: 230px; display: flex; align-items: center; justify-content: space-between; color: var(--ink); background: var(--signal); }
.button-accent b { font-size: 1rem; }
.file-meta { min-height: 1.2rem; margin: .65rem 0 0; color: var(--quiet); font-family: var(--mono); font-size: .58rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta.error { color: var(--red); white-space: normal; line-height: 1.45; }
.record-strip { margin-top: .75rem; display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: .55rem; min-height: 42px; padding: .55rem .7rem; color: white; background: var(--ink); font-size: .65rem; }
.record-strip span:nth-of-type(2) { color: #b8bbb2; }
.record-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--coral); animation: recordPulse 1s infinite; }
.record-strip button { border: 0; color: var(--ink); background: var(--signal); padding: .35rem .55rem; font-weight: 800; font-size: .62rem; }
@keyframes recordPulse { 50% { opacity: .35; } }

.direction-panel {
  margin-top: 1rem;
  padding: 1rem;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  align-items: center;
  gap: 1.5rem;
  border: 1px solid var(--line);
  background: var(--surface);
}
.direction-title { display: flex; align-items: center; gap: .65rem; }
.direction-title p { margin: .16rem 0 0; color: var(--muted); font-size: .66rem; }
.control-group label { display: block; margin-bottom: .35rem; color: var(--quiet); font-family: var(--mono); font-size: .55rem; text-transform: uppercase; }
.segments { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(78px, 1fr); border: 1px solid var(--line-strong); }
.segments button { min-height: 36px; padding: .45rem .65rem; border: 0; border-right: 1px solid var(--line); color: var(--muted); background: transparent; font-size: .68rem; font-weight: 700; }
.segments button:last-child { border-right: 0; }
.segments button.active { color: white; background: var(--ink); }

.analysis-bar { margin-top: 1rem; min-height: 78px; padding: .8rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: white; background: var(--ink); }
.analysis-bar span, .analysis-bar small { display: block; }
.analysis-bar span { font-size: .8rem; font-weight: 750; }
.analysis-bar small { margin-top: .25rem; color: #aeb1a8; font-size: .65rem; }

.results { border-top: 1px solid var(--line-strong); padding-top: 3rem; }
.results-head h2 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.7rem); }
.result-actions { display: flex; gap: .5rem; }
.session-metrics { margin-top: 1.4rem; display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--line); background: var(--surface); }
.metric { min-height: 112px; padding: .9rem; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span, .metric strong, .metric small { display: block; }
.metric span { color: var(--quiet); font-family: var(--mono); font-size: .52rem; text-transform: uppercase; }
.metric strong { margin-top: .75rem; font-size: 1.25rem; }
.metric small { margin-top: .22rem; color: var(--muted); font-size: .6rem; }
.tempo-control { min-height: 32px; margin-top: .55rem; display: grid; grid-template-columns: 28px minmax(76px, 1fr) 28px; align-items: stretch; border: 1px solid var(--line-strong); }
.tempo-control button { border: 0; color: var(--muted); background: var(--paper); font-family: var(--mono); font-size: .58rem; font-weight: 800; }
.tempo-control button:first-child { border-right: 1px solid var(--line); }
.tempo-control button:last-child { border-left: 1px solid var(--line); }
.tempo-control button:hover { color: white; background: var(--ink); }
.tempo-control label { min-width: 0; display: flex; align-items: center; justify-content: center; gap: .25rem; background: var(--surface); }
.tempo-control input { width: 3.4rem; padding: 0; border: 0; color: var(--ink); background: transparent; font-size: 1rem; font-weight: 800; text-align: right; }
.tempo-control input:focus { outline: 0; }
.tempo-control b { font-size: .54rem; }

.diagnostics, .chain-section, .beat-section { margin-top: 3rem; }
.section-heading { padding-bottom: .9rem; border-bottom: 1px solid var(--line); }
.section-heading span { color: var(--quiet); font-family: var(--mono); font-size: .56rem; text-transform: uppercase; }
.section-heading h3 { margin: .2rem 0 0; font-size: 1.25rem; }
.section-heading > p { max-width: 430px; margin: 0; color: var(--muted); font-size: .68rem; line-height: 1.55; text-align: right; }
.diagnostic-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-top: .8rem; }
.diagnostic-item { min-height: 112px; padding: .85rem; border-left: 3px solid var(--line-strong); background: var(--surface); }
.diagnostic-item.good { border-color: var(--green); }
.diagnostic-item.warn { border-color: var(--amber); }
.diagnostic-item.bad { border-color: var(--red); }
.diagnostic-item span { color: var(--quiet); font-family: var(--mono); font-size: .52rem; text-transform: uppercase; }
.diagnostic-item strong { display: block; margin-top: .45rem; font-size: .8rem; }
.diagnostic-item p { margin: .35rem 0 0; color: var(--muted); font-size: .64rem; line-height: 1.45; }

.chain-list { border-bottom: 1px solid var(--line); }
.chain-item { display: grid; grid-template-columns: 56px minmax(190px, .75fr) minmax(320px, 1.4fr) minmax(180px, .75fr); gap: 1rem; align-items: center; min-height: 128px; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.chain-item:last-child { border-bottom: 0; }
.chain-number { display: grid; place-items: center; width: 42px; height: 42px; color: var(--ink); background: var(--signal); font-family: var(--mono); font-weight: 900; }
.plugin-name span { color: var(--quiet); font-family: var(--mono); font-size: .52rem; text-transform: uppercase; }
.plugin-name .evidence-tag { width: fit-content; margin-top: .35rem; display: block; padding: .2rem .3rem; border-left: 3px solid var(--line-strong); color: var(--muted); background: var(--surface-2); font-family: var(--mono); font-size: .48rem; font-weight: 700; }
.plugin-name .evidence-tag.measured { border-color: var(--green); }
.plugin-name .evidence-tag.perceptual { border-color: var(--cyan); }
.plugin-name .evidence-tag.artistic { border-color: var(--amber); }
.plugin-name h4 { margin: .25rem 0 0; font-size: .95rem; }
.plugin-name p { margin: .3rem 0 0; color: var(--muted); font-size: .62rem; line-height: 1.45; }
.parameter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }
.parameter { min-height: 58px; padding: .48rem .55rem; border: 1px solid var(--line); background: var(--surface); }
.parameter span, .parameter b { display: block; }
.parameter span { color: var(--quiet); font-family: var(--mono); font-size: .48rem; text-transform: uppercase; }
.parameter b { margin-top: .35rem; font-size: .7rem; overflow-wrap: anywhere; }
.plugin-reason { padding-left: .85rem; border-left: 1px solid var(--line); }
.plugin-reason span { color: var(--signal-dark); font-family: var(--mono); font-size: .5rem; text-transform: uppercase; }
.plugin-reason p { margin: .35rem 0 0; color: var(--muted); font-size: .64rem; line-height: 1.5; }

.beat-fix { margin-top: .9rem; display: grid; grid-template-columns: .8fr 1.2fr .8fr; gap: 0; border: 1px solid var(--line); background: var(--surface); }
.beat-fix > div { min-height: 120px; padding: .9rem; border-right: 1px solid var(--line); }
.beat-fix > div:last-child { border-right: 0; }
.beat-fix span { color: var(--quiet); font-family: var(--mono); font-size: .52rem; text-transform: uppercase; }
.beat-fix strong { display: block; margin-top: .55rem; font-size: .92rem; }
.beat-fix p { margin: .35rem 0 0; color: var(--muted); font-size: .64rem; line-height: 1.5; }
.evidence-section { margin-top: 3rem; }
.evidence-legend { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .85rem; }
.evidence-legend span { padding: .34rem .48rem; border-left: 3px solid var(--line-strong); background: var(--surface-2); font-family: var(--mono); font-size: .52rem; }
.evidence-legend .measured { border-color: var(--green); }
.evidence-legend .perceptual { border-color: var(--cyan); }
.evidence-legend .artistic { border-color: var(--amber); }
.reference-list { margin: 1rem 0 0; padding: 0; border-top: 1px solid var(--line); list-style: none; }
.reference-list li { min-height: 58px; display: grid; grid-template-columns: minmax(190px, .55fr) 1.45fr; gap: 1rem; align-items: center; border-bottom: 1px solid var(--line); }
.reference-list a { color: var(--ink); font-size: .68rem; font-weight: 800; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.reference-list span { color: var(--muted); font-size: .63rem; line-height: 1.45; }
.method-note { margin-top: 3rem; padding-top: 1rem; display: grid; grid-template-columns: 160px 1fr; gap: 1rem; border-top: 1px solid var(--line-strong); }
.method-note strong { font-family: var(--mono); font-size: .6rem; text-transform: uppercase; }
.method-note p { margin: 0; color: var(--muted); font-size: .65rem; line-height: 1.55; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 1rem; transform: translate(-50%, 20px); max-width: calc(100% - 2rem); padding: .7rem .9rem; color: white; background: var(--ink); opacity: 0; pointer-events: none; transition: .2s; font-size: .7rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .direction-panel { grid-template-columns: 1fr 1fr; }
  .direction-title { grid-column: 1 / -1; }
  .session-metrics { grid-template-columns: repeat(3, 1fr); }
  .metric { border-bottom: 1px solid var(--line); }
  .chain-item { grid-template-columns: 48px 1fr; }
  .parameter-grid, .plugin-reason { grid-column: 2; }
  .plugin-reason { padding: .7rem 0 0; border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 680px) {
  main { width: min(100% - 1rem, 1220px); padding-top: .8rem; }
  .topbar { min-height: 60px; }
  .privacy-state { font-size: .56rem; }
  .workbench-head, .results-head, .section-heading { display: block; }
  .workbench-head > p, .section-heading > p { margin-top: .7rem; text-align: left; }
  .source-grid { grid-template-columns: 1fr; }
  .drop-zone { height: 132px; }
  .direction-panel { grid-template-columns: 1fr; gap: 1rem; }
  .direction-title { grid-column: auto; }
  .segments { grid-auto-columns: 1fr; }
  .analysis-bar { display: block; }
  .analysis-bar .button { width: 100%; margin-top: .8rem; }
  .result-actions { margin-top: 1rem; }
  .result-actions .button { flex: 1; }
  .session-metrics { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(even) { border-right: 0; }
  .diagnostic-list { grid-template-columns: 1fr; }
  .chain-item { grid-template-columns: 40px minmax(0, 1fr); gap: .7rem; }
  .chain-number { width: 34px; height: 34px; }
  .parameter-grid { grid-template-columns: 1fr 1fr; }
  .beat-fix { grid-template-columns: 1fr; }
  .beat-fix > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .beat-fix > div:last-child { border-bottom: 0; }
  .reference-list li { grid-template-columns: 1fr; gap: .35rem; padding: .7rem 0; }
  .method-note { grid-template-columns: 1fr; }
}
