:root {
  --bg: #080808;
  --surface: #101010;
  --surface-2: #161616;
  --border: #1f1f1f;
  --text: #c2c2c2;
  --text-dim: #6e6e6e;
  --text-bright: #d4d4d4;
  --accent: #32c5c1;
  --sp: 0.25rem;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--sp) * 4);
  gap: calc(var(--sp) * 4);
}

/* desktop: the page fits the viewport, only the feeds scroll */
@media (min-width: 1001px) {
  body { height: 100vh; overflow: hidden; }
}

/* header */
header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: calc(var(--sp) * 4);
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: calc(var(--sp) * 4);
}

h1 {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-bright);
  letter-spacing: 0.02em;
}

.sub { color: var(--text-dim); font-size: 0.8rem; margin-top: calc(var(--sp)); }

.clock { text-align: right; font-size: 0.85rem; }
.clock-line { color: var(--text); }
.dim { color: var(--text-dim); }

/* layout */
main {
  display: flex;
  gap: calc(var(--sp) * 4);
  flex: 1;
  min-height: 0;
}

.stage {
  flex: 1;
  min-width: 0;
  position: relative;
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  border: 1px solid var(--border);
  background: #050508;
  overflow: visible;
}

canvas#map {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
  cursor: grab;
}

/* side panels: the chat, pinned to the right edge */
.side {
  flex: 0 0 440px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: calc(var(--sp) * 4);
  min-height: 0;
}

