/* =========================================
   Beat Sequencer - Purple/Neon Theme
   ========================================= */

:root {
    /* Purple/Neon palette */
    --purple-primary: #bf5af2;
    --purple-dark: #9b4dca;
    --purple-glow: rgba(191, 90, 242, 0.6);
    --purple-subtle: rgba(191, 90, 242, 0.2);
    
    /* Background colors */
    --bg-dark: #0d0d0f;
    --bg-card: #1a1a1f;
    --bg-cell: #252530;
    --bg-cell-hover: #2f2f3d;
    
    /* Text colors */
    --text-primary: #ffffff;
    --text-secondary: #a0a0a8;
    --text-muted: #606068;
    
    /* Accent colors */
    --accent-active: #bf5af2;
    --accent-highlight: #d88eff;
    --step-highlight: rgba(191, 90, 242, 0.3);
    
    /* Sizes */
    --cell-size: 44px;
    --cell-gap: 4px;
    --border-radius: 8px;
    --border-radius-sm: 4px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

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

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

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

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--purple-primary), var(--accent-highlight));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px var(--purple-glow);
}

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

/* Visualizer Section */
.visualizer-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1rem;
    border: 1px solid var(--purple-subtle);
}

#waveform {
    width: 100%;
    height: 80px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-dark);
}

/* Grid Section */
.grid-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1rem;
    border: 1px solid var(--purple-subtle);
    overflow-x: auto;
}

.grid-container {
    display: flex;
    gap: 0.75rem;
    min-width: max-content;
}

.row-labels {
    display: flex;
    flex-direction: column;
    gap: var(--cell-gap);
    justify-content: center;
    min-width: 60px;
}

.row-labels .label {
    height: var(--cell-size);
    display: flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(16, var(--cell-size));
    grid-template-rows: repeat(6, var(--cell-size));
    gap: var(--cell-gap);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--bg-cell);
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.cell:hover {
    background: var(--bg-cell-hover);
    border-color: var(--purple-subtle);
}

.cell:active {
    transform: scale(0.95);
}

.cell.active {
    background: var(--accent-active);
    border-color: var(--accent-highlight);
    box-shadow: 0 0 15px var(--purple-glow), inset 0 0 10px rgba(255, 255, 255, 0.2);
}

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

/* Current step highlight */
.cell.current-step {
    background: var(--step-highlight);
    border-color: var(--purple-primary);
}

.cell.active.current-step {
    background: var(--accent-highlight);
    box-shadow: 0 0 25px var(--purple-glow), 0 0 50px var(--purple-glow), inset 0 0 15px rgba(255, 255, 255, 0.3);
    animation: pulse 0.15s ease-out;
}

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

/* Bar dividers */
.cell:nth-child(16n+5),
.cell:nth-child(16n+9),
.cell:nth-child(16n+13) {
    margin-left: 4px;
}

/* Step indicators */
.step-indicators {
    display: flex;
    gap: var(--cell-gap);
    margin-top: 0.5rem;
    padding-left: calc(60px + 0.75rem);
}

.step-indicator {
    width: var(--cell-size);
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 500;
}

.step-indicator:nth-child(4n+5),
.step-indicator:nth-child(4n+9),
.step-indicator:nth-child(4n+13) {
    margin-left: 4px;
}

.step-indicator.current {
    color: var(--purple-primary);
    font-weight: 700;
}

/* Controls Section */
.controls-section {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--purple-subtle);
}

/* Buttons */
.btn {
    min-width: 80px;
    min-height: var(--cell-size);
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--purple-primary);
    color: var(--text-primary);
    box-shadow: 0 0 20px var(--purple-glow);
    min-width: 100px;
}

.btn-primary:hover {
    background: var(--accent-highlight);
    box-shadow: 0 0 30px var(--purple-glow);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary.playing {
    background: #ff6b6b;
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.5);
}

.btn-primary.playing:hover {
    background: #ff8787;
}

.btn-primary.playing .play-icon {
    display: none;
}

.btn-primary.playing .btn-text::before {
    content: '⏹ ';
}

.btn-secondary {
    background: var(--bg-cell);
    color: var(--text-secondary);
    border: 1px solid var(--purple-subtle);
}

.btn-secondary:hover {
    background: var(--bg-cell-hover);
    color: var(--text-primary);
    border-color: var(--purple-primary);
}

.btn-accent {
    background: transparent;
    color: var(--purple-primary);
    border: 1px solid var(--purple-primary);
}

.btn-accent:hover {
    background: var(--purple-subtle);
    color: var(--accent-highlight);
}

/* BPM Control */
.bpm-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 150px;
}

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

#bpm-value {
    color: var(--purple-primary);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Range Slider */
.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--bg-cell);
    border-radius: 4px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--purple-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px var(--purple-glow);
    transition: all var(--transition-fast);
}

.slider::-webkit-slider-thumb:hover {
    background: var(--accent-highlight);
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--purple-primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px var(--purple-glow);
}

/* Control groups */
.transport-controls,
.pattern-controls,
.storage-controls {
    display: flex;
    gap: 0.5rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Start Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 13, 15, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    position: relative;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--purple-primary), var(--accent-highlight));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.pulse-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 150px;
    height: 150px;
    border: 2px solid var(--purple-primary);
    border-radius: 50%;
    animation: pulse-expand 2s ease-out infinite;
    pointer-events: none;
}

@keyframes pulse-expand {
    0% {
        width: 100px;
        height: 100px;
        opacity: 0.8;
    }
    100% {
        width: 200px;
        height: 200px;
        opacity: 0;
    }
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--purple-primary);
    box-shadow: 0 0 20px var(--purple-glow);
    z-index: 1001;
    transition: transform 0.3s ease;
    font-size: 0.875rem;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    :root {
        --cell-size: 40px;
    }
    
    .container {
        padding: 0.75rem;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .row-labels {
        min-width: 50px;
    }
    
    .row-labels .label {
        font-size: 0.65rem;
    }
    
    .step-indicators {
        padding-left: calc(50px + 0.75rem);
    }
    
    .controls-section {
        gap: 0.75rem;
    }
    
    .bpm-control {
        min-width: 120px;
        order: -1;
        width: 100%;
    }
}

@media (max-width: 480px) {
    :root {
        --cell-size: 36px;
        --cell-gap: 3px;
    }
    
    header {
        padding: 1rem 0;
    }
    
    .row-labels {
        min-width: 45px;
    }
    
    .btn {
        min-width: 70px;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
    
    footer {
        font-size: 0.7rem;
    }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 0.5rem 0;
    }
    
    header h1 {
        font-size: 1.25rem;
    }
    
    main {
        gap: 0.75rem;
    }
    
    .visualizer-section {
        padding: 0.5rem;
    }
    
    #waveform {
        height: 50px;
    }
    
    footer {
        padding: 0.5rem;
    }
}

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

/* Focus styles for keyboard navigation */
.btn:focus-visible,
.cell:focus-visible,
.slider:focus-visible {
    outline: 2px solid var(--accent-highlight);
    outline-offset: 2px;
}
