/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #22c55e;
    --success-hover: #16a34a;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-elevated: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #475569;
    --selection-color: rgba(99, 102, 241, 0.3);
    --waveform-color: #6366f1;
    --playhead-color: #f59e0b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

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

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

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

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

/* Upload Section */
.upload-section {
    padding: 1rem;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--surface);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.upload-area h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.upload-area p {
    color: var(--text-secondary);
}

.supported-formats {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Editor Section */
.editor-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    position: relative;
}

/* File Info */
.file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.file-name {
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 1rem;
}

.btn-icon {
    background: var(--surface-elevated);
    border: none;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--border-color);
}

/* Waveform Container */
.waveform-container {
    position: relative;
    height: 150px;
    background: var(--background);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 0.5rem;
    cursor: crosshair;
}

#waveformCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.selection-overlay {
    position: absolute;
    top: 0;
    height: 100%;
    background: var(--selection-color);
    pointer-events: none;
    border-left: 2px solid var(--primary-color);
    border-right: 2px solid var(--primary-color);
}

.playhead {
    position: absolute;
    top: 0;
    width: 2px;
    height: 100%;
    background: var(--playhead-color);
    pointer-events: none;
    display: none;
}

/* Time Display */
.time-display {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-family: 'Monaco', 'Menlo', monospace;
    margin-bottom: 1.5rem;
}

/* Control Groups */
.control-group {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background);
    border-radius: var(--radius-sm);
}

.control-group h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

/* Range Inputs */
.range-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
}

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

.input-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.input-group input[type="text"],
.input-group input[type="number"] {
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.duration-display {
    padding: 0.75rem;
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
    color: var(--primary-color);
}

/* Loop Controls */
.loop-controls {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.number-input {
    display: flex;
    align-items: stretch;
}

.number-input input {
    width: 60px;
    text-align: center;
    border-radius: 0;
    border-left: none;
    border-right: none;
}

.btn-decrement,
.btn-increment {
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}

.btn-decrement {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.btn-increment {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.btn-decrement:hover,
.btn-increment:hover {
    background: var(--surface-elevated);
}

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

.loop-info strong {
    color: var(--primary-color);
    font-family: 'Monaco', 'Menlo', monospace;
}

/* Fade Controls */
.fade-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

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

.slider-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.slider-group input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--surface);
    border-radius: 3px;
    -webkit-appearance: none;
    appearance: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.slider-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.slider-group span {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-family: 'Monaco', 'Menlo', monospace;
}

/* Playback Controls */
.playback-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-left {
    font-size: 1.1rem;
}

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

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

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

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

.btn-stop {
    background: var(--danger-color);
    color: white;
}

.btn-stop:hover {
    background: var(--danger-hover);
}

.btn-download {
    background: var(--success-color);
    color: white;
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
}

.btn-download:hover {
    background: var(--success-hover);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Download Section */
.download-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.format-select {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.format-select label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.format-select select {
    padding: 0.75rem 1rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.format-select select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Processing Overlay */
.processing-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    z-index: 100;
}

.processing-content {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--surface-elevated);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

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

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

footer a:hover {
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    .app-container {
        padding: 0.5rem;
    }

    header {
        padding: 1.5rem 0.5rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .upload-icon {
        font-size: 3rem;
    }

    .upload-area h2 {
        font-size: 1.25rem;
    }

    .editor-section {
        padding: 1rem;
    }

    .waveform-container {
        height: 120px;
    }

    .control-group {
        padding: 0.75rem;
    }

    .range-inputs {
        grid-template-columns: 1fr;
    }

    .loop-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .fade-controls {
        grid-template-columns: 1fr;
    }

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

    .btn {
        width: 100%;
    }

    .format-select {
        flex-direction: column;
        align-items: flex-start;
    }

    .format-select select {
        width: 100%;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

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

/* Selection */
::selection {
    background: var(--primary-color);
    color: white;
}
