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

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: #2c3e50;
    min-height: 100vh;
    font-weight: 300;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: -100%;
    left: -100%;
    width: 300%;
    height: 300%;
    background: 
        radial-gradient(ellipse 800px 600px at 20% 30%, rgba(255, 182, 193, 0.4) 0%, rgba(255, 182, 193, 0.25) 40%, rgba(255, 182, 193, 0.1) 70%, transparent 100%),
        radial-gradient(ellipse 700px 900px at 80% 70%, rgba(173, 216, 230, 0.35) 0%, rgba(173, 216, 230, 0.2) 45%, rgba(173, 216, 230, 0.08) 75%, transparent 100%),
        radial-gradient(ellipse 900px 500px at 50% 90%, rgba(221, 160, 221, 0.3) 0%, rgba(221, 160, 221, 0.18) 50%, rgba(221, 160, 221, 0.06) 80%, transparent 100%),
        radial-gradient(ellipse 600px 800px at 90% 20%, rgba(255, 218, 185, 0.32) 0%, rgba(255, 218, 185, 0.15) 55%, rgba(255, 218, 185, 0.05) 85%, transparent 100%),
        radial-gradient(ellipse 750px 650px at 10% 80%, rgba(152, 251, 152, 0.28) 0%, rgba(152, 251, 152, 0.12) 60%, rgba(152, 251, 152, 0.04) 90%, transparent 100%),
        radial-gradient(ellipse 550px 700px at 70% 10%, rgba(255, 192, 203, 0.25) 0%, rgba(255, 192, 203, 0.1) 65%, transparent 100%);
    filter: blur(80px);
    animation: paintSwirl 25s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

body::after {
    content: '';
    position: fixed;
    top: -100%;
    left: -100%;
    width: 300%;
    height: 300%;
    background: 
        radial-gradient(ellipse 650px 850px at 60% 40%, rgba(255, 215, 0, 0.2) 0%, rgba(255, 215, 0, 0.08) 50%, transparent 80%),
        radial-gradient(ellipse 800px 600px at 30% 80%, rgba(186, 85, 211, 0.18) 0%, rgba(186, 85, 211, 0.06) 60%, transparent 90%),
        radial-gradient(ellipse 500px 900px at 85% 60%, rgba(135, 206, 235, 0.22) 0%, rgba(135, 206, 235, 0.09) 55%, transparent 85%);
    filter: blur(120px);
    animation: paintSwirl 35s ease-in-out infinite reverse;
    pointer-events: none;
    z-index: -2;
}

@keyframes paintSwirl {
    0%, 100% {
        transform: rotate(0deg) scale(1) translate(0, 0);
        opacity: 0.8;
    }
    25% {
        transform: rotate(8deg) scale(1.1) translate(-40px, 30px);
        opacity: 1;
    }
    50% {
        transform: rotate(-6deg) scale(0.9) translate(50px, -20px);
        opacity: 0.7;
    }
    75% {
        transform: rotate(10deg) scale(1.05) translate(-30px, 40px);
        opacity: 0.9;
    }
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Main harmonic map area - center stage */
#harmonic-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding-bottom: 100px; /* Leave space for tab selector */
    background: transparent;
}

/* Tab selector at bottom - hidden on desktop */
#tab-selector {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: none;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(52, 73, 94, 0.1);
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    z-index: 100;
}

.tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #7f8c8d;
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 80px;
}

.tab-btn:hover {
    background: rgba(52, 73, 94, 0.05);
    color: #34495e;
}

.tab-btn.active {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.tab-icon {
    font-size: 1.2rem;
}

.tab-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tab panels - hidden on desktop, shown as fixed overlays on mobile */
.tab-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 80px;
    z-index: 1000;
    display: none;
    overflow-y: auto;
    margin: 1rem;
    max-height: calc(100vh - 120px);
}

.tab-panel.active {
    display: flex !important;
    flex-direction: column;
}

