/* Mobile Responsive Design for Sound-Responsive Fireworks App */

/* Prevent horizontal scrolling on all devices */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    height: 100%;
}

/* Additional global overflow prevention */
html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

/* Base mobile-first approach with improved breakpoints */
@media (max-width: 768px) {
    /* Remove any default margins that might cause overflow */
    html, body {
        margin: 0;
        padding: 0;
        overflow-x: hidden;
        height: 100vh;
        position: relative;
    }

    /* Body and general layout fixes */
    body {
        padding: 8px !important;
        width: 100%;
        max-width: 100vw;
        font-size: 14px;
        overflow-x: hidden;
        overflow-y: auto;
        box-sizing: border-box;
        margin: 0 auto;
        height: 100vh;
    }

    /* App container - Stack everything vertically on mobile with proper height */
    .app-container {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        grid-template-areas: none !important;
        gap: 12px;
        padding: 8px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
        height: calc(100vh - 16px);
        overflow-y: auto;
    }

    /* Control panel - Make buttons properly centered and handle hide/show */
    .control-panel {
        flex: 0 0 auto;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: stretch;
        gap: 8px;
        padding: 12px;
        margin: 0 auto;
        width: calc(100% - 16px);
        max-width: 400px;
        box-sizing: border-box;
        background-color: #1e1e1e;
        border-radius: 12px;
    }

    .control-panel button {
        flex: 1 1 calc(50% - 4px);
        min-width: calc(50% - 4px);
        max-width: calc(50% - 4px);
        height: 60px;
        padding: 8px 6px;
        font-size: 12px;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border-radius: 8px;
        border: none;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    /* When buttons are hidden, adjust layout for remaining visible buttons */
    .control-panel:has(button.is-hidden) button:not(.is-hidden) {
        flex: 1 1 calc(50% - 6px); /* Corrected for 12px gap when 2 buttons side-by-side in 2x1 */
        min-width: calc(50% - 6px);
        max-width: calc(50% - 6px);
    }

    /* If only 2 buttons visible (specifically #togglePanels and #testFirework), arrange them in a 1x2 centered row */
    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) {
        flex-wrap: nowrap; /* Keep them in a single row */
        justify-content: center;
        gap: 12px; /* Maintain consistent gap */
        max-width: fit-content; /* Panel shrinks to content */
        padding: 12px; /* Ensure consistent padding */
        margin: 0 auto; /* Keep the shrunk panel centered */
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) button:not(.is-hidden) {
        flex: 0 1 auto; /* Allow buttons to size based on content, but don't grow excessively */
        min-width: 100px; /* Minimum width for touch target and text */
        /* max-width is removed as panel is fit-content */
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) #testFirework {
        order: 1; /* Test button first */
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) #togglePanels {
        order: 2; /* Show/Hide button second */
    }

    /* If only 2 buttons visible, center them properly */
    .control-panel button.is-hidden {
        display: none !important;
    }

    /* Ensure visible buttons are properly spaced when some are hidden (default 2x1 or 1x2 for specific case) */
    .control-panel:has(.is-hidden) {
        justify-content: center;
        gap: 12px;
    }

    .control-panel button .icon {
        display: block;
        font-size: 20px;
        line-height: 1;
        margin: 0;
    }

    .control-panel button .text {
        display: block;
        font-size: 11px;
        line-height: 1;
        margin: 0;
        font-weight: 500;
    }

    /* Specific button colors for mobile */
    .control-panel button#startMicrophone {
        background-color: #2ecc71;
        color: #ffffff;
    }

    .control-panel button#startMicrophone:active {
        background-color: #27ae60;
    }

    .control-panel button#testFirework {
        background-color: #9b59b6;
        color: #ffffff;
    }

    .control-panel button#testFirework:active {
        background-color: #8e44ad;
    }

    .control-panel button#toggleSettings {
        background-color: #3498db;
        color: #ffffff;
    }

    .control-panel button#toggleSettings:active {
        background-color: #2980b9;
    }

    .control-panel button#togglePanels {
        background-color: #95a5a6;
        color: #ffffff;
    }

    .control-panel button#togglePanels:active {
        background-color: #7f8c8d;
    }

    /* Uploader tabs - Stack navigation and make touch-friendly */
    .uploader-tabs-container {
        flex: 1 1 auto;
        margin-bottom: 0;
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .uploader-tab-navigation {
        flex: 0 0 auto;
        display: flex;
        flex-direction: row;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .uploader-tab-button {
        flex: 1;
        padding: 12px 8px;
        font-size: 13px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-height: 44px; /* Touch-friendly height */
        box-sizing: border-box;
    }

    .uploader-tab-content {
        flex: 1 1 auto;
        overflow: hidden;
        min-height: 0;
    }

    .uploader-tab-pane {
        height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Upload areas - Make them more touch-friendly */
    .upload-area {
        padding: 16px 12px;
        min-height: 100px;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        box-sizing: border-box;
    }

    .upload-content {
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .upload-content p {
        font-size: 13px;
        word-wrap: break-word;
        margin: 4px 0;
    }

    .upload-content button {
        min-width: 140px;
        max-width: calc(100% - 20px);
        padding: 12px 20px;
        font-size: 14px;
        min-height: 44px; /* Touch-friendly */
        box-sizing: border-box;
    }

    /* Preview containers - Responsive grid */
    .preview-container {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 8px;
        max-height: 200px;
        overflow-y: auto;
        overflow-x: hidden;
        width: 100%;
        box-sizing: border-box;
        padding: 8px;
    }

    .image-preview {
        width: 100%;
        height: 100px;
        min-width: 100px;
        box-sizing: border-box;
    }

    /* Remove buttons - Make them larger for touch */
    .remove-preview, .remove-background {
        width: 32px;
        height: 32px;
        font-size: 20px;
        top: 5px;
        right: 5px;
    }

    /* Audio visualizer - Compact mobile layout with proper alignment */
    .audio-visualizer {
        flex: 0 0 auto;
        padding: 12px;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
        min-height: 120px;
        max-height: 150px;
    }

    .volume-meter {
        height: 8px;
        margin-bottom: 10px;
        width: 100%;
        box-sizing: border-box;
    }

    #audioStatus {
        font-size: 13px;
        margin-bottom: 8px;
        word-wrap: break-word;
    }

    .mic-test {
        margin-top: 10px;
        padding-top: 8px;
    }

    .mic-test p {
        font-size: 11px;
        line-height: 1.3;
        word-wrap: break-word;
        margin-bottom: 8px;
    }

    .mic-detection {
        font-size: 11px;
        padding: 6px 10px;
        word-wrap: break-word;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Ensure all containers respect viewport width */
    .image-upload-container,
    .background-upload-container {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
        height: 100%;
        display: flex;
        flex-direction: column;
        padding: 12px;
    }

    .uploader-tab-content,
    .uploader-tab-pane {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
}

/* Settings panel mobile optimizations */
@media (max-width: 768px) {
    .settings-panel {
        width: 95vw !important;
        max-width: 95vw !important;
        height: 90vh;
        max-height: 90vh;
        top: 5vh;
        left: 50%;
        transform: translateX(-50%);
        padding: 16px;
        border-radius: 8px;
        box-sizing: border-box;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .settings-panel h2 {
        font-size: 18px;
        margin-bottom: 15px;
        word-wrap: break-word;
        flex: 0 0 auto;
    }

    /* Tab navigation - Horizontal scroll for many tabs */
    .tab-navigation {
        flex: 0 0 auto;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: none;
        -ms-overflow-style: none;
        margin-bottom: 15px;
        padding-bottom: 5px;
        width: 100%;
        box-sizing: border-box;
    }

    .tab-navigation::-webkit-scrollbar {
        display: none;
    }

    .tab-button {
        font-size: 12px;
        padding: 10px 6px;
        min-width: 70px;
        flex: 0 0 auto;
        margin: 0 1px;
        box-sizing: border-box;
    }

    /* Settings content */
    .tab-content {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        width: 100%;
        box-sizing: border-box;
        min-height: 0;
    }

    .setting {
        margin-bottom: 20px;
        width: 100%;
        box-sizing: border-box;
    }

    .setting label {
        font-size: 14px;
        margin-bottom: 8px;
        word-wrap: break-word;
    }

    .setting-description {
        font-size: 11px;
        line-height: 1.3;
        word-wrap: break-word;
    }

    /* Range sliders - Make them more touch-friendly */
    input[type="range"] {
        height: 8px;
        margin: 15px 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
        -webkit-appearance: none;
    }

    input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
        border: none;
    }

    /* Toggle switches - Make them larger */
    .switch {
        width: 50px;
        height: 26px;
        flex-shrink: 0;
    }

    .slider:before {
        height: 20px;
        width: 20px;
        left: 2px;
        bottom: 2px;
    }

    input:checked + .slider:before {
        transform: translateX(22px);
    }

    /* Settings controls */
    .settings-controls {
        flex: 0 0 auto;
        margin-top: 15px;
        padding-top: 15px;
        flex-direction: column;
        gap: 10px;
        width: 100%;
        box-sizing: border-box;
    }

    .settings-btn {
        min-height: 44px;
        font-size: 14px;
        width: 100%;
        box-sizing: border-box;
    }

    /* Color picker improvements */
    .color-picker-container {
        flex-direction: column;
        gap: 10px;
        width: 100%;
        box-sizing: border-box;
    }

    #colorPicker {
        width: 100%;
        height: 50px;
        box-sizing: border-box;
    }

    #addColor {
        height: 44px;
        font-size: 14px;
        width: 100%;
        box-sizing: border-box;
    }

    .custom-colors-list {
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .color-swatch {
        width: 40px;
        height: 40px;
        flex-shrink: 0;
    }

    .color-swatch button {
        width: 18px;
        height: 18px;
        font-size: 12px;
        top: 1px;
        right: 1px;
    }

    /* Ensure select elements fit properly */
    select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

/* Extra small phones - Portrait orientation */
@media (max-width: 480px) {
    body {
        padding: 5px !important;
        font-size: 13px;
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
        height: 100vh;
    }

    .app-container {
        gap: 8px;
        padding: 5px;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 10px);
    }

    /* Control panel - Stack buttons 2x2 with better spacing */
    .control-panel {
        padding: 10px;
        gap: 6px; /* Default gap when all 4 buttons are shown */
        width: calc(100% - 10px);
        max-width: 350px;
        margin: 0 auto;
        background-color: #1e1e1e;
        border-radius: 10px;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: stretch;
    }

    .control-panel button {
        flex: 1 1 calc(50% - 3px); /* Correct for 6px default gap */
        min-width: calc(50% - 3px);
        max-width: calc(50% - 3px);
        height: 55px;
        padding: 6px 4px;
        font-size: 11px;
        font-weight: 500;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border-radius: 6px;
        box-sizing: border-box;
        border: none;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    /* Handle hidden buttons for 480px screens */
    .control-panel:has(.is-hidden) { /* Added/Ensured this rule with correct gap */
        justify-content: center;
        gap: 10px; /* Set gap to 10px when buttons are hidden (default 2x1 or 1x2 specific case) */
    }

    .control-panel:has(button.is-hidden) button:not(.is-hidden) {
        flex: 1 1 calc(50% - 5px); /* This is now correct for the 10px gap (default 2x1) */
        min-width: calc(50% - 5px);
        max-width: calc(50% - 5px);
    }

    /* Specific 1x2 layout for #togglePanels and #testFirework at 480px */
    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) {
        flex-wrap: nowrap;
        gap: 10px; /* Keep consistent gap */
        max-width: fit-content; /* Panel shrinks to content */
        padding: 10px; /* Ensure consistent padding */
        margin: 0 auto;
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) button:not(.is-hidden) {
        flex: 0 1 auto;
        min-width: 90px;
        /* max-width removed */
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) #testFirework {
        order: 1;
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) #togglePanels {
        order: 2;
    }

    .audio-visualizer {
        padding: 10px;
        width: 100%;
        min-height: 100px;
        max-height: 120px;
    }

    .volume-meter {
        height: 6px;
        width: 100%;
    }

    .mic-test p {
        font-size: 10px;
        margin-bottom: 6px;
    }

    .mic-detection {
        font-size: 10px;
        padding: 5px 8px;
    }

    /* Upload areas - Smaller */
    .upload-area {
        padding: 12px 8px;
        min-height: 80px;
        width: 100%;
    }

    .upload-content p {
        font-size: 12px;
        margin: 3px 0;
    }

    .upload-content button {
        min-width: 120px;
        max-width: calc(100% - 16px);
        padding: 10px 16px;
        font-size: 13px;
    }

    /* Preview grid - Smaller items */
    .preview-container {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 6px;
        max-height: 160px;
        width: 100%;
        padding: 6px;
    }

    .image-preview {
        height: 80px;
        min-width: 80px;
        width: 100%;
    }

    /* Settings panel - Full screen on very small devices */
    .settings-panel {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
        border-radius: 0 !important;
        padding: 12px;
        box-sizing: border-box;
    }

    .tab-button {
        font-size: 11px;
        padding: 8px 4px;
        min-width: 60px;
    }

    .tab-content {
        width: 100%;
    }

    /* Handle hidden buttons for 480px screens */
    .control-panel:has(button.is-hidden) button:not(.is-hidden) {
        flex: 1 1 calc(50% - 5px);
        min-width: calc(50% - 5px);
        max-width: calc(50% - 5px);
    }
}

/* Landscape orientation optimizations for mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .app-container {
        height: calc(100vh - 16px);
    }

    .settings-panel {
        width: 85vw !important;
        height: 95vh !important;
        max-height: 95vh !important;
    }

    /* Make control panel more compact in landscape */
    .control-panel {
        flex-direction: row;
        justify-content: space-evenly;
        width: 100%;
    }

    .control-panel button {
        flex: 1 1 auto;
        max-width: 120px;
        margin: 0 2px;
    }

    /* Audio visualizer - Side by side with uploader in landscape */
    .audio-visualizer {
        min-height: 80px;
        max-height: 100px;
        width: 100%;
    }

    .uploader-tabs-container {
        flex: 1 1 auto;
    }
}

