/* Global Styling and Variables - Minimal Technical Light Theme */
:root {
    --bg-dark: #020204; /* Keep WebGL background dark for bloom/glow contrast */
    --panel-bg: #ffffff;
    --panel-border: #000000;
    --text-primary: #000000;
    --text-muted: #666666;
    --accent-color: #39ff14; /* Default green accent for active controls */
    --accent-glow: rgba(57, 255, 20, 0.15);
    --btn-secondary: #ffffff;
    --btn-secondary-hover: #000000;
    --transition-speed: 0.12s; /* Technical, snappy response */
    --font-sans: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border-radius: 0 !important; /* Force 0 border radius everywhere */
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-sans);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Canvas background */
#webgl-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: block;
}

/* Technical panel base */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    box-shadow: none; /* Flat, no soft drop shadows */
    transition: all var(--transition-speed) ease-out;
}

/* UI container layout */
.ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: grid;
    grid-template-columns: 1fr 280px;
    grid-template-rows: 1fr;
    grid-template-areas: ". sidebar";
    padding: 0;
    gap: 0;
}

.ui-container * {
    pointer-events: auto;
}

/* Live FPS Indicator */
.fps-indicator {
    position: absolute;
    bottom: 24px;
    left: 24px;
    padding: 8px 14px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-primary);
    pointer-events: none;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
}

.controls-sidebar {
    grid-area: sidebar;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: height var(--transition-speed) ease-out;
    border-top: none;
    border-right: none;
    border-bottom: none;
}

/* Collapsed state: minimize vertically, keeping header visible */
.controls-sidebar.collapsed {
    height: 38px;
}

.controls-sidebar.collapsed .sidebar-scrollable,
.controls-sidebar.collapsed .sidebar-footer {
    display: none !important;
}

#toggle-sidebar::before {
    content: '▲';
    font-size: 8px;
}

.controls-sidebar.collapsed #toggle-sidebar::before {
    content: '▼';
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--panel-border);
    cursor: pointer;
    user-select: none;
    transition: background-color var(--transition-speed) ease-out;
}

.sidebar-header:hover {
    background-color: #fafafa;
}

.sidebar-header h2 {
    font-size: 12px;
    font-weight: 800;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Technical clean Scrollbar */
.sidebar-scrollable::-webkit-scrollbar {
    width: 4px;
}

.sidebar-scrollable::-webkit-scrollbar-track {
    background: #f0f0f0;
}

.sidebar-scrollable::-webkit-scrollbar-thumb {
    background: #000000;
}

.control-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-section h3 {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    border-left: 2px solid var(--accent-color);
    padding-left: 6px;
    margin-bottom: 1px;
}

/* Palette grid - 3-column square buttons */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.palette-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 2px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    transition: all var(--transition-speed) ease-out;
}

.palette-btn::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    background-color: var(--btn-color);
    margin-bottom: 4px;
    border: 1px solid #000;
}

.palette-btn:hover {
    background: #fafafa;
    color: #000;
    border-color: #000;
}

.palette-btn.active {
    background: #ffffff;
    color: #000000;
    border: 1px solid #000000;
    outline: 1px solid #000000;
}

/* Sliders, Select, Checkboxes */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 10px;
}

.slider-header label {
    color: var(--text-primary);
    text-transform: uppercase;
    font-weight: 400;
}

.slider-header span {
    color: #000000;
    font-weight: 700;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 2px; /* Super thin line */
    background: #e0e0e0;
    outline: none;
}

/* Chrome Webkit Sliders */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 8px;
    height: 16px;
    background: #000000; /* Sharp black block */
    border: 1px solid #000000;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease-out;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--accent-color);
}

/* Firefox Sliders */
input[type="range"]::-moz-range-thumb {
    width: 8px;
    height: 16px;
    background: #000000;
    border: 1px solid #000000;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease-out;
}

input[type="range"]::-moz-range-thumb:hover {
    background: var(--accent-color);
}

/* Custom Checkbox */
.checkbox-group {
    margin-top: 2px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 20px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-primary);
    user-select: none;
}

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

.checkmark {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 14px;
    width: 14px;
    background-color: #ffffff;
    border: 1px solid var(--panel-border);
}

.checkbox-container:hover input ~ .checkmark {
    border-color: var(--accent-color);
}

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

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

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

/* Inner indicator is a tiny white dot/block */
.checkbox-container .checkmark:after {
    left: 4px;
    top: 4px;
    width: 4px;
    height: 4px;
    background: #ffffff;
}

/* Custom Select */
.select-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.select-group label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
}

select {
    width: 100%;
    padding: 5px 8px;
    background: #ffffff;
    border: 1px solid var(--panel-border);
    color: var(--text-primary);
    outline: none;
    font-family: var(--font-mono);
    font-size: 10px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg fill='black' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 16px;
    padding-right: 28px;
}

select:hover {
    border-color: var(--accent-color);
}

select option {
    background-color: #ffffff;
    color: #000000;
}

/* Buttons styling */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: all var(--transition-speed) ease-out;
    border: 1px solid var(--panel-border);
}

.btn-secondary {
    background: #ffffff;
    color: #000000;
}

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

.btn-full {
    width: 100%;
}

.btn-icon-only {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 1px solid transparent;
    transition: all var(--transition-speed) ease-out;
}

.btn-icon-only:hover {
    border-color: #000000;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--panel-border);
}




/* Preloader style */
#loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    background-color: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.loader-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    font-family: var(--font-mono);
}

.loader-spinner {
    width: 30px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-top-color: #ffffff;
    animation: spin 0.8s linear infinite;
    box-shadow: none;
}

#loader h1 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #ffffff;
}

#loader p {
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #555555;
}

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.animate-fade-in {
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.animate-slide-in {
    animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Split Layout styles (Webcam Left 50% / Canvas Right 50%) */
body.layout-split #webcam-video,
body.layout-split #webcam-canvas-overlay {
    display: block !important;
    position: absolute;
    top: 0;
    left: 0;
    width: 50% !important;
    height: 100% !important;
    object-fit: cover;
    border-right: 1px solid var(--panel-border);
}

body.layout-split #webcam-video {
    z-index: 2;
    transform: scaleX(-1); /* Mirror camera feed */
}

body.layout-split #webcam-canvas-overlay {
    z-index: 3;
    transform: scaleX(-1); /* Mirror drawn canvas overlay to match mirrored feed */
    pointer-events: none; /* Let pointer events pass through to canvas underneath if clicked */
}

body.layout-split #webgl-canvas {
    left: 50% !important;
    width: 50% !important;
    transition: left var(--transition-speed) ease-out, width var(--transition-speed) ease-out;
}

.btn.active {
    background: #000000 !important;
    color: #ffffff !important;
    border-color: #000000 !important;
}

/* Disabled states for form controls */
select:disabled, input[type="range"]:disabled, button:disabled {
    opacity: 0.35 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* Hidden States */
.hidden {
    display: none !important;
}

/* Responsive styles */
@media (max-width: 900px) {
    .ui-container {
        grid-template-columns: 1fr;
        padding: 16px;
    }
    
    .controls-sidebar {
        position: fixed;
        top: 16px;
        right: 16px;
        z-index: 100;
        width: 300px;
        height: calc(100vh - 32px);
    }
}
