:root {
    color-scheme: dark;
    --bg: #06111b;
    --bg-elevated: #0b1c2b;
    --panel: #0e2233;
    --panel-2: #122a3e;
    --border: #1d3a52;
    --border-strong: #2a5070;
    --text: #e3eef6;
    --text-muted: #8ea9bf;
    --accent: #5cc8ff;
    --accent-strong: #2fa9e8;
    --ok: #6fdc8c;
    --warn: #ffd98a;
    --danger: #ff7a7a;
    --winner: #ffd84d;
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: 650;
}

h1:focus {
    outline: none;
}

a {
    color: var(--accent);
}

code {
    font-family: var(--mono);
    font-size: 0.92em;
    background: rgba(92, 200, 255, 0.1);
    padding: 0.05em 0.35em;
    border-radius: 4px;
}

.muted {
    color: var(--text-muted);
    font-weight: 400;
}

/* ---------- Page layout ---------- */

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

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    padding: 10px 18px;
    background: linear-gradient(180deg, #0c2233, #09192a);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand h1 {
    font-size: 18px;
    letter-spacing: 0.02em;
}

.brand-sub {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.run-info {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.run-chip {
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    font-variant-numeric: tabular-nums;
}

.run-chip strong {
    color: var(--text);
    font-weight: 600;
}

.run-chip.state.running {
    color: var(--ok);
    border-color: rgba(111, 220, 140, 0.4);
}

.run-chip.state.paused {
    color: var(--warn);
    border-color: rgba(255, 217, 138, 0.4);
}

.layout {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 440px;
    gap: 16px;
    padding: 16px 18px 24px;
    align-items: start;
}

.stage {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.sidebar {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 92px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
}

/* ---------- Canvas ---------- */

.aquarium-frame {
    width: 100%;
    max-width: calc((100vh - 170px) * 1000 / 600);
    min-width: 480px;
    margin: 0 auto;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
    background: #041421;
}

.aquarium-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 1000 / 600;
}

/* ---------- Controls ---------- */

.controls {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-left: auto;
}

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

.control-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 2px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-weight: 550;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
    background: #18364f;
    border-color: var(--accent);
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn:focus-visible, .chip:focus-visible, .code-button:focus-visible, .decision-summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: #03121d;
    min-width: 120px;
    justify-content: center;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-danger:hover:not(:disabled) {
    border-color: var(--danger);
}

.btn-icon {
    padding: 6px 8px;
}

.chip {
    font: inherit;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 9px;
    cursor: pointer;
}

.chip:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--border-strong);
}

.chip.active {
    color: #03121d;
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 650;
}

.seed-input {
    width: 96px;
    font: inherit;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 6px 8px;
}

.seed-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}

.control-message {
    flex-basis: 100%;
    color: var(--danger);
    font-size: 12px;
    text-align: right;
}

/* ---------- Stats and legend ---------- */

.stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.stat-label {
    font-size: 11px;
    line-height: 1.25;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-height: 2.5em;
}

