/* xfea web viewer — stylesheet.
 *
 * The look is the website's (xfea.ai, src/styles/global.css): a near-black
 * ground, thin lines, one mint accent, Geist for text and Geist Mono for
 * labels, numbers and controls. Its colours are the tokens below; keep
 * them in step with the site's.
 *
 * Two-tier theme system:
 *   1. The user picks a background colour in the Settings popover.
 *   2. ``ui.js::applyBackgroundColor`` measures its luminance and flips
 *      ``<html data-theme="light|dark">``; every token below re-resolves
 *      against the matching block so text, panel backgrounds and icon
 *      tints all flip together. No component reads ``--bg`` directly
 *      for its own fill — they all go through the glass tokens so the
 *      UI reads correctly on any scene colour.
 */

:root {
    /* Scene colours — only --bg + --panel-bg + --accent are user-tweakable
     * (their defaults are GROUND and ACCENT in js/config.js too).
     * Everything else in the UI composes from the tokens below. */
    --bg:             #0a0c0f;   /* the site's ground */
    --panel-bg:       #0e1116;   /* the site's surface */
    --accent:         #4fe0b5;

    --font-sans:      "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono:      "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    /* The site's corners: 3px on controls, 4px on panels and cards. */
    --radius-ctl:     3px;
    --radius:         4px;

    /* Sidebar geometry. Width is a variable so the collapse animation
     * can interpolate it without hard-coding pixel values elsewhere. */
    --sidebar-w:      260px;
    --sidebar-gap:    8px;
}

/* --- Dark mode tokens (default) -------------------------------------- */
html[data-theme="dark"] {
    --fg:              #e6e8eb;   /* ink */
    --muted:           #9aa3ad;
    --faint:           #6f7883;
    /* Panels are the site's surface, a little see-through over the scene. */
    --glass-bg:        color-mix(in srgb, var(--panel-bg) 90%, transparent);
    --glass-bg-strong: color-mix(in srgb, var(--panel-bg) 96%, transparent);
    --glass-bd:        #1f242c;   /* line */
    --glass-bd-hover:  #2a313b;   /* line-strong */
    --hover-bg:        rgba(255, 255, 255, 0.04);
    --active-bg:       rgba(255, 255, 255, 0.07);
    --input-bg:        var(--bg);
    --input-bd:        #2a313b;
    --shadow:          0 12px 32px rgba(0, 0, 0, 0.5);
    --accent-soft:     color-mix(in srgb, var(--accent) 14%, transparent);
    --ok:              #3dd68c;   /* good */
}

/* --- Light mode tokens ---------------------------------------------- */
html[data-theme="light"] {
    --fg:              #14171c;
    --muted:           #4f5864;
    --faint:           #6f7883;
    --glass-bg:        rgba(255, 255, 255, 0.86);
    --glass-bg-strong: rgba(255, 255, 255, 0.95);
    --glass-bd:        rgba(0, 0, 0, 0.10);
    --glass-bd-hover:  rgba(0, 0, 0, 0.20);
    --hover-bg:        rgba(0, 0, 0, 0.05);
    --active-bg:       rgba(0, 0, 0, 0.08);
    --input-bg:        rgba(255, 255, 255, 0.9);
    --input-bd:        rgba(0, 0, 0, 0.16);
    --shadow:          0 10px 28px rgba(20, 30, 50, 0.14);
    --accent-soft:     color-mix(in srgb, var(--accent) 18%, transparent);
    --ok:              #1f9d61;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-sans);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
}

/* The site's focus ring. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

canvas { display: block; }

/* --- Multi-viewport layout ------------------------------------------ */

/*
 * The single WebGLRenderer canvas is fixed to the full window and sits
 * behind the DOM chrome. A grid of transparent ``.viewport`` cells
 * above it catches pointer events for each viewport's OrbitControls
 * and provides the bounding rect used to set the scissor/viewport for
 * that cell's render pass.
 */
#renderer-canvas {
    position: fixed !important;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 0;
}

#viewports {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    padding: 6px;
    z-index: 1;
    pointer-events: none;   /* cells re-enable per element */
}

