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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #140f0c;
    min-height: 100vh;
    padding-top: 80px;
}

/* Mobile Scroll Behavior */
.top-bar.mobile-static {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    will-change: transform;
    z-index: 1000;
}

body:has(.top-bar.mobile-static) {
    padding-top: 0;
}

/* Sticky Top Bar */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #2a1f1a;
    border-bottom: 2px solid #5c2f1f;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.top-bar-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.top-bar-row {
    display: flex;
    align-items: center;
    gap: 30px;
    flex-wrap: wrap;
}

.top-bar-row.bottom-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 15px;
}

.top-bar h1 {
    color: #f4a460;
    font-size: 1.8em;
    margin: 0;
    white-space: nowrap;
}



/* Default fallback in case JS hasn't run yet */
:root {
  --topbar-offset: 140px; /* safe default; will be overwritten by JS */
}

/* Apply the offset to your page content wrappers */
#fretboard-page,
#progression-page,
.page-content {
  padding-top: var(--topbar-offset);
  box-sizing: border-box;
}

/* Make sure nothing else zeroes it out */
body:has(.top-bar.mobile-static) #fretboard-page,
body:has(.top-bar.mobile-static) #progression-page,
body:has(.top-bar.mobile-static) .page-content {
  padding-top: var(--topbar-offset);
}


.mode-toggle {
    display: flex;
    gap: 5px;
    background: #1a1410;
    padding: 4px;
    border-radius: 8px;
}

.mode-btn {
    padding: 8px 20px;
    background: transparent;
    color: #8d7a6a;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.3s;
}

.mode-btn:hover {
    color: #ffe4b5;
}

.mode-btn.active {
    background: #8d5524;
    color: #ffe4b5;
}

.top-row-controls {
    display: flex;
    gap: 15px;
    flex: 1;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.bottom-left-controls,
.bottom-center-controls,
.bottom-right-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Progression Selector Row */
.progression-select-row {
    width: 100%;
    padding: 10px 20px;
    background: rgba(31, 24, 19, 0.3);
    border-top: 1px solid #3d2f27;
    justify-content: center;
    display: flex;
    align-items: center;
    gap: 15px;
}

.progression-select-row select {
    font-size: 1.2em;
    padding: 8px 16px;
    min-width: 300px;
}

.progression-select-row .playback-container {
    flex-shrink: 0;
}

.progression-select-row .playback-button {
    font-size: 1em;
    padding: 8px 20px;
}

.bottom-left-controls {
    flex: 0 0 auto;
}

.bottom-center-controls {
    flex: 1;
    justify-content: center;
}

.bottom-right-controls {
    flex: 0 0 auto;
    justify-content: flex-end;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-group label {
    font-weight: 600;
    color: #c9a887;
    font-size: 0.85em;
    white-space: nowrap;
}

.input-group select {
    padding: 6px 12px;
    border: 2px solid #5c2f1f;
    border-radius: 6px;
    font-size: 1.1em;
    background: #1a1410;
    color: #c9a887;
    cursor: pointer;
    transition: border-color 0.3s;
}

.input-group select:hover {
    border-color: #8d5524;
}

.input-group select:focus {
    outline: none;
    border-color: #8d5524;
}

.compact-group select {
    min-width: 80px;
}

#chord-select-scale-toggle label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

#chord-select-scale-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #8d5524;
}

#zoom-slider {
    width: 80px;
    height: 6px;
    background: #5c2f1f;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    accent-color: #8d5524;
}

#zoom-slider::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: #8d5524;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s;
}

#zoom-slider::-webkit-slider-thumb:hover {
    background: #d4722e;
}

#zoom-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #8d5524;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: background 0.3s;
}

#zoom-slider::-moz-range-thumb:hover {
    background: #d4722e;
}

#zoom-value {
    color: #c9a887;
    font-size: 0.85em;
    font-weight: 600;
    min-width: 40px;
}

.export-btn {
    padding: 6px 16px;
    background: #8d5524;
    color: #ffe4b5;
    border: 2px solid #5c2f1f;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.export-btn:hover {
    background: #d4722e;
    transform: translateY(-1px);
}

