/* ============================================================
   Design tokens
   Light is the default; dark values apply under the OS setting
   (prefers-color-scheme) or an explicit data-theme="dark" on <html>.
   The diagram canvas is deliberately pinned to the light "paper"
   palette in both modes (see .pv-canvas-container below) so the
   canvas-drawn arcs and node colors stay readable.
   --pv-viz-* tokens are consumed by the SVG charts petri-solver.js
   emits; values mirror its built-in light fallbacks.
   ============================================================ */
:root {
    /* The app typeface. A token rather than a literal because the dialogs are
       appended to <body>, NOT inside .pv-root — so they never inherited the
       family set there and every one of them rendered in the browser's default
       serif. See the overlay rules below. */
    --pv-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Theme-invariant: the diagram's paper, light in both themes by design. */
    --pv-paper: #fafafa;

    /* Brand palette for the marketing shell (index.html's --pf-* aliases).
       Deliberately dark in BOTH themes today - the dark ground with the yellow
       accent is the brand, not a dark-mode artifact. Named and centralised here
       so giving the landing page a light variant later is a values-only change
       (add a light override block) rather than an edit to its markup.
       Theme-invariant by design, so exempt from the dark-parity check. */
    --pv-brand-bg: #1C1C1D;
    --pv-brand-bg-alt: #1E1E1D;
    --pv-brand-bg-card: #2a2a2b;
    --pv-brand-ink: #ffffff;
    --pv-brand-ink-muted: #999999;
    --pv-brand-accent: #EBFF00;
    --pv-brand-accent-hover: #d4e600;
    --pv-brand-border: #333333;
    --pv-brand-scrim: rgba(0, 0, 0, 0.6);

    --pv-surface: #ffffff;
    --pv-surface-2: #f6f6f4;
    --pv-surface-3: #ecece9;
    --pv-ink: #24292e;
    --pv-ink-secondary: #586069;
    --pv-ink-muted: #898781;
    --pv-border: #e1e4e8;
    --pv-accent: #2a6fb8;
    --pv-accent-strong: #235d9c;
    --pv-accent-ink: #ffffff;
    --pv-danger: #d73a49;
    --pv-success: #0ca30c;
    --pv-viz-surface: #fcfcfb;
    --pv-viz-ink: #0b0b0b;
    --pv-viz-muted: #898781;
    --pv-viz-grid: #e1e0d9;
    --pv-viz-axis: #c3c2b7;
    --pv-viz-series-1: #2a78d6;
    --pv-viz-series-2: #eb6834;
    --pv-viz-series-3: #1baf7a;
    --pv-viz-series-4: #eda100;
    --pv-viz-series-5: #e87ba4;
    --pv-viz-series-6: #008300;
    --pv-viz-series-7: #4a3aa7;
    --pv-viz-series-8: #e34948;

    --pv-success: #0ca30c;
    --pv-success-strong: #218838;
    --pv-danger-strong: #c82333;
    --pv-warning: #d98300;

    /* Chrome surfaces: floating panels, menus, meters, dialogs. Distinct from
       --pv-surface because they sit ON the canvas and need their own contrast. */
    --pv-panel: #ffffff;
    --pv-panel-soft: rgba(255, 255, 255, 0.92);
    --pv-panel-2: rgba(250, 250, 250, 0.98);
    --pv-hover: #d0d0d0;
    --pv-active: #c0c0c0;
    --pv-grip: rgba(0, 0, 0, 0.15);
    --pv-scrim: rgba(0, 0, 0, 0.5);
    --pv-shadow-sm: rgba(0, 0, 0, 0.08);
    --pv-shadow: rgba(0, 0, 0, 0.15);
    --pv-shadow-md: rgba(0, 0, 0, 0.2);
    --pv-shadow-lg: rgba(0, 0, 0, 0.3);
    --pv-focus-ring: rgba(42, 111, 184, 0.5);
    --pv-warning-glow: rgba(255, 165, 0, 0.5);
    --pv-danger-surface: #f8d7da;
    --pv-danger-surface-hover: #f1b0b7;
    --pv-danger-surface-ink: #721c24;
    --pv-danger-surface-border: #f5c6cb;
    --pv-info-surface: #e7f3ff;
    --pv-info-surface-hover: #cce5ff;
    --pv-info-ink: #0066cc;
    --pv-info-border: #b3d7ff;

    --pv-neutral: #6c757d;
    --pv-neutral-strong: #5a6268;
    --pv-success-muted: #94d3a2;
    --pv-accent-alt: #6f42c1;
    --pv-scrim-soft: rgba(0, 0, 0, 0.3);
    --pv-hover-soft: rgba(0, 0, 0, 0.06);
    --pv-active-soft: rgba(0, 0, 0, 0.1);
    --pv-danger-glow: rgba(220, 53, 69, 0.5);

    /* Dark palette. Single source of truth for BOTH dark paths below
       (prefers-color-scheme and data-theme="dark"); those blocks only remap
       semantic tokens onto these, so the two can never disagree on a value. */
    --pv-d-surface: #1e1e1d;
    --pv-d-surface-2: #171716;
    --pv-d-surface-3: #2a2a28;
    --pv-d-ink: #e8e6df;
    --pv-d-ink-secondary: #a6a49b;
    --pv-d-ink-muted: #898781;
    --pv-d-border: #3a3a38;
    --pv-d-accent: #4d8fd6;
    --pv-d-accent-strong: #6ba3e0;
    --pv-d-accent-ink: #ffffff;
    --pv-d-danger: #e5534b;
    --pv-d-danger-strong: #f85149;
    --pv-d-success: #3fb950;
    --pv-d-success-strong: #2ea043;
    --pv-d-warning: #d29922;
    --pv-d-panel: #232322;
    --pv-d-panel-soft: rgba(35, 35, 34, 0.94);
    --pv-d-panel-2: rgba(28, 28, 27, 0.98);
    --pv-d-hover: #343431;
    --pv-d-active: #3f3f3c;
    --pv-d-grip: rgba(255, 255, 255, 0.24);
    --pv-d-scrim: rgba(0, 0, 0, 0.66);
    --pv-d-shadow-sm: rgba(0, 0, 0, 0.45);
    --pv-d-shadow: rgba(0, 0, 0, 0.55);
    --pv-d-shadow-md: rgba(0, 0, 0, 0.6);
    --pv-d-shadow-lg: rgba(0, 0, 0, 0.72);
    --pv-d-focus-ring: rgba(109, 164, 224, 0.6);
    --pv-d-warning-glow: rgba(210, 153, 34, 0.5);
    --pv-d-danger-surface: #3d1d1f;
    --pv-d-danger-surface-hover: #56282b;
    --pv-d-danger-surface-ink: #ffb4ab;
    --pv-d-danger-surface-border: #5c2b2e;
    --pv-d-info-surface: #10243e;
    --pv-d-info-surface-hover: #17375e;
    --pv-d-info-ink: #79b8ff;
    --pv-d-info-border: #1f4b7a;
    --pv-d-neutral: #6e7681;
    --pv-d-neutral-strong: #8b949e;
    --pv-d-success-muted: #2a5a35;
    --pv-d-accent-alt: #a371f7;
    --pv-d-scrim-soft: rgba(0, 0, 0, 0.5);
    --pv-d-hover-soft: rgba(255, 255, 255, 0.08);
    --pv-d-active-soft: rgba(255, 255, 255, 0.14);
    --pv-d-danger-glow: rgba(229, 83, 75, 0.55);
    --pv-d-viz-muted: #898781;
    --pv-d-viz-surface: #1a1a19;
    --pv-d-viz-ink: #ffffff;
    --pv-d-viz-grid: #2c2c2a;
    --pv-d-viz-axis: #383835;
    --pv-d-viz-series-1: #3987e5;
    --pv-d-viz-series-2: #d95926;
    --pv-d-viz-series-3: #199e70;
    --pv-d-viz-series-4: #c98500;
    --pv-d-viz-series-5: #d55181;
    --pv-d-viz-series-6: #008300;
    --pv-d-viz-series-7: #9085e9;
    --pv-d-viz-series-8: #e66767;

}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --pv-surface: var(--pv-d-surface);
        --pv-surface-2: var(--pv-d-surface-2);
        --pv-surface-3: var(--pv-d-surface-3);
        --pv-ink: var(--pv-d-ink);
        --pv-ink-secondary: var(--pv-d-ink-secondary);
        --pv-ink-muted: var(--pv-d-ink-muted);
        --pv-border: var(--pv-d-border);
        --pv-accent: var(--pv-d-accent);
        --pv-accent-strong: var(--pv-d-accent-strong);
        --pv-accent-ink: var(--pv-d-accent-ink);
        --pv-danger: var(--pv-d-danger);
        --pv-danger-strong: var(--pv-d-danger-strong);
        --pv-success: var(--pv-d-success);
        --pv-success-strong: var(--pv-d-success-strong);
        --pv-warning: var(--pv-d-warning);
        --pv-panel: var(--pv-d-panel);
        --pv-panel-soft: var(--pv-d-panel-soft);
        --pv-panel-2: var(--pv-d-panel-2);
        --pv-hover: var(--pv-d-hover);
        --pv-active: var(--pv-d-active);
        --pv-grip: var(--pv-d-grip);
        --pv-scrim: var(--pv-d-scrim);
        --pv-shadow-sm: var(--pv-d-shadow-sm);
        --pv-shadow: var(--pv-d-shadow);
        --pv-shadow-md: var(--pv-d-shadow-md);
        --pv-shadow-lg: var(--pv-d-shadow-lg);
        --pv-focus-ring: var(--pv-d-focus-ring);
        --pv-warning-glow: var(--pv-d-warning-glow);
        --pv-danger-surface: var(--pv-d-danger-surface);
        --pv-danger-surface-hover: var(--pv-d-danger-surface-hover);
        --pv-danger-surface-ink: var(--pv-d-danger-surface-ink);
        --pv-danger-surface-border: var(--pv-d-danger-surface-border);
        --pv-info-surface: var(--pv-d-info-surface);
        --pv-info-surface-hover: var(--pv-d-info-surface-hover);
        --pv-info-ink: var(--pv-d-info-ink);
        --pv-info-border: var(--pv-d-info-border);
        --pv-neutral: var(--pv-d-neutral);
        --pv-neutral-strong: var(--pv-d-neutral-strong);
        --pv-success-muted: var(--pv-d-success-muted);
        --pv-accent-alt: var(--pv-d-accent-alt);
        --pv-scrim-soft: var(--pv-d-scrim-soft);
        --pv-hover-soft: var(--pv-d-hover-soft);
        --pv-active-soft: var(--pv-d-active-soft);
        --pv-danger-glow: var(--pv-d-danger-glow);
        --pv-viz-muted: var(--pv-d-viz-muted);
    --pv-viz-surface: var(--pv-d-viz-surface);
        --pv-viz-ink: var(--pv-d-viz-ink);
        --pv-viz-grid: var(--pv-d-viz-grid);
        --pv-viz-axis: var(--pv-d-viz-axis);
        --pv-viz-series-1: var(--pv-d-viz-series-1);
        --pv-viz-series-2: var(--pv-d-viz-series-2);
        --pv-viz-series-3: var(--pv-d-viz-series-3);
        --pv-viz-series-4: var(--pv-d-viz-series-4);
        --pv-viz-series-5: var(--pv-d-viz-series-5);
        --pv-viz-series-6: var(--pv-d-viz-series-6);
        --pv-viz-series-7: var(--pv-d-viz-series-7);
        --pv-viz-series-8: var(--pv-d-viz-series-8);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --pv-surface: var(--pv-d-surface);
    --pv-surface-2: var(--pv-d-surface-2);
    --pv-surface-3: var(--pv-d-surface-3);
    --pv-ink: var(--pv-d-ink);
    --pv-ink-secondary: var(--pv-d-ink-secondary);
    --pv-ink-muted: var(--pv-d-ink-muted);
    --pv-border: var(--pv-d-border);
    --pv-accent: var(--pv-d-accent);
    --pv-accent-strong: var(--pv-d-accent-strong);
    --pv-accent-ink: var(--pv-d-accent-ink);
    --pv-danger: var(--pv-d-danger);
    --pv-danger-strong: var(--pv-d-danger-strong);
    --pv-success: var(--pv-d-success);
    --pv-success-strong: var(--pv-d-success-strong);
    --pv-warning: var(--pv-d-warning);
    --pv-panel: var(--pv-d-panel);
    --pv-panel-soft: var(--pv-d-panel-soft);
    --pv-panel-2: var(--pv-d-panel-2);
    --pv-hover: var(--pv-d-hover);
    --pv-active: var(--pv-d-active);
    --pv-grip: var(--pv-d-grip);
    --pv-scrim: var(--pv-d-scrim);
    --pv-shadow-sm: var(--pv-d-shadow-sm);
    --pv-shadow: var(--pv-d-shadow);
    --pv-shadow-md: var(--pv-d-shadow-md);
    --pv-shadow-lg: var(--pv-d-shadow-lg);
    --pv-focus-ring: var(--pv-d-focus-ring);
    --pv-warning-glow: var(--pv-d-warning-glow);
    --pv-danger-surface: var(--pv-d-danger-surface);
    --pv-danger-surface-hover: var(--pv-d-danger-surface-hover);
    --pv-danger-surface-ink: var(--pv-d-danger-surface-ink);
    --pv-danger-surface-border: var(--pv-d-danger-surface-border);
    --pv-info-surface: var(--pv-d-info-surface);
    --pv-info-surface-hover: var(--pv-d-info-surface-hover);
    --pv-info-ink: var(--pv-d-info-ink);
    --pv-info-border: var(--pv-d-info-border);
    --pv-neutral: var(--pv-d-neutral);
    --pv-neutral-strong: var(--pv-d-neutral-strong);
    --pv-success-muted: var(--pv-d-success-muted);
    --pv-accent-alt: var(--pv-d-accent-alt);
    --pv-scrim-soft: var(--pv-d-scrim-soft);
    --pv-hover-soft: var(--pv-d-hover-soft);
    --pv-active-soft: var(--pv-d-active-soft);
    --pv-danger-glow: var(--pv-d-danger-glow);
    --pv-viz-muted: var(--pv-d-viz-muted);
    --pv-viz-surface: var(--pv-d-viz-surface);
    --pv-viz-ink: var(--pv-d-viz-ink);
    --pv-viz-grid: var(--pv-d-viz-grid);
    --pv-viz-axis: var(--pv-d-viz-axis);
    --pv-viz-series-1: var(--pv-d-viz-series-1);
    --pv-viz-series-2: var(--pv-d-viz-series-2);
    --pv-viz-series-3: var(--pv-d-viz-series-3);
    --pv-viz-series-4: var(--pv-d-viz-series-4);
    --pv-viz-series-5: var(--pv-d-viz-series-5);
    --pv-viz-series-6: var(--pv-d-viz-series-6);
    --pv-viz-series-7: var(--pv-d-viz-series-7);
    --pv-viz-series-8: var(--pv-d-viz-series-8);
}