/* layout.js renders split-tree nodes as nested flex containers. The
 * root .split fills #viewports and every .split-child is a flex item
 * that either holds another .split or a .viewport leaf. Classes use a
 * ``split-`` prefix to avoid colliding with the global ``.row``
 * form-row helper. */
#viewports > .split {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: stretch;
    position: relative;
}
.split.split-row { flex-direction: row; }
.split.split-col { flex-direction: column; }

.split-child {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-self: stretch;
    position: relative;
}

/* Draggable gutter between two .split-child boxes inside the same
 * parent .split. Kept thin but with a generous hover hit-box so it's
 * easy to grab. */
.gutter {
    position: relative;
    background: transparent;
    pointer-events: auto;
    flex: 0 0 6px;
    align-self: stretch;
    transition: background 0.15s ease;
}
.gutter-row { cursor: col-resize; }
.gutter-col { cursor: row-resize; }
.gutter:hover,
.gutter:active {
    background: var(--accent-soft);
}

.viewport {
    position: relative;
    pointer-events: auto;
    overflow: hidden;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: border-color 0.15s ease;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
}

/* Outlines only mean something with more than one viewport (the
 * gutters between them exist only then): which one the panels edit. */
#viewports:has(.gutter) .viewport:hover {
    border-color: var(--glass-bd-hover);
}

#viewports:has(.gutter) .viewport.active {
    border-color: var(--accent);
}

/* --- Sidebar shell --------------------------------------------------- */

#sidebar {
    position: absolute;
    top: 12px;
    left: 12px;
    bottom: 12px;
    width: min(var(--sidebar-w), calc(100vw - 24px));  /* never wider than a phone's screen */
    z-index: 10;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-bd);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: width 0.18s ease, opacity 0.18s ease;
}
#sidebar.collapsed {
    width: 0;
    opacity: 0;
    pointer-events: none;
}
/* On a phone the open sidebar covers the screen: above the toolbar (z-index 20), the field bar and the
   min/max markers (40), so its own close button stays within reach; below the popovers (50 and up). */
@media (max-width: 640px) {
    #sidebar { z-index: 45; }
}

#sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: -4px;
    bottom: 0;
    width: 8px;
    cursor: col-resize;
    z-index: 11;
}
#sidebar-resize-handle:hover,
#sidebar-resize-handle.dragging {
    background: var(--accent);
    opacity: 0.3;
    border-radius: 4px;
}

/* Floating tab to reopen the sidebar once it has been collapsed. It's
   hidden by default and only revealed when #sidebar carries .collapsed
   (see the adjacent-sibling rule below). */
#sidebar-reopen {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 20;
    display: none;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-ctl);
    border: 1px solid var(--input-bd);
    background: var(--panel-bg);
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow);
}
#sidebar-reopen:hover { background: var(--hover-bg); }
#sidebar-reopen.visible { display: block; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 0 10px 0 16px;
    border-bottom: 1px solid var(--glass-bd);
}

/* The site's mark and wordmark (its Logo component), then what this is. */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    color: var(--fg);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1;
}
.brand .mark {
    height: 1em;
    width: auto;
}
.brand-app {
    margin-left: 0.3em;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--faint);
}
#sidebar-collapse,
#btn-help {
    background: transparent;
    border: none;
    color: var(--faint);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1;
    padding: 4px 8px;
    border-radius: var(--radius-ctl);
}
#sidebar-collapse:hover,
#btn-help:hover { color: var(--fg); background: var(--hover-bg); }

.header-btns { display: flex; gap: 2px; }

#panels {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 10px;
}
#panels::-webkit-scrollbar { width: 8px; }
#panels::-webkit-scrollbar-thumb {
    background: var(--glass-bd);
    border-radius: 4px;
}

/* --- Collapsible panel groups ---------------------------------------- */

.panel {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--glass-bd);
    margin-bottom: 4px;
    padding-bottom: 4px;
}
.panel:last-child {
    border-bottom: none;
}
.panel[hidden] { display: none; }
/* Section headings are the site's labels: lower-case mono, a little
 * spaced, behind its "›" prompt, which turns down and takes the accent
 * when the section is open. */