/* Desktop layout - show all sections */
@media (min-width: 1024px) {
    #app {
        display: grid;
        grid-template-columns: 250px 1fr 250px;
        grid-template-rows: 1fr;
        grid-template-areas: "chord-library harmonic-main chord-diagrams";
        gap: 2rem;
        padding: 2rem;
        max-width: 1600px;
        margin: 0 auto;
        min-height: 100vh;
        align-items: start;
    }
    
    #harmonic-main {
        grid-area: harmonic-main;
        padding: 0;
        padding-bottom: 0;
        max-width: none;
        margin: 0;
        align-self: start;
        background: transparent;
    }
    
    #chord-library {
        grid-area: chord-library;
        position: static !important;
        display: flex !important;
        margin: 0;
        max-height: 80vh;
        z-index: auto;
        height: 80vh;
        align-self: start;
        overflow: hidden;
    }
    
    #chord-diagrams {
        grid-area: chord-diagrams;
        position: static !important;
        display: flex !important;
        margin: 0;
        max-height: 80vh;
        height: 80vh;
        z-index: auto;
        align-self: start;
        overflow: hidden;
    }
    
    #tab-selector {
        display: none;
    }
    
    /* Ensure all panels have consistent styling */
    .panel {
        height: fit-content;
    }
    
    /* Remove the ::before spacers as they're not needed with proper grid */
    #chord-library::before,
    #chord-diagrams::before {
        display: none;
    }
}

.panel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(52, 73, 94, 0.1);
    border-radius: 20px;
    padding: 2.5rem;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08);
}

#chord-library {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#chord-library h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: #2c3e50;
    flex-shrink: 0;
    letter-spacing: 0.5px;
    text-align: center;
    padding-bottom: 1rem;
    border-bottom: 2px solid rgba(52, 73, 94, 0.1);
}

#chord-type-selector {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
    background: #ecf0f1;
    border-radius: 12px;
    padding: 4px;
}

.type-row {
    display: flex;
    gap: 3px;
}

.type-btn {
    flex: 1;
    min-width: 45px;
    padding: 0.6rem 0.5rem;
    background: transparent;
    color: #7f8c8d;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.type-btn:hover {
    background: rgba(52, 73, 94, 0.1);
    color: #34495e;
}

.type-btn.active {
    background: #ffffff;
    color: #2c3e50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#chord-cards-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding-right: 8px;
    flex: 1;
}

#chord-cards-container::-webkit-scrollbar {
    width: 6px;
}

#chord-cards-container::-webkit-scrollbar-track {
    background: transparent;
}

#chord-cards-container::-webkit-scrollbar-thumb {
    background: rgba(52, 73, 94, 0.2);
    border-radius: 3px;
}

#chord-cards-container::-webkit-scrollbar-thumb:hover {
    background: rgba(52, 73, 94, 0.4);
}

.chord-card {
    background: rgba(255, 255, 255, 1);
    border: none;
    border-radius: 12px;
    padding: 1rem;
    cursor: grab;
    transition: all 0.3s ease;
    user-select: none;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chord-card:hover,
.chord-card:active {
    background: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Touch-specific styles */
@media (hover: none) and (pointer: coarse) {
    .chord-card:active {
        background: #f8f9fa;
        transform: scale(0.98);
    }
}

.chord-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.chord-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #2c3e50;
}

.chord-notes {
    font-size: 0.8rem;
    color: #7f8c8d;
    font-weight: 400;
}

/* Harmonic map wrapper styles */

#harmonic-map-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    height: 100%;
}

#selector-row {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.selector-group {
    position: relative;
}

#view-select, #context-select {
    padding: 0.4rem 0.8rem;
    border: 2px solid #ecf0f1;
    border-radius: 6px;
    background: white;
    color: #7f8c8d;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1rem;
    padding-right: 2rem;
}

#view-select:hover, #context-select:hover {
    border-color: #3498db;
    color: #2c3e50;
}

#view-select:focus, #context-select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
    color: #2c3e50;
}