.export-btn:active {
    transform: translateY(0);
}

/* Legend */
.legend {
    display: flex;
    gap: 15px;
    padding: 0;
    background: transparent;
    border: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #c9a887;
    font-size: 0.8em;
    white-space: nowrap;
}

/* Hide leading note legend item in Chord Select mode */
body:has(#fretboard-page.active) .legend .leading-note-legend {
    display: none;
}

.legend-marker {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #3d2f27;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.65em;
    gap: 1px;
}

.legend-marker.chord-tone {
    background: #f4a460;
    color: #3d1810;
    border: 2px solid #8d5524;
    border-radius: 3px; /* Square */
}

.legend-marker.scale-note {
    background: #5c2f1f;
    color: #ffe4b5;
    border-radius: 50%; /* Circle */
}

.legend-marker.leading-note {
    background: #6b7c3a;
    color: #f4a460;
    border: 2px solid #5c2f1f;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
}

.legend-marker.leading-note::before {
    content: '⮕';
}

.legend-marker.root-note {
    background: #8d5524;
    border: 2px solid #f4a460;
    color: #ffe4b5;
    border-radius: 3px; /* Square for roots */
}

.legend-marker .note-name {
    font-size: 0.95em;
    font-weight: bold;
    line-height: 1;
}

.legend-marker .interval {
    font-size: 0.65em;
    font-weight: normal;
    opacity: 0.85;
    line-height: 1;
}

/* Page Content */
.page-content {
    display: none;
    max-width: 1400px;
    margin: 20px auto;
    padding: 0 20px 30px 20px;
}

.page-content.active {
    display: block;
}

/* Fretboard Container */
#fretboard-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.fretboard-container {
  position: relative;
  overflow: visible !important; /* Ensure playback buttons are visible */
}

.fretboard-container .playback-container {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 100;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.chord-section {
    background: #1f1813;
    border-radius: 12px;
    padding: 20px;
    border: 2px solid #3d2f27;
    position: relative;
}

.chord-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.chord-label {
    font-size: 1.2em;
    font-weight: bold;
    color: #f4a460;
    padding: 8px 0;
    min-width: 80px;
}

.fretboard-container {
    background: #1a1108;
    padding: 20px;
    padding-bottom: 60px;
    border-radius: 12px;
    border: 1px solid rgba(255, 228, 181, 0.2);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.3);
    overflow-x: auto;
    overflow-y: visible;
}

