:root {
    color-scheme: light;
    --text: #0f1117;
    --muted: #57606a;
    --line: #e6e8ee;
    --accent: #3B5CF6;
    --accent-hover: #2d4ed4;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --warn-bg: #fff4e5;
    --warn: #8a4b08;
    --note-bg: #eef1ff;
    --shadow: 0 10px 30px rgba(15, 17, 23, 0.08);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.45;
}

.layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
}
.topbar {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 1.1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: inherit;
    text-decoration: none;
}
.brand img {
    width: 2.5rem;
    height: 2.5rem;
    display: block;
    flex: 0 0 auto;
    border-radius: 0.45rem;
}
.brand > span { display: flex; flex-direction: column; gap: 0.05rem; }
.brand-name {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.15;
}
.topbar .product {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 650;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--accent);
}
.topbar .lede {
    margin: 0;
    max-width: 28rem;
    text-align: right;
    color: var(--muted);
    font-size: 0.9rem;
}

.pane {
    background: var(--surface);
    padding: 1rem 1.1rem 1.5rem;
    overflow: auto;
}
.pane { border-right: 1px solid var(--line); }
.source {
    border-right: 0;
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 1rem;
}
.source-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.pane h2 {
    margin: 0 0 0.7rem;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}
main { overflow: auto; min-width: 0; }

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.lede { margin: 0; color: var(--muted); font-size: 0.92rem; }

.field { display: block; margin: 0.55rem 0; font-size: 0.86rem; }
.field > span { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); }
.field b { font-weight: 600; color: var(--text); }
.field b .help-tip { margin-left: 0.3rem; vertical-align: 0.05em; }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field textarea, .field select {
    width: 100%;
    margin-top: 0.3rem;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 0.55rem;
    padding: 0.45rem 0.55rem;
}
.field textarea { resize: vertical; min-height: 4.5rem; }
.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.2rem;
    padding: 0.2rem;
    margin-bottom: 0.8rem;
    background: #171b22;
    border-radius: 0.7rem;
}
.tabs button,
.tabs .tab {
    font: inherit;
    font-size: 0.86rem;
    font-weight: 600;
    border: 0;
    border-radius: 0.55rem;
    padding: 0.4rem 0.5rem;
    background: transparent;
    color: #c5cad3;
    cursor: pointer;
    text-align: center;
}
.tabs button.on,
.tabs .tab.on {
    background: var(--accent);
    color: white;
}
.body-tabs .tab,
.shape-tabs .tab,
.art-tabs .tab {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}
.body-tabs .tab input,
.shape-tabs .tab input,
.art-tabs .tab input {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
}
.body-tabs .tab:has(input:checked),
.shape-tabs .tab:has(input:checked),
.art-tabs .tab:has(input:checked) {
    background: var(--accent);
    color: white;
}
.shape-tabs { margin-top: -0.35rem; }
.section {
    margin: 0 0 0.85rem;
    padding-bottom: 0.35rem;
}
.section-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin: 0 0 0.55rem;
    font-size: 0.78rem;
    font-weight: 650;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
}
.section-collapsible {
    border-top: 1px solid var(--line);
    padding-top: 0.65rem;
}
.section-collapsible > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}
.section-collapsible > summary::-webkit-details-marker { display: none; }
.section-collapsible > summary::before {
    content: "▸";
    display: inline-block;
    margin-right: 0.35rem;
    color: var(--muted);
}
.section-collapsible[open] > summary::before { content: "▾"; }
.collapsible-body { padding-top: 0.15rem; }
.settings-group {
    margin-top: 0.75rem;
    padding: 0.65rem 0.7rem 0.55rem;
    background: var(--bg);
    border-radius: 0.65rem;
}
.settings-group-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.72rem;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}
.settings-group .switch-row { margin-top: 0.2rem; }
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0.9rem 0 0.2rem;
}
.switch-label {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.help-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    font-style: normal;
    line-height: 1;
    cursor: help;
    flex: 0 0 auto;
    transition: border-color 0.12s, color 0.12s;
}
.help-tip:hover, .help-tip:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}
.help-tip-bubble {
    position: fixed;
    z-index: 1000;
    max-width: 15rem;
    padding: 0.5rem 0.65rem;
    border-radius: 0.55rem;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font-size: 0.8rem;
    line-height: 1.4;
    font-weight: 400;
    box-shadow: var(--shadow);
    pointer-events: none;
}
.toggle {
    position: relative;
    display: inline-block;
    width: 2.75rem;
    height: 1.55rem;
    flex: 0 0 auto;
    cursor: pointer;
}
.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle .slider {
    position: absolute;
    inset: 0;
    background: #171b22;
    border-radius: 999px;
    transition: background 0.18s ease;
}
.toggle .slider::before {
    content: "";
    position: absolute;
    width: 1.2rem;
    height: 1.2rem;
    left: 0.18rem;
    top: 0.175rem;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.18s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.toggle input[type="checkbox"]:checked + .slider { background: var(--accent); }
.toggle input[type="checkbox"]:checked + .slider::before { transform: translateX(1.15rem); }
.toggle input[type="checkbox"]:focus-visible + .slider { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }

.art-actions { display: grid; gap: 0.45rem; margin-top: 0.8rem; }
.upload, .ghost, .btn {
    font: inherit;
    border-radius: 0.65rem;
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}
.upload {
    display: block;
    background: var(--accent);
    color: white;
}
.upload:hover { background: var(--accent-hover); }
.upload input { display: none; }
.ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
}
.ghost:hover { background: var(--bg); }
.font-add { display: block; margin-top: 0.55rem; }
.font-add input { display: none; }
.hint { color: var(--muted); font-size: 0.78rem; margin: 0.8rem 0 0; }

