/* CSS Variables for theming */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --accent-primary: #6c5ce7;
    --accent-secondary: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.4);
    --text-primary: #ffffff;
    --text-secondary: #b2b2c8;
    --text-muted: #666680;
    --success: #00d9a6;
    --warning: #ffc107;
    --danger: #ff6b6b;
    --border-color: #333355;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-lg: 12px;
}

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

html {
    font-size: 16px;
}

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

/* App container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header styles */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
}

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

.logo-img {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.transport-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.transport-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.transport-btn:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--accent-glow);
}

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

.transport-btn .hidden {
    display: none;
}

.tempo-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-tertiary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
}

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

.tempo-control input[type="range"] {
    width: 100px;
    accent-color: var(--accent-primary);
}

.tempo-control input[type="number"] {
    width: 60px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.875rem;
}

/* Main content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sample library sidebar */
.sample-library {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sample-library h2 {
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.library-categories {
    display: flex;
    padding: 0.5rem;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.category-btn {
    flex: 1;
    min-width: 60px;
    padding: 0.5rem;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

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

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

.sample-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.sample-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.25rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    cursor: grab;
    transition: all 0.2s ease;
    gap: 0.5rem;
}

.sample-item:hover {
    background: var(--border-color);
    transform: translateX(4px);
}

.sample-item:active {
    cursor: grabbing;
}

.sample-item.dragging {
    opacity: 0.5;
}

.sample-preview-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.sample-name {
    flex: 1;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sample-add-btn {
    width: 28px;
    height: 28px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.sample-add-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.custom-sample {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.custom-sample-btn {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-align: center;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.custom-sample-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Sequencer section */
.sequencer-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1rem;
    background: var(--bg-primary);
}

.pattern-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.pattern-controls h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.pattern-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.pattern-actions select {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius);
    cursor: pointer;
}

.action-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.step-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.step-controls select {
    padding: 0.375rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius);
    cursor: pointer;
}

.step-controls input[type="range"] {
    width: 80px;
    accent-color: var(--accent-primary);
}

#swingValue {
    color: var(--text-muted);
    font-size: 0.75rem;
    min-width: 30px;
}

/* Step sequencer grid */
.step-sequencer {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: auto;
    position: relative;
}

.sequencer-header {
    display: flex;
    position: sticky;
    top: 0;
    background: var(--bg-tertiary);
    z-index: 10;
    border-bottom: 1px solid var(--border-color);
}

.track-label-header {
    width: 120px;
    min-width: 120px;
    padding: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    border-right: 1px solid var(--border-color);
}

.steps-header {
    display: flex;
    flex: 1;
}

.step-number {
    width: 36px;
    min-width: 36px;
    padding: 0.5rem 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.step-number.beat {
    color: var(--accent-secondary);
    font-weight: 600;
}

.track-controls-header {
    width: 60px;
    min-width: 60px;
    padding: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    text-align: center;
    border-left: 1px solid var(--border-color);
}

.sequencer-tracks {
    min-height: 200px;
}

.sequencer-track {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.sequencer-track:hover {
    background: rgba(255, 255, 255, 0.02);
}

.sequencer-track.drop-target {
    background: rgba(108, 92, 231, 0.1);
}

.track-label {
    width: 120px;
    min-width: 120px;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-right: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.track-color {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.track-name {
    flex: 1;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-remove {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sequencer-track:hover .track-remove {
    opacity: 1;
}

.track-remove:hover {
    color: var(--danger);
}

.track-steps {
    display: flex;
    flex: 1;
}

.step-cell {
    width: 36px;
    min-width: 36px;
    height: 44px;
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.1s ease;
    position: relative;
}

.step-cell:nth-child(4n+1) {
    background: rgba(255, 255, 255, 0.02);
}

.step-cell:hover {
    background: rgba(108, 92, 231, 0.2);
}

.step-cell.active {
    background: var(--accent-primary);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

.step-cell.active:hover {
    background: var(--accent-secondary);
}

.step-cell.playing {
    box-shadow: 0 0 10px var(--accent-glow);
}

.track-volume {
    width: 60px;
    min-width: 60px;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.track-volume input[type="range"] {
    width: 50px;
    accent-color: var(--accent-primary);
    transform: rotate(-90deg);
    transform-origin: center;
}

/* Playhead */
.playhead-container {
    position: relative;
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.playhead {
    position: absolute;
    left: 0;
    top: 0;
    width: 2%;
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
    transition: left 0.05s linear;
    box-shadow: 0 0 10px var(--accent-glow);
}

/* Empty state */
.empty-sequencer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.empty-sequencer-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-sequencer p {
    font-size: 0.875rem;
    max-width: 300px;
}

/* Export section */
.export-section {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 1rem 2rem;
}

.export-section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.export-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.export-options {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.export-options select,
.export-options input[type="number"] {
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius);
}

.export-options input[type="number"] {
    width: 60px;
    text-align: center;
}

.export-btn {
    padding: 0.75rem 1.5rem;
    background: var(--success);
    border: none;
    color: var(--bg-primary);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.export-btn:hover {
    background: #00f0b5;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 217, 166, 0.3);
}

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

.export-progress {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.progress-bar {
    width: 200px;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-primary);
    width: 0%;
    transition: width 0.3s ease;
}

#progressText {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Footer */
.app-footer {
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

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

.app-footer a {
    color: var(--accent-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.app-footer a:hover {
    color: var(--accent-primary);
    text-decoration: underline;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow: var(--shadow);
}

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

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

/* Utility classes */
.hidden {
    display: none !important;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Mobile responsive */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .sample-library {
        width: 100%;
        max-height: 250px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .sample-list {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .sample-item {
        flex: 0 0 calc(50% - 0.25rem);
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
        justify-content: center;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .transport-controls {
        width: 100%;
        justify-content: center;
    }

    .tempo-control {
        flex-wrap: wrap;
        justify-content: center;
    }

    .tempo-control input[type="range"] {
        width: 80px;
    }

    .pattern-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .pattern-actions {
        justify-content: center;
    }

    .step-controls {
        flex-wrap: wrap;
        justify-content: center;
    }

    .sample-item {
        flex: 0 0 100%;
    }

    .track-label {
        width: 80px;
        min-width: 80px;
    }

    .track-label-header {
        width: 80px;
        min-width: 80px;
    }

    .step-cell {
        width: 28px;
        min-width: 28px;
        height: 36px;
    }

    .step-number {
        width: 28px;
        min-width: 28px;
    }

    .export-section {
        padding: 1rem;
    }

    .export-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .export-options {
        flex-wrap: wrap;
        justify-content: center;
    }

    .export-btn {
        width: 100%;
    }

    .export-progress {
        flex-direction: column;
    }

    .progress-bar {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .logo-img {
        width: 32px;
        height: 32px;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .transport-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .track-label {
        width: 60px;
        min-width: 60px;
    }

    .track-label-header {
        width: 60px;
        min-width: 60px;
    }

    .track-name {
        font-size: 0.7rem;
    }

    .step-cell {
        width: 24px;
        min-width: 24px;
        height: 32px;
    }

    .step-number {
        width: 24px;
        min-width: 24px;
        font-size: 0.65rem;
    }

    .track-volume {
        width: 40px;
        min-width: 40px;
    }

    .track-controls-header {
        width: 40px;
        min-width: 40px;
    }
}

/* Print styles */
@media print {
    .app-container {
        background: white;
        color: black;
    }

    .transport-controls,
    .sample-library,
    .export-section,
    .modal {
        display: none;
    }
}
