/* =========================================================================
   STL Map Studio — visual system (copied from STL Sign Studio)
   A precision-tool aesthetic: hairline rules, micro labels, one accent.
   Tokens are defined for the dark theme on :root and overridden for light
   on [data-theme="light"]; nothing outside this block hardcodes a colour.
   ========================================================================= */

:root {
    color-scheme: dark;

    --bg:        #0f1113;
    --bg-panel:  #15171a;
    --bg-sunken: #101214;
    --bg-field:  #1b1e22;
    --bg-hover:  #22262b;
    --bg-active: #2b3037;

    --line:      #26292e;
    --line-soft: #1e2126;
    --line-hard: #363b42;

    --fg:        #e7eaee;
    --fg-2:      #9aa2ac;
    --fg-3:      #6b737d;

    --accent:      #ff8a3d;
    --accent-soft: #ffb083;
    --accent-wash: rgba(255, 138, 61, 0.13);
    --accent-ink:  #171008;

    --ok:   #4ec9a0;
    --warn: #e5b23c;
    --err:  #ef6a5a;

    --viewport: #16181b;
    --viewport-2: #0d0f11;

    --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    --r-sm: 3px;
    --r:    5px;
    --r-lg: 8px;

    --topbar-h: 50px;
    --status-h: 30px;
    --rail-w: 356px;

    --shadow-pop: 0 12px 34px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
    color-scheme: light;

    --bg:        #eceef1;
    --bg-panel:  #ffffff;
    --bg-sunken: #f4f5f7;
    --bg-field:  #ffffff;
    --bg-hover:  #f0f1f4;
    --bg-active: #e4e7ec;

    --line:      #dcdfe4;
    --line-soft: #e7e9ed;
    --line-hard: #c3c8d0;

    --fg:        #1b1e23;
    --fg-2:      #5c646f;
    --fg-3:      #868e99;

    --accent:      #d2621b;
    --accent-soft: #b8551620;
    --accent-wash: rgba(210, 98, 27, 0.10);
    --accent-ink:  #ffffff;

    --ok:   #1f9d74;
    --warn: #b3822a;
    --err:  #cf4436;

    --viewport: #e6e8ec;
    --viewport-2: #d3d7dd;

    --shadow-pop: 0 12px 30px rgba(20, 26, 36, 0.16), 0 2px 6px rgba(20, 26, 36, 0.1);
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

::selection { background: var(--accent-wash); }

/* Scrollbars kept thin so the rail reads as one surface, not a scrolling box. */
.scroll { scrollbar-width: thin; scrollbar-color: var(--line-hard) transparent; }
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-thumb {
    background: var(--line-hard);
    border: 3px solid transparent;
    background-clip: content-box;
    border-radius: 6px;
}
.scroll::-webkit-scrollbar-thumb:hover { background-clip: content-box; background-color: var(--fg-3); }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* =========================================================================
   App frame
   ========================================================================= */

.app {
    max-width: 100vw;
    overflow: hidden;
    display: grid;
    grid-template-rows: var(--topbar-h) 1fr var(--status-h);
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-areas:
        "topbar topbar"
        "rail   stage"
        "status status";
    height: 100vh;
    height: 100dvh;
}

/* ------------------------------ topbar ---------------------------------- */

.topbar {
    grid-area: topbar;
    /* The topbar sits in a `1fr` grid column, so its min-content width would
       otherwise set the floor for the whole app and push the page sideways. */
    min-width: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px 0 14px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--line);
}

.brand {
    min-width: 0;
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    gap: 9px;
    padding-right: 12px;
    margin-right: 2px;
    border-right: 1px solid var(--line);
    height: 100%;
}

.brand-mark {
    width: 24px;
    height: 24px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--accent-ink);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}
.brand-mark svg { width: 15px; height: 15px; display: block; }

.brand-name {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}
.brand-name b { font-weight: 600; }
.brand-name span { color: var(--fg-3); font-weight: 500; }

.topbar-spacer { flex: 1 1 auto; }

.topbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-sep {
    width: 1px;
    height: 22px;
    background: var(--line);
    margin: 0 4px;
}

/* ------------------------------ rail ------------------------------------ */

.rail {
    grid-area: rail;
    background: var(--bg-panel);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    overflow-x: hidden;
}

.rail-inner { padding: 0 0 40px; }

/* ------------------------------ stage ----------------------------------- */

.stage {
    grid-area: stage;
    min-width: 0;
    position: relative;
    background: var(--viewport);
    overflow: hidden;
}

#viewport {
    position: absolute;
    inset: 0;
}
#viewport canvas { display: block; }

/* ------------------------------ status bar ------------------------------ */

.statusbar {
    grid-area: status;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 12px;
    background: var(--bg-panel);
    border-top: 1px solid var(--line);
    font-size: 11px;
    color: var(--fg-2);
}
.statusbar::-webkit-scrollbar { height: 0; }

.stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 0 12px;
    border-right: 1px solid var(--line-soft);
    white-space: nowrap;
}
.stat:first-child { padding-left: 0; }

.stat-k {
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--fg-3);
}
.stat-v {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--fg);
    font-variant-numeric: tabular-nums;
}

.status-flags {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 12px;
}

.flag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 19px;
    padding: 0 8px;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.flag::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}
.flag.is-ok   { color: var(--ok);   background: color-mix(in srgb, var(--ok) 13%, transparent); }
.flag.is-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.flag.is-err  { color: var(--err);  background: color-mix(in srgb, var(--err) 15%, transparent); }

/* =========================================================================
   Controls
   ========================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 30px;
    padding: 0 11px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    color: var(--fg);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { background: var(--bg-active); }
.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
.btn svg { width: 14px; height: 14px; flex: 0 0 auto; }

.btn.is-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}
.btn.is-primary:hover { background: var(--accent-soft); border-color: var(--accent-soft); }

.btn.is-quiet {
    background: transparent;
    border-color: transparent;
    color: var(--fg-2);
}
.btn.is-quiet:hover { background: var(--bg-hover); color: var(--fg); }

.btn.is-icon {
    width: 30px;
    padding: 0;
}

.btn.is-danger:hover { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); }

.btn.is-block { width: 100%; }

:where(button, input, select, a, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* --- segmented control --- */

.seg {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 2px;
    gap: 2px;
}
.seg button {
    height: 24px;
    padding: 0 6px;
    background: transparent;
    border: 0;
    border-radius: 3px;
    color: var(--fg-2);
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
    transition: background 0.1s, color 0.1s;
}
.seg button svg { width: 13px; height: 13px; }
.seg button:hover { color: var(--fg); background: var(--bg-hover); }
.seg button[aria-pressed="true"] {
    background: var(--bg-active);
    color: var(--fg);
    box-shadow: inset 0 0 0 1px var(--line-hard);
}
.seg.is-accent button[aria-pressed="true"] {
    background: var(--accent-wash);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* --- fields --- */

.field-label {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--fg-3);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
    gap: 6px;
    margin-bottom: 13px;
}
.field-row:last-child { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 13px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 13px; }
.grid-2:last-child, .grid-3:last-child { margin-bottom: 0; }

/* Columns are stretched to equal height, so a per-row margin here would show up
   as a vertical offset between the two columns rather than as spacing. */
.grid-2 > .field-row,
.grid-3 > .field-row { margin-bottom: 0; }

.num {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    height: 30px;
    overflow: hidden;
    transition: border-color 0.12s;
}
.num:focus-within { border-color: var(--accent); }
.num input {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    padding: 0 4px 0 9px;
    background: none;
    border: 0;
    outline: none;
    font-family: var(--font-mono);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}
.num input::-webkit-outer-spin-button,
.num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num input[type="number"] { -moz-appearance: textfield; }
.num .unit {
    padding-right: 9px;
    font-size: 10.5px;
    color: var(--fg-3);
    font-family: var(--font-mono);
    pointer-events: none;
    user-select: none;
}