/* Canvas responsive adjustments */
@media (max-width: 768px) {
    #animationCanvas {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 0 !important;
        pointer-events: none !important;
    }
}

/* Fix for very small screens - ensure UI elements are usable */
@media (max-width: 360px) {
    body {
        width: 100vw;
        max-width: 100vw;
        padding: 3px !important;
        height: 100vh;
    }

    .app-container {
        width: 100%;
        max-width: 100%;
        padding: 3px;
        height: calc(100vh - 6px);
    }

    .control-panel {
        padding: 8px;
        gap: 4px; /* Default gap when all 4 buttons are shown */
        width: calc(100% - 6px);
        max-width: 300px;
        margin: 0 auto;
        border-radius: 8px;
        justify-content: center;
        display: flex; /* Ensure flex properties */
        flex-wrap: wrap;
        align-items: stretch;
    }

    .control-panel button {
        flex: 1 1 calc(50% - 2px); /* Corrected for 4px default gap */
        min-width: calc(50% - 2px);
        max-width: calc(50% - 2px);
        height: 50px;
        font-size: 10px;
        padding: 6px 3px;
        /* gap below is for icon/text inside button, not between buttons */
        gap: 2px; 
        border-radius: 6px;
        /* Other properties like display:flex for content, box-sizing, etc., are inherited */
    }

    .upload-content button {
        min-width: 100px;
        max-width: calc(100% - 12px);
        font-size: 12px;
    }

    .image-preview {
        height: 70px;
        min-width: 70px;
        width: 100%;
    }

    .preview-container {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
        width: 100%;
        max-height: 140px;
    }
    
    .audio-visualizer {
        min-height: 80px;
        max-height: 100px;
    }

    /* Handle hidden buttons for very small screens */
    .control-panel:has(.is-hidden) { /* Added this rule */
        justify-content: center;
        gap: 8px; /* Set gap to 8px when buttons are hidden (default 2x1 or 1x2 specific case) */
    }

    .control-panel:has(button.is-hidden) button:not(.is-hidden) {
        flex: 1 1 calc(50% - 4px); /* This is now correct for the 8px gap (default 2x1) */
        min-width: calc(50% - 4px);
        max-width: calc(50% - 4px);
        /* height, padding, font-size etc. are inherited from .control-panel button at 360px */
    }

    /* Specific 1x2 layout for #togglePanels and #testFirework at 360px */
    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) {
        flex-wrap: nowrap;
        gap: 8px; /* Keep consistent gap */
        max-width: fit-content; /* Panel shrinks to content */
        padding: 8px; /* Ensure consistent padding */
        margin: 0 auto;
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) button:not(.is-hidden) {
        flex: 0 1 auto;
        min-width: 80px;
        /* max-width removed */
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) #testFirework {
        order: 1;
    }

    .control-panel:has(#startMicrophone.is-hidden):has(#toggleSettings.is-hidden):not(:has(#togglePanels.is-hidden)):not(:has(#testFirework.is-hidden)) #togglePanels {
        order: 2;
    }
    /* button.is-hidden is inherited: display: none !important; */
}

