:root {
  --bg: #0e131b;
  --panel: #141b26;
  --panel-2: #1a2330;
  --glass: #121924e0;
  --line: #243041;
  --line-2: #33435a;
  --text: #e6edf5;
  --muted: #9aa6b6;
  --faint: #6b7788;
  --accent: #4c8dff;
  --good: #3fd18a;
  --warn: #ffb547;
  --bad: #ff5d5d;
  --own: #f5c542;
  --belief: #9fd3ff;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--mono); }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- top bar ------------------------------------------------------------------------------ */
.topbar {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand {
  font-size: 15px; white-space: nowrap; display: flex; align-items: center; gap: 8px;
  background: none; border: 0; padding: 4px 2px;
}
.brand b { color: var(--accent); font-weight: 600; }
.logo {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 65% 40%, #5ee1ff 0 18%, transparent 20%), var(--accent);
  box-shadow: 0 0 12px #4c8dff88;
}
select, .btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px;
}
select:hover, .btn:hover { border-color: var(--line-2); }
#run-picker { max-width: 260px; min-width: 0; }
.btn.round { width: 30px; height: 30px; padding: 0; border-radius: 50%; font-weight: 600; flex: none; }
.file input { display: none; }
.run-info { margin-left: auto; text-align: right; min-width: 0; }
.run-title { white-space: nowrap; }
.run-desc { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; letter-spacing: 0.04em; }
.badge.pass { background: #3fd18a22; color: var(--good); }
.badge.fail { background: #ff5d5d22; color: var(--bad); cursor: help; }

/* --- main --------------------------------------------------------------------------------- */
main { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#stage3d { position: absolute; inset: 0; z-index: 0; } /* CSS2D labels set z-index per label: keep them under the overlays */
#stage3d canvas { display: block; }
.labels { position: absolute; inset: 0; pointer-events: none; }

.stage-tools, .layer-chips { position: absolute; top: 10px; display: flex; gap: 6px; align-items: center; }
.stage-tools { left: 10px; }
.layer-chips { right: 10px; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 300px); }
.chip, .seg {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  background: var(--glass); backdrop-filter: blur(6px); border: 1px solid var(--line);
  border-radius: 999px; font-size: 12px; cursor: pointer; white-space: nowrap; user-select: none;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { border-color: #4c8dff88; background: #1b2a44e6; }
.chip:not(:has(input:checked)) { color: var(--faint); }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip .dot.ring { background: none; border: 2px solid var(--c); width: 10px; height: 10px; }
.chip:not(:has(input:checked)) .dot { opacity: 0.35; }
.seg { padding: 0; overflow: hidden; gap: 0; }
.seg button { background: none; border: 0; height: 100%; padding: 0 11px; color: var(--muted); }
.seg button.on { background: #4c8dff33; color: var(--text); }

.legend {
  position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px);
  background: var(--glass); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: var(--radius); font-size: 11px; color: var(--muted);
}
.legend summary { cursor: pointer; color: var(--text); list-style: none; padding: 6px 11px; font-size: 12px; }
.legend summary::before { content: "▸ "; color: var(--muted); }
.legend[open] summary::before { content: "▾ "; }
.legend-grid { display: grid; grid-template-columns: auto auto; gap: 3px 16px; padding: 0 11px 9px; }
.legend .sep { grid-column: 1 / -1; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; font-size: 9.5px; margin-top: 5px; }
.legend i { display: inline-block; vertical-align: -1px; margin-right: 6px; }
.legend .sw { width: 9px; height: 9px; border-radius: 50%; }
.legend .ring { width: 11px; height: 11px; border-radius: 50%; border: 2px solid; }
.legend .ring.arc { border-color: #3fd18a #3fd18a transparent transparent; transform: rotate(-45deg); }
.legend .ln { width: 16px; height: 2px; vertical-align: 3px; background: var(--c); }
.legend .ln.dash { background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px); }

/* inspector floats over the scene when something is selected */
.inspector {
  position: absolute; right: 10px; top: 50px; width: 330px; max-height: calc(100% - 64px); overflow-y: auto;
  background: #121924f2; backdrop-filter: blur(8px); border: 1px solid var(--line-2);
  border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 30px #0009;
}
.inspector h3 { margin: 0 0 10px; font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding-right: 22px; }
.inspector .x { position: absolute; right: 8px; top: 6px; background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; padding: 4px; }
.inspector dl, .outcome dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; }
.inspector dt, .outcome dt { color: var(--muted); }
.inspector dd, .outcome dd { margin: 0; }
.inspector .sect { grid-column: 1 / -1; color: var(--faint); font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; margin-top: 4px; }
dd.good { color: var(--good); }
dd.bad { color: var(--bad); }
dd.warn { color: var(--warn); }
.inspector .note { margin: 10px 0 0; padding: 7px 9px; background: var(--panel-2); border-radius: 8px; color: var(--muted); }
.inspector .note.warn { color: var(--warn); background: #ffb5471a; }
.inspector p.muted { margin: 0; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.pill.own { background: #f5c54226; color: var(--own); }
.pill.trash { background: #3fd18a22; color: var(--good); }
.pill.bad { background: #ff5d5d22; color: var(--bad); }
.pill.warn { background: #ffb54722; color: var(--warn); }
.pill.info { background: #5aa9ff22; color: #8cc3ff; }

.hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 260px);
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px;
  color: var(--muted); font-size: 12px; text-align: center; pointer-events: none;
}

.status, .drop { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.status .msg {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; color: var(--muted); max-width: 420px; text-align: center;
}
.status.bad .msg { color: var(--bad); border-color: #ff5d5d55; }
.drop { background: #0e131bcc; pointer-events: auto; }
.drop div { border: 2px dashed var(--accent); border-radius: 16px; padding: 40px 60px; font-size: 16px; }

/* --- welcome ------------------------------------------------------------------------------- */
.welcome {
  position: absolute; inset: 0; overflow-y: auto; padding: 28px 20px;
  background: radial-gradient(1200px 600px at 30% 0%, #1b2a44 0%, transparent 60%), #0e131bf2;
  display: flex; justify-content: center; align-items: flex-start;
}
.welcome-card { position: relative; max-width: 760px; width: 100%; padding-top: 2vh; }
.welcome .x { position: absolute; right: 0; top: 0; background: none; border: 0; color: var(--muted); font-size: 24px; }
.eyebrow { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; margin: 0 0 6px; font-weight: 600; }
.welcome h1 { font-size: clamp(24px, 4vw, 34px); line-height: 1.15; margin: 0 0 12px; font-weight: 650; letter-spacing: -0.01em; }
.welcome .lead { font-size: 15px; color: #c3cdd9; margin: 0 0 18px; max-width: 64ch; }
.welcome h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 22px 0 10px; }
.howto { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.howto li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; color: #c3cdd9; }
.howto b { color: var(--text); font-weight: 600; }
.k { width: 26px; height: 26px; border-radius: 50%; display: block; margin-top: 1px; }
.k-real { background: radial-gradient(circle at 50% 35%, #f2d3b8 0 22%, #f08a4b 24%); }
.k-belief { border: 3px solid #5aa9ff; box-shadow: inset 0 0 0 4px var(--bg), inset 0 0 0 7px #3fd18a; }
.k-callout { border-radius: 7px; background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid #f5c542; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card-btn {
  text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; transition: border-color 0.15s, transform 0.15s;
}
.card-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.card-btn .t { font-weight: 600; font-size: 14px; display: flex; gap: 6px; align-items: center; }
.card-btn .t .tag { font-size: 10px; font-weight: 600; color: var(--accent); background: #4c8dff22; padding: 1px 6px; border-radius: 999px; }
.card-btn .d { color: var(--muted); font-size: 12px; line-height: 1.4; flex: 1; }
.seeds { display: flex; gap: 4px; flex-wrap: wrap; }
.seeds span { font-size: 10.5px; font-family: var(--mono); padding: 1px 6px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.seeds span.ok { color: var(--good); }
.seeds span.ko { color: var(--bad); }
.fineprint { color: var(--faint); font-size: 11.5px; margin-top: 18px; }

/* --- 3D labels ----------------------------------------------------------------------------- */
.lbl { font-size: 11px; line-height: 1.25; white-space: nowrap; pointer-events: none; color: var(--text); text-shadow: 0 1px 2px #000, 0 0 4px #000c; }
.lbl b { font-weight: 600; }
.lbl span { color: var(--muted); margin-left: 5px; }
.lbl-human, .lbl-robot { background: #0e131bc0; border: 1px solid #ffffff1a; border-radius: 6px; padding: 1px 6px; text-shadow: none; }
.lbl-robot { border-color: #4c8dff66; }
.lbl-robot span { color: #9fc2ff; }
.lbl-can { font-size: 10.5px; }
.lbl-can .own { color: var(--own); }
.lbl-bin { color: #5fd49b; font-size: 10px; }
.lbl-track { font-family: var(--mono); font-size: 10px; color: #b9d8ff; margin-top: 4px; }
.lbl-track em { font-style: normal; font-family: system-ui, sans-serif; font-weight: 600; margin-left: 4px; }
.lbl-track .w-owned { color: var(--own); }
.lbl-track .w-trash { color: var(--good); }
.lbl-track .w-target { color: var(--warn); }
.lbl-track .w-gaveup { color: var(--bad); }
.lbl-track .w-maybe { color: var(--faint); }
.lbl-htrack { color: #9fd3ffbb; }

.callout {
  background: #141b26f2; border: 1px solid var(--line); border-left: 3px solid var(--muted);
  border-radius: 8px; padding: 5px 9px; font-size: 12px; max-width: 260px; white-space: normal;
  box-shadow: 0 6px 18px #0008; text-shadow: none;
}
.callout i { font-style: normal; margin-right: 6px; }
.cat-good { border-left-color: #3fd18a; }
.cat-task { border-left-color: #ffb547; }
.cat-percept { border-left-color: #5aa9ff; }
.cat-people { border-left-color: #d59cff; }
.cat-bad { border-left-color: #ff5d5d; }
.cat-world { border-left-color: #f5c542; }

/* --- side panel ---------------------------------------------------------------------------- */
.side { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.card { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card.grow { flex: 1; min-height: 140px; display: flex; flex-direction: column; }
.card h2 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.card-head h2 { margin: 0; }
.state-pill { padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #333; color: #fff; }
.doing { margin: 4px 0 10px; font-size: 14px; line-height: 1.4; min-height: 2.8em; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stats div { background: var(--panel-2); border-radius: 8px; padding: 6px 8px; }
.stats b { display: block; font-size: 15px; font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.stats b small { font-size: 11px; color: var(--good); font-weight: 500; }
.stats span { color: var(--muted); font-size: 10.5px; white-space: nowrap; }

.feed { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; position: relative; }
.ev { display: grid; grid-template-columns: 42px 16px 1fr; gap: 6px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.ev:hover { background: var(--panel-2); }
.ev time { font-family: var(--mono); color: var(--faint); font-size: 11px; padding-top: 1px; }
.ev i { font-style: normal; text-align: center; }
.ev.minor { color: var(--muted); font-size: 12px; }
.ev.future { opacity: 0.35; }
.ev.now { background: #4c8dff1f; }

.outcome-card summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 10px; }
.outcome-card summary::-webkit-details-marker { display: none; }
.outcome-card summary h2 { margin: 0; }
.outcome-card summary h2::after { content: " ▸"; color: var(--faint); }
.outcome-card[open] summary h2::after { content: " ▾"; }
.outcome-summary { font-size: 12px; color: var(--muted); }
.outcome-summary b { color: var(--text); font-weight: 600; }
.outcome { margin-top: 10px; }
.outcome dl { grid-template-columns: 1fr auto 1fr auto; font-size: 12px; gap: 3px 8px; }
.outcome dt { white-space: nowrap; }
.outcome dd { font-family: var(--mono); text-align: right; }
.failures { margin: 8px 0 0; padding-left: 18px; color: var(--bad); }
.provenance { margin-top: 8px; font-size: 10px; color: var(--faint); font-family: var(--mono); }

/* --- timeline ------------------------------------------------------------------------------ */
.timebar { display: flex; align-items: center; gap: 12px; padding: 8px 14px 10px; border-top: 1px solid var(--line); background: var(--panel); }
.play { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 13px; flex: none; box-shadow: 0 0 14px #4c8dff55; }
.clock { font-family: var(--mono); color: var(--muted); width: 128px; flex: none; white-space: nowrap; }
.timeline-wrap { position: relative; flex: 1; min-width: 0; height: 100px; }
#timeline-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.tip {
  position: absolute; bottom: 100%; margin-bottom: 4px; background: #0e131bf2; border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 8px; font-size: 12px; max-width: 320px; pointer-events: none; white-space: nowrap;
}
.tip b { font-family: var(--mono); color: var(--muted); font-weight: 400; margin-right: 4px; }

body.no-run main { grid-template-columns: 1fr; }
body.no-run #help { margin-left: auto; }
body.no-run .side, body.no-run .timebar, body.no-run .stage-tools, body.no-run .layer-chips,
body.no-run .legend, body.no-run .run-info { display: none !important; }

/* --- narrower screens ---------------------------------------------------------------------- */
@media (max-width: 1100px) {
  main { grid-template-columns: 1fr 300px; }
  .layer-chips { max-width: calc(100% - 230px); }
  .run-desc { display: none; }
}
@media (max-width: 760px) {
  .wide-only { display: none !important; }
  .topbar { gap: 8px; padding: 8px 10px; }
  .brand { font-size: 14px; }
  #run-picker { flex: 1; max-width: none; }
  .run-info { display: none; }
  main { grid-template-columns: 1fr; grid-template-rows: minmax(330px, 58vh) auto; overflow-y: auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .card.grow { min-height: 0; flex: none; }
  #help { margin-left: 0; }
  .feed { max-height: 260px; flex: none; }
  .welcome { position: fixed; inset: 0; z-index: 20; }
  body.no-run main { grid-template-rows: 1fr; }
  .layer-chips {
    top: auto; bottom: 10px; left: 10px; right: 10px; max-width: none; flex-wrap: nowrap;
    overflow-x: auto; justify-content: flex-start; scrollbar-width: none;
  }
  .legend, .hint { display: none; }
  .inspector { left: 8px; right: 8px; top: auto; bottom: 50px; width: auto; max-height: 48%; padding: 10px 12px; }
  .stats span { font-size: 10px; }
  .timebar { gap: 8px; padding: 6px 10px 8px; }
  .clock { width: auto; font-size: 11px; }
  .clock .total { display: none; }
  .timeline-wrap { height: 76px; }
  .welcome { padding: 18px 14px; }
}
