/* Farblabor - Lern mit Ben Design & Interactive 3D Features */

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

:root {
    --bg-dark: #0a0f1a;
    --bg-surface: #141b2d;
    --bg-surface-hover: #1a2338;
    --panel-bg: rgba(20, 27, 45, 0.88);
    --panel-border: rgba(255, 255, 255, 0.08);
    --color-r: #ff3b30;
    --color-g: #30d158;
    --color-b: #0a84ff;
    --color-w: #f2f2f7;
    --color-uv: #a855f7;
}

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    background-color: var(--lmb-bg-dark);
    color: var(--lmb-text-main);
    font-family: 'Outfit', sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header Overlay */
.lab-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: linear-gradient(to bottom, rgba(10, 15, 26, 0.95) 0%, rgba(10, 15, 26, 0) 100%);
    pointer-events: none;
}

.lab-header > * {
    pointer-events: auto;
}

.lab-title-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.lab-title-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--lmb-bg-surface);
    border: 2px solid var(--lmb-primary);
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.lab-title-icon img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.lab-title-text h1 {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.1;
}

.lab-title-text p {
    font-size: 0.82rem;
    color: var(--lmb-text-muted);
}

/* Header Eye Sensor Badge (Permanently Visible) */
.header-sensor-badge {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 100px;
    padding: 0.4rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.sensor-preview {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 0 10px rgba(255,255,255,0.3);
    transition: background-color 0.15s, box-shadow 0.15s;
}

.sensor-readout {
    font-family: monospace;
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--lmb-text-main);
    letter-spacing: 0.02em;
}

/* Main 3D Canvas Area */
.viewport-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 70px);
    min-height: 520px;
    flex: 1;
    overflow: hidden;
}

#webgl-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#webgl-canvas:active {
    cursor: grabbing;
}

/* Floating 3D Selected Light Tooltip Popup */
.light-3d-popup {
    position: absolute;
    z-index: 28;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    padding: 0.6rem 0.8rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    pointer-events: auto;
    transform: translate(-50%, -120%);
    transition: opacity 0.2s, transform 0.2s;
}

.light-3d-popup.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -100%) scale(0.9);
}

.delete-light-btn {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.delete-light-btn:hover {
    background: rgba(239, 68, 68, 0.8);
    color: #ffffff;
    transform: scale(1.1);
}

/* Control Panel (Right Sidebar) */
.controls-panel {
    position: absolute;
    top: 5rem;
    right: 1.5rem;
    width: 360px;
    max-height: calc(100% - 6.5rem);
    overflow-y: auto;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    padding: 1.2rem;
    z-index: 25;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-panel::-webkit-scrollbar {
    width: 5px;
}
.controls-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* Tabs Navigation in Panel */
.panel-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 100px;
    padding: 3px;
    gap: 3px;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--lmb-text-muted);
    padding: 0.5rem 0.4rem;
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.tab-btn:hover {
    color: var(--lmb-text-main);
}

.tab-btn.active {
    background: var(--lmb-primary);
    color: #ffffff;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4);
}

.tab-content {
    display: none;
    flex-direction: column;
    gap: 0.9rem;
}

.tab-content.active {
    display: flex;
}

/* 2x2 Object Selection Grid */
.object-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-top: 0.6rem;
}

.object-tile {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 0.75rem 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--lmb-text-main);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.object-tile:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.object-tile[data-obj="metamerism"] {
    grid-column: span 2;
}

.object-tile.active {
    background: var(--lmb-grad-primary);
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
    color: #ffffff;
}



/* Custom Select Control */
.custom-select {
    width: 100%;
    background: rgba(10, 15, 26, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    color: var(--lmb-text-main);
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.custom-select:focus {
    border-color: var(--lmb-primary);
}

/* Add Lamp Action Bar */
.add-lamp-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    padding: 0.7rem;
    justify-content: space-between;
}

.add-lamp-btn {
    background: var(--lmb-grad-primary);
    border: none;
    color: white;
    padding: 0.45rem 0.9rem;
    border-radius: 100px;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.add-lamp-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.color-picker-input {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: none;
}

/* Spotlight Card Control */
.spotlight-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
}

.spotlight-card.selected-in-3d {
    border-color: var(--spotlight-color, var(--lmb-primary)) !important;
    box-shadow: 0 0 16px var(--spotlight-color, var(--lmb-primary)) !important;
}

.spotlight-card.active-spotlight {
    border-color: rgba(255, 255, 255, 0.15);
}

.spotlight-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.spotlight-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 0.9rem;
}

.spotlight-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--spotlight-color);
    box-shadow: 0 0 10px var(--spotlight-color);
}

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

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

.slider-toggle {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.15);
    transition: .3s;
    border-radius: 24px;
}

.slider-toggle:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider-toggle {
    background-color: var(--spotlight-color, var(--lmb-primary));
}

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

/* Range Sliders */
.control-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.6rem;
}

.control-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--lmb-text-muted);
}

.range-input {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.15);
    outline: none;
}

.range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.5);
    transition: transform 0.1s;
}

.range-input::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Missions Cards */
.mission-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
}

.mission-card.completed {
    border-color: var(--lmb-secondary);
    background: rgba(16, 185, 129, 0.08);
}

.mission-title {
    font-size: 0.88rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mission-desc {
    font-size: 0.8rem;
    color: var(--lmb-text-muted);
    line-height: 1.4;
}

/* Presets & Camera Toolbar */
.preset-bar {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    display: flex;
    gap: 0.4rem;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--panel-border);
    padding: 0.4rem;
    border-radius: 100px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    max-width: 92vw;
    overflow-x: auto;
}

.preset-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--lmb-text-main);
    padding: 0.45rem 0.9rem;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.preset-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.preset-btn.active {
    background: var(--lmb-grad-primary);
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

/* Ben Dialog Card */
.ben-assistant-card {
    position: absolute;
    bottom: 1.5rem;
    left: 1.5rem;
    z-index: 25;
    max-width: 330px;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    display: flex;
    gap: 0.8rem;
    align-items: flex-start;
}

.ben-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--lmb-primary);
    flex-shrink: 0;
    background: var(--lmb-bg-surface);
}

.ben-speech {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ben-speech h4 {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--lmb-text-main);
}

.ben-speech p {
    font-size: 0.8rem;
    color: var(--lmb-text-muted);
    line-height: 1.45;
}

/* Responsive Rules */
@media (max-width: 900px) {
    .controls-panel {
        top: auto;
        bottom: 5.5rem;
        right: 1rem;
        left: 1rem;
        width: auto;
        max-height: 45vh;
    }
    
    .preset-bar {
        bottom: 1rem;
    }

    .ben-assistant-card {
        display: none;
    }

    .header-sensor-badge {
        display: none;
    }
}