.text-input {
    width: 100%;
    height: 30px;
    padding: 0 9px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    outline: none;
    font-size: 13px;
    transition: border-color 0.12s;
}
.text-input:focus { border-color: var(--accent); }
.text-input::placeholder { color: var(--fg-3); }

select.select {
    width: 100%;
    height: 30px;
    padding: 0 26px 0 9px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    outline: none;
    font-size: 12.5px;
    cursor: pointer;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 14px) 13px, calc(100% - 10px) 13px;
    background-size: 4px 4px, 4px 4px;
    background-repeat: no-repeat;
    transition: border-color 0.12s;
}
select.select:focus { border-color: var(--accent); }
select.select option { background: var(--bg-panel); color: var(--fg); }

/* --- slider + number pair --- */

.slider {
    display: grid;
    grid-template-columns: 1fr 76px;
    align-items: center;
    gap: 10px;
}
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 18px;
    background: none;
    outline: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: 2px;
    background: var(--line-hard);
}
input[type="range"]::-moz-range-track {
    height: 3px;
    border-radius: 2px;
    background: var(--line-hard);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    margin-top: -5px;
    border-radius: 50%;
    background: var(--fg);
    border: 0;
    box-shadow: 0 0 0 1px var(--bg-panel);
    transition: background 0.12s;
}
input[type="range"]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--fg);
    border: 0;
}
input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }
input[type="range"]:hover::-moz-range-thumb { background: var(--accent); }

/* --- switch --- */

.switch {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    user-select: none;
    font-size: 12.5px;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
    position: relative;
    width: 30px;
    height: 17px;
    flex: 0 0 auto;
    border-radius: 9px;
    background: var(--bg-sunken);
    box-shadow: inset 0 0 0 1px var(--line-hard);
    transition: background 0.15s, box-shadow 0.15s;
}
.switch .track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--fg-3);
    transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track {
    background: var(--accent-wash);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent);
}
.switch input:checked + .track::after {
    transform: translateX(13px);
    background: var(--accent);
}
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- colour picker --- */

.color {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 30px;
    padding: 0 8px 0 4px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    cursor: pointer;
    transition: border-color 0.12s;
}
.color:hover { border-color: var(--fg-3); }
.color input[type="color"] {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: var(--r-sm);
    background: none;
    cursor: pointer;
    overflow: hidden;
}
.color input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(128, 128, 128, 0.45);
    border-radius: var(--r-sm);
}
.color input[type="color"]::-moz-color-swatch {
    border: 1px solid rgba(128, 128, 128, 0.45);
    border-radius: var(--r-sm);
}
.color .hex {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--fg-2);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
}
.swatches button {
    width: 19px;
    height: 19px;
    padding: 0;
    border-radius: var(--r-sm);
    border: 1px solid rgba(128, 128, 128, 0.35);
    cursor: pointer;
    transition: transform 0.1s;
}
.swatches button:hover { transform: scale(1.15); }

.hint {
    font-size: 11px;
    line-height: 1.5;
    color: var(--fg-3);
}

/* =========================================================================
   Rail sections
   ========================================================================= */

.section { border-bottom: 1px solid var(--line); }

.section-head {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    height: 40px;
    padding: 0 14px;
    background: none;
    border: 0;
    cursor: pointer;
    text-align: left;
    color: var(--fg);
}
.section-head:hover { background: var(--bg-hover); }
.section-head .chev {
    width: 11px;
    height: 11px;
    flex: 0 0 auto;
    color: var(--fg-3);
    transition: transform 0.16s ease;
}
.section[data-open="true"] .section-head .chev { transform: rotate(90deg); }
.section-head .title {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    flex: 1 1 auto;
}
.section-head .badge {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--fg-3);
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1px 6px;
}

.section-body { padding: 2px 14px 16px; }
.section[data-open="false"] .section-body { display: none; }

.subhead {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 0 10px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--fg-3);
}
.subhead::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--line);
}

/* =========================================================================
   Viewport overlays
   ========================================================================= */

