/* ===== Theme palette =====
   Dark is the default; [data-theme="light"] on <html> overrides it.
   All chrome colours reference these variables so the light/dark
   toggle only has to flip this block. */
:root {
    --canvas: #0b0d11;
    --bg: #12151b;
    --bg-elev: #171a21;
    --bg-elev2: #1e222a;
    --bg-hover: #232833;
    --badge-bg: #252a35;
    --control-bg: #1c2028;
    --control-hover: #262b36;
    --border: #252a33;
    --border-strong: #343a46;
    --text: #d5d9e0;
    --text-strong: #eef0f4;
    --text-muted: #8a91a0;
    --text-faint: #6b7280;
    --text-hi: #ffffff;
    --accent: #4c6ef5;
    --accent-hover: #5c7cfa;
    --accent-active: #4263eb;
    --accent-soft: rgba(76, 110, 245, 0.16);
    --on-accent: #ffffff;
    --teal: #4fd1b5;
    --green: #74d68a;
    --red: #f7837a;
    --yellow: #e5d38f;
    --orange: #f5a524;
    --syn-comment: #6a9955;
    --syn-keyword: #7aa7ff;
    --syn-string: #ce9178;
    --syn-number: #b5cea8;
    --syn-function: #dcdcaa;
    --panel-translucent: rgba(23, 26, 33, 0.82);
    --sel: rgba(76, 110, 245, 0.3);
    --scrim: rgba(5, 6, 9, 0.6);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
    /* red-tinted surfaces used by the use-after-free panel */
    --red-bg: #2a1719;
    --red-bg-hover: #361c1f;
    --red-border: #5c2429;
    --red-bright: #ff6b6b;
    --red-text: #e0a8a8;

    --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --gutter: 8px;
}

:root[data-theme="light"] {
    --canvas: #eceef3;
    --bg: #ffffff;
    --bg-elev: #f8f9fb;
    --bg-elev2: #f0f2f6;
    --bg-hover: #eaedf2;
    --badge-bg: #e7eaf0;
    --control-bg: #ffffff;
    --control-hover: #f0f2f6;
    --border: #e2e5eb;
    --border-strong: #cdd2da;
    --text: #2a2f3a;
    --text-strong: #111827;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;
    --text-hi: #000000;
    --accent: #3b5bdb;
    --accent-hover: #364fc7;
    --accent-active: #2f44ad;
    --accent-soft: rgba(59, 91, 219, 0.1);
    --on-accent: #ffffff;
    --teal: #0f7f6e;
    --green: #2f8a3e;
    --red: #c0392b;
    --yellow: #8a6d00;
    --orange: #b06a00;
    --syn-comment: #3f8a3f;
    --syn-keyword: #2745c2;
    --syn-string: #a31515;
    --syn-number: #098658;
    --syn-function: #795e26;
    --panel-translucent: rgba(255, 255, 255, 0.85);
    --sel: rgba(59, 91, 219, 0.18);
    --scrim: rgba(17, 24, 39, 0.35);
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
    --shadow-md: 0 6px 20px rgba(17, 24, 39, 0.1);
    --shadow-lg: 0 18px 50px rgba(17, 24, 39, 0.2);
    --red-bg: #fdf0f0;
    --red-bg-hover: #f9e1e1;
    --red-border: #eab4b4;
    --red-bright: #c0392b;
    --red-text: #8a4040;
}

/* ===== Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: var(--font-sans);
    font-size: 14px;
    background: var(--canvas);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'cv11', 'ss01';
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.container { display: flex; flex-direction: column; height: 100vh; }

/* ===== Buttons and form controls ===== */
.btn,
.btn-primary,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 34px;
    padding: 0 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-strong);
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-active); }

.btn-secondary {
    background: var(--control-bg);
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) { background: var(--control-hover); }