/* The diagram itself stays on light "paper" in both modes: canvas arc
   colors are drawn in JS against a light background. */
/* The diagram layer keeps the light "paper" palette in BOTH themes so the
   canvas-drawn arcs and node colors stay readable. Scoped to .pv-stage, not
   .pv-canvas-container: the scale meter and mode menu are siblings of the
   stage inside that container, and pinning at the container level froze them
   light in dark mode. */
.pv-stage {
    --pv-surface: #ffffff;
    --pv-surface-2: #fafafa;
    --pv-surface-3: #ecece9;
    --pv-ink: #24292e;
    --pv-ink-secondary: #586069;
    --pv-border: #e1e4e8;
    /* The new chrome tokens are pinned here as well: elements drawn on the
       canvas (weight badges, token dots) sit on light paper in both themes, so
       a dark shadow or panel value would bleed through. */
    --pv-panel: #ffffff;
    --pv-panel-soft: rgba(255, 255, 255, 0.92);
    --pv-panel-2: rgba(250, 250, 250, 0.98);
    --pv-grip: rgba(0, 0, 0, 0.15);
    --pv-shadow-sm: rgba(0, 0, 0, 0.08);
    --pv-shadow: rgba(0, 0, 0, 0.15);
    --pv-shadow-md: rgba(0, 0, 0, 0.2);
    --pv-shadow-lg: rgba(0, 0, 0, 0.3);

    /* NOTE: safe-area insets are written as env() directly at each use site, and
       always preceded by a plain fallback declaration. Do NOT hoist them into a
       custom property: `calc(10px + var(--x))` where --x holds an unsupported
       env() is invalid *at computed-value time*, which resolves to `unset`
       (i.e. `auto` for an offset) instead of falling back to the previous
       declaration. That silently threw the Login button to the top-left corner. */

    color-scheme: light;
}

