/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    background: #f8f9fa;
    overflow-x: hidden;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Navigation Bar */
.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand-mobile {
    min-width: 0;
    flex: 1;
    color: white;
    padding-right: 10px;
}

.brand-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.1;
}

.nav-brand-mobile p {
    margin: 2px 0 0;
    font-size: 11px;
    line-height: 1.2;
    opacity: 0.9;
}

.nav-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-settings {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Navigation Buttons */
.nav-btn, .settings-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover, .settings-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-1px);
}

.nav-btn:active, .settings-btn:active {
    transform: translateY(0);
    background: rgba(255,255,255,0.4);
}

/* Active state for play and metronome buttons */
.nav-btn.active {
    background: rgba(255,255,255,0.9);
    color: #667eea;
}

.play-btn.active {
    background: rgba(46, 204, 113, 0.9);
    color: white;
}

.metronome-btn.active {
    background: rgba(231, 76, 60, 0.9);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Fretboard Area */
.fretboard-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px 8px 8px;
    min-height: calc(100vh - 80px);
}

#chart-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

#scale-chart {
    max-width: 100%;
    max-height: 100%;
}

/* Note and Interval Names */
#note-names-container, #interval-names-container {
    margin-top: 16px;
    padding: 0 16px;
    text-align: center;
}

#note-names-display, #interval-names-display {
    font-size: 16px;
    font-weight: 500;
    color: #666;
}