.btn-ghost { color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-strong); }
.btn-icon { width: 34px; padding: 0; }
.btn-sm { height: 28px; padding: 0 0.6rem; font-size: 12.5px; }
.btn-xs {
    height: 22px;
    padding: 0 0.5rem;
    font-size: 12px;
    background: var(--control-bg);
    border-color: var(--border-strong);
}
.btn-xs:hover:not(:disabled) { background: var(--control-hover); }
/* An icon-only button that stays down while its filter is on. */
.btn-toggle { width: 22px; padding: 0; margin-left: 0.4rem; vertical-align: middle; }
.btn-toggle .icon { width: 12px; height: 12px; }
.btn-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-toggle[aria-pressed="true"]:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost.btn-xs { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost.btn-xs:hover { background: var(--bg-hover); color: var(--text-strong); }

.chip {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 0.5rem;
    border-radius: 999px;
    background: var(--badge-bg);
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 500;
}
.chip:empty { display: none; }

.select,
.input {
    height: 30px;
    padding: 0 0.6rem;
    background: var(--control-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.select {
    appearance: none;
    padding-right: 1.9rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a91a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 14px;
    text-overflow: ellipsis;
}
.select option, .select optgroup { background: var(--bg-elev); color: var(--text); }
.select:hover, .input:hover { border-color: var(--text-faint); }
.select:focus, .input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ===== Top bar ===== */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 56px;
    padding: 0 0.75rem 0 1rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 500;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding-right: 1rem;
    margin-right: 0.25rem;
    border-right: 1px solid var(--border);
    height: 32px;
    cursor: default;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #5c7cfa 0%, #3b5bdb 55%, #7048e8 100%);
    box-shadow: 0 2px 8px rgba(76, 110, 245, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.brand-mark svg {
    width: 20px;
    height: 20px;
    fill: #ffffff;
    stroke: #ffffff;
    stroke-width: 1.6;
    stroke-linecap: round;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text h1 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; color: var(--text-strong); }
.brand-tagline { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }

.topbar-section { display: flex; align-items: center; gap: 0.35rem; }
.topbar-run { gap: 0.6rem; }
.topbar-end { margin-left: auto; }
.topbar-divider { width: 1px; height: 20px; background: var(--border-strong); margin: 0 0.35rem; }

/* Theme toggle: show the icon for the theme you would switch to */
.theme-toggle .icon-sun { display: none; }
:root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
:root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }

/* Split (run) button */
.split-button { position: relative; display: inline-flex; }
.split-button-action {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    min-width: 116px;
    padding-left: 0.8rem;
    justify-content: flex-start;
    font-weight: 600;
}
/* The play glyph lives in CSS: the label is rewritten when the action changes */
.split-button-action::before {
    content: '';
    width: 9px;
    height: 10px;
    background: currentColor;
    clip-path: polygon(0 0, 100% 50%, 0 100%);
    border-radius: 1px;
    flex-shrink: 0;
}
.split-button-toggle {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    border-left-color: rgba(255, 255, 255, 0.22);
    padding: 0 0.45rem;
}
.split-button-toggle .icon { transition: transform 0.15s; }
.split-button.active .split-button-toggle .icon { transform: rotate(180deg); }

.dropdown-content {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 290px;
    padding: 0.3rem;
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}
.split-button.active .dropdown-content { display: block; animation: pop-in 0.12s ease-out; }
.dropdown-content button {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    padding: 0.5rem 0.65rem 0.5rem 1.7rem;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    text-align: left;
    cursor: pointer;
    position: relative;
    color: var(--text);
    transition: background 0.12s;
}
.dropdown-content button:hover { background: var(--bg-hover); }
.dropdown-content button.selected::before {
    content: '';
    position: absolute;
    left: 0.65rem;
    top: 0.72rem;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}
.menu-label { font-size: 13px; font-weight: 600; color: var(--text-strong); }
.menu-hint { font-size: 12px; color: var(--text-muted); }

@keyframes pop-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Run status */
.status {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    height: 26px;
    padding: 0 0.7rem 0 0.6rem;
    border-radius: 999px;
    background: var(--badge-bg);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
.status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-faint);
}
.status.running { color: var(--accent-hover); background: var(--accent-soft); }
.status.running::before { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.status.success { color: var(--teal); }
.status.success::before { background: var(--teal); }
.status.error { color: var(--red); }
.status.error::before { background: var(--red); }
:root[data-theme="light"] .status.running { color: var(--accent); }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.8); }
}

