:root {
  color-scheme: dark;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  color: #e8e8df;
  background: #151714;
  --panel: #1d201c;
  --line: #383c33;
  --muted: #a5a99d;
  --orange: #f0b16e;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, select, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, select:focus-visible, canvas:focus-visible, input:focus-visible, .trace-body:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.25rem;
  align-items: center;
  min-height: 4.75rem;
  padding: .85rem clamp(.9rem, 3vw, 2rem);
  background: #1a1d19;
  border-bottom: 1px solid var(--line);
}
.identity {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: .7rem;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: -.045em;
  font-size: clamp(1rem, 2.2vw, 1.4rem);
}
.identity strong { color: var(--orange); }
.identity-mark { width: 2rem; height: 2rem; color: var(--orange); }
.session { display: flex; gap: .7rem; align-items: center; }
.session label { color: var(--muted); font-size: .875rem; }
.session select {
  width: clamp(10rem, 22vw, 18rem);
  color: inherit;
  background: #262a23;
  border: 1px solid #42463a;
  border-radius: .45rem;
  padding: .55rem .8rem;
}
.feed-state {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  white-space: nowrap;
  font-size: .875rem;
}
.feed-state::before {
  content: "";
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
  background: currentColor;
}
.feed-state[data-state="live"] { color: #a8d29b; }
.feed-state[data-state="replay"] { color: #c2b9e2; }
.feed-state[data-state="stale"], .feed-state[data-state="error"] { color: #f2ae84; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 25vw);
  gap: 1rem;
  height: calc(100dvh - 4.75rem);
  min-height: 37rem;
  padding: 1rem;
  max-width: 190rem;
  margin-inline: auto;
}
.world-panel, .trace-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .7rem;
}
.map-header, .trace-header {
  min-height: 4.15rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--line);
}
.map-header, .trace-title, .map-actions {
  display: flex;
  align-items: center;
  gap: .65rem;
}
.map-header, .trace-title { justify-content: space-between; }
.world-title { min-width: 0; }
.world-title h1, .trace-title h2, .inspector h2 { margin: 0; font-size: 1rem; letter-spacing: -.025em; }
.world-title h1 { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.world-title span { display: block; margin-top: .15rem; color: var(--muted); font-size: .8rem; }
.world-title span:empty { display: none; }
.control, .trace-filters button {
  border: 1px solid #43473c;
  color: #d8dacf;
  border-radius: .38rem;
  padding: .43rem .68rem;
  background: #252921;
  font-size: .875rem;
  white-space: nowrap;
}
.control:hover, .trace-filters button:hover { background: #31362b; }
.control[aria-pressed="true"], .trace-filters button[aria-pressed="true"] {
  color: #f6c890;
  background: #3a2e20;
  border-color: #876843;
}

.viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: #10140f;
}
#world-map {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
#world-map:active { cursor: grabbing; }
#world-map:focus-visible { outline-offset: -3px; }
.viewport-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: .7rem;
  text-align: center;
  padding: 1.5rem;
  background: #10140fe6;
  color: #d0d3c7;
}
.viewport-message p { max-width: 25rem; margin: 0; }
.map-readout {
  pointer-events: none;
  position: absolute;
  display: flex;
  gap: .7rem;
  top: .7rem;
  left: .7rem;
  align-items: center;
  background: #111610e8;
  border: 1px solid #ffffff24;
  border-radius: .3rem;
  padding: .36rem .58rem;
  font: .77rem var(--mono);
}
#map-tick { color: #b7baab; }
.research {
  position: absolute;
  top: 2.8rem;
  left: .7rem;
  max-width: min(17rem, calc(100% - 4rem));
  padding: .45rem .58rem;
  border: 1px solid #ffffff24;
  border-radius: .3rem;
  background: #111610e8;
  color: #d2d5c8;
  pointer-events: none;
}
.research div { display: flex; flex-wrap: wrap; gap: .2rem .55rem; font-size: .75rem; }
.research strong { color: #e2ceae; overflow-wrap: anywhere; }
.research progress {
  display: block;
  width: 100%;
  height: .32rem;
  margin-top: .35rem;
  accent-color: var(--orange);
}
.zoom-controls {
  position: absolute;
  top: .7rem;
  right: .7rem;
  display: grid;
  background: #171c16;
  border: 1px solid #ffffff35;
  border-radius: .34rem;
}
.zoom-controls button, .inspector-heading button {
  width: 2.3rem;
  height: 2.15rem;
  color: #eeeede;
  font-size: 1.35rem;
  background: transparent;
  border: 0;
}
.zoom-controls button + button { border-top: 1px solid #ffffff35; }
.zoom-controls button:hover, .inspector-heading button:hover { background: #363c32; }
.inspector {
  position: absolute;
  bottom: .7rem;
  left: .7rem;
  width: min(19rem, calc(100% - 1.4rem));
  max-height: 60%;
  overflow: auto;
  border-radius: .4rem;
  border: 1px solid #59604f;
  background: #1c2119f2;
  box-shadow: 0 10px 25px #0006;
}
.inspector-heading {
  display: flex;
  align-items: center;
  gap: .3rem;
  justify-content: space-between;
  padding: .3rem .48rem .3rem .72rem;
  border-bottom: 1px solid var(--line);
}
.inspector dl {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .4rem .8rem;
  margin: 0;
  padding: .65rem .72rem;
  font-size: .85rem;
}
.inspector dt { color: var(--muted); }
.inspector dd { margin: 0; overflow-wrap: anywhere; }

.map-footer, .trace-footer {
  min-height: 2.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .6rem;
  padding: .42rem .85rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: .76rem;
}
#map-position { font-family: var(--mono); }
.map-hint { text-align: end; }
.map-hint span { margin: 0 .14rem; }

.timeline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 5.5rem auto;
  align-items: center;
  gap: .75rem;
  padding: .55rem .85rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .85rem;
}
.timeline input { width: 100%; min-width: 0; margin: 0; accent-color: var(--orange); cursor: ew-resize; }
.timeline output { text-align: end; font: .78rem var(--mono); white-space: nowrap; }
.timeline button { white-space: nowrap; }
.timeline button:disabled { opacity: .55; cursor: default; }

.trace-title { gap: .5rem; margin-bottom: .8rem; }
.tail-control {
  display: flex;
  gap: .32rem;
  align-items: center;
  font-size: .79rem;
  color: var(--muted);
  white-space: nowrap;
}
.tail-control input { accent-color: var(--orange); margin: 0; }
.trace-filters { display: flex; flex-wrap: wrap; gap: .32rem; }
.trace-filters button { font-size: .79rem; padding: .31rem .51rem; }
.trace-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #52584a #1a1e18;
  scrollbar-gutter: stable;
}
.trace-list { list-style: none; padding: 0; margin: 0; }
.trace-entry {
  padding: .93rem 1rem;
  border-bottom: 1px solid #33382f;
  border-left: 2px solid #565d4e;
  overflow-wrap: anywhere;
}
.trace-entry[data-kind="reasoning"] { border-left-color: #a38ccd; }
.trace-entry[data-kind="tool"] { border-left-color: #8aab81; }
.trace-entry[data-kind="error"], .trace-entry[data-status="failed"] { border-left-color: #da8c70; }
.trace-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem .6rem;
  font: .72rem var(--mono);
  color: var(--muted);
}
.trace-kind { text-transform: uppercase; letter-spacing: .075em; }
.trace-entry[data-kind="reasoning"] .trace-kind { color: #c0ace7; }
.trace-entry[data-kind="tool"] .trace-kind { color: #b1d6a9; }
.trace-entry[data-kind="error"] .trace-kind { color: #ffb299; }
.trace-entry h3 {
  margin: .34rem 0 0;
  font-size: .91rem;
  color: #ebeadf;
}
.trace-entry p {
  color: #c8ccbf;
  margin: .28rem 0 0;
  font-size: .91rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.trace-entry summary {
  margin-top: .35rem;
  color: #c8ccbf;
  font-size: .85rem;
  cursor: pointer;
}
.trace-entry .jump {
  margin-top: .45rem;
  padding: .27rem .47rem;
  white-space: normal;
  font: .75rem var(--mono);
}
.trace-empty {
  margin: 0;
  padding: 1rem;
  color: var(--muted);
  line-height: 1.5;
  font-size: .9rem;
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: .65rem;
    min-height: auto;
  }
  .session { grid-row: 2; grid-column: 1 / -1; }
  .session select { width: 100%; }
  .feed-state { grid-column: 2; grid-row: 1; }
  .workspace {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    gap: .65rem;
    padding: .65rem;
  }
  .world-panel { height: 63dvh; min-height: 27rem; }
  .trace-panel { height: 56dvh; min-height: 24rem; }
}
@media (max-width: 400px) {
  .map-header { padding-inline: .55rem; }
  .map-actions { gap: .3rem; }
  .map-actions .control { padding: .38rem .4rem; font-size: .77rem; }
  .map-hint { display: none; }
}
