:root {
    --font-heading: "Space Grotesk", "Segoe UI", sans-serif;
    --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
    --font-mono: "IBM Plex Mono", "SFMono-Regular", monospace;
    --bg-base: #07131d;
    --line: rgba(135, 170, 193, 0.22);
    --line-strong: rgba(115, 244, 211, 0.36);
    --accent: #73f4d3;
    --accent-strong: #f6b05e;
    --text-1: #f3f7fb;
    --text-2: #afc4d5;
    --text-3: #7d96aa;
    --success: #8af0c7;
    --danger: #ff9f97;
}

* {
    box-sizing: border-box;
}

body,
h1,
h2,
h3,
p {
    margin: 0;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: #07131d;
    color: var(--text-1);
    overflow: hidden;
}

a,
button,
select,
input {
    font: inherit;
}

#container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background:
        radial-gradient(circle at 18% 12%, rgba(115, 244, 211, 0.11), transparent 26%),
        radial-gradient(circle at 85% 10%, rgba(246, 176, 94, 0.12), transparent 22%),
        linear-gradient(160deg, #07131d 0%, #0c1d2d 48%, #13293d 100%);
}

#container::before,
#container::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#container::before {
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 52px 52px;
    opacity: 0.48;
}

#container::after {
    background:
        radial-gradient(circle at 20% 90%, rgba(115, 244, 211, 0.08), transparent 24%),
        radial-gradient(circle at 92% 62%, rgba(246, 176, 94, 0.08), transparent 24%);
}

#viewer-container,
#viewer-canvas {
    width: 100%;
    height: 100%;
    display: block;
    position: relative;
    z-index: 1;
}

button,
.panel-link,
.library-actions button {
    min-height: 46px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-1);
    padding: 0.75rem 1rem;
    font-weight: 600;
    cursor: pointer;
    transition:
        transform 180ms ease,
        border-color 180ms ease,
        background 180ms ease,
        box-shadow 180ms ease,
        opacity 180ms ease;
    touch-action: manipulation;
}

button:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.2);
}

button:focus-visible,
select:focus-visible,
#controls-toggle:focus-visible,
#dropzone:focus-visible,
#back-link a:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px rgba(115, 244, 211, 0.18);
    border-color: var(--line-strong);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#controls,
#dropzone,
#loading,
#status,
#back-link a,
#model-tree,
#controls-toggle {
    backdrop-filter: blur(18px);
}

#controls {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 110;
    width: min(360px, calc(100vw - 48px));
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    padding: 24px;
    border-radius: 30px;
    border: 1px solid var(--line);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
        rgba(10, 20, 29, 0.8);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
}

#controls::-webkit-scrollbar,
#model-tree::-webkit-scrollbar {
    width: 8px;
}

#controls::-webkit-scrollbar-thumb,
#model-tree::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
}

.viewer-badge,
.control-section-label {
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.18em;
}

#controls h1 {
    margin: 12px 0 0;
    font-family: var(--font-heading);
    font-size: clamp(1.8rem, 4vw, 2.3rem);
    line-height: 0.98;
    letter-spacing: -0.04em;
}

.info {
    margin: 14px 0 0;
    color: var(--text-2);
    line-height: 1.65;
    font-size: 0.95rem;
}

.control-section {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.slider-group {
    margin-top: 12px;
}

.slider-group label {
    display: inline-block;
    margin-bottom: 8px;
    color: #d5e4ed;
    font-size: 0.9rem;
    font-weight: 600;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    color: var(--text-3);
    font-size: 0.78rem;
}

#controls-toggle {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 140;
    display: none;
    min-height: 46px;
    border-radius: 999px;
    padding: 0.75rem 1.1rem;
    border: 1px solid var(--line);
    background: rgba(10, 20, 29, 0.88);
    color: var(--text-1);
}

#dropzone {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 200;
    width: min(560px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
    padding: 34px 32px;
    border-radius: 34px;
    border: 1px solid rgba(115, 244, 211, 0.26);
    background:
        radial-gradient(circle at top, rgba(115, 244, 211, 0.14), transparent 56%),
        rgba(9, 18, 27, 0.9);
    box-shadow: 0 32px 100px rgba(0, 0, 0, 0.38);
    text-align: center;
}

#dropzone.hidden {
    display: none;
}

#dropzone h2 {
    margin: 14px 0 0;
    font-family: var(--font-heading);
    font-size: clamp(2rem, 5vw, 2.8rem);
    line-height: 0.96;
    letter-spacing: -0.04em;
}

#dropzone p {
    margin: 12px auto 0;
    max-width: 42ch;
    color: var(--text-2);
    line-height: 1.65;
}

