/* ===== CSS Custom Properties ===== */
:root {
    --color-bg: #0f1117;
    --color-surface: #1a1d27;
    --color-surface-hover: #222632;
    --color-surface-raised: #252a38;
    --color-border: #2e3447;
    --color-border-subtle: #232838;
    --color-text: #e8eaf0;
    --color-text-secondary: #9399ab;
    --color-text-muted: #6b7186;
    --color-primary: #6c8aff;
    --color-primary-hover: #85a0ff;
    --color-primary-glow: rgba(108, 138, 255, 0.15);
    --color-accent: #38d9a9;
    --color-accent-hover: #63e6be;
    --color-accent-glow: rgba(56, 217, 169, 0.15);
    --color-outline: #a0aec0;
    --color-outline-hover: #cbd5e0;
    --color-danger: #ff6b6b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

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

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
header {
    height: 56px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    z-index: 100;
    position: relative;
}

.header-inner {
    display: flex;
    align-items: center;
    width: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--color-primary);
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

.logo h1 span {
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    height: calc(100vh - 56px);
}

/* ===== Editor Panel ===== */
.editor-panel {
    width: 420px;
    min-width: 360px;
    height: 100%;
    overflow-y: auto;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.editor-panel::-webkit-scrollbar {
    width: 6px;
}

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

.editor-panel::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.editor-panel::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* ===== Form Sections ===== */
.form-section {
    padding: 16px 0;
    border-bottom: 1px solid var(--color-border-subtle);
}

.form-section:first-child {
    padding-top: 0;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    color: var(--color-text-secondary);
}

.section-header h2 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-secondary);
}

.section-header svg {
    width: 16px;
    height: 16px;
    opacity: 0.6;
}

/* ===== Form Elements ===== */
label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
    margin-top: 10px;
}

label:first-of-type {
    margin-top: 0;
}

.unit {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-weight: 400;
}

textarea,
input[type="number"] {
    width: 100%;
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font);
    font-size: 0.85rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    resize: vertical;
}

textarea:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

textarea.readonly-field {
    opacity: 0.6;
    cursor: default;
    resize: none;
}

textarea {
    min-height: 80px;
}

input[type="number"] {
    max-width: 100%;
}

.hint {
    display: block;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.hint.inline {
    display: inline;
    margin-left: 4px;
}

/* ===== Settings Grid ===== */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.setting-item label {
    margin-top: 0;
}

/* ===== Checkbox ===== */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 400;
    color: var(--color-text);
    margin: 0;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkmark {
    width: 18px;
    height: 18px;
    min-width: 18px;
    border: 1.5px solid var(--color-border);
    border-radius: 5px;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    position: relative;
}

.checkmark::after {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--color-primary);
    opacity: 0;
    transform: scale(0);
    transition: all var(--transition);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    border-color: var(--color-primary);
    background: var(--color-primary-glow);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    opacity: 1;
    transform: scale(1);
}

.checkbox-label input[type="checkbox"]:focus-visible + .checkmark {
    box-shadow: 0 0 0 3px var(--color-primary-glow);
}

/* ===== Button Rows ===== */
.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn svg {
    flex-shrink: 0;
}

/* Secondary */
.btn-secondary {
    background: var(--color-surface-raised);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface-hover);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

/* Primary */
.btn-primary {
    background: var(--color-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(108, 138, 255, 0.25);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    box-shadow: 0 4px 16px rgba(108, 138, 255, 0.35);
}

/* Accent */
.btn-accent {
    background: var(--color-accent);
    color: #0f1117;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(56, 217, 169, 0.25);
}

.btn-accent:hover:not(:disabled) {
    background: var(--color-accent-hover);
    box-shadow: 0 4px 16px rgba(56, 217, 169, 0.35);
}

/* Outline */
.btn-outline {
    background: transparent;
    color: var(--color-outline);
    border: 1px solid var(--color-border);
}

.btn-outline:hover:not(:disabled) {
    color: var(--color-outline-hover);
    border-color: var(--color-text-muted);
    background: var(--color-surface-hover);
}

/* ===== Form Actions ===== */
.form-actions {
    display: flex;
    gap: 8px;
    padding-top: 20px;
    flex-wrap: wrap;
}

.form-actions .btn {
    flex: 1;
    justify-content: center;
    min-width: 100px;
}

/* ===== Preview Panel ===== */
.preview-panel {
    flex: 1;
    height: 100%;
    position: relative;
    background: var(--color-bg);
    overflow: hidden;
}

#preview\.threejs {
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ===== dat.gui override ===== */
.gui-wrap {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.gui-wrap > .main {
    pointer-events: all;
    max-height: 100%;
    overflow: auto;
}

/* ===== Spinner ===== */
.spinner {
    position: absolute;
    inset: 0;
    display: none;
    z-index: 50;
    background: rgba(15, 17, 23, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.spinner-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.spinner-ring {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    animation: spin 0.8s linear infinite;
}

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

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
    }

    .editor-panel {
        width: 100%;
        min-width: unset;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .preview-panel {
        min-height: 50vh;
    }

    .form-actions {
        flex-wrap: wrap;
    }
}

/* ===== Selection ===== */
::selection {
    background: var(--color-primary);
    color: #fff;
}

/* ===== Focus Visible ===== */
.btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}
}