/* Cadence — a lead sheet you can play.
   Layout: masthead · settings console · the chart (bars with real barlines and repeat signs) · transport · selected chord + analysis. */
:root {
  --bg: #edf0ee;
  --surface: #fafbfa;
  --raised: #ffffff;
  --ink: #16201c;
  --muted: #5a6661;
  --line: #d3d9d6;
  --line-strong: #98a49f;
  --accent: #17695a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe6;
  --sel: #e4ece8;
  --fn-t: #2c64a6;
  --fn-pd: #a8691a;
  --fn-d: #b93a32;
  --shadow: 0 1px 2px rgb(22 32 28 / 6%), 0 6px 20px rgb(22 32 28 / 6%);

  --f-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2.125rem;
  --step-4: 3.25rem;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #161d1a; --raised: #1b2420; --ink: #e3eae6; --muted: #92a09a; --line: #29332f; --line-strong: #4a5852;
    --accent: #52c2a1; --accent-ink: #06130f; --accent-soft: #1c3029; --sel: #1f2a26;
    --fn-t: #7ea9e2; --fn-pd: #e2ae57; --fn-d: #f07d73;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #161d1a; --raised: #1b2420; --ink: #e3eae6; --muted: #92a09a; --line: #29332f; --line-strong: #4a5852;
  --accent: #52c2a1; --accent-ink: #06130f; --accent-soft: #1c3029; --sel: #1f2a26;
  --fn-t: #7ea9e2; --fn-pd: #e2ae57; --fn-d: #f07d73;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--step-0)/1.5 var(--f-body);
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding-block: 28px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 20px;
}

/* ---------- masthead ---------- */
.masthead { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; }
.brand { min-width: 0; }
.wordmark {
  margin: 0;
  font: 800 var(--step-4)/1 var(--f-display);
  letter-spacing: -0.035em;
  /* five staff lines behind the name */
  background: repeating-linear-gradient(to bottom, transparent 0 9px, var(--line-strong) 9px 10px) 0 4px / 100% 50px no-repeat;
  display: inline-block;
  padding: 2px 14px 6px 0;
}
.home-link { display: block; width: fit-content; margin: 0 0 10px; font-size: var(--step--1); color: var(--muted); text-decoration: none; }
.home-link:hover, .home-link:focus-visible { color: var(--accent); text-decoration: underline; }
.tagline { margin: 8px 0 0; color: var(--muted); max-width: 60ch; text-wrap: balance; }
.toggles { display: flex; gap: 10px; flex-wrap: wrap; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--surface); }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 999px;
  font-size: var(--step--1); font-weight: 500; color: var(--muted); white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg-wide { display: flex; }
.seg-wide button { flex: 1; }

