:root {
  --bg: #f4f1e8;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #5d6576;
  --line: #d9d4c4;
  --accent: #e8a800;
  --ok: #1f7a3d;
  --fail: #b3261e;
  --user: #2457c5;
  --think: #7b4cc2;
  --act: #d06a00;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); height: 100vh; display: flex; flex-direction: column; }
h1 { font-size: 1.3rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.3rem; }
h4 { font-size: 0.9rem; margin: 0.6rem 0 0.3rem; }
button, select, input { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fffbea; border-radius: 6px; padding: 0.25rem 0.6rem; }
button:hover { background: #fff1b8; }
a.button-link { color: inherit; text-decoration: none; border: 1px solid var(--line); background: #fffbea; border-radius: 6px; padding: 0.25rem 0.6rem; }
a.button-link:hover { background: #fff1b8; }
button:disabled { opacity: 0.5; cursor: wait; }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3em; background: #fafafa; font-size: 0.85em; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.5rem; }
.summary { font-size: 0.95rem; line-height: 1.4; }
.badge { font-size: 0.75rem; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0 0.5rem; margin-left: 0.3rem; }
.badge:empty { display: none; }

/* --- Modes -------------------------------------------------------------------- */
body[data-mode="agent"] .manual-only, body[data-mode="manual"] .agent-only { display: none !important; }

/* --- Top bar ------------------------------------------------------------------ */
.topbar { display: flex; flex-direction: column; align-items: stretch; gap: 0.35rem; padding: 0.45rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.bar-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.step { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; font-size: 0.92rem; }
.step-label { font-weight: 700; color: var(--ink); background: #fff1b8; border-radius: 6px; padding: 0.1rem 0.5rem; }
.step .hint { margin: 0; }
button.primary { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.new-run { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; font-size: 0.92rem; }
.step input[type=number] { width: 6rem; }
.step .goal input { width: 22rem; }
.step select { max-width: 13rem; }
.mode-switch { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mode-switch label { padding: 0.25rem 0.7rem; cursor: pointer; }
.mode-switch input { position: absolute; opacity: 0; }
.mode-switch label:has(input:checked) { background: var(--ink); color: #fff; }
.mode-switch label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.account { margin-left: auto; display: flex; gap: 0.6rem; align-items: center; color: var(--muted); font-size: 0.9rem; }

/* --- Layout ------------------------------------------------------------------- */
/* Sizes come from the draggable gutters (layout.js): --split-x is the world's share
   of the width, --split-y the bottom row's share of the height, --split-b the
   timeline's share of the bottom row. */
.layout { --split-x: 0.535; --split-y: 0.27; --gutter: 0.5rem;
  flex: 1; min-height: 0; display: grid; gap: 0; padding: 0.5rem;
  grid-template-columns: minmax(0, calc(var(--split-x) * 100%)) var(--gutter) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto var(--gutter) minmax(0, calc(var(--split-y) * 100%));
  grid-template-areas: "world gx side" "player player player" "gy gy gy" "bottom bottom bottom"; }
.player { margin-top: var(--gutter); }
.bottom { --split-b: 0.535; grid-area: bottom; display: grid; min-height: 0; grid-template-rows: minmax(0, 1fr);
  grid-template-columns: minmax(0, calc(var(--split-b) * 100%)) var(--gutter) minmax(0, 1fr); }
body[data-mode="manual"] .layout { grid-template-areas: "world gx side" "world gx side" "gy gy gy" "bottom bottom bottom"; }
.gutter { position: relative; touch-action: none; outline: none; }
.gutter-x, .gutter-b { cursor: col-resize; }
.gutter-y { cursor: row-resize; }
.gutter::after { content: ""; position: absolute; border-radius: 2px; background: transparent; transition: background 0.15s; }
.gutter-x::after, .gutter-b::after { top: 30%; bottom: 30%; left: calc(50% - 2px); width: 4px; }
.gutter-y::after { left: 35%; right: 35%; top: calc(50% - 2px); height: 4px; }
.gutter:hover::after, .gutter:focus-visible::after, body.resizing .gutter::after { background: var(--line); }
.gutter:focus-visible::after { background: var(--accent); }
/* A divider pushed into a section's minimum size turns amber and says which section. */
.gutter[data-limit]::after { background: var(--accent); }
.gutter[data-limit] { z-index: 10; cursor: not-allowed; }
.gutter[data-limit]::before { content: attr(data-limit); position: absolute; z-index: 1; left: 50%; top: 50%; transform: translate(-50%, -50%); white-space: nowrap; pointer-events: none;
  background: var(--ink); color: #fff; font-size: 0.8rem; font-weight: 600; border-radius: 6px; padding: 0.2rem 0.55rem; box-shadow: 0 2px 8px rgba(0,0,0,0.25); }
body.resizing { user-select: none; }
body.resizing .world canvas { pointer-events: none; }
.gutter-x { grid-area: gx; }
.gutter-y { grid-area: gy; }
.world { grid-area: world; position: relative; border-radius: 8px; overflow: hidden; background: #cfe0b8; min-height: 0; }
#canvas { width: 100%; height: 100%; display: block; outline: none; }
.side { grid-area: side; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; min-height: 0; }
.player { grid-area: player; }
.log { overflow-y: auto; min-height: 0; }
.inspector { overflow-y: auto; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem; }

/* --- World overlays ------------------------------------------------------------ */
/* Controls bottom left, inventory bottom right; when the world is too narrow for
   both on one line, the inventory wraps above the controls instead of covering them. */
.world-bar { position: absolute; left: 0.5rem; right: 0.5rem; bottom: 0.5rem; display: flex; flex-wrap: wrap-reverse; align-items: flex-end; justify-content: space-between; gap: 0.4rem; pointer-events: none; }
.world-bar > * { pointer-events: auto; }
.view-controls { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; background: rgba(255,255,255,0.88); border-radius: 6px; padding: 0.3rem 0.6rem; font-size: 0.9rem; }
.coverage-stats { color: var(--muted); font-size: 0.8rem; }
.inventory { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; background: rgba(255,255,255,0.92); border: 2px solid var(--act); border-radius: 8px; padding: 0.3rem 0.6rem; font-size: 0.9rem; }
.inventory[hidden] { display: none; }
.inventory.inv-empty { border-color: var(--line); color: var(--muted); }
.inv-label { font-weight: 600; white-space: nowrap; }
.inv-slot { display: flex; align-items: center; gap: 0.35rem; }
.inv-swatch { width: 0.9rem; height: 0.9rem; border-radius: 50%; border: 1px solid rgba(0,0,0,0.25); }
.inventory.inv-empty .inv-swatch { display: none; }
.g-inventory { font-size: 0.72rem; background: #fff1b8; border-radius: 99px; padding: 0.05rem 0.45rem; margin-top: 0.15rem; }
.g-inventory[hidden] { display: none; }
.eyes-note { position: absolute; top: 0.5rem; left: 0.5rem; right: 0.5rem; background: rgba(29,36,51,0.85); color: #fff; padding: 0.4rem 0.7rem; border-radius: 6px; font-size: 0.85rem; }
.eyes-note[hidden] { display: none; }
.tooltip { position: absolute; pointer-events: none; background: rgba(29,36,51,0.92); color: #fff; padding: 0.3rem 0.5rem; border-radius: 4px; font-size: 0.85rem; transform: translate(12px, 12px); white-space: pre; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 1.1rem; pointer-events: none; }
.empty[hidden] { display: none; }
.agent-view { position: absolute; inset: 0; background: #10141f; color: #e8ecf5; padding: 1rem 1.25rem 3.5rem; overflow: auto; }
.agent-view h2 { color: #ffd34d; }
.agent-view .hint { color: #a9b3c7; }
.agent-view .summary { font-size: 1.15rem; }
.agent-view pre { font-size: 0.85rem; line-height: 1.35; white-space: pre-wrap; }

/* --- Goal confirmation and verdict ------------------------------------------------- */
.goal-dialog { position: absolute; inset: 0; background: rgba(16, 20, 31, 0.55); display: grid; place-items: center; padding: 1rem; z-index: 5; }
.goal-dialog[hidden] { display: none; }
.runs-card { max-height: 90%; overflow: auto; width: min(44rem, 100%); }
.runs-card h3 { margin: 0.8rem 0 0.3rem; font-size: 0.95rem; }
.run-list { list-style: none; margin: 0; padding: 0; }
.run-list li button { width: 100%; text-align: left; padding: 0.35rem 0.5rem; margin: 0.15rem 0; background: #f6f7fa; border: 1px solid #e3e6ee; border-radius: 6px; font-size: 0.85rem; }
.run-list li button:hover { background: #eef1f7; }
.run-list li.shared button { border-left: 3px solid var(--act); }
.run-share { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.9rem; }
.run-share[hidden] { display: none; }
.run-share input { min-width: 22rem; }
.goal-card { background: var(--panel); border-radius: 12px; padding: 1.2rem 1.4rem; max-width: 34rem; box-shadow: 0 10px 40px rgba(0,0,0,0.3); }
.goal-card h2 { font-size: 1.1rem; }
.goal-text { color: var(--muted); font-style: italic; margin: 0.3rem 0; }
.goal-interpretation { font-size: 1.15rem; line-height: 1.4; margin: 0.6rem 0; }
.goal-unverifiable { background: #fff4e5; border: 1px solid #f0c07a; border-radius: 8px; padding: 0.5rem 0.7rem; }
.goal-unverifiable[hidden] { display: none; }
.goal-spec { background: #f6f7fa; border-radius: 6px; padding: 0.5rem; font-size: 0.78rem; max-height: 14rem; overflow: auto; }
.goal-buttons { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
#goal-confirm { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; padding: 0.4rem 0.9rem; }
.human-free { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.human-free input { flex: 1; padding: 0.35rem 0.5rem; border: 1px solid var(--line); border-radius: 6px; }
.human-options button { font-weight: 600; }
.log-list .beat-ask, .log-list .beat-answer { font-weight: 600; }
.log-list .beat-stuck { color: var(--fail); }
.log-list .beat-guard { color: var(--fail); }
/* Belief vs truth: what the world checks beside what the team believes */
.truth { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.4rem; margin: -0.2rem 0 0.5rem; font-size: 0.82rem; }
.truth[hidden] { display: none; }
.truth-col { border-radius: 6px; padding: 0.35rem 0.55rem; min-width: 0; }
.truth-col h3 { font-size: 0.78rem; margin: 0 0 0.2rem; }
.truth-col p { margin: 0 0 0.2rem; }
.truth-col .hint { font-size: 0.74rem; margin: 0; }
.truth-world { background: #eef5ff; }
.truth-team { background: #faf7ee; }
.truth-interp { color: var(--muted); }
.checks { list-style: none; margin: 0.15rem 0 0; padding: 0; }
.checks li { display: flex; gap: 0.35rem; align-items: baseline; }
.checks li small { margin-left: auto; color: var(--muted); white-space: nowrap; }
.checks .check-mark { font-weight: 700; width: 1em; }
.checks .met { color: var(--ok); }
.checks .met .check-mark { color: var(--ok); }
.truth-plan { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.truth-claim { border-left: 3px solid var(--agent, var(--line)); padding-left: 0.4rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.truth-claim.ok b { color: var(--ok); }
.truth-claim.fail b { color: var(--fail); }
.truth-verdict { grid-column: 1 / -1; margin: 0; font-weight: 700; border-radius: 6px; padding: 0.3rem 0.55rem; background: #f1f3f7; }
.truth-verdict.agree { background: #edf7ef; color: var(--ok); }
.truth-verdict.disagree { background: #fdecea; color: var(--fail); }
/* Short screens: the graph needs the room. Full texts stay in the hover titles. */
@media (max-height: 900px) {
  .truth { gap: 0.3rem; margin-bottom: 0.3rem; font-size: 0.78rem; }
  .truth-col { padding: 0.2rem 0.45rem; }
  .truth-col h3 { font-size: 0.72rem; margin: 0; }
  .truth-interp, .truth-plan, .truth-col .hint { display: none; }
  .truth-claim { -webkit-line-clamp: 1; margin: 0; }
  .truth-verdict { padding: 0.15rem 0.45rem; }
}
.unfrozen { background: #fff4e5; border: 1px solid #f0c07a; border-radius: 6px; padding: 0.35rem 0.55rem; font-size: 0.82rem; }
.log-list .beat-progress { color: #2457c5; font-weight: 600; }
.p-status.disagree { color: var(--fail); font-weight: 700; }
.log-list .beat-verdict { font-weight: 700; }

/* --- Agent graph ---------------------------------------------------------------- */
.graph-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.graph { position: relative; flex: 1; min-height: 0; }
.graph-grid { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-content: center; gap: 2.2rem 1.2rem; height: 100%; padding: 0.4rem; }
.g-agents { display: flex; flex-direction: column; gap: 2.2rem; align-items: center; justify-content: center; }
.g-lead, .g-helpers { display: flex; flex-wrap: wrap; gap: 0.7rem; justify-content: center; width: 100%; }
.g-card { --agent: var(--act); }
.g-card .g-head b { color: var(--agent); }
.graph-grid.team { grid-template-columns: 1fr; gap: 1.1rem; align-content: start; height: auto; min-height: 100%; }
.graph-grid.team .g-lead { align-items: center; flex-wrap: nowrap; gap: 0.8rem; }
.graph-grid.team .g-helpers { flex-wrap: nowrap; gap: 0.45rem; }
.graph-grid.team .g-node { min-width: 0; padding: 0.35rem 0.55rem; font-size: 0.8rem; }
.graph-grid.team .g-node small { font-size: 0.66rem; max-width: 7rem; }
.graph-grid.team .g-world { grid-column: 1; }
.graph.multi .g-lead .g-card { width: min(100%, 21rem); padding: 0.45rem 0.6rem; }
.graph.multi .g-helpers .g-card { flex: 1 1 0; min-width: 0; width: auto; padding: 0.4rem 0.45rem; font-size: 0.85rem; border-radius: 10px; }
.graph.multi .g-helpers .g-head { flex-wrap: wrap; gap: 0.25rem; }
.graph.multi .g-helpers .g-icon { font-size: 1.05rem; }
.graph.multi .g-helpers .g-model { margin-left: 0; font-size: 0.62rem; }
.graph.multi .g-status { font-size: 0.72rem; margin: 0.1rem 0 0.25rem; }
.graph.multi .g-thought { min-height: 2.8em; max-height: 4.2em; overflow: hidden; font-size: 0.76rem; padding: 0.25rem 0.4rem; margin-bottom: 0.3rem; }
.graph.multi .g-lead .g-thought { font-size: 0.82rem; }
.graph.multi .g-helpers .chip { font-size: 0.62rem; padding: 0.02rem 0.3rem; }
.graph.multi .g-chips { gap: 0.2rem; }
.graph.multi .g-counters { font-size: 0.62rem; margin-top: 0.3rem; }
.graph { overflow: hidden; }
.edge-delegate { stroke: #9aa6c4; stroke-dasharray: none; stroke-width: 2.5; }
.packet-delegate circle { fill: #2457c5; }
.g-side { display: flex; flex-direction: column; gap: 1rem; justify-content: center; }
.g-world { grid-column: 1 / -1; justify-self: center; }
.g-card { position: relative; z-index: 1; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 0.6rem 0.75rem; width: min(100%, 28rem); cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s; }
.g-card:focus-visible { outline: 3px solid var(--accent); }
.g-card.active { border-color: var(--agent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--agent) 18%, transparent); }
.g-card.thinking { border-color: var(--think); box-shadow: 0 0 0 4px rgba(123,76,194,0.18); animation: think 1.2s ease-in-out infinite; }
.g-card.finished { border-color: var(--ok); }
@keyframes think { 50% { box-shadow: 0 0 0 9px rgba(123,76,194,0.06); } }
.g-head { display: flex; align-items: center; gap: 0.45rem; }
.g-icon { font-size: 1.35rem; }
.g-model { margin-left: auto; font-size: 0.75rem; font-family: ui-monospace, Menlo, monospace; background: #eef0f5; border-radius: 4px; padding: 0.05rem 0.4rem; }
.g-status { font-size: 0.8rem; color: var(--muted); margin: 0.2rem 0 0.35rem; }
.g-card.thinking .g-status { color: var(--think); font-weight: 600; }
.g-card.thinking .g-status::before { content: "💭 "; }
.g-card.acting .g-status { color: var(--act); font-weight: 600; }
.g-card.acting .g-status::before { content: "⚙ "; }
.g-thought { min-height: 3.6em; font-size: 0.95rem; line-height: 1.35; background: #faf7ee; border-radius: 8px; padding: 0.35rem 0.5rem; margin-bottom: 0.45rem; }
.g-thought:empty::before { content: "…"; color: var(--muted); }
.g-thought[data-kind="thought"]::before { content: "💡 "; }
.g-thought[data-kind="result"] { background: #edf7ef; }
.g-thought[data-kind="fail"] { background: #fdecea; }
.g-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.g-guards:empty { display: none; }
.g-guard { font-size: 0.7rem; margin-top: 0.3rem; padding: 0.15rem 0.4rem; border-left: 3px solid var(--fail); background: #fbf3f3; }
.chip { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 99px; background: #f1f3f7; border: 1px solid #dde1ea; }
.chip.lit { background: var(--act); color: #fff; border-color: var(--act); }
.g-counters { font-size: 0.72rem; color: var(--muted); margin-top: 0.45rem; }
.g-node { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 0.1rem; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 0.45rem 0.8rem; min-width: 8rem; text-align: center; font-size: 0.9rem; cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s; }
.g-node small { color: var(--muted); font-size: 0.72rem; }
.g-node.disabled { opacity: 0.45; border-style: dashed; }
.g-node.pulse { border-color: var(--act); box-shadow: 0 0 0 6px rgba(208,106,0,0.18); }
.g-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 2; }
.edge { stroke: #c9c3b0; stroke-width: 2; stroke-dasharray: 5 5; }
.packet circle { fill: var(--act); stroke: #fff; stroke-width: 2; }
.packet text { font: 600 13px ui-monospace, Menlo, monospace; fill: var(--ink); paint-order: stroke; stroke: #fff; stroke-width: 4px; }
.packet-ok circle { fill: var(--ok); }
.packet-fail circle { fill: var(--fail); }
.packet.arrived { opacity: 0; transition: opacity 0.25s; }

/* --- Player --------------------------------------------------------------------- */
.player { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.35rem 0.75rem; }
.player > button { font-size: 1.1rem; min-width: 2.6rem; }
#p-play { background: var(--ink); color: #fff; border-color: var(--ink); }
.p-status { color: var(--muted); font-size: 0.9rem; margin-left: auto; }

/* --- Timeline ----------------------------------------------------------------- */
.log-list { list-style: none; margin: 0; padding: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
.log-list li { padding: 0.15rem 0.3rem; border-bottom: 1px dotted #eee; border-radius: 4px; }
.log-list .call { color: var(--user); }
.log-list .ok { color: var(--ok); }
.log-list .fail { color: var(--fail); }
.log-list .sys { color: var(--muted); }
.log-list .beat { cursor: pointer; border-left: 4px solid var(--agent, transparent); padding-left: 0.4rem; }
.log-list .beat-delegate, .log-list .beat-report { font-weight: 600; }
.log-list .beat:hover { background: #f6f3ea; }
.log-list .beat.current { background: #fff1b8; outline: 1px solid var(--accent); }
.log-list .beat-thinking { color: var(--think); }
.log-list .beat-decision { color: var(--ink); }
.log-list .beat-tool { color: var(--act); }
.log-list .beat-result { color: var(--ok); }
.log-list .beat-result.fail { color: var(--fail); }

/* --- Inspector / memory tabs ------------------------------------------------------ */
.tabs { display: flex; gap: 0.3rem; margin-bottom: 0.5rem; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; font-weight: 600; color: var(--muted); padding: 0.15rem 0.5rem; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.memory-body[hidden], .inspector-body[hidden] { display: none; }
.mem-count { font-weight: 600; margin: 0 0 0.4rem; }
.mem-note { border-left: 4px solid var(--agent, var(--line)); background: #faf7ee; border-radius: 6px; padding: 0.35rem 0.55rem; margin-bottom: 0.4rem; font-size: 0.85rem; transition: box-shadow 0.3s; }
.mem-note.fresh { box-shadow: 0 0 0 3px var(--accent); }
.mem-note.deleted { opacity: 0.55; }
.mem-note.deleted .mem-text { text-decoration: line-through; }
.mem-head { display: flex; gap: 0.45rem; align-items: baseline; flex-wrap: wrap; }
.mem-head b { font-family: ui-monospace, Menlo, monospace; }
.mem-scope { font-size: 0.7rem; border-radius: 99px; padding: 0 0.45rem; background: #e3ecff; }
.mem-scope.private { background: #eee; }
.mem-author { margin-left: auto; color: var(--muted); font-size: 0.75rem; }
.mem-text { margin: 0.2rem 0; white-space: pre-wrap; }
.mem-meta { font-size: 0.75rem; color: var(--muted); }
.mem-meta.unread { color: var(--act); font-weight: 600; }
.mem-history { margin: 0.2rem 0 0; padding-left: 1.2rem; font-size: 0.78rem; }

/* --- Inspector ------------------------------------------------------------------ */
.inspector-body pre.json { background: #f6f7fa; border-radius: 6px; padding: 0.5rem; font-size: 0.78rem; overflow: auto; max-height: 22rem; white-space: pre-wrap; }
.inspector-body details { margin: 0.25rem 0; }
.inspector-body summary { cursor: pointer; font-size: 0.88rem; }
.inspector-body .said { background: #faf7ee; border-radius: 6px; padding: 0.4rem 0.55rem; }
.msgs { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.3rem; }
.msg { border-left: 3px solid var(--line); padding: 0.2rem 0.5rem; font-size: 0.82rem; }
.msg-user { border-color: var(--user); }
.msg-assistant { border-color: var(--think); }
.msg-tool { border-color: var(--act); }
.msg-role { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.msg-content { white-space: pre-wrap; }
pre.msg-content { font-size: 0.75rem; max-height: 10rem; overflow: auto; margin: 0.2rem 0; }
.msg-call { font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; color: var(--act); }

/* --- Manual mode ---------------------------------------------------------------- */
.tools { display: flex; flex-direction: column; gap: 0.4rem; }
.tool { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; border-top: 1px solid #eee; padding-top: 0.4rem; }
.tool:first-child { border-top: 0; padding-top: 0; }
.tool button { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; min-width: 8.5rem; text-align: left; }
.tool input { width: 5rem; }
.tool input.id { width: 6rem; }
.tool label { font-size: 0.8rem; color: var(--muted); display: flex; gap: 0.25rem; align-items: center; }
.keys { margin-top: 0.75rem; font-size: 0.85rem; }
.keys ul { padding-left: 1.1rem; margin: 0.4rem 0 0; }

/* --- Login ------------------------------------------------------------------------ */
.login-page { display: grid; place-items: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 2rem 2.25rem; width: min(26rem, 92vw); }
.login-box h1 { font-size: 1.6rem; margin-bottom: 0.4rem; }
.login-box form { display: flex; flex-direction: column; gap: 0.9rem; margin: 1rem 0; }
.login-box label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.95rem; }
.login-box label.remember { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--muted); }
.login-box input:not([type=checkbox]) { padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; }
.login-box button { padding: 0.55rem; font-weight: 600; }
.flash { padding: 0.5rem 0.75rem; border-radius: 6px; margin: 0.5rem 0; }
.flash.error { background: #fdecea; color: var(--fail); border: 1px solid #f3c2bd; }

/* --- Effects tuning (developer only, ?fx=tune) ------------------------------------ */
.fx-tune { position: fixed; right: 0.75rem; top: 6rem; z-index: 50; width: 19rem; max-height: calc(100vh - 7rem); overflow: auto; background: rgba(255,255,255,0.96); border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.75rem; font-size: 0.8rem; box-shadow: 0 6px 24px rgba(0,0,0,0.2); }
.fx-tune label { display: grid; grid-template-columns: 6.5rem 1fr 2.6rem; align-items: center; gap: 0.4rem; margin: 0.15rem 0; font-family: ui-monospace, Menlo, monospace; }
.fx-tune label.changed { color: var(--act); font-weight: 700; }
.fx-tune output { text-align: right; }
.fx-tune div { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.5rem; }
.fx-tune button { font-size: 0.78rem; padding: 0.15rem 0.45rem; }
.fx-tune p { margin: 0.4rem 0 0; color: var(--muted); word-break: break-all; }

/* --- Teacher pages (classes and accounts) -------------------------------------------- */
.teacher-page { height: auto; min-height: 100vh; display: block; }
.teacher-page h1 a { color: inherit; text-decoration: none; }
.teacher-page .bar-row > a, .teacher-main a { color: var(--user); }
.teacher-main { max-width: 60rem; margin: 0 auto; padding: 1rem; }
.teacher-main h2 { font-size: 1.25rem; margin: 0.5rem 0; display: flex; align-items: center; gap: 0.6rem; }
.teacher-main h3 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; }
.teacher-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 0.92rem; }
.teacher-table th, .teacher-table td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); }
.teacher-table th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.row-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
.row-actions form { margin: 0; }
.teacher-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 0.8rem 0; }
.teacher-form p { margin: 0; }
.teacher-form input:not([type=hidden]) { padding: 0.3rem 0.45rem; border: 1px solid var(--line); border-radius: 6px; }
.teacher-form input[type=number] { width: 4.5rem; }
.teacher-form input[name=prefix] { width: 7rem; }
button.danger { color: var(--fail); border-color: #f3c2bd; background: #fdecea; }
.state { font-size: 0.75rem; font-weight: 600; border-radius: 99px; padding: 0.05rem 0.55rem; }
.state.open { background: #edf7ef; color: var(--ok); }
.state.closed { background: #f1f3f7; color: var(--muted); }
.state.ended { background: #fdecea; color: var(--fail); }
.table-scroll { overflow-x: auto; }
.challenge-table th, .challenge-table td.pts { text-align: center; }
.challenge-table td.pts a { font-weight: 700; text-decoration: none; }
.challenge-table td.pts2 a { color: var(--ok); }
.challenge-table td.pts0 a { color: var(--fail); }
.flash.ok { background: #edf7ef; color: var(--ok); border: 1px solid #bfe3c8; }
.login-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 0.6rem; margin-top: 1rem; }
.login-card { border: 1px dashed var(--muted); border-radius: 8px; padding: 0.6rem 0.8rem; background: #fff; break-inside: avoid; }
.login-card p { margin: 0.2rem 0; }
.login-card code { font-size: 1.1rem; font-weight: 700; }
.card-site, .card-class { color: var(--muted); font-size: 0.8rem; }
@media print {
  .no-print { display: none !important; }
  body, .teacher-page { background: #fff; }
  .teacher-main { max-width: none; padding: 0; }
}

/* Edit mode (agentui/editor.js) */
#edit-design.on { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.g-card.selected { border-color: var(--agent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--agent) 25%, transparent); }
.g-edited { color: var(--accent); font-weight: 700; }
.g-remove { margin-left: 0.2rem; border: 0; background: none; padding: 0 0.2rem; color: var(--muted); font-size: 0.8rem; cursor: pointer; }
.g-remove:hover { color: var(--fail); }
.g-add { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-top: 0.6rem; position: relative; z-index: 1; }
.g-add button { border-style: dashed; font-size: 0.8rem; }
.chip.added { background: #e6f4ea; border-color: var(--ok); }
.chip.removed { text-decoration: line-through; color: var(--muted); background: none; border-style: dashed; }
.editor { display: flex; flex-direction: column; gap: 0.5rem; }
.ed-head { display: flex; align-items: center; gap: 0.4rem; }
.ed-pen { color: var(--accent); font-weight: 700; }
.ed-name { flex: 1; min-width: 0; font-weight: 600; font-size: 1rem; }
.ed-status { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.ed-status[data-kind="ok"] { color: var(--ok); }
.ed-status[data-kind="fail"] { color: var(--fail); white-space: normal; }
.ed-buttons { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.ed-row { display: flex; gap: 0.5rem; align-items: center; font-size: 0.9rem; }
.ed-errors { background: #fbf3f3; border: 1px solid var(--fail); border-radius: 6px; padding: 0.4rem 0.6rem; font-size: 0.85rem; }
.ed-warnings { background: #fff4e5; border: 1px solid #f0c07a; border-radius: 6px; padding: 0.4rem 0.6rem; font-size: 0.85rem; }
.ed-errors ul, .ed-warnings ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
.ed-agent { display: flex; flex-direction: column; gap: 0.45rem; border-top: 1px solid var(--line); padding-top: 0.5rem; }
.ed-agent h4 { margin: 0; }
.ed-agent .hint { margin: 0; }
.ed-field { display: flex; flex-direction: column; gap: 0.15rem; }
.ed-label { font-size: 0.8rem; font-weight: 600; display: flex; justify-content: space-between; gap: 0.5rem; }
.ed-field textarea, .ed-field input, .ed-rule textarea { width: 100%; box-sizing: border-box; font: inherit; font-size: 0.85rem; }
.ed-field input[type="number"] { width: 6rem; }
.ed-count { font-weight: 400; color: var(--muted); }
.ed-count.over { color: var(--fail); font-weight: 700; }
.ed-rules { display: flex; flex-direction: column; gap: 0.35rem; }
.ed-rule { display: flex; gap: 0.3rem; align-items: flex-start; }
.ed-rule textarea { flex: 1; }
.ed-rule-tools { display: flex; flex-direction: column; gap: 0.15rem; align-items: center; }
.ed-rule-tools button { padding: 0 0.35rem; font-size: 0.75rem; }
.ed-rules > button { align-self: flex-start; }
.ed-tools { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ed-tools fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 0.25rem 0.5rem; margin: 0; flex: 1 1 12rem; }
.ed-tools legend { font-size: 0.75rem; color: var(--muted); }
.ed-tool { display: inline-flex; align-items: center; gap: 0.2rem; margin: 0.1rem 0.5rem 0.1rem 0; font-size: 0.8rem; }
.ed-tool.ed-changed code { background: #fff1b8; }
.ed-guards { display: flex; flex-direction: column; gap: 0.2rem; }
.ed-agent > button { align-self: flex-start; }
.ed-preview pre { white-space: pre-wrap; max-height: 22rem; overflow: auto; }
.diff { font-size: 0.82rem; display: flex; flex-direction: column; gap: 0.2rem; }
.diff h5 { margin: 0.5rem 0 0.1rem; }
.diff-line.ins, .diff ins { background: #e6f4ea; text-decoration: none; }
.diff-line.del, .diff del { background: #fbe9e9; }
.diff-text { white-space: pre-wrap; border-left: 3px solid var(--line); padding-left: 0.4rem; }

/* Compare runs (agentui/compare.js) */
#compare-dialog, #challenge-dialog { position: fixed; z-index: 50; }
.compare-card { width: min(78rem, 100%); max-width: none; max-height: 92vh; }
.cmp-filters { display: flex; flex-wrap: wrap; gap: 0.8rem; font-size: 0.9rem; }
.cmp-filters select { max-width: 28rem; }
.cmp-scroll { overflow-x: auto; }
table.cmp { border-collapse: collapse; font-size: 0.82rem; width: 100%; }
table.cmp th, table.cmp td { border-bottom: 1px solid var(--line); padding: 0.25rem 0.4rem; text-align: left; vertical-align: top; }
table.cmp th { position: sticky; top: 0; background: var(--panel); white-space: nowrap; }
table.cmp td:nth-child(n+8) { white-space: nowrap; }
table.cmp td:nth-child(7) { min-width: 12rem; }
table.cmp .ok { color: var(--ok); font-weight: 700; }
table.cmp .fail { color: var(--fail); font-weight: 700; }
table.cmp tr.disagree { background: #fff4e5; }
.linkish { border: 0; background: none; padding: 0; color: #2457c5; text-decoration: underline; }
.cmp-diff h3 { font-size: 0.95rem; margin: 0.8rem 0 0.3rem; }
table.cmp .pending { color: var(--muted); font-style: italic; }
table.cmp .pts2, .ch-table .pts2 { color: var(--ok); font-weight: 700; }
table.cmp .pts0, .ch-table .pts0 { color: var(--fail); font-weight: 700; }
table.cmp .pts1, .ch-table .pts1 { font-weight: 700; }
.open-compare { margin-left: auto; font-size: 0.92rem; }
#open-challenge { font-size: 0.92rem; }
.ch-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; font-size: 0.9rem; margin: 0.6rem 0; }
.ch-status { min-height: 1.2em; font-weight: 600; }
table.ch-attempts tr.picked { background: #eef4ff; }
table.ch-table td:nth-child(3) { min-width: 12rem; }
table.ch-table td:nth-child(7), table.ch-attempts td:nth-child(7) { min-width: 0; }
.cmp-filters label { max-width: 100%; }
.cmp-filters select { max-width: 100%; }
.diff-text.rewritten { display: flex; flex-direction: column; gap: 0.25rem; }
.diff-text.rewritten del, .diff-text.rewritten ins { display: block; padding: 0.15rem 0.3rem; }

/* Tooltips (static/js/tips.js): every title, on hover and on keyboard focus. */
.ui-tip { position: fixed; z-index: 1000; max-width: min(24rem, calc(100vw - 12px)); padding: 0.4rem 0.6rem; border-radius: 6px; background: rgba(29,36,51,0.95); color: #fff; font-size: 0.82rem; line-height: 1.35; white-space: pre-line; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.ui-tip[hidden] { display: none; }

/* "Start driving" asks for attention when a tool is used before a run exists. */
@keyframes nudge { 0%, 100% { box-shadow: 0 0 0 0 rgba(232,168,0,0); } 30% { box-shadow: 0 0 0 6px rgba(232,168,0,0.75); } }
.nudge { animation: nudge 0.6s ease-out 3; }