.stat-value {
    font-size: 20px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.stat-note {
    font-size: 11px;
    color: var(--text-muted);
}

.stat-note.warn {
    color: var(--warn);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 4px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ---------- Panels ---------- */

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.panel-header h2 {
    font-size: 15px;
}

.panel-header .muted {
    font-size: 12px;
}

.toggle {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.tag {
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    padding: 1px 8px;
    white-space: nowrap;
}

.tag-ok {
    color: var(--ok);
    background: rgba(111, 220, 140, 0.12);
}

.tag-rejected {
    color: var(--danger);
    background: rgba(255, 122, 122, 0.14);
}

.tag-dead {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
}

.tag-winner {
    color: #2a2100;
    background: var(--winner);
    margin-left: 6px;
}

.code-button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font: inherit;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--accent);
    background: rgba(92, 200, 255, 0.08);
    border: 1px solid rgba(92, 200, 255, 0.35);
    border-radius: 6px;
    padding: 2px 8px;
    cursor: pointer;
    white-space: nowrap;
}

.code-button:hover {
    background: rgba(92, 200, 255, 0.18);
    border-color: var(--accent);
}

/* ---------- Timeline ---------- */

.timeline-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.timeline-item {
    display: grid;
    grid-template-columns: 44px 80px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 5px 8px;
    border-radius: 6px;
    border-left: 3px solid transparent;
}

.timeline-item + .timeline-item {
    margin-top: 2px;
}

.timeline-item.clickable {
    cursor: pointer;
}

.timeline-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.timeline-item.selected {
    background: rgba(92, 200, 255, 0.1);
}

.timeline-item.kind-birth {
    border-left-color: var(--ok);
}

.timeline-item.kind-death {
    border-left-color: #b8a08a;
}

.timeline-item.kind-rejection {
    border-left-color: var(--danger);
}

.timeline-time {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 12px;
}

.timeline-kind {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.timeline-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-empty {
    color: var(--text-muted);
    padding: 8px;
}

/* ---------- Inspector ---------- */

.inspector-empty {
    text-align: center;
    padding: 28px 12px;
}

.inspector-empty h2 {
    margin: 8px 0 6px;
    font-size: 16px;
}

.inspector-empty p {
    margin: 6px 0;
}

.inspector-header h2 {
    font-size: 17px;
}

.btn-close {
    margin-left: auto;
}

.cohort-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
}

.self-state {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    margin: 0 0 14px;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.self-state > div {
    min-width: 0;
}

.self-state .wide, .self-state .self-energy {
    grid-column: 1 / -1;
}

.self-state dt {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.self-state dd {
    margin: 1px 0 0;
    font-variant-numeric: tabular-nums;
}

.meter {
    display: inline-block;
    vertical-align: middle;
    width: 140px;
    height: 8px;
    background: #06111b;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 8px;
    border: 1px solid var(--border);
}

.meter-fill {
    display: block;
    height: 100%;
    border-radius: 4px;
}

.inspector-note {
    margin: 6px 0 12px;
}

.section-title {
    font-size: 13px;
    margin: 4px 0 8px;
}

.decision-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.decision {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-elevated);
    overflow: hidden;
}

.decision.expanded {
    border-color: var(--border-strong);
}

.decision.rejected {
    border-left: 3px solid var(--danger);
}

.decision.accepted {
    border-left: 3px solid rgba(111, 220, 140, 0.6);
}

.decision-summary {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    font: inherit;
    color: var(--text);
    background: transparent;
    border: 0;
    padding: 7px 10px;
    cursor: pointer;
    text-align: left;
}

.decision-summary:hover {
    background: rgba(255, 255, 255, 0.03);
}

.decision-id {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--accent);
}

.decision-tick {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.decision-action {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pin {
    font-size: 10px;
    color: var(--warn);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.decision-body {
    padding: 4px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.step {
    position: relative;
    padding-left: 30px;
}

.step + .step::before {
    content: "";
    position: absolute;
    left: 10px;
    top: -12px;
    height: 12px;
    border-left: 1px dashed var(--border-strong);
}

.step-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.step-header h4 {
    font-size: 13px;
}

.step-header .muted {
    font-size: 12px;
}

.step-header .code-button {
    margin-left: auto;
}

.step-number {
    position: absolute;
    left: 0;
    top: 0;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    background: var(--panel-2);
    border: 1px solid var(--border-strong);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    display: grid;
    place-items: center;
}

.step p {
    margin: 2px 0;
}

.perception-self {
    color: var(--text-muted);
    font-size: 12.5px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.data-table th {
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding: 3px 6px;
}

.data-table td {
    padding: 3px 6px;
    border-bottom: 1px solid rgba(29, 58, 82, 0.5);
}

.data-table .num {
    text-align: right;
}

.kind-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: 0;
}

.kind-dot.kind-plankton {
    background: #8dffb8;
}

.kind-dot.kind-fish {
    background: #ffb454;
}

.kind-dot.kind-carcass {
    background: #b8a08a;
    border-radius: 1px;
}

.candidates {
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.candidate {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 90px 52px;
    align-items: center;
    gap: 8px;
    padding: 3px 6px;
    border-radius: 6px;
    font-size: 12.5px;
}

.candidate.winner {
    background: rgba(255, 216, 77, 0.1);
    outline: 1px solid rgba(255, 216, 77, 0.45);
}

.candidate-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-bar {
    height: 6px;
    background: #06111b;
    border-radius: 3px;
    overflow: hidden;
}

.score-fill {
    display: block;
    height: 100%;
    background: var(--accent-strong);
    border-radius: 3px;
}

.candidate.winner .score-fill {
    background: var(--winner);
}

.score-value {
    text-align: right;
    font-family: var(--mono);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}

.hint {
    font-size: 11.5px;
    margin-top: 4px !important;
}

.outcome.accepted {
    color: var(--ok);
}

.outcome.rejected {
    color: var(--danger);
}

/* ---------- Control lock ---------- */

.lock-banner {
    flex-basis: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12.5px;
    padding: 5px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
}

.lock-banner .lock-action {
    margin-left: auto;
    padding: 3px 10px;
    font-size: 12px;
    min-width: 0;
}

.lock-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: none;
    background: var(--text-muted);
}

.lock-banner.mine {
    border-color: rgba(111, 220, 140, 0.4);
    background: rgba(111, 220, 140, 0.07);
}

.lock-banner.mine .lock-dot {
    background: var(--ok);
}

.lock-banner.other {
    border-color: rgba(255, 217, 138, 0.4);
    background: rgba(255, 217, 138, 0.06);
}

.lock-banner.other .lock-dot {
    background: var(--warn);
}

.lock-banner.free .lock-dot {
    background: var(--accent);
}

/* ---------- Code panel ---------- */

.code-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(2, 8, 14, 0.62);
    display: flex;
    justify-content: flex-end;
}

.code-panel {
    width: min(920px, 100vw);
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border-strong);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
}

.code-panel-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #0c2233, #09192a);
}

.code-panel-header h2 {
    font-size: 17px;
}

.code-panel-header .btn-close {
    margin-left: auto;
}

.code-panel-kicker {
    display: block;
    font-size: 11px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 2px;
}

.code-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
}

.code-panel-body h3 {
    font-size: 13px;
    margin-bottom: 6px;
}

.code-panel-body p {
    margin: 0;
}

.code-explanation {
    line-height: 1.55;
}

.code-missing {
    color: var(--warn);
}

.run-data {
    border: 1px dashed rgba(255, 217, 138, 0.45);
    background: rgba(255, 217, 138, 0.05);
    border-radius: 10px;
    padding: 12px 14px;
}

.run-data h3 {
    color: var(--warn);
}

.run-data > .muted {
    font-size: 12px;
    margin-bottom: 8px;
}

.run-data dl {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px 14px;
    margin: 8px 0 0;
}

.run-data dl .wide {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 10px;
}

.run-data dt {
    font-size: 11px;
    color: var(--text-muted);
}

.run-data dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

.snippet {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.snippet-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 12px;
}

.snippet-copy {
    margin-left: auto;
}

.source-badge {
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    padding: 2px 9px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.source-badge.real {
    color: #03121d;
    background: var(--ok);
}

.source-badge.simplified {
    color: #2a2100;
    background: var(--warn);
}

.snippet-note {
    font-size: 12px;
    color: var(--warn);
}

.code-block {
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.55;
    background: #050e17;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: thin;
}

.code-block.file-context {
    max-height: 60vh;
    overflow-y: auto;
}

.code-line {
    display: flex;
    min-height: 1.55em;
    white-space: pre;
}

.code-line.in-snippet {
    background: rgba(92, 200, 255, 0.08);
    box-shadow: inset 3px 0 0 var(--accent);
}

.code-line .ln {
    flex: none;
    width: 4.2em;
    padding-right: 1em;
    text-align: right;
    color: #4f6b82;
    user-select: none;
}

.code-line .lc {
    padding-right: 16px;
}

.tk-kw { color: #c792ea; }
.tk-type { color: #7fdbca; }
.tk-method { color: #82aaff; }
.tk-str { color: #ecc48d; }
.tk-comment { color: #6a8aa3; font-style: italic; }
.tk-num { color: #f78c6c; }

.context-toggle {
    align-self: flex-start;
    font-size: 12px;
    padding: 4px 10px;
}

.snippet-footnote {
    font-size: 11.5px;
}

.teaching-qa {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
}

.teaching-qa > div {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}

/* ---------- Deferred decisions ---------- */

.export-link {
    font-size: 12px;
    padding: 3px 10px;
    text-decoration: none;
}

.timeline-item.kind-discard {
    border-left-color: #c9a0ff;
}

.timeline-item.kind-expiry {
    border-left-color: var(--warn);
}

.timeline-item.kind-fallback {
    border-left-color: var(--accent);
}

.timeline-item.kind-failure {
    border-left-color: #ff9f5a;
}

.source-tag {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
}

.source-tag.source-deferred {
    color: var(--accent);
    background: rgba(92, 200, 255, 0.12);
}

.source-tag.source-fallback {
    color: var(--warn);
    background: rgba(255, 217, 138, 0.12);
}

.tag-paused {
    color: var(--warn);
    border: 1px dashed rgba(255, 217, 138, 0.6);
}

.origin {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.origin > div {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 8px;
}

.origin dt {
    font-size: 12px;
    color: var(--text-muted);
}

.origin dd {
    margin: 0;
}

.pending-state dd {
    line-height: 1.5;
}

.waiting-mark {
    display: inline-block;
    min-width: 1.6em;
    text-align: center;
    font-weight: 700;
    color: #06131e;
    background: rgba(240, 248, 255, 0.92);
    border-radius: 999px;
    line-height: 1.2;
}

.metrics .panel-header .code-button {
    margin-left: auto;
}

.mode-tag {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
}

.mode-tag.mode-slowbrain {
    color: var(--accent);
    background: rgba(92, 200, 255, 0.12);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 8px;
}

.metric {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.metric-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-size: 18px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.metric-unit {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
}

.metric-note {
    font-size: 11px;
    color: var(--text-muted);
}

.metric-breakdown {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 8px 16px;
    margin-top: 10px;
}

.metric-breakdown h3 {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0 0 4px;
}

.metric-breakdown ul {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 12.5px;
}

.metric-breakdown li {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.metric-breakdown strong {
    font-variant-numeric: tabular-nums;
}

.setup-grid {
    border: 0;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px 10px;
}

.setup-grid:disabled {
    opacity: 0.55;
}

.setup-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
    color: var(--text-muted);
}

.setup-field input, .setup-field select {
    font: inherit;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 5px 8px;
}

.setup-field input:focus, .setup-field select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}

.setup-error {
    text-align: left;
}

/* ---------- Sign-in and footer ---------- */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(360px, 100%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 22px;
}

.login-card .brand {
    margin-bottom: 8px;
}

.login-card label {
    font-size: 12px;
    color: var(--text-muted);
}

.login-input {
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 8px 10px;
}

.login-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
}

.login-error {
    margin: 0;
    color: var(--danger);
    font-size: 12.5px;
}

.login-note {
    margin: 4px 0 0;
    font-size: 12px;
}

.app-footer {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 18px 16px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

.logout-form {
    margin: 0 0 0 auto;
}

.logout-form .btn {
    font-size: 12px;
    padding: 4px 10px;
}

/* ---------- Header tools, presence and guide links ---------- */

.brand-fish {
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
}

.top-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.guide-button, .presence-button {
    font-size: 12px;
    padding: 3px 10px;
    text-decoration: none;
}

.presence {
    position: relative;
}

.presence-button strong {
    font-variant-numeric: tabular-nums;
}

.presence-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
}

.presence-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 31;
    width: min(380px, calc(100vw - 32px));
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
    padding: 12px 14px;
}

.presence-popover header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.presence-popover h2 {
    font-size: 14px;
}

.presence-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.presence-item {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
}

.presence-item.me {
    border-color: rgba(92, 200, 255, 0.35);
}

.presence-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 12px;
    color: #06131e;
    background: var(--accent);
}

.presence-item.status-background .presence-avatar {
    background: #7f9bb0;
}

.presence-item.status-disconnected .presence-avatar {
    background: transparent;
    color: var(--text-muted);
    border: 1px dashed var(--text-muted);
}

.presence-main {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    min-width: 0;
}

.presence-role {
    font-size: 11px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 7px;
}

.presence-role.controls {
    color: var(--ok);
    border-color: rgba(111, 220, 140, 0.45);
}

.presence-meta {
    flex-basis: 100%;
    font-size: 11px;
}

.presence-status {
    font-size: 11px;
    white-space: nowrap;
    color: var(--ok);
}

.presence-item.status-background .presence-status {
    color: var(--text-muted);
}

.presence-item.status-disconnected .presence-status {
    color: var(--warn);
}

.presence-note {
    margin: 10px 0 0;
    font-size: 11.5px;
}

.run-chip.auto-paused {
    color: var(--warn);
    border-style: dashed;
    border-color: rgba(255, 217, 138, 0.5);
}

.guide-link {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    text-decoration: none;
    line-height: 1;
    flex: none;
    vertical-align: middle;
}

.guide-link:hover, .guide-link:focus-visible {
    color: #06131e;
    background: var(--accent);
    border-color: var(--accent);
    outline: none;
}

.timeline-item.kind-system {
    border-left-color: #9fb3c4;
}

/* ---------- Guide page ---------- */

.guide-page {
    min-height: 100vh;
}

.guide-topbar {
    justify-content: space-between;
}

.brand-link {
    color: inherit;
    text-decoration: none;
}

.guide-lead {
    flex: 1;
    min-width: 240px;
    margin: 0;
    font-size: 13px;
}

.guide-back {
    text-decoration: none;
}

.guide-layout {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    gap: 28px;
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px 18px 40px;
    align-items: start;
}

.guide-toc {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 96px);
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
}

.guide-toc h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.guide-toc ol {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 13px;
}

.guide-toc a {
    color: var(--text);
    text-decoration: none;
}

.guide-toc a:hover {
    color: var(--accent);
}

.guide-build {
    margin: 10px 0 0;
    font-size: 11px;
    word-break: break-all;
}

.guide-content {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 0;
    font-size: 14.5px;
    line-height: 1.6;
}

.guide-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 22px;
    scroll-margin-top: 76px;
}

.guide-section h2 {
    font-size: 20px;
    margin-bottom: 10px;
}

.guide-section h3 {
    font-size: 15px;
    margin: 18px 0 6px;
    color: #cfe3f1;
    scroll-margin-top: 76px;
}

.guide-section p {
    margin: 8px 0;
}

.guide-section ul, .guide-section ol {
    margin: 8px 0;
    padding-left: 22px;
}

.guide-section li + li {
    margin-top: 4px;
}

.callout {
    margin: 12px 0;
    padding: 10px 14px;
    border-left: 3px solid var(--accent);
    background: rgba(92, 200, 255, 0.07);
    border-radius: 0 8px 8px 0;
}

.table-scroll {
    overflow-x: auto;
    margin: 10px 0;
}

.guide-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    line-height: 1.5;
}

.guide-table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-strong);
    padding: 6px 10px;
    white-space: nowrap;
}

.guide-table td {
    border-bottom: 1px solid var(--border);
    padding: 7px 10px;
    vertical-align: top;
}

.guide-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.guide-table tr.changed td {
    background: rgba(255, 217, 138, 0.07);
}

.guide-table td.sym {
    white-space: nowrap;
    text-align: center;
    vertical-align: middle;
}

.guide-table td.cohort-row {
    white-space: normal;
    max-width: 120px;
}

.guide-table.params td:first-child, .guide-table.params td:last-child {
    white-space: nowrap;
}

.guide-table.influence td.where {
    min-width: 230px;
}

.guide-table.influence td.where > div + div {
    margin-top: 4px;
}

.where-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: 4px;
    padding: 0 5px;
    margin-right: 4px;
    color: #06131e;
}

