:root {
  --ivory: #f3edde;
  --ivory-2: #e7eddc;
  --ink: #18332b;
  --muted: #60766d;
  --mint: #b9dec8;
  --mint-dark: #356b58;
  --terra: #cf704c;
  --copper: #ad5d3f;
  --line: rgba(37, 75, 62, .18);
  --panel: rgba(248, 245, 232, .92);
  --serif: Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--ivory-2); color: var(--ink); font-family: var(--sans); }
button, input { font: inherit; }
button, .load-button { border: 0; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, .load-button:focus-within { outline: 3px solid #e98a62; outline-offset: 3px; }

.live-header {
  height: 58px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  background: #f6f0e2;
  border-bottom: 1px solid var(--line);
}
.live-brand { color: var(--ink); font: 500 23px var(--serif); text-decoration: none; }
.archive-link { justify-self: end; color: var(--mint-dark); font-size: 12px; text-decoration: none; }
.live-state { display: flex; min-width: 0; align-items: center; gap: 8px; color: var(--muted); font: 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; }
.live-state span { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-state i { width: 8px; height: 8px; border-radius: 50%; background: #a8b4ad; box-shadow: 0 0 0 4px rgba(80, 105, 95, .08); }
.live-state.ready i { background: #55a879; box-shadow: 0 0 0 4px rgba(69, 165, 112, .13); }
.live-state.paused i { background: #d69855; }
.live-state.notice i { background: var(--terra); box-shadow: 0 0 0 4px rgba(207, 112, 76, .14); }
.live-state.failed i { background: #c75842; }

.live-shell { height: calc(100vh - 58px); display: grid; grid-template-columns: minmax(0, 1fr) 390px; }
.world-panel { position: relative; min-width: 0; overflow: hidden; background: radial-gradient(circle at 52% 28%, #d9e3cf 0, #aebfac 58%, #799889 100%); }
#world-canvas { display: block; width: 100%; height: 100%; touch-action: none; background: #aebdab; }
.world-wash { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 43%, transparent 56%, rgba(21,48,39,.08) 100%), linear-gradient(180deg, rgba(255,244,213,.025), transparent 30%, transparent 80%, rgba(17,45,35,.05)); }
.clock-card, .world-title, .camera-bar, .resident-list { position: absolute; z-index: 2; }
.clock-card { top: 18px; left: 20px; display: flex; gap: 18px; padding: 9px 12px; border: 1px solid rgba(255,255,255,.72); border-radius: 8px; background: rgba(246,241,224,.77); backdrop-filter: blur(12px); color: var(--muted); font: 10px var(--mono); text-transform: uppercase; }
.clock-card strong { margin-left: 5px; color: var(--ink); font-weight: 500; }
.world-title { right: 18px; top: 14px; padding: 8px 11px 7px; border: 1px solid rgba(246,241,224,.45); border-radius: 8px; background: rgba(238,241,218,.72); box-shadow: 0 5px 22px rgba(17,45,35,.12); backdrop-filter: blur(10px); color: var(--ink); text-align: right; }
.world-title span { display: block; color: #49645b; font: 10px var(--mono); text-transform: uppercase; letter-spacing: .1em; }
.world-title strong { font: 32px/1.1 var(--serif); text-shadow: 0 1px rgba(255,255,255,.35); }
.camera-bar { left: 20px; bottom: 22px; display: flex; padding: 4px; gap: 3px; border-radius: 8px; background: rgba(22,49,40,.86); backdrop-filter: blur(10px); }
.camera-bar button { padding: 8px 11px; border-radius: 5px; background: transparent; color: #dce9df; font-size: 11px; }
.camera-bar button[aria-pressed=true] { background: var(--ivory); color: var(--ink); }
.resident-list { right: 20px; bottom: 22px; display: flex; gap: 7px; }
.resident-list button { padding: 8px 13px; border-radius: 999px; background: rgba(248,244,230,.82); color: var(--ink); box-shadow: 0 3px 16px rgba(30,63,51,.12); font-size: 11px; }
.resident-list button[aria-pressed=true] { background: var(--terra); color: white; }

.instrument-panel { overflow-y: auto; border-left: 1px solid var(--line); background: #f7f2e5; }
.instrument-panel > section { padding: 20px; border-bottom: 1px solid var(--line); }
.section-head { display: flex; justify-content: space-between; gap: 12px; align-items: end; }
.section-head small { color: var(--muted); font: 9px var(--mono); text-transform: uppercase; letter-spacing: .12em; }
.section-head h2 { margin: 3px 0 0; font: 400 24px/1 var(--serif); }
.brain-card .section-head h2 { font-size: 29px; }
.section-head output { color: var(--muted); font: 10px var(--mono); }
.brain-card { background: #edf0df; }
.neural-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-top: 14px; padding: 3px; border-radius: 7px; background: rgba(24, 51, 43, .09); }
.neural-tabs button { padding: 7px; border-radius: 5px; background: transparent; color: var(--muted); font-size: 10px; }
.neural-tabs button[aria-selected=true] { background: #17342c; color: #f2eee0; }
[role=tabpanel][hidden] { display: none; }
#brain-canvas { display: block; width: 100%; height: 300px; margin: 14px 0 9px; border-radius: 10px; background: #091713; }
.brain-legend { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font: 8px var(--mono); text-transform: uppercase; }
.brain-legend span { display: flex; align-items: center; gap: 5px; }
.brain-legend i { width: 7px; height: 7px; border-radius: 50%; }
.brain-legend .negative { background: #f06e42; }
.brain-legend .positive { background: #5ce3d4; }
.scale-control { display: block; margin-top: 15px; }
.scale-control > span { display: flex; justify-content: space-between; font-size: 11px; }
.scale-control output { font-family: var(--mono); }
.activity-numbers { display: flex; justify-content: space-between; gap: 12px; margin: 10px 0; font-size: 10px; color: var(--muted); }
.activity-numbers output { display: block; margin-top: 3px; font-family: var(--mono); color: var(--ink); }
.scale-control input { width: 100%; accent-color: var(--terra); }
.rate-note, .control-card p { margin: 10px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.retina-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.retina-grid figure { min-width: 0; margin: 0; }
.retina-grid figcaption { margin: 0 0 5px; color: var(--muted); font: 8px var(--mono); text-align: center; text-transform: uppercase; letter-spacing: .1em; }
.retina-grid canvas { display: block; width: 100%; aspect-ratio: .78; border-radius: 8px; background: #07100e; }
.retina-legend { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--muted); font: 8px var(--mono); }
.retina-legend span { display: flex; align-items: center; gap: 5px; }
.retina-legend i { width: 8px; height: 8px; border-radius: 2px; background: linear-gradient(135deg, #c65d3f, #50bca7); }
.retina-legend .unsupported { background: transparent; border: 1px solid #70847a; }
.retina-count { margin: 12px 0 0; color: var(--ink); font: 10px var(--mono); text-align: center; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 14px; }
.segmented button { padding: 9px 4px; border: 1px solid var(--line); border-radius: 6px; background: #f6f1e4; color: var(--ink); font-size: 10px; }
.segmented button[aria-pressed=true] { border-color: var(--mint-dark); background: var(--mint-dark); color: white; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 14px; }
.action-grid button { min-height: 42px; padding: 8px; border-radius: 6px; background: #dce9dc; color: var(--ink); font-size: 10px; }
.action-grid button:first-child { grid-column: 1 / -1; background: #edd4ba; }
.action-grid button:disabled { opacity: .42; cursor: not-allowed; }
.encounter-card { background: #f0eadc; }
.encounter-steps { display: grid; gap: 8px; margin-top: 13px; }
.encounter-step { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.encounter-step legend { width: 100%; padding: 0; color: var(--ink); font: 10px var(--mono); }
.encounter-step legend button { float: right; padding: 0; background: transparent; color: var(--copper); font: 8px var(--mono); }
.encounter-step label { display: grid; gap: 3px; color: var(--muted); font: 8px var(--mono); }
.encounter-step label:first-of-type, .encounter-target { grid-column: 1 / -1; }
.encounter-step input, .encounter-step select, .encounter-add select { min-width: 0; width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 4px; background: #faf7ef; color: var(--ink); font: 9px var(--mono); }
.encounter-step input[type=color] { height: 29px; padding: 2px; }
.encounter-target { margin: 0; color: var(--muted); font: 9px var(--mono); overflow-wrap: anywhere; }
.encounter-add { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 8px; }
.encounter-add button, .encounter-send { padding: 8px 10px; border-radius: 5px; background: #dce9dc; color: var(--ink); font-size: 9px; }
.encounter-send { width: 100%; margin-top: 7px; background: var(--ink); color: white; }
.encounter-add button:disabled, .encounter-send:disabled { opacity: .43; cursor: not-allowed; }
.encounter-status, .encounter-native-status { display: block; margin-top: 8px; color: var(--muted); font: 9px/1.45 var(--mono); }
.encounter-native-status { color: var(--mint-dark); }
.checkpoint-card { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.checkpoint-card button, .load-button { padding: 10px 5px; border-radius: 6px; background: var(--ink); color: white; text-align: center; font-size: 10px; }
.load-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.identity-card { color: var(--muted); font-size: 9px; line-height: 1.4; }
.identity-card p { display: grid; grid-template-columns: 78px 1fr; gap: 8px; margin: 4px 0; }
.identity-card strong { color: var(--ink); font-weight: 650; }

.start-layer { position: fixed; z-index: 20; inset: 58px 0 0; display: grid; place-items: center; padding: 24px; background: rgba(225,235,219,.82); backdrop-filter: blur(18px); }
.start-layer[hidden] { display: none; }
.start-card { width: min(520px, 100%); padding: 40px; border: 1px solid rgba(47,91,74,.23); border-radius: 16px; background: rgba(248,244,231,.96); box-shadow: 0 28px 80px rgba(32,68,54,.18); }
.eyebrow { margin: 0; color: var(--terra); font: 10px var(--mono); text-transform: uppercase; letter-spacing: .15em; }
.start-card h1 { margin: 10px 0 12px; font: 400 49px/.95 var(--serif); }
.start-card > p:not(.eyebrow) { color: var(--muted); font-size: 13px; line-height: 1.55; }
.start-card button { width: 100%; padding: 14px; border-radius: 7px; background: var(--terra); color: white; font-weight: 650; }
.load-track { height: 5px; margin: 24px 0 8px; overflow: hidden; border-radius: 10px; background: #d5ddd2; }
.load-track i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--mint-dark), var(--terra)); transition: width .25s; }
.load-track.indeterminate i { animation: loading-sweep 1.15s ease-in-out infinite alternate; }
@keyframes loading-sweep { from { transform: translateX(-70%); } to { transform: translateX(165%); } }
.load-detail { min-height: 20px; margin: 0 0 14px !important; font: 10px var(--mono) !important; }
.support-note { margin-bottom: 0 !important; font-size: 10px !important; }
.load-button:has(input:disabled) { opacity: .45; cursor: not-allowed; }

@media (max-width: 900px) {
  body { overflow: auto; }
  .live-header { grid-template-columns: 1fr auto; }
  .live-state { display: none; }
  .live-shell { height: auto; min-height: calc(100vh - 58px); grid-template-columns: 1fr; }
  .world-panel { height: 68vh; min-height: 480px; }
  .instrument-panel { overflow: visible; border-top: 1px solid var(--line); border-left: 0; }
  .instrument-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .brain-card, .identity-card { grid-column: 1 / -1; }
}

@media (max-width: 580px) {
  .live-header { padding: 0 14px; }
  .archive-link { font-size: 10px; }
  .world-panel { height: 66vh; min-height: 430px; }
  .clock-card { right: 12px; left: 12px; flex-wrap: wrap; }
  .world-title { top: 76px; right: 14px; }
  .world-title strong { font-size: 25px; }
  .camera-bar { left: 12px; bottom: 14px; }
  .resident-list { right: 12px; bottom: 62px; }
  .instrument-panel { display: block; }
  #brain-canvas { height: 340px; }
  .start-card { padding: 28px 24px; }
  .start-card h1 { font-size: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .load-track.indeterminate i { animation: none; transform: none; }
}

.tone-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 10px; }
.tone-controls button { padding: 10px 2px; border: 1px solid var(--line); border-radius: 6px; background: #f6f1e4; color: var(--ink); font: 10px var(--mono); }
.motor-output { margin-top: 12px; max-height: 430px; overflow-y: auto; scrollbar-width: thin; }
.motor-output details { border-top: 1px solid var(--line); padding: 5px 0; }
.motor-output summary { font: 11px var(--mono); cursor: pointer; padding: 3px 0; }
.motor-channel { display: grid; grid-template-columns: minmax(100px, 1fr) 65px 32px; align-items: center; gap: 7px; min-height: 17px; font: 9px var(--mono); color: var(--muted); }
.motor-channel output { text-align: right; font-variant-numeric: tabular-nums; }
.motor-track { position: relative; height: 6px; background: #183c33; overflow: hidden; }
.motor-track[data-signed="true"]::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: #c6d9ca88; }
.motor-track i { position: absolute; height: 100%; background: #a1dfb2; }
.motor-track i[data-negative="true"] { background: #e5aa89; }

.plasticity-card { background: #eef0e3; }
.plasticity-action { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 7px 9px; margin-top: 13px; }
.plasticity-action button { padding: 8px 10px; border-radius: 5px; background: var(--ink); color: white; font-size: 10px; }
.plasticity-action button:disabled { opacity: .45; cursor: not-allowed; }
.plasticity-action label { display: flex; align-items: center; justify-content: end; gap: 5px; color: var(--muted); font: 8px var(--mono); }
.plasticity-action select { min-width: 0; padding: 6px 4px; border: 1px solid var(--line); border-radius: 4px; background: #f7f3e8; color: var(--ink); font: 8px var(--mono); }
.plasticity-action span { grid-column: 1 / -1; color: var(--muted); font: 9px/1.35 var(--mono); }
.plasticity-map { margin: 13px 0 0; }
.plasticity-map figcaption { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; color: var(--muted); font: 8px var(--mono); }
.plasticity-map canvas { display: block; width: 100%; height: 34px; border-radius: 4px; background: #132f28; image-rendering: pixelated; }
.plasticity-targets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.plasticity-targets p { display: grid; gap: 3px; margin: 0; padding: 7px; border: 1px solid var(--line); border-radius: 5px; }
.plasticity-targets strong { font: 9px var(--mono); }
.plasticity-targets small { color: var(--muted); font: 8px var(--mono); }
.plasticity-targets output { color: var(--mint-dark); font: 8px/1.4 var(--mono); }
.plasticity-identity { overflow-wrap: anywhere; font-family: var(--mono); }

.neural-field-control { display:grid; gap:.4rem; margin:.7rem 0; font-size:.8rem; }
.neural-field-control select { width:100%; padding:.55rem; color:inherit; background:#edf1e5; border:1px solid #bac8af; border-radius:.4rem; font:inherit; }
.neural-tabs { grid-template-columns: repeat(3, 1fr); }
.sense-caption { display: flex; justify-content: space-between; gap: 8px; margin: 17px 0 8px; color: var(--ink); font: 10px var(--mono); }
.sense-caption output { color: var(--muted); }
.acoustic-bands { display: grid; grid-template-columns: repeat(16, 1fr); height: 100px; gap: 3px; padding: 8px 6px 0; border-radius: 6px; background: #123c32; }
.acoustic-bands > span { position: relative; background: #ffffff09; }
.acoustic-bands i { position: absolute; bottom: 0; width: 100%; height: 0; background: linear-gradient(#eed1a2, #69bf9b); }
.sense-axis { display: flex; justify-content: space-between; margin-top: 5px; font: 9px var(--mono); color: var(--muted); }
.foot-senses { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font: 9px var(--mono); }
.foot-senses > div { display: grid; gap: 4px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.foot-senses output { color: var(--mint-dark); font-variant-numeric: tabular-nums; }
.body-readouts { font: 9px/1.4 var(--mono); }
.body-readouts > div { display: flex; justify-content: space-between; gap: 8px; margin: 8px 0; }
.body-readouts dt { color: var(--muted); }
.body-readouts dd { margin: 0; text-align: right; }

.neuron-inspector { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.neuron-inspector > summary { cursor: pointer; font-size: 13px; }
.neuron-search { margin-top: 12px; font-size: 11px; }
.neuron-search > div { display: flex; gap: 6px; margin-top: 5px; }
.neuron-search input { width: 100%; min-width: 0; padding: 8px; border: 1px solid var(--line); background: #faf7ef; border-radius: 4px; font: 11px var(--mono); }
.neuron-search button { border: 1px solid var(--line); border-radius: 4px; background: #dfebd8; padding: 6px 12px; color: var(--ink); }
.neuron-results { display: grid; gap: 4px; max-height: 175px; overflow-y: auto; }
.neuron-results button { text-align: left; border: 0; border-bottom: 1px solid var(--line); padding: 6px 0; background: transparent; color: var(--ink); font: 10px var(--mono); overflow-wrap: anywhere; cursor: pointer; }
.neuron-inspector h3 { margin: 16px 0 8px; font-size: 17px; }
.neuron-inspector dl { display: grid; grid-template-columns: 98px minmax(0, 1fr); gap: 7px 10px; font: 10px/1.5 var(--mono); }
.neuron-inspector dt { color: var(--muted); }
.neuron-inspector dd { margin: 0; overflow-wrap: anywhere; }
.neuron-inspector details details { margin: 6px 0; }
.neuron-inspector [data-cell-details] > details { font: 10px/1.5 var(--mono); margin: 6px 0; }
.neuron-inspector ul { padding-left: 16px; overflow-wrap: anywhere; }
.neuron-value { display: block; margin: 12px 0 6px; font: 9px/1.6 var(--mono); overflow-wrap: anywhere; }
.neuron-trace { display: block; width: 100%; height: 100px; border-radius: 5px; }
