/* ============================================
   Responsive Design - Mobile First
   ============================================ */

/* Touch-friendly defaults */
@media (pointer: coarse) {
    .step,
    .drum-step {
        min-height: 44px;
        min-width: 44px;
    }
    
    .track-controls button {
        min-width: 44px;
        min-height: 44px;
        font-size: 12px;
    }
    
    .btn-euc {
        min-width: 44px;
        min-height: 44px;
    }
    
    .corner-btn {
        width: 80px;
        height: 80px;
    }
}

/* ============================================
   Mobile (< 768px)
   ============================================ */
@media screen and (max-width: 767px) {
    :root {
        --gap-sm: 6px;
        --gap-md: 10px;
        --gap-lg: 14px;
    }
    
    /* Persistent Play Button */
    #play-container {
        top: 10px;
        z-index: 1101;
    }
    
    #play-container .play-btn {
        width: 50px;
        height: 50px;
    }
    
    #play-container .play-icon {
        font-size: 20px;
    }
    
    /* Global Controls */
    #global-controls[data-state="expanded"] {
        width: calc(100% - 20px);
        max-width: none;
        top: 80px;
        left: 10px;
        right: 10px;
        transform: none;
        max-height: 60vh;
    }
    
    #global-controls[data-state="docked"] {
        left: 5px;
        width: 45px;
    }
    
    .expanded-content {
        padding: var(--gap-sm);
    }
    
    .transport-section {
        padding-left: 0;
        flex-direction: column;
        gap: var(--gap-sm);
    }
    
    .master-sliders {
        flex-wrap: wrap;
    }
    
    .master-slider input[type="range"] {
        width: 50px;
    }
    
    .randomize-buttons,
    .genre-buttons {
        gap: 4px;
    }
    
    .btn-master-action,
    .btn-genre-preset {
        padding: 5px 8px;
        font-size: 10px;
    }
    
    /* Quantization sections responsive */
    .quantize-grid-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .btn-quantize-grid {
        padding: 5px 8px;
        font-size: 10px;
        min-width: 32px;
    }
    
    .scale-row,
    .chord-header {
        flex-direction: column;
        gap: 6px;
    }
    
    .omnichord-grid {
        overflow-x: auto;
    }
    
    .chord-row {
        min-width: 280px;
    }
    
    .btn-chord {
        padding: 5px 1px;
        font-size: 8px;
        min-width: 26px;
    }
    
    .btn-toggle {
        font-size: 10px;
        padding: 4px 8px;
    }
    
    .quantize-select {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    .tempo-control,
    .swing-control {
        flex-direction: row;
        width: 100%;
        justify-content: space-between;
    }
    
    .tempo-control input[type="range"],
    .swing-control input[type="range"] {
        flex: 1;
        margin: 0 8px;
    }
    
    /* Main Sequencer */
    #main-sequencer {
        padding: 80px 10px 100px;
        gap: var(--gap-md);
    }
    
    .sequencer-track {
        padding: var(--gap-sm);
    }
    
    /* Track Header */
    .track-header {
        flex-direction: column;
        gap: var(--gap-sm);
        align-items: flex-start;
    }
    
    .track-label {
        width: 100%;
        justify-content: space-between;
    }
    
    .track-preset {
        width: 100%;
    }
    
    .preset-select {
        flex: 1;
    }
    
    /* Sequencer Grid - Keep 2x8 but smaller */
    .sequencer-grid {
        gap: 3px;
        padding: var(--gap-xs);
    }
    
    .step {
        min-height: 32px;
    }
    
    /* Effects - Horizontal scroll */
    .track-effects {
        overflow-x: auto;
        flex-wrap: nowrap;
        justify-content: flex-start;
        padding-bottom: var(--gap-sm);
        -webkit-overflow-scrolling: touch;
    }
    
    .effect-slider {
        min-width: 45px;
        flex-shrink: 0;
    }
    
    /* Track Controls - Wrap tighter */
    .track-controls {
        gap: 4px;
    }
    
    .track-controls button {
        min-width: 40px;
        height: 34px;
        font-size: 13px;
        padding: 0 5px;
    }
    
    /* Corner Buttons */
    .corner-btn {
        width: 70px;
        height: 70px;
        font-size: 11px;
        bottom: 15px;
    }
    
    .corner-btn-left {
        left: 15px;
    }
    
    .corner-btn-right {
        right: 15px;
    }
    
    .corner-btn-topleft {
        top: 10px;
        left: 10px;
        width: 60px;
        height: 60px;
        font-size: 10px;
    }
    
    /* Mixer Panel - Full screen overlay */
    #mixer-panel[data-state="expanded"] {
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        transform: none;
        border-radius: 0;
        z-index: 1000;
    }
    
    .mixer-channels {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
    }
    
    .channel-fader {
        height: 80px;
    }
    
    /* Mixer Docked - Narrower */
    #mixer-panel[data-state="docked"] {
        width: 40px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    .docked-mute {
        width: 32px;
        height: 32px;
        font-size: 9px;
    }
    
    /* Drum Panel - Full screen overlay */
    #drum-panel[data-state="expanded"] {
        width: 100%;
        height: 100%;
        top: 0;
        right: 0;
        transform: none;
        border-radius: 0;
        max-height: 100%;
        z-index: 1000;
    }
    
    .drum-grid {
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: repeat(2, 1fr);
    }
    
    .drum-step {
        min-width: 24px;
        min-height: 24px;
    }
    
    /* Drum Docked */
    #drum-panel[data-state="docked"] {
        width: 60px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    .mute-group {
        width: 52px;
        font-size: 8px;
        padding: 6px 2px;
    }
    
    /* Audio Start Overlay */
    .start-content {
        padding: 24px;
        margin: 10px;
    }
    
    .start-content h1 {
        font-size: 24px;
    }
    
    .marquee {
        width: 250px;
    }
    
    #start-audio-btn {
        padding: 12px 30px;
        font-size: 12px;
    }
}

