:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel-2: #1e2530;
  --border: #2a3342;
  --text: #e6e9ee;
  --muted: #8b96a5;
  --accent: #35b8a4;
  --accent-2: #2a9385;
  --danger: #e0635f;
  --radius: 10px;
  font-size: 16px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  background: var(--accent);
  color: #06221e;
  border: 0;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}
button:hover { background: var(--accent-2); }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.ghost:hover { color: var(--text); background: var(--panel-2); }
button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: 0.5; cursor: default; }
input, textarea, select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
}
textarea { min-height: 8rem; resize: vertical; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; }
label { display: block; margin: 0.8rem 0 0.25rem; color: var(--muted); font-size: 0.85rem; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.sidebar .brand { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.75rem; }
.sidebar a.nav {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  color: var(--text);
}
.sidebar a.nav:hover { background: var(--panel-2); text-decoration: none; }
.sidebar a.nav.active { background: var(--panel-2); color: var(--accent); }
.sidebar .section { margin: 0.9rem 0 0.3rem; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.sidebar .foot { margin-top: auto; padding-top: 1rem; color: var(--muted); font-size: 0.85rem; }

.main { flex: 1; padding: 1.5rem 2rem; max-width: 900px; margin: 0 auto; width: 100%; min-width: 0; }
/* Town & interior views drop the reading-width cap: the pixel stage zooms in
   integer steps, so every extra column of pixels is usable world. */
.main.wide { max-width: none; padding: 1rem 1.25rem; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 0.9rem;
}
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.error { color: var(--danger); margin: 0.5rem 0; }

.center-box { max-width: 380px; margin: 12vh auto 0; }
.center-box .card { padding: 1.5rem; }

.bot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.9rem; }
.bot-card { cursor: pointer; transition: border-color 0.15s; }
.bot-card:hover { border-color: var(--accent); }
.bot-card .emoji { font-size: 1.7rem; }
.bot-card .name { font-weight: 700; margin: 0.2rem 0; }

.chat { display: flex; flex-direction: column; height: calc(100vh - 3rem); }
.chat-log { flex: 1; overflow-y: auto; padding-right: 0.5rem; }
.msg { max-width: 85%; margin: 0.5rem 0; padding: 0.6rem 0.9rem; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: break-word; }
.msg.user { background: var(--accent-2); color: #eafffb; margin-left: auto; }
.msg.assistant { background: var(--panel); border: 1px solid var(--border); }
.msg .fb { margin-top: 0.35rem; display: flex; gap: 0.4rem; align-items: center; }
.msg .fb button { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 0.1rem 0.45rem; border-radius: 6px; font-size: 0.85rem; }
.msg .fb button.sel { border-color: var(--accent); color: var(--accent); }
.chat-input { display: flex; gap: 0.6rem; padding-top: 0.8rem; }
.chat-input textarea { min-height: 3rem; max-height: 10rem; }
.typing { color: var(--muted); font-style: italic; padding: 0.4rem 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
code, pre { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; }
pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 1rem; overflow-x: auto; white-space: pre-wrap; }
.pill { display: inline-block; padding: 0.05rem 0.5rem; border: 1px solid var(--border); border-radius: 99px; font-size: 0.75rem; color: var(--muted); }

/* ---- town ----
   World objects carry no web chrome: no border-radius, no box-shadow, no
   gradients. Everything sits on the 32px grid at integer scale. */
.town { position: relative; overflow: hidden; }
.town, .town * { image-rendering: pixelated; }
.town-stage { position: relative; }
.town-building {
  position: absolute;
  z-index: 1;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  background-repeat: no-repeat;
  cursor: pointer;
}
.town-building.is-lively { filter: brightness(1.18); } /* lights on: talked to today */
.town-building:hover { filter: brightness(1.12); }
.town-building:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.town-building.is-busy { animation: town-busy 0.9s steps(2, jump-none) infinite; }
@keyframes town-busy { 50% { filter: brightness(1.35); } }
.town-actor {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background-repeat: no-repeat;
}
/* An agent out in the street is a target in their own right — the only way
   to reach a housemate whose home's single door leads to someone else. */
.town-actor[data-bot-id] { pointer-events: auto; cursor: pointer; }
/* Grounds the sprite against light tiles (pavement, sidewalks) where a
   pale outfit color can otherwise blend straight into the ground. */
.town-actor::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  bottom: 2px;
  width: 26px;
  height: 8px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  transform: translateX(-50%);
}
/* A hanging wooden nameplate — flat colors only, no radius/shadow/gradient. */
.town-sign {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: #5c4023;
  border: 2px solid #2f2013;
  color: #f2e3c2;
  font: 700 11px/1.4 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.5px;
  padding: 0 6px;
  pointer-events: none;
}
/* A housemate's name, worn above their head in a shared room. Sits higher
   than a building's sign so it clears the sprite's headroom. */
.interior-nametag {
  top: -4px;
  font-size: 10px;
  padding: 0 4px;
  border-width: 1px;
  z-index: 3;
}

.town-host { height: calc(100vh - 7rem); }
/* Wide mode trims the page padding, so the hosts get the difference back. */
.main.wide .town-host { height: calc(100vh - 5rem); }
.main.wide .interior { height: calc(100vh - 2rem); }

/* ---- interiors ----
   Room on the left (about a third of the width), the bot's chat as the
   main event on the right. The room keeps the town's no-chrome pixel
   rules; the chat is ordinary UI. */
.interior { display: flex; gap: 1.2rem; height: calc(100vh - 3rem); min-height: 0; }
.interior-room { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* The room stays square rather than stretching to fill its column: as wide
   as the panel (capped so the square always fits above the footer), centred
   in the leftover height. The camera fills whatever box this yields. */
.interior-host {
  aspect-ratio: 1;
  width: min(100%, calc(100vh - 8rem));
  min-height: 0;
  margin: auto 0;
  position: relative;
  overflow: hidden;
  background: #10131a;
}
.interior-chat {
  flex: 2;
  min-width: 20rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  padding-left: 1.2rem;
}
/* The extracted log+composer stack fills whatever container holds it —
   the full-page .chat and the interior's docked window alike. */
.chat-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.swatch-row { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.swatch {
  width: 44px;
  height: 44px;
  padding: 4px;
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  line-height: 1;
}
.swatch:hover { background: var(--panel-2); border-color: var(--muted); }
.swatch.sel { border-color: var(--accent); }
.swatch canvas { width: 32px; height: 32px; image-rendering: pixelated; display: block; }
.swatch-preview { width: 96px; height: 96px; image-rendering: pixelated; }
.town-footer { padding: 0.4rem 0.6rem; color: var(--muted); font-size: 0.75rem; }

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .foot { margin: 0 0 0 auto; padding: 0; }
  .main { padding: 1rem; }
  .chat { height: calc(100vh - 9rem); }
  /* Narrow screens stack the room above its chat window. The stacked
     sidebar eats vertical space, so wide mode gives its gains back here. */
  .interior, .main.wide .interior { flex-direction: column; height: calc(100vh - 9rem); }
  .main.wide { padding: 1rem; }
  .main.wide .town-host { height: calc(100vh - 7rem); }
  .interior-room { flex: 1; min-height: 0; }
  /* Stacked layout: the square would eat the chat's share, so the room
     fills whatever height its half of the stack allows instead. */
  .interior-host { aspect-ratio: auto; width: 100%; flex: 1; margin: 0; }
  .interior-chat { flex: 1.2; min-width: 0; max-width: none; border-left: 0; padding-left: 0; border-top: 1px solid var(--border); padding-top: 0.8rem; }
}

/* Who else is home. The room is the pleasant way to switch; this is the
   fast way, for when you know who you want. */
.housemates { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.housemate {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.housemate:hover { border-color: var(--accent, #888); }
.housemate[aria-current="true"] {
  border-color: var(--accent, #888);
  background: rgba(127, 127, 127, 0.14);
  font-weight: 600;
  cursor: default;
}

.attach-chips { display: none; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.4rem; }
.attach-chips.sent { display: flex; margin-top: 0.4rem; margin-bottom: 0; }
.chip { display: inline-flex; align-items: center; gap: 0.3rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 0.15rem 0.5rem; font-size: 0.8rem; color: var(--muted); text-decoration: none; }
.chip-remove { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 0.8rem; }
.attach-thumb { max-width: 160px; max-height: 160px; border-radius: 6px; display: block; }
/* Streamed text before the stored reply replaces it. The caret is the only
   difference from a settled .msg.assistant — it says "still writing". */
.msg.assistant.streaming::after {
  content: "▍";
  color: var(--accent);
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
