:root {
    --bg-primary: #0a0d14;
    --bg-secondary: #121824;
    --bg-tertiary: #1b2334;
    --bg-card: rgba(var(--panel-rgb, 22, 30, 46), 0.75);
    --border-subtle: rgba(var(--fg-rgb, 255, 255, 255), 0.08);
    --border-accent: rgba(var(--accent-rgb, 0, 240, 255), 0.3);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --cyan: #00f0ff;
    --cyan-glow: rgba(var(--accent-rgb, 0, 240, 255), 0.4);
    --purple: #8b5cf6;
    --purple-glow: rgba(var(--purple-rgb, 139, 92, 246), 0.4);
    --emerald: #10b981;
    --emerald-glow: rgba(var(--emerald-rgb, 16, 185, 129), 0.4);
    --amber: #f59e0b;
    --amber-glow: rgba(var(--amber-rgb, 245, 158, 11), 0.4);
    --rose: #f43f5e;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light theme: guitar wood (fretboard tan, navy accents, black dots). Every themed color in this file is
   var(--name, dark value), so these variables only exist here and the dark theme keeps its exact values. */
:root[data-theme="light"] {
    --bg-primary: #e0c084;
    --bg-secondary: #fbf1da;
    --bg-tertiary: #efdcb3;
    --border-subtle: rgba(92, 64, 28, 0.16);
    --border-accent: rgba(59, 65, 102, 0.4);

    --text-primary: #2a1f12;
    --text-secondary: #5c4930;
    --text-muted: #86704f;
    --text-strong: #1e150a;

    --cyan: #3b4166;
    --cyan-glow: rgba(59, 65, 102, 0.22);
    --purple: #6b46c1;
    --purple-glow: rgba(107, 70, 193, 0.22);
    --emerald: #0f7a55;
    --emerald-glow: rgba(15, 122, 85, 0.22);
    --amber: #b45309;
    --amber-glow: rgba(180, 83, 9, 0.22);
    --rose: #be123c;

    --accent-rgb: 59, 65, 102;
    --accent-2: #262b47;
    --on-accent: #fbf3df;
    --fg-rgb: 92, 64, 28;
    --shadow-rgb: 110, 78, 36;
    --panel-rgb: 248, 236, 207;
    --deep-rgb: 240, 222, 182;
    --emerald-rgb: 15, 122, 85;
    --amber-rgb: 180, 83, 9;
    --rose-rgb: 190, 18, 60;
    --red-rgb: 185, 28, 28;
    --purple-rgb: 107, 70, 193;
    --violet-rgb: 126, 34, 206;
    --orange-rgb: 194, 65, 12;
    --emerald-hi: #0b6b4a;
    --sky: #1d5b8f;
    --amber-hi: #a34a04;
    --red-hi: #b91c1c;
    --orange-hi: #b2470e;
    --slate: #8a7556;
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    line-height: 1.5;
    background-image: 
        radial-gradient(circle at 15% 15%, rgba(var(--purple-rgb, 139, 92, 246), 0.12) 0%, transparent 40%),
        radial-gradient(circle at 85% 75%, rgba(var(--accent-rgb, 0, 240, 255), 0.1) 0%, transparent 45%),
        linear-gradient(180deg, #0a0d14 0%, #080b11 100%);
    background-attachment: fixed;
    overflow-x: hidden;
}

/* Glassmorphism Card Utility */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px rgba(var(--shadow-rgb, 0, 0, 0), 0.35);
}

/* Navigation Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(var(--deep-rgb, 10, 13, 20), 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0.85rem 2rem;
}

.header-container {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--cyan);
}

/* Line icons (icons.js): thin single stroke in the text color, a bit larger than the text */
.icon {
    width: 1.4em;
    height: 1.4em;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.34em;
}

.tool-btn .icon {
    width: 20px;
    height: 20px;
}

.tool-btn.play-btn .icon {
    width: 22px;
    height: 22px;
}

.theme-opt,
.metro-icon {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.step-icon .icon {
    width: 14px;
    height: 14px;
}

.logo-title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, var(--text-strong, #fff), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-badge {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.15);
    color: var(--cyan);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(var(--accent-rgb, 0, 240, 255), 0.3);
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    background: var(--bg-secondary);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    gap: 4px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1.15rem;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
}

.tab-btn.active {
    color: var(--text-strong, #fff);
    background: linear-gradient(135deg, rgba(var(--accent-rgb, 0, 240, 255), 0.2), rgba(var(--purple-rgb, 139, 92, 246), 0.25));
    border: 1px solid var(--border-accent);
    box-shadow: 0 0 12px rgba(var(--accent-rgb, 0, 240, 255), 0.2);
}

/* Narrow screens: logo and theme toggle on top, tabs on their own row */
@media (max-width: 640px) {
    .app-header { padding: 0.75rem 1rem; }
    .header-container { flex-wrap: wrap; gap: 0.6rem; }
    .nav-tabs { order: 3; width: 100%; justify-content: center; }
}

/* Theme toggle (tối / sáng tông gỗ guitar) in the header */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    font-family: var(--font-sans);
    transition: var(--transition);
}

.theme-toggle:hover {
    border-color: var(--border-accent);
}

.theme-opt {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    transition: var(--transition);
}

:root:not([data-theme="light"]) .theme-opt-dark,
:root[data-theme="light"] .theme-opt-light {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.14);
    color: var(--cyan);
}

/* Main Layout */
.main-content {
    max-width: 1440px;
    margin: 2rem auto;
    padding: 0 1.5rem 3rem 1.5rem;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========================================================
   SECTION: GUITAR TUNER
   ======================================================== */
.tuner-container {
    max-width: 680px;
    margin: 0 auto;
}

.tuner-main-card {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.tuner-header {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.select-control {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
}

.tuner-gauge-wrap {
    position: relative;
    width: 320px;
    height: 180px;
    display: flex;
    justify-content: center;
}

#tunerMeterCanvas {
    width: 320px;
    height: 180px;
}

.tuner-note-center {
    position: absolute;
    bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.detected-note {
    font-family: var(--font-display);
    font-size: 4rem;
    font-weight: 800;
    line-height: 1;
    color: var(--text-primary);
    text-shadow: 0 0 20px rgba(var(--fg-rgb, 255, 255, 255), 0.2);
}

.detected-octave {
    font-size: 2rem;
    color: var(--text-muted);
}

.tuner-in-tune .detected-note {
    color: var(--emerald);
    text-shadow: 0 0 25px var(--emerald-glow);
}

.target-string-label {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.tuning-status-tag {
    margin-top: 1rem;
    padding: 0.4rem 1.2rem;
    border-radius: 20px;
    border: 1px solid transparent;
    font-weight: 700;
    font-size: 0.95rem;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.tuning-status-tag.in-tune {
    background: rgba(var(--emerald-rgb, 16, 185, 129), 0.15);
    color: var(--emerald);
    border: 1px solid var(--emerald);
    box-shadow: 0 0 15px var(--emerald-glow);
}

.tuning-status-tag.flat {
    background: rgba(var(--amber-rgb, 245, 158, 11), 0.15);
    color: var(--amber);
    border: 1px solid var(--amber);
}

.tuning-status-tag.sharp {
    background: rgba(var(--rose-rgb, 244, 63, 94), 0.15);
    color: var(--rose);
    border: 1px solid var(--rose);
}

.tuner-hint {
    margin-top: 1rem;
    max-width: 480px;
    text-align: center;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-muted);
}

/* Headstock (tuner.js renderHeadstock): pegs, strings, the active string vibrating */
.tuner-headstock {
    --hs-face: #222b3d;
    --hs-edge: rgba(var(--accent-rgb, 0, 240, 255), 0.35);
    --hs-board: #141a26;
    --hs-nut: #e9e4d6;
    --hs-plain: #c9d1dc;
    --hs-wound: #d4b27c;
    --hs-metal: #9aa6b8;
    --hs-knob: #39445a;
    --hs-knob-edge: #9aa6b8;
    --peg-c: var(--cyan);
    width: 100%;
    max-width: 460px;
    margin-top: 1rem;
}

:root[data-theme="light"] .tuner-headstock {
    --hs-face: #5a3c22;
    --hs-edge: #3a2614;
    --hs-board: #3d2817;
    --hs-nut: #f7eed6;
    --hs-plain: #efe4cc;
    --hs-wound: #e3c48f;
    --hs-metal: #d8c9a9;
    --hs-knob: #e6d1a4;
    --hs-knob-edge: #8a6a40;
}

.tuner-headstock[data-state="flat"] { --peg-c: var(--amber); }
.tuner-headstock[data-state="sharp"] { --peg-c: var(--rose); }
.tuner-headstock[data-state="in-tune"] { --peg-c: var(--emerald); }

.tuner-headstock svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.hs-face { fill: var(--hs-face); stroke: var(--hs-edge); stroke-width: 1.5; }
.hs-logo {
    fill: rgba(var(--fg-rgb, 255, 255, 255), 0.22);
    font: 700 11px var(--font-display);
    letter-spacing: 0.12em;
    text-anchor: middle;
}
:root[data-theme="light"] .hs-logo { fill: rgba(251, 241, 218, 0.4); }
.hs-board { fill: var(--hs-board); }
.hs-fret { stroke: var(--hs-metal); stroke-width: 2; opacity: 0.7; }
.hs-nut { fill: var(--hs-nut); }

.hs-string { stroke: var(--hs-plain); fill: none; stroke-linecap: round; opacity: 0.75; transition: opacity 0.2s; }
.hs-string[data-idx="3"], .hs-string[data-idx="4"], .hs-string[data-idx="5"] { stroke: var(--hs-wound); }
.hs-string.active { stroke: var(--peg-c); opacity: 1; filter: drop-shadow(0 0 3px var(--peg-c)); }
.hs-vibration {
    fill: var(--peg-c);
    fill-opacity: 0.2;
    stroke: var(--peg-c);
    stroke-opacity: 0.5;
    stroke-width: 0.8;
    stroke-linejoin: round;
    pointer-events: none;
}

.hs-peg { cursor: pointer; }
.hs-shaft { fill: var(--hs-knob-edge); }
.hs-knob { fill: var(--hs-knob); stroke: var(--hs-knob-edge); stroke-width: 1.5; transition: stroke 0.2s, fill 0.2s; }
.hs-bushing { fill: none; stroke: var(--hs-metal); stroke-width: 1.5; opacity: 0.6; }
.hs-post { fill: var(--hs-metal); }
.hs-peg:hover .hs-knob { stroke: var(--cyan); }

/* The peg to turn: knob, post and note name light up in the needle's color */
.hs-peg.active .hs-knob { stroke: var(--peg-c); stroke-width: 2.5; filter: drop-shadow(0 0 6px var(--peg-c)); }
.hs-peg.active .hs-post { fill: var(--peg-c); }


.hs-chip { outline: none; }
.hs-chip-bg { fill: var(--bg-secondary); stroke: var(--border-subtle); stroke-width: 1.5; transition: stroke 0.2s; }
.hs-peg:hover .hs-chip-bg, .hs-chip:focus-visible .hs-chip-bg { stroke: var(--border-accent); }
.hs-peg.target .hs-chip-bg { stroke: var(--cyan); stroke-width: 2.5; fill: rgba(var(--accent-rgb, 0, 240, 255), 0.12); }
.hs-peg.active .hs-chip-bg { stroke: var(--peg-c); stroke-width: 2.5; }
.hs-note {
    fill: var(--text-primary);
    font: 800 17px var(--font-display);
    text-anchor: middle;
    dominant-baseline: central;
}
.hs-octave { font-size: 10px; font-weight: 600; fill: var(--text-muted); }

.hs-tuned { display: none; pointer-events: none; }
.hs-peg.tuned .hs-tuned { display: inline; }
.hs-tuned circle { fill: var(--emerald); }
.hs-tuned path { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ========================================================
   SECTION: TRANSCRIBE & INGESTION
   ======================================================== */
.transcribe-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

@media (max-width: 1100px) {
    .transcribe-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .transcribe-grid { grid-template-columns: 1fr; }
}

.upload-card, .record-card, .url-card {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.badge-ytdlp {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(var(--red-rgb, 239, 68, 68), 0.2), rgba(var(--violet-rgb, 168, 85, 247), 0.2));
    border: 1px solid rgba(var(--red-rgb, 239, 68, 68), 0.4);
    color: var(--red-hi, #f87171);
    box-shadow: 0 0 10px rgba(var(--red-rgb, 239, 68, 68), 0.2);
}

.card-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-desc {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 1.5rem;
}

/* URL Ingestion Styling */
/* Song search (name / lyrics line + singer -> YouTube results) */
.song-search-panel {
    padding: 1.15rem 1.4rem;
    border-radius: var(--radius-lg);
    background: rgba(var(--panel-rgb, 18, 24, 38), 0.72);
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.08);
    box-shadow: 0 4px 20px rgba(var(--shadow-rgb, 0, 0, 0), 0.25);
}

.song-search {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.song-search-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.song-search-input {
    flex: 1 1 180px;
    min-width: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.92rem;
    font-family: var(--font-sans);
    padding: 0.75rem 0.9rem;
    outline: none;
    transition: var(--transition);
}

.song-search-input::placeholder {
    color: var(--text-muted);
    font-size: 0.84rem;
}

.song-search-input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 15px var(--cyan-glow);
}

.btn-song-search {
    flex: 0 0 auto;
    background: linear-gradient(135deg, var(--cyan), var(--purple));
    border: none;
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: var(--font-display);
    cursor: pointer;
    transition: var(--transition);
}

.btn-song-search:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* No width until a search is sent; then it grows in and the two boxes shrink to give it room */
.btn-song-clear {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    width: 0;
    margin-left: -0.5rem;       /* cancels the row gap while hidden */
    padding: 0;
    background: var(--bg-secondary);
    border: 0 solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    opacity: 0;
    visibility: hidden;
    cursor: pointer;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-song-clear.shown {
    width: 2.6rem;
    margin-left: 0;
    border-width: 1px;
    opacity: 1;
    visibility: visible;
}

.btn-song-clear:hover {
    color: var(--text-primary);
    border-color: var(--cyan);
}

.song-search-status {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.song-search-status[hidden] {
    display: none;
}

.song-search-results {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 320px;
    overflow-y: auto;
}

.song-search-results:empty {
    display: none;
}

.song-result {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    text-align: left;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.45rem;
    color: var(--text-primary);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition);
}

.song-result:hover,
.song-result:focus-visible {
    border-color: var(--cyan);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.05);
}

.song-result.best {
    border-color: var(--border-accent);
}

.song-result-thumb {
    width: 96px;
    aspect-ratio: 16 / 9;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 6px;
    background: var(--bg-tertiary);
}

.song-result-info {
    flex: 1;
    min-width: 0;
}

.song-result-title {
    font-size: 0.86rem;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Tone nam / nữ / nam nữ đều ok, cạnh tên bài */
.song-voice {
    font-weight: 500;
    color: var(--text-secondary);
}

.lyrics-song-voice {
    margin-left: -0.45rem;
    font-size: 0.95rem;
}

.song-result-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.song-result-badge {
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--cyan);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.1);
    border: 1px solid var(--border-accent);
    border-radius: 12px;
    padding: 0.15rem 0.5rem;
}

.song-search-divider {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.9rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.song-search-divider::before,
.song-search-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border-subtle);
}

.url-input-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.url-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: var(--transition);
    overflow: hidden;
}

.url-input-wrapper:focus-within {
    border-color: var(--cyan);
    box-shadow: 0 0 15px var(--cyan-glow);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.03);
}

.url-icon {
    padding: 0 0.85rem;
    font-size: 1.1rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

.url-text-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.92rem;
    padding: 0.85rem 0;
    outline: none;
    font-family: var(--font-sans);
}

.url-text-input::placeholder {
    color: var(--text-muted);
    font-size: 0.84rem;
}

.url-clear-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0 0.85rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
}

.url-clear-btn:hover {
    color: var(--rose);
}

.url-actions-row {
    display: flex;
    gap: 0.6rem;
}

.btn-paste {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-paste:hover {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.08);
    color: var(--text-primary);
    border-color: rgba(var(--fg-rgb, 255, 255, 255), 0.2);
}

.btn-fetch-analyze {
    flex: 1;
    background: linear-gradient(135deg, #ef4444, var(--purple));
    border: none;
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: var(--font-display);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(var(--red-rgb, 239, 68, 68), 0.35);
}

.btn-fetch-analyze:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 22px rgba(var(--red-rgb, 239, 68, 68), 0.5);
    background: linear-gradient(135deg, var(--rose), #9333ea);
}

.btn-fetch-analyze:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(var(--fg-rgb, 255, 255, 255), 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.supported-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 1.25rem;
}

.platform-tag {
    font-size: 0.73rem;
    padding: 0.22rem 0.6rem;
    border-radius: 12px;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.04);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 500;
    transition: var(--transition);
}

.platform-tag:hover {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.08);
}

