body {
    margin: 0;
    overflow: hidden;
    background: #1a1a1a;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    color: #eee;
    user-select: none;
}

#app {
    display: flex;
    width: 100vw;
    height: 100vh;
    gap: 16px;
    padding: 16px;
    box-sizing: border-box;
}

#viewport {
    flex-grow: 1;
    position: relative;
    cursor: crosshair;
    border-radius: 12px;
    overflow: hidden;
}

canvas {
    display: block;
    outline: none;
}

/* Panel */
.panel {
    background: #252525;
    padding: 18px;
    box-sizing: border-box;
    z-index: 10;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-radius: 12px;
    border: 1px solid #333333;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#left-panel {
    width: 160px;
    flex-shrink: 0;
    gap: 0;
    overflow: hidden; /* tab content handles its own scroll */
}

.left-tab-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.left-tab-content::-webkit-scrollbar { width: 5px; }
.left-tab-content::-webkit-scrollbar-track { background: transparent; }
.left-tab-content::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
.left-tab-content::-webkit-scrollbar-thumb:hover { background: #444; }

#left-panel-bottom {
    flex-shrink: 0;
}

/* Compact light property rows */
.light-group {
    margin-bottom: 10px;
}

.light-group-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #a3a3a3;
    margin-bottom: 6px;
}

.light-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}

.light-label {
    font-size: 10px;
    color: #777;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    width: 44px;
}

.light-slider {
    flex: 1;
    min-width: 0;
}

.light-swatch {
    flex: 1;
    height: 22px !important;
    min-width: 0;
}

/* Right column: stacks Properties panel and View tools panel */
#right-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 220px;
    flex-shrink: 0;
}

#right-panel {
    width: 220px;
    flex-shrink: 0;
    flex: 1;        /* expand to fill remaining column height */
    min-height: 0;  /* allow overflow-y: auto to work correctly */
}

#view-tools-panel {
    flex-shrink: 0;
}

.panel-collapse-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

.panel-collapse-header:hover .collapse-chevron {
    color: #d4d4d8;
}

.collapse-chevron {
    color: #555;
    transition: transform 0.2s ease, color 0.15s;
    flex-shrink: 0;
}

.collapse-chevron.expanded {
    transform: rotate(90deg);
}

#materials-panel {
    width: 210px;
    flex-shrink: 0;
}

h3 {
    margin: 0 0 14px 0;
    font-size: 10px;
    text-transform: uppercase;
    color: #a3a3a3;
    letter-spacing: 2px;
    font-weight: 700;
}

h4 {
    margin: 0 0 8px 0;
    font-size: 10px;
    color: #a3a3a3;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

hr {
    border: 0;
    border-top: 1px solid #2a2a2a;
    margin: 12px 0;
}

/* === Tool Buttons === */
.tools-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tool-btn {
    background: #252525;
    border: 1px solid #333;
    color: #e4e4e7;
    padding: 9px 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    width: 100%;
    font-weight: 500;
    text-align: left;
    box-sizing: border-box;
}

.tool-btn:hover {
    background: #3f3f46;
    border-color: #52525b;
    color: #ffffff;
}

.tool-btn.active {
    background: #2563eb;
    border-color: #1d4ed8;
    color: white;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.4);
}

#btn-delete.active {
    background: #dc2626;
    border-color: #b91c1c;
    box-shadow: 0 2px 10px rgba(220, 38, 38, 0.4);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    flex-shrink: 0;
}


/* Snap toggle */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: #aaa;
    cursor: pointer;
    padding: 2px 0;
}

.toggle-row input[type="checkbox"] {
    accent-color: #2563eb;
    width: 15px;
    height: 15px;
    cursor: pointer;
}

/* Hide the raw checkbox for toggle-switch rows; higher specificity than rule above */
.toggle-row input[type="checkbox"].toggle-check {
    display: none;
}

/* Pill toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    background: #3a3a3a;
    border: 1px solid #444;
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: #666;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s, background 0.2s;
}

.toggle-check:checked + .toggle-switch {
    background: #2563eb;
    border-color: #1d4ed8;
}

.toggle-check:checked + .toggle-switch::after {
    transform: translateX(16px);
    background: #ffffff;
}

.toggle-switch:hover {
    border-color: #555;
}

.toggle-check:checked + .toggle-switch:hover {
    background: #3b82f6;
}

/* View Preset Buttons */
.view-preset-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 0;
}