@media (max-width: 1200px) {
  .side { flex-basis: 380px; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  padding: calc(var(--sp) * 2) calc(var(--sp) * 4);
  border-bottom: 1px solid var(--border);
}

.feed-panel { flex: 1; }

.feed {
  flex: 1;
  overflow-y: auto;
  padding: calc(var(--sp) * 2);
  font-size: 0.78rem;
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a transparent;
}

.feed::-webkit-scrollbar { width: 6px; }
.feed::-webkit-scrollbar-thumb { background: #2a2a2a; }

.feed .ev {
  padding: calc(var(--sp) * 1.5) calc(var(--sp) * 2);
  border-bottom: 1px solid #131313;
  animation: fadein 0.4s ease;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.feed .ev .t { color: var(--text-dim); font-size: 0.68rem; margin-right: 0.5rem; }
.feed .ev .say { color: var(--text-bright); white-space: pre-wrap; }
.feed .ev .thought { color: var(--text-dim); font-style: italic; }
.feed .ev .note { color: var(--text-dim); }
.feed .ev .arch { color: var(--accent); }
.feed .ev .agent-name { font-weight: 500; }

/* movements read differently from observations */
.feed .ev.move {
  border-left: 2px solid #222;
  padding-left: calc(var(--sp) * 1.5);
}
.feed .ev.move .mv { color: #6f6f6f; }

/* agents panel */
.agents-panel { flex: 0 0 auto; }

.agents {
  display: flex;
  flex-direction: column;
  padding: calc(var(--sp) * 2);
  gap: calc(var(--sp) * 2);
}

.agent-card {
  display: flex;
  align-items: center;
  gap: calc(var(--sp) * 3);
  padding: calc(var(--sp) * 2);
  border: 1px solid #1a1a1a;
  cursor: pointer;
  transition: border-color 0.2s;
}

.agent-card:hover { border-color: #333; }

.agent-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
}

.agent-info { flex: 1; min-width: 0; }

.agent-name { font-size: 0.85rem; color: var(--text-bright); }

.agent-meta { font-size: 0.68rem; color: var(--text-dim); }

.agent-energy {
  height: 3px;
  background: #1a1a1a;
  margin-top: calc(var(--sp));
  width: 100%;
}

.agent-energy .fill { height: 100%; background: var(--accent); transition: width 0.6s ease; }

/* bubbles */
.bubble {
  position: absolute;
  max-width: 200px;
  background: #141414;
  border: 1px solid #2c2c2c;
  color: var(--text-bright);
  font-size: 0.72rem;
  line-height: 1.4;
  padding: 0.4rem 0.55rem;
  z-index: 20;
  pointer-events: none;
  animation: bubble-in 0.25s ease;
  transform-origin: bottom center;
}

.bubble::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  margin-left: -4px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #2c2c2c;
}

.bubble-whisper { border-style: dashed; background: #101014; }
.bubble-group { border-style: dashed; background: #13130f; }
.bubble-broadcast { background: #0d1616; }

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(4px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* hover tooltip: the last thought */
.agent-tip {
  position: absolute;
  z-index: 30;
  pointer-events: none;
  max-width: 220px;
  background: #101010;
  border: 1px solid #2a2a2a;
  padding: 0.45rem 0.6rem;
  font-size: 0.7rem;
}

.tip-name { font-weight: 500; margin-bottom: 0.15rem; }
.tip-thought { color: var(--text-dim); font-style: italic; line-height: 1.4; }

/* footer */
footer {
  border-top: 1px solid var(--border);
  padding-top: calc(var(--sp) * 3);
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: calc(var(--sp) * 2) calc(var(--sp) * 4);
  cursor: pointer;
  border-bottom: 1px solid transparent;
  margin-bottom: -1px;
}

.tab:hover { color: var(--text-bright); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.feed.pane { display: none; }
.feed.pane.active { display: block; }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: calc(var(--sp) * 6);
}

/* display:flex would override the hidden attribute, so state it explicitly */
.modal[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  max-width: 620px;
  width: 100%;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--sp) * 3) calc(var(--sp) * 4);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-bright);
}

.close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: calc(var(--sp));
}

.close:hover { color: var(--text-bright); }

.modal-tabs { border-bottom: 1px solid var(--border); }

.profile-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.ptab { display: none; padding: calc(var(--sp) * 4); }
.ptab.active { display: block; }

.arch-note {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: calc(var(--sp) * 3);
}

.nat { font-size: 0.8rem; line-height: 1.7; color: var(--text); }

.mind-thought {
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-bottom: calc(var(--sp) * 4);
  border-left: 2px solid var(--border);
  padding-left: calc(var(--sp) * 3);
}

.mem {
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}

.stat-table { font-size: 0.75rem; }
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: calc(var(--sp) * 1.5) 0;
  border-bottom: 1px solid #131313;
}
.stat-k { color: var(--text-dim); }
.stat-v { color: var(--text-bright); }

.journal-text {
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}

#ptab-journal { font-size: 0.75rem; line-height: 1.6; white-space: pre-wrap; color: var(--text); }

/* connection lost */
.conn {
  position: fixed;
  bottom: calc(var(--sp) * 4);
  right: calc(var(--sp) * 4);
  font-size: 0.7rem;
  color: #c26b5b;
  border: 1px solid #3a201c;
  background: #14100f;
  padding: calc(var(--sp) * 2) calc(var(--sp) * 3);
  z-index: 60;
}

/* responsive */
@media (max-width: 1000px) {
  main { flex-direction: column; justify-content: flex-start; }
  .stage { width: 100%; }
  .canvas-wrap { position: relative; width: 100%; height: auto; aspect-ratio: 1; }
  canvas#map { width: 100%; height: 100%; }
  .side {
    max-width: none;
    width: 100%;
    flex: 0 1 auto;
  }
  .feed-panel {
    flex: 0 1 auto;
    max-height: 45vh;
    min-height: 140px;
  }
  .feed {
    min-height: 0;
    max-height: calc(45vh - 3.4rem);
  }
  .agents-panel { flex: 0 0 auto; }
  .clock { text-align: left; }
  header { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 480px) {
  body { padding: calc(var(--sp) * 3); }
  .feed { font-size: 0.72rem; }
  .bubble { max-width: 70vw; }
}
