:root {
  --bg: #1d2321;
  --panel: #f6f1e7;
  --ink: #2b2420;
  --muted: #7b6f64;
  --line: #e2d8c6;
  --accent: #d9603b;
  --work: #e8a33a;
  --idle: #5aa45f;
  --bubble: #fffdf8;
  font-family: "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { display: flex; overflow: hidden; }

#stage { position: relative; flex: 1; min-width: 0; }
#world { width: 100%; height: 100%; display: block; image-rendering: pixelated; cursor: grab; }
#world.dragging { cursor: grabbing; }
#hud { position: absolute; top: 12px; left: 12px; display: flex; gap: 8px; align-items: center; color: #fff; font-size: 13px; text-shadow: 0 1px 2px #000; }
.badge { background: var(--accent); color: #fff; padding: 3px 10px; border-radius: 999px; font-weight: 600; text-shadow: none; }
.badge.grok { background: #222; border: 1px solid #555; }
#zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
#zoom button { width: 34px; height: 34px; border-radius: 8px; border: 0; background: #fffdf8e6; font-size: 18px; cursor: pointer; }

#panel { width: 360px; background: var(--panel); border-left: 3px solid #3b2f28; overflow-y: auto; padding: 16px; }
h1 { margin: 0 0 12px; font-size: 22px; letter-spacing: .5px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; }
button { font: inherit; }
.ghost { background: none; border: 0; font-size: 20px; cursor: pointer; padding: 0 0 8px; }

#filters { display: flex; gap: 6px; margin: 10px 0; }
#filters button { flex: 1; padding: 5px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; }
#filters button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

#botList { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
#botList li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
#botList li:hover { background: #ece4d4; }
#botList canvas { width: 32px; height: 32px; image-rendering: pixelated; }
#botList .nm { font-weight: 600; font-size: 14px; }
#botList .rl { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#botList .meta { flex: 1; min-width: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.working { background: var(--work); box-shadow: 0 0 0 3px #e8a33a44; }

.who { display: flex; gap: 12px; align-items: center; }
#portrait { width: 96px; height: 96px; image-rendering: pixelated; background: #ece4d4; border-radius: 12px; }
.status { margin-top: 6px; font-size: 13px; }
.status b { color: var(--work); }
.job { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.follow { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.follow input { width: auto; }

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.messages li { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font-size: 13px; line-height: 1.35; }
.messages li.user { background: #e7f0fb; border-color: #c9dbf0; }
.messages li.system { background: #f3ece0; color: var(--muted); font-style: italic; }
.messages .t { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.feed li { cursor: pointer; }
.empty { color: var(--muted); font-size: 13px; font-style: italic; }

#askForm { display: flex; gap: 6px; margin-top: 12px; }
#askForm button { padding: 0 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
#askForm button:disabled { opacity: .5; cursor: default; }

.hallBtn { position: absolute; top: 10px; right: 12px; padding: 8px 14px; border: 2px solid #3b2f28; border-radius: 10px; background: #f6d76b; color: #2b2420; font-weight: 700; cursor: pointer; box-shadow: 0 2px 0 #3b2f28; }
.hallBtn.active { background: #d9603b; color: #fff; }
.hallBtn:active { transform: translateY(2px); box-shadow: none; }
#toast { position: absolute; left: 50%; top: 50px; transform: translateX(-50%); background: #2b2420e8; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 13px; pointer-events: none; }
.seg { display: flex; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; padding: 6px; border: 0; background: #fff; cursor: pointer; }
.seg button.on { background: var(--ink); color: #fff; }
#askForm, #hallForm { display: flex; gap: 6px; margin-top: 8px; }
#hallForm button, .endBtn { padding: 0 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
#hallForm button:disabled { opacity: .5; }
.endBtn { width: 100%; padding: 9px; margin-top: 14px; background: #3b2f28; }
.chat { max-height: 42vh; overflow-y: auto; }
#hallLog { max-height: 55vh; margin-top: 12px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 11px; text-transform: none; letter-spacing: 0; float: right; }
.dot.talking { background: #4f8ad8; box-shadow: 0 0 0 3px #4f8ad844; }

#townStats { display: flex; gap: 6px; }
#townStats span { background: #00000066; padding: 2px 8px; border-radius: 999px; }
#zoom button.on { background: #6fbf5f; color: #fff; }
#world.planting { cursor: crosshair; }
.needs { display: grid; grid-template-columns: auto 1fr 32px; gap: 4px 8px; align-items: center; font-size: 12px; margin: 10px 0 4px; }
.needs .bar { height: 8px; background: #e8decb; border-radius: 4px; overflow: hidden; }
.needs .bar i { display: block; height: 100%; border-radius: 4px; transition: width .6s; }
.needs .v { text-align: right; color: var(--muted); }
.care { display: flex; gap: 6px; margin-top: 8px; }
.care + .care { margin-top: 12px; }
.care button { flex: 1; padding: 6px 4px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font-size: 12px; }
.care button:hover { background: #fdf3e2; }

#clipBar { position: absolute; top: 52px; right: 12px; display: flex; gap: 6px; }
#clipBar button { padding: 5px 9px; border: 2px solid #3b2f28; border-radius: 8px; background: #fffdf8; font-size: 12px; font-weight: 600; cursor: pointer; }
#clipBar button.on { background: #3b2f28; color: #fff; }
#clipBar #recBtn.rec { background: #d62d20; color: #fff; border-color: #7a140d; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .75; } }
#headline { position: absolute; left: 50%; top: 92px; transform: translateX(-50%); max-width: 80%; background: #d62d20; color: #fff; font-weight: 800;
  padding: 8px 14px; border-radius: 8px; border: 2px solid #3b2f28; box-shadow: 0 3px 0 #3b2f28; font-size: 14px; text-align: center; pointer-events: none; }
.care.town { margin-top: 0; }
.chaos { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; margin-top: 8px; }
.chaos select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); font: inherit; }

@media (max-width: 760px) {
  body { flex-direction: column; }
  #stage { height: 55vh; flex: none; }
  #panel { width: 100%; flex: 1; border-left: 0; border-top: 3px solid #3b2f28; }
}

#targetBar { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  background: #2b2420f0; color: #fff; padding: 8px 10px 8px 14px; border-radius: 12px; font-size: 13px; font-weight: 700; box-shadow: 0 4px 14px #0005; }
#targetBar[hidden] { display: none; }
#targetBar button { border: 0; border-radius: 8px; padding: 5px 10px; font: inherit; font-weight: 700; cursor: pointer; background: #ffe14d; color: #2b2420; }
#targetBar #targetCancel { background: #5a4c44; color: #fff; }
canvas.targeting { cursor: crosshair; }

#interiorBar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100% - 24px); background: #2b2420f0; color: #fff; padding: 8px 10px 8px 14px; border-radius: 12px; font-size: 13px; box-shadow: 0 4px 14px #0005; z-index: 5; }
#interiorBar[hidden] { display: none; }
#interiorCount { color: #e8d9c4; font-size: 12px; }
#interiorTabs { display: flex; gap: 4px; flex-wrap: wrap; }
#interiorTabs button, #interiorExit, #interiorSummon { border: 0; border-radius: 8px; padding: 5px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; background: #5a4c44; color: #fff; }
#interiorTabs button.on { background: #ffe14d; color: #2b2420; }
#interiorExit { background: #ffe14d; color: #2b2420; }

#summonMenu { position: absolute; z-index: 8; width: 240px; display: flex; flex-direction: column; gap: 8px; background: #2b2420f5; color: #fff;
  padding: 10px; border-radius: 12px; font-size: 13px; box-shadow: 0 6px 18px #0007; }
#summonMenu[hidden] { display: none; }
#summonSel { width: 100%; border: 0; border-radius: 8px; padding: 6px; font: inherit; font-size: 12px; background: #fffdf7; color: #2b2420; }
#summonMenu .row { display: flex; gap: 6px; }
#summonMenu button { flex: 1; border: 0; border-radius: 8px; padding: 6px 10px; font: inherit; font-weight: 700; cursor: pointer; background: #ffe14d; color: #2b2420; }
#summonMenu #summonCancel { background: #5a4c44; color: #fff; }
#summonMenu #summonFind { background: #fffdf7; color: #2b2420; }

/* Grok badge + budget popover */
button.badge { border: 0; cursor: pointer; font: inherit; font-weight: 600; }
.badge.grok.paused, .badge.grok.capped { background: #6b5a2a; border-color: #a8893a; }
#grokPop, #captionCard { position: absolute; top: 44px; left: 12px; width: 300px; max-width: calc(100% - 24px); box-sizing: border-box; background: var(--panel); color: var(--ink); border: 2px solid #3b2f28; border-radius: 12px; padding: 12px 14px; font-size: 13px; box-shadow: 0 6px 20px #0006; z-index: 5; }
#captionCard { top: auto; bottom: 16px; left: 50%; transform: translateX(-50%); width: 420px; }
.gpHead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.gpHead .ghost { background: none; border: 0; cursor: pointer; font-size: 14px; color: var(--muted); }
.gpStatus { font-weight: 600; margin-bottom: 6px; }
.gpStatus.warn { color: #a0522d; }
.gpMeter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-bottom: 6px; }
.gpMeter i { display: block; height: 100%; width: 0; background: var(--idle); transition: width .3s; }
.gpMeter i.hot { background: var(--accent); }
.gpRow { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 8px; }
.gpRow select { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.gpPause, #capCopy { width: 100%; padding: 7px; border: 0; border-radius: 8px; background: var(--ink); color: #fff; cursor: pointer; font: inherit; font-weight: 600; }
.gpPause.resume { background: var(--idle); }
#capText { width: 100%; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; resize: vertical; }
.capRow { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; }
#capCopy { width: auto; padding: 6px 16px; background: var(--accent); }
