:root {
  color-scheme: dark;
  --bg: #03090f;
  --panel: #06131c;
  --panel-2: #071b24;
  --line: #0b5b6c;
  --line-strong: #1ce8ed;
  --cyan: #55f6ff;
  --text: #e8faff;
  --muted: #7699a6;
  --green: #51ef99;
  --amber: #ffba5a;
  --violet: #ba75ff;
  --danger: #ff6f74;
  --shadow: 0 0 0 1px #073947, 0 0 20px #04c9df1c, inset 0 1px #56f6ff18;
  font-family: "Bahnschrift", "Arial Narrow", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; min-height: 100%; margin: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 68% -8%, #073a5350, transparent 34rem),
    radial-gradient(circle at 15% 115%, #083e4c45, transparent 42rem),
    linear-gradient(135deg, #02070c 0%, #041019 48%, #03070c 100%);
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.nexus-shell {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 9px;
  border-right: 1px solid #0b5567;
  background: linear-gradient(180deg, #05141d, #030b12 82%);
  box-shadow: 4px 0 24px #000b;
  z-index: 3;
}
.rail::after {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  opacity: .78;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 5px 18px;
  color: var(--cyan);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .08em;
  white-space: nowrap;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--cyan);
  color: var(--cyan);
  clip-path: polygon(50% 0, 94% 24%, 94% 76%, 50% 100%, 6% 76%, 6% 24%);
  text-shadow: 0 0 9px var(--cyan);
}
.rail-nav { display: grid; gap: 5px; }
.nav-button {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 10px 7px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #a4c0c9;
  text-align: left;
  font-size: 11px;
  cursor: pointer;
}
.nav-button:hover { background: #0a2832; color: var(--text); }
.nav-button.is-active {
  border-color: #118b99;
  background: linear-gradient(90deg, #075764, #07313b);
  color: var(--cyan);
  box-shadow: inset 0 0 15px #12dce322;
}
.nav-icon {
  color: currentColor;
  font-size: 15px;
  line-height: 1;
  text-align: center;
}
.rail-foot {
  margin-top: auto;
  padding: 10px 5px 4px;
  border-top: 1px solid #0a3542;
  color: var(--muted);
  font: 9px/1.45 Consolas, monospace;
}
.rail-foot b { color: var(--green); font-weight: 700; }

.operator {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 65px;
  padding: 10px 18px;
  border-bottom: 1px solid #0a6070;
  background: linear-gradient(180deg, #071923e8, #041019ed);
  box-shadow: 0 3px 20px #0009;
  z-index: 2;
}
.eyebrow {
  color: var(--cyan);
  font: 700 10px/1 Consolas, monospace;
  letter-spacing: .14em;
}
.view-title {
  margin: 4px 0 0;
  color: #f4feff;
  font-size: clamp(16px, 1.6vw, 23px);
  font-stretch: condensed;
  letter-spacing: .055em;
}
.top-metrics {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}
.metric-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  min-height: 25px;
  padding: 5px 8px;
  border: 1px solid #0b4757;
  background: #061923;
  color: var(--muted);
  font: 10px/1 Consolas, monospace;
  white-space: nowrap;
}
.metric-chip b { color: var(--text); font-weight: 700; }
.metric-chip.is-live b { color: var(--green); }
.metric-chip.is-alert b { color: var(--amber); }
.controls {
  display: flex;
  gap: 5px;
  align-items: center;
  margin-left: auto;
}
.control-button {
  min-width: 34px;
  height: 31px;
  border: 1px solid #0b7283;
  background: #06222d;
  color: #bceff2;
  cursor: pointer;
  font: 700 11px/1 Consolas, monospace;
}
.control-button:hover, .control-button.is-active {
  border-color: var(--cyan);
  background: #0a5968;
  box-shadow: inset 0 0 13px #50faff28, 0 0 12px #30e9ec26;
}
.control-button.pause { min-width: 72px; }

.operator-grid {
  display: grid;
  grid-template-columns: minmax(196px, 16vw) minmax(400px, 1fr) minmax(252px, 20vw);
  gap: 10px;
  min-height: 0;
  padding: 10px;
}
.context-column {
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: #127a89 #06151e;
}
.panel {
  margin-bottom: 10px;
  border: 1px solid #0d5666;
  background: linear-gradient(145deg, #071925e8, #041018eb);
  box-shadow: var(--shadow);
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  min-height: 32px;
  margin: 0;
  padding: 8px 9px;
  border-bottom: 1px solid #0d5060;
  color: #c8f7fb;
  font: 700 11px/1 Consolas, monospace;
  letter-spacing: .08em;
}
.panel-title small { color: var(--muted); font-weight: 400; letter-spacing: 0; }
.panel-body { padding: 9px; }
.subtle { color: var(--muted); font-size: 11px; }
.empty { padding: 8px 0; color: var(--muted); font-size: 11px; }

.stage-column {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}
.stage-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow: auto hidden;
  padding: 0 3px;
}
.stage-tab {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid #0c5060;
  background: #061720;
  color: var(--muted);
  font: 10px/1 Consolas, monospace;
  cursor: pointer;
}
.stage-tab:hover, .stage-tab.is-active { color: var(--cyan); border-color: var(--cyan); background: #08303b; }
.stage-tab .tab-dot { color: var(--green); margin-right: 4px; }
.world-frame {
  position: relative;
  min-width: 0;
  min-height: 390px;
  overflow: hidden;
  border: 1px solid #14b8c2;
  background:
    linear-gradient(#07304033 1px, transparent 1px),
    linear-gradient(90deg, #07304033 1px, transparent 1px),
    #020b12;
  background-size: 22px 22px;
  box-shadow: 0 0 0 1px #064250, 0 0 28px #00c8df26, inset 0 0 48px #000b;
}
.world-frame::before, .world-frame::after {
  content: "";
  position: absolute;
  z-index: 2;
  width: 15px;
  height: 15px;
  pointer-events: none;
}
.world-frame::before {
  inset: 8px auto auto 8px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
}
.world-frame::after {
  inset: auto 8px 8px auto;
  border-right: 2px solid var(--cyan);
  border-bottom: 2px solid var(--cyan);
}
#world {
  width: 100%;
  height: 100%;
}
#world canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  cursor: crosshair;
  image-rendering: pixelated;
}
.stage-hud {
  position: absolute;
  z-index: 3;
  left: 12px;
  bottom: 10px;
  max-width: min(70%, 440px);
  padding: 7px 9px;
  border: 1px solid #0b6676;
  background: #03131ccf;
  color: #a9dce2;
  font: 10px/1.35 Consolas, monospace;
  pointer-events: none;
}
.stage-hud b { color: var(--cyan); }
.stage-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid #0a4655;
  background: #051720;
  color: var(--muted);
  font: 10px/1 Consolas, monospace;
}
.stage-status b { color: var(--cyan); }

.space-list, .agent-list, .event-feed, .compact-list { display: grid; gap: 5px; }
.space-button, .agent-button {
  display: grid;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px;
  border: 1px solid #0a4050;
  background: #061923;
  color: #bddde2;
  text-align: left;
  cursor: pointer;
}
.space-button { grid-template-columns: 8px minmax(0, 1fr) auto; }
.agent-button { grid-template-columns: 24px minmax(0, 1fr) auto; }
.space-button:hover, .agent-button:hover, .space-button.is-selected, .agent-button.is-selected {
  border-color: #16cdda;
  background: #09313c;
  color: #f0ffff;
}
.space-dot, .agent-orb {
  flex: 0 0 auto;
  border: 1px solid #b8faff;
  box-shadow: 0 0 9px currentColor;
}
.space-dot { width: 8px; height: 8px; border-radius: 50%; }
.agent-orb {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #0a3541;
  color: var(--cyan);
  font: 700 9px/1 Consolas, monospace;
}
.agent-button .name, .space-button .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-button .meta, .space-button .meta { color: var(--muted); font: 9px/1.3 Consolas, monospace; }
.pill {
  padding: 3px 5px;
  border: 1px solid #0a6070;
  color: var(--cyan);
  background: #06232d;
  font: 9px/1 Consolas, monospace;
}
.pill.online { border-color: #199c65; color: var(--green); }
.pill.moving { border-color: #4db8ea; color: #78dfff; }
.pill.warn { border-color: #ba7952; color: var(--amber); }

.key-value {
  display: grid;
  grid-template-columns: minmax(78px, 42%) 1fr;
  gap: 6px 8px;
  margin: 0;
  font-size: 11px;
}
.key-value dt { color: var(--muted); }
.key-value dd { min-width: 0; margin: 0; color: #d8f0f2; overflow-wrap: anywhere; }
.key-value dd strong { color: var(--cyan); }
.divider { height: 1px; margin: 10px 0; background: #0a4351; }
.need-row { display: grid; grid-template-columns: 58px 1fr 31px; align-items: center; gap: 6px; margin: 5px 0; color: var(--muted); font: 10px/1 Consolas, monospace; }
.meter { position: relative; height: 7px; overflow: hidden; border-radius: 8px; background: #09232d; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #1fc6df, #62f4ff); box-shadow: 0 0 10px #47f4ff8c; }
.meter.energy > i { background: linear-gradient(90deg, #3edafa, #69edff); }
.meter.hunger > i { background: linear-gradient(90deg, #e96cb6, #cf7eff); }
.meter.social > i { background: linear-gradient(90deg, #a875ff, #ed78ff); }
.meter.good > i { background: linear-gradient(90deg, #2acb7e, #65ffad); }
.need-row em { color: #bdeff2; font-style: normal; text-align: right; }

.event {
  padding: 7px 0;
  border-bottom: 1px solid #0a3744;
  color: #bdd9de;
  font-size: 10px;
  line-height: 1.35;
}
.event:last-child { border-bottom: 0; }
.event time { color: #6e9ca6; }
.event strong { color: var(--cyan); font-weight: 700; }
.event .event-text { display: block; padding-top: 3px; color: #a9cbd0; }
.feed-scroll { max-height: min(48vh, 490px); overflow: auto; }

.mini-map {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #0a6979;
  background: #020b12;
  image-rendering: pixelated;
}
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 8px; margin-top: 8px; color: var(--muted); font: 9px/1.3 Consolas, monospace; }
.legend i { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; vertical-align: middle; }
.toggle-list { display: grid; gap: 6px; }
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px;
  border: 1px solid #0a4654;
  background: #061923;
  color: #bfdee2;
  font: 10px/1 Consolas, monospace;
  cursor: pointer;
}
.toggle:hover { border-color: #0e96a8; }
.toggle b { color: var(--green); }
.toggle.is-off b { color: #597680; }

.space-hero {
  position: relative;
  min-height: 78px;
  padding: 11px;
  border: 1px solid #0b6170;
  overflow: hidden;
  background: linear-gradient(115deg, #092c36, #06141d);
}
.space-hero::after {
  content: "";
  position: absolute;
  right: -16px;
  bottom: -20px;
  width: 100px;
  height: 100px;
  border: 18px solid #25dceb22;
  border-radius: 50%;
}
.space-hero h3 { position: relative; margin: 0 0 5px; color: var(--cyan); font-size: 15px; letter-spacing: .06em; }
.space-hero p { position: relative; margin: 0; color: #b8d5d9; font-size: 11px; }
.object-row {
  display: grid;
  grid-template-columns: 17px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid #0a3542;
  color: #c6e5e8;
  font-size: 10px;
}
.object-row:last-child { border-bottom: 0; }
.object-icon { color: var(--amber); font-size: 15px; }
.object-row small { color: var(--muted); }

.research-stat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px;
  padding: 8px 0;
  border-bottom: 1px solid #0a3744;
  color: #a9cbd1;
  font-size: 10px;
}
.research-stat b { color: var(--cyan); font: 700 13px/1 Consolas, monospace; }
.chain {
  display: grid;
  gap: 6px;
  padding: 6px 0;
  color: #a7c9cf;
  font: 10px/1.4 Consolas, monospace;
}
.chain span { padding: 6px 7px; border-left: 2px solid #12bfcd; background: #071d27; }
.chain span:last-child { color: var(--green); border-color: var(--green); }

@media (max-width: 1150px) {
  .operator-grid { grid-template-columns: minmax(180px, 23vw) minmax(360px, 1fr); }
  .right-context { display: none; }
}
@media (max-width: 790px) {
  .nexus-shell { grid-template-columns: 1fr; }
  .rail {
    position: sticky;
    top: 0;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 7px;
    border-right: 0;
    border-bottom: 1px solid #0b5567;
  }
  .brand { padding: 4px 6px; }
  .rail-nav { display: flex; gap: 4px; }
  .nav-button { display: block; padding: 7px; font-size: 9px; white-space: nowrap; }
  .nav-icon { display: none; }
  .rail-foot { display: none; }
  .topbar { align-items: flex-start; flex-wrap: wrap; gap: 8px; padding: 9px; }
  .controls { margin-left: 0; }
  .operator-grid { grid-template-columns: 1fr; padding: 7px; }
  .left-context { max-height: 175px; }
  .world-frame { min-height: 360px; }
}