main { padding: 1rem; }
#stage.htmx-request { opacity: 0.55; }
.view-wrap {
    position: relative;
    height: min(62vh, 560px);
    background: #e0e2e6;
    border-radius: 0.9rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}
#view { width: 100%; height: 100%; display: block; cursor: grab; }
#view:active { cursor: grabbing; }
.view-toggle {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    padding: 0.2rem;
    background: rgba(23, 27, 34, 0.88);
    border-radius: 0.6rem;
}
.view-toggle button {
    font: inherit;
    font-size: 0.78rem;
    color: #c5cad3;
    background: transparent;
    border: 0;
    border-radius: 0.45rem;
    padding: 0.35rem 0.6rem;
    cursor: pointer;
}
.view-toggle button.on {
    background: var(--accent);
    color: white;
}
.view-hint {
    position: absolute;
    left: 0.75rem;
    bottom: 0.55rem;
    margin: 0;
    color: #c5cad3;
    font-size: 0.75rem;
    pointer-events: none;
}
body.together .hint-bed,
body:not(.together) .hint-fit,
body.exploded .hint-fit,
body:not(.exploded) .hint-explode,
body.together .plan-bed,
body:not(.together) .plan-together { display: none; }
.plan {
    margin-top: 0.75rem;
    background: #e0e2e6;
    border-radius: 0.9rem;
    overflow: hidden;
}
.plan svg { display: block; width: 100%; height: 180px; }
.readout {
    margin-top: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0.75rem;
}
.readout summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    padding: 0.55rem 0.75rem;
    list-style: none;
}
.readout summary::-webkit-details-marker { display: none; }
.readout summary::before {
    content: "▸";
    display: inline-block;
    margin-right: 0.4rem;
    color: var(--muted);
}
.readout[open] summary::before { content: "▾"; }
.readout:not([open]) .readout-body { display: none; }
.readout-body { padding: 0 0.75rem 0.75rem; }
.warn { margin-top: 0.75rem; }
.warn, .note {
    margin: 0 0 0.4rem;
    padding: 0.45rem 0.65rem;
    border-radius: 0.55rem;
    font-size: 0.88rem;
}
.warn { background: var(--warn-bg); color: var(--warn); }
.note { background: var(--note-bg); color: #24306e; }
.swatches { display: flex; flex-wrap: wrap; gap: 0.45rem 0.8rem; list-style: none; padding: 0; margin: 0.4rem 0; }
.swatches li { display: flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.swatches i { width: 0.9rem; height: 0.9rem; border-radius: 0.25rem; border: 1px solid rgba(0,0,0,0.15); display: block; }
.meta { color: var(--muted); font-size: 0.82rem; margin: 0.2rem 0 0.6rem; }
.download {
    flex: 0 0 auto;
    margin-top: auto;
    padding: 0.85rem 0 0.15rem;
    border-top: 1px solid var(--line);
    background: var(--surface);
    position: sticky;
    bottom: 0;
}
.download .btn {
    display: block;
    width: 100%;
    text-align: center;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.download .btn:hover { background: var(--accent-hover); }
.download .btn:disabled,
.download button.btn:disabled {
    background: var(--text);
    opacity: 0.35;
}
.legal {
    margin-top: 0.7rem;
    text-align: center;
}
.legal-by {
    margin: 0;
    color: var(--muted);
    font-size: 0.74rem;
    line-height: 1.45;
}
.legal-by a {
    color: inherit;
    text-decoration: none;
}
.legal-by a:hover { color: var(--text); }
.legal-logo {
    height: 1.05rem;
    width: auto;
    vertical-align: -0.2em;
    margin-left: 0.15rem;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.legal-by a:hover .legal-logo { opacity: 1; }
.footer-copy {
    margin: 0.45rem 0 0;
    color: var(--muted);
    font-size: 0.68rem;
    line-height: 1.4;
}
.btn {
    display: inline-block;
    background: var(--text);
    color: white;
    border: 0;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.orient { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.78rem; }

@media (max-width: 980px) {
    .layout { grid-template-columns: 1fr; grid-template-rows: auto; height: auto; }
    .topbar { flex-direction: column; align-items: flex-start; }
    .topbar .lede { text-align: left; max-width: none; }
    .pane, main { overflow: visible; }
    .pane, .source { border: 0; border-bottom: 1px solid var(--line); }
    .view-wrap { height: 420px; }
}
