/* ── Theme ──
   Every colour is a CSS variable, so the whole app re-skins by swapping these.
   Chord-quality colours are shared; each theme only redefines the "chrome".
   Switch via the header picker (sets data-theme on <html>). Default = midnight. */
:root {
  /* shared (all themes) */
  --q-major: #f59e0b;
  --q-dominant: #f97316;
  --q-minor: #6366f1;
  --q-halfdim: #8b5cf6;
  --q-dim: #ef4444;
  --good: #10b981;     /* voice-leading / success green */
  --warn: #f59e0b;     /* extension amber */
  --danger: #ef4444;
  --border-selected: var(--accent);
}

/* Midnight — deep slate + teal (the default, less generic than indigo) */
:root, [data-theme="midnight"] {
  --bg: #0c0f16;
  --surface: #161c28;
  --border: #283242;
  --text: #eef2f8;
  --text-muted: #93a1b5;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
}

/* Indigo — the original look */
[data-theme="indigo"] {
  --bg: #111827;
  --surface: #1f2937;
  --border: #374151;
  --text: #f9fafb;
  --text-muted: #9ca3af;
  --accent: #6366f1;
  --accent-hover: #818cf8;
}

/* Plum — warm violet on a near-black aubergine */
[data-theme="plum"] {
  --bg: #140f1a;
  --surface: #221a2e;
  --border: #3a2f4a;
  --text: #f4f0f8;
  --text-muted: #ab9cbb;
  --accent: #c084fc;
  --accent-hover: #d8b4fe;
}

/* Ember — charcoal + warm amber, studio feel */
[data-theme="ember"] {
  --bg: #14110d;
  --surface: #211c16;
  --border: #3a3128;
  --text: #f6f1ea;
  --text-muted: #b3a895;
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
}