/* Canvas backdrop. --pv-paper is intentionally theme-invariant (see the
   token block); it is the paper the diagram sits on, not a themed surface. */
.pv-canvas-container {
    background: var(--pv-paper);
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    /* The canvas surfaces declare their own touch-action, so the app still owns
       its pan/pinch gestures. Declaring `none` at the document level additionally
       blocked browser pinch-zoom on menus, dialogs and the JSON pane — which
       fails WCAG 1.4.4 and contradicts the viewport meta in index.html. */
    overscroll-behavior: none;
}

petri-view {
    display: block;
    width: 100%;
    /* svh, not dvh: the shell must not resize as the iOS URL bar animates, and
       100vh alone puts the bottom ~90px of the app under it. */
    height: 100vh;
    height: 100svh;
    border: 1px solid var(--pv-border);
    box-sizing: border-box;
}

.pv-root {
    position: relative;
    width: 100%;
    height: 100%;
    font-family: var(--pv-font);
    background: var(--pv-surface-2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Prevent text selection and touch callouts during interactions */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Horizontal layout when toggled */
.pv-root.pv-layout-horizontal {
    flex-direction: row;
}

canvas.pv-canvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* nodes */
.pv-node {
    position: absolute;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

/* place: outer container 72-80px, inner white circle with black stroke (r~16) */
.pv-place {
    width: 80px;
    height: 80px;
    border-radius: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.pv-place-inner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--pv-surface);
    border: 1.5px solid #000;
    box-shadow: none;
    box-sizing: border-box;
}

.pv-place-handle {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: transparent;
    pointer-events: auto;
    touch-action: none;
}

/* transition: 30x30 square */
.pv-transition {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
    background: var(--pv-surface);
    border: 1px solid #000;
}

.pv-transition.pv-active {
    background: #62fa75;
}

.pv-transition.pv-firing {
    opacity: 0.6;
    pointer-events: none;
}

/* Canvas node label. Scoped to .pv-node deliberately: a second, unrelated
   `.pv-label` further down styles form labels inside dialogs, and at equal
   specificity the later rule was winning — so every node label on the canvas
   silently rendered at 14px with a stray 6px bottom margin instead of the 12px
   authored here. The descendant selector settles it without renaming the class
   across the component. */
.pv-node .pv-label {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: 400;
    color: #222;
    top: 100%;
    margin-top: 6px;
    margin-bottom: 0;
    pointer-events: none;
}

/* tokens: small circles inside place */
.pv-token {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--pv-surface);
    color: #000;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    padding: 0 6px;
    border: 1px solid var(--pv-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    pointer-events: none;
}

.pv-token-dot {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #000;
    box-shadow: none;
    pointer-events: none;
}

/* Token breakdown on hover */
.pv-token-breakdown {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1000;
}

.pv-token-breakdown-item {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
}

.pv-token-breakdown-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid;
    background: var(--pv-surface);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
}

.pv-token-breakdown-count {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 700;
    /* Background color is set dynamically to match token color */
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    pointer-events: none;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    /* Text color is set dynamically based on background color brightness */
}

.pv-inhibit {
    stroke: #c0392b;
}

.pv-weight {
    position: absolute;
    font-size: 11px;
    background: var(--pv-surface);
    padding: 2px 6px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    pointer-events: none;
    border: 1px solid transparent;
}

.pv-weight-inhibit {
    font-style: italic;
}

/* Label-edit mode highlighting */
.pv-label-editable {
    outline: 3px dashed rgba(0, 120, 215, 0.6);
    cursor: pointer;
}

.pv-label-editable:hover {
    outline-color: rgba(0, 120, 215, 0.9);
}

/* Group-select mode highlighting */
.pv-group-selected {
    outline: 3px solid rgba(255, 165, 0, 0.8);
    box-shadow: 0 0 8px rgba(255, 165, 0, 0.5);
}

.pv-group-selected:hover {
    outline-color: rgba(255, 140, 0, 1);
}

/* Layout: Canvas container and JSON editor as peers */
.pv-canvas-container {
    flex: 1 1 auto;
    min-width: 200px;
    min-height: 150px;
    position: relative;
    overflow: hidden;
    /* Prevent default touch behaviors like scroll/zoom during pan/drag */
    touch-action: none;
}

.pv-stage {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
}

/* Divider between canvas and editor */
.pv-layout-divider {
    flex: 0 0 8px;
    background: linear-gradient(180deg, var(--pv-surface-3) 0%, var(--pv-surface-2) 50%, var(--pv-surface-3) 100%);
    cursor: row-resize;
    position: relative;
    z-index: 50;
    transition: background 0.2s;
}

.pv-layout-divider:hover,
.pv-layout-divider:active {
    background: linear-gradient(180deg, var(--pv-active) 0%, var(--pv-hover) 50%, var(--pv-active) 100%);
}

.pv-layout-divider::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 3px;
    background: var(--pv-grip);
    border-radius: 2px;
}

/* Horizontal divider when layout is horizontal */
.pv-root.pv-layout-horizontal .pv-layout-divider {
    background: linear-gradient(90deg, var(--pv-surface-3) 0%, var(--pv-surface-2) 50%, var(--pv-surface-3) 100%);
    cursor: col-resize;
}

.pv-root.pv-layout-horizontal .pv-layout-divider:hover,
.pv-root.pv-layout-horizontal .pv-layout-divider:active {
    background: linear-gradient(90deg, var(--pv-active) 0%, var(--pv-hover) 50%, var(--pv-active) 100%);
}

.pv-root.pv-layout-horizontal .pv-layout-divider::before {
    width: 3px;
    height: 40px;
}

/* JSON Editor as peer component */
.pv-json-editor {
    flex: 1 1 auto;
    min-width: 200px;
    min-height: 150px;
    padding: 12px;
    background: var(--pv-panel-2);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: auto;
    border-radius: 0;
    box-shadow: none;
    position: relative;
    z-index: 10;
}

/* Override fixed positioning when in split layout */
.pv-root .pv-json-editor {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    height: auto;
    max-height: none;
}

/* Layout toggle button */
.pv-layout-toggle {
    position: absolute;
    top: 10px;
    right: 70px;
    width: 44px;
    height: 36px;
    border-radius: 6px;
    border: none;
    background: var(--pv-panel-soft);
    box-shadow: 0 2px 6px var(--pv-shadow);
    cursor: pointer;
    font-size: 16px;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    transition: background 0.2s;
}

.pv-layout-toggle:hover {
    background: var(--pv-panel);
}

.pv-layout-toggle:active {
    background: var(--pv-surface-3);
}

/* Remove focus outline on toolbar buttons to avoid visual inconsistency */
.pv-tool:focus,
.pv-play:focus {
    outline: none;
}

/* Keep keyboard navigation accessible with visible focus for keyboard users */
.pv-tool:focus-visible,
.pv-play:focus-visible {
    outline: 2px solid var(--pv-focus-ring);
    outline-offset: 2px;
}

/* ============================================
   ACE Editor Toolbar & Components
   ============================================ */

.pv-ace-toolbar {
    display: flex;
    gap: 6px;
    padding: 6px 4px;
    align-items: center;
    background: transparent;
}

.pv-ace-toolbar-btn {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--pv-border);
    background: var(--pv-surface);
    cursor: pointer;
    font-size: 12px;
}

