/* === CSS Variables === */
:root {
    --bg-dark: #0a0a0c;
    --bg-panel: #121216;
    --bg-panel-alt: #18181d;
    --bg-hover: #1e1e24;
    --bg-active: #252530;

    --border-subtle: #2a2a35;
    --border-medium: #3a3a48;

    --text-primary: #e8e8ec;
    --text-secondary: #9898a8;
    --text-muted: #686878;

    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-glow: rgba(99, 102, 241, 0.3);

    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;

    --light-directional: #fbbf24;
    --light-point: #60a5fa;
    --light-spot: #a78bfa;

    --font-mono: 'JetBrains Mono', monospace;
    --font-sans: 'Space Grotesk', sans-serif;

    --panel-width-left: 240px;
    --panel-width-right: 400px;
    --toolbar-height: 96px;
    --topbar-height: 44px;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-dark);
    line-height: 1.5;
}

/* === Layout === */
#app {
    display: grid;
    grid-template-columns: var(--panel-width-left) 1fr var(--panel-width-right);
    grid-template-rows: var(--topbar-height) calc(100vh - var(--topbar-height) - var(--toolbar-height));
    grid-template-areas:
        "topbar topbar topbar"
        "left canvas right";
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

#gl-canvas {
    grid-area: canvas;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: block;
    background: linear-gradient(135deg, #0d0d10 0%, #15151a 100%);
    object-fit: none;
    object-position: top left;
}

/* === Top Bar === */
#top-bar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 20px;
    color: var(--accent-primary);
    text-shadow: 0 0 12px var(--accent-glow);
}

.logo-text {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.02em;
}

.repo-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #ffffff;
    text-decoration: none;
}

.repo-link:hover {
    text-decoration: underline;
}

.repo-link img {
    opacity: 0.85;
    transition: opacity 0.2s, filter 0.2s;
}

.repo-link:hover img {
    opacity: 1;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.8));
}

.top-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.top-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

.top-controls select {
    background: var(--bg-panel-alt);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: pointer;
}

.top-controls select:hover {
    border-color: var(--border-medium);
}

.top-controls input[type="checkbox"] {
    accent-color: var(--accent-primary);
}

.stats {
    display: flex;
    gap: 16px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}

#fps-counter {
    color: var(--success);
}

/* === Panels === */
.panel {
    background: var(--bg-panel);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#left-panel {
    grid-area: left;
}

#right-panel {
    grid-area: right;
    border-right: none;
    border-left: 1px solid var(--border-subtle);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-panel-alt);
}

