@font-face { font-family: 'Mabry Pro'; src: url('../fonts/Mabry_Pro_Light.otf') format('opentype'); font-weight: 300; font-display: swap; }
@font-face { font-family: 'Mabry Pro'; src: url('../fonts/Mabry_Pro_Regular.otf') format('opentype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Mabry Pro'; src: url('../fonts/Mabry_Pro_Medium.otf') format('opentype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Mabry Pro'; src: url('../fonts/Mabry_Pro_Bold.otf') format('opentype'); font-weight: 700; font-display: swap; }

:root {
  --red: #BF0017;
  --red-hover: #D6001A;
  --maroon: #56000F;
  --bone: #F8F7F3;
  --cream: #F2EFE7;
  --white: #FFFFFF;
  --text: #1A0005;
  --text-sec: #56000F;
  --text-muted: rgba(86, 0, 15, 0.45);
  --accent: #BF0017;
  --glow: rgba(191, 0, 23, 0.15);
  --border: rgba(86, 0, 15, 0.1);
  --border-med: rgba(86, 0, 15, 0.18);
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --font: 'Mabry Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font); background: var(--bone); color: var(--text); line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* Touch feel: no double-tap zoom delay, no long-press text selection on controls */
button, input[type="range"] { font-family: var(--font); touch-action: manipulation; }
button { -webkit-user-select: none; user-select: none; }

.app { max-width: 860px; margin: 0 auto; padding: 18px 20px 36px; }

/* ---- Shared bits ---- */
.section-label {
  display: block; font-size: 0.7rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 6px;
}

.back-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.back-btn {
  width: 32px; height: 32px; border: 1.5px solid var(--border-med); border-radius: 50%;
  background: var(--white); color: var(--text-sec); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 150ms ease;
}
.back-btn svg { width: 16px; height: 16px; }
.back-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--glow); }
.back-btn:active { transform: scale(0.92); }
.back-row-title { font-size: 0.7rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }

.icon-btn {
  width: 34px; height: 34px; border: 1.5px solid var(--border-med); border-radius: 50%;
  background: var(--white); color: var(--text-sec); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: all 150ms ease;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--glow); }
.icon-btn:active { transform: scale(0.92) rotate(180deg); }

/* ================================================
   HOME
   ================================================ */
.home-intro { text-align: center; margin: 10px 0 24px; }
.home-title { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); line-height: 1.15; }
.home-tagline { font-size: 0.95rem; font-weight: 300; color: var(--text-sec); margin-top: 8px; max-width: 440px; margin-left: auto; margin-right: auto; }

.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.mode-card {
  background: var(--white); border: 1.5px solid var(--border); border-radius: var(--r-lg);
  padding: 0; cursor: pointer; text-align: left; overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
  animation: card-in 400ms ease backwards;
}
.mode-card:nth-child(2) { animation-delay: 80ms; }
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } }
.mode-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 10px 28px rgba(86, 0, 15, 0.08); }
.mode-card:active { transform: translateY(0); }

.mode-card-visual {
  background: var(--cream); padding: 20px 16px 14px;
  display: flex; align-items: center; justify-content: center; gap: 14px; min-height: 128px;
}
.mode-mini-chord { background: var(--white); border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px 8px 4px; }
.mode-arrow { font-size: 1.6rem; color: var(--accent); font-weight: 700; }

.mode-card-visual-random { gap: 8px; flex-wrap: wrap; }
.random-tile {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 46px; height: 46px; padding: 0 10px;
  background: var(--white); border: 1.5px solid var(--border-med); border-radius: var(--r-md);
  font-size: 1.15rem; font-weight: 700; color: var(--maroon);
}
.random-tile:nth-child(1) { transform: rotate(-6deg); }
.random-tile:nth-child(2) { transform: rotate(4deg) translateY(6px); }
.random-tile:nth-child(3) { transform: rotate(-2deg) translateY(-4px); }
.random-tile:nth-child(4) { transform: rotate(7deg) translateY(4px); }
.random-tile:nth-child(5) { transform: rotate(-5deg); }
.random-tile.alt { background: var(--red); border-color: var(--red); color: var(--white); }