.pv-ace-editor-wrapper {
    width: 100%;
    flex: 1 1 auto;
    min-height: 120px;
    box-sizing: border-box;
    border-radius: 6px;
    border: 1px solid var(--pv-border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pv-ace-editor {
    width: 100%;
    flex: 1 1 auto;
    min-height: 120px;
}

/* ============================================
   Modal Overlays & Dialogs
   ============================================ */

.pv-modal-overlay {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: var(--pv-scrim);
    z-index: 2147483646;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pv-modal-dialog {
    background: var(--pv-surface);
    border-radius: 8px;
    padding: 24px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 4px 20px var(--pv-shadow-lg);
    max-height: 85vh;
    overflow: auto;
}

.pv-modal-dialog-wide {
    max-width: 700px;
    max-height: 85vh;
    overflow: auto;
}

.pv-modal-dialog-xl {
    max-width: 900px;
    max-height: 90vh;
    border: 1px solid var(--pv-border);
    border-radius: 12px;
    padding: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.pv-modal-title {
    margin: 0 0 16px 0;
    font-size: 20px;
    font-weight: bold;
    color: var(--pv-ink);
}

.pv-modal-title-lg {
    font-size: 22px;
}

.pv-modal-description {
    margin: '0 0 16px 0';
    font-size: 14px;
    color: var(--pv-ink-secondary);
}

/* ============================================
   Dialog Headers
   ============================================ */

.pv-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--pv-border);
    background: var(--pv-surface-2);
    border-radius: 12px 12px 0 0;
}

.pv-dialog-header-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--pv-ink);
}

.pv-dialog-close-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--pv-surface-2);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pv-ink-secondary);
    transition: background 0.2s, color 0.2s;
}

.pv-dialog-close-icon:hover {
    background: var(--pv-surface-3);
    color: var(--pv-ink);
}

.pv-dialog-close-icon:active {
    background: var(--pv-hover);
}

/* ============================================
   Form Elements
   ============================================ */

.pv-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    box-sizing: border-box;
    font-family: inherit;
}

.pv-input:focus {
    outline: none;
    border-color: var(--pv-accent);
}

.pv-input-mono {
    font-family: monospace;
}

.pv-input-sm {
    padding: 6px 10px;
    font-size: 13px;
}

.pv-textarea {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    box-sizing: border-box;
    font-family: monospace;
    resize: vertical;
    background: var(--pv-surface-2);
}

.pv-textarea:focus {
    outline: none;
    border-color: var(--pv-accent);
}

.pv-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--pv-ink);
    display: block;
    margin-bottom: 6px;
}

.pv-label-sm {
    font-size: 13px;
    margin-bottom: 4px;
}

/* ============================================
   Buttons
   ============================================ */

.pv-btn {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--pv-border);
    background: var(--pv-surface-2);
    color: var(--pv-ink);
}

.pv-btn:hover {
    background: var(--pv-surface-3);
}

.pv-btn-primary {
    color: var(--pv-accent-ink);
    background: var(--pv-accent);
    border: none;
}

.pv-btn-primary:hover {
    background: var(--pv-accent-strong);
}

.pv-btn-success {
    color: var(--pv-accent-ink);
    background: var(--pv-success);
    border: none;
}

.pv-btn-success:hover {
    background: var(--pv-success-strong);
}

.pv-btn-danger {
    color: var(--pv-accent-ink);
    background: var(--pv-danger);
    border: none;
}

.pv-btn-danger:hover {
    background: var(--pv-danger-strong);
}

.pv-btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.pv-btn-lg {
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
}

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

/* ============================================
   Button Containers
   ============================================ */

.pv-btn-container {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

.pv-btn-container-center {
    justify-content: center;
}

/* ============================================
   Fallback Editor Toolbar
   ============================================ */

.pv-editor-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.pv-editor-toolbar-btn {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid var(--pv-border);
    background: var(--pv-surface);
    cursor: pointer;
}

.pv-editor-toolbar-btn:hover {
    background: var(--pv-surface-2);
}

.pv-editor-textarea {
    width: 100%;
    flex: 1 1 auto;
    min-height: 120px;
    font-family: monospace;
    font-size: 12px;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    padding: 10px;
    box-sizing: border-box;
    resize: none;
}

/* ============================================
   Open URL Dialog
   ============================================ */

.pv-url-dialog {
    max-width: 500px;
}

.pv-url-dialog-title {
    margin: 0 0 16px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--pv-ink);
}

.pv-headers-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
    max-height: 150px;
    overflow-y: auto;
}

.pv-header-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pv-header-input {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--pv-border);
    border-radius: 4px;
}

.pv-header-remove-btn {
    padding: 6px 10px;
    font-size: 12px;
    background: var(--pv-danger-surface);
    color: var(--pv-danger-surface-ink);
    border: 1px solid var(--pv-danger-surface-border);
    border-radius: 4px;
    cursor: pointer;
}

.pv-header-remove-btn:hover {
    background: var(--pv-danger-surface-hover);
}

.pv-add-header-btn {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--pv-info-surface);
    color: var(--pv-info-ink);
    border: 1px solid var(--pv-info-border);
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 16px;
}

.pv-add-header-btn:hover {
    background: var(--pv-info-surface-hover);
}

/* ============================================
   Share Dialog
   ============================================ */

.pv-share-textarea {
    width: 100%;
    height: 60px;
    padding: 12px;
    font-size: 13px;
    font-family: monospace;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    background: var(--pv-surface-2);
    resize: none;
    box-sizing: border-box;
}

.pv-share-preview-container {
    text-align: center;
    padding: 16px;
    background: var(--pv-surface-2);
    border-radius: 6px;
    margin-bottom: 16px;
}

.pv-share-preview-img {
    max-width: 100%;
    max-height: 200px;
    border: 1px solid var(--pv-border);
    border-radius: 4px;
}

/* ============================================
   Scale Meter
   ============================================ */

.pv-scale-meter {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 160px;
    padding: 8px;
    background: var(--pv-panel-soft);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--pv-shadow);
    /* Was 3000, which outranked the mode menu (1200), the hamburger and the
       login button (1300) — a zoom readout has no business painting over the
       app's own chrome. */
    z-index: 1100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    user-select: none;
    font-family: var(--pv-font);
}

.pv-scale-label {
    font-size: 12px;
    color: var(--pv-ink);
    line-height: 1;
}

.pv-scale-reset {
    width: 36px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid var(--pv-border);
    background: var(--pv-surface);
    cursor: pointer;
    font-size: 12px;
    color: var(--pv-ink);
    margin-bottom: 4px;
    padding: 0;
}

.pv-scale-reset:hover {
    background: var(--pv-surface-2);
    border-color: var(--pv-ink-muted);
}

.pv-scale-track {
    position: relative;
    width: 10px;
    flex: 1 1 auto;
    height: 100%;
    background: var(--pv-surface-3);
    border-radius: 6px;
    overflow: hidden;
    align-self: center;
}

.pv-scale-fill {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: 10px;
    height: 0%;
    background: linear-gradient(180deg, var(--pv-accent), var(--pv-accent-strong));
    border-radius: 6px;
}

.pv-scale-thumb {
    position: absolute;
    left: 50%;
    transform: translate(-50%, 50%);
    bottom: 0%;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--pv-surface);
    border: 2px solid var(--pv-accent);
    box-shadow: 0 1px 3px var(--pv-shadow-md);
}

.pv-scale-legend {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--pv-ink-secondary);
}

/* ============================================
   Help Dialog
   ============================================ */

.pv-help-title {
    margin: 0 0 16px 0;
    font-size: 22px;
    font-weight: bold;
    color: var(--pv-ink);
}

.pv-help-content {
    font-size: 14px;
    line-height: 1.6;
    color: var(--pv-ink);
}

.pv-help-content h3 {
    margin: 16px 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--pv-ink);
}

.pv-help-content h4 {
    margin: 12px 0 6px 0;
    font-size: 14px;
    font-weight: 600;
}

.pv-help-content p {
    margin: 0 0 12px 0;
}

.pv-help-content ul {
    margin: 6px 0 12px 20px;
    padding: 0;
}

.pv-help-content ul ul {
    margin: 4px 0 4px 20px;
}

.pv-help-close-btn {
    display: block;
    margin: 20px auto 0;
    padding: 10px 32px;
    font-size: 15px;
    font-weight: 500;
    color: var(--pv-accent-ink);
    background: var(--pv-accent);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.pv-help-close-btn:hover {
    background: var(--pv-accent-strong);
}

/* ============================================
   Simulation Dialog
   ============================================ */

.pv-sim-overlay {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: var(--pv-scrim);
    z-index: 2147483646;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pv-sim-dialog {
    background: var(--pv-surface);
    border-radius: 12px;
    padding: 0;
    max-width: 900px;
    width: 100%;
    box-shadow: 0 4px 20px var(--pv-shadow-lg);
    max-height: 90vh;
    border: 1px solid var(--pv-border);
    display: flex;
    flex-direction: column;
    position: relative;
}

.pv-sim-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--pv-border);
}