.panel > summary {
    list-style: none;
    cursor: pointer;
    padding: 9px 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--muted);
    user-select: none;
    display: flex;
    align-items: center;
    transition: color 0.12s ease;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before {
    content: '›';
    display: inline-block;
    width: 10px;
    margin-right: 8px;
    color: var(--faint);
    text-align: center;
    transition: transform 0.12s ease, color 0.12s ease;
}
.panel[open] > summary::before { transform: rotate(90deg); color: var(--accent); }
.panel > summary:hover { color: var(--fg); }

.panel-body {
    padding: 4px 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
/* display: flex above beats the hidden attribute: the Problem and Step rows,
   hidden when there is only one of each, showed up empty. */
.row[hidden] { display: none; }
.panel-body label,
.popover-body label {
    font-size: 12px;
    color: var(--muted);
    min-width: 64px;
}
.panel-body label:has(input[type="checkbox"]),
.popover-body label:has(input[type="checkbox"]) {
    min-width: 0;
    color: var(--fg);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

/* --- Subpanel inside Results (Deform / Stress) ----------------------- */

.subpanel {
    border-top: 1px solid var(--glass-bd);
    padding-top: 10px;
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.subpanel[hidden] { display: none; }
.subpanel-head {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--faint);
    padding: 0 6px;
}

/* Collapsible sub-panels inside Results (Contour, Vectors, Deformation). */
.subdetails {
    border-top: 1px solid var(--glass-bd);
    padding-top: 6px;
    margin-top: 4px;
}
.subdetails[hidden] { display: none; }
.subdetails > summary {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--faint);
    cursor: pointer;
    padding: 4px 6px;
    user-select: none;
    list-style: none;
}
.subdetails > summary:hover { color: var(--fg); }
.subdetails > summary::before {
    content: '›';
    display: inline-block;
    width: 10px;
    margin-right: 6px;
    text-align: center;
    transition: transform 0.12s ease, color 0.12s ease;
}
.subdetails[open] > summary::before {
    transform: rotate(90deg);
    color: var(--accent);
}
.subdetails > summary::-webkit-details-marker { display: none; }
.subdetails > .row,
.subdetails > div > .row {
    /* Inherits .panel-body .row styles via cascade */
}

/* --- Model tree ------------------------------------------------------ */

#model-tree {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.tree-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: var(--radius-ctl);
    cursor: pointer;
    font-size: 12px;
    color: var(--fg);
    transition: background 0.1s ease;
    user-select: none;
}
.tree-row:hover { background: var(--hover-bg); }
.tree-row.selected {
    background: var(--accent-soft);
    color: var(--accent);
}
.tree-row input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}
.tree-row .tree-icon {
    width: 14px;
    height: 14px;
    color: var(--muted);
    flex-shrink: 0;
}
.tree-row .tree-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: 12px;
}

/* Part rows: an eye to show or hide, the element count on the right.
 * A hidden part's row fades; the part shown alone keeps the accent. */
.tree-eye {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-ctl);
    color: var(--muted);
    cursor: pointer;
}
.tree-eye svg { width: 15px; height: 15px; }
.tree-eye:hover { color: var(--fg); background: var(--hover-bg); }
.tree-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--faint);
}
.tree-row.is-hidden .tree-name,
.tree-row.is-hidden .tree-icon { opacity: 0.4; }
.tree-row.is-hidden .tree-eye { color: var(--faint); }
.tree-row.is-alone .tree-eye { color: var(--accent); }
.tree-row[hidden], .tree-group[hidden] { display: none; }

/* --- Tree groups ------------------------------------------------------ */