.mode-card-body { padding: 16px 18px 6px; }
.mode-card-name { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.mode-card-desc { font-size: 0.88rem; font-weight: 300; color: var(--text-sec); margin-top: 4px; }
.mode-card-cta {
  padding: 12px 18px 16px; font-size: 0.78rem; font-weight: 500; color: var(--accent);
  margin-top: auto;
}
.mode-card-cta::after { content: ' \2192'; transition: margin-left 150ms ease; }
.mode-card:hover .mode-card-cta::after { margin-left: 4px; }

/* ================================================
   SETUP SCREENS
   ================================================ */
.setup-prompt { font-size: 1.1rem; font-weight: 500; color: var(--text); margin-bottom: 14px; text-align: center; }

.pair-chips-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.pair-chips-label { font-size: 0.7rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-right: 2px; }
.pair-chip {
  padding: 6px 14px; border: 1.5px solid var(--border-med); border-radius: 9999px;
  background: var(--white); font-size: 0.82rem; font-weight: 500; color: var(--text-sec);
  cursor: pointer; transition: all 150ms ease;
}
.pair-chip:hover { border-color: var(--accent); color: var(--accent); }
.pair-chip.selected { background: var(--accent); border-color: var(--accent); color: var(--white); }
.pair-chip:active { transform: scale(0.95); }

/* Preset chips live in their own scroller so mobile can swipe them */
.preset-scroll-wrap { min-width: 0; }
.preset-scroll { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.chord-grid {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 10px; margin-bottom: 18px;
}
.chord-card {
  position: relative; background: var(--white); border: 1.5px solid var(--border);
  border-radius: var(--r-lg); padding: 10px 4px 8px; cursor: pointer; flex: 0 1 106px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}
.chord-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.chord-card:active { transform: scale(0.97); }
.chord-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.chord-card-name { font-size: 1rem; font-weight: 700; color: var(--text); }
/* Corner controls sit ON the card edge so they never cover the diagram's
   open/muted string markers. */
.chord-card-remove {
  position: absolute; top: -7px; left: -7px; width: 20px; height: 20px;
  border: 1.5px solid var(--border-med); border-radius: 50%;
  background: var(--white); color: var(--text-muted);
  font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center;
  transition: all 150ms ease; z-index: 2;
  box-shadow: 0 1px 5px rgba(86, 0, 15, 0.15);
}
.chord-card-remove:hover { border-color: var(--accent); color: var(--accent); background: var(--glow); }
.chord-card-edit {
  position: absolute; top: 18px; left: -7px; width: 20px; height: 20px;
  border: 1.5px solid var(--border-med); border-radius: 50%;
  background: var(--white); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all 150ms ease; z-index: 2;
  box-shadow: 0 1px 5px rgba(86, 0, 15, 0.15);
}
.chord-card-edit:hover { border-color: var(--accent); color: var(--accent); background: var(--glow); }
.chord-card-edit svg { width: 10px; height: 10px; }
.chord-card-check {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px;
  border: 1.5px solid var(--accent); border-radius: 50%;
  background: var(--accent); color: var(--white);
  display: flex; align-items: center; justify-content: center; z-index: 2;
  box-shadow: 0 1px 5px rgba(86, 0, 15, 0.15);
}
.chord-card-check svg { width: 11px; height: 11px; }

/* F version picker */
.fversion-block { background: var(--cream); border-radius: var(--r-md); padding: 14px 16px 16px; margin-bottom: 18px; }
.fversion-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.fversion-card {
  flex: 1; min-width: 96px; background: var(--white); border: 1.5px solid var(--border);
  border-radius: var(--r-md); padding: 10px 6px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.fversion-card:hover { border-color: var(--accent); }
.fversion-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.fversion-name { font-size: 0.92rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.fversion-label { font-size: 0.7rem; font-weight: 400; color: var(--text-muted); }

/* Random settings */
.random-settings { margin-bottom: 18px; text-align: center; }
.push-note { font-size: 0.78rem; color: var(--text-muted); margin: 8px auto 0; max-width: 420px; }
.seg-toggle { display: inline-flex; border: 1.5px solid var(--border-med); border-radius: 9999px; background: var(--white); padding: 3px; gap: 2px; }
.seg-btn {
  padding: 7px 18px; border: none; border-radius: 9999px; background: transparent;
  font-size: 0.85rem; font-weight: 500; color: var(--text-sec); cursor: pointer;
  transition: all 150ms ease;
}
.seg-btn:hover { color: var(--accent); }
.seg-btn.selected { background: var(--accent); color: var(--white); }

/* Setup actions */
.setup-actions { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; margin-top: 4px; }
.pool-count { font-size: 0.82rem; color: var(--text-muted); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 34px; border: none; border-radius: 9999px;
  background: var(--red); color: var(--white);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 18px rgba(191, 0, 23, 0.28);
  transition: background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}
.btn-primary svg { width: 15px; height: 15px; }
.btn-primary:hover { background: var(--red-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-primary:disabled {
  background: var(--cream); color: var(--text-muted); cursor: not-allowed;
  box-shadow: none; transform: none;
}

/* ================================================
   PRACTICE SCREENS
   ================================================ */
.pair-select-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.pair-title-arrow { color: var(--accent); font-size: 2rem; font-weight: 700; line-height: 1; }

/* Remove a chord from the progression (shows when there are more than 2) */
.chord-select-remove {
  position: absolute; top: -7px; right: -7px; z-index: 3;
  width: 20px; height: 20px; padding: 0;
  border: 1.5px solid var(--border-med); border-radius: 50%;
  background: var(--white); color: var(--text-muted);
  font-size: 14px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 5px rgba(86, 0, 15, 0.15); transition: all 150ms ease;
}
.chord-select-remove:hover { border-color: var(--accent); color: var(--accent); background: var(--glow); }

/* Add a chord to the progression (up to 4) */
.add-chord-btn {
  width: 42px; height: 42px; flex-shrink: 0;
  border: 1.5px dashed var(--border-med); border-radius: 50%;
  background: var(--cream); color: var(--accent);
  font-family: var(--font); font-size: 1.4rem; font-weight: 300; line-height: 1;
  cursor: pointer; transition: all 150ms ease;
}
.add-chord-btn:hover { border-color: var(--accent); background: var(--glow); }
.add-chord-btn:active { transform: scale(0.92); }

/* Chord selector (popover grid) */
.chord-select { position: relative; }
.chord-select-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 20px; border: 1.5px solid var(--border-med); border-radius: var(--r-lg);
  background: var(--white); cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.chord-select-btn:hover { border-color: var(--accent); }
.chord-select.open .chord-select-btn { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.chord-select-name { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); line-height: 1.2; }
.chord-select-caret { width: 18px; height: 18px; color: var(--text-sec); transition: transform 200ms ease; }
.chord-select.open .chord-select-caret { transform: rotate(180deg); }

.chord-select-pop {
  display: none; position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: var(--white); border: 1.5px solid var(--border-med); border-radius: var(--r-lg);
  box-shadow: 0 12px 32px rgba(26, 0, 5, 0.14); z-index: 60;
  padding: 10px; width: min(92vw, 372px);
}
.chord-select.open .chord-select-pop { display: block; }
.chord-select-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chord-option {
  position: relative; border: 1.5px solid transparent; border-radius: var(--r-md);
  background: transparent; padding: 6px 2px 5px; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center;
  transition: border-color 120ms ease, background 120ms ease;
}
.chord-option:hover { background: var(--glow); }
.chord-option.selected { border-color: var(--accent); background: var(--glow); }
.chord-option:disabled { opacity: 0.3; cursor: not-allowed; }
.chord-option:disabled:hover { background: transparent; }
.chord-option-edit {
  position: absolute; top: 2px; right: 2px; width: 21px; height: 21px;
  border-radius: 50%; background: var(--cream); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; z-index: 2;
  transition: all 120ms ease;
}
.chord-option-edit:hover { background: var(--glow); color: var(--accent); }
.chord-option-edit svg { width: 11px; height: 11px; }
.chord-option-name { font-size: 0.88rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.chord-option-sub { font-size: 0.62rem; font-weight: 400; color: var(--text-muted); }

/* Step tabs */
.step-tabs {
  display: flex; background: var(--white); border: 1.5px solid var(--border-med);
  border-radius: 9999px; padding: 4px; gap: 4px; margin-bottom: 12px;
}
.step-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 8px; border: none; border-radius: 9999px; background: transparent;
  cursor: pointer; transition: background 180ms ease;
}
.step-num {
  width: 22px; height: 22px; border-radius: 50%; background: var(--cream);
  color: var(--text-sec); font-size: 0.78rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all 180ms ease;
}
.step-name { font-size: 0.88rem; font-weight: 500; color: var(--text-sec); transition: color 180ms ease; white-space: nowrap; }
.step-tab:hover .step-name { color: var(--accent); }
.step-tab.active { background: var(--red); }
.step-tab.active .step-num { background: var(--white); color: var(--red); }
.step-tab.active .step-name { color: var(--white); }

.step-tip { text-align: center; font-size: 0.9rem; font-weight: 300; color: var(--text-sec); max-width: 520px; margin: 0 auto 18px; }

/* Focus mode toggle (Guided / Explore) */
.focus-mode-row { display: flex; justify-content: center; margin-bottom: 12px; }
.focus-mode-row .seg-btn { padding: 6px 20px; font-size: 0.8rem; }

/* Stage middle */
.stage-mid { display: flex; flex-direction: column; gap: 16px; margin-bottom: 20px; position: relative; }

/* Guided session: phase-based emphasis. The layout never changes — the parts
   that don't matter for the current phase just dim. */
/* Step 1 is about the chords only — hide the pattern UI entirely rather than
   dim it (a greyed pattern reads as "play this quietly" to learners). It
   reappears with the warmup count-in. */
.stage-mid[data-phase="1"] .pattern-setup-box { display: none; }

/* Guided setup: the pattern area is clearly scoped to steps 2 + 3 */
.pattern-setup-box {
  background: var(--cream); border-radius: var(--r-lg);
  padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 12px;
}
.pattern-setup-head { display: flex; align-items: center; justify-content: center; gap: 10px; }
.pattern-setup-head .section-label { margin-bottom: 0; }
.pattern-setup-badge {
  background: var(--maroon); color: var(--white);
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 10px; border-radius: 9999px;
}
.pattern-setup-box .pattern-block .section-label { display: none; }
.pattern-setup-box .pattern-strip { background: var(--white); }
.pattern-setup-note { text-align: center; font-size: 0.76rem; color: var(--text-muted); margin: 0; }
/* Once the session is in steps 2/3, the setup framing quiets down */
.stage-mid[data-phase="2"] .pattern-setup-note,
.stage-mid[data-phase="3"] .pattern-setup-note,
.stage-mid[data-phase="countin"] .pattern-setup-note { display: none; }
.stage-mid[data-phase="2"] .chord-diagrams-row,
.stage-mid[data-phase="countin"] .chord-diagrams-row { opacity: 0.55; transition: opacity 400ms ease; }
.stage-mid[data-phase="2"] .pattern-strip,
.stage-mid[data-phase="3"] .pattern-strip,
.stage-mid[data-phase="2"] .chord-diagrams-row,
.stage-mid[data-phase="3"] .chord-diagrams-row,
.stage-mid[data-phase="countin"] .pattern-strip { transition: opacity 400ms ease; }

/* Guided phase banner */
.phase-banner {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%) translateY(-4px);
  background: var(--maroon); color: var(--white);
  font-size: 0.82rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 8px 20px; border-radius: 9999px; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(86, 0, 15, 0.3);
  opacity: 0; pointer-events: none; z-index: 20;
  transition: opacity 250ms ease, transform 250ms ease;
}
.phase-banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Guided count-in: big numbers over the whole stage */
.count-overlay {
  position: absolute; inset: -4px; z-index: 30; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(248, 247, 243, 0.92); border-radius: var(--r-lg);
}
.count-overlay.show { display: flex; }
.count-overlay-sub { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.count-next {
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--maroon);
}
.count-pattern {
  display: flex; align-items: center; gap: 7px;
  background: var(--white); border: 1.5px solid var(--border-med);
  border-radius: 9999px; padding: 9px 16px;
}
.count-pattern .strip-arrow { width: 17px; height: 17px; color: var(--maroon); }
.count-pattern-gap { width: 12px; height: 3px; background: var(--border-med); border-radius: 2px; }
.count-overlay-num {
  font-size: 7rem; font-weight: 700; color: var(--red); line-height: 1;
  text-shadow: 0 8px 30px rgba(191, 0, 23, 0.25);
}
.count-overlay-num.pulse { animation: count-pulse 300ms ease; }
@keyframes count-pulse {
  from { transform: scale(1.35); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

.chord-scroll-wrap { position: relative; }
.chord-diagrams-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 18px; }
/* The cloned second copy of the loop only exists for the mobile conveyor */
@media (min-width: 641px) {
  .chord-panel-clone { display: none; }
}
.chord-panel {
  background: var(--white); border: 2px solid var(--border); border-radius: var(--r-lg);
  padding: 14px 18px 10px; text-align: center; max-width: 240px; flex: 1;
  transition: border-color 200ms ease, box-shadow 200ms ease, opacity 200ms ease;
}
/* 3-4 chord progressions: smaller panels so the whole loop stays visible */
.chords-3 .chord-panel { max-width: 185px; padding: 10px 12px 8px; }
.chords-4 .chord-panel { max-width: 165px; padding: 10px 10px 8px; }
.chords-3 .chord-panel-name, .chords-4 .chord-panel-name { font-size: 1.2rem; }
.chord-panel-svg svg { max-width: 100%; height: auto; }
.chord-panel-name { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.chord-panel.active { border-color: var(--accent); box-shadow: 0 0 0 4px var(--glow); }
.chord-panel.inactive { opacity: 0.42; }

.muted-hint { text-align: center; }
.muted-hint-text { font-size: 0.8rem; color: var(--text-muted); font-style: normal; }

/* Beat dots */
.beat-dots-row { display: flex; justify-content: center; align-items: flex-start; }
.beat-dots-row.grouped { gap: 30px; }
.beat-bar-group { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.beat-bar-dots { display: flex; gap: 14px; }
.beat-bar-label {
  font-size: 0.62rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); transition: color 150ms ease;
}
.beat-bar-group.current .beat-bar-label { color: var(--accent); font-weight: 700; }
.beat-dot {
  width: 11px; height: 11px; border-radius: 50%; background: var(--border-med);
  transition: transform 120ms ease, background 120ms ease;
}
.beat-dot.active { background: var(--red); transform: scale(1.45); }

/* Pattern strip */
.pattern-strip {
  background: var(--white); border: 1.5px solid var(--border); border-radius: var(--r-lg);
  padding: 14px 16px 10px; max-width: 480px; margin: 0 auto; width: 100%;
}
.strip-slots { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; position: relative; }
.strip-playhead {
  position: absolute; top: -6px; bottom: -6px; left: 0; width: 2.5px;
  background: var(--red); border-radius: 2px; opacity: 0;
  transform: translateX(-50%); pointer-events: none;
  box-shadow: 0 0 6px rgba(191, 0, 23, 0.4);
  transition: opacity 150ms ease;
}
.strip-slot {
  height: 44px; border-radius: var(--r-md); background: var(--cream);
  display: flex; align-items: center; justify-content: center; color: var(--maroon);
  transition: background 100ms ease, color 100ms ease, transform 100ms ease;
}
.strip-slot.empty { background: transparent; }
/* A rest reads as a dash, matching the pattern-card previews */
.strip-slot.empty::after { content: '\2013'; font-size: 1.05rem; font-weight: 600; color: rgba(86, 0, 15, 0.28); }
.strip-slot.active { background: var(--red); color: var(--white); transform: scale(1.06); }

/* Custom pattern: slots become tappable toggles */
.strip-slot.editable { border: none; font-family: var(--font); cursor: pointer; transition: background 100ms ease, box-shadow 100ms ease, transform 100ms ease; }
.strip-slot.editable.empty { background: var(--cream); box-shadow: inset 0 0 0 1.5px var(--border); }
.strip-slot.editable:hover { box-shadow: inset 0 0 0 1.5px var(--accent); }
.strip-slot.editable:active { transform: scale(0.94); }
.strip-slot.editable.active { box-shadow: none; }
.strip-hint { text-align: center; font-size: 0.72rem; color: var(--text-muted); margin-top: 8px; }

/* The Push: marker on the slot where the chord change lands */
.pattern-strip:has(.push-slot) { padding-top: 30px; }
.strip-slot.push-slot { position: relative; box-shadow: inset 0 0 0 2px var(--maroon); overflow: visible; }
.push-flag {
  position: absolute; top: -17px; left: 50%; transform: translateX(-50%);
  background: var(--maroon); color: var(--white);
  font-size: 0.5rem; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 6px; border-radius: 9999px; white-space: nowrap;
}
.strip-count.push-count { color: var(--maroon); font-weight: 700; }

/* 16th-note grid variant */
.strip-slots.slots-16 { grid-template-columns: repeat(16, 1fr); gap: 3px; }
.strip-slots.slots-16 .strip-slot { height: 36px; border-radius: var(--r-sm); }
.strip-slots.slots-16 .strip-arrow { width: 13px; height: 13px; }
.strip-slots.slots-16 .strip-slot.empty::after { font-size: 0.85rem; }
.strip-counts.slots-16 { grid-template-columns: repeat(16, 1fr); gap: 3px; }
.strip-counts.slots-16 .strip-count { font-size: 0.58rem; }
.custom-mode-row { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.custom-mode-row .seg-btn { padding: 6px 16px; font-size: 0.78rem; }
.strip-arrow { width: 22px; height: 22px; }
.strip-counts { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 4px; }
.strip-count { text-align: center; font-size: 0.72rem; font-weight: 500; color: var(--text-muted); }

/* Pattern picker: mini cards showing each pattern's arrows */
.pattern-block { text-align: center; }
.pattern-block .section-label { text-align: center; }
.pattern-picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pattern-card {
  background: var(--white); border: 1.5px solid var(--border); border-radius: var(--r-md);
  padding: 11px 8px 9px; cursor: pointer; flex: 0 1 156px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 8px;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}
.pattern-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.pattern-card:active { transform: scale(0.97); }
.pattern-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.pattern-card-name { font-size: 0.76rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.pattern-card-preview { display: flex; align-items: center; gap: 3px; min-height: 14px; }
.pattern-card-preview .strip-arrow { width: 12px; height: 12px; color: var(--maroon); }
.pattern-card-preview.dense { gap: 2px; }
.pattern-card-preview.dense .strip-arrow { width: 8px; height: 8px; }
.pp-slot { display: inline-flex; align-items: center; }
.pp-gap { display: inline-block; width: 8px; height: 2px; background: var(--border-med); border-radius: 1px; }
.pattern-card-preview.dense .pp-gap { width: 5px; }
.pp-slot.pp-change { position: relative; }
.pp-slot.pp-change .strip-arrow { color: var(--red); }
.pp-slot.pp-change::after {
  content: ''; position: absolute; bottom: -5px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--red);
}

/* ================================================
   RANDOM PLAY
   ================================================ */
.random-stage { display: flex; justify-content: center; align-items: stretch; gap: 18px; }
.random-now {
  background: var(--white); border: 2px solid var(--accent); border-radius: var(--r-lg);
  box-shadow: 0 0 0 4px var(--glow); padding: 14px 22px 0; text-align: center;
  position: relative; overflow: hidden;
}
.random-now.pop { animation: now-pop 340ms ease; }
@keyframes now-pop {
  0% { transform: scale(0.97); box-shadow: 0 0 0 8px rgba(191, 0, 23, 0.3); }
  100% { transform: scale(1); box-shadow: 0 0 0 4px var(--glow); }
}
.random-slot-label { font-size: 0.7rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 2px; }
.random-now .random-slot-label { color: var(--accent); }
.random-now-svg svg, .random-next-svg svg { max-width: 100%; height: auto; }
.random-now-name { font-size: 1.9rem; font-weight: 700; color: var(--text); line-height: 1.1; padding-bottom: 14px; }
.change-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--cream); }
.change-progress-fill { height: 100%; width: 0%; background: var(--red); }

.random-next {
  background: var(--white); border: 2px dashed var(--border-med); border-radius: var(--r-lg);
  padding: 14px 16px 10px; text-align: center; opacity: 0.75;
  display: flex; flex-direction: column; justify-content: flex-start; align-self: center;
}
.random-next-name { font-size: 1.15rem; font-weight: 700; color: var(--text-sec); }

/* ================================================
   TRANSPORT
   ================================================ */
.transport-row {
  display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap;
  background: var(--white); border: 1.5px solid var(--border); border-radius: var(--r-lg);
  padding: 14px 20px;
}
.play-cta {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 13px 30px; border: none; border-radius: 9999px;
  background: var(--red); color: var(--white); font-size: 0.98rem; font-weight: 700;
  cursor: pointer; box-shadow: 0 6px 18px rgba(191, 0, 23, 0.28);
  transition: background 150ms ease, transform 150ms ease;
}
.play-cta-icon { display: inline-flex; }
.play-cta-icon svg { width: 15px; height: 15px; }
.play-cta:hover { background: var(--red-hover); }
.play-cta:active { transform: scale(0.97); }
.play-cta:disabled { opacity: 0.7; cursor: wait; }
.play-cta.is-playing { background: var(--maroon); box-shadow: none; }

.tempo-control { display: flex; flex-direction: column; min-width: 190px; }
.tempo-control .section-label { margin-bottom: 8px; display: flex; justify-content: space-between; align-items: baseline; }
.tempo-label { font-size: 0.82rem; font-weight: 700; color: var(--accent); letter-spacing: 0; text-transform: none; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: var(--cream); border: 1px solid var(--border); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); border: 3px solid var(--white);
  box-shadow: 0 1px 5px rgba(86, 0, 15, 0.3); margin-top: -8.5px;
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--cream); border: 1px solid var(--border); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--red); border: 3px solid var(--white);
  box-shadow: 0 1px 5px rgba(86, 0, 15, 0.3);
}

/* Volume popover */
.volume-wrap { position: relative; }
.volume-wrap .icon-btn svg { width: 17px; height: 17px; }
.volume-wrap.open .icon-btn { border-color: var(--accent); color: var(--accent); background: var(--glow); }
.volume-pop {
  display: none; position: absolute; bottom: calc(100% + 10px); right: -6px;
  background: var(--white); border: 1.5px solid var(--border-med); border-radius: var(--r-lg);
  box-shadow: 0 12px 32px rgba(26, 0, 5, 0.14); z-index: 70;
  padding: 14px 16px; width: 210px;
}
.volume-wrap.open .volume-pop { display: block; }
.volume-row { margin-bottom: 10px; }
.volume-row:last-child { margin-bottom: 0; }
.volume-row .section-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.volume-val { font-size: 0.78rem; font-weight: 700; color: var(--accent); letter-spacing: 0; text-transform: none; }

/* Chord sound toggle */
.chord-audio-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.82rem; font-weight: 500; color: var(--text-sec); cursor: pointer; user-select: none;
}
.chord-audio-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  width: 38px; height: 22px; border-radius: 9999px; background: var(--border-med);
  position: relative; transition: background 180ms ease; flex-shrink: 0;
}
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--white); transition: transform 180ms ease; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.chord-audio-toggle input:checked + .toggle-track { background: var(--red); }
.chord-audio-toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }

/* ================================================
   CHORD LIBRARY BROWSER
   ================================================ */
.chord-select-browse {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 8px; padding: 10px 12px;
  border: 1.5px dashed var(--border-med); border-radius: var(--r-md);
  background: var(--cream); font-size: 0.8rem; font-weight: 500; color: var(--text-sec);
  cursor: pointer; transition: all 150ms ease;
}
.chord-select-browse svg { width: 14px; height: 14px; }
.chord-select-browse:hover { border-color: var(--accent); color: var(--accent); background: var(--glow); }

.chord-card-add {
  border-style: dashed; border-color: var(--border-med); background: var(--cream);
  justify-content: center; min-height: 120px;
}
.chord-card-add:hover { background: var(--glow); }
.chord-card-add-plus { font-size: 1.9rem; font-weight: 300; color: var(--accent); line-height: 1; }
.chord-card-add-label { font-size: 0.76rem; font-weight: 500; color: var(--text-sec); }

.lib-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(26, 0, 5, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.lib-modal {
  background: var(--white); border-radius: var(--r-lg); width: min(100%, 440px);
  padding: 18px 20px 20px; box-shadow: 0 24px 64px rgba(26, 0, 5, 0.3);
  animation: modal-in 200ms ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } }
.lib-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.lib-modal-title { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.lib-close {
  width: 30px; height: 30px; border: none; border-radius: 50%; background: var(--cream);
  color: var(--text-sec); font-size: 19px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 150ms ease;
}
.lib-close:hover { background: var(--glow); color: var(--accent); }

.lib-pill {
  border: 1.5px solid var(--border-med); border-radius: var(--r-sm); background: var(--white);
  font-family: var(--font); font-weight: 500; color: var(--text); cursor: pointer;
  transition: all 120ms ease; text-align: center;
}
.lib-pill:hover { border-color: var(--accent); color: var(--accent); }
.lib-pill.selected { background: var(--accent); border-color: var(--accent); color: var(--white); }

.lib-roots { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-bottom: 14px; }
.lib-root { font-size: 0.85rem; padding: 7px 2px; }
.lib-types { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 14px; }
.lib-type { font-size: 0.72rem; padding: 6px 2px; }

.lib-preview { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 14px; }
.lib-preview-empty { font-size: 0.85rem; color: var(--text-muted); padding: 40px 0; }
.lib-preview-mid { text-align: center; }
.lib-preview-name { font-size: 1.3rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.lib-voicing-counter { font-size: 0.68rem; color: var(--text-muted); margin-top: 1px; }
.lib-voicing-nav {
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--border-med); transition: color 150ms ease;
}
.lib-voicing-nav svg { width: 22px; height: 22px; }
.lib-voicing-nav:hover:not(:disabled) { color: var(--accent); }
.lib-voicing-nav:disabled { opacity: 0.3; cursor: default; }

.lib-confirm { width: 100%; }

/* ---- Custom chord builder ---- */
.cust-open-link {
  display: block; width: 100%; margin-top: 10px; padding: 8px 4px;
  border: none; background: none; cursor: pointer;
  font-family: var(--font); font-size: 0.8rem; font-weight: 600; color: var(--accent);
  text-decoration: underline; text-underline-offset: 3px;
}
.cust-open-link:hover { color: var(--maroon); }

.cust-back svg { width: 17px; height: 17px; }
.cust-head-spacer { width: 30px; height: 30px; }

.cust-name {
  width: 100%; padding: 9px 12px; margin-bottom: 14px;
  border: 1.5px solid var(--border-med); border-radius: var(--r-sm);
  /* 16px minimum — anything smaller makes iOS Safari zoom the page on focus */
  font-family: var(--font); font-size: 1rem; font-weight: 600; color: var(--text);
  background: var(--white);
}
.cust-name:focus { outline: none; border-color: var(--accent); }
.cust-name::placeholder { color: var(--text-muted); font-weight: 400; }

.cust-body {
  display: flex; gap: 14px; justify-content: center; align-items: flex-start;
  flex-wrap: wrap; margin-bottom: 10px;
}
.cust-row { display: flex; gap: 4px; align-items: center; margin-bottom: 4px; }
.cust-row-head { margin-bottom: 7px; }
.cust-fretnum { width: 17px; font-size: 0.7rem; color: var(--text-muted); text-align: right; flex: 0 0 auto; }
.cust-cell {
  width: 36px; height: 33px; padding: 0; cursor: pointer;
  border: 1px solid rgba(86, 0, 15, 0.25); border-radius: 6px; background: var(--cream);
  display: flex; align-items: center; justify-content: center; transition: background 120ms ease;
}
.cust-cell:hover { background: var(--glow); }
.cust-dot {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent);
  color: var(--white); font-weight: 700; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
}
.cust-openmute {
  width: 36px; height: 26px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--border-med); border-radius: 6px; background: var(--white);
  color: var(--text-sec); font-size: 1rem; line-height: 1; font-family: var(--font);
  display: flex; align-items: center; justify-content: center; transition: all 120ms ease;
}
.cust-openmute:hover { border-color: var(--accent); color: var(--accent); }
.cust-open-ring {
  width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid var(--accent); display: block;
}
.cust-preview { text-align: center; padding-top: 12px; }
.cust-preview-name { font-size: 1.05rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.cust-hear {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  padding: 6px 14px; border: 1.5px solid var(--border-med); border-radius: 999px;
  background: var(--white); cursor: pointer;
  font-family: var(--font); font-size: 0.78rem; font-weight: 600; color: var(--text-sec);
  transition: all 120ms ease;
}
.cust-hear svg { width: 11px; height: 11px; }
.cust-hear:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--glow); }
.cust-hear:disabled { opacity: 0.4; cursor: default; }

