/* Agent World viewer. Dark cabinet around a pixel-art stage. */

:root {
  --bg: #14181f;
  --bg-2: #1b212b;
  --ink: #e8e6d8;
  --ink-dim: #8b93a3;
  --frame: #2c3442;
  --accent: #ffd75e;
  --paper: #fffdf0;
  --paper-ink: #22242e;
  --pixel: "Press Start 2P", monospace;
  --mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---- header ---------------------------------------------------------- */

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 2px solid var(--frame);
  flex: none;
}

header h1 {
  font-family: var(--pixel);
  font-size: 13px;
  margin: 0;
  color: var(--accent);
  text-shadow: 2px 2px 0 #00000066;
  letter-spacing: 1px;
}

#hint {
  color: var(--ink-dim);
  font-size: 12px;
  margin-left: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn { font-size: 14px; color: #8b93a3; flex: none; }
.conn.live { color: #5fce6a; }
.conn.done { color: #8b93a3; }
.conn.err  { color: #e05f5f; }

/* ---- stage ------------------------------------------------------------ */

main {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 12px;
}

#stage {
  position: relative;
  flex: 1;
  border: 3px solid var(--frame);
  border-radius: 6px;
  overflow: hidden;
  background: #0d1117;
  box-shadow: 0 0 0 1px #000, 0 8px 30px #00000088 inset;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: grab;
  touch-action: none;
}
#game.dragging { cursor: grabbing; }
#game.over-agent { cursor: pointer; }

/* ---- speech bubbles ---------------------------------------------------- */

#bubbles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  max-width: 240px;
  background: var(--paper);
  color: var(--paper-ink);
  border: 2px solid #22242e;
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12.5px;
  line-height: 1.35;
  box-shadow: 3px 3px 0 #00000055;
  pointer-events: auto;
  animation: bubble-pop 120ms ease-out;
  white-space: pre-line;
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 10px;
  height: 10px;
  background: var(--paper);
  border-right: 2px solid #22242e;
  border-bottom: 2px solid #22242e;
  transform: translateX(-50%) rotate(45deg);
}

.bubble .who {
  font-family: var(--pixel);
  font-size: 7px;
  display: block;
  margin-bottom: 4px;
  opacity: 0.85;
}

.bubble.clickable { cursor: pointer; }
.bubble.clickable:hover { background: #fff7d6; }

/* Thought clouds: same anchor as speech, but rounded, italic, and trailing
   comic-style dots instead of a pointer. */
.bubble.thought {
  background: #eef1fb;
  border-radius: 16px;
  font-style: italic;
  color: #3c4356;
}
.bubble.thought::after {
  /* the larger thought-dot, replacing speech's triangle tail */
  left: 42%;
  bottom: -9px;
  width: 9px;
  height: 9px;
  background: #eef1fb;
  border: 2px solid #22242e;
  border-radius: 50%;
  transform: none;
}
.bubble.thought::before {
  content: "";
  position: absolute;
  left: 36%;
  bottom: -17px;
  width: 5px;
  height: 5px;
  background: #eef1fb;
  border: 2px solid #22242e;
  border-radius: 50%;
}
.bubble.thought.clickable:hover { background: #f7f9ff; }
.bubble.thought .who { font-style: normal; }
.bubble .more { color: #7b5cb8; font-weight: 600; }

@keyframes bubble-pop {
  from { transform: translate(-50%, -100%) scale(0.6); opacity: 0; }
  to   { transform: translate(-50%, -100%) scale(1);   opacity: 1; }
}

/* ---- overlays ---------------------------------------------------------- */

.hidden { display: none !important; }

.pill {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #000000aa;
  border: 1px solid var(--frame);
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
}

#endcard {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d1117bb;
}
.endcard-inner {
  text-align: center;
  font-family: var(--pixel);
  font-size: 11px;
  line-height: 2.2;
}
#btn-replay {
  font-family: var(--pixel);
  font-size: 10px;
  background: var(--accent);
  color: #22242e;
  border: 2px solid #22242e;
  border-radius: 4px;
  box-shadow: 3px 3px 0 #00000088;
  padding: 8px 14px;
  cursor: pointer;
}
#btn-replay:hover { filter: brightness(1.08); }

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d1117;
  z-index: 5;
}
.loading-inner { text-align: center; color: var(--ink-dim); font-family: var(--pixel); font-size: 10px; }
.spinner {
  width: 24px; height: 24px;
  margin: 0 auto 16px;
  background: var(--accent);
  animation: spin 0.9s steps(8) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- agent panel -------------------------------------------------------- */

#panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 216px;
  background: #1b212bee;
  border: 2px solid var(--frame);
  border-radius: 6px;
  padding: 12px;
  font-size: 12.5px;
  backdrop-filter: blur(2px);
}

#panel-close {
  position: absolute;
  top: 6px; right: 6px;
  background: none;
  border: none;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
}
#panel-close:hover { color: var(--ink); }

#panel-memory-btn {
  position: absolute;
  top: 6px; right: 28px;
  background: none;
  border: none;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 12px;
}
#panel-memory-btn:hover { color: var(--ink); }
#panel.memory-mode #panel-memory-btn { color: var(--accent); }

/* memory mode: the log replaces the live-status body of the panel */
#panel.memory-mode #panel-vitals,
#panel.memory-mode .panel-section { display: none; }
#panel-memory {
  margin-top: 8px;
  max-height: 46vh;
  overflow-y: auto;
  font-size: 11.5px;
}
#panel-memory.hidden { display: none; }
.mem-day {
  color: var(--ink-dim);
  font-family: var(--pixel);
  font-size: 7px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 8px 0 3px;
}
.mem-day.current { color: var(--accent); }
.mem-text {
  white-space: pre-wrap;
  color: var(--ink);
  border-left: 2px solid var(--frame);
  padding-left: 7px;
}
.mem-failed { color: var(--ink-dim); font-style: italic; }

