/* Simplified Control Panel Layout
   - Consistent layout across all states
   - No complex button hiding/showing
   - Better responsive design
   - Cleaner code structure
*/

/* ===== MODE TOGGLE BUTTON ===== */
#modeToggleButton {
    background-color: #e74c3c;
}

#modeToggleButton:hover:not(:disabled) {
    background-color: #c0392b;
}

#modeToggleButton.bubble-mode {
    background-color: #3498db;
}

#modeToggleButton.bubble-mode:hover:not(:disabled) {
    background-color: #2980b9;
}

/* ===== LANGUAGE SWITCHER DROPDOWN ===== */
.language-switcher-dropdown {
    position: relative;
    z-index: 100;
    /* Desktop positioning: align to right above uploader container */
    position: fixed;
    top: 20px;
    right: 20px;
    pointer-events: auto;
}

.language-switcher-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background-color: #2c2c2c;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    min-width: 120px;
    font-size: 14px;
    font-weight: 500;
}

.language-switcher-button:hover {
    background-color: #3c3c3c;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.language-switcher-button .language-icon {
    font-size: 18px;
}

.language-switcher-button .current-language-text {
    flex: 1;
    text-align: left;
}

.language-switcher-button .dropdown-arrow {
    font-size: 12px;
    transition: transform 0.2s ease;
}

.language-switcher-button[aria-expanded="true"] .dropdown-arrow {
    transform: rotate(180deg);
}

.language-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    margin-top: 6px;
    min-width: 150px;
    max-width: calc(100vw - 40px);
    background-color: #2c2c2c;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.language-dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.language-dropdown-menu .language-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    font-size: 14px;
    border-radius: 0;
    position: relative;
}

.language-dropdown-menu .language-option:hover {
    background-color: #3c3c3c;
}

.language-dropdown-menu .language-option.active {
    background: #4a90e2 linear-gradient(135deg, #4a90e2 0%, #357abd 100%) !important;
    background-size: 100% 100% !important;
    background-clip: padding-box !important;
    color: white !important;
    font-weight: 600;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: none;
    outline: none;
}

.language-dropdown-menu .language-option.active:hover {
    background: #5ba0f2 linear-gradient(135deg, #5ba0f2 0%, #4589cd 100%) !important;
    background-size: 100% 100% !important;
    background-clip: padding-box !important;
}

.language-dropdown-menu .language-option:first-child {
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

.language-dropdown-menu .language-option:last-child {
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

.language-dropdown-menu .language-option .language-flag {
    font-size: 16px;
    line-height: 1;
}

.language-dropdown-menu .language-option .language-text {
    flex: 1;
    font-size: 13px;
}

/* ===== CONTROL PANEL BASE STYLES ===== */
.control-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background-color: #1e1e1e;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    pointer-events: auto;
    position: relative;
    z-index: 10;
}

/* Control Panel Buttons - Base Styles */
.control-panel button {
    /* Layout */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    
    /* Sizing */
    padding: 10px 16px;
    min-width: 80px;
    min-height: 56px;
    
    /* Styling */
    background-color: #2c2c2c;
    color: white;
    border: none;
    border-radius: 8px;
    
    /* Typography */
    font-size: 14px;
    font-weight: 500;
    
    /* Interaction */
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    
    /* Prevent layout shifts */
    flex: 0 0 auto;
}

/* Button Icons and Text */
.control-panel button .icon {
    font-size: 20px;
    line-height: 1;
}

.control-panel button .text {
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
}

/* Button Hover States */
.control-panel button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.control-panel button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
}

/* Disabled State */
.control-panel button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Button-Specific Colors */
#startMicrophone {
    background-color: #2ecc71;
}

#startMicrophone:hover:not(:disabled) {
    background-color: #27ae60;
}

#startMicrophone.active {
    background-color: #e74c3c;
    animation: pulse 2s infinite;
}

#startMicrophone.active:hover:not(:disabled) {
    background-color: #c0392b;
}

#testFirework {
    background-color: #3498db;
}