/* Fretboard Grid */
.fretboard-grid {
    display: grid;
    grid-template-columns: 60px repeat(13, 1fr); /* Default for 12 frets, overridden by JS */
    gap: 0;
    min-width: 900px;
    background: linear-gradient(135deg, #3d1810 0%, #2a1108 100%);
    border: 1px solid rgba(255, 228, 181, 0.15);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.string-label {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #ffe4b5;
    font-size: 1.1em;
    padding: 10px;
}

/* Mandolin paired string label styling - smaller, closer */
.mandolin-fretboard .string-label.mandolin-paired-string {
    height: 20px;
    margin-top: -40px;
    font-size: 0.8em;
    padding: 5px;
    opacity: 0.7;
}

.fret-cell {
    position: relative;
    height: 60px;
    border-right: 3px solid #8B7355;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fret-cell::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 2px;
    background: rgba(255, 228, 181, 0.3);
    z-index: 0;
}

/* Mandolin paired string styling - same string line, closer spacing */
.mandolin-fretboard .fret-cell.mandolin-paired-string {
    height: 20px; /* Much smaller height for paired strings */
    margin-top: -40px; /* Pull up close to the previous string */
}

.fret-cell:first-of-type {
    border-left: 5px solid #8B7355;
}

.fret-cell.fret-0 {
    background: #a0826d;
    border-left: 5px solid #8B7355;
    border-right: 3px solid #8B7355;
}

.fret-marker {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.85em;
    cursor: pointer;
    transition: transform 0.2s;
    border: 2px solid transparent;
    position: relative;
    z-index: 1;
}

.fret-marker:hover {
    transform: scale(1.1);
}

.fret-marker {
    flex-direction: column;
    gap: 2px;
    font-size: 0.9em;
}

.fret-marker .note-name {
    font-size: 1em;
    font-weight: bold;
}

.fret-marker .interval {
    font-size: 0.7em;
    font-weight: normal;
    opacity: 0.8;
}

.fret-marker sub {
    font-size: 0.6em;
    font-weight: normal;
    vertical-align: sub;
    line-height: 0;
    margin-left: 2px;
}

.fret-marker sup {
    font-size: 1em;
    font-weight: bold;
    vertical-align: super;
    line-height: 0;
}

.fret-marker.chord-tone {
    background: #f4a460;
    color: #3d1810;
    border: 3px solid #8d5524;
    border-radius: 4px; /* Square for chord tones */
    font-size: 0.75em;
}

.fret-marker.scale-note {
    background: #5c2f1f;
    color: #ffe4b5;
    border-color: #3d2f27;
    border-radius: 50%; /* Circle for scale notes */
    font-size: 0.7em;
}

.fret-marker.leading-note {
    background: #6b7c3a;
    color: #f4a460;
    border: 2px solid #5c2f1f;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    position: relative;
    top: -2px;
}

.fret-marker.leading-note::before {
    content: '⮕';
}

.fret-marker.leading-chord-tone {
    background: #3d2f27;
    color: #d4a574;
    border: 2px solid #5c2f1f;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
}

.fret-marker.leading-chord-tone::before {
    content: '➜';
    font-size: 0.8em;
}

.fret-marker.root {
    background: #8d5524;
    color: #ffe4b5;
    border: 3px solid #f4a460;
    font-weight: 900;
}

.fret-marker.chord-tone.root {
    background: #8d5524;
    color: #ffe4b5;
    border: 3px solid #f4a460;
    border-radius: 4px;
}

.fret-number {
    position: absolute;
    bottom: -40px;
    font-size: 0.8em;
    color: #c9a887;
    font-weight: bold;
}

/* Move fret numbers and inlays down on mandolin for more spacing */
.mandolin-fretboard .fret-number {
    bottom: -50px;
}

.fret-inlay {
    position: absolute;
    bottom: -60px;
    width: 12px;
    height: 12px;
    background: #d4a574;
    border-radius: 50%;
}

.mandolin-fretboard .fret-inlay {
    bottom: -70px;
}

/* Progression Mode */
.progression-selector {
    background: #1a1410;
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 30px;
    border: 2px solid #3d2f27;
}

.progression-selector h2 {
    color: #f4a460;
    margin-bottom: 20px;
    text-align: center;
}

.key-selector {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.key-selector label {
    color: #c9a887;
    font-weight: 600;
}

.key-selector select {
    padding: 8px 16px;
    background: #1a1410;
    color: #c9a887;
    border: 2px solid #5c2f1f;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
}

.key-selector select:hover {
    border-color: #8d5524;
}

.progression-toggles {
    display: flex;
    gap: 30px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.progression-toggles label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #c9a887;
    font-weight: 600;
    cursor: pointer;
}

.progression-toggles input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #8d5524;
}

.progression-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
}

.progression-btn {
    padding: 15px 20px;
    background: #2a1f1a;
    color: #c9a887;
    border: 2px solid #5c2f1f;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    text-align: left;
}

.progression-btn:hover {
    background: #8d5524;
    border-color: #d4722e;
    color: #ffe4b5;
    transform: translateY(-2px);
}

#progression-display {
    display: flex;
    flex-direction: column;
    gap: 30px;
    transition: transform 0.2s ease;
}

/* Progression Placeholder */
.progression-placeholder {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 500px;
    margin: 40px 0;
    border: 2px dashed #5c2f1f;
    border-radius: 12px;
    overflow: hidden;
}