.platform-tag.yt-tag {
    border-color: rgba(var(--red-rgb, 239, 68, 68), 0.35);
    color: var(--red-hi, #fca5a5);
    background: rgba(var(--red-rgb, 239, 68, 68), 0.08);
}

.platform-tag.sc-tag {
    border-color: rgba(var(--orange-rgb, 249, 115, 22), 0.35);
    color: var(--orange-hi, #fdba74);
    background: rgba(var(--orange-rgb, 249, 115, 22), 0.08);
}

.platform-tag.direct-tag {
    border-color: rgba(var(--emerald-rgb, 16, 185, 129), 0.35);
    color: var(--emerald-hi, #6ee7b7);
    background: rgba(var(--emerald-rgb, 16, 185, 129), 0.08);
}

.platform-tag.more-tag {
    border-color: rgba(var(--accent-rgb, 0, 240, 255), 0.35);
    color: var(--sky, #7dd3fc);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.08);
}

.dropzone {
    border: 2px dashed rgba(var(--fg-rgb, 255, 255, 255), 0.15);
    border-radius: var(--radius-md);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: rgba(var(--shadow-rgb, 0, 0, 0), 0.15);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--cyan);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.03);
}

.dropzone-icon {
    font-size: 2.5rem;
    color: var(--cyan);
    margin-bottom: 0.75rem;
}

.dropzone-text {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.dropzone-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Recorder UI */
.recorder-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

#recorderCanvas {
    width: 100%;
    height: 80px;
    margin-bottom: 1rem;
}

.recorder-time {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.recorder-controls {
    display: flex;
    gap: 1rem;
}

.rec-btn {
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
}

.rec-btn.record-start {
    background: var(--rose);
    color: #fff;
    box-shadow: 0 0 15px rgba(var(--rose-rgb, 244, 63, 94), 0.4);
}

.rec-btn.record-stop {
    background: var(--bg-tertiary);
    color: #fff;
    border: 1px solid var(--border-subtle);
}

/* Demo presets bar */
.demo-presets-card {
    grid-column: 1 / -1;
    padding: 1.25rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.presets-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.preset-pills {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.preset-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.preset-btn:hover {
    border-color: var(--purple);
    background: rgba(var(--purple-rgb, 139, 92, 246), 0.15);
}

/* Processing Modal / Overlay */
.processing-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(var(--deep-rgb, 8, 11, 17), 0.85);
    backdrop-filter: blur(10px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.processing-overlay.active {
    display: flex;
}

.processing-modal {
    width: 480px;
    padding: 2.5rem;
    text-align: center;
}

.proc-progress-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    margin-bottom: 1.5rem;
}

.proc-percent-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 90px;
    padding: 0.4rem 1.2rem;
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.08);
    border: 1.5px solid rgba(var(--accent-rgb, 0, 240, 255), 0.35);
    border-radius: 999px;
    box-shadow: 0 0 20px rgba(var(--accent-rgb, 0, 240, 255), 0.25), inset 0 0 12px rgba(var(--accent-rgb, 0, 240, 255), 0.12);
}

.proc-percent-val {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--cyan);
    letter-spacing: 0.5px;
    text-shadow: 0 0 16px rgba(var(--accent-rgb, 0, 240, 255), 0.6);
    font-variant-numeric: tabular-nums;
}

.proc-progress-bar-track {
    width: 100%;
    height: 8px;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.08);
    border: 1px solid rgba(var(--accent-rgb, 0, 240, 255), 0.2);
    border-radius: 999px;
    overflow: hidden;
}

.proc-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--sky, #38bdf8), var(--cyan));
    box-shadow: 0 0 12px rgba(var(--accent-rgb, 0, 240, 255), 0.65);
    border-radius: 999px;
    transition: width 0.35s ease;
}