.panel-header h3 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.panel-actions {
    display: flex;
    gap: 4px;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* === Add Menu === */
.add-menu {
    display: none;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    padding: 8px;
    margin-bottom: 8px;
}

.add-menu.active {
    display: block;
}

.add-menu-section {
    margin-bottom: 8px;
}

.add-menu-section:last-child {
    margin-bottom: 0;
}

.add-menu-section h4 {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding-left: 4px;
}

.add-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.add-item:hover {
    background: var(--bg-hover);
}

.add-item .icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

/* === Scene List === */
.scene-list {
    list-style: none;
}

.scene-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.scene-item:hover {
    background: var(--bg-hover);
}

.scene-item.selected {
    background: var(--bg-active);
    outline: 1px solid var(--accent-primary);
}

.scene-item .icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

.scene-item.object .icon { color: var(--text-secondary); }
.scene-item.light-directional .icon { color: var(--light-directional); }
.scene-item.light-point .icon { color: var(--light-point); }
.scene-item.light-spot .icon { color: var(--light-spot); }

.scene-item .name {
    flex: 1;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scene-item .visibility {
    opacity: 0.5;
    font-size: 12px;
    cursor: pointer;
}

.scene-item .visibility:hover {
    opacity: 1;
}

/* === Properties Panel === */
.no-selection {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
    padding: 20px;
}

.property-section {
    margin-bottom: 16px;
}

.property-section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 10px;
}

.property-section-header h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.property-row {
    display: grid;
    grid-template-columns: 80px 1fr;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.property-row label {
    font-size: 11px;
    color: var(--text-secondary);
}

.property-row input[type="text"],
.property-row input[type="number"] {
    width: 100%;
    padding: 8px 8px;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    min-height: 32px;
}

/* Make number input spinners bigger and ensure space for them */
.property-row input[type="number"] {
    padding-right: 20px; /* Space for spinner buttons */
}

.property-row input[type="number"]::-webkit-inner-spin-button,
.property-row input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    height: 28px;
    width: 16px;
    cursor: pointer;
}

.property-row input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.vector-input {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.vector-input input[type="number"] {
    text-align: right;
    padding: 8px 28px 8px 26px; /* left for label, right for spinner */
    min-height: 32px;
    width: 100%;
    -moz-appearance: textfield; /* Firefox: hide default spinners */
}

/* Webkit spinner styling */
.vector-input input[type="number"]::-webkit-inner-spin-button,
.vector-input input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    height: 24px;
    width: 16px;
    cursor: pointer;
}

/* Direct inputs without wrapper (fallback) */
.vector-input > input:nth-child(1) { border-left: 2px solid #ef4444; }
.vector-input > input:nth-child(2) { border-left: 2px solid #22c55e; }
.vector-input > input:nth-child(3) { border-left: 2px solid #3b82f6; }

/* Axis input wrapper with label */
.axis-input {
    display: flex;
    align-items: center;
    gap: 0;
    position: relative;
    background: var(--bg-panel-alt);
    border-radius: var(--radius-sm);
}

.axis-input .axis-label {
    position: absolute;
    left: 8px;
    font-size: 10px;
    font-weight: 700;
    opacity: 0.9;
    text-transform: uppercase;
    pointer-events: none;
    z-index: 1;
}

.axis-input.axis-x { border-left: 3px solid #ef4444; }
.axis-input.axis-y { border-left: 3px solid #22c55e; }
.axis-input.axis-z { border-left: 3px solid #3b82f6; }

.axis-input.axis-x .axis-label { color: #ef4444; }
.axis-input.axis-y .axis-label { color: #22c55e; }
.axis-input.axis-z .axis-label { color: #3b82f6; }

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker-wrapper input[type="color"] {
    width: 32px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.color-hex {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slider-row input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    background: var(--bg-panel-alt);
    border-radius: 2px;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
}

.slider-row .value {
    font-family: var(--font-mono);
    font-size: 11px;
    min-width: 36px;
    text-align: right;
    color: var(--text-secondary);
}

.property-row input[type="checkbox"] {
    accent-color: var(--accent-primary);
}

/* === Bottom Toolbar === */
#toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-height);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 0 16px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-subtle);
    z-index: 1000;
}

.tool-group, .camera-controls-hint {
    position: relative;
    z-index: 1;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
    background: var(--bg-panel-alt);
    border-radius: var(--radius-md);
}

.tool-group-tag {
    font-size: 10px;
    color: #ffffff;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    white-space: nowrap;
    padding: 0 5px 0 7px;
}

.tool-group-divider {
    width: 1px;
    height: 24px;
    background: var(--border-subtle);
    margin: 0 3px;
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.15s;
}

.tool-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tool-btn.active {
    background: var(--accent-primary);
    color: white;
    box-shadow: 0 0 12px var(--accent-glow);
}

.tool-btn.tool-disabled,
.tool-btn.tool-disabled:hover {
    opacity: 0.25;
    cursor: not-allowed;
    background: transparent;
    color: var(--text-muted);
    box-shadow: none;
}

.tool-icon {
    font-size: 18px;
}

.camera-controls-hint {
    display: flex;
    gap: 20px;
    padding: 10px 16px;
    background: var(--bg-panel-alt);
    border-radius: var(--radius-md);
    font-size: 16px;
    color: var(--text-secondary);
}

.camera-controls-hint span {
    white-space: nowrap;
    color: #ffffff;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-secondary);
}

.btn-secondary {
    background: var(--bg-panel-alt);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-icon {
    width: 24px;
    height: 24px;
    padding: 0;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
}

.btn-icon:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.btn-add {
    height: 24px;
    padding: 0 8px;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    white-space: nowrap;
    cursor: pointer;
}

.btn-add:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* === Selection Highlight Animation === */
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { box-shadow: 0 0 8px 2px var(--accent-glow); }
}

.scene-item.selected {
    animation: pulse-glow 2s ease-in-out infinite;
}

/* === Name Input === */
.name-input {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 11px;
}

.name-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* === Remove Section === */
.remove-section {
    margin-top: 16px;
    border-top: 1px solid var(--border-subtle);
    padding-top: 8px;
}

.remove-section .property-section-header h4 {
    color: var(--danger);
}

.remove-section .property-row {
    display: block;
}

.remove-link {
    color: var(--danger);
    cursor: pointer;
    font-size: 12px;
    transition: opacity 0.15s ease;
    white-space: nowrap;
}

.remove-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Constrained slider styling */
.constrained-slider {
    position: relative;
}

.slider-hint {
    font-size: 9px;
    color: var(--text-muted);
    opacity: 0.6;
    margin-top: 2px;
    font-style: italic;
}

.inner-angle-slider {
    accent-color: #f59e0b;
}

.outer-angle-slider {
    accent-color: #8b5cf6;
}

/* Footer text elements inside toolbar */
.footer-left, .footer-right {
    font-size: 14px;
    color: #ffffff;
    opacity: 0.7;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    pointer-events: none;
    position: absolute;
}

.footer-left {
    left: 12px;
    font-style: italic;
}

.footer-right {
    right: 12px;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.footer-right a {
    color: #ffffff;
    text-decoration: none;
}

.footer-right a:hover {
    color: #ffffff;
    text-decoration: underline;
}