#panel-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
#panel-face { image-rendering: pixelated; background: #10141b; border-radius: 4px; flex: none; }
#panel-name { font-family: var(--pixel); font-size: 10px; margin-bottom: 5px; }
#panel-sub  { color: var(--ink-dim); font-size: 11px; }

#panel-vitals { display: grid; gap: 5px; margin: 8px 0; }
.vital { display: grid; grid-template-columns: 58px 1fr; gap: 8px; align-items: center; }
.vital .vlabel { color: var(--ink-dim); font-size: 11px; text-transform: capitalize; }
.vital .vbar {
  height: 8px;
  background: #10141b;
  border: 1px solid var(--frame);
  border-radius: 3px;
  overflow: hidden;
}
.vital .vfill { height: 100%; transition: width 300ms; }

.panel-section { margin-top: 8px; }
.panel-label {
  color: var(--ink-dim);
  font-family: var(--pixel);
  font-size: 7px;
  text-transform: uppercase;
  margin-bottom: 4px;
  letter-spacing: 1px;
}
#panel-plan { min-height: 16px; }
#panel-inv .inv-row { display: flex; justify-content: space-between; color: var(--ink); }
#panel-inv .inv-row .qty { color: var(--accent); font-family: var(--mono); }
.dim { color: var(--ink-dim); }

/* Thoughts (model rationales) and said/heard lines, newest on top. */
.mind-log { display: flex; flex-direction: column; gap: 4px; max-height: 132px; overflow-y: auto; }
.mind-log .mind-row { font-size: 12px; line-height: 1.35; color: var(--ink); }
.mind-log .mind-row .t { color: var(--ink-dim); font-family: var(--mono); font-size: 10px; margin-right: 5px; }
.mind-log .mind-row.refused { color: var(--ink-dim); }

/* ---- event feed ---------------------------------------------------------- */

#feed {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column-reverse;
  gap: 3px;
  max-width: 46%;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 11.5px;
}
.feed-row {
  background: #0d1117bb;
  border-left: 3px solid var(--frame);
  border-radius: 3px;
  padding: 3px 8px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed-row.notable   { color: var(--ink); border-left-color: var(--accent); }
.feed-row.highlight { color: #ffb3b3; border-left-color: #e05f5f; }

/* ---- controls (the time slider) ------------------------------------------ */

footer#controls {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  padding: 12px 18px 16px;
  background: var(--bg-2);
  border-top: 2px solid var(--frame);
}

#btn-play,
#btn-thoughts {
  font-size: 15px;
  width: 42px;
  height: 34px;
  background: var(--frame);
  color: var(--ink);
  border: 2px solid #000;
  border-radius: 4px;
  box-shadow: 2px 2px 0 #00000088;
  cursor: pointer;
}
#btn-play:hover,
#btn-thoughts:hover { background: #3a4456; }
#btn-play:active,
#btn-thoughts:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #00000088; }
#btn-thoughts.off { opacity: 0.45; filter: grayscale(1); }

.slider-cap { font-size: 15px; }

#speed {
  -webkit-appearance: none;
  appearance: none;
  width: clamp(140px, 38vw, 420px);
  min-width: 0;
  height: 10px;
  background: #10141b;
  border: 2px solid #000;
  border-radius: 6px;
  outline-offset: 3px;
}
#speed::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 24px;
  background: var(--accent);
  border: 2px solid #000;
  border-radius: 3px;
  box-shadow: 2px 2px 0 #00000088;
  cursor: ew-resize;
}
#speed::-moz-range-thumb {
  width: 14px;
  height: 20px;
  background: var(--accent);
  border: 2px solid #000;
  border-radius: 3px;
  box-shadow: 2px 2px 0 #00000088;
  cursor: ew-resize;
}

#speed-label {
  font-family: var(--pixel);
  font-size: 8px;
  color: var(--ink-dim);
  line-height: 1.7;
  white-space: nowrap;
}

#clock {
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--accent);
  min-width: 150px;
  text-align: right;
  white-space: nowrap;
}

@media (max-height: 560px), (max-width: 760px) {
  header h1 { font-size: 10px; }
  #hint { display: none; }
  main { padding: 6px; }
  footer#controls { padding: 8px 10px 10px; }
  #clock { min-width: 0; }
}

/* ---- modal ----------------------------------------------------------------- */

#modal {
  position: fixed;
  inset: 0;
  background: #000000a8;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#modal-card {
  position: relative;
  width: min(520px, calc(100vw - 40px));
  max-height: 70vh;
  overflow-y: auto;
  background: var(--paper);
  color: var(--paper-ink);
  border: 3px solid #22242e;
  border-radius: 8px;
  box-shadow: 6px 6px 0 #00000088;
  padding: 18px 20px;
}

#modal-close {
  position: absolute;
  top: 8px; right: 10px;
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  color: #22242e;
}

#modal-speaker { font-family: var(--pixel); font-size: 11px; margin-bottom: 6px; }
#modal-meta { color: #6b6f80; font-size: 12px; margin-bottom: 12px; }
#modal-text { font-size: 14.5px; line-height: 1.55; white-space: pre-line; }
#modal-heard {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed #b9b4a0;
  color: #6b6f80;
  font-size: 12px;
}