.proc-title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.proc-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.pipeline-steps {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    text-align: left;
    counter-reset: step;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    counter-increment: step;
}

/* Số thứ tự chỉ đếm các bước đang hiện (bước tải bị ẩn khi phân tích lại bài đã có) */
.step-icon + span::before {
    content: counter(step) ". ";
}

.step-item.done {
    color: var(--emerald);
}

.step-item.active {
    color: var(--cyan);
    font-weight: 600;
}

.step-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    font-size: 0.75rem;
}

.step-item.done .step-icon {
    background: rgba(var(--emerald-rgb, 16, 185, 129), 0.2);
    color: var(--emerald);
}

.step-item.active .step-icon {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.2);
    color: var(--cyan);
    box-shadow: 0 0 10px var(--cyan-glow);
}

/* ========================================================
   SECTION: ALPHATAB STUDIO & PLAYER
   ======================================================== */
.player-workspace {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Dynamic Chord Banner */
.chord-banner {
    padding: 1.25rem 2rem;
    display: grid;
    grid-template-columns: 200px 1fr 180px;
    gap: 1.5rem;
    align-items: center;
}

@media (max-width: 900px) {
    .chord-banner { grid-template-columns: 1fr; }
}

.current-chord-card {
    display: flex;
    flex-direction: column;
}

.chord-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.chord-tone-tag {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--amber);
    background: rgba(var(--amber-rgb, 245, 158, 11), 0.15);
    border: 1px solid rgba(var(--amber-rgb, 245, 158, 11), 0.35);
    padding: 1px 7px;
    border-radius: 10px;
    letter-spacing: 0.3px;
}

.chord-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 700;
}

.active-chord-name {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--amber);
    text-shadow: 0 0 20px var(--amber-glow);
}

.next-chord-pill {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Chord Progression Timeline */
.timeline-scroll-wrap {
    overflow-x: auto;
    padding-bottom: 6px;
}

.chord-timeline {
    display: flex;
    gap: 6px;
    min-width: 100%;
}

.timeline-chord-block {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.85rem;
    min-width: 70px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.timeline-chord-block:hover {
    border-color: var(--amber);
    background: rgba(var(--amber-rgb, 245, 158, 11), 0.1);
}

.timeline-chord-block.active {
    background: linear-gradient(135deg, rgba(var(--amber-rgb, 245, 158, 11), 0.25), rgba(var(--amber-rgb, 245, 158, 11), 0.1));
    border-color: var(--amber);
    box-shadow: 0 0 12px var(--amber-glow);
}

.t-chord-name {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
}

.t-chord-time {
    font-size: 0.68rem;
    color: var(--text-muted);
}

/* Chord SVG Mini Diagram Box */
.chord-diagram-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chord-diagram-svg {
    width: 120px;
    height: 120px;
}

/* ========================================================
   SECTION: PLAYER TOOLBAR (PLACED BEFORE LYRICS)
   ======================================================== */
.player-toolbar {
    padding: 0.8rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: rgba(var(--panel-rgb, 15, 23, 42), 0.85);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.08);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(var(--shadow-rgb, 0, 0, 0), 0.3);
}

/* One row per area: playback · guitar accompaniment · tempo, tone, capo */
.toolbar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.toolbar-row + .toolbar-row {
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-subtle);
}

/* Top-right button: folds the toolbar to its playback row; that row keeps clear of it */
.player-toolbar {
    position: relative;
}

.toolbar-collapse-btn {
    position: absolute;
    top: calc(0.8rem + 9px);    /* centred on the 46px play button */
    right: 0.5rem;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(var(--shadow-rgb, 0, 0, 0), 0.18);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.toolbar-collapse-btn:hover {
    border-color: var(--cyan);
    color: var(--cyan);
}

.toolbar-collapse-btn .icon {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

.toolbar-collapse-btn + .toolbar-row {
    margin-right: 24px;
}

.player-toolbar.collapsed .toolbar-row + .toolbar-row {
    display: none;
}

.player-toolbar.collapsed .toolbar-collapse-btn .icon {
    transform: rotate(180deg);
}

/* Same height for every control of a row */
.toolbar-row .select-control,
.toolbar-row .volume-group,
.toolbar-row .time-display {
    height: 32px;
}

.toolbar-row .select-control {
    padding: 0 0.6rem;
    font-size: 0.8rem;
}

/* Variant labels carry the strokes as arrows: keep the closed select narrow, the open list shows them in full */
#accompVariantSelect {
    max-width: 250px;
}

.tool-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

.tool-btn:hover {
    border-color: var(--cyan);
    color: var(--cyan);
    transform: scale(1.05);
}

.tool-btn.play-btn {
    background: linear-gradient(135deg, var(--cyan), var(--accent-2, #0284c7));
    color: var(--on-accent, #050b14);
    width: 46px;
    height: 46px;
    box-shadow: 0 0 16px var(--cyan-glow);
}

.tool-btn.replay-btn {
    background: var(--bg-tertiary);
    color: var(--cyan);
}

.time-display {
    font-family: var(--font-mono);
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 0 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
}

/* Tone (Cao độ bài hát): khác tone gốc thì nổi màu */
.tone-select.shifted {
    background: rgba(var(--amber-rgb, 245, 158, 11), 0.18);
    color: var(--amber);
    border-color: var(--amber);
}

.btn-easy-chords {
    background: linear-gradient(135deg, rgba(var(--emerald-rgb, 16, 185, 129), 0.15), rgba(var(--accent-rgb, 0, 240, 255), 0.15));
    border: 1px solid rgba(var(--emerald-rgb, 16, 185, 129), 0.45);
    color: var(--emerald);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-easy-chords:hover {
    border-color: var(--emerald);
    background: rgba(var(--emerald-rgb, 16, 185, 129), 0.25);
    box-shadow: 0 0 12px rgba(var(--emerald-rgb, 16, 185, 129), 0.35);
    transform: translateY(-1px);
}

.btn-easy-chords.active {
    background: linear-gradient(135deg, var(--emerald), #059669);
    color: var(--on-accent, #04121a);
    border-color: var(--emerald-hi, #34d399);
    box-shadow: 0 0 14px rgba(var(--emerald-rgb, 16, 185, 129), 0.5);
    font-weight: 800;
}

.btn-easy-chords.active {
    background: linear-gradient(135deg, var(--emerald), #059669);
    color: var(--on-accent, #04121a);
    border-color: var(--emerald-hi, #34d399);
    box-shadow: 0 0 14px rgba(var(--emerald-rgb, 16, 185, 129), 0.5);
    font-weight: 800;
}

/* Round on/off buttons (Đệm guitar, Gõ nhịp): dim when off, lit when on, pulsing while the guitar samples load */
.tool-btn.toggle-btn {
    color: var(--text-muted);
}

.tool-btn.toggle-btn.active {
    background: linear-gradient(135deg, rgba(var(--emerald-rgb, 16, 185, 129), 0.25), rgba(var(--accent-rgb, 0, 240, 255), 0.2));
    border-color: var(--emerald);
    color: var(--emerald-hi, #34d399);
    box-shadow: 0 0 12px rgba(var(--emerald-rgb, 16, 185, 129), 0.4);
}

.tool-btn.toggle-btn.busy {
    animation: toggle-busy 0.9s ease-in-out infinite alternate;
}

@keyframes toggle-busy {
    from { opacity: 1; }
    to { opacity: 0.45; }
}

.tool-btn.toggle-btn.active .metro-icon {
    display: inline-block;
    animation: metro-tick 0.5s infinite alternate ease-in-out;
}

@keyframes metro-tick {
    0% { transform: rotate(-10deg); }
    100% { transform: rotate(10deg); }
}

.export-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    text-decoration: none;
}

.btn-secondary:hover {
    border-color: var(--cyan);
    color: var(--cyan);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.08);
}

/* ========================================================
   SECTION: SYNCHRONIZED FULL-CANVAS LYRICS & LEAD SHEET
   ======================================================== */
.lyrics-banner.expanded-leadsheet {
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    background: linear-gradient(180deg, rgba(var(--panel-rgb, 17, 24, 43), 0.9) 0%, rgba(var(--deep-rgb, 9, 13, 24), 0.98) 100%);
    border: 1px solid rgba(var(--purple-rgb, 139, 92, 246), 0.28);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(var(--shadow-rgb, 0, 0, 0), 0.45);
    position: relative;
    overflow: hidden;
    min-height: 480px;

    /* Scalable font variables for Lead Sheet */
    --leadsheet-word-size: 1.22rem;
    --leadsheet-chord-size: 0.92rem;
    --leadsheet-line-gap: 1rem;
}

/* Font Size Modifiers */
.lyrics-banner.font-sm {
    --leadsheet-word-size: 1.05rem;
    --leadsheet-chord-size: 0.82rem;
    --leadsheet-line-gap: 0.75rem;
}
.lyrics-banner.font-md {
    --leadsheet-word-size: 1.22rem;
    --leadsheet-chord-size: 0.92rem;
    --leadsheet-line-gap: 1rem;
}
.lyrics-banner.font-lg {
    --leadsheet-word-size: 1.55rem;
    --leadsheet-chord-size: 1.12rem;
    --leadsheet-line-gap: 1.25rem;
}
.lyrics-banner.font-xl {
    --leadsheet-word-size: 1.9rem;
    --leadsheet-chord-size: 1.35rem;
    --leadsheet-line-gap: 1.5rem;
}

.lyrics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.08);
}

.lyrics-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.lyrics-song-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    max-width: 380px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Live Whisper progress pill (shown while lyrics stream in) */
.lyrics-progress {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--purple);
    background: rgba(var(--purple-rgb, 139, 92, 246), 0.15);
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid rgba(var(--purple-rgb, 139, 92, 246), 0.35);
    animation: lyricsProgressPulse 1.6s ease-in-out infinite;
}

.lyrics-progress[hidden] {
    display: none;
}

@keyframes lyricsProgressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.lyrics-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.lyrics-font-tools {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.04);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.lyrics-font-tools .tool-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-right: 2px;
}

.btn-tool-sm {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-tool-sm:hover {
    color: var(--cyan);
    border-color: var(--cyan);
}

.font-level-indicator {
    font-size: 0.72rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
}

.lyrics-action-btn {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.04);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 5px;
}

.lyrics-action-btn:hover {
    color: var(--text-primary);
    border-color: var(--cyan);
}

.lyrics-action-btn:disabled {
    opacity: 0.4;
    cursor: default;
    color: var(--text-secondary);
    border-color: var(--border-subtle);
}

/* Dragging a chord to another word */
.ls-chord-anchor {
    cursor: grab;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body.chord-dragging,
body.chord-dragging * {
    cursor: grabbing !important;
}

.leadsheet-word-box.drag-source {
    opacity: 0.4;
}

.leadsheet-word-box.drop-ok {
    outline: 2px dashed var(--emerald);
    outline-offset: 2px;
    border-radius: 6px;
    background: rgba(var(--emerald-rgb, 16, 185, 129), 0.1);
}

.leadsheet-word-box.drop-bad {
    outline: 2px dashed rgba(var(--rose-rgb, 244, 63, 94), 0.55);
    outline-offset: 2px;
    border-radius: 6px;
}

.chord-drag-ghost {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    transform: translate(-50%, calc(-100% - 14px));
    padding: 5px 11px;
    border-radius: 8px;
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.92);
    color: var(--on-accent, #0f172a);
    font-weight: 800;
    font-size: 0.85rem;
    white-space: nowrap;
    box-shadow: 0 8px 22px rgba(var(--shadow-rgb, 0, 0, 0), 0.5);
}

.chord-drag-ghost.bad {
    background: rgba(var(--rose-rgb, 244, 63, 94), 0.92);
    color: #fff;
}

/* On/off switches of the lyrics panel (Thế bấm, Cuộn): a pill with the label and a small sliding switch */
.pill-switch {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 5px 4px 11px;
    border-radius: 999px;
    border: 1px solid var(--border-subtle);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.04);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.pill-switch:hover {
    color: var(--text-primary);
    border-color: var(--cyan);
}

.pill-switch.active {
    color: var(--cyan);
    border-color: rgba(var(--accent-rgb, 0, 240, 255), 0.45);
}

/* Icon in place of the label on a phone (the phone block below); the title names the switch */
.pill-switch .pill-icon {
    display: none;
}

.pill-switch-track {
    position: relative;
    width: 26px;
    height: 15px;
    border-radius: 999px;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.18);
    transition: background 0.2s;
}

.pill-switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: transform 0.2s, background 0.2s;
}

.pill-switch.active .pill-switch-track {
    background: var(--cyan);
}

.pill-switch.active .pill-switch-track::after {
    transform: translateX(11px);
    background: var(--on-accent, #050b14);
}

/* Spotlight Karaoke Bar (Active Live Singing Line) */
.lyrics-karaoke-box {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.03);
    border: 1px solid rgba(var(--accent-rgb, 0, 240, 255), 0.18);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    transition: all 0.25s ease;
}

.lyrics-karaoke-box.collapsed {
    display: none;
}

.lyric-placeholder-text {
    font-family: var(--font-display);
    font-size: 1.15rem;
    color: var(--text-muted);
}

.active-lyric-lead {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem 0.85rem;
    min-height: 52px;
}

.lyric-token-cell {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 3px 6px;
    border-radius: 6px;
    transition: all 0.15s ease-out;
    cursor: pointer;
}

.lyric-token-cell:hover {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
}

.token-word {
    font-family: var(--font-display);
    font-size: 1.55rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-strong, #fff);
    text-shadow: 0 0 16px rgba(var(--fg-rgb, 255, 255, 255), 0.2);
    transition: all 0.15s ease-out;
}

.token-chord {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--amber);
    min-height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 7px;
    border-radius: 4px;
    background: rgba(var(--amber-rgb, 245, 158, 11), 0.15);
    border: 1px solid rgba(var(--amber-rgb, 245, 158, 11), 0.35);
    margin-top: 3px;
    letter-spacing: 0.5px;
    transition: all 0.15s ease-out;
}

.token-chord.empty {
    visibility: hidden;
    background: transparent;
    border-color: transparent;
}

.lyric-token-cell.active-word {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.12);
    transform: scale(1.08);
}

.lyric-token-cell.active-word .token-word {
    color: var(--cyan);
    text-shadow: 0 0 20px var(--cyan-glow);
}

.lyric-token-cell.active-word .token-chord {
    color: var(--on-accent, #000);
    background: var(--amber);
    border-color: var(--amber);
    box-shadow: 0 0 14px var(--amber-glow);
    font-weight: 900;
}

.active-phrase-chords {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.phrase-chord-label {
    font-weight: 600;
    color: var(--text-secondary);
}

.phrase-chord-pill {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--cyan);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.12);
    border: 1px solid rgba(var(--accent-rgb, 0, 240, 255), 0.3);
    padding: 2px 8px;
    border-radius: 4px;
    transition: var(--transition);
}

.phrase-chord-pill.active {
    background: var(--cyan);
    color: var(--on-accent, #000);
    box-shadow: 0 0 10px var(--cyan-glow);
}

.next-lyric-lead {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.88rem;
    color: var(--text-muted);
    border-top: 1px dashed rgba(var(--fg-rgb, 255, 255, 255), 0.08);
    padding-top: 6px;
}

.next-lyric-text {
    font-weight: 500;
}

.next-lyric-chords {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--amber);
}

/* ========================================================
   SECTION: EXPANSIVE FULL SONG LEAD SHEET (CHORDS OVER LYRICS)
   ======================================================== */
.leadsheet-full-canvas {
    display: flex;
    flex-direction: column;
    gap: var(--leadsheet-line-gap);
    max-height: 580px;
    overflow-y: auto;
    margin: 0 -2rem;   /* edge to edge across the banner's 2rem sides: a highlighted line has no gap left or right */
    scroll-behavior: smooth;
}

/* Custom Scrollbar for Lead Sheet */
.leadsheet-full-canvas::-webkit-scrollbar {
    width: 6px;
}
.leadsheet-full-canvas::-webkit-scrollbar-track {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.02);
    border-radius: 4px;
}
.leadsheet-full-canvas::-webkit-scrollbar-thumb {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.25);
    border-radius: 4px;
}
.leadsheet-full-canvas::-webkit-scrollbar-thumb:hover {
    background: var(--cyan);
}

.leadsheet-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    padding: 5rem 2rem;
    color: var(--text-muted);
    font-size: 1.05rem;
    font-style: italic;
    text-align: center;
}

