:root {
    color-scheme: dark;
    --bg: #071018;
    --surface: #0d1923;
    --surface-raised: #122230;
    --surface-soft: #172a38;
    --line: rgba(173, 210, 230, 0.14);
    --line-strong: rgba(173, 210, 230, 0.24);
    --text: #eef7fb;
    --muted: #91a7b5;
    --accent: #65d9c2;
    --accent-strong: #27b99d;
    --accent-ink: #03271f;
    --blue: #67b8f7;
    --danger: #ff7f88;
    --warning: #f4c96b;
    --success: #67dda3;
    --shadow: 0 28px 90px rgba(0, 0, 0, 0.38);
    --radius-lg: 22px;
    --radius-md: 15px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 12% -5%, rgba(39, 185, 157, 0.15), transparent 30rem),
        radial-gradient(circle at 92% 12%, rgba(103, 184, 247, 0.11), transparent 31rem),
        linear-gradient(145deg, #071018, #09131c 62%, #071018);
}

button, input { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
    width: min(1480px, calc(100% - 40px));
    margin: 0 auto;
    padding: 42px 0 52px;
}

.hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 28px;
}

.eyebrow, .viewer-kicker {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
    margin-bottom: 8px;
    font-size: clamp(2rem, 4vw, 3.35rem);
    line-height: 1;
    letter-spacing: -0.045em;
}

.subtitle {
    max-width: 680px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.55;
}

.service-state {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #bfd0d9;
    background: rgba(13, 25, 35, 0.8);
    font-size: 0.78rem;
    font-weight: 700;
}

.state-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(103, 221, 163, 0.1);
}

.service-state[data-state="processing"] .state-dot { background: var(--warning); animation: pulse 1.2s ease-in-out infinite; }
.service-state[data-state="failed"] .state-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 127, 136, 0.1); }

.workspace {
    display: grid;
    grid-template-columns: minmax(310px, 390px) minmax(0, 1fr);
    min-height: 700px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: rgba(13, 25, 35, 0.94);
    box-shadow: var(--shadow);
}

.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 28px;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(18, 34, 48, 0.92), rgba(11, 23, 32, 0.92));
}

label {
    display: block;
    margin-bottom: 9px;
    color: #d9e8ee;
    font-size: 0.84rem;
    font-weight: 720;
}

.input-wrap { position: relative; }

.input-wrap input {
    width: 100%;
    padding: 15px 78px 15px 15px;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    outline: none;
    color: var(--text);
    background: rgba(4, 13, 20, 0.68);
    font-size: 1rem;
    transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.input-wrap input:focus {
    border-color: var(--accent);
    background: rgba(4, 13, 20, 0.9);
    box-shadow: 0 0 0 3px rgba(101, 217, 194, 0.13);
}

.input-wrap input:disabled { opacity: 0.62; }

#character-count {
    position: absolute;
    top: 50%;
    right: 13px;
    transform: translateY(-50%);
    color: #738b9a;
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
}

.field-help {
    margin: 8px 2px 16px;
    color: #718a99;
    font-size: 0.73rem;
    line-height: 1.45;
}

.primary-button {
    display: inline-flex;
    width: 100%;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    border-radius: 12px;
    color: var(--accent-ink);
    background: linear-gradient(135deg, #72e8d0, #45c9ae);
    box-shadow: 0 10px 24px rgba(39, 185, 157, 0.18);
    cursor: pointer;
    font-weight: 780;
    transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease;
}

.primary-button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.04); }
.primary-button:active:not(:disabled) { transform: translateY(0); }
.primary-button:focus-visible, .icon-button:focus-visible, .download-item:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.primary-button:disabled { cursor: wait; opacity: 0.72; }

.button-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(3, 39, 31, 0.25);
    border-top-color: var(--accent-ink);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.primary-button.is-busy .button-spinner { display: block; }

.job-card, .downloads-card {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(5, 15, 22, 0.38);
}

.job-heading-row, .downloads-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.job-card h2, .downloads-card h2, .viewer-toolbar h2 {
    margin-bottom: 0;
    font-size: 0.96rem;
    letter-spacing: -0.01em;
}

