/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --white-key: #ffffff;
    --white-key-active: #e0e7ff;
    --black-key: #1e293b;
    --black-key-active: #3b82f6;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --border-radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header */
.header {
    text-align: center;
    padding: 1.5rem 1rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Controls Panel */
.controls-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
    align-items: flex-end;
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Select Dropdown */
#instrument-select {
    padding: 0.625rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--surface-light);
    border-radius: var(--border-radius);
    background: var(--surface-light);
    color: var(--text-primary);
    cursor: pointer;
    min-width: 160px;
    transition: border-color 0.2s;
}

#instrument-select:hover,
#instrument-select:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* Octave Controls */
.octave-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface-light);
    padding: 0.25rem;
    border-radius: var(--border-radius);
}

.octave-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: var(--primary-color);
    color: white;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.octave-btn:hover {
    background: var(--primary-hover);
}

.octave-btn:active {
    transform: scale(0.95);
}

#octave-display {
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 2rem;
    text-align: center;
}

/* Volume Slider */
#volume-slider {
    width: 120px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--surface-light);
    border-radius: 3px;
    cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

#volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

#volume-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

#volume-display {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 40px;
}

/* Sustain Button */
.sustain-group {
    align-items: center;
}

.sustain-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: 2px solid var(--surface-light);
    border-radius: var(--border-radius);
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.sustain-btn:hover {
    border-color: var(--primary-color);
}

.sustain-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.sustain-btn.active .sustain-text {
    color: white;
}

.sustain-icon {
    font-size: 1rem;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Piano Container */
.piano-container {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    overflow-x: auto;
}

.octave-labels {
    display: flex;
    justify-content: space-around;
    margin-bottom: 0.5rem;
    padding: 0 2rem;
}

.octave-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.octave-label sub {
    font-size: 0.7rem;
}

/* Piano Keyboard */
.piano {
    display: flex;
    justify-content: center;
    position: relative;
    padding: 0.5rem 0;
    min-width: fit-content;
}

.key {
    position: relative;
    cursor: pointer;
    transition: transform 0.05s, box-shadow 0.05s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.white-key {
    width: 50px;
    height: 200px;
    background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
    border: 1px solid #cbd5e1;
    border-radius: 0 0 6px 6px;
    margin: 0 1px;
    z-index: 1;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.white-key:hover {
    background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
}

.white-key.active {
    background: linear-gradient(180deg, var(--white-key-active) 0%, #c7d2fe 100%);
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.black-key {
    width: 32px;
    height: 120px;
    background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
    border: 1px solid #0f172a;
    border-radius: 0 0 4px 4px;
    position: absolute;
    z-index: 2;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.black-key:hover {
    background: linear-gradient(180deg, #475569 0%, #334155 100%);
}

.black-key.active {
    background: linear-gradient(180deg, var(--black-key-active) 0%, #2563eb 100%);
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Key Labels */
.key-label {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 600;
    color: #64748b;
    pointer-events: none;
}

.black-key .key-label {
    color: #94a3b8;
    bottom: 8px;
    font-size: 0.6rem;
}

.note-label {
    position: absolute;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: #94a3b8;
    pointer-events: none;
}

.black-key .note-label {
    bottom: 24px;
    font-size: 0.55rem;
    color: #64748b;
}

/* Keyboard Guide */
.keyboard-guide {
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.keyboard-guide h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.key-mappings {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.key-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.key-group {
    display: flex;
    gap: 0.25rem;
}

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--surface-light);
    border: 1px solid #475569;
    border-radius: 4px;
    color: var(--text-primary);
}

.key-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Recording Panel */
.recording-panel {
    background: var(--surface);
    padding: 1.25rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.recording-panel h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.recording-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.recording-controls button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.recording-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.record-btn {
    background: var(--surface-light);
    color: var(--text-primary);
}

.record-btn:hover:not(:disabled) {
    background: #475569;
}

.record-btn.recording {
    background: var(--danger);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.record-icon {
    font-size: 0.875rem;
    color: var(--danger);
}

.record-btn.recording .record-icon {
    color: white;
}

.play-btn {
    background: var(--success);
    color: white;
}

.play-btn:hover:not(:disabled) {
    background: #16a34a;
}

.play-btn.playing {
    background: var(--warning);
}

.stop-btn {
    background: var(--surface-light);
    color: var(--text-primary);
}

.stop-btn:hover:not(:disabled) {
    background: #475569;
}

.clear-btn {
    background: var(--surface-light);
    color: var(--text-primary);
}

.clear-btn:hover:not(:disabled) {
    background: var(--danger);
    color: white;
}

.download-btn {
    background: var(--primary-color);
    color: white;
}

.download-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.recording-status {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.recording-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--surface-light);
}

.recording-indicator.active {
    background: var(--danger);
    animation: blink 0.5s infinite;
}

.recording-indicator.playing {
    background: var(--success);
    animation: blink 0.5s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem 1rem;
    margin-top: auto;
    border-top: 1px solid var(--surface-light);
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.footer a:hover {
    color: #60a5fa;
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.75rem;
    }

    .controls-panel {
        padding: 1rem;
        gap: 1rem;
    }

    .control-group {
        flex: 1 1 auto;
        min-width: 140px;
    }

    .piano-container {
        padding: 1rem 0.5rem;
    }

    .white-key {
        width: 36px;
        height: 150px;
    }

    .black-key {
        width: 24px;
        height: 90px;
    }

    .key-label {
        font-size: 0.6rem;
    }

    .black-key .key-label {
        font-size: 0.5rem;
    }

    .note-label {
        display: none;
    }

    .keyboard-guide {
        padding: 1rem;
    }

    .key-mappings {
        flex-direction: column;
    }

    .recording-controls {
        justify-content: center;
    }

    .recording-controls button {
        flex: 1 1 auto;
        justify-content: center;
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 0.5rem;
    }

    .header {
        padding: 1rem 0.5rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .white-key {
        width: 28px;
        height: 120px;
    }

    .black-key {
        width: 18px;
        height: 70px;
    }

    .control-group label {
        font-size: 0.75rem;
    }

    #instrument-select {
        min-width: 120px;
        font-size: 0.875rem;
    }

    #volume-slider {
        width: 80px;
    }

    .recording-controls button span:not(.record-icon):not(.play-icon):not(.stop-icon):not(.clear-icon):not(.download-icon) {
        display: none;
    }

    .recording-controls button {
        min-width: 44px;
        padding: 0.625rem;
    }
}

/* Touch devices */
@media (hover: none) {
    .white-key:hover {
        background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
    }

    .black-key:hover {
        background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus styles */
button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.key:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: -3px;
}