.leadsheet-empty-state span {
    font-size: 2.8rem;
}

/* Each Verse / Chorus Phrase Row */
/* Dạo đầu: the intro's chords on their own line above the lyrics (not a lyric row), starting where the lyrics do.
   No words under them: they sit in the line, not floated above an empty word */
.leadsheet-intro-row {
    display: flex;
    align-items: center;
    padding: 0.75rem 3.15rem 0.75rem 5.4rem;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.015);
    cursor: pointer;
}

.leadsheet-intro-row .leadsheet-line-flow,
.hide-diagrams .leadsheet-intro-row .leadsheet-line-flow { align-items: center; padding-top: 0; row-gap: 6px; }
.leadsheet-intro-row .leadsheet-word-box.chord-only,
.hide-diagrams .leadsheet-intro-row .leadsheet-word-box.chord-only { min-width: 0; }
.leadsheet-intro-row .ls-chord-anchor { position: static; transform: none; }
.leadsheet-intro-row .ls-chord-anchor:hover { transform: translateY(-2px) scale(1.05); }
.leadsheet-intro-row .ls-word { display: none; }

.leadsheet-row {
    position: relative;
    display: flex;
    align-items: flex-start;
    padding: 0.75rem 3.15rem 0.75rem 5.4rem;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.015);
    transition: background 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.leadsheet-row:hover {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.045);
}

.leadsheet-row.active-line {
    background: linear-gradient(90deg, rgba(var(--accent-rgb, 0, 240, 255), 0.12), rgba(var(--purple-rgb, 139, 92, 246), 0.05));
    box-shadow: 0 0 24px rgba(var(--accent-rgb, 0, 240, 255), 0.09);
}

.leadsheet-row.preparing-line {
    background: linear-gradient(90deg, rgba(var(--amber-rgb, 245, 158, 11), 0.12), rgba(var(--accent-rgb, 0, 240, 255), 0.03)) !important;
    box-shadow: 0 0 22px rgba(var(--amber-rgb, 245, 158, 11), 0.18) !important;
}

/* 3-2-1 Countdown Badge - Fixed position at left, single number 3 -> 2 -> 1, never shifts text */
.leadsheet-countdown-slot {
    position: absolute;
    left: 2.85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 5;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    border: 1.5px solid rgba(var(--fg-rgb, 255, 255, 255), 0.15);
}

.leadsheet-row.preparing-line .leadsheet-countdown-slot {
    opacity: 1;
}

.cd-num-single {
    font-family: var(--font-display), var(--font-mono), sans-serif;
    font-size: 1.15rem;
    font-weight: 900;
    line-height: 1;
    display: inline-block;
    transition: transform 0.1s ease;
}