.cust-fretwin { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.cust-fretwin-label { font-size: 0.78rem; font-weight: 600; color: var(--text-sec); min-width: 76px; text-align: center; }
.cust-fret-btn {
  width: 28px; height: 28px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--border-med); border-radius: 50%; background: var(--white);
  color: var(--text-sec); font-size: 1rem; line-height: 1; font-family: var(--font);
  display: flex; align-items: center; justify-content: center; transition: all 120ms ease;
}
.cust-fret-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.cust-fret-btn:disabled { opacity: 0.35; cursor: default; }

.cust-hint { font-size: 0.74rem; color: var(--text-muted); text-align: center; margin: 0 0 12px; line-height: 1.45; }

/* ---- Footer ---- */
.footer { margin-top: 28px; text-align: center; }
.footer-text { font-size: 0.72rem; color: var(--text-muted); }
.footer-link { color: var(--text-sec); text-decoration: none; font-weight: 500; }
.footer-link:hover { color: var(--accent); }

/* ================================================
   RESPONSIVE
   ================================================ */
/* ================================================
   MOBILE — app-like: tight vertical rhythm, sticky transport,
   swipeable pattern carousel, minimal scrolling
   ================================================ */
@media (max-width: 640px) {
  .app { padding: 10px 12px 16px; }

  .home-title { font-size: 1.6rem; }
  .home-intro { margin: 4px 0 16px; }
  .mode-cards { grid-template-columns: 1fr; gap: 12px; }
  .mode-card-visual { min-height: 104px; padding: 14px 12px 10px; }

  .back-row { margin-bottom: 8px; }
  .back-btn { width: 28px; height: 28px; }

  /* Compact selectors and controls */
  .pair-select-row { gap: 8px; margin-bottom: 10px; }
  .pair-title-arrow { font-size: 1.5rem; }
  .chord-select-btn { padding: 5px 12px 5px 16px; gap: 7px; }
  .chord-select-name { font-size: 1.45rem; }
  .focus-mode-row { margin-bottom: 8px; }
  .focus-mode-row .seg-btn { padding: 5px 16px; font-size: 0.76rem; }
  .step-tabs { margin-bottom: 8px; padding: 3px; }
  /* All three step names stay readable: drop the number circles instead */
  .step-tab .step-num { display: none; }
  .step-name { font-size: 0.72rem; }
  .step-tab { gap: 0; padding: 8px 2px; }
  .step-tip { font-size: 0.78rem; margin-bottom: 10px; }

  /* Stage density */
  .stage-mid { gap: 10px; margin-bottom: 12px; }
  .chord-panel { padding: 8px 8px 6px; }
  .chord-panel-name { font-size: 1.15rem; margin-top: 0; }

  /* Chord panels become a swipeable carousel; the sounding chord auto-scrolls
     into view during playback. Two chords still fit without scrolling. */
  .chord-diagrams-row {
    flex-wrap: nowrap; justify-content: flex-start;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; scrollbar-width: none;
    gap: 8px; padding: 4px 2px;
  }
  .chord-diagrams-row::-webkit-scrollbar { display: none; }
  .chord-panel,
  .chords-3 .chord-panel,
  .chords-4 .chord-panel { flex: 0 0 166px; max-width: none; scroll-snap-align: start; }
  .chords-3 .chord-panel-name, .chords-4 .chord-panel-name { font-size: 1.05rem; }
  .chord-scroll-wrap::before, .chord-scroll-wrap::after {
    position: absolute; top: 4px; bottom: 4px; width: 44px;
    pointer-events: none; z-index: 3; transition: opacity 200ms ease;
    display: flex; align-items: center;
    font-size: 1.5rem; font-weight: 700; color: var(--accent); line-height: 1;
  }
  .chord-scroll-wrap::before {
    content: '\2039'; left: 0; justify-content: flex-start; padding-left: 2px;
    background: linear-gradient(to right, var(--bone) 30%, transparent);
    animation: fade-nudge-left 1.6s ease-in-out infinite;
  }
  .chord-scroll-wrap::after {
    content: '\203A'; right: 0; justify-content: flex-end; padding-right: 2px;
    background: linear-gradient(to left, var(--bone) 30%, transparent);
    animation: fade-nudge-right 1.6s ease-in-out infinite;
  }
  .chord-scroll-wrap.scroll-start::before { opacity: 0; animation: none; }
  .chord-scroll-wrap.scroll-end::after { opacity: 0; animation: none; }
  .add-chord-btn { width: 36px; height: 36px; font-size: 1.2rem; }
  .chord-select-remove { top: -6px; right: -6px; }
  .pattern-strip { padding: 10px 10px 8px; }
  .strip-slot { height: 38px; }
  .pattern-setup-box { padding: 10px 10px 8px; gap: 8px; }
  .pattern-setup-note { font-size: 0.7rem; }
  .random-stage { gap: 8px; }
  .random-now { padding: 10px 10px 0; }
  .random-now-name { font-size: 1.4rem; padding-bottom: 10px; }
  .count-overlay-num { font-size: 4.5rem; }

  /* Pattern picker becomes a swipeable one-row carousel */
  .pattern-picker {
    flex-wrap: nowrap; justify-content: flex-start;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding: 2px 2px 6px; margin: 0 -2px;
    scrollbar-width: none;
  }
  .pattern-picker::-webkit-scrollbar { display: none; }
  .pattern-card { flex: 0 0 132px; scroll-snap-align: center; }
  /* Edge fades + pulsing chevrons signal there is more to swipe; both melt
     away at the ends. --fade-bg matches the surface behind the carousel. */
  .pattern-block { position: relative; --fade-bg: var(--bone); }
  .pattern-setup-box .pattern-block { --fade-bg: var(--cream); }
  .pattern-block::before, .pattern-block::after {
    position: absolute; top: 24px; bottom: 6px; width: 52px;
    pointer-events: none; z-index: 3; transition: opacity 200ms ease;
    display: flex; align-items: center;
    font-size: 1.5rem; font-weight: 700; color: var(--accent); line-height: 1;
  }
  /* Inside the guided setup box the picker's own label is hidden, so the
     carousel starts at the top of the block — align the fades with it. */
  .pattern-setup-box .pattern-block::before,
  .pattern-setup-box .pattern-block::after { top: 2px; }
  .pattern-block::before {
    content: '\2039'; left: -2px; justify-content: flex-start; padding-left: 2px;
    background: linear-gradient(to right, var(--fade-bg) 35%, transparent);
    animation: fade-nudge-left 1.6s ease-in-out infinite;
  }
  .pattern-block::after {
    content: '\203A'; right: -2px; justify-content: flex-end; padding-right: 2px;
    background: linear-gradient(to left, var(--fade-bg) 35%, transparent);
    animation: fade-nudge-right 1.6s ease-in-out infinite;
  }
  .pattern-block.scroll-start::before { opacity: 0; animation: none; }
  .pattern-block.scroll-end::after { opacity: 0; animation: none; }

  /* Random Challenge presets: one swipeable row with the same edge fades */
  .pair-chips-row { flex-wrap: nowrap; }
  .pair-chips-label { flex-shrink: 0; }
  .preset-scroll-wrap { position: relative; flex: 1; }
  .preset-scroll {
    flex-wrap: nowrap; justify-content: flex-start;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; scrollbar-width: none;
    padding: 2px 0;
  }
  .preset-scroll::-webkit-scrollbar { display: none; }
  .preset-scroll .pair-chip { flex-shrink: 0; scroll-snap-align: start; font-size: 0.78rem; padding: 5px 12px; }
  .preset-scroll-wrap::before, .preset-scroll-wrap::after {
    position: absolute; top: 0; bottom: 0; width: 38px;
    pointer-events: none; z-index: 3; transition: opacity 200ms ease;
    display: flex; align-items: center;
    font-size: 1.25rem; font-weight: 700; color: var(--accent); line-height: 1;
  }
  .preset-scroll-wrap::before {
    content: '\2039'; left: 0; justify-content: flex-start;
    background: linear-gradient(to right, var(--bone) 35%, transparent);
    animation: fade-nudge-left 1.6s ease-in-out infinite;
  }
  .preset-scroll-wrap::after {
    content: '\203A'; right: 0; justify-content: flex-end;
    background: linear-gradient(to left, var(--bone) 35%, transparent);
    animation: fade-nudge-right 1.6s ease-in-out infinite;
  }
  .preset-scroll-wrap.scroll-start::before { opacity: 0; animation: none; }
  .preset-scroll-wrap.scroll-end::after { opacity: 0; animation: none; }

  @keyframes fade-nudge-right {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(3px); }
  }
  @keyframes fade-nudge-left {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-3px); }
  }

  /* Sticky transport: play/tempo always in thumb reach, like an app bar.
     Respects the iPhone home-indicator safe area. */
  .transport-row {
    position: sticky; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); z-index: 80;
    flex-wrap: nowrap; gap: 10px; padding: 10px 12px;
    box-shadow: 0 6px 24px rgba(86, 0, 15, 0.16);
  }
  /* Icon-only round play button keeps the bar to a single row */
  .play-cta { padding: 14px; border-radius: 50%; flex-shrink: 0; }
  .play-cta .play-cta-label { display: none; }
  .play-cta-icon svg { width: 17px; height: 17px; }
  .tempo-control { min-width: 0; flex: 1; }
  .chord-audio-toggle { font-size: 0.7rem; gap: 5px; flex-shrink: 0; }

  .footer { margin-top: 12px; }
  .footer-text { font-size: 0.62rem; }
}