#view-select option:disabled, #context-select option:disabled {
    color: #bdc3c7;
    font-style: italic;
}

#view-select option:not(:disabled), #context-select option:not(:disabled) {
    color: #2c3e50;
}

#context-select {
    border-color: rgba(155, 89, 182, 0.3);
}

#context-select:hover {
    border-color: #9b59b6;
}

#context-select:focus {
    border-color: #9b59b6;
    box-shadow: 0 0 0 3px rgba(155, 89, 182, 0.1);
}

#harmonic-map-container {
    background: transparent;
    border-radius: 20px;
    padding: 2rem;
    position: relative;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 400px;
}


#harmonic-map {
    border-radius: 12px;
    cursor: default;
}

#chord-displays-column {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100%;
}

#current-chord-display,
#next-chord-display {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    text-align: center;
}

#current-chord-display h3,
#next-chord-display h3 {
    font-size: 0.9rem;
    font-weight: 500;
    color: #7f8c8d;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#current-chord-name,
#next-chord-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 1rem;
}


.fretboard-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    background: rgba(236, 240, 241, 0.4);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid rgba(52, 73, 94, 0.1);
}

.fretboard-container svg {
    max-width: 100%;
    height: auto;
    transform: scale(1.3);
}

#fretboard-display {
    background-color: #1a1a1a;
    border-radius: 8px;
    padding: 1rem;
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#fretboard-display svg {
    max-width: 100%;
    height: auto;
}

.chord-history-container {
    display: flex;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    border: 1px solid rgba(52, 73, 94, 0.1);
}

/* Desktop - more compact styling for 5 items */
@media (min-width: 1024px) {
    .chord-history-item {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}

/* Mobile - position chord history above tabs and hide extra items */
@media (max-width: 1023px) {
    .chord-history-container {
        position: fixed;
        bottom: 120px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1000;
        backdrop-filter: blur(20px);
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.1);
        gap: 0.75rem;
    }
    
    .chord-history-item {
        padding: 0.6rem 1.2rem;
    }
    
    .chord-history-item.desktop-only {
        display: none;
    }
}