.vp-overlay {
    position: absolute;
    z-index: 3;
    display: flex;
    gap: 5px;
    pointer-events: none;
}
.vp-overlay > * { pointer-events: auto; }

.vp-tl { top: 12px; left: 12px; }
.vp-tr { top: 12px; right: 12px; }
.vp-bl { bottom: 12px; left: 12px; flex-direction: column; align-items: flex-start; }
.vp-br { bottom: 12px; right: 12px; flex-direction: column; }

.vp-cluster {
    display: flex;
    gap: 1px;
    background: color-mix(in srgb, var(--bg-panel) 88%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 3px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
}
.vp-cluster.is-col { flex-direction: column; }

.vp-btn {
    height: 26px;
    min-width: 26px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: none;
    border: 0;
    border-radius: 3px;
    color: var(--fg-2);
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.vp-btn:hover { background: var(--bg-hover); color: var(--fg); }
.vp-btn[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); }
.vp-btn svg { width: 14px; height: 14px; }

.vp-readout {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--fg-3);
    background: color-mix(in srgb, var(--bg-panel) 80%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 4px 8px;
    letter-spacing: 0.02em;
}

.vp-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    text-align: center;
    color: var(--fg-3);
    pointer-events: none;
    z-index: 2;
}
.vp-empty svg { width: 34px; height: 34px; opacity: 0.5; }
.vp-empty p { margin: 0; font-size: 12.5px; }
.vp-empty small { font-size: 11px; opacity: 0.75; }
.vp-empty.is-hidden { display: none; }

.vp-busy {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 11px;
    font-size: 11.5px;
    color: var(--fg-2);
    background: color-mix(in srgb, var(--bg-panel) 92%, transparent);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transition: opacity 0.18s;
    pointer-events: none;
}
.vp-busy.is-on { opacity: 1; }
.vp-busy::before {
    content: "";
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--line-hard);
    border-top-color: var(--accent);
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   Popovers / dialogs
   ========================================================================= */

.pop {
    position: fixed;
    z-index: 60;
    width: 290px;
    padding: 14px;
    background: var(--bg-panel);
    border: 1px solid var(--line-hard);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-pop);
}
.pop[hidden] { display: none; }
.pop-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--fg-3);
    margin: 0 0 12px;
}
.pop-actions {
    display: flex;
    gap: 7px;
    margin-top: 15px;
}
.pop-actions .btn { flex: 1 1 auto; }

.scrim {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.4);
}
.scrim[hidden] { display: none; }

.menu {
    position: fixed;
    z-index: 60;
    min-width: 200px;
    padding: 5px;
    background: var(--bg-panel);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    box-shadow: var(--shadow-pop);
}
.menu[hidden] { display: none; }
.menu button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    height: 28px;
    padding: 0 9px;
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--fg);
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
}
.menu button:hover { background: var(--bg-hover); }
.menu button svg { width: 14px; height: 14px; color: var(--fg-3); flex: 0 0 auto; }
.menu button .sub { margin-left: auto; font-size: 10.5px; color: var(--fg-3); font-family: var(--font-mono); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }

/* --- toast --- */