/* ===== Panels ===== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: var(--gutter) var(--gutter) 0;
    min-height: 0;
}
.panel,
.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
    min-width: 200px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.panel:first-child { flex: 1 1 24%; }
.panel:nth-child(3) { flex: 1 1 56%; }
.sidebar { flex: 1 1 20%; }

/* The gutters between panels are the resizers */
.resizer {
    width: var(--gutter);
    flex-shrink: 0;
    cursor: col-resize;
    position: relative;
    background: transparent;
}
.resizer::after {
    content: '';
    position: absolute;
    top: 30%;
    bottom: 30%;
    left: 50%;
    width: 2px;
    margin-left: -1px;
    border-radius: 2px;
    background: transparent;
    transition: background 0.15s, top 0.15s, bottom 0.15s;
}
.resizer:hover::after { background: var(--accent); top: 0; bottom: 0; }
.resizer:active::after { background: var(--accent-hover); top: 0; bottom: 0; }

.panel-header,
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem 0.75rem;
    min-height: 46px;
    padding: 0.45rem 0.6rem 0.45rem 0.9rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
}
.panel-title { display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.panel-header h2,
.sidebar-header h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-strong);
    white-space: nowrap;
}
.help-link {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    color: var(--text-muted);
    transition: color 0.15s, background 0.15s;
}
.help-link .icon { width: 15px; height: 15px; }
.help-link:hover { color: var(--accent-hover); background: var(--accent-soft); }

.panel-header-controls {
    display: flex;
    flex: 1 1 200px;
    justify-content: flex-end;
    gap: 0.35rem;
    align-items: center;
    min-width: 0;
}
.panel-header-controls .select { flex: 1 1 auto; min-width: 0; max-width: 320px; }

/* File inputs are hidden behind a button-styled label */
.file-input-wrapper { position: relative; display: inline-block; }
.file-input-wrapper input[type="file"] { position: absolute; left: -9999px; opacity: 0; }
.file-input-label { cursor: pointer; }

/* ===== Editor ===== */
.editor-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--bg);
}

.editor-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Highlighted code overlay — must scroll in lock-step with the textarea */
#litmus-highlight {
    position: absolute;
    top: 0;
    left: 0;
    /* wider than the panel so long lines don't wrap */
    min-width: 100%;
    width: max-content;
    pointer-events: none;
    margin: 0 !important;
    padding: 1rem 1rem 1rem 5.5em !important;
    background: transparent !important;
    overflow: visible;
    /* no wrapping — lines must stay on one row so Prism counts them correctly */
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
    font-family: var(--font-mono) !important;
    font-size: 0.9rem !important;
    line-height: 1.6 !important;
    border: none !important;
}

#litmus-highlight code {
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
}

/* Textarea for input; it must share the overlay's font metrics exactly */
#litmus-input {
    position: absolute;
    top: 0;
    left: 0;
    /* must be at least as wide as the content so the scrollbar appears */
    min-width: 100%;
    width: 100%;
    height: 100%;
    margin: 0 !important;
    padding: 1rem 1rem 1rem 5.5em !important;
    background: transparent !important;
    font-family: var(--font-mono) !important;
    font-size: 0.9rem !important;
    line-height: 1.6 !important;
    outline: none !important;
    border: none !important;
    resize: none;
    color: transparent;
    caret-color: var(--text-strong);
    tab-size: 4;
    z-index: 1;
    /* horizontal + vertical scroll; no wrapping */
    overflow: auto;
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
}

#litmus-input:focus { outline: none; }
#litmus-input::selection { background: var(--sel); }
#litmus-input::placeholder { color: var(--text-faint); }

/* Override PrismJS colours */
pre[class*="language-"] {
    background: var(--bg) !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: var(--font-mono) !important;
    font-size: 0.9rem !important;
    line-height: 1.6 !important;
    white-space: pre !important;
    word-wrap: normal !important;
    overflow-wrap: normal !important;
    tab-size: 4 !important;
}