.tree-group {
    margin-bottom: 2px;
}
.tree-group-header {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--faint);
    text-transform: lowercase;
    letter-spacing: 0.06em;
    padding: 4px 6px;
    cursor: pointer;
    user-select: none;
    list-style: none;
}
.tree-group-header:hover { color: var(--fg); }
.tree-group-header::-webkit-details-marker { display: none; }
.tree-group-header::before {
    content: '›';
    display: inline-block;
    width: 10px;
    margin-right: 6px;
    text-align: center;
    transition: transform 0.12s ease, color 0.12s ease;
}
.tree-group[open] > .tree-group-header::before {
    transform: rotate(90deg);
    color: var(--accent);
}
.tree-info-row {
    cursor: default;
    padding-left: 16px;
}
.tree-info-row:hover { background: none; }
.tree-subtext {
    font-size: 10px;
    margin-top: 1px;
    padding-left: 6px;
    white-space: normal;
    word-break: break-word;
}

/* --- Form controls (shared sidebar + popover) ------------------------ */

input[type="color"] {
    width: 32px;
    height: 22px;
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    background: var(--input-bg);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.panel-body input[type="range"],
.popover-body input[type="range"] {
    flex: 1;
    min-width: 100px;
    accent-color: var(--accent);
}
.panel-body input[type="text"].num-input,
.panel-body input.num-input,
.popover-body input[type="text"].num-input,
.popover-body input.num-input {
    width: 70px;
    height: 26px;
    background: var(--input-bg);
    color: var(--fg);
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    padding: 0 7px;
    font-size: 12px;
    font-family: var(--font-mono);
}
.panel-body select,
.popover-body select {
    flex: 1;
    min-width: 0;
    height: 26px;
    background: var(--input-bg);
    color: var(--fg);
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    padding: 0 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
}
/* Buttons are the site's controls: a thin outline, mono type. */
.panel-body button,
.popover-body button {
    min-height: 28px;
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    padding: 0 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.panel-body button:hover,
.popover-body button:hover {
    background: var(--hover-bg);
    border-color: var(--glass-bd-hover);
}
.panel-body button.active,
.popover-body button.active {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
}

.axis-btn { padding: 0 10px !important; }

.num-readout {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
    min-width: 48px;
}

.panel-body .muted,
.popover-body .muted {
    font-size: 11px;
    color: var(--faint);
    line-height: 1.45;
}

/* Stress rows — checkbox label + inline color swatch. */
.stress-row {
    justify-content: space-between;
}
.stress-row label { flex: 1; }
.stress-vec-color {
    width: 28px;
    height: 18px;
}

/* --- Top-right icon bar (frame-less) --------------------------------- */

#topbar {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 20;
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-bd);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.topbar-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-ctl);
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    transition: color 0.12s ease, background 0.12s ease;
}
.topbar-btn svg {
    width: 17px;
    height: 17px;
    display: block;
}
.topbar-btn:hover {
    color: var(--fg);
    background: var(--hover-bg);
}
.topbar-btn.active {
    color: var(--accent);
    background: var(--accent-soft);
}

/* --- Popovers -------------------------------------------------------- */

.popover {
    position: absolute;
    top: 64px;
    right: 16px;
    z-index: 19;
    width: 280px;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-bd);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: var(--shadow);
    display: none;
    flex-direction: column;
    gap: 4px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.popover.open {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}
.popover h3 {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--faint);
    margin: 10px 0 6px 2px;
}
.popover h3:first-child { margin-top: 2px; }
.popover-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

/* Tiny uppercase header used inside the viewports popover to mark
 * "Split active" / "Layout presets" sections. */
.popover-section-title {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--faint);
    margin: 2px 0 -2px 2px;
}

/* Two buttons side by side for split right / split down. */
.row-split {
    display: flex;
    gap: 6px;
}
.row-split button {
    flex: 1 1 0;
}

/* 4-column grid of compact layout-preset buttons. */
.preset-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}
.preset-grid button {
    padding: 6px 0 !important;
    font-size: 11px !important;
    text-align: center;
}

/* --- Colorbar / legend (per-viewport) -------------------------------- */

/* Each viewport cell owns one ``.colorbar`` — built by scene.js on
 * hydration, positioned on the right edge of the cell, and repainted
 * by appearance.drawColorbar when the *active* viewport's field or
 * colormap changes. Other viewports keep whichever legend state their
 * last active moment produced. */