/* ============================================
   Small Mobile (< 400px)
   ============================================ */
@media screen and (max-width: 399px) {
    .track-name {
        font-size: 10px;
    }
    
    .vu-meter {
        width: 40px;
        height: 16px;
    }
    
    .preset-select {
        font-size: 12px;
        min-width: 90px;
    }
    
    .effect-slider label {
        font-size: 6px;
    }
    
    .effect-slider input[type="range"] {
        width: 40px;
    }
    
    .track-controls button {
        min-width: 36px;
        height: 32px;
        font-size: 12px;
    }
    
    .step {
        min-height: 28px;
    }
    
    .corner-btn {
        width: 60px;
        height: 60px;
        font-size: 10px;
    }
}

/* ============================================
   Tablet (768px - 1023px)
   ============================================ */
@media screen and (min-width: 768px) and (max-width: 1023px) {
    #play-container {
        top: 12px;
    }
    
    .corner-btn-topleft {
        top: 12px;
        left: 12px;
        width: 70px;
        height: 70px;
    }
    
    #global-controls[data-state="expanded"] {
        max-width: 450px;
        top: 100px;
        right: 60px;
        left: auto;
    }
    
    .master-sliders {
        gap: var(--gap-sm);
    }
    
    .genre-buttons {
        gap: 4px;
    }
    
    .btn-genre-preset {
        padding: 5px 8px;
        font-size: 10px;
    }
    
    #main-sequencer {
        padding: 80px 30px 120px;
        max-width: 800px;
    }
    
    /* Mixer Panel */
    #mixer-panel[data-state="expanded"] {
        width: 350px;
    }
    
    .mixer-channels {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .channel-fader {
        height: 90px;
    }
    
    /* Drum Panel */
    #drum-panel[data-state="expanded"] {
        width: 480px;
    }
}

/* ============================================
   Desktop (1024px+)
   ============================================ */
@media screen and (min-width: 1024px) {
    #global-controls[data-state="expanded"] {
        min-width: 550px;
        max-width: 700px;
    }
    
    .window-content.expanded-content {
        gap: var(--gap-md);
    }
    
    #main-sequencer {
        max-width: 950px;
        padding-top: 100px;
    }
    
    .sequencer-grid {
        gap: 6px;
    }
    
    .step {
        min-height: 44px;
    }
    
    /* Mixer full width */
    #mixer-panel[data-state="expanded"] {
        width: 420px;
    }
    
    .channel-fader {
        height: 120px;
    }
    
    /* Drum Panel */
    #drum-panel[data-state="expanded"] {
        width: 520px;
    }
    
    .drum-step {
        min-width: 22px;
        min-height: 22px;
    }
}

/* ============================================
   Large Desktop (1400px+)
   ============================================ */
@media screen and (min-width: 1400px) {
    #main-sequencer {
        max-width: 1100px;
    }
    
    .sequencer-track {
        padding: var(--gap-lg);
    }
    
    .step {
        min-height: 50px;
    }
    
    .track-controls button {
        min-width: 40px;
        height: 30px;
    }
}

/* ============================================
   Landscape Phone
   ============================================ */
@media screen and (max-width: 900px) and (orientation: landscape) {
    #play-container {
        top: 5px;
    }
    
    .corner-btn-topleft {
        top: 5px;
        left: 5px;
        width: 50px;
        height: 50px;
        font-size: 9px;
    }
    
    #global-controls[data-state="expanded"] {
        top: 60px;
        right: 60px;
        left: auto;
        max-height: calc(100vh - 70px);
        overflow-y: auto;
        max-width: 400px;
    }
    
    .window-titlebar {
        padding: 2px 8px;
    }
    
    .expanded-content {
        padding: 6px;
    }
    
    .play-btn {
        width: 40px;
        height: 40px;
    }
    
    .play-icon {
        font-size: 16px;
    }
    
    #main-sequencer {
        padding-top: 60px;
        padding-bottom: 80px;
    }
    
    .sequencer-track {
        padding: 6px;
    }
    
    .track-header {
        flex-direction: row;
    }
    
    .corner-btn {
        width: 50px;
        height: 50px;
        bottom: 10px;
    }
    
    /* Panels slide from side */
    #mixer-panel[data-state="expanded"],
    #drum-panel[data-state="expanded"] {
        width: 50%;
        height: 100%;
        top: 0;
        transform: none;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .bg-layer {
        animation: none;
    }
    
    .marquee span {
        animation: none;
    }
}

/* ============================================
   High Contrast Mode
   ============================================ */
@media (prefers-contrast: high) {
    :root {
        --bg-dark: #000;
        --bg-mid: #111;
        --chrome-light: #fff;
    }
    
    .step.active,
    .drum-step.active {
        border: 3px solid #fff;
    }
    
    button {
        border-width: 3px;
    }
}

/* ============================================
   Dark Mode (default, but explicit)
   ============================================ */
@media (prefers-color-scheme: dark) {
    /* Already dark by default */
}

/* ============================================
   Print Styles (just in case)
   ============================================ */
@media print {
    body {
        background: white;
        color: black;
    }
    
    .bg-layer,
    #audio-start-overlay,
    .corner-btn,
    .panel {
        display: none;
    }
}