.chord-history-item {
    padding: 0.75rem 1.5rem;
    background: white;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
    border: 2px solid #ecf0f1;
    min-width: 90px;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chord-history-item.empty {
    color: #bdc3c7;
    background: rgba(236, 240, 241, 0.3);
    border-color: rgba(189, 195, 199, 0.2);
    box-shadow: none;
}

.chord-history-item:not(.empty) {
    animation: slideInFromRight 0.4s ease;
    cursor: pointer;
}

.chord-history-item:not(.empty):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.chord-history-item.current-chord {
    background: linear-gradient(135deg, #3498db, #2980b9) !important;
    color: white !important;
    border-color: #2980b9 !important;
    box-shadow: 0 3px 12px rgba(52, 152, 219, 0.3) !important;
    transform: scale(1.05) !important;
}

.chord-history-item.current-chord:hover {
    transform: scale(1.08) translateY(-2px) !important;
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.4) !important;
}

.chord-history-item.selected {
    background: linear-gradient(135deg, #3498db, #2980b9) !important;
    color: white !important;
    border-color: #2980b9 !important;
    box-shadow: 0 4px 16px rgba(52, 152, 219, 0.4) !important;
    transform: scale(1.15) !important;
    opacity: 1 !important;
}

.chord-history-item[data-position="1"]:not(.empty) {
    opacity: 0.85;
}

.chord-history-item[data-position="2"]:not(.empty) {
    opacity: 0.7;
}

@keyframes slideInFromRight {
    from {
        transform: translateX(20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}


@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.playing {
    animation: pulse 0.5s ease-in-out;
}

/* Mobile and tablet - show tab system */
@media (max-width: 1023px) {
    #tab-selector {
        display: flex;
    }
    
    #harmonic-main {
        padding-bottom: 80px;
    }
    
    /* Hide sections by default on mobile - only show via tabs */
    #chord-library,
    #chord-diagrams {
        display: none !important;
    }
    
    /* Show sections only when they have active class */
    #chord-library.active,
    #chord-diagrams.active {
        display: flex !important;
    }
    
    /* Make diagram tab more compact on mobile */
    #chord-diagrams.active {
        height: auto !important;
        min-height: auto !important;
        flex-shrink: 0;
        justify-content: flex-start;
    }
    
    /* Hide next chord preview on mobile */
    #next-chord-display {
        display: none !important;
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    #harmonic-main {
        padding: 0.5rem 1rem;
    }
    
    .panel {
        padding: 1.5rem;
        border-radius: 15px;
    }
    
    #tab-selector {
        padding: 0.5rem;
        gap: 0.25rem;
    }
    
    .tab-btn {
        padding: 0.5rem 1rem;
        min-width: 70px;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    .tab-icon {
        font-size: 1rem;
    }
    
    .tab-label {
        font-size: 0.65rem;
    }
    
    .tab-panel {
        margin: 0.5rem;
        bottom: 70px;
        max-height: calc(100vh - 140px);
    }
    
    #chord-library h2 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
    }
    
    #chord-type-selector {
        margin-bottom: 1rem;
        padding: 3px;
    }
    
    .type-btn {
        padding: 0.5rem 0.4rem;
        font-size: 0.7rem;
        min-width: 40px;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    #chord-cards-container {
        gap: 6px;
    }
    
    .chord-card {
        padding: 0.75rem;
        border-radius: 10px;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    .chord-name {
        font-size: 1rem;
        margin-bottom: 0.2rem;
    }
    
    .chord-notes {
        font-size: 0.75rem;
    }
    
    #harmonic-map-container {
        padding: 1rem;
        height: 350px;
        min-height: 350px;
    }
    
    #chord-displays-column {
        flex-direction: column;
        gap: 1rem;
    }
    
    #current-chord-display,
    #next-chord-display {
        padding: 1rem;
        border-radius: 12px;
    }
    
    #current-chord-display h3,
    #next-chord-display h3 {
        font-size: 0.8rem;
        margin-bottom: 0.4rem;
    }
    
    #current-chord-name,
    #next-chord-name {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .fretboard-container {
        min-height: 120px;
        padding: 0.5rem;
        border-radius: 8px;
    }
    
    .fretboard-container svg {
        transform: scale(1);
    }
}

@media (max-width: 480px) {
    #harmonic-main {
        padding: 0.25rem 0.75rem;
    }
    
    .panel {
        padding: 1rem;
        border-radius: 12px;
    }
    
    #chord-library h2 {
        font-size: 1rem;
    }
    
    .type-btn {
        padding: 0.4rem 0.3rem;
        font-size: 0.65rem;
        min-width: 35px;
    }
    
    #harmonic-map-container {
        height: 180px;
        min-height: 180px;
        padding: 0.5rem 0.75rem;
        align-items: flex-start;
    }
    
    #chord-displays-column {
        flex-direction: column;
        gap: 0.5rem;
        justify-content: flex-start;
        padding-top: 1rem;
    }
    
    #current-chord-display,
    #next-chord-display {
        padding: 0.5rem;
        flex-shrink: 0;
    }
    
    #current-chord-display h3 {
        margin-bottom: 0.2rem;
        font-size: 0.7rem;
    }
    
    #current-chord-name {
        margin-bottom: 0.3rem;
        font-size: 1rem;
    }
    
    .fretboard-container {
        min-height: 40px;
        display: flex;
        justify-content: center;
        align-items: flex-start;
    }
    
    .chord-card {
        padding: 0.5rem;
    }
    
    .chord-name {
        font-size: 0.9rem;
    }
    
    .chord-notes {
        font-size: 0.7rem;
    }
    
    .tab-btn {
        padding: 0.4rem 0.8rem;
        min-width: 60px;
    }
    
    .tab-icon {
        font-size: 0.9rem;
    }
    
    .tab-label {
        font-size: 0.6rem;
    }
}