.colorbar {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 300px;
    z-index: 10;
    cursor: pointer;  /* opens the colour settings (menus.js) */
}
/* On a phone a shorter scale, clear of the view cube above and the field bar below. */
@media (max-width: 640px) {
    .colorbar {
        right: 12px;
        width: 18px;
        height: 200px;
    }
}
.colorbar:hover .cb-canvas,
.colorbar:hover .cb-label { border-color: var(--accent); }
.colorbar .cb-canvas {
    width: 100%;   /* the .colorbar box's size, which the ticks are laid out on */
    height: 100%;
    border: 1px solid var(--glass-bd);
    border-radius: 3px;
    display: block;
}

/* Out-of-range color bands — flush with the main gradient. */
.cb-swatch {
    position: absolute;
    left: 0;
    width: 100%;
    height: 10px;
    border: 1px solid var(--glass-bd);
    box-sizing: border-box;
    display: none;
}
.colorbar .cb-over-swatch  { bottom: 100%; border-radius: 3px 3px 0 0; border-bottom: none; }
.colorbar .cb-under-swatch { top: 100%;    border-radius: 0 0 3px 3px; border-top: none; }
.colorbar.has-over  .cb-max { top: -14px; }
.colorbar.has-under .cb-min { bottom: -14px; }
.colorbar .cb-max,
.colorbar .cb-min {
    position: absolute;
    right: 32px;
    color: var(--fg);
    font-size: 11px;
    font-family: var(--font-mono);
    white-space: nowrap;
}
.colorbar .cb-max { top: 0; }
.colorbar .cb-min { bottom: 0; }

/* Legend title. Anchored to the RIGHT edge of the viewport rather than
 * centred on the bar, so long labels (e.g. "Stress (Pa) — vonMises")
 * grow leftward instead of overflowing past the right edge and getting
 * clipped. Uses has-over offset to sit above the upper swatch when the
 * over-colour band is present. */
.colorbar .cb-label {
    position: absolute;
    right: 0;
    bottom: 100%;
    margin-bottom: 8px;
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
    text-align: right;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    background: var(--glass-bg-strong);
    padding: 4px 8px;
    border-radius: var(--radius-ctl);
    border: 1px solid var(--glass-bd);
}
.colorbar.has-over .cb-label { bottom: calc(100% + 14px); }

/* --- Loading / error overlay ----------------------------------------- */

#loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    /* The site's backdrop: a faint blue glow on the ground. */
    background: radial-gradient(ellipse at 55% 45%, #16202c 0%, #0e1218 40%, var(--bg) 75%);
    z-index: 1000;
}
#loading .brand { font-size: 26px; }
#loading p {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.06em;
    color: var(--faint);
    animation: loading-pulse 1.4s ease-in-out infinite;
}
#loading.is-error p {
    max-width: 60ch;
    color: #ff6b6b;
    text-align: center;
    animation: none;
}
@keyframes loading-pulse { 50% { opacity: 0.45; } }
.spinner {
    width: 36px;
    height: 36px;
    margin-bottom: 1rem;
    border: 3px solid var(--glass-bd-hover);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- In-viewer step-loading toast ------------------------------------ */

/* Appears at the top of the viewport while the next step's JSON is
   being fetched from the server. Translucent so the user can still see
   the current render underneath; pointer-events: none so orbit/zoom
   aren't interrupted. */
#step-loading {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-bd);
    border-radius: 999px;
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    pointer-events: none;
    z-index: 500;
    animation: step-loading-in 0.18s ease-out;
}
#step-loading[hidden] { display: none; }
.spinner-sm {
    width: 14px;
    height: 14px;
    margin: 0;
    border-width: 2px;
}
@keyframes step-loading-in {
    from { opacity: 0; transform: translate(-50%, -6px); }
    to   { opacity: 1; transform: translate(-50%,  0);    }
}

/* --- Bottom-left info bar -------------------------------------------- */

#info {
    position: absolute;
    top: 16px;
    left: calc(var(--sidebar-w) + 28px);
    color: var(--faint);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    z-index: 10;
    transition: left 0.18s ease;
}
#sidebar.collapsed ~ #info { left: 48px; }  /* clear of the #sidebar-reopen button */