/* Daylight — clean light theme */
[data-theme="daylight"] {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --border: #dde1e9;
  --text: #1a1f29;
  --text-muted: #5c6675;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The `hidden` attribute must always win — a class/id that sets `display`
   (e.g. .score-modal, .controls, .mode-panel) otherwise beats the UA [hidden]
   rule on specificity and the element shows when it shouldn't. This is the
   canonical fix; we only ever toggle visibility via the hidden attribute. */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.75rem;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Placeholder brand logo — text + piano icon until a real logo is drawn */
.brand { display: inline-flex; align-items: center; gap: 0.5rem; }
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.9rem; height: 1.9rem; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 1.05rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.brand-name {
  font-weight: 800; letter-spacing: 0.01em;
  background: linear-gradient(90deg, var(--text), var(--accent));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}

.theme-picker {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  flex-direction: row;
  text-transform: none;
  letter-spacing: 0;
}
.theme-picker select {
  min-width: auto;
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
}

/* ── Mode tabs ── */

.mode-tabs {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.mode-tab {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 5px;
  padding: 0.38rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.mode-tab:hover { color: var(--text); }
.mode-tab.active { background: var(--accent); color: #fff; }

.pool-count {
  display: inline-block;
  min-width: 1.3em;
  padding: 0 0.35em;
  margin-left: 0.25em;
  border-radius: 999px;
  background: #10b981;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  vertical-align: middle;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: #10b981;
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ── Controls ── */

.controls {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  min-width: 120px;
}

select:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.slider-label { flex: 1; min-width: 180px; }

.slider-wrap { display: flex; align-items: center; gap: 0.75rem; }

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}

.slider-wrap span {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  min-width: 1.5ch;
  text-align: right;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

.checkbox-label input { accent-color: var(--accent); cursor: pointer; }

.mode-actions { display: flex; gap: 0.5rem; margin-left: auto; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover { border-color: var(--accent); color: var(--text); }

.btn-reset {
  margin-left: auto;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-reset:hover { border-color: var(--q-dim); color: var(--q-dim); }

/* ── Results toolbar ── */

.rhythm-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.rhythm-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  white-space: nowrap;
}

.rhythm-btns { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* Generate refine axes (#45) — paired options stacked vertically (#50) */
.refine-axis {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.refine-axis .rhythm-btn { width: 100%; justify-content: center; }
.refine-name {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  margin-right: 0.15rem;
}

.rhythm-btn {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.12s;
}

.rhythm-btn:hover { border-color: var(--accent); color: var(--text); }
.rhythm-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-export {
  margin-left: auto;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.45rem 1.1rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-export:hover:not(:disabled) { background: var(--accent); color: #fff; }
.btn-export:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Progressions / Candidates ── */

#progressions,
#candidates {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.progression {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.progression:hover { border-color: var(--text-muted); }
.progression.selected { border-color: var(--border-selected); }

.prog-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.prog-radio { font-size: 0.9rem; color: var(--accent); }
.prog-label { font-size: 0.88rem; font-weight: 500; letter-spacing: 0.03em; }
.prog-key {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: capitalize;
}
.prog-duration {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-share {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--text-muted);
  border-radius: 8px;
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-share:hover { border-color: var(--accent); color: var(--accent); }

.share-error {
  font-size: 0.85rem;
  color: #c0392b;
  padding: 0.5rem 0;
}

/* stretch so every card in a row is the same height regardless of extensions */
.chord-cards { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: stretch; }
.chord-cards .chord-wrap { min-width: 60px; }
.chord-cards .chord-card { width: 100%; flex: 1 1 auto; }

.chord-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  min-width: 68px;
  text-align: center;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: filter 0.1s, outline 0.1s;
  user-select: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
/* never clip the notes line — let it wrap fully */
.chord-notes { overflow-wrap: anywhere; white-space: normal; }

.chord-card:hover  { filter: brightness(1.3); }
.chord-card.playing {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  filter: brightness(1.4);
}

.chord-card.q-major    { border-color: var(--q-major); }
.chord-card.q-dominant { border-color: var(--q-dominant); }
.chord-card.q-minor    { border-color: var(--q-minor); }
.chord-card.q-halfdim  { border-color: var(--q-halfdim); }
.chord-card.q-dim      { border-color: var(--q-dim); }

.chord-symbol { font-size: 0.9rem; font-weight: 700; }
.chord-roman  { font-size: 0.65rem; color: var(--text-muted); margin-top: 0.15rem; }
.chord-notes  { font-size: 0.6rem; color: var(--text-muted); margin-top: 0.3rem; line-height: 1.4; }

/* ── Playback ── */

.btn-play {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.28rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-play:hover   { border-color: var(--accent); color: var(--text); }
.btn-play.playing { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Builder ── */

.mode-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* the `hidden` attribute must win over the display:flex above
   (equal specificity otherwise lets the panel show in every mode) */
.mode-panel[hidden] { display: none; }

.edit-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
}
.edit-hint b { color: var(--text); font-weight: 600; }

.builder-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.builder-history {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  flex-wrap: wrap;
  min-height: 52px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
}

.builder-history-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.history-arrow {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Small chord card variant for the history strip */
.chord-card-sm {
  padding: 0.35rem 0.5rem;
  min-width: 52px;
  font-size: 0.8rem;
}

.chord-card-sm .chord-symbol { font-size: 0.8rem; }
.chord-card-sm .chord-roman  { font-size: 0.6rem; margin-top: 0.1rem; }

.btn-finish {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, opacity 0.15s;
  flex-shrink: 0;
}

.btn-finish:hover:not(:disabled) { background: var(--accent-hover); }
.btn-finish:disabled { opacity: 0.4; cursor: not-allowed; }

.builder-carousel-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.builder-carousel {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  transition: opacity 0.14s ease;
}

.builder-carousel.fading { opacity: 0; }

/* Carousel chord cards are slightly larger */
.carousel-card {
  min-width: 80px;
  padding: 0.7rem 0.85rem;
  transition: filter 0.1s, transform 0.1s, outline 0.1s;
}

.carousel-card:hover {
  filter: brightness(1.3);
  transform: translateY(-2px);
}

/* Most-likely chord gets a subtle top highlight */
.carousel-card.carousel-top {
  outline: 1px solid rgba(99, 102, 241, 0.5);
  outline-offset: 2px;
}

/* Preview button inside carousel cards */
.carousel-preview-btn {
  display: block;
  margin: 0.4rem auto 0;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.6rem;
  cursor: pointer;
  transition: all 0.1s;
  white-space: nowrap;
}

.carousel-preview-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Chord wrap + controls ── */

.chord-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

/* In progressions: controls only visible on hover */
.chord-controls {
  display: flex;
  gap: 0.2rem;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.chord-wrap:hover .chord-controls {
  opacity: 1;
  pointer-events: auto;
}

/* In builder history: controls always visible */
.chord-controls-sm {
  opacity: 1;
  pointer-events: auto;
}

/* Touch devices: always show */
@media (hover: none) {
  .chord-controls {
    opacity: 1;
    pointer-events: auto;
  }
}

.ctrl-btn {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 22px;
  height: 18px;
  font-size: 0.65rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.1s;
}

.ctrl-btn:hover:not(:disabled) { background: var(--bg); color: var(--text); border-color: var(--text-muted); }
.ctrl-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.ctrl-delete:hover:not(:disabled) { border-color: var(--q-dim); color: var(--q-dim); }

/* History strip uses chord-wrap-sm to keep wraps compact */
.chord-wrap-sm { gap: 0.15rem; }
.chord-wrap-sm .ctrl-btn { width: 18px; height: 15px; font-size: 0.55rem; }

/* ── Chord voicing panel ── */

.chord-voicing {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.chord-wrap:hover .chord-voicing {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: none) {
  .chord-voicing { opacity: 1; pointer-events: auto; }
}

/* Affordance: a persistent "⋯" on editable chord cards so it's obvious there
   are voicing controls to reveal (issue #34). */
.chord-wrap:has(.chord-voicing) .chord-card { position: relative; }
.chord-wrap:has(.chord-voicing) .chord-card::after {
  content: '⋯';
  position: absolute;
  top: 1px;
  right: 5px;
  font-size: 0.75rem;
  line-height: 1;
  color: var(--text-muted);
  opacity: 0.55;
}
.chord-wrap:has(.chord-voicing):hover .chord-card::after { opacity: 1; color: var(--accent); }

.voicing-row {
  display: flex;
  gap: 0.15rem;
  justify-content: center;
  flex-wrap: wrap;
}

.voicing-btn {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.3rem;
  font-size: 0.55rem;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.1s;
  min-width: 18px;
  text-align: center;
}

.voicing-type-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.2rem;
  font-size: 0.55rem;
  line-height: 1.4;
  cursor: pointer;
  max-width: 110px;
}

.voicing-btn:hover { background: var(--bg); color: var(--text); border-color: var(--text-muted); }
.voicing-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* VL-preferred inversion: clearly green-outlined (the "recommended" voicing),
   even when not selected, so the user can see which inversion voice-leads best. */
.voicing-btn.vl-hint {
  position: relative;
  border-color: #10b981;
  color: #10b981;
  box-shadow: inset 0 -2px 0 #10b981;
}
/* When VL-preferred is also selected: solid green. */
.voicing-btn.vl-hint.active { background: #10b981; border-color: #10b981; color: #fff; box-shadow: none; }

/* VL action button (picks the optimal inversion) */
.voicing-btn.vl-btn { border-color: #10b981; color: #10b981; }
.voicing-btn.vl-btn:hover { background: #10b981; color: #fff; border-color: #10b981; }

/* Extension button highlighted when it's a common tone with a neighbour */
.voicing-btn.ext-good { border-color: #f59e0b; color: #f59e0b; }
.voicing-btn.ext-good.active { background: #f59e0b; border-color: #f59e0b; color: #111827; }
.voicing-btn.ext-good:hover { background: #f59e0b; color: #111827; border-color: #f59e0b; }

.voicing-oct-label {
  font-size: 0.5rem;
  color: var(--text-muted);
  align-self: center;
  padding: 0 0.1rem;
}

/* ── Mode panels ── */

.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  background: var(--surface);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}



.btn-save-pool {
  background: transparent;
  color: #10b981;
  border: 1px solid #10b981;
  border-radius: 6px;
  padding: 0.28rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn-save-pool:hover:not(:disabled) { background: #10b981; color: #fff; }
.btn-save-pool.saved {
  color: var(--text-muted);
  border-color: var(--border);
  cursor: default;
}
.btn-save-pool:disabled { cursor: default; }

.share-banner {
  font-size: 0.82rem;
  color: #f59e0b;
  padding: 0.4rem 0;
}

/* ── Arrange: pool blocks ── */

.arrange-section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.arrange-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

.arrange-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.7;
  font-style: italic;
}

.arrange-timeline-header { margin-top: 0.5rem; }
.arrange-actions { display: flex; gap: 0.5rem; align-items: center; margin-left: auto; }

.pool-blocks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.pool-empty-msg {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Progression cards (name, length, chords-within) #44 ── */
.pool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--card, var(--accent));
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  width: auto; min-width: 230px; max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.pool-card-head { display: flex; align-items: center; gap: 0.5rem; }
/* the colour chip is the editable name — defaults to A/B/C, grows with text */
.pool-card-chip {
  min-width: 22px; border-radius: 6px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.12rem 0.4rem; font-size: 0.82rem; font-weight: 800; color: #fff;
  outline: none; cursor: text; white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.pool-card-chip:focus { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.pool-card-dur { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; margin-left: auto; }
/* Mini chord-blocks: roman over spelling, width ∝ beats, never truncated (#47) */
.chord-row { display: flex; gap: 3px; align-items: stretch; }
.chord-block {
  /* grow ∝ beats (set inline) but never shrink below the chord text */
  flex-shrink: 0; min-width: max-content;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; padding: 0.28rem 0.45rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.chord-block-roman {
  font-size: 0.78rem; font-weight: 700; color: var(--text); line-height: 1.1;
  white-space: nowrap;
}
.chord-block-spell {
  font-size: 0.66rem; color: var(--text-muted); line-height: 1.1;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
/* legacy single-line summaries (still used in tooltips elsewhere) */
.pool-card-chords {
  font-size: 0.74rem; color: var(--text-muted); line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.pool-card-foot { display: flex; align-items: center; gap: 0.35rem; }
.pool-card-key { font-size: 0.68rem; color: var(--text-muted); text-transform: capitalize; margin-right: auto; }
.pool-card-btn {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0.25rem 0.5rem; font-size: 0.7rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: all 0.12s;
}
.pool-card-btn:hover { border-color: var(--accent); color: var(--text); }
.pool-card-btn.add:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.pool-card.add-card {
  border: 2px dashed var(--border); border-left: 2px dashed var(--border);
  align-items: center; justify-content: center; gap: 0.2rem;
  color: var(--text-muted); cursor: pointer; min-height: 92px;
}
.pool-card.add-card:hover { border-color: var(--accent); color: var(--accent); }
.add-card .add-plus { font-size: 1.6rem; line-height: 1; }
.add-card .add-label { font-size: 0.72rem; }

/* arrangement slot name + duration */
.arrange-slot-name {
  font-size: 0.68rem; font-weight: 600; color: var(--text);
  max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center;
}
.arrange-slot-dur { font-size: 0.62rem; color: var(--text-muted); }

.pool-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 90px;
  min-height: 90px;
  border-radius: 10px;
  padding: 0.55rem 0.5rem 0.4rem;
  cursor: pointer;
  transition: filter 0.12s, transform 0.12s;
  position: relative;
  gap: 0.25rem;
}

.pool-block:hover { filter: brightness(1.2); transform: translateY(-2px); }
.pool-block.editing { outline: 2px solid var(--text); outline-offset: 2px; }

/* ── Pool editor (expanded saved progression) ── */
.pool-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}
.pool-editor-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.pool-editor .edit-hint { margin: 0.6rem 0; }

.pool-block-label {
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

.pool-block-key {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.8);
  text-align: center;
  line-height: 1.3;
}

.pool-block-add {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  width: 22px;
  height: 18px;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.1s;
}

.pool-block-add:hover { background: rgba(255,255,255,0.35); }

.pool-block-actions { display: flex; gap: 0.3rem; }
.pool-block-btn {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 5px;
  min-width: 26px;
  height: 20px;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.1s;
}
.pool-block-btn:hover { background: rgba(255,255,255,0.4); }

/* ── Arrange: timeline track ── */

.arrangement-track {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 88px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}

.arrange-empty-msg {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

.arrange-slot {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  cursor: grab;
  min-width: 96px;
}

.arrange-slot.dragging { opacity: 0.4; cursor: grabbing; }
.arrange-slot.playing .arrange-slot-insts {
  outline: 3px solid var(--text);
  outline-offset: 1px;
  box-shadow: 0 0 12px rgba(255,255,255,0.35);
}
.arrange-slot.drop-target .arrange-slot-insts {
  outline: 2px dashed var(--accent);
  outline-offset: 1px;
}

/* the repeating instances strip — first full detail, repeats faded ghosts */
.arrange-slot-insts {
  position: relative;
  display: flex;
  gap: 2px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}
.arrange-inst {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 3px;
  overflow: hidden;
  border-left: 3px solid var(--card, var(--accent));
  background: color-mix(in srgb, var(--card, var(--accent)) 12%, var(--surface));
}
.arrange-inst.ghost {
  opacity: 0.42;
  border-left-color: transparent;
  background: color-mix(in srgb, var(--card, var(--accent)) 7%, transparent);
}
.arrange-inst-label {
  font-size: 0.8rem; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

.arrange-slot-ctrls {
  display: flex; align-items: center; justify-content: center;
  gap: 0.3rem; flex-wrap: wrap;
}
.arrange-slot-name {
  font-size: 0.68rem; font-weight: 700; color: var(--text);
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.arrange-move { display: flex; gap: 0.2rem; }

/* mini chord row inside a lead instance — romans only, fills the block */
.chord-row.mini { width: 100%; height: 100%; gap: 1px; }
.chord-row.mini .chord-block {
  padding: 0 0.15rem; min-width: 1.1rem;
  background: transparent; border: none;
  border-right: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
}
.chord-row.mini .chord-block:last-child { border-right: none; }
.chord-row.mini .chord-block-roman { font-size: 0.7rem; }

/* mini beat grid inside a lead beat instance */
.beat-mini { display: flex; flex-direction: column; gap: 1px; width: 100%; height: 100%; justify-content: center; }
.beat-mini-row { display: flex; gap: 1px; flex: 1; }
.beat-mini-cell { flex: 1; border-radius: 1px; background: color-mix(in srgb, var(--text) 12%, transparent); }
.beat-mini-cell.beat-mini-down { background: color-mix(in srgb, var(--text) 20%, transparent); }
.beat-mini-cell.on { background: var(--card, var(--accent)); }

.arrange-slot-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 0.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.1s;
}

.arrange-slot-remove:hover { color: var(--q-dim); border-color: var(--q-dim); }

.arrange-reps {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.arrange-rep-btn {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  width: 18px;
  height: 16px;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.1s;
}

.arrange-rep-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.arrange-rep-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.arrange-rep-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  min-width: 2ch;
  text-align: center;
}

.arrange-arrow {
  font-size: 0.9rem;
  color: var(--text-muted);
  flex-shrink: 0;
  align-self: center;
  margin-bottom: 1.5rem;
}

/* ── Small secondary button ── */

.btn-sm {
  padding: 0.3rem 0.7rem !important;
  font-size: 0.75rem !important;
}

/* ── Share / error banners ── */

.share-error {
  font-size: 0.85rem;
  color: #c0392b;
  padding: 0.5rem 0;
}

/* ── Collapsible controls (mobile only) ── */
.controls-toggle {
  display: none;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

/* ── Song label + panel nav (Arrange-as-home IA) ── */
.song-label { font-size: 0.8rem; color: var(--text-muted); }

.panel-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.btn-back {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-back:hover { border-color: var(--accent); color: var(--text); }
.panel-title { font-size: 0.95rem; font-weight: 600; }

/* + placeholder block in the Progressions area */
.pool-block.add-block {
  background: transparent;
  border: 2px dashed var(--border);
  color: var(--text-muted);
}
.pool-block.add-block:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.pool-block.add-block .pool-block-label { font-size: 2rem; font-weight: 400; color: inherit; }

/* tiny popover menu for Choose / Write */
.add-menu {
  position: absolute;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.add-menu button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.add-menu button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.add-menu button:hover .add-menu-hint { color: rgba(255,255,255,0.85); }
.add-menu-icon { font-size: 1rem; width: 1.2em; text-align: center; }
.add-menu-hint { font-size: 0.68rem; color: var(--text-muted); font-weight: 400; }

/* ── Beats lane (step sequencer) ── */
.beat-block .pool-block-label { font-size: 1.6rem; }

.beat-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.beat-editor-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.beat-editor-head .arrange-actions { margin-left: auto; }

/* Bulk "apply settings to all" bar (arrange view) */
.apply-all-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem;
  padding: 0.6rem 0.85rem; margin-bottom: 0.75rem;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid var(--accent); border-radius: 10px;
}
.apply-all-title { font-size: 0.82rem; font-weight: 700; color: var(--text); }
.apply-all-opt { font-size: 0.8rem; color: var(--text); display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.apply-all-bar .btn-finish { margin-left: auto; }

/* Beat generator panel (#49, #53) */
.beat-gen-body { display: flex; flex-direction: column; gap: 0.6rem; }
.beat-gen-sublabel {
  font-size: 0.66rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); margin-top: 0.2rem;
}
.beat-gen-voices {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.4rem 0.9rem;
}
.beat-gen-voice { display: flex; align-items: center; gap: 0.4rem; }
.beat-gen-voice-name { flex: 1; font-size: 0.8rem; color: var(--text); }
.beat-gen-voice-count {
  min-width: 1.4rem; text-align: center; font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 0.85rem;
}

.beat-grid { display: flex; flex-direction: column; gap: 0.35rem; }
.beat-row { display: flex; align-items: center; gap: 0.6rem; }
.beat-row-label {
  width: 48px;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: capitalize;
  text-align: right;
  flex-shrink: 0;
}
.beat-cells { display: grid; grid-template-columns: repeat(16, 1fr); gap: 3px; flex: 1; }
.beat-cell {
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  cursor: pointer;
  padding: 0;
  transition: background 0.08s;
}
.beat-cell.downbeat { border-color: var(--text-muted); }
.beat-cell:hover { background: var(--border); }
.beat-cell.on { background: var(--accent); border-color: var(--accent); }

/* ── Dynamics custom inputs ── */
.dyn-count {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}
.dyn-count input {
  width: 42px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.25rem 0.35rem;
  font-size: 0.8rem;
}

/* ── Write 'More' chord palette ── */
.builder-carousel-label { display: flex; align-items: center; gap: 0.75rem; }
.builder-carousel-label #more-chords-btn { margin-left: auto; }

.extra-chords {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}
.extra-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.extra-loading { font-size: 0.82rem; color: var(--text-muted); }

/* ── Controls accordion (progressive disclosure) ── */
.ctrl-accordion { display: flex; flex-direction: column; gap: 0.4rem; }

.ctrl-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.ctrl-group.open { border-color: var(--accent); }

.ctrl-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font: inherit;
}
.ctrl-group-header:hover { background: var(--bg); }
.cg-icon    { font-size: 0.95rem; width: 1.3em; text-align: center; opacity: 0.85; flex-shrink: 0; }
.cg-name    { font-weight: 600; font-size: 0.85rem; min-width: 64px; text-align: left; }
.cg-summary { color: var(--text-muted); font-size: 0.8rem; flex: 1; text-align: left;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-chevron { color: var(--text-muted); transition: transform 0.15s; }
.ctrl-group.open .cg-chevron { transform: rotate(90deg); }

.ctrl-group-body { display: none; padding: 0.2rem 0.9rem 0.85rem; }
.ctrl-group.open .ctrl-group-body { display: block; }

/* Conditional sub-option: revealed only when relevant, visually nested under
   its parent with an accent spine and a smooth slide (see docs/DESIGN.md —
   never label a control "only applies to X"; reveal it instead). */
.ctrl-subrow {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 0 0 0 0.9rem;
  padding-left: 0.9rem;
  border-left: 2px solid var(--accent);
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-4px);
  transition: max-height 0.25s ease, opacity 0.2s ease, transform 0.2s ease,
              margin-top 0.2s ease, padding-top 0.2s ease;
}
.ctrl-subrow.open {
  max-height: 140px;
  opacity: 1;
  transform: translateY(0);
  margin-top: 0.55rem;
  padding-top: 0.5rem;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  header { padding: 0.85rem 1rem; }
  header h1 { font-size: 1.05rem; flex-basis: 100%; }
  .mode-tabs { width: 100%; }
  .mode-tab { flex: 1; padding: 0.45rem 0.5rem; text-align: center; }

  main { padding: 1rem; gap: 1.25rem; }
  .controls { padding: 1rem; gap: 1rem; }

  /* Collapse the controls block down to just its toggle when collapsed */
  .controls-toggle { display: block; }
  .controls.collapsed > *:not(.controls-toggle) { display: none; }

  .control-row, .rhythm-row { gap: 0.75rem; }
  .slider-label { min-width: 140px; }
  .btn-reset { margin-left: 0; }

  /* Tighter button rows */
  .rhythm-btn { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
  .rhythm-btns { gap: 0.3rem; }

  /* Smaller pool blocks + arrangement slots */
  .pool-block { width: 72px; min-height: 72px; }
  .pool-block-label { font-size: 1.2rem; }
  .arrange-slot-insts { height: 52px; }

  /* Larger touch targets for chord controls / voicing */
  .ctrl-btn { width: 28px; height: 24px; font-size: 0.8rem; }
  .voicing-btn { padding: 0.25rem 0.45rem; font-size: 0.65rem; min-width: 26px; }
}