.where-tag.ui { background: var(--accent); }
.where-tag.config { background: var(--warn); }
.where-tag.runner { background: #c9a0ff; }

.cfg {
    font-weight: 650;
    color: #ffe7a8;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cfg.cfg-changed {
    color: var(--warn);
    text-decoration: underline dotted;
}

.cfg-default {
    font-size: 12px;
    color: var(--text-muted);
}

.chip-inline {
    display: inline-block;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 8px;
    margin: 3px 4px 0 0;
    font-variant-numeric: tabular-nums;
}

.const-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 6px;
    margin: 8px 0;
}

.const-grid > div {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
    font-size: 13px;
}

.const-grid > div > span:nth-child(2) {
    font-family: var(--mono);
    color: #ffe7a8;
}

.const-grid > div > span:last-child {
    margin-left: auto;
    font-size: 11px;
}

.guide-code {
    margin: 10px 0;
}

.guide-code summary {
    cursor: pointer;
    color: var(--accent);
    margin-bottom: 6px;
}

.guide-cmd {
    font-family: var(--mono);
    font-size: 12.5px;
    background: #061522;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    white-space: pre;
}

.flow > li::marker, .phases > li::marker {
    color: var(--accent);
    font-weight: 700;
}

.experiment {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 14px 8px;
    margin: 10px 0;
    background: rgba(255, 255, 255, 0.02);
}