/* ================================================
   ACCESS GATE (js/gate.js)
   Shown only on the standalone site when the visitor hasn't verified.
   ================================================ */
body.is-gated { overflow: hidden; }

.gate-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: var(--bone);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.gate-card {
  width: min(100%, 420px); text-align: center;
  background: var(--white); border-radius: var(--r-lg);
  padding: 32px 26px 26px;
  box-shadow: 0 24px 64px rgba(26, 0, 5, 0.12);
}
.gate-kicker {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 10px;
}
.gate-title {
  font-size: 1.5rem; font-weight: 700; color: var(--text);
  line-height: 1.2; margin: 0 0 10px;
}
.gate-text {
  font-size: 0.9rem; line-height: 1.5; color: var(--text-sec);
  margin: 0 0 20px;
}
.gate-form { display: flex; flex-direction: column; gap: 10px; }
.gate-input {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border-med); border-radius: var(--r-sm);
  /* 16px minimum stops iOS Safari zooming the page on focus */
  font-family: var(--font); font-size: 1rem; color: var(--text);
  background: var(--white); text-align: center;
}
.gate-input:focus { outline: none; border-color: var(--accent); }
.gate-input::placeholder { color: var(--text-muted); }
.gate-btn {
  width: 100%; padding: 12px 18px; border: none; border-radius: 9999px;
  background: var(--accent); color: var(--white); cursor: pointer;
  font-family: var(--font); font-size: 0.95rem; font-weight: 700;
  transition: background 150ms ease, opacity 150ms ease;
}
.gate-btn:hover:not(:disabled) { background: var(--maroon); }
.gate-btn:disabled { opacity: 0.6; cursor: default; }
.gate-error {
  font-size: 0.82rem; line-height: 1.45; color: var(--accent);
  margin: 14px 0 0;
}
.gate-foot {
  font-size: 0.82rem; color: var(--text-sec);
  margin: 18px 0 0; padding-top: 16px; border-top: 1px solid var(--border);
}
.gate-link { color: var(--accent); font-weight: 600; }

