/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #020617;
    color: #f8fafc;
    overflow: hidden;
    height: 100%;
}

/* Main Layout Grid */
#app-container {
    display: flex;
    flex-direction: row;
    height: 100%;
    width: 100%;
}

/* Viewport Canvas Area */
#canvas-container {
    flex: 1;
    position: relative;
    background-color: #020617; /* Deep midnight slate */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#viewport-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    touch-action: none;
}

/* Control Panel Sidebar (Desktop default) */
#control-panel {
    width: 400px;
    background-color: #0f172a; /* Slate-900 background */
    border-left: 2px solid #1e293b;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
    z-index: 5;
}

/* Header Banner */
#panel-header {
    background-color: #1e293b;
    padding: 16px 20px;
    border-bottom: 1px solid #334155;
    text-align: center;
}

#panel-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #38bdf8; /* Sky-400 */
    letter-spacing: 0.1em;
    position: relative;
    cursor: help;
    display: inline-block;
}

#panel-header h1::after {
    content: attr(data-tooltip);
    white-space: pre;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: #f8fafc;
    padding: 8px 14px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    text-align: center;
    line-height: 1.5;
    letter-spacing: 0;
    font-family: inherit;
}

#panel-header h1:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(8px);
}

/* Scrolling Sidebar Content */
#panel-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: #475569 #0f172a;
}

/* Custom Scrollbar for Sidebar */
#panel-scroll::-webkit-scrollbar {
    width: 8px;
}

#panel-scroll::-webkit-scrollbar-track {
    background: #0f172a;
}

#panel-scroll::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 4px;
    border: 2px solid #0f172a;
}

#panel-scroll::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Sections */
.control-section {
    background: rgba(30, 41, 59, 0.4); /* Slate-800 with transparency */
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 0.05em;
    margin-bottom: 5px;
}

/* Grid helper rows */
.row {
    display: flex;
    flex-direction: row;
    gap: 15px;
}

.col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #f8fafc;
}

/* Custom Selectors (Arrow buttons + center label) */
.selector-arrows {
    display: flex;
    flex-direction: row;
    align-items: center;
    background-color: #1e293b;
    border: 1px solid #475569;
    border-radius: 6px;
    height: 35px;
    overflow: hidden;
}

.arrow-btn {
    width: 35px;
    height: 100%;
    background: none;
    border: none;
    color: #f8fafc;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background-color 0.2s;
}

.arrow-btn:hover {
    background-color: #334155;
}

.select-label {
    flex: 1;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #38bdf8;
    user-select: none;
}

/* Tab buttons group */
.tabs-group {
    display: flex;
    flex-direction: row;
    background-color: #1e293b;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 2px;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 0;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.tab-btn.active {
    background-color: #38bdf8;
    color: #0f172a;
}

/* Secondary (5-option) Tab group */
.tabs-group.secondary {
    padding: 2px;
}

.tabs-group.secondary .tab-btn {
    font-size: 0.73rem;
    padding: 6px 0;
}

/* Slider Row */
.slider-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 14px;
}

.slider-row:first-of-type {
    margin-top: 0;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #e2e8f0;
}

/* Segmented Control Button Group */
.segmented-control {
    display: flex;
    flex-direction: row;
    background-color: #020617;
    border: 1px solid #1e293b;
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
    margin-top: 4px;
}

.segment-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 8px 6px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.segment-btn:hover {
    color: #e2e8f0;
    background-color: rgba(255, 255, 255, 0.05);
}

.segment-btn.active {
    background-color: #0284c7; /* Sky-600 */
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Custom Styled Range Sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: #334155;
    border-radius: 3px;
    outline: none;
    margin: 0;
    padding: 6px 0;
    touch-action: pan-y; /* Prevent vertical touch scroll from moving slider values */
    box-sizing: content-box;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #38bdf8;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(56, 189, 248, 0.4);
    transition: transform 0.1s, background-color 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #0ea5e9;
    transform: scale(1.15);
}

input[type="range"]::-webkit-slider-thumb:active {
    background: #0ea5e9;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: #38bdf8;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(56, 189, 248, 0.4);
    transition: transform 0.1s;
}

input[type="range"]::-moz-range-thumb:hover {
    background: #0ea5e9;
    transform: scale(1.15);
}

/* Custom Checkbox styles */
.checkbox-row {
    display: flex;
    align-items: center;
    padding: 3px 0;
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    user-select: none;
    color: #e2e8f0;
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    height: 18px;
    width: 18px;
    background-color: #1e293b;
    border: 1px solid #475569;
    border-radius: 4px;
    margin-right: 10px;
    display: inline-block;
    position: relative;
    transition: all 0.2s;
}

.checkbox-container:hover input ~ .checkmark {
    border-color: #38bdf8;
}