.cd-num-single.num-pop {
    animation: cdNumberPop 0.26s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cdNumberPop {
    0% { transform: scale(0.4); opacity: 0.2; }
    55% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Number 3: Gold / Amber */
.leadsheet-countdown-slot[data-cd="3"] {
    background: rgba(var(--amber-rgb, 245, 158, 11), 0.22);
    border: 2px solid var(--amber);
    box-shadow: 0 0 16px rgba(var(--amber-rgb, 245, 158, 11), 0.7);
}
.leadsheet-countdown-slot[data-cd="3"] .cd-num-single {
    color: var(--amber-hi, #fbbf24);
}

/* Number 2: Vivid Orange */
.leadsheet-countdown-slot[data-cd="2"] {
    background: rgba(var(--orange-rgb, 249, 115, 22), 0.24);
    border: 2px solid #f97316;
    box-shadow: 0 0 16px rgba(var(--orange-rgb, 249, 115, 22), 0.7);
}
.leadsheet-countdown-slot[data-cd="2"] .cd-num-single {
    color: var(--orange-hi, #fb923c);
}

/* Number 1: Electric Cyan */
.leadsheet-countdown-slot[data-cd="1"] {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.22);
    border: 2px solid var(--cyan);
    box-shadow: 0 0 20px rgba(var(--accent-rgb, 0, 240, 255), 0.9);
}
.leadsheet-countdown-slot[data-cd="1"] .cd-num-single {
    color: var(--cyan);
}

.leadsheet-line-flow {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    column-gap: 0.35rem; /* Tự nhiên, không bị dãn chữ */
    row-gap: 82px;       /* Đủ khoảng trống cho thế bấm + hợp âm khi xuống dòng */
    padding-top: 80px;   /* Đủ khoảng trống cho thế bấm + hợp âm dòng đầu */
    flex: 1;
    transition: padding-top 0.2s ease, row-gap 0.2s ease;
}

.hide-diagrams .leadsheet-line-flow {
    padding-top: 34px;
    row-gap: 36px;
}

/* Individual Word Box: Chiều rộng thuần túy theo độ rộng của chữ, KHÔNG BỊ KÉO DÃN */
.leadsheet-word-box {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    position: relative;
    padding: 0 1px;
    margin: 0;
    border-radius: 4px;
    transition: background 0.15s ease;
    cursor: pointer;
    vertical-align: bottom;
    width: fit-content;
}

.leadsheet-word-box:hover {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.08);
}

.leadsheet-word-box.no-chord {
    padding-bottom: 0;
}

/* Chord Anchor: Thế bấm ở TRÊN, tên hợp âm ở DƯỚI.
   Position absolute ở phía trên chữ -> KHÔNG LÀM DÃN CHỮ CỦA LỜI BÀI HÁT */
.ls-chord-anchor {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column; /* Thế bấm ở trên, tên hợp âm ở dưới */
    align-items: center;
    gap: 3px;
    margin-bottom: 0;
    pointer-events: auto; /* Cho phép click để mở popup chọn thế bấm thay thế */
    cursor: pointer;
    white-space: nowrap;
    z-index: 10;
    transition: transform 0.15s ease;
}

.ls-chord-anchor:hover {
    transform: translateX(-50%) translateY(-2px) scale(1.05);
}

.ls-chord-anchor:hover .mini-chord-svg {
    border-color: var(--cyan) !important;
    box-shadow: 0 0 14px rgba(var(--accent-rgb, 0, 240, 255), 0.55), 0 4px 12px rgba(var(--shadow-rgb, 0, 0, 0), 0.75) !important;
}

.ls-chord-anchor:hover .ls-chord {
    border-color: var(--cyan) !important;
    color: var(--cyan) !important;
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.22) !important;
    box-shadow: 0 0 12px rgba(var(--accent-rgb, 0, 240, 255), 0.45) !important;
}

/* Mini Guitar Chord Finger Diagram: Thế bấm ở phía trên của hợp âm */
.ls-chord-diagram-mini {
    display: inline-block;
    line-height: 0;
    margin-bottom: 1px;
    transition: transform 0.18s ease;
}

.mini-chord-svg {
    box-shadow: 0 3px 10px rgba(var(--shadow-rgb, 0, 0, 0), 0.65);
    border-radius: 4px;
    display: block;
    transition: all 0.15s ease;
}

.leadsheet-word-box:hover .ls-chord-diagram-mini {
    transform: translateY(-2px);
}

/* Toggle Hide Diagrams */
.hide-diagrams .ls-chord-diagram-mini {
    display: none !important;
}

/* A chord with no word under it (chord change between words, after a line, intro): as wide as the diagram / chord
   name above it (they are centered over the box), so several in a row don't overlap */
.leadsheet-word-box.chord-only {
    min-width: 86px;
}

.hide-diagrams .leadsheet-word-box.chord-only {
    min-width: 3.4rem;
}

/* Tên hợp âm: Nằm ngay dưới thế bấm và ngay phía trên chữ */
.ls-chord {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 850;
    color: var(--amber);
    line-height: 1;
    padding: 2.5px 7px;
    border-radius: 4px;
    background: rgba(var(--amber-rgb, 245, 158, 11), 0.18);
    border: 1px solid rgba(var(--amber-rgb, 245, 158, 11), 0.45);
    letter-spacing: 0.3px;
    transition: all 0.15s ease;
    user-select: none;
    text-align: center;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(var(--shadow-rgb, 0, 0, 0), 0.4);
}

.ls-chord.empty {
    visibility: hidden;
    background: transparent;
    border-color: transparent;
}

/* Word on Bottom - Progressive left-to-right karaoke wipe */
.ls-word {
    font-family: var(--font-display);
    font-size: var(--leadsheet-word-size);
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    display: inline-block;
    position: relative;
    --wipe-pct: 0%;
    /* Gradient: cyan fills from left to right as word is sung, remaining part stays gray */
    background: linear-gradient(
        to right,
        var(--cyan) 0%,
        var(--cyan) var(--wipe-pct, 0%),
        var(--slate, #8492a6) calc(var(--wipe-pct, 0%) + 1.2%),
        var(--slate, #8492a6) 100%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    user-select: none;
    transition: none; /* No lag: updates at 60fps/120fps with audio loop */
    text-shadow: none !important;
    filter: none !important;
}

/* Fallback for browsers that don't support text background-clip */
@supports not (-webkit-background-clip: text) {
    .ls-word {
        color: var(--slate, #8492a6);
    }
    .leadsheet-word-box.word-reached .ls-word,
    .leadsheet-row.line-past .ls-word {
        color: var(--cyan);
    }
}

/* Từ chưa hát tới: 100% màu xám */
.leadsheet-word-box.word-upcoming .ls-word {
    --wipe-pct: 0%;
}

/* Từ đã hát qua hoặc cả câu đã hát qua: 100% màu xanh */
.leadsheet-word-box.word-reached .ls-word,
.leadsheet-row.line-past .ls-word {
    --wipe-pct: 100%;
}

/* Chord pill highlight: the word being sung, and the chord still playing after its word (flat, no glow) */
.leadsheet-word-box.word-current .ls-chord,
.leadsheet-word-box.chord-playing .ls-chord {
    background: var(--amber);
    color: var(--on-accent, #000);
    font-weight: 900;
    border-color: var(--amber);
}

/* AlphaTab Score Container (Hidden) */
.alphatab-wrapper {
    display: none !important;
}

/* Rhythm: meter select + style select */
.rhythm-control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rhythm-saved {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--emerald-hi, #34d399);
    white-space: nowrap;
}

/* Preview đệm guitar: small card above the right end of the lyric line being sung */
.accomp-preview {
    position: fixed;
    z-index: 500;   /* above the header, below overlays and dialogs */
    width: 512px;
    max-width: calc(100vw - 16px);
    padding: 8px 10px 6px;
    border-radius: var(--radius-md);
    background: rgba(var(--deep-rgb, 10, 15, 28), 0.88);
    border: 1px solid rgba(var(--accent-rgb, 0, 240, 255), 0.28);
    box-shadow: 0 10px 28px rgba(var(--shadow-rgb, 0, 0, 0), 0.5), 0 0 18px rgba(var(--accent-rgb, 0, 240, 255), 0.08);
    backdrop-filter: blur(6px);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.accomp-preview.dragging {
    cursor: grabbing;
    border-color: rgba(var(--accent-rgb, 0, 240, 255), 0.6);
}

.accomp-preview .ap-head,
.accomp-preview .ap-foot {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    line-height: 1.2;
    white-space: nowrap;
}

.accomp-preview .ap-head {
    margin-bottom: 4px;
}

.accomp-preview .ap-mode {
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--on-accent, #0f172a);
    background: var(--text-muted);
}

.accomp-preview .ap-mode[data-kind="pick"] {
    background: var(--emerald);
}

.accomp-preview .ap-mode[data-kind="strum"] {
    background: var(--amber);
}

.accomp-preview .ap-label {
    color: var(--text-primary);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Footer: "variant : chord" */
.accomp-preview .ap-variant {
    color: var(--text-primary);
    font-weight: 800;
}

.accomp-preview .ap-chord {
    color: var(--cyan);
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 700;
}

.accomp-preview .ap-chord:not(:empty)::before {
    content: ": ";
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-weight: 600;
}

.accomp-preview .ap-canvas {
    display: block;
    width: 492px;
    max-width: 100%;
    height: auto;
}

.accomp-preview .ap-foot {
    color: var(--text-secondary);
    margin-top: 2px;
}

.accomp-preview .ap-next {
    margin-left: auto;
    color: var(--amber);
    font-weight: 600;
}

/* Volume (nhạc bài hát, guitar đệm) */
.volume-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(var(--panel-rgb, 15, 23, 42), 0.65);
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.12);
    border-radius: 8px;
    padding: 0 8px;
}

.vol-icon {
    font-size: 0.9rem;
    line-height: 1;
}

.btn-vol-mute {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    transition: transform 0.15s ease;
}

.btn-vol-mute:hover {
    transform: scale(1.18);
}

.volume-slider {
    width: 80px;
    height: 5px;
    cursor: pointer;
    accent-color: var(--sky, #38bdf8);
}

.volume-slider.accomp-volume {
    accent-color: var(--emerald);
}

.volume-group.effect-group {
    padding: 0 7px;
    gap: 5px;
}

.effect-tag {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted, #94a3b8);
    user-select: none;
    line-height: 1;
}

.volume-slider.effect-slider {
    width: 58px;
    height: 4px;
}

.volume-slider.echo-slider {
    accent-color: #38bdf8;
}

.volume-slider.reverb-slider {
    accent-color: #a855f7;
}

/* ==========================================================================
   Alternative Chord Voicings Modal (Bảng Chọn Thế Bấm Thay Thế)
   ========================================================================== */
.chord-voicings-modal-overlay {
    position: fixed;
    inset: 0;   /* not 100vw: that counts the scroll bar and set the dialog off centre */
    background: rgba(var(--deep-rgb, 3, 7, 18), 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: cvFadeIn 0.22s ease-out;
}

@keyframes cvFadeIn {
    from {
        opacity: 0;
        transform: scale(0.97);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.chord-voicings-dialog {
    max-width: 860px;
    width: 100%;
    max-height: 88vh;
    background: linear-gradient(135deg, rgba(var(--panel-rgb, 15, 23, 42), 0.95), rgba(var(--deep-rgb, 7, 12, 22), 0.97));
    border: 1.5px solid rgba(var(--accent-rgb, 0, 240, 255), 0.28);
    border-radius: 18px;
    box-shadow: 0 25px 60px rgba(var(--shadow-rgb, 0, 0, 0), 0.85), 0 0 35px rgba(var(--accent-rgb, 0, 240, 255), 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cv-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.09);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.02);
}

.cv-title-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
}

.cv-badge-icon {
    font-size: 1.85rem;
    line-height: 1;
    filter: drop-shadow(0 0 8px rgba(var(--accent-rgb, 0, 240, 255), 0.5));
}

.cv-title {
    font-size: 1.35rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.cv-subtitle {
    font-size: 0.84rem;
    color: var(--text-muted);
    margin: 3px 0 0 0;
}

.cv-close-btn {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.06);
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.14);
    color: var(--text-muted);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    transition: all 0.18s ease;
}

.cv-close-btn:hover {
    background: rgba(var(--rose-rgb, 244, 63, 94), 0.2);
    border-color: var(--rose);
    color: var(--rose);
    transform: rotate(90deg);
}

.cv-dialog-body {
    padding: 22px 24px;
    overflow-y: auto;
    flex: 1;
}

.cv-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}

/* Individual Voicing Card */
.cv-voicing-card {
    background: rgba(var(--panel-rgb, 15, 23, 42), 0.65);
    border: 1.5px solid rgba(var(--fg-rgb, 255, 255, 255), 0.12);
    border-radius: 14px;
    padding: 16px 14px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    user-select: none;
}

.cv-voicing-card:hover {
    transform: translateY(-4px);
    border-color: rgba(var(--accent-rgb, 0, 240, 255), 0.55);
    background: rgba(var(--panel-rgb, 15, 23, 42), 0.85);
    box-shadow: 0 12px 28px rgba(var(--shadow-rgb, 0, 0, 0), 0.6), 0 0 18px rgba(var(--accent-rgb, 0, 240, 255), 0.2);
}

/* ACTIVE STATE: Viền sáng cyan, phát sáng rõ rệt */
.cv-voicing-card.active {
    border: 2px solid var(--cyan) !important;
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.08) !important;
    box-shadow: 0 0 26px rgba(var(--accent-rgb, 0, 240, 255), 0.42), inset 0 0 18px rgba(var(--accent-rgb, 0, 240, 255), 0.14) !important;
    transform: translateY(-2px);
}

.cv-card-top-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.cv-card-title {
    font-size: 0.94rem;
    font-weight: 800;
    color: var(--amber);
}

.cv-card-badge {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 2.5px 8px;
    border-radius: 20px;
    letter-spacing: 0.3px;
    transition: all 0.18s ease;
}

.cv-voicing-card.active .cv-card-badge {
    background: var(--cyan);
    color: var(--on-accent, #040810);
    box-shadow: 0 0 10px rgba(var(--accent-rgb, 0, 240, 255), 0.7);
}

.cv-voicing-card:not(.active) .cv-card-badge {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.07);
    color: var(--text-muted);
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.12);
}

.cv-card-diagram-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 6px 0 12px;
}

.modal-chord-svg {
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(var(--shadow-rgb, 0, 0, 0), 0.75);
    display: block;
    max-width: 100%;
    height: auto;
}

.cv-card-bottom {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: auto;
}

.cv-card-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cv-card-action-btn {
    width: 100%;
    margin-top: 8px;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: all 0.18s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.cv-voicing-card.active .cv-card-action-btn {
    background: var(--cyan);
    color: var(--on-accent, #040810);
    box-shadow: 0 0 12px rgba(var(--accent-rgb, 0, 240, 255), 0.55);
}

.cv-voicing-card:not(.active) .cv-card-action-btn {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.08);
    color: var(--text-main);
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.15);
}

.cv-voicing-card:not(.active):hover .cv-card-action-btn {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.2);
    border-color: var(--cyan);
    color: var(--cyan);
}

.cv-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-top: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.09);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.02);
}