.pv-sim-title {
    margin: 0;
    font-size: 22px;
    font-weight: bold;
    color: var(--pv-ink);
}

.pv-sim-close-btn {
    background: transparent;
    border: none;
    font-size: 32px;
    line-height: 1;
    color: var(--pv-ink-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
}

.pv-sim-close-btn:hover {
    background: var(--pv-surface-2);
    color: var(--pv-ink);
}

.pv-sim-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-height: 0;
}

.pv-sim-description {
    margin: 0 0 20px 0;
    font-size: 14px;
    color: var(--pv-ink-secondary);
    line-height: 1.5;
}

.pv-sim-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.pv-sim-section {
    margin-bottom: 16px;
}

.pv-sim-section-title {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--pv-ink);
}

.pv-sim-field-label {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--pv-ink);
}

.pv-sim-field-input {
    width: 100%;
    padding: 6px;
    font-size: 13px;
    border: 1px solid var(--pv-border);
    border-radius: 4px;
    box-sizing: border-box;
}

.pv-sim-field-input-mb {
    margin-bottom: 8px;
}

.pv-sim-field-input:focus {
    outline: none;
    border-color: var(--pv-accent);
}

.pv-sim-variables-container {
    max-height: 150px;
    overflow: auto;
    border: 1px solid var(--pv-border);
    border-radius: 4px;
    padding: 8px;
    background: var(--pv-surface-2);
}

.pv-sim-no-items {
    margin: 0;
    font-size: 13px;
    color: var(--pv-ink-muted);
    font-style: italic;
}

.pv-sim-checkbox-wrapper {
    margin-bottom: 6px;
    display: flex;
    align-items: center;
}

.pv-sim-checkbox {
    margin-right: 8px;
    cursor: pointer;
}

.pv-sim-checkbox-label {
    font-size: 13px;
    cursor: pointer;
    color: var(--pv-ink);
}

.pv-sim-rate-wrapper {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.pv-sim-rate-label {
    font-size: 13px;
    color: var(--pv-ink);
    flex: 1;
    margin-right: 8px;
}

.pv-sim-rate-input {
    width: 80px;
    padding: 4px;
    font-size: 13px;
    border: 1px solid var(--pv-border);
    border-radius: 4px;
}

.pv-sim-rate-input:focus {
    outline: none;
    border-color: var(--pv-accent);
}

.pv-sim-plot-container {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid var(--pv-border);
    border-radius: 8px;
    background: var(--pv-surface-2);
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pv-sim-plot-placeholder {
    margin: 0;
    font-size: 14px;
    color: var(--pv-ink-muted);
    font-style: italic;
}

.pv-sim-buttons {
    margin-top: 20px;
    padding: 16px 24px;
    border-top: 1px solid var(--pv-border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: var(--pv-surface-2);
}

.pv-sim-btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.pv-sim-btn-primary {
    color: var(--pv-accent-ink);
    background: var(--pv-accent);
}

.pv-sim-btn-primary:hover {
    background: var(--pv-accent-strong);
}

.pv-sim-btn-export {
    color: var(--pv-accent-ink);
    background: var(--pv-accent-alt);
}

.pv-sim-btn-export:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pv-sim-btn-secondary {
    color: var(--pv-ink);
    background: var(--pv-surface-2);
    border: 1px solid var(--pv-border);
}

.pv-sim-btn-secondary:hover {
    background: var(--pv-surface-3);
}

/* ============================================
   Layout Algorithm Dialog
   ============================================ */

.pv-layout-overlay {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: var(--pv-scrim);
    z-index: 2147483646;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pv-layout-dialog {
    background: var(--pv-surface);
    border-radius: 8px;
    padding: 24px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 4px 20px var(--pv-shadow-lg);
    max-height: 85vh;
    overflow: auto;
}

.pv-layout-dialog-title {
    margin: 0 0 16px 0;
    font-size: 22px;
    font-weight: bold;
    color: var(--pv-ink);
}

.pv-layout-dialog-desc {
    margin: 0 0 16px 0;
    font-size: 14px;
    color: var(--pv-ink-secondary);
}

.pv-layout-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pv-layout-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
    background: var(--pv-surface-2);
    border: 2px solid var(--pv-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.pv-layout-option:hover {
    background: var(--pv-surface-3);
    border-color: var(--pv-accent);
}

.pv-layout-option-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.pv-layout-option-icon {
    font-size: 20px;
}

.pv-layout-option-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--pv-ink);
}

.pv-layout-option-desc {
    font-size: 13px;
    color: var(--pv-ink-secondary);
    line-height: 1.4;
}

.pv-layout-close-btn {
    margin-top: 20px;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--pv-ink);
    background: var(--pv-surface-2);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.pv-layout-close-btn:hover {
    background: var(--pv-surface-3);
}

/* ============================================
   My Diagrams Dialog
   ============================================ */

.pv-diagrams-overlay {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: var(--pv-scrim);
    z-index: 2147483646;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pv-diagrams-dialog {
    background: var(--pv-surface);
    border-radius: 8px;
    padding: 24px;
    max-width: 800px;
    width: 100%;
    max-height: 80vh;
    overflow: auto;
    box-shadow: 0 4px 20px var(--pv-shadow-lg);
}

.pv-diagrams-title {
    margin: 0 0 16px 0;
    font-size: 22px;
    font-weight: bold;
    color: var(--pv-ink);
}

.pv-diagrams-loading {
    padding: 20px;
    text-align: center;
    color: var(--pv-ink-secondary);
}

.pv-diagrams-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--pv-ink-secondary);
    font-size: 14px;
}

.pv-diagrams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.pv-diagram-card {
    border: 1px solid var(--pv-border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
}

.pv-diagram-card:hover {
    box-shadow: 0 4px 12px var(--pv-shadow);
    transform: translateY(-2px);
}

.pv-diagram-thumbnail {
    width: 100%;
    height: 120px;
    background: var(--pv-surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.pv-diagram-thumbnail img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.pv-diagram-info {
    padding: 12px;
}

.pv-diagram-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--pv-ink);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pv-diagram-desc {
    font-size: 12px;
    color: var(--pv-ink-secondary);
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.pv-diagram-date {
    font-size: 11px;
    color: var(--pv-ink-muted);
}

.pv-diagram-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.pv-diagram-open-btn {
    flex: 1;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--pv-accent-ink);
    background: var(--pv-accent);
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.pv-diagram-open-btn:hover {
    background: var(--pv-accent-strong);
}

.pv-diagram-actions {
    display: flex;
    border-top: 1px solid var(--pv-border);
}

.pv-diagram-action-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
}

.pv-diagram-action-btn-open {
    color: var(--pv-accent);
}

.pv-diagram-action-btn-open:hover {
    background: var(--pv-info-surface);
}

.pv-diagram-action-btn-delete {
    color: var(--pv-danger);
    border-left: 1px solid var(--pv-border);
}

.pv-diagram-action-btn-delete:hover {
    background: var(--pv-panel)5f5;
}

.pv-diagrams-close-btn {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    background: var(--pv-neutral);
    color: var(--pv-accent-ink);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.pv-diagrams-close-btn:hover {
    background: var(--pv-neutral-strong);
}

/* ============================================
   Edit Details Dialog
   ============================================ */

.pv-edit-dialog {
    max-width: 450px;
}

.pv-edit-dialog-title {
    margin: 0 0 20px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--pv-ink);
}

.pv-edit-field-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--pv-ink-secondary);
    display: block;
    margin-bottom: 6px;
}

.pv-edit-field-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    box-sizing: border-box;
    margin-bottom: 16px;
}

.pv-edit-field-input:focus {
    outline: none;
    border-color: var(--pv-accent);
}

/* Edit Remote Diagram Details Dialog */
.pv-edit-diagram-overlay {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: var(--pv-scrim);
    z-index: 2147483647;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pv-edit-diagram-dialog {
    background: var(--pv-surface);
    border-radius: 8px;
    padding: 24px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 4px 20px var(--pv-shadow-lg);
}

.pv-edit-diagram-title {
    margin: 0 0 16px 0;
    font-size: 22px;
    font-weight: bold;
    color: var(--pv-ink);
}

.pv-edit-diagram-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--pv-ink);
    margin-bottom: 4px;
}

.pv-edit-diagram-input {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    margin-bottom: 16px;
    box-sizing: border-box;
}