.checkbox-container input:checked ~ .checkmark {
    background-color: #38bdf8;
    border-color: #38bdf8;
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid #0f172a;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Footer Action Buttons Container */
#panel-actions {
    padding: 16px 20px;
    background-color: #1e293b;
    border-top: 1px solid #334155;
    display: flex;
    flex-direction: row;
    gap: 10px;
}

.action-btn {
    flex: 1;
    height: 40px;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.primary-btn {
    background-color: #0284c7; /* Sky-600 */
    color: #ffffff;
    border: 1px solid #0ea5e9;
}

.primary-btn:hover {
    background-color: #0ea5e9;
}

.secondary-btn {
    background-color: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
}

.secondary-btn:hover {
    background-color: #475569;
}

/* Success Toast Notifications */
#toast {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(4, 120, 87, 0.95); /* Semi-transparent emerald-700 */
    border: 1px solid #34d399; /* Emerald-400 */
    color: #d1fae5;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    z-index: 100;
    transition: opacity 0.3s, transform 0.3s;
    text-align: center;
    pointer-events: none;
}

#toast.hidden {
    opacity: 0;
    transform: translate(-50%, 20px);
}

/* Mobile Utilities classes */
.mobile-only {
    display: none;
}


/* Favorites Row Controls */
.favorites-row {
    display: flex;
    flex-direction: row;
    gap: 8px;
    margin-top: 4px;
    align-items: center;
}

.select-dropdown {
    flex: 1;
    background-color: #020617;
    border: 1px solid #1e293b;
    border-radius: 6px;
    color: #f8fafc;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 8px 12px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
    /* Custom chevron indicator */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 32px;
}

.select-dropdown:focus {
    border-color: #0284c7;
}

.fav-action-btn {
    background-color: #1e293b;
    color: #f8fafc;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.fav-action-btn:hover {
    background-color: #334155;
    border-color: #475569;
}

.danger-btn {
    background-color: rgba(239, 68, 68, 0.12); /* Tailwind red-500 alpha */
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.danger-btn:hover {
    background-color: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
    color: #ffffff;
}

/* Lockable Settings Controls Layout */
.lock-input-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.lock-input-group input[type="range"] {
    flex: 1;
}

.lock-input-group .segmented-control {
    flex: 1;
}

.lock-btn {
    background: transparent;
    border: none;
    color: #475569; /* Slate-600 */
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    opacity: 0.7; /* Clearly visible but subtle */
    user-select: none;
}

.lock-btn.locked {
    color: #38bdf8; /* Cyberpunk cyan when active */
    opacity: 1.0;
    transform: scale(1.15);
    text-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}

.lock-btn:hover {
    color: #38bdf8;
    opacity: 0.8;
}

/* Palette Grid Segmented Control Layout */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
}

.palette-grid .segment-btn {
    border-radius: 4px !important;
    height: 32px;
    font-size: 0.7rem;
    border: 1px solid #334155;
    background: rgba(30, 41, 59, 0.7);
    padding: 0 2px;
    white-space: nowrap;
}


/* Drag Handle / Splitter styles (Desktop defaults) */
#panel-drag-handle {
    position: absolute;
    left: -12px;
    top: 0;
    bottom: 0;
    width: 24px;
    cursor: ew-resize;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    transition: background-color 0.2s, border-left 0.2s, border-top 0.2s, box-shadow 0.2s;
}

#panel-drag-handle:hover,
#panel-drag-handle.active {
    background-color: rgba(56, 189, 248, 0.1);
}

.drag-pill {
    width: 4px;
    height: 40px;
    background-color: rgba(56, 189, 248, 0.4); /* Subtle blue tint so it stands out against dark background */
    border-radius: 2px;
    transition: background-color 0.2s, height 0.2s, width 0.2s;
}

#panel-drag-handle:hover .drag-pill,
#panel-drag-handle.active .drag-pill {
    background-color: #38bdf8;
    height: 60px;
    width: 5px;
}

/* Make the drag handle border and background stand out clearly when the panel is collapsed */
#control-panel:not(.open) #panel-drag-handle {
    border-left: 2px solid rgba(56, 189, 248, 0.6);
    background-color: rgba(15, 23, 42, 0.85);
    box-shadow: -4px 0 15px rgba(56, 189, 248, 0.25);
}

/* ==========================================================================
   Responsive Mobile Styling (Sliding Sidebar & Bottom Sheet Layout)
   ========================================================================== */