.cv-hint-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 7px;
}


/* Chord editor: root / quality chips, delete, replace everywhere */
.cv-chord-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}

.cv-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cv-chip {
    min-width: 40px;
    padding: 5px 10px;
    border-radius: 8px;
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.14);
    background: rgba(var(--panel-rgb, 15, 23, 42), 0.7);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.cv-chip:hover {
    border-color: rgba(var(--accent-rgb, 0, 240, 255), 0.5);
    color: var(--text-primary);
}

.cv-chip.active {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.16);
    border-color: var(--cyan);
    color: var(--cyan);
}

.cv-footer-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.cv-replace-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.cv-replace-all[hidden],
.cv-delete-btn[hidden] {
    display: none;
}


.cv-dialog-footer {
    gap: 12px;
    flex-wrap: wrap;
}



/* Song library ("Lịch sử") */
.history-panel {
    scroll-margin-top: 90px;   /* the next page scrolls the list's top in under the sticky header, not behind it */
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.65rem;
}

.history-summary {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.history-filter {
    width: 100%;
    margin-bottom: 0.6rem;
}

.history-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.6rem;
}

.history-toolbar .history-filter {
    flex: 1 1 200px;
    min-width: 0;
    margin-bottom: 0;
}

.history-sort,
.history-facet {
    flex: 0 0 auto;
}

/* A facet filter in use stands out */
.history-facet.active {
    border-color: var(--cyan);
    color: var(--cyan);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.45rem;
}

.history-thumb {
    width: 96px;
    aspect-ratio: 16 / 9;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 6px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.history-btn {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.history-btn:hover:not(:disabled) {
    border-color: var(--cyan);
    color: var(--cyan);
}

.history-btn.primary {
    border-color: var(--border-accent);
    color: var(--cyan);
}

.history-btn.danger:hover:not(:disabled) {
    border-color: var(--rose);
    color: var(--rose);
}

.history-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.history-status {
    font-size: 0.68rem;
    font-weight: 700;
    border-radius: 12px;
    padding: 0.05rem 0.45rem;
    margin-right: 0.3rem;
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
}

.history-status.analyzed {
    color: var(--emerald);
    border-color: rgba(var(--emerald-rgb, 16, 185, 129), 0.4);
}

.history-status.downloaded {
    color: var(--amber);
    border-color: rgba(var(--amber-rgb, 245, 158, 11), 0.4);
}

.history-empty {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 1rem 0;
    text-align: center;
}

/* Tapping the song does its first action (open / analyze) */
.history-item.clickable {
    cursor: pointer;
    transition: var(--transition);
}

.history-item.clickable:hover {
    border-color: var(--cyan);
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.05);
}

/* Pages of 20 songs: ‹ 1 … 4 5 6 … 9 › under the list */
.history-pager {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding-top: 0.75rem;
}

.history-pager[hidden] {
    display: none;
}

.history-page-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.history-page-btn:hover:not(:disabled) {
    border-color: var(--cyan);
    color: var(--cyan);
}

.history-page-btn.current {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.14);
    border-color: rgba(var(--accent-rgb, 0, 240, 255), 0.45);
    color: var(--cyan);
}

.history-page-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.history-page-btn .icon {
    width: 16px;
    height: 16px;
}

[dir="rtl"] .history-page-btn .icon {
    transform: scaleX(-1);
}

.history-page-gap {
    min-width: 20px;
    text-align: center;
    color: var(--text-muted);
}

/* ========================================================
   Studio Processing Status Toast & Disabled Menu Controls
   ======================================================== */
/* Toast nổi góc dưới phải: trên header và preview đệm, dưới overlay xử lý và các dialog */
.studio-status-banner {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 900;
    max-width: min(380px, calc(100vw - 32px));
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.7rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--amber);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 32px rgba(var(--shadow-rgb, 0, 0, 0), 0.45);
    animation: toastIn 0.25s ease-out;
}

.studio-status-banner.completed {
    border-left-color: var(--emerald);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
    .studio-status-banner {
        left: 16px;
        right: 16px;
        bottom: 16px;
        max-width: none;
    }
}

.status-pulse-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 8px var(--amber);
    flex-shrink: 0;
    animation: dotBlink 1.2s infinite ease-in-out;
}

.studio-status-banner.completed .status-pulse-dot {
    background: var(--emerald);
    box-shadow: 0 0 8px var(--emerald);
    animation: none;
}

@keyframes dotBlink {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.85); }
}

.status-banner-text {
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
    letter-spacing: 0.2px;
}

/* Studio Controls Disabled State */
.player-toolbar.studio-disabled {
    opacity: 0.45 !important;
    pointer-events: none !important;
    filter: grayscale(0.65) !important;
    user-select: none !important;
    cursor: not-allowed !important;
    transition: opacity 0.25s ease, filter 0.25s ease;
}

.leadsheet-container.studio-disabled .ls-chord-anchor {
    pointer-events: none !important;
    cursor: not-allowed !important;
}

.leadsheet-container.studio-disabled .leadsheet-row {
    cursor: not-allowed !important;
}

/* ========================================================
   LIGHT THEME (tông gỗ guitar): page grain and chord diagrams
   ======================================================== */