.view-preset-btn {
    background: #252525;
    border: 1px solid #333;
    color: #e4e4e7;
    padding: 8px 4px 6px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    box-sizing: border-box;
    font-family: inherit;
}

.view-preset-btn:hover {
    background: #3f3f46;
    border-color: #52525b;
    color: #ffffff;
}

.view-preset-btn:active {
    background: #2563eb;
    border-color: #1d4ed8;
    color: white;
}

/* Persistent active state for nav tool buttons (Pan, Move) */
.view-preset-btn.active {
    background: #2563eb;
    border-color: #1d4ed8;
    color: white;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.4);
    text-align: center;
    flex-direction: column;
}

.view-preset-btn.active:hover {
    background: #2563eb;
}

/* Override tool-btn row layout when view-preset-btn is also applied */
.view-preset-btn.tool-btn {
    flex-direction: column;
    justify-content: center;
    text-align: center;
    padding: 8px 4px 6px;
    font-size: 11px;
    gap: 4px;
    width: 100%;
}

/* Add Shape */
.section-label {
    font-size: 10px;
    color: #a3a3a3;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.shape-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
}

.shape-btn {
    aspect-ratio: 1;
    background: #252525;
    border: 1px solid #333;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
    color: #d4d4d8;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.shape-btn:hover {
    background: #3f3f46;
    border-color: #52525b;
    color: #ffffff;
}

.shape-btn:active {
    background: #2563eb;
    border-color: #1d4ed8;
    color: white;
}


/* === Right Panel === */
.prop-subtitle {
    font-size: 12px;
    color: #a3a3a3;
    margin: -6px 0 16px 0;
}

.prop-section {
    margin-bottom: 14px;
}

/* XYZ row of value boxes */
.xyz-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-bottom: 8px;
}

.xyz-box {
    background: #252525;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 7px 4px 6px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s;
}

.xyz-box:hover {
    border-color: #4a4a4a;
}

.xyz-box.selected {
    border-color: #3b82f6;
}

.xyz-label {
    display: block;
    font-size: 10px;
    color: #a3a3a3;
    margin-bottom: 3px;
}

.xyz-val {
    font-size: 12px;
    color: #f4f4f5;
}

/* Single slider per property group */
.prop-slider-main {
    width: 100%;
    height: 3px;
    border-radius: 2px;
    background: #2d2d2d;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    display: block;
}

.prop-slider-main::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid #3b82f6;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.prop-slider-main::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid #3b82f6;
    cursor: pointer;
}

.hidden-slider {
    display: none;
}

/* Color swatch (material editor) */
.face-swatch-wrapper {
    position: relative;
    width: 100%;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #3a3a3a;
    cursor: pointer;
}

#mat-color-display {
    width: 100%;
    height: 100%;
    background: #888888;
}

#mat-color,
.color-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    border: none;
    padding: 0;
    margin: 0;
}

/* Materials Library */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.new-mat-btn {
    background: #2563eb;
    border: none;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.new-mat-btn:hover {
    background: #1d4ed8;
}

.close-panel-btn {
    background: transparent;
    border: 1px solid #444;
    color: #a3a3a3;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.12s;
}

.close-panel-btn:hover {
    background: #3f3f46;
    color: #ffffff;
    border-color: #52525b;
}

/* Material row in object properties */
.material-row {
    display: flex;
    gap: 5px;
    align-items: center;
}

.material-row .material-select {
    flex: 1;
}

.open-mat-panel-btn {
    background: #1e3a5f;
    border: 1px solid #2563eb;
    color: #60a5fa;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.12s;
}

.open-mat-panel-btn:hover {
    background: #2563eb;
    color: white;
}

.material-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
    border: 1px solid transparent;
    transition: all 0.12s;
}

.material-item:hover {
    background: #2e2e2e;
}

.material-item.active {
    background: #1a2e4a;
    border-color: #2563eb;
}

.mat-swatch {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

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

#material-editor {
    margin-top: 10px;
}

.material-select {
    width: 100%;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 6px;
    color: #f4f4f5;
    font-size: 12px;
    padding: 6px 8px;
    box-sizing: border-box;
    outline: none;
    cursor: pointer;
    font-family: inherit;
}

.material-select:focus {
    border-color: #3b82f6;
}