@media (max-width: 1024px) {
    #app-container {
        flex-direction: column;
        height: 100%;
        position: relative;
    }
    
    #canvas-container {
        width: 100%;
        height: 100%;
        background-color: #020617;
        z-index: 1;
        position: relative;
    }
    
    #control-panel {
        position: fixed;
        background-color: rgba(15, 23, 42, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-left: 1px solid rgba(56, 189, 248, 0.15);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), width 0.4s cubic-bezier(0.16, 1, 0.3, 1), height 0.4s cubic-bezier(0.16, 1, 0.3, 1);
        display: flex;
        flex-direction: column;
        z-index: 10;
    }

    /* Default Side Sheet (for narrow landscape, tablets, and square windows) */
    #control-panel {
        top: 0;
        bottom: 0;
        right: 0;
        width: 400px;
        max-width: 85%;
        height: 100%;
        border-left: 1px solid rgba(56, 189, 248, 0.2);
        border-top: none;
        border-radius: 0;
        transform: translateX(calc(100% - 12px)); /* 12px handle boundary stays visible */
    }

    #control-panel.open {
        transform: translateX(0);
    }

    #panel-drag-handle {
        left: -12px;
        top: 0;
        bottom: 0;
        width: 24px;
        height: 100%;
        cursor: ew-resize;
    }

    /* Portrait orientation bottom sheet (only on narrow vertical screens e.g., aspect ratio <= 13:15 and width <= 600px) */
    @media (max-width: 600px) and (max-aspect-ratio: 13/15) {
        #control-panel {
            left: 0;
            right: 0;
            bottom: 0;
            top: auto;
            width: 100%;
            max-width: 100%;
            height: 50%; /* Default to half height, adjustable by dragging */
            border-top: 1px solid rgba(56, 189, 248, 0.2);
            border-left: none;
            border-radius: 20px 20px 0 0;
            transform: translateY(calc(100% - 12px)); /* 12px handle boundary stays visible */
        }
        
        #control-panel.open {
            transform: translateY(0);
        }

        #panel-drag-handle {
            left: 0;
            right: 0;
            top: -12px;
            bottom: auto;
            width: 100%;
            height: 24px;
            cursor: ns-resize;
            border-left: none;
        }

        .drag-pill {
            width: 40px;
            height: 4px;
        }

        #panel-drag-handle:hover .drag-pill,
        #panel-drag-handle.active .drag-pill {
            width: 60px;
            height: 4px;
        }

        /* Collapsed style adjustments for horizontal layout */
        #control-panel:not(.open) #panel-drag-handle {
            border-top: 2px solid rgba(56, 189, 248, 0.6);
            border-left: none;
            box-shadow: 0 -4px 15px rgba(56, 189, 248, 0.25);
        }
    }
    
    .mobile-only {
        display: block;
    }
    
    #panel-header {
        display: block;
        padding: 12px 20px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }
    
    #panel-scroll {
        padding: 12px 18px;
        gap: 12px;
        flex: 1;
        overflow-y: auto;
    }
    
    #panel-actions {
        padding: 10px 10px 12px 10px;
        background-color: #1e293b;
        border-top: 1px solid #334155;
        flex-shrink: 0;
        display: flex;
        flex-direction: row;
        gap: 6px;
    }
    
    .action-btn {
        font-size: 0.7rem;
        height: 38px;
        padding: 0 2px;
        border-radius: 4px;
    }
    
    /* Toast spacing on mobile */
    #toast {
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        max-width: 90%;
        font-size: 0.8rem;
    }
}

/* --- New Fullscreen & Floating Controls --- */
.fullscreen-mode #control-panel,
.fullscreen-mode #panel-drag-handle {
    display: none !important;
}

.fullscreen-mode #canvas-container {
    width: 100vw !important;
    height: 100dvh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 9999 !important;
}

#floating-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    gap: 10px;
}

.floating-btn {
    background: rgba(15, 23, 42, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.floating-btn:hover {
    background: rgba(30, 41, 59, 0.85);
    color: #f8fafc;
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.floating-btn:active {
    transform: translateY(0) scale(0.95);
}

.heart-icon {
    transition: transform 0.2s ease, fill 0.2s ease, stroke 0.2s ease;
}

.heart-icon.filled {
    fill: #f43f5e;
    stroke: #f43f5e;
    color: #f43f5e;
    animation: heartBeat 0.3s ease-out;
}

@keyframes heartBeat {
    0% { transform: scale(1); }
    30% { transform: scale(1.3); }
    60% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

/* --- Music Active Status Indicator --- */
#music-indicator {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.65);
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: 20px;
    padding: 8px 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #38bdf8;
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: opacity 0.3s ease;
}

#music-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

.music-bars {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 12px;
}

.music-bar {
    width: 3px;
    background-color: #38bdf8;
    border-radius: 1px;
    animation: musicWave 0.8s ease-in-out infinite alternate;
}

.music-bar:nth-child(1) { animation-delay: 0.1s; height: 6px; }
.music-bar:nth-child(2) { animation-delay: 0.3s; height: 12px; }
.music-bar:nth-child(3) { animation-delay: 0.5s; height: 8px; }

@keyframes musicWave {
    0% { transform: scaleY(0.3); }
    100% { transform: scaleY(1.3); }
}