.toasts {
    position: fixed;
    bottom: calc(var(--status-h) + 14px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: center;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--line-hard);
    border-radius: 20px;
    box-shadow: var(--shadow-pop);
    font-size: 12.5px;
    animation: toast-in 0.2s ease;
}
.toast.is-err { border-color: color-mix(in srgb, var(--err) 55%, transparent); color: var(--err); }
.toast.is-ok::before {
    content: "";
    width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* --- language switch --- */

.lang {
    display: flex;
    gap: 1px;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 2px;
}
.lang button {
    height: 22px;
    padding: 0 8px;
    background: none;
    border: 0;
    border-radius: 3px;
    color: var(--fg-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    cursor: pointer;
}
.lang button:hover { color: var(--fg); }
.lang button[aria-pressed="true"] { background: var(--bg-active); color: var(--fg); }

/* =========================================================================
   Warnings list
   ========================================================================= */

.warnings { display: flex; flex-direction: column; gap: 7px; }
.warn-item {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--r);
    font-size: 11.5px;
    line-height: 1.45;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
}
.warn-item svg { width: 14px; height: 14px; flex: 0 0 auto; margin-top: 1px; }
.warn-item.is-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.warn-item.is-err  { color: var(--err);  border-color: color-mix(in srgb, var(--err) 32%, transparent); }
.warn-item.is-ok   { color: var(--fg-2); }

/* =========================================================================
   Responsive
   ========================================================================= */

.mobile-tabs { display: none; }

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "stage"
            "status";
    }
    .rail {
        position: fixed;
        inset: var(--topbar-h) 0 var(--status-h) 0;
        z-index: 40;
        border-right: 0;
        border-top: 1px solid var(--line);
    }
    body[data-panel="view"] .rail { display: none; }
    .mobile-tabs { display: flex; }
    .brand-name span { display: none; }
    .topbar { gap: 6px; padding: 0 8px; }
}

@media (max-width: 620px) {
    .brand { padding-right: 8px; }
    .brand-name b { display: none; }
    .hide-sm { display: none !important; }
}

@media (max-width: 560px) {
    #btnExport span { display: none; }
    #btnExport { width: 32px; padding: 0; }
    .stat { padding: 0 9px; }
    .vp-overlay { gap: 4px; }
}

.is-hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --- floating dimension tags over the viewport --- */

.dim-label {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    padding: 2px 6px;
    border-radius: 3px;
    background: color-mix(in srgb, var(--bg-panel) 85%, transparent);
    border: 1px solid var(--line);
    color: var(--fg-2);
    font-family: var(--font-mono);
    font-size: 10px;
    line-height: 1.35;
    letter-spacing: 0.02em;
    white-space: nowrap;
    pointer-events: none;
    transition: opacity 0.15s;
}


/* =========================================================================
   STL Map additions
   ========================================================================= */

/* `hidden` must win over the display rules above (.grid-2, .field-row, …). */
[hidden] { display: none !important; }

/* The map overlays use z-indexes above Leaflet's panes; the stage keeps them
   inside its own stacking context, under the rail, menus, scrim and toasts. */
.stage { isolation: isolate; }

/* --- stage: the map and the model share the stage, one at a time --- */

.pane { position: absolute; inset: 0; }
body[data-stage="map"] .pane-model,
body[data-stage="model"] .pane-map { visibility: hidden; }

#map { position: absolute; inset: 0; z-index: 0; background: var(--bg-sunken); }
#frame {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 500;
    border: 2px solid var(--accent);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.map-search {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 600;
    display: flex;
    gap: 6px;
    width: min(380px, calc(100% - 24px - 46px));   /* leave the zoom buttons (top right) free */
}
.map-search .text-input { box-shadow: var(--shadow-pop); }
.search-results {
    position: absolute;
    top: 36px;
    left: 0;
    right: 38px;
    max-height: 50vh;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: var(--bg-panel);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    box-shadow: var(--shadow-pop);
}
.search-results[hidden] { display: none; }
.search-results li { margin: 0; }
.search-results button {
    width: 100%;
    padding: 6px 8px;
    text-align: left;
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    cursor: pointer;
}
.search-results button:hover,
.search-results button:focus-visible { background: var(--bg-hover); outline: none; }
.search-results .is-note { padding: 6px 8px; color: var(--fg-2); }

.map-actions {
    position: absolute;
    left: 50%;
    bottom: 64px;   /* clear of the toasts, which sit at the stage's bottom edge */
    transform: translateX(-50%);
    z-index: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}
.map-scale {
    padding: 4px 9px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--fg-2);
    background: color-mix(in srgb, var(--bg-panel) 90%, transparent);
    border: 1px solid var(--line);
    border-radius: 20px;
}
.map-scale:empty { display: none; }

/* --- progress: one band over the stage, for data loading and building --- */

