* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    /* background: #dde1e7; */ /* Will be controlled by WebGL */
    overflow: hidden;
}

#webglCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: block;
    cursor: default;
    background-color: #333333; /* Default background if WebGL fails or before it loads */
}

#controls-pane {
    position: absolute;
    top: 50px;
    right: 50px;
    width: 360px; /* Fixed width */
    max-height: 90vh; /* Max height to prevent overflow and allow scrolling */
    min-height: 210px;
    padding: 15px; /* Reduced padding */
    box-sizing: border-box;
    border-radius: 18px; /* Consistent with WebGL glass */
    z-index: 10;
    overflow-x: hidden; /* Prevent horizontal scroll */
    background-color: transparent; /* Remove HTML background */
    overflow-y: auto; /* Ensure scrollbar appears when content overflows */

    /* Custom scrollbar for WebKit browsers (Chrome, Safari, Edge) */
    scrollbar-width: thin; /* For Firefox */
    scrollbar-color: rgba(180, 180, 180, 0.6) transparent; /* thumb color track color - For Firefox */
}

/* WebKit scrollbar styling */
#controls-pane::-webkit-scrollbar {
    width: 8px; /* Width of the scrollbar */
}

#controls-pane::-webkit-scrollbar-track {
    background: transparent; /* Make the track transparent */
    margin: 2px 0; /* Optional: add some margin to the track if needed */
}

#controls-pane::-webkit-scrollbar-thumb {
    background-color: rgba(180, 180, 180, 0.6); /* Translucent thumb color */
    border-radius: 4px; /* Rounded corners for the thumb */
    border: 1px solid rgba(255, 255, 255, 0.1); /* Optional: subtle border for better visibility */
}

#controls-pane::-webkit-scrollbar-thumb:hover {
    background-color: rgba(150, 150, 150, 0.8); /* Slightly more opaque on hover */
}

/* Hide scrollbar arrows/buttons for WebKit browsers */
#controls-pane::-webkit-scrollbar-button {
    display: none; /* This should be sufficient */
    width: 0;      /* Adding these as extra measures, though typically not needed if display:none works */
    height: 0;
}

#controls-title {
    font-size: 16px;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 10px;
    padding-bottom: 8px;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #ddd;
}

#controls-title:active {
    cursor: grabbing;
}

.drag-handle {
    width: 16px;
    height: 16px;
    background-image: url('../assets/grab handle.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.6;
    margin-right: 8px; /* Add space between handle and title text */
}

.control-buttons {
    display: flex;
    gap: 6px;
    align-items: center;
}

.frosted-button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #ccc;
    font-size: 10px;
    padding: 4px 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
}

.frosted-button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.frosted-button.primary {
    background: rgba(0, 122, 255, 0.3);
    border-color: rgba(0, 122, 255, 0.5);
    color: white;
}

.frosted-button.primary:hover {
    background: rgba(0, 122, 255, 0.4);
    border-color: rgba(0, 122, 255, 0.6);
}

.button-icon {
    width: 12px;
    height: 12px;
    filter: brightness(0) invert(1);
    opacity: 0.7;
}

.tabs-container {
    display: flex;
    flex-wrap: wrap; /* Allow pills to wrap to the next line */
    gap: 5px; /* Add gap between pills, including wrapped lines */
    margin-bottom: 10px; /* Reduced margin */
}

.tab-pill {
    flex-grow: 1;
    padding: 6px 10px; /* Reduced padding */
    font-size: 12px; /* Reduced font size */
    text-align: center;
    background-color: rgba(255, 255, 255, 0.1); /* Semi-transparent for frosted glass look */
    border: 1px solid rgba(255, 255, 255, 0.2); /* Subtle border */
    border-radius: 12px; /* Pill shape */
    /* margin-right: 5px; */ /* Replaced by gap in .tabs-container */
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    color: #eee; /* Light text color for dark background */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.tab-pill:last-child {
    margin-right: 0; /* Still useful if gap isn't fully supported or for specific row endings */
}

.tab-pill.active {
    background-color: rgba(0, 122, 255, 0.4); /* Semi-transparent iOS-like blue */
    color: white;
    font-weight: 500;
    border-color: rgba(0, 122, 255, 0.6);
}