/* --- Section slots --------------------------------------------------- */

.section-slots { display: flex; flex-direction: column; gap: 10px; }
.section-slot {
    background: var(--input-bg);
    border: 1px solid var(--glass-bd);
    border-radius: var(--radius);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.section-slot .slot-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
}
.section-slot .slot-header .slot-title { flex: 1; }

/* --- Colorbar intermediate ticks ------------------------------------- */

.colorbar .cb-ticks {
    position: absolute;
    right: 32px;
    top: 0;
    bottom: 0;
    width: 120px;
    pointer-events: none;
}
.cb-tick {
    position: absolute;
    right: 0;
    color: var(--fg);
    font-size: 10px;
    font-family: var(--font-mono);
    white-space: nowrap;
    transform: translateY(50%);
    opacity: 0.75;
}

/* --- Probe tooltip --------------------------------------------------- */

#probe-tooltip {
    position: fixed;
    z-index: 50;
    background: var(--glass-bg-strong);
    color: var(--fg);
    border: 1px solid var(--glass-bd-hover);
    border-radius: var(--radius);
    padding: 7px 10px;
    font-size: 11px;
    font-family: var(--font-mono);
    line-height: 1.45;
    box-shadow: var(--shadow);
    pointer-events: none;
    max-width: 280px;
}
/* With actions it is the selection card: it takes clicks. */
#probe-tooltip.has-actions { pointer-events: auto; }
#probe-tooltip .card-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--glass-bd);
}
#probe-tooltip .card-actions button {
    height: 24px;
    padding: 0 8px;
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    font: inherit;
    cursor: pointer;
}
#probe-tooltip .card-actions button:hover { border-color: var(--accent); color: var(--accent); }
#probe-tooltip b { color: var(--fg); font-weight: 500; }
#probe-tooltip .probe-field { color: var(--accent); }

/* --- Min / max markers (extremes.js) --------------------------------- */

/* Anchored by the dot: left / top are the node's place on screen. */
.extreme-marker {
    position: fixed;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 6px;
    transform: translate(-5px, -50%);
    pointer-events: none;
    font: 11px/1 var(--font-mono);
    color: var(--fg);
    white-space: nowrap;
}
.extreme-marker i {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--fg);
    box-sizing: border-box;
    flex: none;
}
.extreme-max i { background: #ff5a4f; }
.extreme-min i { background: #4f9dff; }
.extreme-marker span {
    padding: 3px 6px;
    border-radius: var(--radius-ctl);
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-bd);
}

/* --- Help modal ------------------------------------------------------ */

#help-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}
#help-modal .help-card {
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-bd);
    border-radius: var(--radius);
    min-width: 340px;
    max-width: 480px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
#help-modal header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--glass-bd);
}
#help-modal h2 {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--muted);
}
#help-modal .help-close {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 0 4px;
}
#help-modal .help-close:hover { color: var(--fg); }
#help-list {
    padding: 12px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.help-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
}
.help-keys {
    min-width: 120px;
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}
.help-keys kbd {
    background: var(--input-bg);
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    padding: 1px 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--fg);
}
.help-desc { color: var(--muted); flex: 1; }

/* --- VTU list -------------------------------------------------------- */

#vtu-list { display: flex; flex-direction: column; gap: 3px; }
#vtu-list a {
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 11px;
    text-decoration: none;
}
#vtu-list a:hover { text-decoration: underline; }

/* --- Results bar (bottom) -------------------------------------------- */