.progress {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px 4px 11px;
    font-size: 11.5px;
    color: var(--fg-2);
    background: color-mix(in srgb, var(--bg-panel) 94%, transparent);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.progress[hidden] { display: none; }
.progress::before {
    content: "";
    width: 11px;
    height: 11px;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 2px solid var(--line-hard);
    border-top-color: var(--accent);
    animation: spin 0.7s linear infinite;
}
.progress .btn { height: 24px; padding: 0 9px; }
.progress .btn[hidden] { display: none; }
body[data-stage="map"] .progress { top: 58px; }

/* --- rail content --- */

.area-info { margin: 6px 0; color: var(--fg-2); font-size: 12px; white-space: pre-line; }
.area-info:empty { display: none; }

.class-head,
.class-row {
    display: grid;
    grid-template-columns: 1fr 74px 74px 34px;
    gap: 6px;
    align-items: center;
}
.class-head { margin-bottom: 4px; font-size: 10.5px; color: var(--fg-3); text-transform: uppercase; letter-spacing: 0.06em; }
.class-list { display: flex; flex-direction: column; gap: 5px; }
.class-row .switch { min-width: 0; }
.class-row .switch span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.class-row .num input { width: 100%; }
.class-row .color { padding: 0; justify-content: center; }
.class-row .color .hex { display: none; }

.inlay-classes { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 10px; }
.inlay-classes label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }

.change-list { margin: 0; padding: 0; list-style: none; font-family: var(--font-mono); font-size: 11.5px; }
.change-list li { display: flex; align-items: center; gap: 7px; padding: 2px 0; }
.swatch { display: inline-block; width: 12px; height: 12px; border: 1px solid var(--line-hard); border-radius: 2px; }

textarea.text-input { height: auto; padding: 6px 9px; resize: vertical; line-height: 1.4; }
.field-row .btn.is-block { margin-top: 6px; }

/* A value the schema refuses: marked, never silently clamped while typing. */
.num input.is-invalid,
.text-input.is-invalid { color: var(--err); }
.num:has(input.is-invalid) { border-color: var(--err); }

.legal { margin: 14px 16px 0; font-size: 11px; color: var(--fg-3); }
.legal a { color: var(--fg-2); }

/* --- info.html: a plain reading page on the same tokens --- */

body.doc { overflow: auto; height: auto; max-width: 780px; margin: 0 auto; padding: 24px 16px; font-size: 14px; }
body.doc a { color: var(--accent); }
body.doc pre { white-space: pre-wrap; background: var(--bg-sunken); border: 1px solid var(--line); padding: 10px; overflow-x: auto; }

/* --- marked buildings --- */

#btnPick[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); border-color: var(--accent); }
.mark-list { margin: 8px 0; padding: 0; list-style: none; font-size: 12px; }
.mark-list:empty { display: none; }
.mark-list li { display: flex; align-items: center; gap: 7px; padding: 2px 0; min-height: 26px; }
.mark-list .mark-no { font-family: var(--font-mono); font-size: 11px; color: var(--fg-2); min-width: 1.6em; }
.mark-list .mark-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mark-list li.is-off .mark-name { color: var(--fg-2); text-decoration: line-through; }
.mark-list .mark-note { font-size: 11px; color: var(--fg-2); white-space: nowrap; }
.mark-list .btn { height: 24px; width: 24px; padding: 0; flex: 0 0 auto; }
.mark-list .btn svg { width: 13px; height: 13px; }

.pick-banner {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 700;
    display: flex;
    align-items: center;
    gap: 9px;
    max-width: calc(100% - 32px);
    padding: 5px 6px 5px 12px;
    font-size: 12px;
    color: var(--fg);
    background: color-mix(in srgb, var(--bg-panel) 94%, transparent);
    border: 1px solid var(--accent);
    border-radius: 20px;
    box-shadow: var(--shadow-pop);
}
.pick-banner svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--accent); }
.pick-banner .btn { height: 26px; padding: 0 11px; flex: 0 0 auto; }
#map.is-picking, #map.is-picking .leaflet-interactive { cursor: crosshair; }
