:root {
    --bg: #10151c;
    --bg-raised: #171e27;
    --bg-inset: #0c1015;
    --line: #2a3542;
    --text: #e7eef5;
    --muted: #8b98a8;
    --accent: #e8a87c;
    --accent-dim: #b67d52;
    --cyan: #6aa7c8;
    --lime: #c4d675;
    --danger: #d17a6a;
    --axis-x: #d17a6a;
    --axis-y: #8fbf7a;
    --axis-z: #6aa7c8;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
    --radius: 12px;
    --font: "Segoe UI", "Noto Sans", sans-serif;
    --mono: "Cascadia Mono", "Consolas", monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(1200px 600px at 10% -10%, #1b2733 0%, var(--bg) 55%);
    color: var(--text);
    font-family: var(--font);
}

body {
    min-height: 100vh;
}

.editor-body {
    height: 100vh;
    overflow: hidden;
}

h1,
h2,
h3 {
    margin: 0;
    font-weight: 650;
    letter-spacing: 0.01em;
}

a {
    color: var(--accent);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--line);
    background: rgba(16, 21, 28, 0.92);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 5;
}

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

.brand h1 {
    font-size: 1.05rem;
}

.brand-mark {
    width: 14px;
    height: 14px;
    border: 2px solid var(--accent);
    box-shadow: 7px 7px 0 0 var(--cyan);
}

.nav {
    display: flex;
    gap: 8px;
}

.nav-link {
    color: var(--muted);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.92rem;
}

.nav-link.is-active,
.nav-link:hover {
    color: var(--text);
    background: #22303d;
}

.hint {
    margin: 0 0 0 auto;
    color: var(--muted);
    font-size: 0.82rem;
}

.workspace {
    display: grid;
    grid-template-columns: 340px 1fr;
    height: calc(100vh - 57px);
}

.panel {
    border-right: 1px solid var(--line);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: rgba(12, 16, 21, 0.55);
    overflow: auto;
}

.card {
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 12px;
}

.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.field-span {
    grid-column: 1 / -1;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--muted);
}

input[type="number"],
input[type="color"] {
    background: var(--bg-inset);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    font: 0.95rem/1.2 var(--mono);
}

input[type="color"] {
    height: 38px;
    padding: 4px;
    cursor: pointer;
}

input:disabled {
    opacity: 0.45;
}

.file-field {
    position: relative;
    display: block;
}

.file-field input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-field span {
    display: block;
    text-align: center;
    padding: 10px;
    border: 1px dashed var(--accent-dim);
    border-radius: 8px;
    color: var(--accent);
    background: #1a1511;
}

.image-stage {
    margin-top: 12px;
    height: 160px;
    border-radius: 8px;
    background:
        linear-gradient(45deg, #1b232c 25%, transparent 25%),
        linear-gradient(-45deg, #1b232c 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #1b232c 75%),
        linear-gradient(-45deg, transparent 75%, #1b232c 75%);
    background-size: 18px 18px;
    background-position: 0 0, 0 9px, 9px -9px, -9px 0;
    background-color: #12181f;
    border: 1px solid var(--line);
    overflow: hidden;
    display: grid;
    place-items: center;
}

.image-stage img {
    max-width: 100%;
    max-height: 100%;
    display: none;
    object-fit: contain;
}

.image-stage.has-image img {
    display: block;
}

.image-stage.has-image .image-placeholder {
    display: none;
}

.image-placeholder {
    margin: 0;
    padding: 12px;
    color: var(--muted);
    font-size: 0.82rem;
    text-align: center;
}

.toggle-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0;
}

.check {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    color: var(--text);
}

.check input {
    accent-color: var(--accent);
}

.btn {
    width: 100%;
    border: 0;
    border-radius: 8px;
    padding: 10px;
    background: linear-gradient(180deg, #3a2a20, #2a1d16);
    color: var(--accent);
    border: 1px solid var(--accent-dim);
    cursor: pointer;
    font-weight: 650;
}

.btn:hover:not(:disabled) {
    filter: brightness(1.08);
}

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

.btn-secondary {
    background: linear-gradient(180deg, #24303a, #1a222c);
    color: var(--cyan);
    border: 1px solid #3d5566;
}

.btn-secondary.is-active {
    background: linear-gradient(180deg, #3a2a20, #2a1d16);
    color: var(--accent);
    border-color: var(--accent-dim);
}

.image-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.bump-strength {
    margin-top: 10px;
}

.vertex-meta,
.field-note,
.status {
    color: var(--muted);
    font-size: 0.8rem;
}

.field-note {
    margin: 10px 0 0;
}

.viewport-wrap {
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    background: #0a0d11;
    user-select: none;
}

#sceneCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

#sceneCanvas.is-dragging {
    cursor: grabbing;
}

.viewport-legend {
    position: absolute;
    left: 16px;
    bottom: 42px;
    display: flex;
    gap: 12px;
    color: var(--muted);
    font-size: 0.78rem;
}

.swatch {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 4px;
    vertical-align: middle;
}

.swatch.x { background: var(--axis-x); }
.swatch.y { background: var(--axis-y); }
.swatch.z { background: var(--axis-z); }

.status {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 12px;
    margin: 0;
    font-family: var(--mono);
}

.doc-body {
    background: var(--bg);
}

.doc {
    max-width: 860px;
    margin: 0 auto;
    padding: 36px 22px 80px;
}

.doc-hero h2 {
    font-size: 2rem;
    margin: 6px 0 12px;
}

.eyebrow {
    color: var(--accent);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-size: 0.72rem;
    margin: 0;
}

.toc,
.doc section {
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    margin: 18px 0;
}

.toc ol,
.plain {
    color: var(--muted);
}

.doc h3 {
    font-size: 1.15rem;
    margin-bottom: 12px;
}

.doc p,
.doc li {
    line-height: 1.65;
}

.formula-block {
    background: var(--bg-inset);
    border-left: 3px solid var(--accent);
    padding: 12px 16px;
    margin: 14px 0;
    border-radius: 0 8px 8px 0;
}

.formula-label,
.formula-note {
    color: var(--muted);
    font-size: 0.8rem;
    margin: 0 0 8px;
}

.formula {
    font-family: "Cambria Math", Georgia, serif;
    font-size: 1.05rem;
    margin: 6px 0;
}

.matrix {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--lime);
    margin: 0;
    overflow-x: auto;
}

.diagram {
    width: 100%;
    height: auto;
    margin: 12px 0;
}

code {
    font-family: var(--mono);
    color: var(--cyan);
    font-size: 0.9em;
}

@media (max-width: 980px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .panel {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    #sceneCanvas {
        height: 70vh;
    }

    .hint {
        display: none;
    }
}