.tab-pill:hover:not(.active) {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.tab-panel {
    display: none;
    padding-top: 5px; /* Reduced padding */
}

.tab-panel.active {
    display: block;
}

.control-group {
    margin-bottom: 8px; /* Reduced margin */
}

.control-group label {
    display: block;
    font-size: 11px; /* Reduced font size */
    margin-bottom: 3px; /* Reduced margin */
    color: #ccc; /* Adjusted for darker background */
}

.control-group label span {
    float: right;
    font-weight: normal;
    color: #bbb; /* Adjusted for darker background */
}

.control-group input[type="range"] {
    width: 100%;
    box-sizing: border-box;
}

/* Slider Styling */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 16px; /* Overall height of the slider area */
    background: transparent; /* Make default track transparent */
    outline: none;
    padding: 0;
    margin: 0; /* Remove default margins */
}

/* Webkit (Chrome, Safari, Edge, Opera) */
input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px; /* Slimmer track */
    cursor: pointer;
    background: rgba(255, 255, 255, 0.15); /* Light grey track, adjusted for dark bg */
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 14px; /* Slimmer thumb */
    width: 14px;  /* Slimmer thumb */
    border-radius: 50%;
    background: #e0e0e0; /* Lighter thumb for dark bg */
    cursor: pointer;
    margin-top: -5px; /* Vertically center thumb on track ( (track_height - thumb_height) / 2 ) */
    box-shadow: 0 1px 3px rgba(0,0,0,0.2); /* Subtle shadow for depth */
    border: 1px solid rgba(0,0,0,0.05); /* Very subtle border */
}

/* Mozilla Firefox */
input[type="range"]::-moz-range-track {
    width: 100%;
    height: 4px; /* Slimmer track */
    cursor: pointer;
    background: rgba(255, 255, 255, 0.15); /* Adjusted for dark bg */
    border-radius: 2px;
    border: none;
}

input[type="range"]::-moz-range-thumb {
    height: 14px; /* Slimmer thumb */
    width: 14px; /* Slimmer thumb */
    border-radius: 50%;
    background: #e0e0e0; /* Adjusted for dark bg */
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Microsoft Edge (Legacy - for older Edge, modern Edge uses WebKit styles) */
input[type="range"]::-ms-track {
    width: 100%;
    height: 4px; /* Slimmer track */
    cursor: pointer;
    background: transparent;
    border-color: transparent;
    color: transparent;
}

input[type="range"]::-ms-fill-lower {
    background: rgba(255, 255, 255, 0.15); /* Adjusted for dark bg */
    border-radius: 2px;
}

input[type="range"]::-ms-fill-upper {
    background: rgba(255, 255, 255, 0.15); /* Adjusted for dark bg */
    border-radius: 2px;
}

input[type="range"]::-ms-thumb {
    height: 14px; /* Slimmer thumb */
    width: 14px; /* Slimmer thumb */
    border-radius: 50%;
    background: #e0e0e0; /* Adjusted for dark bg */
    cursor: pointer;
    margin-top: 0px; /* Edge handles thumb positioning differently */
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Headings within control pane */
#controls-pane h4 {
    font-size: 13px; /* Reduced font size */
    margin-top: 10px; /* Reduced margin */
    margin-bottom: 6px; /* Reduced margin */
    font-weight: 500;
    color: #ddd; /* Ensure readability on dark bg */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Inline toggle switch styling */
.inline-toggle {
    width: 40px !important;
    height: 20px !important;
    margin: 0;
}

.inline-toggle .toggle-slider {
    border-radius: 20px;
}

.inline-toggle .toggle-slider:before {
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
}

.inline-toggle input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.separator {
    border: none;
    height: 1px;
    background-color: rgba(255, 255, 255, 0.1); /* Adjusted for dark bg */
    margin: 8px 0; /* Reduced margin */
}

/* Grid Controls Panel */
.grid-controls {
    position: fixed;
    bottom: 50px; /* Match the 50px virtual margin */
    left: 155px; /* Positioned after add button (75px) + button width (50px) + gap (20px) */
    width: 240px;
    height: 50px;
    padding: 10px 20px;
    border-radius: 25px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    
    /* Remove glass effect - will be rendered in canvas */
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
}

.grid-control-item {
    display: flex;
    align-items: center;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2); /* Adjusted for dark bg */
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 24px;
    transition: 0.2s;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: #e0e0e0; /* Adjusted for dark bg */
    border-radius: 50%;
    transition: 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
    background-color: rgba(0, 122, 255, 0.5); /* Adjusted for dark bg */
    border-color: rgba(0, 122, 255, 0.7);
}

/* Grid Spacing Slider */
.grid-spacing-slider {
    width: 120px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    border: none;
    cursor: pointer;
}

.grid-spacing-slider::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: pointer;
}