#testFirework:hover:not(:disabled) {
    background-color: #2980b9;
}

#toggleSettings {
    background-color: #3498db;
}

#toggleSettings:hover:not(:disabled) {
    background-color: #2980b9;
}

#togglePanels {
    background-color: #95a5a6;
}

#togglePanels:hover:not(:disabled) {
    background-color: #7f8c8d;
}

/* Pulse Animation */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* ===== HIDDEN PANELS STATE ===== */
/* When panels are hidden, make control panel floating */

/* Desktop: Top-left positioning */
.app-container.hidden-panels .control-panel {
    position: fixed;
    top: 10px;
    left: 10px;
    transform: none;
    width: auto;
    max-width: none;
    padding: 8px 12px;
    gap: 8px;
    z-index: 150;
    background-color: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    margin: 0;
}

/* Hide mode toggle button in hidden state */
.app-container.hidden-panels .control-panel #modeToggleButton {
    display: none !important;
}

/* Hide Start and Settings buttons in hidden state */
.app-container.hidden-panels .control-panel #startMicrophone,
.app-container.hidden-panels .control-panel #toggleSettings,
.app-container.hidden-panels .language-switcher-dropdown {
    display: none !important;
}

/* Show only Test and Show buttons in hidden state */
.app-container.hidden-panels .control-panel #testFirework,
.app-container.hidden-panels .control-panel #togglePanels {
    display: flex !important;
    flex: 0 0 auto;
    min-width: 80px;
    max-width: 120px;
    height: 56px;
    padding: 10px 16px;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .control-panel {
        gap: 10px;
        padding: 14px;
    }
    
    .control-panel button {
        min-width: 90px;
        padding: 10px 14px;
    }
}

/* Mobile Portrait (max-width: 767px) */
@media (max-width: 767px) {
    .control-panel {
        /* Use flexbox for horizontal row layout instead of grid */
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
        gap: 6px;
        padding: 8px;
        width: calc(100% - 32px);
        max-width: 300px;
        margin: 0 auto;
        box-sizing: border-box;
    }
    
    .control-panel button {
        /* Equal width buttons in row layout */
        flex: 1;
        min-width: 60px;
        max-width: none;
        min-height: 50px;
        padding: 4px 2px;
        box-sizing: border-box;
        
        /* Ensure text doesn't overflow */
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Adjust icon and text for mobile */
    .control-panel button .icon {
        font-size: 18px;
    }
    
    .control-panel button .text {
        font-size: 9px;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* CRITICAL: Hidden panels state on mobile - Must be INSIDE media query */
    .app-container.hidden-panels .control-panel {
        position: fixed !important;
        top: 8px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: auto !important;
        max-width: none !important;
        min-width: auto !important;
        padding: 6px 8px !important;
        gap: 6px !important;
        z-index: 150 !important;
        margin: 0 !important;
        /* Ensure it only sizes to fit the 2 visible buttons */
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: center !important;
        align-items: center !important;
        /* Override the mobile control panel width constraints */
        box-sizing: content-box !important;
    }
    
    .app-container.hidden-panels .control-panel #testFirework,
    .app-container.hidden-panels .control-panel #togglePanels {
        min-width: 70px !important;
        max-width: 90px !important;
        height: 44px !important;
        padding: 8px 10px !important;
        flex: 0 0 auto !important; /* Don't stretch to fill container */
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .app-container.hidden-panels .control-panel #testFirework .icon,
    .app-container.hidden-panels .control-panel #togglePanels .icon {
        font-size: 18px !important;
    }
    
    .app-container.hidden-panels .control-panel #testFirework .text,
    .app-container.hidden-panels .control-panel #togglePanels .text {
        font-size: 9px !important; /* Match mobile normal state */
    }
}

/* Small Mobile (361px - 480px) - Fix button height for hidden state to prevent text cutoff */
@media (max-width: 480px) and (min-width: 361px) {
    .app-container.hidden-panels .control-panel #testFirework,
    .app-container.hidden-panels .control-panel #togglePanels {
        height: 48px !important; /* Increased from 44px to prevent text cutoff */
        padding: 6px 8px !important; /* Slightly reduced padding to fit */
    }
}