.placeholder-fretboard {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.75;
    background:
        /* Horizontal fret lines */
        repeating-linear-gradient(
            to bottom,
            transparent,
            transparent calc(100% / 7 - 2px),
            #5c2f1f calc(100% / 7 - 2px),
            #5c2f1f calc(100% / 7)
        ),
        /* Vertical string lines */
        repeating-linear-gradient(
            to right,
            transparent,
            transparent calc(100% / 7 - 1px),
            #3d2f27 calc(100% / 7 - 1px),
            #3d2f27 calc(100% / 7)
        ),
        /* Base fretboard color */
        linear-gradient(to bottom, #1a1410, #0f0b09);
    /* Add fret markers using radial gradients */
    background-image:
        radial-gradient(circle, #5c2f1f 6px, transparent 6px),
        radial-gradient(circle, #5c2f1f 6px, transparent 6px),
        repeating-linear-gradient(
            to bottom,
            transparent,
            transparent calc(100% / 7 - 2px),
            #5c2f1f calc(100% / 7 - 2px),
            #5c2f1f calc(100% / 7)
        ),
        repeating-linear-gradient(
            to right,
            transparent,
            transparent calc(100% / 7 - 1px),
            #3d2f27 calc(100% / 7 - 1px),
            #3d2f27 calc(100% / 7)
        ),
        linear-gradient(to bottom, #1a1410, #0f0b09);
    background-position:
        30% 50%,
        60% 50%,
        0 0,
        0 0,
        0 0;
    background-size:
        20px 20px,
        20px 20px,
        100% 100%,
        100% 100%,
        100% 100%;
    background-repeat: no-repeat;
}

.placeholder-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px;
    background: rgba(10, 8, 7, 0.85);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.placeholder-arrow {
    font-size: 3em;
    color: #f4a460;
    margin-bottom: 20px;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.progression-placeholder h2 {
    color: #f4a460;
    font-size: 1.8em;
    margin-bottom: 10px;
}

.progression-placeholder p {
    color: #c9a887;
    font-size: 1.1em;
}

/* MIDI Playback Controls */
.playback-button {
    background: #8d5524;
    color: #ffe4b5;
    border: 2px solid #f4a460;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 0.9em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    display: flex !important;
    align-items: center;
    gap: 6px;
    visibility: visible !important;
    opacity: 1 !important;
}

.playback-button:hover {
    background: #a66929;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(141, 85, 36, 0.4);
}

.playback-button:active {
    transform: translateY(0);
}

.playback-button.playing {
    background: #6b7c3a;
    border-color: #8d9f55;
}

.playback-flyout {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background: #1a1410;
    border: 2px solid #5c2f1f;
    border-radius: 8px;
    padding: 16px;
    min-width: 280px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: none;
}

.playback-flyout.active {
    display: block;
}

.playback-flyout h4 {
    color: #f4a460;
    font-size: 1em;
    margin-bottom: 12px;
    font-weight: bold;
}

.playback-modes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.playback-mode-btn {
    background: #2a1f1a;
    color: #c9a887;
    border: 2px solid #3d2f27;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
}

.playback-mode-btn:hover {
    background: #3d2f27;
    border-color: #5c2f1f;
    transform: translateX(2px);
}

.playback-mode-btn:active {
    transform: translateX(0);
}

.playback-mode-btn .icon {
    font-size: 1.2em;
    min-width: 20px;
    text-align: center;
}

.playback-mode-btn .label {
    flex: 1;
}

.playback-mode-btn .description {
    font-size: 0.8em;
    color: #8d7a6a;
    margin-top: 2px;
}

.playback-controls-wrapper {
    position: relative;
}

.stop-button {
    background: #5c2f1f;
    color: #ffe4b5;
    border: 2px solid #3d2f27;
    margin-top: 12px;
    width: 100%;
}

.stop-button:hover {
    background: #6b3a24;
    border-color: #5c2f1f;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    body {
        padding-top: 20px;
    }

    .page-content {
        padding: 0 20px;
    }

    .top-bar-content {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .top-bar h1 {
        font-size: 1.5em;
        text-align: center;
    }

    .mode-toggle {
        justify-content: center;
    }

    .legend {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }

    .legend-item {
        font-size: 0.75em;
    }

    .top-controls {
        flex-direction: column;
        gap: 10px;
    }

    .input-group {
        justify-content: space-between;
    }

    .fretboard-container {
        padding: 10px;
        padding-bottom: 50px;
    }

    .chord-controls {
        flex-direction: column;
    }

    .progression-list {
        grid-template-columns: 1fr;
    }
}