@media (max-width: 640px) {
  .gate-card { padding: 26px 20px 22px; }
  .gate-title { font-size: 1.3rem; }
}


/* ChorwFlow Logout */

/* Logout unten */

#logout-btn{
  display:block;
  margin:40px auto 24px;
  padding:10px 16px;
  border:none;
  border-radius:999px;
  background:#f3f4f6;
  color:#6b7280;
  font-size:14px;
  cursor:pointer;
  transition:.2s;
}

#logout-btn:hover{
  background:#e5e7eb;
  color:#111827;
}


/* ==================================================
   APP TOOLBAR & THREE-DOT MENU
   Language selection and logout on the home screen
   ================================================== */
#app-toolbar {
      position: fixed;
      top: 12px;
      right: 16px;
      z-index: 1000;
      display: none;
      align-items: center;
      justify-content: flex-end;
    }
    #app-toolbar .toolbar-icon {
      box-sizing: border-box;
      width: 36px;
      height: 36px;
      padding: 7px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border: 1px solid rgba(148,163,184,.28);
      border-radius: 50%;
      background: rgba(255,255,255,.88);
      color: #334155;
      cursor: pointer;
      box-shadow: 0 2px 8px rgba(15,23,42,.08);
      transition: background .15s, border-color .15s, transform .15s;
    }
    #app-toolbar .toolbar-icon:hover { background: #f1f5f9; transform: translateY(-1px); }
    #app-toolbar .toolbar-icon svg { display:block; width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
    #app-toolbar .toolbar-icon:focus-visible, #app-menu .menu-item:focus-visible { outline: 2px solid #22c55e; outline-offset: 2px; }
    #app-menu.app-menu {
      position: absolute;
      top: calc(100% + 9px);
      right: 0;
      width: 210px;
      padding: 7px;
      border: 1px solid rgba(148,163,184,.25);
      border-radius: 13px;
      background: #fff;
      color: #1e293b;
      box-shadow: 0 12px 32px rgba(15,23,42,.16);
    }
    #app-menu[hidden] { display:none; }
    #app-menu .menu-heading { padding: 7px 10px 5px; color:#64748b; font-size:11px; font-weight:700; letter-spacing:.07em; text-transform:uppercase; }
    #app-menu .menu-item { width:100%; min-height:39px; box-sizing:border-box; display:flex; align-items:center; gap:10px; padding:8px 10px; border:0; border-radius:8px; background:transparent; color:inherit; font:inherit; font-size:14px; text-align:left; cursor:pointer; }
    #app-menu .menu-item:hover { background:#f1f5f9; }
    #app-menu .menu-flag { width:22px; font-size:17px; line-height:1; }
    #app-menu .menu-check { margin-left:auto; color:#15803d; opacity:0; font-weight:700; }
    #app-menu .language-menu-item[aria-pressed="true"] { background:#ecfdf3; color:#166534; font-weight:600; }
    #app-menu .language-menu-item[aria-pressed="true"] .menu-check { opacity:1; }
    #app-menu .menu-divider { height:1px; margin:6px 3px; background:#e2e8f0; }
    #app-menu .logout-menu-item svg { width:18px; height:18px; flex:0 0 18px; }
    #app-menu .logout-menu-item { color:#b91c1c; }
    #app-menu .logout-menu-item:hover { background:#fef2f2; }
    @media (max-width:480px) { #app-toolbar { top:8px; right:8px; } }

/* =========================================================
   PERSIAN (fa) — consolidated RTL text + LTR music UI
   ========================================================= */

/* Chord progression stays centered and ordered left-to-right. */
html[lang="fa"] .pair-select-row {
  direction: ltr;
  justify-content: center;
}
html[lang="fa"] .pair-select-row .add-chord-btn {
  order: 99;
}

/* Chord diagrams, moving chord carousel and random mode: LTR. */
html[lang="fa"] .chord-scroll-wrap,
html[lang="fa"] .chord-diagrams-row,
html[lang="fa"] .random-stage {
  direction: ltr;
}

/* Rhythm counts, arrows, playhead and pattern previews: LTR. */
html[lang="fa"] .pattern-strip,
html[lang="fa"] .strip-slots,
html[lang="fa"] .strip-counts,
html[lang="fa"] .beat-dots-row,
html[lang="fa"] .beat-bar-group,
html[lang="fa"] .beat-bar-dots,
html[lang="fa"] .pattern-picker,
html[lang="fa"] .pattern-card,
html[lang="fa"] .pattern-card-preview {
  direction: ltr;
}

/* Playback and tempo controls retain their standard left-to-right order. */
html[lang="fa"] .transport-row,
html[lang="fa"] .tempo-control,
html[lang="fa"] .tempo-control .section-label,
html[lang="fa"] input[type="range"] {
  direction: ltr;
}

/* Chord Library: use the actual classes rendered by js/app.js.
   Only the Latin-note/type grids are LTR; the modal's Persian copy stays RTL. */
html[lang="fa"] .lib-roots,
html[lang="fa"] .lib-types {
  direction: ltr;
}
html[lang="fa"] .lib-root,
html[lang="fa"] .lib-type {
  direction: ltr;
  text-align: center;
}

/* Keep Persian home-card descriptions right-aligned. */
html[lang="fa"] .mode-card-body,
html[lang="fa"] .mode-card-name,
html[lang="fa"] .mode-card-desc,
html[lang="fa"] .mode-card-cta {
  text-align: right;
}