code[class*="language-"] {
    background: transparent !important;
    color: var(--text) !important;
    font-family: var(--font-mono) !important;
    font-size: 0.9rem !important;
    line-height: 1.6 !important;
    white-space: pre !important;
    word-wrap: normal !important;
    overflow-wrap: normal !important;
    tab-size: 4 !important;
    text-shadow: none !important;
}

.token.comment { color: var(--syn-comment); font-style: italic; }
.token.keyword { color: var(--syn-keyword); }
.token.string { color: var(--syn-string); }
.token.number { color: var(--syn-number); }
.token.operator { color: var(--text); background: none !important; }
.token.punctuation { color: var(--text-muted); }
.token.function { color: var(--syn-function); }

/* Line numbers */
pre.line-numbers {
    position: relative;
    /* Let Prism control padding-left; its plugin sets it to match the gutter width */
    counter-reset: linenumber;
}

pre.line-numbers > code {
    position: relative;
    white-space: inherit;
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    font-size: 0.9rem;
    /* Prism plugin sets left automatically; keep width/style only */
    width: 3em;
    letter-spacing: 0;
    border-right: 1px solid var(--border);
    user-select: none;
    padding-right: 0.5rem;
    padding-left: 0.5rem;
    /* Ensure rows fill the full height of the pre */
    bottom: 0;
    overflow: hidden;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
    line-height: 1.6;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    color: var(--text-faint);
    display: block;
    text-align: right;
}

/* Source code highlight overlay */
#source-highlight-overlay { pointer-events: none; }

.highlight-marker {
    border-radius: 3px;
    transition: opacity 0.15s ease-in-out;
    animation: highlightPulse 0.3s ease-in-out;
}

@keyframes highlightPulse {
    0% { opacity: 0; transform: scale(0.98); }
    50% { opacity: 1; transform: scale(1.02); }
    100% { opacity: 1; transform: scale(1); }
}

/* ===== Graph panel ===== */
.carousel-container { flex: 1; position: relative; display: none; min-height: 0; }
.carousel-container.active { display: flex; flex-direction: column; }
#cy {
    flex: 1;
    background-color: var(--bg);
    background-image: radial-gradient(var(--border) 1px, transparent 1px);
    background-size: 22px 22px;
}

/* Floating overlays share one surface. The graph toolbar goes without the
   blur: a backdrop filter makes an element the containing block of its
   position: fixed descendants, which would pin the toolbar's menus to it. */
.carousel-btn,
.carousel-indicator,
.execution-info,
.graph-controls,
.graph-stats {
    background: var(--panel-translucent);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}
.carousel-btn,
.carousel-indicator,
.execution-info,
.graph-stats {
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}
.graph-controls { background: var(--bg-elev); }

.carousel-controls {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 200;
    transform: translateY(-50%);
    padding: 0 12px;
}
.carousel-btn {
    pointer-events: all;
    color: var(--text-strong);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.15s, transform 0.15s, opacity 0.15s;
}
.carousel-btn .icon { width: 18px; height: 18px; }
.carousel-btn:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--on-accent); transform: scale(1.06); }
.carousel-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.carousel-indicator {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 999px;
    padding: 0.35rem 0.9rem;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-strong);
    z-index: 100;
    white-space: nowrap;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background-color: var(--bg);
    background-image: radial-gradient(var(--border) 1px, transparent 1px);
    background-size: 22px 22px;
}
.empty-state-inner { text-align: center; max-width: 320px; padding: 2rem; }
.empty-state-inner p { font-size: 13px; line-height: 1.55; }
.empty-state-inner strong { color: var(--text-strong); }
.empty-state-icon {
    width: 44px;
    height: 44px;
    padding: 10px;
    margin-bottom: 0.9rem;
    border-radius: 12px;
    background: var(--accent-soft);
    fill: var(--accent);
    stroke: var(--accent);
    stroke-width: 1.6;
    stroke-linecap: round;
    box-sizing: content-box;
}
.empty-state-title { font-size: 15px !important; font-weight: 600; color: var(--text-strong); margin-bottom: 0.35rem; }