/* ---------- console ---------- */
.console {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: end;
}
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px 16px; align-items: end; min-width: 0; }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span, .mini-label {
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
select {
  appearance: none; -webkit-appearance: none;
  width: 100%;
  border: 1px solid var(--line); border-radius: 8px; background: var(--raised);
  padding: 7px 30px 7px 10px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.field-range { grid-column: span 2; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 6px 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: var(--step--1); color: var(--muted); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.btn-generate {
  border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font: 700 var(--step-1)/1 var(--f-display); letter-spacing: -0.01em;
  padding: 16px 22px; display: inline-flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
  transition: transform .12s ease, filter .12s ease;
}
.btn-generate:hover { filter: brightness(1.06); }
.btn-generate:active { transform: translateY(1px); }
kbd {
  font: 500 0.6875rem/1 var(--f-mono); padding: 3px 5px; border-radius: 4px;
  border: 1px solid color-mix(in srgb, currentColor 40%, transparent); opacity: .8;
}

/* ---------- the chart ---------- */
.sheet {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 22px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 20px; align-items: start; margin-bottom: 18px; }
.sheet-head > div:first-child { min-width: 0; flex: 1 1 320px; }
.sheet-title { margin: 0; font: 700 var(--step-2)/1.15 var(--f-display); letter-spacing: -0.015em; }
.source { margin: 4px 0 0; color: var(--muted); font-size: var(--step--1); max-width: 70ch; }
.view-switch { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.field-inline { display: flex; align-items: center; gap: 8px; }
.field-inline select { width: auto; max-width: 100%; }
#tuning-wrap { min-width: 0; max-width: 100%; }

.measures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: 18px; }
.bar {
  position: relative;
  display: flex;
  gap: 4px;
  border-left: 1.5px solid var(--ink);
  padding: 18px 8px 4px;
  min-width: 0;
}
.measures .bar:nth-child(4n) { border-right: 1.5px solid var(--ink); }
.bar.last { border-right: 1.5px solid var(--ink); }
.bar-no { position: absolute; top: 0; left: 6px; font: 500 0.6875rem/1 var(--f-mono); color: var(--muted); }
/* repeat signs for loops, final double bar for resolved endings */
.is-loop .bar.first { border-left: 4px solid var(--ink); }
.is-loop .bar.first::before, .is-loop .bar.last::after {
  content: ""; position: absolute; top: calc(50% + 4px); width: 4px; height: 18px; transform: translateY(-50%);
  background: radial-gradient(circle, var(--ink) 1.9px, transparent 2.3px) 0 0 / 4px 9px repeat-y;
}
.is-loop .bar.first::before { left: 3px; }
.is-loop .bar.last { border-right: 4px solid var(--ink); }
.is-loop .bar.last::after { right: 3px; }
.is-final .bar.last { border-right: 6px double var(--ink); }

.chord {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  gap: 6px;
  border-radius: var(--r);
  padding: 4px 4px 6px;
  transition: background .15s ease, box-shadow .15s ease;
  --fn: var(--fn-t);
}
.fn-T { --fn: var(--fn-t); }
.fn-PD { --fn: var(--fn-pd); }
.fn-D { --fn: var(--fn-d); }
.chord.is-selected { background: var(--sel); }
.chord.weak .chord-main { border-bottom-style: dashed; }
.focus-head.weak { border-bottom-style: dashed; }
.flow-step.weak { border-style: dashed; }
.chord.is-playing { box-shadow: inset 0 0 0 2px var(--accent); }
.chord.is-locked { background: repeating-linear-gradient(-45deg, transparent 0 7px, color-mix(in srgb, var(--accent) 10%, transparent) 7px 8px); }
.chord.is-locked.is-selected { background-color: var(--sel); }
.chord-main {
  border: 0; background: transparent; width: 100%; padding: 4px 2px 8px;
  display: grid; justify-items: center; gap: 2px; border-bottom: 3px solid var(--fn); border-radius: 6px 6px 0 0;
}
.sym { font: 700 var(--step-3)/1 var(--f-display); letter-spacing: -0.02em; white-space: nowrap; }
.sym sup, .focus-sym sup { font-size: 0.5em; font-weight: 600; vertical-align: 0.85em; margin-left: 1px; letter-spacing: 0; }
.sym-bass { font-weight: 500; font-size: 0.62em; color: var(--muted); margin-left: 1px; }
.rn { font: 500 var(--step--1)/1.2 var(--f-mono); color: var(--muted); }
.rn.big { font-size: var(--step-1); color: var(--ink); }
.fn-tag {
  font-size: 0.625rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fn);
}
.chord.half .sym { font-size: var(--step-2); }

.gwrap { display: grid; justify-items: center; gap: 2px; width: 100%; }
.gbox { width: 100%; max-width: 116px; height: auto; display: block; }
.half .gbox { max-width: 96px; }
.g-fret { stroke: var(--line-strong); stroke-width: 1; }
.g-string { stroke: var(--muted); }
.g-nut { fill: var(--ink); }
.g-base { fill: var(--muted); font: 500 9px var(--f-mono); }
.g-mute { fill: var(--muted); font: 600 10px var(--f-body); }
.g-open { fill: none; stroke: var(--ink); stroke-width: 1.2; }
.g-open.root { stroke: var(--accent); stroke-width: 2; }
.g-dot { fill: var(--ink); }
.g-dot.root { fill: var(--accent); }
.g-barre { fill: var(--ink); opacity: .22; }
.g-lab { fill: var(--bg); font: 600 6.4px var(--f-mono); }
.g-name { fill: var(--muted); font: 500 7px var(--f-mono); }
.g-lab.root { fill: var(--accent-ink); }

.shape-nav { display: flex; align-items: center; gap: 2px; }
.shape-count { font: 500 0.6875rem/1 var(--f-mono); color: var(--muted); min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 28px; height: 28px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted);
}
.icon-btn:hover { border-color: var(--line); color: var(--ink); background: var(--surface); }
.icon-btn.on { color: var(--accent); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.simile {
  flex: 1; align-self: stretch; display: grid; place-items: center; align-content: center; gap: 6px;
  border: 0; background: transparent; color: var(--ink); border-radius: var(--r); min-height: 120px;
}
.simile svg { width: 44px; height: 44px; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; fill: currentColor; }
.simile-name { font: 500 0.6875rem/1 var(--f-mono); color: var(--muted); }
.simile:hover { background: var(--surface); }
.simile.is-playing { box-shadow: inset 0 0 0 2px var(--accent); }
.chord-tools { display: flex; gap: 2px; justify-content: center; min-height: 28px; }

.mini-kbd { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 6px; width: 100%; max-width: 170px; }
.bass-tag { font: 500 0.6875rem/1 var(--f-mono); color: var(--accent); writing-mode: vertical-rl; transform: rotate(180deg); }
.kbd { width: 100%; height: auto; display: block; }
.k-w { fill: var(--raised); stroke: var(--line-strong); stroke-width: .6; }
.k-b { fill: var(--ink); }
.k-w.on.tone, .k-b.on.tone { fill: var(--fn-t); }
.k-w.on.root, .k-b.on.root { fill: var(--accent); }
.k-lab { font: 600 5px var(--f-mono); fill: var(--accent-ink); }
.k-lab.tone { fill: #fff; }
.k-oct { font: 500 4.4px var(--f-mono); fill: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: var(--step--1); color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i { width: 14px; height: 3px; border-radius: 2px; background: var(--fn); display: inline-block; }
.lg.weak i { height: 0; background: none; border-top: 3px dashed var(--fn); border-radius: 0; }
.lg-intro { font-weight: 600; }
.lg-root i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* ---------- transport ---------- */
.transport {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px;
}
.btn-play {
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 10px 20px 10px 14px;
  background: var(--ink); color: var(--bg); font-weight: 600; min-width: 112px;
}
.btn-play svg { width: 18px; height: 18px; fill: currentColor; }
.btn-play .ico-stop, .btn-play[aria-pressed="true"] .ico-play { display: none; }
.btn-play[aria-pressed="true"] .ico-stop { display: block; }
.btn-play[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tempo input { width: 120px; }
.tempo output { font: 500 var(--step--1) var(--f-mono); min-width: 3ch; font-variant-numeric: tabular-nums; }
.transport .field > span { font-size: 0.6875rem; }
.transport-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.btn-ghost { border: 1px solid var(--line); background: var(--raised); border-radius: 8px; padding: 7px 12px; font-size: var(--step--1); font-weight: 500; }
.btn-ghost:hover { border-color: var(--line-strong); }
#play-scale[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.hint { flex-basis: 100%; margin: 0; font-size: 0.75rem; color: var(--muted); }

/* ---------- lower: selected chord + analysis ---------- */
.lower { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.focus, .why, .history { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; min-width: 0; }
.side { display: grid; gap: 20px; min-width: 0; }
.eyebrow { margin: 0 0 8px; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.h2 { margin: 0 0 12px; font: 700 var(--step-1)/1.2 var(--f-display); }
.h3 { margin: 0 0 10px; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.focus-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; padding-bottom: 16px; border-bottom: 3px solid var(--fn); margin-bottom: 18px; }
.focus-sym { font: 800 var(--step-4)/1 var(--f-display); letter-spacing: -0.03em; }
.focus-meta { display: grid; gap: 4px; }
.tones { list-style: none; margin: 0 0 0 auto; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tones li { display: grid; justify-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px 4px; background: var(--raised); min-width: 44px; }
.tone-name { font: 600 var(--step-0)/1.2 var(--f-body); }
.tone-int { font: 500 0.6875rem/1.3 var(--f-mono); color: var(--muted); }
.tone-int.root { color: var(--accent); }

.focus-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 22px; }
.focus-grid.solo { grid-template-columns: minmax(0, 1fr); }
.big-g .gbox { max-width: 190px; margin: 0 auto 10px; }
.alts { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.alt { border: 1px solid var(--line); background: var(--raised); border-radius: 8px; padding: 4px 2px 3px; display: grid; justify-items: center; gap: 1px; }
.alt .gbox { max-width: 54px; }
.alt span { font: 500 0.625rem/1.2 var(--f-mono); color: var(--muted); white-space: nowrap; }
.alt.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.big-kbd { overflow-x: auto; }
.big-kbd .kbd { min-width: 460px; }
.voicing-notes { margin: 10px 0 0; font: 500 var(--step--1)/1.5 var(--f-mono); color: var(--muted); }

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 14px; }
.flow-step { font: 600 0.6875rem/1 var(--f-mono); color: var(--fn); border: 1.5px solid var(--fn); border-radius: 6px; padding: 4px 6px; }
.flow-arrow { color: var(--line-strong); font-size: 0.75rem; }
.analysis { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.analysis li { padding-left: 14px; position: relative; font-size: var(--step--1); line-height: 1.55; }
.analysis li::before { content: ""; position: absolute; left: 0; top: 0.6em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.cref { font-family: var(--f-display); font-weight: 700; }
.fn-help { margin: 14px 0 0; font-size: 0.75rem; line-height: 1.5; color: var(--muted); }

.history ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.history button { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--raised); border-radius: 8px; padding: 8px 10px; display: grid; gap: 2px; }
.history button:hover { border-color: var(--line-strong); }
.h-chords { font: 600 var(--step--1)/1.35 var(--f-display); overflow-wrap: anywhere; }
.h-meta { font-size: 0.6875rem; color: var(--muted); }
.history .empty { font-size: var(--step--1); color: var(--muted); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: var(--step--1); box-shadow: var(--shadow); z-index: 20;
}
.copy-fallback { position: fixed; opacity: 0; pointer-events: none; }


/* ---------- scales ---------- */
.scales { background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; box-shadow: var(--shadow); display: grid; gap: 12px; min-width: 0; }
.scales-head { display: flex; flex-wrap: wrap; gap: 10px 20px; justify-content: space-between; align-items: start; }
.scales-title-wrap { min-width: 0; flex: 1 1 280px; }
.scales .h2 { margin-bottom: 2px; }
.scale-for { margin: 0; font-size: var(--step--1); color: var(--muted); }
.scales-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: var(--step--1); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { border-color: var(--line-strong); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.num { min-width: 34px; justify-content: center; font-family: var(--f-mono); }
.chip-tag { font-size: 0.625rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }
.chip.on .chip-tag { color: inherit; opacity: .8; }
.scale-why { margin: 0; font-size: var(--step--1); line-height: 1.55; max-width: 90ch; }
.chord-scales { display: flex; flex-wrap: wrap; gap: 6px; }
.cs-item { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px; display: grid; gap: 1px; text-align: left; }
.cs-item b { font-family: var(--f-display); }
.cs-item span { font-size: 0.75rem; color: var(--muted); }
.cs-item.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pos-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.neck-wrap { overflow-x: auto; padding-bottom: 4px; }
.neck { display: block; width: 100%; min-width: 680px; height: auto; }
.n-fret { stroke: var(--line-strong); stroke-width: 1.2; }
.n-nut { fill: var(--ink); }
.n-string { stroke: var(--muted); }
.n-inlay { fill: var(--line); }
.n-name { fill: var(--muted); font: 600 10px var(--f-mono); }
.n-fnum { fill: var(--muted); font: 500 9px var(--f-mono); }
.n-window { fill: color-mix(in srgb, var(--accent) 10%, transparent); stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3; }
.n-note circle { fill: var(--raised); stroke: var(--line-strong); stroke-width: 1.2; }
.n-note text { font: 600 8px var(--f-mono); fill: var(--ink); }
.n-note.ctone circle { fill: var(--fn-t); stroke: var(--fn-t); }
.n-note.ctone text { fill: #fff; }
.n-note.croot circle { fill: var(--accent); stroke: var(--accent); }
.n-note.croot text { fill: var(--accent-ink); }
.n-note.sroot circle { stroke: var(--ink); stroke-width: 2.4; }
.n-note.avoid circle { stroke: var(--fn-d); stroke-width: 2; stroke-dasharray: 3 2; }
.n-note.avoid text { fill: var(--fn-d); }
.k-w.on.avoid { fill: color-mix(in srgb, var(--fn-d) 22%, var(--raised)); }
.k-lab.avoid { fill: var(--fn-d); }
.sl.avoid i { border: 2px dashed var(--fn-d); }
.n-note.out { opacity: 0.16; }
.n-note.is-sounding circle { stroke: var(--fn-d); stroke-width: 3.2; }
.n-note { transition: opacity .15s ease; }
.k-w.on.croot, .k-b.on.croot { fill: var(--accent); }
.k-w.on.ctone, .k-b.on.ctone { fill: var(--fn-t); }
.k-w.on.scale { fill: var(--sel); }
.k-b.on.scale { fill: var(--muted); }
.k-lab.scale { fill: var(--ink); }
.k-lab.croot { fill: var(--accent-ink); }
.k-lab.ctone { fill: #fff; }
.scale-legend { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.75rem; color: var(--muted); }
.sl { display: inline-flex; align-items: center; gap: 6px; }
.sl i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1.2px solid var(--line-strong); background: var(--raised); }
.sl.croot i { background: var(--accent); border-color: var(--accent); }
.sl.ctone i { background: var(--fn-t); border-color: var(--fn-t); }
.sl.sroot i { border: 2.4px solid var(--ink); }


/* ---------- panel tabs: Scales | Licks ---------- */
.panel-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 4px; }
.panel-tabs button {
  border: 0; background: transparent; padding: 8px 14px 10px; font: 700 var(--step-1)/1 var(--f-display); color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px; border-radius: 6px 6px 0 0;
}
.panel-tabs button:hover { color: var(--ink); }
.panel-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.panel-body { display: grid; gap: 12px; min-width: 0; }

/* ---------- licks ---------- */
.licks-grid { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: 20px; align-items: start; }
.lick-list-wrap { display: grid; gap: 10px; min-width: 0; }
.lick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 560px; overflow-y: auto; padding-right: 4px; }
.lick-item { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; display: grid; gap: 2px; }
.lick-item:hover { border-color: var(--line-strong); }
.lick-item.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--raised); }
.li-name { font: 600 var(--step-0)/1.3 var(--f-display); display: flex; align-items: center; gap: 6px; }
.li-check { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 11px; flex: none; }
.li-meta { font-size: 0.75rem; color: var(--muted); }
.lick-list .empty { font-size: var(--step--1); color: var(--muted); padding: 6px 2px; }
.lick-detail { display: grid; gap: 12px; min-width: 0; }
.lick-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: 10px; }
.lick-title { min-width: 0; flex: 1 1 260px; }
.lick-name { margin: 0 0 6px; font: 800 var(--step-2)/1.15 var(--f-display); letter-spacing: -0.015em; }
.lick-tags { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.lick-tags span { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.lick-tags span:first-child { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.btn-learned { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: var(--step--1); font-weight: 600; }
.btn-learned[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.lick-tip { margin: 0; font-size: var(--step-0); line-height: 1.55; max-width: 75ch; }
.lick-where { margin: 0; font-size: var(--step--1); color: var(--muted); }
.lick-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.btn-lick { display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 9px 18px 9px 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-lick svg, .btn-ctx svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-lick svg.fill, .btn-ctx svg.fill { fill: currentColor; stroke: none; }
.btn-ctx { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; }
.btn-ctx[aria-pressed="true"], .btn-lick[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.speed { display: inline-flex; align-items: center; gap: 8px; }
.lick-status { font: 700 var(--step--1)/1 var(--f-display); padding: 7px 12px; border-radius: 999px; background: var(--sel); color: var(--ink); }
.lick-status.turn { background: var(--accent); color: var(--accent-ink); }
.lick-empty { border: 1px dashed var(--line-strong); border-radius: 12px; padding: 22px; display: grid; gap: 12px; justify-items: start; color: var(--muted); }
.lick-empty p { margin: 0; max-width: 60ch; }
.tab-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px 2px; }
.tab { display: block; width: 100%; height: auto; margin: 0 auto 0 0; }
.lick-tags span:nth-child(4) { text-transform: capitalize; }
.tb-line { stroke: var(--line-strong); stroke-width: 1; }
.tb-bar { stroke: var(--ink); stroke-width: 1.4; }
.tb-bar.end { stroke-width: 2.4; }
.tb-name { fill: var(--muted); font: 600 9px var(--f-mono); }
.tb-chord { fill: var(--ink); font: 700 12px var(--f-display); }
.tb-count { fill: var(--muted); font: 500 8.5px var(--f-mono); }
.tb-count.and { opacity: .55; }
.tb-note rect { fill: var(--surface); }
.tb-note text { fill: var(--ink); font: 600 11px var(--f-mono); }
.tb-note.is-sounding rect { fill: var(--accent); }
.tb-note.is-sounding text { fill: var(--accent-ink); }
.tb-tech { fill: var(--muted); font: 600 8.5px var(--f-mono); }
.tb-arc, .tb-bend, .tb-slide, .tb-vib { fill: none; stroke: var(--muted); stroke-width: 1.2; }
.tb-head { fill: var(--muted); }
.lick-neck .neck { min-width: 560px; }
.n-note.lick.ctone circle { fill: var(--fn-t); }
@media (max-width: 860px) {
  .licks-grid { grid-template-columns: minmax(0, 1fr); }
  .lick-list { max-height: 240px; }
}


/* licks v2: scale connection */
.lick-group { list-style: none; display: flex; justify-content: space-between; align-items: baseline; margin: 8px 2px 0; font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.lick-group:first-child { margin-top: 0; }
.lick-group span { font-family: var(--f-mono); font-weight: 500; letter-spacing: 0; }
.chip-x { gap: 8px; }
.lick-from { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); }
.lick-from b { font-family: var(--f-display); }
.lick-from-notes { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.lick-from-notes i { font: 600 0.6875rem/1 var(--f-mono); font-style: normal; padding: 4px 6px; border-radius: 6px; background: var(--raised); border: 1px solid var(--line); }
.link-btn { border: 0; background: none; padding: 2px 0; color: var(--accent); font-weight: 600; font-size: var(--step--1); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.lick-from .link-btn { margin-left: auto; }
.chip.partial { border-style: dashed; }
.chip.partial:not(.on) { color: var(--muted); }
.pos-note { font-size: 0.75rem; color: var(--muted); }
.tb-deg { fill: var(--muted); font: 600 9px var(--f-mono); }
.tb-deg.ct { fill: var(--accent); }
.tab-legend { margin: -4px 0 0; font-size: 0.75rem; color: var(--muted); }
.tl-deg { font: 600 0.6875rem var(--f-mono); color: var(--muted); }
.tl-deg.ct { color: var(--accent); }
.n-note.lick circle { stroke-width: 2; }
.n-note.lick.passing circle { stroke-dasharray: 3 2; }


/* lick fit badges */
.fit-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--line-strong); }
.fit-dot.good { background: var(--accent); }
.fit-dot.ok { background: var(--fn-pd); }
.fit-dot.poor { background: transparent; border: 1.5px solid var(--line-strong); }
.lick-fit { margin: 0; display: flex; align-items: baseline; gap: 8px; font-size: var(--step--1); line-height: 1.5; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); }
.lick-fit .fit-dot { transform: translateY(1px); }
.lick-fit.good { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.lick-fit.ok { border-color: color-mix(in srgb, var(--fn-pd) 50%, var(--line)); }
.lick-fit.poor { border-color: color-mix(in srgb, var(--fn-d) 50%, var(--line)); }
.tb-deg.bad { fill: var(--fn-d); }
.tb-deg.warn { fill: var(--fn-pd); }
.tl-deg.bad { color: var(--fn-d); }
.tl-deg.warn { color: var(--fn-pd); }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .lower { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .console { grid-template-columns: minmax(0, 1fr); }
  .btn-generate { justify-content: center; }
  .field-seg, .field-range { grid-column: 1 / -1; }
  .measures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .measures .bar:nth-child(4n) { border-right: 0; }
  .measures .bar:nth-child(2n) { border-right: 1.5px solid var(--ink); }
  .is-loop .bar.last { border-right: 4px solid var(--ink); }
  .is-final .bar.last { border-right: 6px double var(--ink); }
  .sheet { padding: 16px 12px 12px; }
  .focus-grid { grid-template-columns: minmax(0, 1fr); }
  .tones { margin-left: 0; }
  .transport-actions { margin-left: 0; }
}
@media (max-width: 420px) {
  .wordmark { font-size: var(--step-3); background-size: 100% 34px; background-image: repeating-linear-gradient(to bottom, transparent 0 6px, var(--line-strong) 6px 7px); }
  .field-range { grid-column: auto; }
  .sym { font-size: var(--step-2); }
  .chord.half .sym { font-size: var(--step-1); }
  .bar { padding-inline: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