/* Touch-friendly interactions */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    button:hover {
        transform: none !important;
    }

    .upload-content button:hover {
        transform: none !important;
    }

    .remove-preview:hover,
    .remove-background:hover {
        transform: none !important;
    }

    /* Add active states for touch feedback */
    button:active {
        transform: scale(0.95) !important;
        transition: transform 0.1s ease !important;
    }

    .upload-content button:active {
        transform: scale(0.95) !important;
    }
}

/* High-DPI screen optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .remove-preview,
    .remove-background {
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .color-swatch {
        border-width: 1px;
    }
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) {
    /* Ensure sufficient contrast and touch target sizes */
    button, .upload-content button, .tab-button {
        min-height: 44px;
        min-width: 44px;
    }

    /* Improve focus visibility */
    button:focus,
    .tab-button:focus,
    input[type="range"]:focus {
        outline: 2px solid #4CAF50;
        outline-offset: 2px;
    }

    /* Better text readability */
    .setting-description {
        line-height: 1.4;
    }

    .mic-test p {
        line-height: 1.4;
    }
}

/* Additional overflow fixes */
@media (max-width: 768px) {
    * {
        box-sizing: border-box !important;
    }
    
    /* Prevent any element from causing horizontal overflow */
    .app-container > * {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* File input text */
    .file-types {
        word-wrap: break-word;
        overflow-wrap: break-word;
        margin: 4px 0;
    }
    
    /* Settings panel content */
    .settings-panel * {
        max-width: 100%;
        word-wrap: break-word;
    }
    
    /* Toggle setting layout fix */
    .toggle-setting {
        display: flex !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .toggle-setting > label[for] {
        flex: 1 1 auto;
        margin-right: 10px;
    }
    
    .toggle-setting > .switch {
        flex: 0 0 auto;
    }
}

/* Print styles - hide interactive elements */
@media print {
    .control-panel,
    .settings-panel,
    .uploader-tabs-container {
        display: none !important;
    }
    
    .audio-visualizer {
        page-break-inside: avoid;
    }
}

/* Fallback for browsers that don't support :has() selector */
.control-panel button.hidden,
.control-panel button[style*="display: none"],
.control-panel button[style*="display:none"] {
    display: none !important;
}

/* When any button has hidden class, adjust remaining buttons */
.control-panel.has-hidden-buttons {
    justify-content: center;
    gap: 12px;
}

.control-panel.has-hidden-buttons button:not(.hidden):not([style*="display: none"]) {
    flex: 1 1 calc(50% - 6px);
    min-width: calc(50% - 6px);
    max-width: calc(50% - 6px);
} 