.graph-controls {
    position: absolute;
    bottom: 12px;
    left: 12px;
    display: none;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius);
    z-index: 100;
}
.graph-controls.active { display: flex; }
.layout-dropdown, .export-dropdown, .relations-dropdown { position: relative; display: inline-block; }
.graph-controls button {
    height: 28px;
    padding: 0 0.7rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.graph-controls button:hover { background: var(--bg-hover); color: var(--text-strong); }
.layout-dropdown.open .layout-btn,
.export-dropdown.open .export-btn,
.relations-dropdown.open .relations-btn { background: var(--bg-hover); color: var(--text-strong); }
.toolbar-divider { width: 1px; height: 16px; background: var(--border-strong); margin: 0 3px; }

/* Menus above the graph toolbar; the script positions them */
.layout-dropdown-content,
.export-dropdown-content,
.relations-dropdown-content {
    display: none;
    position: fixed;
    padding: 0.3rem;
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    min-width: 160px;
}
.relations-dropdown-content { min-width: 230px; }
.layout-dropdown.open .layout-dropdown-content,
.export-dropdown.open .export-dropdown-content,
.relations-dropdown.open .relations-dropdown-content { display: block; }
.layout-option, .export-option {
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}
.layout-option:hover, .export-option:hover { background: var(--bg-hover); color: var(--text-strong); }
.layout-option.active { color: var(--accent-hover); font-weight: 600; }
:root[data-theme="light"] .layout-option.active { color: var(--accent); }

.relations-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.35rem 0.4rem 0.5rem 0.55rem;
    margin-bottom: 0.2rem;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.relations-header-actions { display: flex; gap: 4px; }
.relations-header-actions button {
    background: var(--control-bg);
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
    transition: background 0.15s, color 0.15s;
}
.relations-header-actions button:hover { background: var(--control-hover); color: var(--text-strong); }

#relations-checkboxes { padding: 0.1rem 0; }
.relation-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0.35rem 0.55rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.12s;
    user-select: none;
}
.relation-checkbox-item:hover { background: var(--bg-hover); }
.relation-checkbox-item input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}
.relation-checkbox-item .relation-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.relation-checkbox-item label {
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    flex: 1;
}

.graph-stats {
    position: absolute;
    bottom: 12px;
    right: 12px;
    border-radius: var(--radius);
    padding: 0.65rem 0.85rem;
    font-size: 12.5px;
    display: none;
    flex-direction: column;
    gap: 0.3rem;
    z-index: 100;
    min-width: 170px;
}
.graph-stats.active { display: flex; }
.graph-stats div { display: flex; justify-content: space-between; gap: 1rem; }
.graph-stats strong { color: var(--text-muted); font-weight: 500; }
.graph-stats span { color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; }
.justification-set-details { margin-top: 0.3rem; padding-top: 0.4rem; border-top: 1px solid var(--border); }
.justification-set-details summary { cursor: pointer; color: var(--text-muted); }
.justification-set-details summary strong { color: var(--text); }
#justification-set {
    margin-top: 0.4rem;
    max-height: 16rem;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 11.5px;
}
#justification-set span { color: inherit; font-weight: inherit; }

/* The two justification panels opt out of the `div { display: flex }` rules
   above.

   Those rules exist to lay a stat out as "label ... value" on one row, and they
   apply to every div in the panel -- which caught the justification list, laid
   its entries out side by side, and, because an author `display` beats the
   `hidden` attribute's user-agent `display: none`, left the per-execution
   overlay permanently visible with a Show/Hide button that changed only its
   own label. */
#justification-set,
#justification-set div,
#justifications-overlay {
    display: block;
}

#justifications-overlay[hidden] {
    display: none;
}