.status-pill {
    padding: 5px 8px;
    border-radius: 999px;
    color: #9fb1bd;
    background: rgba(145, 167, 181, 0.1);
    font-size: 0.63rem;
    font-weight: 780;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.status-pill[data-state="queued"] { color: var(--warning); background: rgba(244, 201, 107, 0.1); }
.status-pill[data-state="processing"] { color: var(--blue); background: rgba(103, 184, 247, 0.1); }
.status-pill[data-state="complete"] { color: var(--success); background: rgba(103, 221, 163, 0.1); }
.status-pill[data-state="failed"] { color: var(--danger); background: rgba(255, 127, 136, 0.1); }

#status-message {
    min-height: 36px;
    margin: 14px 0 12px;
    color: var(--muted);
    font-size: 0.79rem;
    line-height: 1.45;
}

.progress-track {
    width: 100%;
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(145, 167, 181, 0.12);
}

.progress-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent-strong), var(--blue));
    transition: width 350ms ease;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    margin: 8px 0 0;
    color: #6f8796;
    font-size: 0.66rem;
    font-variant-numeric: tabular-nums;
}

.downloads-card { min-height: 170px; }
.downloads-title-row { margin-bottom: 14px; }
#file-count { color: #6f8796; font-size: 0.7rem; }

.empty-downloads {
    display: grid;
    min-height: 94px;
    place-items: center;
    border: 1px dashed var(--line-strong);
    border-radius: 11px;
    color: #657d8c;
    font-size: 0.75rem;
    text-align: center;
}

.downloads-list { display: grid; gap: 8px; max-height: 290px; overflow-y: auto; padding: 1px 3px 1px 1px; }

.download-item {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 24px;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--text);
    background: rgba(23, 42, 56, 0.65);
    text-decoration: none;
    transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.download-item:hover { border-color: var(--line-strong); background: rgba(28, 52, 68, 0.85); transform: translateX(1px); }
.download-bundle { border-color: rgba(101, 217, 194, 0.18); background: rgba(39, 185, 157, 0.09); }

.file-format {
    display: grid;
    width: 38px;
    height: 32px;
    place-items: center;
    border-radius: 7px;
    color: var(--blue);
    background: rgba(103, 184, 247, 0.1);
    font-size: 0.57rem;
    font-weight: 800;
}

.download-bundle .file-format { color: var(--accent); background: rgba(101, 217, 194, 0.1); }
.file-copy { min-width: 0; }
.file-copy strong, .file-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-copy strong { margin-bottom: 3px; font-size: 0.74rem; }
.file-copy small { color: #6f8796; font-size: 0.63rem; }
.download-arrow { color: #718b9a; text-align: center; }

.viewer-panel { display: grid; min-width: 0; grid-template-rows: auto auto minmax(500px, 1fr) auto; padding: 26px 26px 16px; }

.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 2px 18px;
}

.viewer-kicker { margin-bottom: 5px; color: #6f8796; font-size: 0.61rem; }
.viewer-actions { display: flex; gap: 8px; }

.icon-button {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: #a7bbc6;
    background: rgba(5, 15, 22, 0.44);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 680;
}

.icon-button:hover:not(:disabled) { border-color: var(--line-strong); color: var(--text); }
.icon-button:disabled { cursor: not-allowed; opacity: 0.38; }

.viewer-controls {
    display: grid;
    grid-template-columns: minmax(190px, 0.8fr) minmax(260px, 1.6fr);
    gap: 20px;
    margin: 0 2px 16px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: rgba(5, 15, 22, 0.48);
}

.control-label-row, .part-control-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 9px;
    color: #b8cbd4;
    font-size: 0.7rem;
    font-weight: 720;
}

.control-label-row label { margin: 0; font-size: inherit; }
.control-label-row output { color: var(--accent); font-variant-numeric: tabular-nums; }
.explode-control input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.part-control-heading button {
    padding: 2px 0;
    border: 0;
    color: var(--blue);
    background: transparent;
    cursor: pointer;
    font-size: 0.66rem;
}

.part-toggles { display: flex; flex-wrap: wrap; gap: 7px; }
.part-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #b9cad2;
    background: rgba(20, 39, 52, 0.72);
    cursor: pointer;
    font-size: 0.66rem;
    font-weight: 650;
}
.part-toggle:has(input:not(:checked)) { opacity: 0.48; }
.part-toggle input { width: 13px; height: 13px; margin: 0; accent-color: var(--accent); }
.part-swatch { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255,255,255,0.2); }