/* Extra Small Mobile (321px - 360px) - Fix button height for hidden state to prevent text cutoff */
@media (max-width: 360px) and (min-width: 321px) {
    .app-container.hidden-panels .control-panel #testFirework,
    .app-container.hidden-panels .control-panel #togglePanels {
        height: 48px !important; /* Increased from 44px to prevent text cutoff */
        padding: 6px 8px !important; /* Slightly reduced padding to fit */
    }
}

/* Ultra Small Mobile (max-width: 320px) - Fix button height for hidden state to prevent text cutoff */
@media (max-width: 320px) {
    .app-container.hidden-panels .control-panel #testFirework,
    .app-container.hidden-panels .control-panel #togglePanels {
        height: 46px !important; /* Increased from 44px to prevent text cutoff */
        padding: 5px 7px !important; /* Slightly reduced padding to fit */
    }
}

/* ===== ACCESSIBILITY ===== */

/* Focus styles */
.control-panel button:focus-visible {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .control-panel {
        border: 2px solid #ffffff;
    }
    
    .control-panel button {
        border: 1px solid #ffffff;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .control-panel button {
        transition: none;
    }
    
    .control-panel button:hover:not(:disabled) {
        transform: none;
    }
    
    #startMicrophone.active {
        animation: none;
    }
}

/* ===== SPECIAL STATES ===== */

/* Settings panel open indicator */
.control-panel #toggleSettings.settings-open {
    background-color: #2980b9;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.5);
}

/* Mic active state with enhanced visibility */
.control-panel #startMicrophone.active {
    position: relative;
}

.control-panel #startMicrophone.active::before {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    background-color: #e74c3c;
    border-radius: 50%;
    box-shadow: 0 0 0 2px white;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
}

/* ===== DARK MODE SUPPORT ===== */
/* Force dark mode - ignore system preferences */
.control-panel {
    background-color: #1e1e1e !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.control-panel button {
    background-color: #2c2c2c !important;
    color: white !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
}

.control-panel button:hover:not(:disabled) {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
}

/* Ensure button colors remain consistent */
#startMicrophone {
    background-color: #2ecc71 !important;
    color: white !important;
}

#testFirework {
    background-color: #3498db !important;
    color: white !important;
}

#toggleSettings {
    background-color: #3498db !important;
    color: white !important;
}

#togglePanels {
    background-color: #95a5a6 !important;
    color: white !important;
}

/* ===== FONT SIZE CONSISTENCY FIXES ===== */

/* Mobile Portrait (max-width: 767px) - Ensure hidden state matches normal state */
@media (max-width: 767px) {
    .app-container.hidden-panels .control-panel #testFirework .text,
    .app-container.hidden-panels .control-panel #togglePanels .text {
        font-size: 9px !important; /* Match mobile normal state */
    }
}

/* Small Mobile (361px - 480px) - Ensure hidden state matches normal state */
@media (max-width: 480px) and (min-width: 361px) {
    .app-container.hidden-panels .control-panel #testFirework .text,
    .app-container.hidden-panels .control-panel #togglePanels .text {
        font-size: 7px !important; /* Match small mobile normal state */
    }
}

/* Extra Small Mobile (321px - 360px) - Ensure hidden state matches normal state */
@media (max-width: 360px) and (min-width: 321px) {
    .app-container.hidden-panels .control-panel #testFirework .text,
    .app-container.hidden-panels .control-panel #togglePanels .text {
        font-size: 7px !important; /* Match extra small mobile normal state */
    }
}

/* Ultra Small Mobile (max-width: 320px) - Ensure hidden state matches normal state */
@media (max-width: 320px) {
    .app-container.hidden-panels .control-panel #testFirework .text,
    .app-container.hidden-panels .control-panel #togglePanels .text {
        font-size: 6px !important; /* Match ultra small mobile normal state */
    }
}