.pv-edit-diagram-input:focus {
    outline: none;
    border-color: var(--pv-accent);
}

.pv-edit-diagram-textarea {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    margin-bottom: 20px;
    box-sizing: border-box;
    resize: vertical;
}

.pv-edit-diagram-textarea:focus {
    outline: none;
    border-color: var(--pv-accent);
}

.pv-edit-diagram-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.pv-edit-diagram-btn-cancel {
    padding: 10px 20px;
    font-size: 14px;
    background: var(--pv-surface-2);
    color: var(--pv-ink);
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.pv-edit-diagram-btn-cancel:hover {
    background: var(--pv-border);
}

.pv-edit-diagram-btn-save {
    padding: 10px 20px;
    font-size: 14px;
    background: var(--pv-success);
    color: var(--pv-accent-ink);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.pv-edit-diagram-btn-save:hover {
    background: var(--pv-success-strong);
}

.pv-edit-diagram-btn-save:disabled {
    background: var(--pv-success-muted);
    cursor: not-allowed;
}

/* ============================================
   Hamburger Menu
   ============================================ */

.pv-hamburger-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: none;
    background: var(--pv-panel-soft);
    box-shadow: 0 2px 6px var(--pv-shadow);
    cursor: pointer;
    font-size: 20px;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    transition: background 0.2s;
}

.pv-hamburger-btn:hover {
    background: var(--pv-panel);
}

.pv-hamburger-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--pv-scrim);
    z-index: 1299;
}

.pv-hamburger-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100%;
    background: var(--pv-surface);
    box-shadow: 2px 0 8px var(--pv-shadow-sm);
    display: flex;
    flex-direction: column;
    z-index: 1300;
}

.pv-hamburger-header {
    padding: 16px 16px 16px 60px;
    border-bottom: 1px solid var(--pv-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.pv-hamburger-header-btn {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pv-ink-secondary);
}

.pv-hamburger-title {
    margin: 0;
    font-size: 18px;
    font-weight: bold;
}

.pv-hamburger-close-btn {
    background: transparent;
    border: none;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    color: var(--pv-ink-secondary);
}

.pv-hamburger-content {
    padding: 8px 0;
    flex: 1 1 auto;
    overflow: auto;
}

.pv-hamburger-dropdown {
    position: absolute;
    top: 55px;
    left: 10px;
    min-width: 180px;
    background: var(--pv-panel-soft);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--pv-shadow-md);
    z-index: 1300;
    padding: 6px 0;
    user-select: none;
}

.pv-hamburger-separator {
    height: 1px;
    background: var(--pv-border);
    margin: 8px 0;
}

.pv-hamburger-user-info {
    padding: 10px 16px;
    font-size: 13px;
    color: var(--pv-ink-secondary);
    border-bottom: 1px solid var(--pv-border);
}

/* ============================================
   Top-Right User/Login Button
   ============================================ */

.pv-top-right-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    height: 40px;
    padding: 0 16px;
    border-radius: 6px;
    border: none;
    background: var(--pv-panel-soft);
    box-shadow: 0 2px 6px var(--pv-shadow);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--pv-font);
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    transition: background 0.2s;
    white-space: nowrap;
}

.pv-top-right-btn:hover {
    background: var(--pv-panel);
}

/* Legacy menu classes for compatibility */
.pv-menu-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: var(--pv-panel-soft);
    box-shadow: 0 2px 8px var(--pv-shadow);
    cursor: pointer;
    font-size: 20px;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.pv-menu-btn:hover {
    background: var(--pv-surface);
}

.pv-menu-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2100;
    display: flex;
}

.pv-menu-panel {
    width: 280px;
    max-width: 80vw;
    height: 100%;
    background: var(--pv-surface);
    box-shadow: 2px 0 12px var(--pv-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pv-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--pv-border);
    background: var(--pv-surface-2);
}

.pv-menu-header-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pv-ink-secondary);
}

.pv-menu-header-btn:hover {
    background: var(--pv-surface-2);
}

.pv-menu-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--pv-ink);
    margin: 0;
}

.pv-menu-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--pv-surface-2);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pv-ink-secondary);
}

.pv-menu-close-btn:hover {
    background: var(--pv-surface-3);
}

.pv-menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.pv-menu-backdrop {
    flex: 1;
    background: var(--pv-scrim-soft);
    cursor: pointer;
}

.pv-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 14px;
    color: var(--pv-ink);
}

.pv-menu-item:hover {
    background: var(--pv-surface-2);
}

.pv-menu-item-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.pv-menu-separator {
    height: 1px;
    background: var(--pv-surface-3);
    margin: 8px 16px;
}

.pv-menu-user-info {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--pv-ink-secondary);
    background: var(--pv-surface-2);
    border-radius: 6px;
    margin: 8px 16px;
}

/* ============================================
   Mode Toolbar
   ============================================ */

.pv-mode-menu {
    position: absolute;
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 6px 8px;
    background: var(--pv-panel-soft);
    border-radius: 8px;
    box-shadow: 0 2px 6px var(--pv-shadow);
    z-index: 1200;
    align-items: center;
    user-select: none;
    font-size: 14px;
}

.pv-mode-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.pv-mode-btn:hover {
    background: var(--pv-hover-soft);
}

.pv-mode-btn.pv-active {
    background: var(--pv-active-soft);
}

.pv-play-btn {
    width: 44px;
    height: 36px;
    border-radius: 6px;
    border: none;
    background: linear-gradient(180deg, var(--pv-surface), var(--pv-surface-2));
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pv-play-btn:hover {
    background: linear-gradient(180deg, var(--pv-surface-2), var(--pv-surface-3));
}

/* ============================================
   Invalid Flash Animation
   ============================================ */

.pv-invalid {
    animation: pv-flash-invalid 0.35s ease;
}

@keyframes pv-flash-invalid {
    0%, 100% { box-shadow: none; }
    50% { box-shadow: 0 0 0 3px var(--pv-danger-glow); }
}

/* ============================================================
   Toolbar + simulation state feedback
   ============================================================ */
.pv-tool.pv-active {
    background: color-mix(in srgb, var(--pv-accent) 14%, transparent);
    box-shadow: inset 0 0 0 1.5px var(--pv-accent);
    border-radius: 6px;
}
.pv-tool:disabled {
    opacity: 0.45;
    cursor: default;
}
.pv-simulating .pv-canvas-container {
    box-shadow: inset 0 0 0 3px var(--pv-accent);
}
.pv-simulating .pv-play {
    background: color-mix(in srgb, var(--pv-accent) 18%, transparent);
    border-radius: 6px;
}
.pv-transition.pv-firing {
    animation: pv-fire-flash 240ms ease-out;
}
@keyframes pv-fire-flash {
    0% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--pv-accent) 60%, transparent); }
    100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--pv-accent) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
    .pv-transition.pv-firing { animation: none; outline: 3px solid var(--pv-accent); }
}

/* ============================================================
   Toasts (replace window.alert)
   ============================================================ */
.pv-toast-host {
    position: fixed;
    bottom: 84px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    max-width: min(560px, 90vw);
}
.pv-toast {
    pointer-events: auto;
    cursor: pointer;
    background: var(--pv-surface);
    color: var(--pv-ink);
    border: 1px solid var(--pv-border);
    border-left: 4px solid var(--pv-accent);
    border-radius: 8px;
    padding: 10px 14px;
    font: 13px/1.45 var(--pv-font);
    box-shadow: 0 6px 24px var(--pv-shadow-md);
    white-space: pre-line;
    animation: pv-toast-in 160ms ease-out;
    max-width: 100%;
}
.pv-toast-error { border-left-color: var(--pv-danger); }
.pv-toast-success { border-left-color: var(--pv-success); }
.pv-toast-out { opacity: 0; transition: opacity 280ms ease-out; }
@keyframes pv-toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ============================================================
   Analysis workbench
   ============================================================ */