:root[data-theme="light"] body {
    background-image:
        repeating-linear-gradient(91deg, rgba(110, 70, 22, 0.06) 0 1px, transparent 1px 7px),
        repeating-linear-gradient(88deg, rgba(110, 70, 22, 0.05) 0 2px, transparent 2px 19px),
        linear-gradient(180deg, #e6c88c 0%, #d6b06c 100%);
}

/* Chord diagrams like a printed chord chart: tan fretboard, dark frets and strings, black dots */
:root[data-theme="light"] .dg-board { fill: #ecd6a3; stroke: rgba(92, 64, 28, 0.35); }
:root[data-theme="light"] .dg-nut { stroke: #2a1f12; }
:root[data-theme="light"] .dg-fret { stroke: rgba(92, 64, 28, 0.45); }
:root[data-theme="light"] .dg-string { stroke: rgba(60, 40, 15, 0.6); }
.dg-dot { fill: #00f0ff; stroke: #ffffff; }
.dg-open { fill: #00f0ff; stroke: #ffffff; }
.dg-mute { stroke: #94a3b8; fill: none; }
.dg-mute circle,
.dg-mute line { stroke: #94a3b8; }
:root[data-theme="light"] .dg-dot { fill: #000000 !important; stroke: #000000 !important; filter: none !important; }
:root[data-theme="light"] .dg-open { fill: #000000 !important; stroke: #000000 !important; filter: none !important; }
:root[data-theme="light"] .dg-barre { stroke: #000000 !important; }
:root[data-theme="light"] .dg-mute { stroke: #475569 !important; fill: none; }
:root[data-theme="light"] .dg-mute circle,
:root[data-theme="light"] .dg-mute line { stroke: #475569 !important; }
:root[data-theme="light"] .dg-label { fill: #8a4b0b; }
:root[data-theme="light"] .dg-name { fill: var(--amber); }

/* ========================================================
   HEADER ACTIONS: interface language, theme, settings
   ======================================================== */
.i18n-pending body {
    visibility: hidden;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lang-picker {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px 0 10px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid var(--border-subtle);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    color: var(--text-muted);
    cursor: pointer;
}

.lang-picker:hover {
    border-color: var(--border-accent);
}

.lang-picker select {
    max-width: 150px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

.lang-picker option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.settings-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.settings-btn:hover {
    border-color: var(--border-accent);
    color: var(--cyan);
}

@media (max-width: 640px) {
    .theme-opt-text { display: none; }
    .lang-picker select { max-width: 96px; }
}

/* ========================================================
   SETTINGS DIALOG (settings.js)
   ======================================================== */
.set-overlay {
    position: fixed;
    inset: 0;
    z-index: 10060;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(var(--deep-rgb, 3, 7, 18), 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.set-overlay[hidden] {
    display: none;
}

.set-dialog {
    width: 100%;
    max-width: 1080px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(135deg, rgba(var(--panel-rgb, 15, 23, 42), 0.96), rgba(var(--deep-rgb, 7, 12, 22), 0.98));
    border: 1px solid rgba(var(--accent-rgb, 0, 240, 255), 0.25);
}

.set-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
}

.set-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-display);
    font-size: 1.15rem;
    color: var(--text-primary);
}

.set-tabs {
    display: flex;
    gap: 4px;
    padding: 3px;
    margin-right: auto;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
}

.set-tab {
    padding: 0.35rem 0.9rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.set-tab.active {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.14);
    color: var(--cyan);
}

.set-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}

.set-status {
    min-height: 1.6rem;
    padding: 0.3rem 1.25rem 0.6rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.set-status.ok { color: var(--emerald); }
.set-status.error { color: var(--rose); }

.set-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0.4rem 0 0.8rem;
}

.set-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 0.6rem 1.5rem;
}

.set-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    min-height: 36px;
}

.set-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.set-row .select-control,
.set-input {
    height: 34px;
    padding: 0 0.6rem;
    font-size: 0.82rem;
}

.set-row .set-input {
    flex: 1;
    max-width: 260px;
}

.set-input.mono {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    letter-spacing: 0.04em;
}

/* A toggle, not a tick box: the knob drawn as a gradient (Firefox draws no ::after on an input) */
.set-switch {
    appearance: none;
    -webkit-appearance: none;
    flex: none;
    width: 36px;
    height: 20px;
    margin: 0;
    border-radius: 999px;
    background: radial-gradient(circle at 10px 50%, var(--text-secondary) 6px, transparent 7px), rgba(var(--fg-rgb, 255, 255, 255), 0.18);
    cursor: pointer;
}

.set-switch:checked {
    background: radial-gradient(circle at 26px 50%, #fff 6px, transparent 7px), var(--emerald);
}

.set-switch:focus-visible {
    outline: 2px solid var(--border-accent);
    outline-offset: 2px;
}

/* Every select and slider of a row in one right-hand column of the same width */
.set-row > .select-control,
.set-row > .set-range {
    flex: none;
    width: 170px;
}

.set-range .volume-slider {
    flex: 1;
    width: auto;
    min-width: 0;
}

.set-range {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.set-range-val {
    min-width: 3em;
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.set-meters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.set-check {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
}

/* The open tab's buttons, under what scrolls (#settingsActions): on the dialog itself, no box of their own */
.set-foot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
}

.set-spacer {
    flex: 1;
}

/* In-page confirm / alert (dialogs.js), above every other dialog */
.app-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 10100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
}

.app-dialog {
    width: min(440px, 100%);
    padding: 1.25rem 1.25rem 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-accent);
    background: var(--bg-secondary);
    box-shadow: 0 16px 48px rgba(var(--shadow-rgb, 0, 0, 0), 0.5);
}

.app-dialog-text {
    margin-bottom: 1.1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-line;
}

.app-dialog-foot {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.set-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

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

.set-btn.primary {
    background: rgba(var(--accent-rgb, 0, 240, 255), 0.14);
    border-color: rgba(var(--accent-rgb, 0, 240, 255), 0.45);
    color: var(--cyan);
}

.set-btn.danger {
    color: var(--rose);
    border-color: rgba(var(--rose-rgb, 244, 63, 94), 0.4);
}

.set-btn.small {
    height: 28px;
    padding: 0 0.6rem;
    font-size: 0.78rem;
}

.set-icon-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
}

.set-icon-btn:hover { color: var(--text-primary); border-color: var(--border-accent); }
.set-icon-btn.danger:hover { color: var(--rose); border-color: rgba(var(--rose-rgb, 244, 63, 94), 0.5); }

/* Styles tab: list on the left, editor on the right */
.set-styles {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* The style to edit: picked from a list, next to "Thêm điệu" */
.set-style-pick {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.set-style-pick .select-control {
    flex: 1;
    min-width: 0;
    height: 34px;
    padding: 0 0.6rem;
    font-size: 0.85rem;
}

.set-deleted {
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-subtle);
}

.set-deleted-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.set-deleted-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--text-secondary);
    padding: 2px 0;
}

.set-section {
    margin: 1rem 0 0.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.set-rows {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.set-var {
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.02);
}

.set-var-top {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.4rem;
}

.set-var-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--amber);
    white-space: nowrap;
}

.set-var-notation {
    flex: 1;
    font-size: 0.95rem;
    letter-spacing: 0.06em;
    color: var(--text-primary);
}

.set-var-tools {
    display: flex;
    gap: 4px;
}

.set-bars {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}

.set-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.set-bar .set-input {
    flex: 1;
}

.set-bar-n {
    min-width: 3.5em;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.set-var-error {
    font-size: 0.76rem;
    color: var(--rose);
    margin-top: 2px;
}

.set-var-error:empty { display: none; }

.set-palette {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin-top: 0.8rem;
}

.set-sym {
    min-width: 30px;
    height: 30px;
    padding: 0 6px;
    border-radius: 6px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.92rem;
    cursor: pointer;
}

.set-sym:hover { border-color: var(--border-accent); color: var(--cyan); }


/* Right-to-left languages: the headstock is a picture of the guitar (bass strings on the left), never mirrored */
[dir="rtl"] .tuner-headstock {
    direction: ltr;
}

/* Times and numbers read left to right in every language ("00:42 / 04:13") */
[dir="rtl"] .time-display {
    direction: ltr;
}

/* ========================================================
   PHONES: the page stays put, the header, tabs, search and player toolbar compact at the top; only the lyrics
   scroll under them (the tuner and history tabs scroll themselves)
   ======================================================== */
@media (max-width: 768px) {
    body {
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* No backdrop-filter: it would hold the fixed tab bar inside the header instead of the screen */
    .app-header {
        flex: none;
        padding: 6px 10px;
        backdrop-filter: none;
        background: rgba(var(--deep-rgb, 10, 13, 20), 0.96);
    }

    .header-container { flex-wrap: nowrap; gap: 6px; }
    .logo-area { gap: 6px; }
    .logo-icon { width: 30px; height: 30px; font-size: 0.95rem; }
    .logo-title { font-size: 1.05rem; }
    .logo-badge { display: none; }
    .header-actions { gap: 6px; }
    .lang-picker { height: 30px; padding: 0 2px 0 8px; }
    .lang-picker select { max-width: 84px; font-size: 0.75rem; }
    .theme-opt { padding: 3px 7px; }
    .theme-opt-text { display: none; }
    .settings-btn { width: 30px; height: 30px; }

    /* The three tabs: a bar at the bottom of the screen, under the thumb */
    body { padding-bottom: 52px; }
    .nav-tabs {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        height: 52px;
        padding: 4px 6px;
        gap: 4px;
        border: none;
        border-top: 1px solid var(--border-subtle);
        border-radius: 0;
        background: rgba(var(--deep-rgb, 10, 13, 20), 0.96);
    }
    .tab-btn {
        flex: 1 1 0;
        min-width: 0;
        flex-direction: column;
        justify-content: center;
        gap: 1px;
        padding: 2px 4px;
        font-size: 0.68rem;
        line-height: 1.2;
        white-space: nowrap;
    }
    .tab-btn .icon { width: 20px; height: 20px; }
    .tab-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

    .main-content {
        flex: 1;
        min-height: 0;
        width: 100%;
        margin: 0;
        padding: 8px;   /* the lyrics end a little above the tab bar */
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    /* The studio fills exactly what is left: its lyrics scroll, nothing else */
    #studioPane.active { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
    #studioPane .player-workspace { flex: 1; min-height: 0; gap: 6px; }

    /* Tuner and Lịch sử the same way: the card fills what is left and scrolls inside, like the lyrics */
    #tunerPane.active,
    #historyPane.active { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
    #tunerPane .tuner-container,
    #historyPane .player-workspace { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; }
    .tuner-main-card { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px; }
    .tuner-main-card > * { flex-shrink: 0; }
    /* As tight as it goes: a tall phone shows it all, a short one scrolls the card */
    .tuner-header { display: none; }
    .tuner-gauge-wrap { margin-top: 12px; }
    .target-string-label { margin-top: 0; }
    .tuning-status-tag { margin-top: 8px; }
    .tuner-headstock { max-width: 330px; margin-top: 8px; }
    .tuner-hint { margin-top: 8px; }
    /* the title and filters stay, the song list scrolls */
    .history-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
    .history-panel > * { flex-shrink: 0; }
    .history-panel .history-list { flex: 1 1 0; min-height: 0; overflow-y: auto; }
    /* Lịch sử: the filters in two rows (search and sort, then the three filters), one low line per song (tap it to
       open; analyze again and delete as icons; the usual "Đã phân tích" left out), the pages under the list */
    .history-panel { padding: 10px; border-radius: var(--radius-md); }
    .history-header { flex-wrap: nowrap; margin-bottom: 8px; }
    .history-header .card-title { min-width: 0; white-space: nowrap; }
    .history-summary { flex: none; font-size: 0.72rem; }
    .history-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 8px; }
    .history-toolbar .history-filter { grid-area: 1 / 1 / 2 / 3; height: 34px; padding: 0 0.75rem; font-size: 0.85rem; }
    .history-sort { grid-area: 1 / 3; }
    .history-sort,
    .history-facet { width: 100%; min-width: 0; height: 34px; padding: 0 0.4rem; font-size: 0.78rem; }
    .history-list { gap: 6px; }
    .history-item { gap: 8px; padding: 6px; }
    .history-thumb { width: 64px; font-size: 1.1rem; }
    .history-info .song-result-title { font-size: 0.84rem; }
    .history-status.analyzed { display: none; }
    .history-actions { gap: 0; }
    .history-btn.primary { display: none; }
    .history-btn { display: inline-flex; padding: 7px; border-color: transparent; background: none; }
    .history-btn .icon { width: 18px; height: 18px; }
    .history-btn-label { display: none; }
    .history-pager { padding-top: 8px; }

    #songSearchPanel { flex: none; padding: 6px 8px; border-radius: var(--radius-md); }
    #songSearchPanel .card-title-row { display: none; }
    /* no title above: drop its spacing so the row sits centred in the panel */
    #songSearchPanel .song-search { margin-top: 0; }
    #songSearchPanel .song-search-inputs { flex-wrap: nowrap; gap: 6px; }
    /* 16px: iOS zooms into a smaller input */
    #songSearchPanel .song-search-input { flex: 1 1 0; padding: 0.35rem 0.6rem; font-size: 16px; }
    /* the song's name gets more room than the singer's (6 : 4) */
    #songSearchPanel #songQueryInput { flex: 6 1 0; }
    #songSearchPanel #songArtistInput { flex: 4 1 0; }
    .btn-song-search { padding: 0 0.7rem; }
    .btn-song-search span { display: none; }
    .btn-song-clear { margin-left: -6px; }
    .btn-song-clear.shown { width: 34px; }
    .song-search-results { max-height: 40vh; }

    /* One line per toolbar row, swiped sideways when it doesn't fit */
    .player-toolbar { flex: none; padding: 6px 8px; gap: 5px; border-radius: var(--radius-md); }
    .toolbar-row { flex-wrap: nowrap; overflow-x: auto; gap: 5px; scrollbar-width: none; }
    .toolbar-row::-webkit-scrollbar { display: none; }
    .toolbar-row + .toolbar-row { padding-top: 5px; }
    .toolbar-row > * { flex-shrink: 0; }
    .toolbar-row .select-control,
    .toolbar-row .volume-group,
    .toolbar-row .time-display { height: 30px; }
    .toolbar-row .select-control { padding: 0 0.4rem; font-size: 0.75rem; }
    .tool-btn { width: 32px; height: 32px; }
    .tool-btn.play-btn { width: 36px; height: 36px; }
    /* no hover zoom: a row that scrolls sideways clips it, and a tap leaves the hover on */
    .tool-btn:hover { transform: none; }
    .tool-btn .icon,
    .tool-btn.play-btn .icon { width: 17px; height: 17px; }
    .time-display { padding: 0 0.5rem; font-size: 0.78rem; }
    .volume-slider { width: 64px; }
    #accompVariantSelect { max-width: 150px; }
    /* centred on the 36px play button */
    .toolbar-collapse-btn { top: 11px; right: 4px; width: 26px; height: 26px; }
    .toolbar-collapse-btn + .toolbar-row { margin-right: 28px; }

    .lyrics-banner.expanded-leadsheet {
        flex: 1;
        min-height: 0;
        padding: 8px 6px 0;
        gap: 6px;
        border-radius: var(--radius-md);
    }
    /* Title and tools on one line: the title shortened with "…", the tools kept right and small (icons for the
       switches, undo only while there is something to undo, no font percentage) */
    .lyrics-header { flex: none; flex-wrap: nowrap; gap: 6px; padding-bottom: 6px; }
    .lyrics-header-left { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; gap: 4px; }
    .lyrics-song-title { flex: 0 1 auto; min-width: 0; max-width: none; font-size: 0.92rem; }
    .lyrics-song-voice { flex: none; margin-left: 0; font-size: 0.78rem; white-space: nowrap; }
    .lyrics-progress { flex: none; }
    .lyrics-actions { flex: none; margin-left: auto; flex-wrap: nowrap; gap: 4px; }
    .lyrics-action-btn { padding: 4px 7px; }
    .lyrics-action-btn:disabled { display: none; }
    .lyrics-action-btn span,
    .lyrics-font-tools .tool-label,
    .font-level-indicator { display: none; }
    .lyrics-font-tools { gap: 3px; padding: 2px 3px; }
    .lyrics-font-tools .btn-tool-sm { padding: 2px 6px; }
    .pill-switch { gap: 4px; padding: 3px 4px 3px 6px; }
    .pill-switch .pill-icon { display: inline-block; width: 16px; height: 16px; }
    .pill-switch .pill-text { display: none; }
    /* Room under the last lines: the guitar preview sits at the bottom of the screen */
    .leadsheet-full-canvas { flex: 1; min-height: 0; max-height: none; margin: 0 -6px; padding-bottom: 35vh; }

    /* Settings: nearly the whole screen, the two tabs side by side across it, the editor's fields stacking their label
       over the input */
    .set-overlay { padding: 8px; }
    .set-dialog { max-height: calc(100dvh - 16px); }
    .set-head { flex-wrap: wrap; gap: 8px; padding: 0.6rem 0.75rem; }
    .set-tabs { order: 3; width: 100%; margin-right: 0; }
    .set-tab { flex: 1; }
    .set-close { order: 2; margin-left: auto; }   /* the X stays top right, the tabs go under */
    .set-body { padding: 0.75rem; }
    .set-row > .select-control,
    .set-row > .set-range { width: 150px; }
    .set-styles { gap: 0.75rem; }
    .set-editor .set-row { flex-direction: column; align-items: stretch; gap: 4px; }
    .set-editor .set-row .set-input,
    .set-editor .set-row > .select-control { flex: none; width: 100%; max-width: none; }
    /* a pattern's arrows on their own line under its name and tools */
    .set-var-top { flex-wrap: wrap; row-gap: 4px; }
    .set-var-label { flex: 1; }
    .set-var-notation { order: 3; flex-basis: 100%; }
    .set-foot { gap: 6px; padding: 0.6rem 0.75rem; }
    .set-foot .set-btn { padding: 0 0.6rem; font-size: 0.78rem; }

    /* Chord dialog: nearly the whole screen, the notes and qualities in even grids, two thế bấm cards a row, the
       footer on two lines (replace everywhere; delete and done side by side), no hint */
    .chord-voicings-modal-overlay { padding: 8px; }
    .chord-voicings-dialog { max-height: calc(100dvh - 16px); border-radius: 14px; }
    .cv-dialog-header { gap: 8px; padding: 10px 12px; }
    .cv-title-wrap { min-width: 0; gap: 8px; }
    .cv-badge-icon { font-size: 1.3rem; }
    .cv-title { font-size: 1.05rem; }
    .cv-subtitle { font-size: 0.72rem; }
    .cv-close-btn { flex: none; }
    .cv-dialog-body { padding: 10px 12px; }
    .cv-chord-picker { gap: 4px; margin-bottom: 12px; }
    #cvRootRow { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
    #cvQualityRow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
    .cv-chip { min-width: 0; padding: 5px 2px; font-size: 0.78rem; }
    .cv-cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .cv-voicing-card { padding: 8px 6px 6px; border-radius: 10px; }
    .cv-voicing-card:hover { transform: none; }
    .cv-card-top-row { flex-wrap: wrap; gap: 3px; margin-bottom: 4px; }
    .cv-card-title { font-size: 0.78rem; }
    .cv-card-badge { padding: 1.5px 6px; font-size: 0.62rem; }
    .cv-card-diagram-wrap { margin: 2px 0 4px; }
    .cv-card-desc { font-size: 0.68rem; }
    .cv-card-action-btn { margin-top: 4px; padding: 5px 4px; font-size: 0.74rem; }
    .cv-dialog-footer { gap: 8px; padding: 8px 12px; }
    .cv-hint-text { display: none; }
    .cv-footer-actions { width: 100%; gap: 8px; }
    .cv-replace-all { flex: 1 1 100%; }
    .cv-done-btn { margin-left: auto; }   /* delete left, done right, as in Settings */

    /* Lyrics: a smaller type at each A- / A+ level with the chords scaled to it, the lines close to the edges (the
       3-2-1 countdown in a narrow margin), less room kept above the words for the chords and thế bấm */
    .lyrics-banner.font-sm { --leadsheet-word-size: 0.95rem; --leadsheet-chord-size: 0.66rem; --leadsheet-line-gap: 0.4rem; }
    .lyrics-banner.font-md { --leadsheet-word-size: 1.08rem; --leadsheet-chord-size: 0.72rem; --leadsheet-line-gap: 0.5rem; }
    .lyrics-banner.font-lg { --leadsheet-word-size: 1.3rem; --leadsheet-chord-size: 0.8rem; --leadsheet-line-gap: 0.6rem; }
    .lyrics-banner.font-xl { --leadsheet-word-size: 1.55rem; --leadsheet-chord-size: 0.88rem; --leadsheet-line-gap: 0.75rem; }
    .ls-chord { padding: 1.5px 4px; font-size: var(--leadsheet-chord-size); }
    .leadsheet-row,
    .leadsheet-intro-row { padding: 0.4rem calc(0.45rem + 6px) 0.4rem calc(1.75rem + 6px); }
    .leadsheet-countdown-slot { left: calc(0.2rem + 6px); width: 22px; height: 22px; }
    .cd-num-single { font-size: 0.8rem; }
    .leadsheet-line-flow { column-gap: 0.28rem; padding-top: 64px; row-gap: 66px; }
    .hide-diagrams .leadsheet-line-flow { padding-top: 26px; row-gap: 28px; }
    .mini-chord-svg { width: 60px; height: 35px; }
    .leadsheet-word-box.chord-only { min-width: 64px; }
    .hide-diagrams .leadsheet-word-box.chord-only { min-width: 2.6rem; }
}