#resultsbar-wrap {
    position: absolute;
    left: calc(var(--sidebar-w) + 24px);
    right: 16px;
    bottom: 14px;
    z-index: 15;
    display: flex;
    justify-content: center;
    pointer-events: none;
}
#sidebar.collapsed ~ #resultsbar-wrap { left: 12px; }
#resultsbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-bd);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    pointer-events: auto;
    font-family: var(--font-mono);
    font-size: 12px;
}
#resultsbar[hidden], #resultsbar [hidden] { display: none; }
.bar-group { display: inline-flex; align-items: center; gap: 6px; }
.bar-label, .bar-toggle { color: var(--muted); }
.bar-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
#resultsbar select, .bar-btn {
    height: 26px;
    background: var(--input-bg);
    color: var(--fg);
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    padding: 0 8px;
    font: inherit;
    cursor: pointer;
}
.bar-btn.active { border-color: var(--accent); color: var(--accent); }
.popover.from-bar { top: auto; right: auto; bottom: 64px; }
.popover.from-legend { top: 20%; right: 72px; }

/* --- View cube (viewcube.js) ------------------------------------------ */

#viewcube {
    position: absolute;
    top: 68px;
    right: 22px;
    z-index: 18;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
/* On a phone (the width js/sidebar.js calls narrow) the cube shrinks into the corner, leaving the model room. */
@media (max-width: 640px) {
    #viewcube {
        top: 58px;
        right: 12px;
        transform: scale(0.7);
        transform-origin: top right;
    }
}
#viewcube .cube {
    position: relative;
    width: 56px;    /* 2 × HALF in viewcube.js */
    height: 56px;
    transform-style: preserve-3d;
}
#viewcube .face {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 0;
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-bd-hover);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.04em;
    backface-visibility: hidden;
    cursor: pointer;
}
#viewcube .face:hover { color: var(--accent); border-color: var(--accent); }
#viewcube-home {
    height: 20px;
    padding: 0 8px;
    background: transparent;
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    color: var(--faint);
    font-family: var(--font-mono);
    font-size: 10px;
    cursor: pointer;
}
#viewcube-home:hover { color: var(--accent); border-color: var(--accent); }
.tree-search { padding: 10px 10px 0; }
.tree-search input {
    width: 100%; height: 28px; padding: 0 8px;
    background: var(--input-bg); color: var(--fg);
    border: 1px solid var(--input-bd); border-radius: var(--radius-ctl);
    font-family: var(--font-mono); font-size: 12px;
}
.tree-hint {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 16px 12px;
    border-top: 1px solid var(--glass-bd);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--faint);
}
.tree-hint [hidden] { display: none; }
#tree-show-all { color: var(--accent); cursor: pointer; }
#tree-show-all:hover { text-decoration: underline; }

/* --- Right-click menu (contextmenu.js) -------------------------------- */

#context-menu {
    position: fixed;
    z-index: 60;
    min-width: 220px;
    padding: 4px;
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-bd-hover);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--fg);
}
#context-menu[hidden] { display: none; }
#context-menu .cm-head {
    padding: 6px 8px 4px;
    color: var(--faint);
    font-size: 11px;
    letter-spacing: 0.04em;
}
#context-menu .cm-sep {
    height: 1px;
    margin: 4px 2px;
    background: var(--glass-bd);
}
#context-menu .cm-sep:first-child { display: none; }
#context-menu .cm-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 26px;
    padding: 0 8px;
    background: transparent;
    border: none;
    border-radius: var(--radius-ctl);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}
#context-menu button.cm-item:hover { background: var(--hover-bg); color: var(--accent); }
#context-menu .cm-item span { flex: 1; }
#context-menu .cm-item kbd {
    font: inherit;
    font-size: 11px;
    color: var(--faint);
}
#context-menu .cm-choices { cursor: default; gap: 6px; }
#context-menu .cm-choices button {
    min-width: 26px;
    height: 22px;
    background: transparent;
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    color: var(--fg);
    font: inherit;
    cursor: pointer;
}
#context-menu .cm-choices button:hover { border-color: var(--accent); color: var(--accent); }

/* --- Contour / vectors / both (fieldarrows.js) ------------------------ */

.seg {
    display: inline-flex;
    border: 1px solid var(--input-bd);
    border-radius: var(--radius-ctl);
    overflow: hidden;
}
.seg button {
    height: 24px;
    padding: 0 9px;
    background: transparent;
    border: none;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--input-bd); }
.seg button:hover { color: var(--fg); }
.seg button.active { color: var(--accent); background: var(--accent-soft); }