.pv-analysis-dialog {
    width: min(1100px, 94vw);
    max-width: none;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    padding: 16px 20px;
    background: var(--pv-surface);
    color: var(--pv-ink);
}
.pv-analysis-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--pv-border);
    margin: 4px 0 0;
}
.pv-analysis-tab {
    appearance: none;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 14px;
    font: 600 13px/1 var(--pv-font);
    color: var(--pv-ink-secondary);
    cursor: pointer;
}
.pv-analysis-tab:hover { color: var(--pv-ink); }
.pv-analysis-tab.pv-active {
    color: var(--pv-accent);
    border-bottom-color: var(--pv-accent);
}
.pv-analysis-hint {
    margin: 8px 0;
    font-size: 12.5px;
    color: var(--pv-ink-secondary);
}
.pv-analysis-body {
    display: flex;
    gap: 16px;
    flex: 1;
    min-height: 0;
}
.pv-analysis-controls {
    width: 250px;
    flex: none;
    overflow-y: auto;
    padding-right: 6px;
}
.pv-analysis-section { margin-bottom: 14px; }
.pv-analysis-section h3 {
    margin: 0 0 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--pv-ink-muted);
}
.pv-analysis-section label {
    font-size: 12.5px;
    color: var(--pv-ink);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.pv-analysis-section input[type="number"],
.pv-analysis-section select {
    background: var(--pv-surface);
    color: var(--pv-ink);
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 12.5px;
    width: 88px;
}
.pv-analysis-section select { width: 100%; }
.pv-analysis-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.pv-analysis-range label { flex-direction: column; align-items: flex-start; }
.pv-analysis-range input { width: 64px; }
.pv-analysis-stack { display: flex; flex-direction: column; align-items: stretch; margin-bottom: 8px; gap: 3px; }
.pv-analysis-checklist,
.pv-analysis-rates {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--pv-border);
    border-radius: 6px;
    padding: 8px;
    background: var(--pv-surface-2);
}
.pv-analysis-rates label { justify-content: space-between; }
.pv-analysis-rates input { width: 72px; }
.pv-analysis-advanced summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--pv-ink-secondary);
}
.pv-analysis-main {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.pv-analysis-plot {
    border: 1px solid var(--pv-border);
    border-radius: 8px;
    background: var(--pv-viz-surface);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}
.pv-analysis-plot svg { display: block; }
.pv-analysis-placeholder { color: var(--pv-ink-muted); font-size: 13px; }
.pv-analysis-error { color: var(--pv-danger); font-size: 13px; margin: 0; }
.pv-analysis-results { overflow-x: auto; }
.pv-analysis-table {
    border-collapse: collapse;
    font-size: 12.5px;
    width: 100%;
}
.pv-analysis-table th,
.pv-analysis-table td {
    border-bottom: 1px solid var(--pv-border);
    padding: 5px 10px;
    text-align: left;
    color: var(--pv-ink);
}
.pv-analysis-table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--pv-ink-muted);
}
.pv-analysis-table td.pv-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.pv-analysis-actions { margin-top: 12px; }
/* Small viewports. Height is part of the test because a phone in landscape is
   844x390 — wider than the width breakpoint, but with under 200px per pane.
   _isNarrowViewport() in petri-view.js matches this query exactly. */
@media (max-width: 760px), (max-height: 520px) {
    .pv-analysis-body { flex-direction: column; }
    .pv-analysis-controls { width: auto; }

    /* The JSON pane starts collapsed to its handle on a phone. The canvas grows
       from zero into the slack (see _defaultCanvasFlex) and the run bar takes
       what it needs, so the pane must not compete for height.

       The collapse is explicit rather than intrinsic: once Ace mounts, the pane's
       natural height is ~180px, so `flex: 0 0 auto` alone would still eat more
       than half a landscape phone. Collapsed is height 0; .pv-json-open (set by
       _toggleEditorPane) is the only way it takes space. */
    .pv-root .pv-json-editor {
        min-height: 0;
        flex: 0 0 auto;
        height: 0;
        padding: 0 8px;
        overflow: hidden;
    }
    .pv-root.pv-json-open .pv-json-editor {
        height: auto;
        flex: 0 0 55%;
        padding: 8px;
        overflow: auto;
    }
    .pv-canvas-container { min-height: 0; }

    /* The scale meter is gone on phones, not merely shrunk. It is a desktop
       affordance: pinch and double-tap already cover zoom, the run bar's ⛶ button
       covers "show me everything", and parked at right:6px/top:50% it sat squarely
       on top of the diagram it was reporting on. */
    .pv-scale-meter { display: none; }

    /* The mode pill is replaced by the docked run bar (_createMenu branches on
       _isNarrowViewport). Belt-and-braces in case one is left over from a resize. */
    .pv-mode-menu { display: none; }

    /* Keep the handle visually slim but give it a real touch target, and make
       the grip wide enough to read as draggable. */
    .pv-layout-divider { flex: 0 0 14px; }
    .pv-layout-divider::before { width: 56px; height: 4px; }
    .pv-root:not(.pv-layout-horizontal) .pv-layout-divider::after {
        content: '';
        position: absolute;
        left: 0;
        right: 0;
        top: -10px;
        bottom: -10px;
    }

    /* 44px is the minimum comfortable touch target. */
    .pv-editor-toolbar-btn,
    .pv-menu-btn,
    .pv-menu-header-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Keep the app chrome clear of the notch and the rounded corners. */
    .pv-hamburger-btn { left: 10px; left: calc(10px + env(safe-area-inset-left, 0px)); }
    .pv-top-right-btn { right: 10px; right: calc(10px + env(safe-area-inset-right, 0px)); }
}

/* Landscape phone (844x390). The stacked layout is still right — the diagram
   wants the full width — but 390px of height leaves no room to spend on chrome,
   so the bar goes on a diet and the fireable sheet gets a shallower cap.
   Gated on a coarse pointer so a short desktop window is unaffected. */
@media (max-height: 520px) and (orientation: landscape) and (pointer: coarse) {
    .pv-run-bar { padding: 4px 8px; padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 0px)); }
    .pv-run-btn { min-height: 40px; }
    .pv-fire-sheet { max-height: min(60vh, 220px); }

    /* The wordmark and its fixed-position title band cost ~14% of the height
       here for no information; the drawer already links home. */
    .fixed-title { display: none; }
}

/* Modal dialogs become bottom sheets on a phone: a centred box sized for a
   desktop viewport overflows a 390x844 screen, and its content is then
   unreachable because the overlay itself does not scroll. dvh (not svh) here so
   a software keyboard raised by a focused field does not push it off-screen. */
@media (max-width: 760px), (max-height: 520px) {
    .pv-modal-overlay,
    .pv-layout-overlay,
    .pv-diagrams-overlay,
    .pv-edit-diagram-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .pv-modal-overlay > *,
    .pv-layout-overlay > *,
    .pv-diagrams-overlay > *,
    .pv-edit-diagram-overlay > * {
        width: 100%;
        max-width: none;
        max-height: 88dvh;
        overflow-y: auto;
        touch-action: pan-y;
        border-radius: 16px 16px 0 0;
        padding-bottom: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    }

    /* The analysis workbench renders its plot at 0px on a phone: the controls
       column keeps its full intrinsic height while the plot's min-height never
       gets a chance to apply. Give the plot a floor and let the dialog scroll.

       .pv-analysis-body must also stop being height-constrained here. Stacked,
       its two children are taller than the `flex: 1` box it gets, and since it
       does not clip they overflowed it and painted straight through the action
       row below. On a phone the sheet is the scroller; the body sizes to content. */
    .pv-analysis-body {
        flex: 0 0 auto;
        min-height: 0;
    }
    .pv-analysis-main {
        min-height: min(45vh, 260px);
        overflow: visible;
    }
    .pv-analysis-controls {
        flex: 0 0 auto;
        max-height: none;
        overflow: visible;
    }
}

/* ============================================================
   Phone run bar and fireable sheet
   Built by _createRunBar()/_createFireSheet() in petri-view.js, which only
   run when _isNarrowViewport() is true — so nothing here can reach desktop.
   The bar is a flex child of .pv-root rather than an absolutely-positioned
   child of the canvas pane, which is why it stays docked to the bottom edge
   instead of floating over the diagram once the JSON pane opens.
   ============================================================ */
.pv-run-bar {
    display: none;
    position: relative; /* containing block for the fireable sheet */
    flex-direction: column;
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
    background: var(--pv-surface);
    border-top: 1px solid var(--pv-border);
    border-radius: 0;
    padding: 6px 8px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
    z-index: 1200;
}

.pv-run-main {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pv-run-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    font-size: 16px;
    line-height: 1;
    color: var(--pv-ink);
    background: var(--pv-surface-2);
    border: 1px solid var(--pv-border);
    border-radius: 10px;
    cursor: pointer;
}