.delete-mat-btn {
    background: #7f1d1d;
    border: 1px solid #991b1b;
    color: #fca5a5;
    padding: 7px 12px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    margin-top: 10px;
    font-size: 12px;
    font-weight: 600;
    box-sizing: border-box;
    transition: background 0.12s;
}

.delete-mat-btn:hover {
    background: #991b1b;
}

.delete-mat-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Object name input */
.name-input {
    width: 100%;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 6px;
    color: #f4f4f5;
    font-size: 13px;
    padding: 7px 10px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}

.name-input:focus {
    border-color: #3b82f6;
    color: #eee;
}

#no-selection {
    color: #555;
    font-size: 12px;
    padding: 4px 0 8px 0;
}

/* Render Action Button */
.glow-btn {
    margin-top: auto;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border: none;
    color: white;
    font-weight: 600;
    font-size: 14px;
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
}

.glow-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.glow-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.glow-btn svg {
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

#instructions {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.65);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 12px;
    pointer-events: none;
    white-space: nowrap;
    color: #ccc;
    z-index: 10;
}

/* FAB — shared layout for all viewport FAB strips */
#fab-select,
#fab-solid-extrude,
#fab-loopcut {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    gap: 12px;
}

/* FAB — shared button style */
.fab-mode-btn,
#btn-fab-solid-extrude,
#btn-fab-linked-face,
#btn-fab-loopcut-h,
#btn-fab-loopcut-v {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(30, 30, 30, 0.92);
    border: 2px solid #444;
    color: #d4d4d8;
    cursor: pointer;
    font-size: 8px;
    font-weight: 600;
    letter-spacing: 0.03em;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    touch-action: manipulation;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.fab-mode-btn:hover,
#btn-fab-solid-extrude:hover,
#btn-fab-linked-face:hover,
#btn-fab-loopcut-h:hover,
#btn-fab-loopcut-v:hover {
    background: rgba(50, 50, 50, 0.95);
    border-color: #666;
}

.fab-mode-btn.active,
#btn-fab-solid-extrude.active,
#btn-fab-linked-face.active,
#btn-fab-loopcut-h.active,
#btn-fab-loopcut-v.active {
    background: #2563eb;
    border-color: #1d4ed8;
    color: #fff;
}

/* Scrollbar */
.panel::-webkit-scrollbar {
    width: 5px;
}

.panel::-webkit-scrollbar-track {
    background: transparent;
}

.panel::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

.panel::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* === Render Overlay === */
#render-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.render-modal {
    background: #252525;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90vw;
    max-height: 90vh;
    box-sizing: border-box;
}

#render-progress-container {
    width: 300px;
    height: 6px;
    background: #1e1e1e;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 20px;
    border: 1px solid #333;
}

#render-progress-bar {
    width: 0%;
    height: 100%;
    background: #3b82f6;
    transition: width 0.1s linear;
}

.render-image-wrapper {
    background: #111;
    border-radius: 8px;
    border: 1px solid #333;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

#render-result-img {
    max-width: 100%;
    max-height: 60vh;
    display: block;
    object-fit: contain;
}

#render-actions {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
}

#render-actions .tool-btn {
    width: auto;
    min-width: 120px;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 24px;
}

/* === Panel Tabs === */
.panel-tabs {
    display: flex;
    gap: 3px;
    background: #1a1a1a;
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.panel-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: #777;
    padding: 6px 4px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    transition: all 0.15s;
    font-family: inherit;
}

.panel-tab:hover {
    color: #d4d4d8;
}

.panel-tab.active {
    background: #2d2d2d;
    color: #f4f4f5;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* === Scene Graph === */
#scene-graph-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.scene-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 5px 5px 6px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.12s, border-color 0.12s;
}

.scene-item:hover {
    background: #2e2e2e;
}

.scene-item.active {
    background: #1a2e4a;
    border-color: #2563eb;
}

.scene-item.obj-hidden {
    opacity: 0.45;
}

.scene-vis-btn,
.scene-del-btn {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.12s;
}

.scene-vis-btn:hover {
    color: #d4d4d8;
}

.scene-del-btn {
    opacity: 0;
    transition: opacity 0.12s, color 0.12s;
}

.scene-item:hover .scene-del-btn {
    opacity: 1;
}

.scene-del-btn:hover {
    color: #f87171;
}

.scene-item-name {
    flex: 1;
    font-size: 12px;
    color: #e4e4e7;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.scene-empty {
    color: #555;
    font-size: 12px;
    padding: 4px 2px;
    font-style: italic;
}