.notes-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.note-item {
    padding: 6px 12px;
    background: #fff;
    border-radius: 20px;
    border: 1px solid #e0e0e0;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.note-item.root {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Horizontal Fretboard Container */
.horizontal-fretboard-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 20px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

#horizontal-fretboard-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

/* Piano Container */
.piano-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

/* Piano Mode Layout - Stack piano above horizontal fretboard */
.app-container.piano-layout {
    flex-direction: column;
}

.app-container.piano-layout .piano-container {
    order: 1;
}

.app-container.piano-layout .horizontal-fretboard-container {
    order: 2;
    border-top: 1px solid #e0e0e0;
}

.app-container.piano-layout .main-content {
    display: none;
}

/* Piano Staff Styling */
.staff-container {
    background: transparent !important;
    border: none !important;
    padding: 10px !important;
    margin: 10px auto !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    width: 100% !important;
}

.staff-container svg {
    max-width: 100%;
    height: auto;
}

/* Settings Panels */
.settings-panel {
    position: fixed;
    top: 80px;
    right: -100%;
    width: 90%;
    max-width: 400px;
    height: calc(100vh - 80px);
    background: white;
    border-radius: 16px 0 0 16px;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    transition: right 0.3s ease;
    z-index: 200;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.settings-panel.show {
    right: 0;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e0e0e0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 16px 0 0 0;
}

.settings-header h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* Gear Toggle Button - Hidden by default, only shown in desktop vertical mode */
.gear-toggle {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.gear-toggle:hover {
    background: rgba(255,255,255,0.3);
}

.settings-content {
    padding: 24px;
    padding-bottom: 80px; /* Extra space for mobile browser UI */
}

/* Settings Sections */
.settings-section {
    margin-bottom: 32px;
}

.settings-section h4 {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #667eea;
}

/* Setting Groups */
.setting-group {
    margin-bottom: 16px;
}

.setting-group label {
    display: block;
    font-weight: 500;
    color: #555;
    margin-bottom: 6px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-group input[type="checkbox"] {
    margin-right: 8px;
}

/* Form Controls */
select, input[type="range"], input[type="number"] {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    transition: border-color 0.2s ease;
}

select:focus, input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

input[type="range"] {
    padding: 0;
    height: 6px;
    background: #ddd;
    appearance: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* String Voicing Controls */
.string-voicing-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.action-buttons button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    background: #667eea;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.action-buttons button:hover {
    background: #5a67d8;
}

.action-buttons button:active {
    background: #4c51bf;
}

/* Small text */
small {
    display: block;
    font-size: 11px;
    color: #888;
    margin-top: 4px;
    line-height: 1.3;
}

small.is-problem {
    color: #b83232;
    font-weight: 600;
}

/* Settings Overlay */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.settings-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Quick Settings Specific Styles */
.quick-settings .settings-content {
    padding: 24px;
}

.quick-settings .setting-group {
    margin-bottom: 20px;
}

/* Desktop Styles */
@media (min-width: 768px) {
    .nav-bar {
        padding: 16px 32px;
    }
    
    .nav-controls {
        gap: 12px;
    }
    
    .nav-settings {
        gap: 12px;
    }
    
    .nav-btn, .settings-btn {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    .nav-brand-mobile p {
        font-size: 12px;
    }
    
    .fretboard-area {
        padding: 0 12px 12px 12px;
    }
    
    .settings-panel {
        top: 96px;
        height: calc(100vh - 96px);
        max-width: 480px;
    }
    
    .settings-content {
        padding: 32px;
        padding-bottom: 32px; /* Reset to normal on desktop */
    }
    
    .string-voicing-controls {
        grid-template-columns: 1fr 1fr 1fr;
    }
    
    .action-buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .action-buttons button {
        flex: 1;
        min-width: 140px;
    }
}

/* Desktop Sidebar Styles - Enable for all desktop widths */
@media (min-width: 900px) {
    /* Desktop Vertical Mode - Show quick settings as persistent sidebar */
    .app-container.vertical-layout .quick-settings {
        position: fixed;
        top: 80px;
        right: 0;
        width: 320px;
        height: calc(100vh - 80px);
        background: white;
        border-radius: 0;
        box-shadow: -4px 0 20px rgba(0,0,0,0.15);
        transition: none;
        z-index: 50;
        overflow-y: auto;
        border-left: 1px solid #e0e0e0;
    }
    
    .app-container.vertical-layout .quick-settings .settings-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border-radius: 0;
        position: relative;
    }
    
    .app-container.vertical-layout .quick-settings .close-btn {
        display: none;
    }
    
    /* Show gear toggle in desktop vertical mode */
    .app-container.vertical-layout .quick-settings .gear-toggle {
        display: flex;
    }
    
    /* Adjust main content to accommodate sidebar */
    .app-container.vertical-layout .main-content {
        margin-right: 320px;
    }
    
    /* Hide regular settings buttons in nav for desktop vertical mode */
    .app-container.vertical-layout .nav-settings .settings-btn {
        display: none;
    }
    
    /* Show only gear toggle in nav for desktop vertical mode */
    .app-container.vertical-layout .nav-settings .gear-toggle {
        display: flex;
    }
    
    /* Override the normal panel behavior for desktop vertical mode */
    .app-container.vertical-layout .settings-overlay {
        display: none !important;
    }
}

/* Large Desktop Styles */
@media (min-width: 1200px) {
    .settings-panel {
        max-width: 520px;
    }
    
    .settings-content {
        padding: 32px;
        padding-bottom: 32px; /* Keep normal padding on large desktop */
    }
    
    .string-voicing-controls {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 16px;
    }
}

@media (min-width: 1400px) {
    /* Further styles for even larger desktops can be added here */
}

/* Landscape Phone Styles */
@media (max-height: 500px) and (orientation: landscape) {
    .nav-bar {
        padding: 8px 16px;
    }
    
    .nav-btn, .settings-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    
    .fretboard-area {
        padding: 0 8px 8px 8px;
        min-height: calc(100vh - 60px);
    }
    
    .settings-panel {
        top: 60px;
        height: calc(100vh - 60px);
        width: 95%;
        max-width: 600px;
    }
    
    .settings-header {
        padding: 12px 20px;
    }
    
    .settings-content {
        padding: 16px;
        padding-bottom: 60px; /* Extra space for landscape mobile */
    }
    
    .settings-section {
        margin-bottom: 20px;
    }
    
    .setting-group {
        margin-bottom: 12px;
    }
}

/* Hide elements for mobile-first approach */
.horizontal-fretboard-container,
.piano-container {
    display: none;
}

.horizontal-fretboard-container.show,
.piano-container.show {
    display: flex;
}

/* Compatibility styles for fretboard dots and elements */
.dot {
    position: absolute;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    border: 2px solid #fff;
    background-color: black;
    width: 25px;
    height: 25px;
}

.dot-black {
    background-color: black;
    border: 2px solid white;
    color: white;
    font-weight: bold;
    width: 30px;
    height: 30px;
}

.dot-white {
    background-color: white;
    border: 3px solid black;
    color: black;
    width: 25px;
    height: 25px;
}

.dot.root {
    background: #e74c3c;
    border: 2px solid #c0392b;
}

.dot.open-string {
    background: #3498db;
    border: 3px solid #2980b9;
}

.dot:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

.interval-label, .note-label {
    font-size: 12px;
    font-family: sans-serif;
    line-height: 1;
    user-select: none;
    color: inherit;
    font-weight: bold;
    text-shadow: 0 1px 3px #000, 0 0 2px #333;
    text-align: center;
    width: 100%;
    display: block;
    pointer-events: none;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 6;
}

.scale-dot {
    position: absolute;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.3);
    border: 1px solid rgba(102, 126, 234, 0.5);
    z-index: 5;
    opacity: 0.75;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* Dynamic fretboard specific overrides */
#dynamic-fretboard {
    box-shadow: none !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Override positioning for dynamic fretboard dots - they calculate position manually */
#dynamic-fretboard .dot,
#horizontal-fretboard-wrapper .dot {
    transform: none !important;
}

#dynamic-fretboard .scale-dot,
#horizontal-fretboard-wrapper .scale-dot {
    transform: none !important;
}

#dynamic-fretboard .dot .interval-label,
#horizontal-fretboard-wrapper .dot .interval-label {
    transform: translate(-50%, -50%) !important;
}

.piano-key {
    cursor: pointer;
    transition: all 0.1s ease;
}

.piano-key:hover {
    transform: translateY(-1px);
}

.piano-key.active {
    background: #667eea !important;
    transform: translateY(2px);
}

/* Responsive fretboard scaling */
@media (max-width: 480px) {
    .nav-bar {
        align-items: flex-start;
        gap: 8px;
    }

    .nav-brand-mobile p {
        max-width: 13rem;
    }

    #scale-chart {
        transform: scale(0.85);
        transform-origin: center;
    }
}

@media (max-width: 320px) {
    .nav-brand-mobile p {
        display: none;
    }

    #scale-chart {
        transform: scale(0.75);
    }
}

/* Ensure proper touch targets */
@media (pointer: coarse) {
    .nav-btn, .settings-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    select, input[type="number"] {
        min-height: 44px;
    }
    
    .action-buttons button {
        min-height: 44px;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .nav-btn, .settings-btn {
        border: 0.5px solid rgba(255,255,255,0.1);
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
.nav-btn:focus-visible,
.settings-btn:focus-visible,
select:focus-visible,
input:focus-visible,
button:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .nav-bar,
    .settings-panel,
    .settings-overlay {
        display: none !important;
    }
    
    .main-content {
        margin: 0;
        padding: 0;
    }
    
    body {
        background: white;
    }
}

/* When gear toggle is in navigation bar, style it like other nav buttons */
.nav-settings .gear-toggle {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    border-radius: 6px;
    width: auto;
    height: auto;
    padding: 8px 12px;
    font-size: 14px;
}

.nav-settings .gear-toggle:hover {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.3);
}
