/* AiWorld — shared tokens for the spectator page and the admin console. */
:root {
  --ink: #0d2230;
  --ink-2: #143347;
  --ink-3: #1d4560;
  --glass: rgba(11, 30, 43, 0.8);
  --glass-strong: rgba(11, 30, 43, 0.92);
  --foam: #eaf3ef;
  --mist: #9db6bd;
  --mist-2: #6e8c96;
  --line: rgba(234, 243, 239, 0.1);
  --line-2: rgba(234, 243, 239, 0.18);
  --sun: #f2c330;
  --plank: #b8894f;
  --lagoon: #62d2d8;
  --leaf: #8bd17c;
  --coral: #ff6f61;
  --font: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --pixel: 'Silkscreen', 'Atkinson Hyperlegible', monospace;
  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
  --gutter: 16px;
  --panel-w: 368px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--foam);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
body.spectator { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Stage ---------- */
#stage { position: fixed; inset: 0; }
#view { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#view:active { cursor: grabbing; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

/* ---------- Wordmark ---------- */
.wordmark {
  margin: 0;
  font: 700 30px/1 var(--pixel);
  letter-spacing: 0.02em;
  color: var(--foam);
  text-shadow: 2px 2px 0 var(--plank), 4px 4px 0 #6b4a2b, 5px 6px 10px rgba(0, 0, 0, 0.35);
}

/* ---------- HUD ---------- */
.hud { position: fixed; z-index: 5; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top {
  top: var(--gutter); left: var(--gutter); right: calc(var(--panel-w) + var(--gutter) * 2);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.brand { text-shadow: 0 1px 12px rgba(0, 0, 0, 0.3); }
.tagline { margin: 10px 0 0; color: var(--foam); opacity: 0.85; font-size: 14px; max-width: 34ch; }
.hud-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.pill, .conn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 12px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 13px; color: var(--foam); white-space: nowrap;
}
.pill svg { width: 15px; height: 15px; color: var(--mist); }
.clock-text { font-family: var(--pixel); font-size: 12px; letter-spacing: 0.04em; }
.clock-icon { width: 12px; height: 12px; border-radius: 50%; background: var(--sun); box-shadow: 0 0 8px rgba(242, 195, 48, 0.7); }
.clock.is-night .clock-icon { background: transparent; box-shadow: inset 4px -2px 0 0 #cfdcff; transform: rotate(-20deg); }

.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mist-2); }
.conn[data-state='live'] .conn-dot { background: var(--leaf); box-shadow: 0 0 0 0 rgba(139, 209, 124, 0.6); animation: live 2.4s infinite; }
.conn[data-state='connecting'] .conn-dot, .conn[data-state='retry'] .conn-dot { background: var(--sun); }
.conn[data-state='offline'] .conn-dot { background: var(--coral); }
@keyframes live { 0% { box-shadow: 0 0 0 0 rgba(139, 209, 124, 0.55); } 70% { box-shadow: 0 0 0 8px rgba(139, 209, 124, 0); } 100% { box-shadow: 0 0 0 0 rgba(139, 209, 124, 0); } }

/* ---------- Camera control ---------- */
.camctl {
  position: fixed; z-index: 5; left: var(--gutter); bottom: var(--gutter);
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.seg { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font-size: 13px; cursor: pointer; color: var(--mist); }
.seg:hover { color: var(--foam); }
.seg.is-on { background: var(--foam); color: var(--ink); font-weight: 700; }

/* ---------- Caption (the followed character's latest line) ---------- */
.caption {
  position: fixed; z-index: 4;
  left: var(--gutter); right: calc(var(--panel-w) + var(--gutter) * 2);
  bottom: calc(var(--gutter) + 52px);
  margin: 0 auto; max-width: 720px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  pointer-events: none;
  transition: opacity 0.6s;
}
.caption.is-stale { opacity: 0.45; }
.caption-who {
  font-size: 12px; font-weight: 700; color: var(--ink);
  background: var(--c, var(--lagoon)); padding: 2px 9px; border-radius: 999px; margin-bottom: 6px;
}
.caption-text {
  margin: 0; padding: 8px 14px; border-radius: var(--r-md);
  background: rgba(7, 20, 29, 0.74);
  font-size: 17px; line-height: 1.4; color: var(--foam);
  max-width: 62ch;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.caption[data-kind='thought'] .caption-text { font-style: italic; color: #d7eef0; }
.caption[data-kind='say'] .caption-text::before { content: '\201C'; }
.caption[data-kind='say'] .caption-text::after { content: '\201D'; }

/* ---------- In-world labels ---------- */
.anchor { width: 0; height: 0; position: relative; }
.tag {
  position: absolute; left: 0; bottom: 0; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 7px; border-radius: 999px;
  background: rgba(7, 20, 29, 0.72); color: var(--foam);
  font-size: 13px; font-weight: 700; white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.tag-dot { width: 9px; height: 9px; border-radius: 2px; background: var(--c); }
.anchor.is-selected .tag { border-color: var(--c); }
.think { display: none; gap: 3px; }
.anchor[data-status='thinking'] .think { display: inline-flex; }
.think i { width: 4px; height: 4px; border-radius: 50%; background: var(--c); animation: think 1.2s infinite ease-in-out; }
.think i:nth-child(2) { animation-delay: 0.15s; }
.think i:nth-child(3) { animation-delay: 0.3s; }
@keyframes think { 0%, 70%, 100% { transform: translateY(0); opacity: 0.4; } 35% { transform: translateY(-4px); opacity: 1; } }

.bubble {
  position: absolute; left: 0; bottom: 34px; transform: translateX(-50%);
  width: max-content; max-width: 240px;
  padding: 8px 12px; border-radius: 14px;
  background: #fbfdfc; color: #10232e;
  font-size: 14px; line-height: 1.35; text-align: left;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px;
  background: #fbfdfc; transform: translateX(-50%) rotate(45deg); border-radius: 2px;
}
.bubble.pop { animation: pop 0.28s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: translateX(-50%) scale(0.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.sign {
  position: absolute; left: 0; bottom: 0; transform: translateX(-50%);
  width: max-content; max-width: 200px;
  padding: 7px 10px 6px; border-radius: 4px;
  background: #d9ad6e; color: #3a2512;
  border: 2px solid #8a5f33; box-shadow: 0 3px 0 #6b4a2b;
  font-size: 13px; line-height: 1.3; text-align: center;
}
.sign p { margin: 0; font-weight: 700; }
.sign span { display: block; margin-top: 3px; font-size: 11px; opacity: 0.75; }

/* ---------- Panel ---------- */
.panel {
  position: fixed; z-index: 6;
  top: var(--gutter); right: var(--gutter); bottom: var(--gutter); width: var(--panel-w);
  display: flex; flex-direction: column;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-lg);
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 20px 50px rgba(3, 12, 18, 0.35);
  overflow: hidden;
}
.sheet-handle { display: none; }
.section-title { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--mist); letter-spacing: 0.01em; }

.roster-wrap { padding: 16px 16px 6px; flex: 0 0 auto; max-height: 46%; overflow-y: auto; }
.roster { display: flex; flex-direction: column; gap: 8px; }

.card {
  display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 4px 11px; align-items: start;
  width: 100%; text-align: left; cursor: pointer;
  padding: 11px 12px; border-radius: var(--r-md);
  background: rgba(234, 243, 239, 0.04); border: 1px solid var(--line);
  transition: background 0.15s, border-color 0.15s;
}
.card-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card:hover { background: rgba(234, 243, 239, 0.07); }
.card.is-selected { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.card.is-off { opacity: 0.6; }
.cube {
  grid-row: span 1; width: 30px; height: 30px; margin-top: 2px; border-radius: 6px;
  background: var(--c);
  box-shadow: inset -6px -6px 0 rgba(0, 0, 0, 0.22), inset 5px 5px 0 rgba(255, 255, 255, 0.22);
}
.card-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.card-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-model { color: var(--mist); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status {
  margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--mist);
}
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status[data-s='thinking'] { color: var(--lagoon); }
.status[data-s='thinking']::before { animation: blink 1s infinite; }
.status[data-s='acting'] { color: var(--sun); }
.status[data-s='waiting'] { color: var(--mist); }
.status[data-s='paused'], .status[data-s='stopped'] { color: var(--mist-2); }
.status[data-s='error'] { color: var(--coral); }
@keyframes blink { 50% { opacity: 0.25; } }
.card-goal { font-size: 14px; color: var(--foam); line-height: 1.35; }
.card-goal:empty { display: none; }
.card-action { font-size: 13px; color: var(--mist); display: flex; gap: 8px; justify-content: space-between; min-width: 0; }
.card-action .act { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-action .next { flex: none; color: var(--mist-2); }

.empty { display: flex; gap: 14px; align-items: center; padding: 14px; border: 1px dashed var(--line-2); border-radius: var(--r-md); color: var(--mist); font-size: 14px; }
.empty p { margin: 0; }
.empty strong { color: var(--foam); display: block; }
.empty-art { flex: none; width: 34px; height: 34px; border-radius: 7px; background: var(--ink-3); box-shadow: inset -7px -7px 0 rgba(0, 0, 0, 0.25), inset 6px 6px 0 rgba(255, 255, 255, 0.08); }

.budget { padding: 12px 16px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); flex: none; }
.budget-head { display: flex; align-items: center; gap: 8px; }
.budget-head .section-title { margin-bottom: 6px; margin-right: auto; }
.badge { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: rgba(242, 195, 48, 0.16); color: var(--sun); margin-bottom: 6px; }
.badge-stop { background: rgba(255, 111, 97, 0.16); color: var(--coral); }
.budget-figs { display: flex; align-items: baseline; gap: 8px; }
.budget-spend { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.budget-of { color: var(--mist); font-size: 14px; }
.meter { height: 8px; margin: 8px 0 7px; border-radius: 2px; background: rgba(234, 243, 239, 0.08); overflow: hidden; }
.meter span {
  display: block; height: 100%; width: 0; border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--sun) 0 10px, #e0b11f 10px 12px);
  transition: width 0.8s ease;
}
.meter.is-high span { background: repeating-linear-gradient(90deg, var(--coral) 0 10px, #e85a4d 10px 12px); }
.budget-note { margin: 0; font-size: 13px; color: var(--mist); }

.feed-wrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 14px 0 0; }
.feed-wrap .section-title { padding: 0 16px; }
.feed { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; min-height: 0; }
.feed-empty { margin: 0; padding: 4px 16px 16px; color: var(--mist); font-size: 14px; }
.ev {
  display: grid; grid-template-columns: 18px 1fr auto; gap: 2px 8px;
  padding: 7px 8px; border-radius: var(--r-sm); font-size: 14px; line-height: 1.4;
}
.ev.is-new { animation: evin 0.6s ease-out; }
@keyframes evin { from { background: rgba(234, 243, 239, 0.1); } to { background: transparent; } }
.ev-icon { width: 14px; height: 14px; margin-top: 3px; color: var(--mist); }
.ev-body { min-width: 0; overflow-wrap: anywhere; }
.ev-who { font-weight: 700; color: var(--c, var(--foam)); margin-right: 5px; }
.ev-time { color: var(--mist-2); font-size: 12px; margin-top: 2px; white-space: nowrap; }
.ev.k-thought .ev-text { color: #cfe6e8; font-style: italic; }
.ev.k-thought .ev-icon { color: var(--lagoon); }
.ev.k-action .ev-icon { color: var(--sun); }
.ev.k-action .ev-text { color: var(--mist); }
.ev.k-say .ev-icon { color: var(--foam); }
.ev.k-say .ev-text::before { content: '\201C'; }
.ev.k-say .ev-text::after { content: '\201D'; }
.ev.k-system .ev-text { color: var(--mist); }
.ev.k-system .ev-icon { color: var(--mist-2); }
.ev.k-error { background: rgba(255, 111, 97, 0.08); }
.ev.k-error .ev-icon, .ev.k-error .ev-text { color: var(--coral); }

/* ---------- Loading ---------- */
.loading {
  position: fixed; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at 50% 40%, #1b4a66, var(--ink) 70%);
  transition: opacity 0.8s;
}
.loading.is-done { opacity: 0; pointer-events: none; }
.loading p { margin: 0; color: var(--mist); font-size: 15px; }
.loading-cube { display: flex; gap: 6px; }
.loading-cube i { width: 14px; height: 14px; background: var(--leaf); animation: stack 1.2s infinite ease-in-out; box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.25); }
.loading-cube i:nth-child(2) { background: var(--plank); animation-delay: 0.15s; }
.loading-cube i:nth-child(3) { background: var(--sun); animation-delay: 0.3s; }
@keyframes stack { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }

/* ---------- Phone: panel becomes a bottom sheet ---------- */
@media (max-width: 860px) {
  :root { --sheet-peek: 236px; }
  .hud-top { right: var(--gutter); flex-direction: column; gap: 8px; }
  .wordmark { font-size: 22px; }
  .tagline { display: none; }
  .hud-right { justify-content: flex-start; }
  .pill, .conn { height: 28px; padding: 0 10px; font-size: 12px; }
  .camctl { left: auto; right: var(--gutter); top: var(--gutter); bottom: auto; }
  .seg { padding: 5px 11px; font-size: 12px; }
  .caption { left: var(--gutter); right: var(--gutter); bottom: calc(var(--sheet-peek) + 10px); }
  .caption-text { font-size: 15px; -webkit-line-clamp: 2; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    height: var(--sheet-peek); border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
    transition: height 0.32s cubic-bezier(.2, .8, .2, 1);
  }
  .panel[data-sheet='open'] { height: min(80vh, calc(100vh - 80px)); height: min(80dvh, calc(100dvh - 80px)); }
  body:has(.panel[data-sheet='open']) .caption { opacity: 0; }
  .sheet-handle {
    display: flex; justify-content: center; align-items: center; flex: none;
    height: 22px; width: 100%; border: 0; background: transparent; cursor: pointer; padding: 0;
  }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); }
  .roster-wrap { padding-top: 2px; max-height: none; overflow: visible; }
  .panel[data-sheet='peek'] .roster-wrap { padding-bottom: 10px; }
  .panel[data-sheet='peek'] .card:not(.is-selected) { display: none; }
  .panel[data-sheet='peek'] .roster-wrap .section-title { display: none; }
  .panel { overflow-y: auto; }
  .panel[data-sheet='peek'] { overflow: hidden; }
  .feed-wrap { flex: none; }
  .feed { overflow: visible; }
}


/* ---------- v2: needs, conditions, inventory on cards ---------- */
.needs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px 10px; margin-top: 4px; }
.need { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.need-label { font-size: 11px; line-height: 1.1; color: var(--mist); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.need.is-low .need-label { color: #ffb0a6; }
.need-bar { height: 4px; border-radius: 2px; background: rgba(234, 243, 239, 0.1); overflow: hidden; }
.need-bar i { display: block; height: 100%; width: 0; border-radius: 2px; transition: width 0.6s ease, background 0.6s; }
.card:not(.is-selected) .needs { gap: 2px 6px; }
.card:not(.is-selected) .need-label { display: none; }
.card:not(.is-selected) .card-goal { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.chip { font-size: 11.5px; line-height: 1; padding: 4px 7px; border-radius: 999px; background: rgba(234, 243, 239, 0.08); color: var(--mist); white-space: nowrap; }
.chip.is-bad { background: rgba(255, 111, 97, 0.16); color: #ffb0a6; }
.card-more { display: none; flex-direction: column; gap: 6px; margin-top: 4px; }
.card.is-selected .card-more { display: flex; }
.card-traits { font-size: 13px; color: var(--foam); opacity: 0.85; font-style: italic; line-height: 1.35; }
.card-traits:empty { display: none; }
.inv { display: flex; flex-wrap: wrap; gap: 4px; }
.item { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 7px 3px 5px; border-radius: 6px; background: rgba(3, 14, 21, 0.4); border: 1px solid var(--line); color: var(--foam); }
.item b { color: var(--mist); font-weight: 700; }
.item b:empty { display: none; }
.item.is-held { border-color: var(--sun); }
.item-sw { width: 10px; height: 10px; border-radius: 2px; box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.25); }
.status[data-s='sleeping'] { color: #a9b8ff; }
.status[data-s='unconscious'] { color: var(--coral); }
.status[data-s='unconscious']::before { animation: blink 1.4s infinite; }

/* weather pill */
.weather-icon { width: 14px; height: 12px; position: relative; }
.weather-icon::before { content: ''; position: absolute; left: 1px; top: 2px; width: 12px; height: 7px; border-radius: 6px; background: #cfdcef; box-shadow: 3px -3px 0 -1px #cfdcef; }
.weather[data-kind='clear'] .weather-icon::before { left: 2px; top: 1px; width: 10px; height: 10px; border-radius: 50%; background: var(--sun); box-shadow: 0 0 6px rgba(242, 195, 48, 0.7); }
.weather[data-kind='rain'] .weather-icon::after, .weather[data-kind='storm'] .weather-icon::after { content: ''; position: absolute; left: 3px; top: 10px; width: 8px; height: 3px; background: repeating-linear-gradient(90deg, #7fb6ff 0 1.5px, transparent 1.5px 3.5px); }
.weather[data-kind='storm'] .weather-icon::before { background: #8d97a6; box-shadow: 3px -3px 0 -1px #8d97a6; }
.weather[data-kind='snow'] .weather-icon::after { content: ''; position: absolute; left: 3px; top: 10px; width: 8px; height: 3px; background: radial-gradient(circle, #fff 0 1px, transparent 1.2px) 0 0 / 3px 3px; }

/* minimap */
.minimap {
  position: fixed; z-index: 5; left: var(--gutter); top: 112px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
}
.minimap-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 13px; color: var(--mist);
}
.minimap-toggle:hover { color: var(--foam); }
.minimap-toggle svg { width: 15px; height: 15px; }
.minimap.is-open .minimap-toggle { color: var(--foam); }
#minimap-canvas {
  display: none; width: 184px; height: 184px; border-radius: var(--r-md); cursor: crosshair;
  border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(3, 12, 18, 0.35); background: var(--ink-2);
  image-rendering: pixelated;
}
.minimap.is-open #minimap-canvas { display: block; }

/* in-world labels: sleep, unconscious, hp, fx */
.zzz { display: none; position: absolute; left: 10px; bottom: 26px; font: 700 13px/1 var(--pixel); color: #cfdcff; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); }
.anchor.is-asleep .zzz { display: block; }
.zzz i { position: absolute; left: 0; bottom: 0; font-style: normal; opacity: 0; animation: zzz 2.4s infinite ease-out; }
.zzz i:nth-child(2) { animation-delay: 0.8s; }
.zzz i:nth-child(3) { animation-delay: 1.6s; font-size: 16px; }
@keyframes zzz { 0% { transform: translate(0, 0) scale(0.6); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(18px, -30px) scale(1.1); opacity: 0; } }
.anchor.is-out .tag { border-color: var(--coral); }
.anchor.is-out .tag-name::after { content: ' (out cold)'; color: #ffb0a6; font-weight: 400; }
.anchor.is-asleep .bubble, .anchor.is-out .bubble { display: none; }
.hpbar { position: absolute; left: 0; bottom: 0; transform: translateX(-50%); width: 34px; height: 5px; border-radius: 3px; background: rgba(7, 20, 29, 0.75); border: 1px solid rgba(255, 255, 255, 0.15); overflow: hidden; }
.hpbar i { display: block; height: 100%; width: 100%; background: var(--leaf); }
.fx-icon { position: absolute; left: 0; bottom: 0; transform: translateX(-50%); width: 24px; height: 24px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); animation: pop 0.28s cubic-bezier(.3, 1.6, .5, 1); }
.fx-icon svg { width: 100%; height: 100%; display: block; }

@media (max-width: 860px) {
  .minimap { left: auto; right: var(--gutter); top: calc(var(--gutter) + 40px); align-items: flex-end; }
  .minimap-toggle { height: 28px; padding: 0 10px; font-size: 12px; }
  #minimap-canvas { width: 132px; height: 132px; }
  .panel[data-sheet='peek'] .card-more, .panel[data-sheet='peek'] .card-goal { display: none; }
  .panel[data-sheet='peek'] .chips { flex-wrap: nowrap; overflow: hidden; }
  .needs { gap: 3px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ===================== Admin console ===================== */
body.admin { background: radial-gradient(ellipse 120% 60% at 50% -10%, #1b4a66, var(--ink) 60%) fixed; min-height: 100%; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--mist); }
.small { font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: rgba(234, 243, 239, 0.06); color: var(--foam);
  font-size: 14px; font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: rgba(234, 243, 239, 0.12); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--sun); border-color: var(--sun); color: #2a1f00; }
.btn-primary:hover:not(:disabled) { background: #ffd24a; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--mist); }
.btn-ghost:hover:not(:disabled) { color: var(--foam); }
.btn-danger { background: var(--coral); border-color: var(--coral); color: #2b0703; }
.btn-danger:hover:not(:disabled) { background: #ff8a7e; }
.btn-danger-text { color: var(--coral); }
.btn-small { height: 30px; padding: 0 10px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span:first-child, .field-label { font-size: 13px; color: var(--mist); font-weight: 700; }
.inline { display: flex; gap: 8px; }
input[type='text'], input[type='password'], input[type='number'], select, textarea {
  width: 100%; min-width: 0; height: 38px; padding: 0 11px;
  background: rgba(3, 14, 21, 0.45); color: var(--foam);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font: inherit; font-size: 14.5px;
}
textarea { height: auto; padding: 9px 11px; line-height: 1.45; resize: vertical; }
select { appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--mist) 50%), linear-gradient(135deg, var(--mist) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--sun); box-shadow: 0 0 0 3px rgba(242, 195, 48, 0.18); }
[data-dirty='1'] { border-color: rgba(242, 195, 48, 0.6); }
input[type='color'] { width: 38px; height: 38px; padding: 3px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: rgba(3, 14, 21, 0.45); cursor: pointer; }

.login { min-height: 100vh; display: grid; place-items: center; padding: var(--gutter); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 28px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: 0 20px 50px rgba(3, 12, 18, 0.35); }
.login-sub { margin: -6px 0 4px; color: var(--mist); }
.form-error { margin: 0; color: var(--coral); font-size: 14px; }
.back { color: var(--mist); font-size: 14px; text-align: center; }

.console { max-width: 1120px; margin: 0 auto; padding: var(--gutter) var(--gutter) 64px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0 20px; flex-wrap: wrap; }
.topbar-brand { display: flex; align-items: baseline; gap: 12px; }
.wordmark-sm { font-size: 22px; }
.topbar-sub { font-size: 15px; color: var(--mist); font-weight: 700; }
.topbar-actions { display: flex; gap: 4px; flex-wrap: wrap; }

.banner { margin-bottom: 16px; padding: 12px 16px; border-radius: var(--r-md); background: rgba(255, 111, 97, 0.12); border: 1px solid rgba(255, 111, 97, 0.4); color: #ffd5cf; font-size: 14.5px; }
.banner strong { color: var(--coral); }

.block { margin-bottom: 16px; padding: 18px 20px 20px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-lg); }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.block-head .block-title { margin: 0; }
.block-title { margin: 0 0 14px; font-size: 18px; font-weight: 700; }
.sub-title { margin: 14px 0 8px; font-size: 14px; color: var(--mist); font-weight: 700; }

.run-grid { display: grid; grid-template-columns: 1.1fr 1fr 1.1fr; gap: 24px; align-items: start; }
.run-cell { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.run-state { margin: 0; display: flex; align-items: center; gap: 9px; font-size: 15px; }
.run-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.run-dot.is-on { background: var(--leaf); box-shadow: 0 0 10px rgba(139, 209, 124, 0.7); }
.run-dot.is-paused { background: var(--sun); }
.btn-toggle { height: 42px; align-self: flex-start; border-color: rgba(242, 195, 48, 0.5); color: var(--sun); }
.btn-toggle.is-paused { background: var(--leaf); border-color: var(--leaf); color: #0d2a08; }
.run .budget-figs { margin-top: -4px; }
.run .meter { margin: 0; }
.run .muted { margin: 0; }

.agents { display: flex; flex-direction: column; gap: 10px; }
.agent { padding: 14px; border-radius: var(--r-md); background: rgba(234, 243, 239, 0.035); border: 1px solid var(--line); border-left: 4px solid var(--c); }
.agent.is-dirty { border-color: rgba(242, 195, 48, 0.4); border-left-color: var(--c); }
.agent.is-off { opacity: 0.75; }
.agent-top { display: flex; align-items: center; gap: 10px; }
.agent-name { font-size: 17px !important; font-weight: 700; max-width: 280px; }
.agent-top .status { margin-left: 4px; margin-right: auto; }
.agent-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.3fr); gap: 12px; margin-top: 12px; align-items: end; }
.agent-stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--mist); padding-bottom: 9px; }
.agent-stats b { color: var(--foam); }
.warn { margin: 10px 0 0; padding: 8px 12px; border-radius: var(--r-sm); background: rgba(242, 195, 48, 0.12); color: #ffe39a; font-size: 14px; }
.agent-error { margin: 10px 0 0; color: var(--coral); font-size: 14px; overflow-wrap: anywhere; }
.agent-doing { margin: 10px 0 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; color: var(--mist); }
.agent-doing b { color: var(--foam); font-weight: 700; }
.agent-more { margin-top: 10px; }
.agent-more summary { cursor: pointer; font-size: 14px; color: var(--mist); font-weight: 700; padding: 4px 0; }
.agent-more summary:hover { color: var(--foam); }
.agent-more textarea { margin-top: 6px; }
.notes { margin: 6px 0 0; padding-left: 20px; font-size: 14px; color: var(--foam); display: flex; flex-direction: column; gap: 3px; }
.agent-actions { display: flex; gap: 6px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--mist); position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 38px; height: 22px; border-radius: 999px; background: rgba(234, 243, 239, 0.15); position: relative; transition: background 0.15s; }
.switch-ui::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--foam); transition: transform 0.15s; }
.switch input:checked + .switch-ui { background: var(--leaf); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--sun); outline-offset: 2px; }

.add { margin-top: 16px; padding-top: 4px; border-top: 1px solid var(--line); }
.add-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 0.9fr) auto; gap: 12px; margin-bottom: 12px; }
.field-wide { grid-column: 1 / -1; }
.add .warn { margin: 0 0 12px; }

.two-col { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 16px; }
.two-col .block { margin-bottom: 16px; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.bars li { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 14px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-val { color: var(--mist); }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 2px; background: rgba(234, 243, 239, 0.08); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--lagoon); border-radius: 2px; }

.table-wrap { position: relative; overflow-x: auto; margin: 0 -4px 10px; }
.prices { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 520px; }
.prices th { text-align: left; font-size: 12.5px; color: var(--mist); font-weight: 700; padding: 0 4px 6px; }
.prices td { padding: 4px; }
.prices td:first-child { width: 40%; }
.prices input { height: 34px; }
.prices select { height: 34px; }
.row-actions { white-space: nowrap; text-align: right; }

.danger { border-color: rgba(255, 111, 97, 0.35); }
.danger .block-title { color: var(--coral); }
.danger-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.danger-row p { margin: 0; color: var(--mist); max-width: 60ch; }

.dialog { width: min(420px, calc(100vw - 32px)); padding: 22px; border-radius: var(--r-lg); border: 1px solid var(--line-2); background: var(--ink-2); color: var(--foam); }
.dialog::backdrop { background: rgba(3, 10, 15, 0.6); backdrop-filter: blur(3px); }
.dialog h2 { margin: 0 0 8px; font-size: 19px; }
.dialog p { margin: 0 0 14px; color: var(--mist); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toasts { position: fixed; z-index: 50; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(520px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 10px 16px; border-radius: var(--r-md); background: var(--ink-3); border: 1px solid var(--line-2); font-size: 14.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); transition: opacity 0.4s, transform 0.4s; }
.toast-error { background: #4a1d1b; border-color: rgba(255, 111, 97, 0.6); color: #ffd5cf; }
.toast.is-out { opacity: 0; transform: translateY(8px); }

@media (max-width: 860px) {
  .run-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .two-col { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .agent-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .agent-stats { grid-column: 1 / -1; padding-bottom: 0; }
  .add-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .block { padding: 16px; }
  .agent-grid, .add-grid { grid-template-columns: minmax(0, 1fr); }
  .agent-top { flex-wrap: wrap; }
  .agent-name { flex: 1; }
  .switch-text { display: none; }
  .field-color { flex-direction: row; align-items: center; gap: 10px; }
}

/* ---------- Admin v2: traits, needs, inventory ---------- */
.opt { font-style: normal; font-weight: 400; color: var(--mist-2); margin-left: 4px; }
.traits, .life { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 10px; }
.trait-group { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 8px; align-items: start; }
.trait-key { font-size: 13px; font-weight: 700; color: var(--mist); padding-top: 3px; }
.trait-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.trait-text { font-size: 14px; }
.tchip { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: rgba(234, 243, 239, 0.08); border: 1px solid var(--line); }
.tchip.is-bad { background: rgba(255, 111, 97, 0.14); color: #ffb0a6; border-color: rgba(255, 111, 97, 0.3); }
.tchip.is-held { border-color: var(--sun); }
.tbars, .needs-ro { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 5px 18px; }
.tbars li, .needs-ro li { display: grid; grid-template-columns: 110px minmax(0, 1fr) 36px; gap: 8px; align-items: center; font-size: 13px; }
.tb-label { color: var(--foam); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-bar { height: 6px; border-radius: 2px; background: rgba(234, 243, 239, 0.08); overflow: hidden; }
.tb-bar i { display: block; height: 100%; background: var(--lagoon); border-radius: 2px; }
.tb-val { color: var(--mist); text-align: right; font-size: 12.5px; }
.hint { margin: 6px 0 0; }
@media (max-width: 520px) {
  .trait-group { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .tbars li, .needs-ro li { grid-template-columns: 90px minmax(0, 1fr) 30px; }
}