.dropzone-badge {
    display: inline-flex;
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    border: 1px solid rgba(115, 244, 211, 0.24);
    background: rgba(115, 244, 211, 0.1);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dropzone-actions {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.dropzone-note {
    margin-top: 16px;
    color: var(--text-3);
    font-size: 0.88rem;
}

#file-input {
    display: none;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 210;
    width: min(360px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
    display: none;
    padding: 24px;
    border-radius: 26px;
    border: 1px solid var(--line);
    background: rgba(9, 18, 27, 0.9);
    box-shadow: 0 28px 72px rgba(0, 0, 0, 0.32);
    text-align: center;
}

#loading-text {
    color: var(--text-1);
    font-weight: 600;
}

.progress-bar {
    width: 100%;
    height: 12px;
    margin-top: 14px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-strong));
    transition: width 220ms ease;
}

#status {
    position: absolute;
    left: 24px;
    bottom: 24px;
    z-index: 110;
    max-width: min(420px, calc(100vw - 48px));
    padding: 0.8rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(9, 18, 27, 0.86);
    color: var(--text-2);
    font-size: 0.92rem;
    line-height: 1.5;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
}

#status.error {
    border-color: rgba(255, 159, 151, 0.28);
    color: var(--danger);
}

#status.success {
    border-color: rgba(138, 240, 199, 0.28);
    color: var(--success);
}

#back-link {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 115;
}

#back-link a {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    padding: 0.72rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(9, 18, 27, 0.86);
    color: var(--text-1);
    text-decoration: none;
    transition:
        transform 180ms ease,
        border-color 180ms ease,
        background 180ms ease;
}

#back-link a:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
    background: rgba(9, 18, 27, 0.96);
}

#model-tree {
    position: absolute;
    top: 80px;
    right: 24px;
    z-index: 110;
    display: none;
    width: min(280px, calc(100vw - 48px));
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    padding: 20px;
    border-radius: 28px;
    border: 1px solid var(--line);
    background: rgba(9, 18, 27, 0.86);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.3);
}

#model-tree.visible {
    display: block;
}

#model-tree h3 {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.12rem;
    letter-spacing: -0.03em;
}

.tree-item {
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    color: var(--text-2);
    font-size: 0.9rem;
    line-height: 1.55;
    transition: color 180ms ease;
}

.tree-item:last-child {
    border-bottom: none;
}

.tree-item:hover {
    color: var(--accent);
}

.userspace-library {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: none;
}

.userspace-library.visible {
    display: block;
}

.userspace-library h2 {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.12rem;
    letter-spacing: -0.03em;
}

.userspace-library p {
    margin: 8px 0 0;
    color: var(--text-2);
    font-size: 0.88rem;
    line-height: 1.6;
}

.userspace-library select {
    width: 100%;
    min-height: 46px;
    margin-top: 12px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-1);
    padding: 0.75rem 0.85rem;
}

.library-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.library-status {
    min-height: 18px;
    margin-top: 10px;
    color: var(--text-3);
    font-size: 0.82rem;
    line-height: 1.5;
}

@media (max-width: 900px) {
    #controls-toggle {
        display: inline-flex;
    }

    #controls {
        top: 76px;
        left: 16px;
        width: calc(100vw - 32px);
        max-height: calc(100vh - 148px);
        opacity: 0;
        pointer-events: none;
        transform: translateY(-12px);
        transition:
            opacity 200ms ease,
            transform 200ms ease;
    }

    #controls.mobile-visible {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }

    #back-link {
        top: 16px;
        right: 16px;
    }

    #status {
        left: 16px;
        bottom: 16px;
        max-width: calc(100vw - 32px);
    }

    #model-tree {
        top: auto;
        bottom: 76px;
        right: 16px;
        width: calc(100vw - 32px);
        max-height: 38vh;
    }
}

@media (max-width: 640px) {
    #controls,
    #dropzone,
    #loading,
    #model-tree {
        width: calc(100vw - 24px);
    }

    #controls {
        left: 12px;
        padding: 20px;
        border-radius: 24px;
    }

    #controls-toggle {
        top: 12px;
        left: 12px;
    }

    #back-link {
        top: 12px;
        right: 12px;
    }

    #dropzone,
    #loading {
        padding: 24px 20px;
    }

    .control-grid,
    .dropzone-actions,
    .library-actions {
        grid-template-columns: 1fr;
    }

    .dropzone-actions {
        display: grid;
    }

    .dropzone-actions > button {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition-duration: 1ms !important;
        transition-delay: 0ms !important;
    }
}