.viewer-stage {
    position: relative;
    min-height: 500px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 17px;
    background:
        radial-gradient(circle at center, rgba(55, 100, 126, 0.12), transparent 52%),
        #08121a;
}

.viewer-stage::after {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 32%;
    background: linear-gradient(transparent, rgba(3, 9, 14, 0.25));
    content: "";
    pointer-events: none;
}

#model-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    outline: none;
    cursor: grab;
    touch-action: none;
}

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

.viewer-placeholder, .viewer-loading {
    position: absolute;
    z-index: 2;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    padding: 24px;
    text-align: center;
    pointer-events: none;
}

.viewer-placeholder[hidden], .viewer-loading[hidden] { display: none; }
.viewer-placeholder h3 { margin: 20px 0 7px; color: #c8d7de; font-size: 0.98rem; }
.viewer-placeholder p { max-width: 340px; margin: 0; color: #667e8d; font-size: 0.74rem; line-height: 1.5; }

.placeholder-mark { position: relative; width: 68px; height: 58px; opacity: 0.7; }
.placeholder-mark span { position: absolute; inset: 0; border: 1px solid rgba(101, 217, 194, 0.38); transform: rotate(30deg) skew(-5deg); }
.placeholder-mark span:nth-child(2) { transform: rotate(150deg) skew(-5deg); }
.placeholder-mark span:nth-child(3) { transform: rotate(270deg) skew(-5deg); }

.viewer-loading { gap: 15px; color: #a7bbc6; background: rgba(5, 14, 21, 0.72); font-size: 0.78rem; backdrop-filter: blur(3px); }
.large-spinner { width: 34px; height: 34px; border: 3px solid rgba(101, 217, 194, 0.16); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.75s linear infinite; }

.viewer-hint { margin: 11px 0 0; color: #596f7d; font-size: 0.65rem; text-align: center; }
.viewer-hint span { margin: 0 5px; color: #3d5260; }

.toast {
    position: fixed;
    z-index: 20;
    right: 24px;
    bottom: 24px;
    max-width: min(420px, calc(100% - 48px));
    padding: 13px 16px;
    border: 1px solid rgba(255, 127, 136, 0.28);
    border-radius: 11px;
    color: #ffdfe1;
    background: rgba(67, 23, 29, 0.96);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    font-size: 0.78rem;
    line-height: 1.45;
}

[hidden] { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.45; transform: scale(0.8); } }

@media (max-width: 920px) {
    .app-shell { width: min(100% - 24px, 760px); padding-top: 28px; }
    .workspace { grid-template-columns: 1fr; }
    .controls-panel { border-right: 0; border-bottom: 1px solid var(--line); }
    .viewer-panel { grid-template-rows: auto auto minmax(480px, 62vh) auto; }
}

@media (max-width: 560px) {
    .app-shell { width: 100%; padding: 22px 12px 28px; }
    .hero { align-items: flex-start; flex-direction: column; gap: 17px; padding: 0 5px; }
    .service-state { align-self: flex-start; }
    .workspace { border-radius: 17px; }
    .controls-panel, .viewer-panel { padding: 19px; }
    .viewer-toolbar { align-items: flex-start; }
    .viewer-actions { flex-direction: column; }
    .viewer-controls { grid-template-columns: 1fr; }
    .viewer-stage { min-height: 420px; }
    .viewer-panel { grid-template-rows: auto auto minmax(420px, 58vh) auto; }
    .viewer-hint { line-height: 1.7; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