.pv-run-btn:active { background: var(--pv-surface-3); }

/* The fireable count is the bar's primary affordance, so it gets the accent
   and takes the slack width. */
.pv-run-fire {
    flex: 1 1 auto;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    background: var(--pv-accent);
    border-color: var(--pv-accent-strong);
    color: var(--pv-accent-ink);
}

/* Nothing can fire: stop advertising a tap that leads to an empty list. */
.pv-run-fire.pv-run-dead {
    background: var(--pv-surface-2);
    border-color: var(--pv-border);
    color: var(--pv-ink-muted);
}

.pv-run-bar.pv-fire-open .pv-run-fire { background: var(--pv-accent-strong); }

.pv-run-step {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--pv-ink-secondary);
    white-space: nowrap;
    padding: 0 2px;
}

/* Edit tools stay one tap away, but off the presenting surface by default. */
.pv-run-tools { display: none; gap: 4px; }
.pv-run-bar.pv-run-editing .pv-run-tools { display: flex; }
.pv-run-tools .pv-tool {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
}

.pv-fire-sheet {
    display: none;
    /* Anchored above the bar rather than stacked in the root's flex column:
       opening it must not resize the canvas or move the divider split. */
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    box-sizing: border-box;
    max-height: min(45vh, 320px);
    box-shadow: 0 -6px 18px var(--pv-shadow-sm);
    overflow-y: auto;
    /* Every ancestor sets touch-action: none for the canvas gestures, so the
       sheet has to re-enable vertical panning or it cannot be scrolled. */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    background: var(--pv-surface);
    border-top: 1px solid var(--pv-border);
    z-index: 1200;
}

.pv-fire-row {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--pv-border);
}

.pv-fire-name {
    flex: 1 1 auto;
    min-height: 44px;
    text-align: left;
    padding: 0 12px;
    font-size: 15px;
    color: var(--pv-ink);
    background: none;
    border: 0;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pv-fire-name:active { background: var(--pv-surface-3); }

.pv-fire-locate {
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
    font-size: 16px;
    color: var(--pv-ink-secondary);
    background: none;
    border: 0;
    border-left: 1px solid var(--pv-border);
    cursor: pointer;
}

.pv-fire-empty {
    padding: 14px 12px;
    font-size: 13px;
    color: var(--pv-ink-secondary);
}

@media (max-width: 760px), (max-height: 520px) {
    .pv-run-bar { display: flex; }
    .pv-fire-sheet:not([hidden]) { display: block; }

    /* .pv-root is a flex column and the bar is appended before the JSON editor
       exists. Order pins it to the bottom regardless of DOM order, so the editor
       cannot end up underneath it. */
    .pv-root > .pv-run-bar { order: 99; }

    /* _removeJsonEditor() writes an inline height:100%/min-height:100% here,
       which would deny the bar any room. */
    .pv-root > .pv-canvas-container {
        height: auto;
        min-height: 0;
    }
}

/* ============================================================
   Label legibility at fit scale (touch devices only)
   _applyViewTransform() sets --pv-inv-scale and toggles pv-lod-min/pv-lod-mid
   on .pv-root. Fitting a 30-node net to a 390px phone lands around 0.22x, where
   every label is drawn at ~2.6 CSS px and adjacent ones overlap into an
   unreadable smear. Dropping labels by importance is what makes a fitted
   diagram read as topology rather than noise.

   Scoped to (pointer: coarse) so a mouse user never loses a label; desktop also
   sits at scale 1, above every threshold, so the classes are absent there anyway.
   ============================================================ */
@media (pointer: coarse) {
    /* An unbreakable id like O00_O11_O22 is far wider than the 80px node box and
       runs straight through its neighbours. */
    .pv-node .pv-label {
        max-width: 92px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Mid zoom: keep places (which carry the marking) and whatever can fire. */
    .pv-root.pv-lod-mid .pv-transition:not(.pv-active) .pv-label { display: none; }

    /* Far out: labels are sub-pixel. Keep only the two things a presenter is
       pointing at — where the tokens are, and what can fire next. */
    .pv-root.pv-lod-min .pv-label { display: none; }
    .pv-root.pv-lod-min .pv-place[data-marked] .pv-label,
    .pv-root.pv-lod-min .pv-transition.pv-active .pv-label { display: block; }
}

/* ============================================================
   Dialog typography
   Every dialog is appended to <body>, not into .pv-root, so none of them
   inherited the app typeface — all eleven overlays rendered in the browser's
   default serif, next to a sans-serif app. Form controls made it worse: they
   do not inherit font at all, so a single dialog showed Times (container),
   Arial 18px (buttons) and Arial 12.5px (inputs) at once.

   The control rule uses :where() so it contributes ZERO specificity — the
   deliberate monospace fields (.pv-input-mono, .pv-textarea, .pv-editor-textarea,
   .pv-share-textarea) still win without needing !important.
   ============================================================ */
.pv-modal-overlay,
.pv-layout-overlay,
.pv-diagrams-overlay,
.pv-edit-diagram-overlay,
.pv-hamburger-overlay,
.pv-toast {
    font-family: var(--pv-font);
}

:where(.pv-modal-overlay, .pv-layout-overlay, .pv-diagrams-overlay,
       .pv-edit-diagram-overlay, .pv-hamburger-overlay)
:where(button, input, select, textarea, label, h1, h2, h3, h4, p, li, td, th) {
    font-family: inherit;
}

@media (max-width: 760px), (max-height: 520px) {
    /* iOS Safari zooms the whole page when a control smaller than 16px takes
       focus, and leaves it zoomed. The analysis inputs were 12.5px, so tapping
       a rate field threw the layout every time. */
    .pv-modal-overlay input,
    .pv-modal-overlay select,
    .pv-modal-overlay textarea,
    .pv-modal-overlay .pv-analysis-section input[type="number"],
    .pv-modal-overlay .pv-analysis-section input[type="text"],
    .pv-modal-overlay .pv-analysis-section select {
        font-size: 16px;
    }

    /* Action rows are authored right-aligned for a wide dialog; at 390px the
       five analysis buttons overflowed the sheet and clipped off both edges. */
    .pv-btn-container {
        flex-wrap: wrap;
        justify-content: stretch;
        gap: 8px;
    }
    .pv-btn-container > * {
        flex: 1 1 auto;
        min-width: 44%;
        min-height: 44px;
    }

    /* Four tabs do not fit on one line at 390px; wrapping them to two rows
       staggered the underline. Scroll the row instead and keep it one line. */
    .pv-analysis-tabs {
        /* `flex: 0 0 auto` is load-bearing. Setting overflow to anything but
           visible makes this item's automatic minimum size resolve to 0, so the
           column-flex dialog was free to squash the whole tab row to its 1px
           bottom border — the tabs vanished while their buttons still measured
           22px each. */
        flex: 0 0 auto;
        flex-wrap: nowrap;
        overflow-x: auto;
        touch-action: pan-x;
        scrollbar-width: none;
    }
    .pv-analysis-tabs::-webkit-scrollbar { display: none; }
    .pv-analysis-tab {
        flex: 0 0 auto;
        white-space: nowrap;
        padding: 10px;
    }

    /* Reclaim horizontal room: the desktop dialog is padded for a 1100px box. */
    .pv-analysis-dialog { padding: 0 12px 12px; }
    .pv-dialog-header { padding: 14px 16px; }

    /* Give label rows a real touch target. Deliberately NOT display:flex — the
       base rule is inline-flex so the label shrink-wraps its control; making it
       block-level let a width:100% <select> claim the whole line and squeezed the
       caption ("x axis") into a centred sliver above it. */
    .pv-analysis-section label {
        min-height: 32px;
    }
    /* An unstyled <sub> inherits the control's font size; keep it subscript-sized
       so "t_end" reads as one symbol rather than two words. */
    .pv-analysis-section label sub {
        font-size: 10px;
    }
}

/* Version footer at the bottom of the hamburger menu. Muted and small — it is
   provenance for a bug report, not a menu item. */
.pv-menu-version {
    display: block;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    color: var(--pv-ink-muted);
    text-decoration: none;
    border-top: 1px solid var(--pv-border);
    margin-top: 8px;
}

.pv-menu-version:hover {
    color: var(--pv-ink-secondary);
    text-decoration: underline;
}