/* One justification per line, its derivation indented under it. */
#justification-set div,
#justifications-overlay {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#justifications-overlay {
    margin-top: 0.4rem;
    max-height: 14rem;
    overflow: auto;
    padding: 0.5rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text);
}

.execution-info {
    position: absolute;
    top: 56px;
    left: 12px;
    /* clear of the carousel indicator at the top centre */
    max-width: max(280px, calc(50% - 100px));
    border-radius: var(--radius);
    padding: 0.65rem 0.85rem;
    font-size: 12.5px;
    display: none;
    flex-direction: column;
    gap: 0.3rem;
    z-index: 100;
}
.execution-info.active { display: flex; }
.execution-info div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}
.execution-info > div + div { margin-top: 0.3rem; }
.execution-info div[hidden] { display: none; }
.execution-info strong { color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.execution-info span { color: var(--text-strong); font-family: var(--font-mono); font-size: 12px; text-align: right; }
.execution-info #justifications-btn { flex-shrink: 0; }
/* The justification row wraps so its list can open under it */
.execution-info div:has(> #justifications-overlay) { flex-wrap: wrap; }
.execution-info div:has(> #justifications-overlay) > #justifications-overlay { flex-basis: 100%; }

/* ===== Sidebar ===== */
.sidebar-header { min-height: 46px; }

.accordion {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.accordion-item {
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.accordion-item:last-child { border-bottom: none; }

.accordion-header {
    width: 100%;
    background: var(--bg);
    border: none;
    color: var(--text-strong);
    padding: 0.7rem 0.9rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
}

.accordion-header:hover { background: var(--bg-hover); }
.accordion-header.active { background: var(--bg-elev); }

.accordion-icon {
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.accordion-header.active .accordion-icon { transform: rotate(-180deg); }

.accordion-content {
    flex: 0 0 0;
    overflow: hidden;
    transition: flex 0.25s ease;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

.accordion-content.active {
    flex: 1 1 auto;
    overflow-y: auto;
    border-top: 1px solid var(--border);
}

.accordion-content p {
    padding: 0.9rem;
    color: var(--text-muted);
    font-size: 13px;
}

/* Assertion results */
.assertion-item {
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.assertion-item:hover { background: var(--bg-elev2); }
.assertion-item:last-child { border-bottom: none; }

.assertion-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.4rem;
}

.assertion-type {
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: var(--badge-bg);
}

.assertion-type.witnessed { color: var(--green); }
.assertion-type.contradicted { color: var(--red); }
.assertion-type.confirmed { color: var(--teal); }
.assertion-type.refuted { color: var(--orange); }

.assertion-exec-id {
    font-size: 12px;
    color: var(--text-muted);
}

.assertion-expr {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    padding: 0.45rem 0.55rem;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin: 0.5rem 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.assertion-result {
    font-size: 12.5px;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.assertion-result-icon { font-weight: bold; font-size: 1rem; }
.assertion-result.true { color: var(--green); }
.assertion-result.false { color: var(--red); }

.assertion-memberships {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.assertion-memberships-title {
    font-size: 12px;
    color: var(--text-strong);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.membership-item {
    font-size: 12px;
    padding: 0.4rem 0.5rem;
    background: var(--bg-elev);
    border-radius: var(--radius-sm);
    margin: 0.3rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.membership-relation {
    font-family: var(--font-mono);
    color: var(--teal);
    font-weight: 600;
}

.membership-pair {
    font-family: var(--font-mono);
    color: var(--text);
}

.membership-result { margin-left: auto; font-weight: 600; }
.membership-result.true { color: var(--green); }
.membership-result.false { color: var(--red); }

.assertion-validity {
    padding: 0.75rem 0.9rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.assertion-validity-icon { font-size: 1.1rem; font-weight: bold; }
.assertion-validity.valid { color: var(--green); }
.assertion-validity.invalid { color: var(--red); }

/* Loops; the script also sets their surface inline */
.loop-item {
    padding: 0.75rem;
    margin: 0.5rem 0;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius) !important;
    cursor: pointer;
    transition: background 0.15s;
}

.loop-item:hover { background: var(--bg-elev2); }

.loop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.loop-toggle {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.loop-item.expanded .loop-toggle { transform: rotate(180deg); }

.loop-conditions {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.loop-item.expanded .loop-conditions {
    max-height: 500px;
    overflow-y: auto;
}

.uaf-item { border-radius: var(--radius) !important; }

/* Episodicity conditions */
.episodicity-condition {
    margin: 0.4rem 0;
    padding: 0.4rem 0.5rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.episodicity-condition:hover { background: var(--bg-hover); }

.condition-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.condition-toggle {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.episodicity-condition.expanded .condition-toggle { transform: rotate(180deg); }

.condition-violations {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin-left: 1.5rem;
    margin-top: 0.3rem;
}

.episodicity-condition.expanded .condition-violations {
    max-height: 300px;
    overflow-y: auto;
}

/* ===== Log console ===== */
.console {
    display: flex;
    flex-direction: column;
    height: 156px;
    margin: var(--gutter);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}
.console-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 32px;
    padding: 0 0.35rem 0 0.9rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
#log {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0.9rem;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.55;
}
.log-entry { padding: 0.1rem 0; overflow-wrap: anywhere; }
.log-time { color: var(--text-faint); margin-right: 0.5rem; font-variant-numeric: tabular-nums; }
.log-detail {
    white-space: pre;
    overflow-x: auto;
    margin: 0.25rem 0 0.15rem 0;
    padding: 0.35rem 0.55rem;
    background: var(--bg-elev);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    overflow-wrap: normal;
}
.error { color: var(--red); }
.success { color: var(--green); }
.info { color: var(--teal); }

/* ===== Settings modal ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--scrim);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modal-in 0.16s ease-out;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to { opacity: 1; transform: none; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1rem 1rem 1.4rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-strong);
}

.modal-close {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
}

.modal-close:hover { color: var(--text-strong); background: var(--bg-hover); }

.modal-body {
    padding: 0.4rem 1.4rem 1.2rem;
    overflow-y: auto;
}

.setting-group { padding-top: 1rem; }
.setting-group + .setting-group { margin-top: 0.4rem; border-top: 1px solid var(--border); }

.setting-group h3 {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 0.75rem;
}

.setting-item { margin-bottom: 0.7rem; color: var(--text); font-size: 13.5px; }

.setting-item label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    color: var(--text);
    font-size: 13.5px;
}

.setting-item input[type="checkbox"],
.setting-item input[type="radio"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
}

.setting-indent { margin-left: 1.6rem; }
.input-number { width: 76px; }
.setting-item .select { flex: 1; max-width: 280px; }
.setting-options { display: flex; flex-wrap: wrap; gap: 0.3rem 1.25rem; margin: 0.5rem 0 0 1.6rem; }
.setting-options-group { margin: 0.6rem 0 0 1.6rem; font-size: 11px; letter-spacing: 0.02em; text-transform: uppercase; color: var(--text-muted); }
/* A compared model that is already the primary one: there is nothing to
   compare it with, so it is greyed out and cannot be ticked. */
.setting-options label:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
.setting-options input:disabled { cursor: not-allowed; }
.setting-note { margin: 0.5rem 0 0 1.6rem; font-size: 12px; line-height: 1.5; color: var(--text-muted); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.9rem 1.4rem;
    border-top: 1px solid var(--border);
    background: var(--bg-elev2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ===== Narrow windows: icons stand in for labels ===== */
@media (max-width: 1280px) {
    .brand-tagline, #settings-summary { display: none; }
}
@media (max-width: 1020px) {
    .topbar .btn-label { display: none; }
    .topbar .btn-ghost { width: 34px; padding: 0; }
    .brand { padding-right: 0.75rem; }
}

.assertion-verdicts { list-style: none; margin: 0.5rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.assertion-verdicts code { font-size: 12px; }

/* Text for screen readers only, as on an icon-only button. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* The Cancel button shows only while a run goes (W5, #181); .btn would
   otherwise override [hidden]. */
#cancel-btn[hidden] { display: none; }