.experiment h3 {
    margin-top: 10px;
}

.experiment .predict {
    border-left: 3px solid var(--winner);
    padding-left: 10px;
}

.glossary {
    display: grid;
    grid-template-columns: minmax(160px, max-content) 1fr;
    gap: 6px 16px;
    margin: 8px 0;
}

.glossary dt {
    font-weight: 650;
}

.glossary dd {
    margin: 0;
    color: #cfe0ec;
}

.tl-kind {
    display: inline-block;
    font-size: 12px;
    padding: 1px 8px;
    border-left: 3px solid var(--border-strong);
    background: rgba(255, 255, 255, 0.03);
}

.tl-kind.kind-birth { border-left-color: var(--ok); }
.tl-kind.kind-death { border-left-color: var(--danger); }
.tl-kind.kind-rejection { border-left-color: var(--warn); }
.tl-kind.kind-discard { border-left-color: #c9a0ff; }
.tl-kind.kind-expiry { border-left-color: var(--warn); }
.tl-kind.kind-fallback { border-left-color: var(--accent); }
.tl-kind.kind-failure { border-left-color: #ff9f5a; }
.tl-kind.kind-system { border-left-color: #9fb3c4; }

.legend-energy {
    display: inline-block;
    width: 24px;
    height: 5px;
    background: #06131e;
    border-radius: 1px;
    padding: 1px;
}

.legend-energy > span {
    display: block;
    height: 100%;
    background: hsl(84, 85%, 55%);
}

.legend-bubble {
    display: inline-block;
    font-size: 11px;
    line-height: 1;
    color: #06131e;
    background: rgba(240, 248, 255, 0.92);
    border-radius: 7px;
    padding: 2px 5px;
    letter-spacing: 1px;
}

.legend-vision {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1.5px dashed rgba(160, 220, 255, 0.7);
    background: rgba(140, 210, 255, 0.12);
}

.legend-selected {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(3, 14, 24, 0.75);
    border: 1.5px solid #fff;
}

.legend-plankton {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8dffb8;
    box-shadow: 0 0 0 4px rgba(120, 255, 170, 0.2);
}

.legend-carcass {
    color: #b8a08a;
    font-size: 12px;
}

.legend-paused {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: #ffd98a;
    background: rgba(3, 14, 24, 0.72);
    border-radius: 10px;
    padding: 2px 8px;
}

@media (max-width: 900px) {
    .guide-layout {
        grid-template-columns: 1fr;
    }

    .guide-toc {
        position: static;
        max-height: none;
    }
}

/* ---------- Framework defaults ---------- */

.blazor-error-boundary {
    background: #5b1d1d;
    padding: 1rem 1rem 1rem 1rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "Došlo k chybě.";
}

/* ---------- Stage 4b-2: cohorts, prompts, LLM ---------- */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.cohort-editor {
    border: 0;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cohort-editor:disabled {
    opacity: 0.55;
}

.cohort-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cohort-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px 10px;
    padding: 6px 8px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.cohort-row-badge {
    align-self: center;
}

.cohort-row .cohort-name {
    flex: 1 1 160px;
}

.cohort-row .cohort-count input {
    width: 72px;
}

.cohort-row .cohort-prompt {
    flex: 1 1 200px;
}

.cohort-remove {
    align-self: center;
}

.cohort-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.setup-subtitle {
    font-size: 13px;
    margin: 12px 0 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.degraded-banner {
    margin: 0 16px 10px;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 122, 122, 0.6);
    background: rgba(255, 122, 122, 0.12);
    color: var(--text);
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    align-items: center;
}

.degraded-banner strong {
    color: var(--danger);
}

.cohort-metrics td, .cohort-metrics th {
    white-space: nowrap;
}

.cohort-metrics .cohort-strategy {
    display: block;
    font-size: 11px;
}

.llm-arithmetic {
    margin-top: 6px;
}

.llm-step {
    border-color: rgba(182, 156, 255, 0.45);
}

.declared-reason {
    margin-top: 6px;
    padding: 6px 10px;
    border-left: 3px solid #b69cff;
    background: rgba(182, 156, 255, 0.08);
    border-radius: 4px;
}

.declared-reason .declared-label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.declared-reason p {
    margin: 2px 0 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.prompt-json summary, .prompt-full summary {
    cursor: pointer;
    font-size: 12.5px;
    color: var(--accent);
    margin-top: 6px;
}

.prompt-json pre, .prompt-text {
    font-family: var(--mono);
    font-size: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    margin: 6px 0;
    max-height: 320px;
    overflow: auto;
}

.prompt-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px 12px;
}

.prompt-toolbar .setup-field {
    min-width: 200px;
}

.prompt-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 4px 12px;
    margin: 10px 0;
    font-size: 12.5px;
}

.prompt-meta div {
    min-width: 0;
}

.prompt-meta .wide {
    grid-column: 1 / -1;
}

.prompt-meta dt {
    color: var(--text-muted);
    font-size: 11px;
}

.prompt-meta dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.prompt-texts h3 {
    font-size: 12.5px;
    margin: 6px 0 0;
}

.prompt-texts.compare {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 10px;
}

.prompt-edit textarea {
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 8px 10px;
    resize: vertical;
    width: 100%;
}

.prompt-edit-actions {
    display: flex;
    gap: 8px;
    margin: 6px 0;
}

.prompt-saved {
    color: var(--ok);
    text-align: left;
}

code.hash {
    font-size: 11px;
    overflow-wrap: anywhere;
}

/* Stage 5: predators, reflex, intents, messages, memory, presets. */
.timeline-item.kind-kill { border-left-color: #ff5a5f; background: rgba(255, 90, 95, 0.1); font-weight: 600; }
.timeline-item.kind-attack { border-left-color: #ffaa78; }
.timeline-item.kind-reflex { border-left-color: #dcefff; }
.timeline-item.kind-intent { border-left-color: #9be564; }
.timeline-item.kind-message { border-left-color: #ff7eb6; }
.timeline-item.kind-memory { border-left-color: #ffd84d; }
.timeline-item.kind-accompaniment { border-left-color: #9fb3c4; }
.tl-kind.kind-kill { border-left-color: #ff5a5f; }
.tl-kind.kind-attack { border-left-color: #ffaa78; }
.tl-kind.kind-reflex { border-left-color: #dcefff; }
.tl-kind.kind-intent { border-left-color: #9be564; }
.tl-kind.kind-message { border-left-color: #ff7eb6; }
.tl-kind.kind-memory { border-left-color: #ffd84d; }
.tl-kind.kind-accompaniment { border-left-color: #9fb3c4; }

.source-tag.source-reflex {
    color: #ffffff;
    background: rgba(255, 90, 95, 0.25);
}

.diet-tag.diet-carnivore {
    color: #ffffff;
    background: rgba(232, 80, 91, 0.3);
    border: 1px solid #e8505b;
}

.diet-tag.diet-herbivore {
    color: var(--ok);
    background: rgba(111, 220, 140, 0.12);
}

.preset-row, .world-row {
    border: 0;
    margin: 0 0 10px;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px 14px;
}

.preset-row:disabled, .world-row:disabled {
    opacity: 0.6;
}

.preset-row .preset-select {
    min-width: 260px;
}

.preset-description, .world-diff {
    flex-basis: 100%;
    margin: 0;
}

.world-source {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-small {
    padding: 2px 8px;
    font-size: 12px;
}

.untrusted-title {
    color: #ffb3d1;
}

.untrusted-text {
    font-style: italic;
    overflow-wrap: anywhere;
}

.inbox-list {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
    display: grid;
    gap: 8px;
}

.inbox-item {
    border: 1px dashed rgba(255, 126, 182, 0.55);
    border-radius: 8px;
    padding: 6px 10px;
    background: rgba(255, 126, 182, 0.05);
}

.inbox-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 4px;
}

.accompaniment {
    font-size: 13px;
    margin: 4px 0 0;
}

.plan-outcome .outcome {
    display: inline;
}

.memory-table td.untrusted-text {
    max-width: 180px;
}