.grid-spacing-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: pointer;
    border: none;
}

/* Glass Icons */
.glass-icon {
    position: fixed;
    z-index: 15;
    pointer-events: none;
    opacity: 0.8;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1)) brightness(0) invert(1);
}

#add-image-icon {
    width: 24px;
    height: 24px;
}

#grid-icon {
    width: 20px;
    height: 20px;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    padding: 20px;
    border-radius: 12px;
}

.frosted-panel {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.modal-content h4 {
    margin: 0 0 15px 0;
    color: #ddd;
    font-size: 14px;
}

#config-name-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: #ddd;
    font-size: 12px;
    margin-bottom: 15px;
    outline: none;
    box-sizing: border-box;
}

#config-name-input:focus {
    border-color: rgba(0, 122, 255, 0.5);
    background: rgba(255, 255, 255, 0.15);
}

#config-name-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Dropdown Styles */
.dropdown {
    position: fixed; /* Changed from absolute to fixed */
    width: 250px;
    max-height: 400px; /* Increased max height since it's no longer constrained by control pane */
    overflow-y: auto;
    border-radius: 8px;
    z-index: 1000; /* Increased z-index to ensure it's above everything */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    /* Position will be set dynamically by JavaScript */
    
    /* Custom scrollbar styling for dropdown */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: rgba(180, 180, 180, 0.4) transparent; /* Firefox */
}

.dropdown-header{
    color: #fff;
    font-size: 14px;
    padding: 5px 15px;
}


/* WebKit scrollbar styling for dropdown */
.dropdown::-webkit-scrollbar {
    width: 6px; /* Thinner than control panel */
}

.dropdown::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}

.dropdown::-webkit-scrollbar-thumb {
    background-color: rgba(180, 180, 180, 0.4);
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.dropdown::-webkit-scrollbar-thumb:hover {
    background-color: rgba(150, 150, 150, 0.6);
}

/* Hide scrollbar arrows for dropdown */
.dropdown::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

.config-list {
    max-height: 250px;
    overflow-y: auto;
    
    /* Remove scrollbar from config-list since dropdown handles it */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* Hide scrollbar for config-list on WebKit browsers */
.config-list::-webkit-scrollbar {
    display: none;
}

.config-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 11px;
    color: #ccc;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.config-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ddd;
}

.config-item.selected {
    background: rgba(0, 122, 255, 0.3);
    color: white;
}

.config-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.config-name {
    font-weight: 500;
}

.config-date {
    font-size: 9px;
    opacity: 0.7;
}

.delete-config {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(220, 53, 69, 0.2);
    border: 1px solid rgba(220, 53, 69, 0.4);
    color: #dc3545;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    opacity: 0;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.config-item:hover .delete-config {
    opacity: 1;
}

.delete-config:hover {
    background: rgba(220, 53, 69, 0.4);
    border-color: rgba(220, 53, 69, 0.6);
    transform: scale(1.1);
}

.no-configs {
    padding: 20px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
}

/* Ensure control group and other elements inside controls-pane have appropriate styling */
#controls-pane .control-group {
    margin-bottom: 8px; /* Existing or desired margin */
}

#controls-pane h3,
#controls-pane label {
    color: #ccc; /* Default label color adjusted */
}

#chromaticAberrationAmountControlGroup {
    transition: opacity 0.3s ease, max-height 0.3s ease-out, margin-bottom 0.3s ease;
    overflow: hidden;
    /* margin-bottom will be set by default .control-group style, 
       but we can remove it when hidden if needed */
}

.preset-item {
    background: rgba(0, 122, 255, 0.1);
    border-left: 3px solid rgba(0, 122, 255, 0.5);
}

.preset-item:hover {
    background: rgba(0, 122, 255, 0.2);
}

.config-separator {
    padding: 8px 12px;
    font-size: 10px;
    font-weight: 600;
    color: #999;
    background: rgba(255, 255, 255, 0.05);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#reflectionGradientSlider {
    margin: 8px 0 4px 0;
}
.gradient-readout{
    font-size: 10px;
    color:#bbb;
    text-align:center;
}
