/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(-45deg, #98fb98, #90ee90, #87ceeb, #b19cd9, #dda0dd, #afeeee);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    animation: float 6s ease-in-out infinite;
    position: relative;
    overflow: hidden;
}

header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 3s ease infinite;
    pointer-events: none;
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 8px;
    background: linear-gradient(45deg, #32cd32, #90ee90, #87ceeb, #b19cd9);
    background-size: 300% 300%;
    animation: gradientText 8s ease infinite;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    font-size: 1rem;
    color: #666;
    margin-bottom: 0;
}

/* Mobile Indicator Styles */
.mobile-indicator {
    background: linear-gradient(45deg, #ff6b6b, #ff8e53);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    margin-top: 12px;
    box-shadow: 0 3px 12px rgba(255, 107, 107, 0.3);
    animation: pulse 2s ease infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Section Styles */
section {
    background: rgba(255, 255, 255, 0.95);
    margin-bottom: 15px;
    padding: 18px;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    animation: float 8s ease-in-out infinite;
    animation-delay: var(--animation-delay, 0s);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

section:hover {
    transform: translateY(-5px) scale(1.01);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.15);
}

section:nth-child(2) { --animation-delay: -2s; }
section:nth-child(3) { --animation-delay: -4s; }
section:nth-child(4) { --animation-delay: -6s; }
section:nth-child(5) { --animation-delay: -8s; }

section h2, section h3 {
    margin-bottom: 15px;
    color: #333;
}

/* Piano Keyboard Styles */
.piano-keyboard {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    height: 150px;
    margin: 20px 0;
    position: relative;
    background: #000;
    padding: 10px;
    border-radius: 10px;
}

.white-keys {
    display: flex;
    position: relative;
    z-index: 1;
}

.black-keys {
    display: flex;
    position: absolute;
    z-index: 2;
    left: 50%;
    transform: translateX(-50%);
    top: 10px;
}

.key {
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid #333;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-weight: bold;
    user-select: none;
    position: relative;
}

.key.white {
    background: #fff;
    width: 70px;
    height: 120px;
    margin: 0 1px;
    color: #333;
    border-radius: 0 0 8px 8px;
}

.key.black {
    background: #333;
    width: 45px;
    height: 80px;
    color: #fff;
    border-radius: 0 0 5px 5px;
    font-size: 0.8rem;
    margin: 0 7px;
}

.key.black.spacer {
    visibility: hidden;
    width: 70px;
    margin: 0 20px;
}

.key:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.key.white:hover {
    background: #f0f0f0;
}

.key.black:hover {
    background: #555;
}

.key.active {
    transform: translateY(2px);
}

.key.selected {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
}

.key span {
    padding: 5px;
    font-size: 0.9rem;
}

/* Audio Source Selection */
.audio-source-selection {
    text-align: center;
    margin: 20px 0;
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.audio-source-selection h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.2rem;
}

.audio-source-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.radio-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 20px;
    border: 2px solid #ddd;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
    min-width: 150px;
}

.radio-option:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

.radio-option input[type="radio"] {
    display: none;
}

.radio-option input[type="radio"]:checked + .radio-label {
    color: #667eea;
    font-weight: bold;
}

.radio-option input[type="radio"]:checked ~ small {
    color: #667eea;
}

.radio-option:has(input[type="radio"]:checked) {
    border-color: #667eea;
    background: linear-gradient(45deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
}

.radio-label {
    font-size: 1.1rem;
    margin-bottom: 5px;
    transition: all 0.3s ease;
}

.radio-option small {
    font-size: 0.85rem;
    color: #666;
    text-align: center;
    transition: all 0.3s ease;
}

/* Mobile responsive adjustments for audio source selection */
@media (max-width: 768px) {
    .audio-source-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .radio-option {
        min-width: auto;
        padding: 12px 15px;
    }
    
    .radio-label {
        font-size: 1rem;
    }
    
    .radio-option small {
        font-size: 0.8rem;
    }
}

/* Selected Notes Display */
.selected-notes {
    text-align: center;
    margin: 20px 0;
}

.note-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.note-display {
    background: #f8f9fa;
    border: 2px dashed #ddd;
    border-radius: 10px;
    padding: 15px;
    margin: 10px 0;
    min-height: 50px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.note-badge {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.note-badge:hover {
    transform: scale(1.05);
}

/* Analysis Grid */
.analysis-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

.analysis-card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

.results-list {
    max-height: 600px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(6, 1fr); /* Increased from 3 to 6 columns */
    gap: 6px; /* Reduced from 12px to 6px */
    padding: 6px; /* Reduced from 8px to 6px */
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #fafafa;
}

.result-item {
    background: white;
    margin: 0;
    padding: 6px 8px; /* Reduced from 12px to 6px 8px */
    border-radius: 6px; /* Reduced from 8px to 6px */
    border-left: 3px solid #667eea; /* Reduced from 4px to 3px */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* Reduced shadow */
    cursor: pointer;
    transition: transform 0.2s ease;
    min-height: 35px; /* Reduced from 60px to 35px */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.result-item:hover {
    transform: translateY(-1px); /* Reduced from -2px to -1px */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15); /* Reduced shadow */
}

.result-item .name {
    font-weight: bold;
    color: #333;
    font-size: 0.85rem; /* Reduced font size */
    line-height: 1.2; /* Tighter line height */
}

.result-item .notes {
    font-size: 0.75rem; /* Reduced from 0.9rem to 0.75rem */
    color: #666;
    margin-top: 2px; /* Reduced from 5px to 2px */
    line-height: 1.1; /* Tighter line height */
}

.result-item .confidence {
    font-size: 0.7rem; /* Reduced from 0.8rem to 0.7rem */
    color: #999;
    float: right;
}

/* Chord Status Indicators */
.result-item.exact-match {
    border-left-color: #28a745;
    background: linear-gradient(135deg, #f8fff9 0%, #ffffff 100%);
}

.chord-status {
    font-size: 0.75rem;
    margin-top: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

.chord-status.exact {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.chord-status.missing {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    margin-right: 4px;
}

.chord-status.extra {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Buttons - Enhanced Mac compatibility */
.btn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
    margin: 5px;
    min-width: 120px;
    /* Mac compatibility fixes */
    -webkit-appearance: none;
    appearance: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* Ensure button is always clickable */
    position: relative;
    z-index: 1;
    /* Additional Mac Chrome fixes */
    outline: none;
    -webkit-focus-ring-color: transparent;
    -webkit-touch-callout: none;
    -webkit-text-size-adjust: none;
}

/* Mac-specific button fixes */
@supports (-webkit-appearance: none) {
    .btn {
        /* Force clickable area on Mac Safari/Chrome */
        display: inline-block;
        vertical-align: middle;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
}

/* Force button interactivity on Mac */
.btn:hover,
.btn:focus,
.btn:active {
    outline: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* Specific fixes for transpose buttons on Mac */
#transposeUp,
#transposeDown {
    /* Ensure these critical buttons always work on Mac */
    -webkit-appearance: none !important;
    appearance: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
    outline: none !important;
    cursor: pointer !important;
    position: relative !important;
    z-index: 2 !important; /* Higher z-index for transpose buttons */
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.btn.secondary {
    background: #6c757d;
}

.btn.secondary:hover {
    background: #5a6268;
    box-shadow: 0 6px 20px rgba(108, 117, 125, 0.4);
}

.btn.secondary.active {
    background: #dc3545;
    color: white;
    animation: pulse 1.5s infinite;
}

.btn.secondary.active:hover {
    background: #c82333;
}

@keyframes pulse {
    0% { box-shadow: 0 4px 15px rgba(220, 53, 69, 0.4); }
    50% { box-shadow: 0 6px 20px rgba(220, 53, 69, 0.6); }
    100% { box-shadow: 0 4px 15px rgba(220, 53, 69, 0.4); }
}

/* Playback Controls */
.playback-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.random-order-display {
    text-align: center;
    margin: 12px 0;
}

.random-order-display h4 {
    margin-bottom: 8px;
    color: #555;
    font-size: 1rem;
}

.musical-staff-container {
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
    min-height: 140px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: auto; /* Allow horizontal scrolling if needed */
}

.musical-staff {
    width: 100%;
    max-width: 1000px;
    min-width: 800px; /* Ensure minimum width for readability */
    height: 120px;
    background: white;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.staff-lines line {
    stroke: #333;
    stroke-width: 1;
}

.staff-note {
    fill: #333;
    stroke: #333;
    stroke-width: 1;
}

.staff-note-head {
    fill: #333;
}

.staff-note-stem {
    stroke: #333;
    stroke-width: 1.5;
}

.staff-ledger-line {
    stroke: #333;
    stroke-width: 1;
}

.staff-duration-indicator {
    font-family: serif;
    font-size: 12px;
    fill: #666;
}

.tempo-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.tempo-control input[type="range"] {
    width: 200px;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.tempo-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(45deg, #667eea, #764ba2);
    cursor: pointer;
}

#tempoValue {
    font-weight: bold;
    color: #667eea;
    min-width: 30px;
}

/* Info Section */
.info-card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

.theory-content {
    line-height: 1.8;
}

.theory-content p {
    margin-bottom: 10px;
}

.theory-content .highlight {
    background: #fff3cd;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

/* Responsive Design */
@media (max-width: 768px) {
    .analysis-grid {
        grid-template-columns: 1fr;
    }
    
    .results-list {
        grid-template-columns: repeat(4, 1fr); /* Increased from 2 to 4 for tablets */
        gap: 5px; /* Reduced gap */
    }
    
    .piano-keyboard {
        transform: scale(0.8);
        margin: 10px 0;
    }
    
    .playback-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .musical-staff {
        min-width: 600px; /* Smaller minimum for tablets */
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .container {
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .results-list {
        grid-template-columns: repeat(2, 1fr); /* 2 columns for small phones */
        gap: 4px; /* Smaller gap for mobile */
    }
    
    .result-item {
        min-height: 30px; /* Reduced from 50px to 30px */
        padding: 4px 6px; /* Reduced from 10px to 4px 6px */
        font-size: 0.8rem; /* Smaller font for mobile */
    }
    
    .result-item .name {
        font-size: 0.8rem;
    }
    
    .result-item .notes {
        font-size: 0.7rem;
    }
    
    .result-item .confidence {
        font-size: 0.65rem;
    }
    
    .musical-staff {
        min-width: 400px; /* Even smaller for phones, but still readable */
    }
    
    .musical-staff-container {
        padding: 8px; /* Reduce padding on small screens */
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Fade-in animation */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Gradient animation for background */
@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    25% {
        background-position: 100% 50%;
    }
    50% {
        background-position: 100% 100%;
    }
    75% {
        background-position: 0% 100%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Floating animation for sections */
@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Gradient text animation */
@keyframes gradientText {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Shimmer effect for header */
@keyframes shimmer {
    0% {
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }
    100% {
        transform: translateX(100%) translateY(100%) rotate(45deg);
    }
}

/* Chord controls styling */
.chord-controls {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.chord-controls .btn {
    min-width: 150px;
    margin: 0 5px; /* Add spacing between buttons */
}

.chord-controls .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #666;
}

.chord-controls .btn:disabled:hover {
    background: #666;
    transform: none;
}

/* Chord count styling */
.chord-count {
    font-size: 0.8rem;
    color: #666;
    font-weight: normal;
    margin-left: 8px;
}

/* Arpeggio display styling */
.arpeggio-display {
    font-size: 0.9rem;
    color: #2196F3;
    font-weight: bold;
    margin-left: 12px;
    padding: 4px 8px;
    background: rgba(33, 150, 243, 0.1);
    border-radius: 4px;
    border: 1px solid rgba(33, 150, 243, 0.3);
}

.arpeggio-note {
    display: inline-block;
    padding: 2px 6px;
    margin: 0 2px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.arpeggio-note.current {
    background: #2196F3;
    color: white;
    transform: scale(1.2);
    font-weight: bold;
}

.arpeggio-note.played {
    background: rgba(33, 150, 243, 0.3);
    color: #1976D2;
}
