:root {
  --bg: #f4efe6; --paper: #fffdf8; --ink: #22201c; --muted: #6f685c; --line: #ddd4c4;
  --road: #3a3833; --road-line: #d9c89a; --accent: #c2410c; --good: #3f7d4f; --warn: #b7791f; --bad: #b42318;
  --bubble: #efe7d6; --closed: #cfc6b5; --thought: #5b4b8a;
  --serif: 'Fraunces', Georgia, serif; --sans: 'Inter', system-ui, sans-serif; --mono: 'JetBrains Mono', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171613; --paper: #211f1b; --ink: #ede6d8; --muted: #a39a89; --line: #37332c;
    --road: #0f0e0c; --road-line: #6d6040; --bubble: #2d2a24; --closed: #3a362f; --thought: #b3a3e6;
  }
}
:root[data-theme="dark"] {
  --bg: #171613; --paper: #211f1b; --ink: #ede6d8; --muted: #a39a89; --line: #37332c;
  --road: #0f0e0c; --road-line: #6d6040; --bubble: #2d2a24; --closed: #3a362f; --thought: #b3a3e6;
}
* { box-sizing: border-box; }
html { height: 100%; overflow: hidden; background: var(--bg); }
/* the page never scrolls: controls and street stay put, the panel takes the rest and scrolls inside */
body { margin: 0 auto; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); padding: 0 16px 16px; max-width: 1280px;
  height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.controls, .street { flex: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.title { font: 700 17px/1 var(--serif); margin: 0; letter-spacing: -0.01em; white-space: nowrap; }
.clock { font: 500 13px var(--mono); white-space: nowrap; }
.timeline { font: 700 16px var(--serif); border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); padding: 4px 8px; max-width: 260px; }
#live[hidden] { display: none; }
#clock-date { color: var(--muted); font-family: var(--sans); font-size: 12px; margin-left: 2px; }

.controls { display: flex; gap: 10px; align-items: center; padding: 14px 0 12px; flex-wrap: wrap; }
.speeds { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--paper); }
.speeds button { border: 0; background: none; padding: 6px 11px; font: 500 13px var(--mono); }
.speeds button + button { border-left: 1px solid var(--line); }
.speeds button.on { background: var(--ink); color: var(--bg); }
.speeds button:disabled { opacity: .35; cursor: default; }
#scrub { flex: 1; min-width: 160px; accent-color: var(--accent); }
.days { display: flex; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); position: relative; }
.days button { border: 0; background: none; padding: 5px 10px; font: 500 16px/1 var(--sans); display: grid; place-items: center; }
.days button + button, .days input + button { border-left: 1px solid var(--line); }
.days button:disabled { opacity: .3; cursor: default; }
#when { position: absolute; left: 34px; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.live-btn { border: 1px solid var(--bad); color: var(--bad); background: none; border-radius: 8px; padding: 5px 12px; font-weight: 600; }
.live-btn.on { background: var(--bad); color: #fff; }
.api-btn { border: 1px solid var(--line); color: var(--ink); background: var(--paper); border-radius: 8px; padding: 5px 12px; font: 600 13px var(--mono); text-decoration: none; white-space: nowrap; }
.api-btn:hover { border-color: var(--muted); }

.street { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 14px 0; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; }
/* buildings keep (nearly) one size on every screen (--w, set by the viewer); the screen decides how many fit before the street scrolls */
.track { min-width: 100%; width: max-content; }
.buildings { display: grid; grid-auto-flow: column; grid-auto-columns: calc(var(--w, 122px) - 6px); gap: 6px; align-items: end; padding-top: 22px; }
/* houses get a plain gable roof: a fill triangle, with two stroked lines that start on the walls' border centre line */
.bld.house { border-radius: 0; border-top: 0; margin-top: 24px; }
.bld.house::after { content: ''; position: absolute; left: -0.75px; right: -0.75px; bottom: calc(100% - 1px); height: 24px; background: var(--bg); clip-path: polygon(50% 0.75px, 100% 100%, 0 100%); }
.roof { position: absolute; left: -0.75px; width: calc(100% + 1.5px); bottom: 100%; height: 23.25px; overflow: visible; z-index: 1; pointer-events: none; }
.roof line { stroke: var(--ink); stroke-width: 1.5px; stroke-linecap: round; }
.bld.house:hover .roof line, .bld.house.sel .roof line { stroke: var(--accent); }
.bld.vacant .roof line { stroke-dasharray: 3 3; }
.bld { border: 1.5px solid var(--ink); border-bottom: 0; border-radius: 6px 6px 0 0; min-height: 86px; padding: 5px 5px 6px; position: relative; display: flex; flex-direction: column; justify-content: space-between; background: var(--bg); }
.bld.big { min-height: 104px; }
.bld.closed { background: var(--closed); }
.bld.vacant { opacity: .6; border-style: dashed; }
.bld.vacant small { color: var(--accent); font-weight: 600; }
.bld h3 { margin: 0; font: 600 12px/1.2 var(--sans); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bld .sn { display: none; }
.bld small { display: block; color: var(--muted); font-size: 10.5px; line-height: 1.2; min-height: 2.4em; }
.occ { display: flex; min-height: calc(var(--d) + 2px); align-items: flex-end; --d: 24px; }
/* people in a building are always circles: they never shrink, and overlap only as much as the building needs */
.occ .dot { flex: none; position: relative; width: var(--d); height: var(--d); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; line-height: 1; font: 700 11px/1 var(--sans); color: #fff; border: 2px solid var(--paper); box-shadow: 0 1px 2px #0004; cursor: pointer; box-sizing: border-box; }
.occ .dot + .dot { margin-left: min(3px, calc((100% - var(--n, 1) * var(--d)) / max(var(--n, 1) - 1, 1))); }
.occ .dot.more { background: var(--muted); font-size: 0.8em; letter-spacing: -0.03em; }
.road { position: relative; height: 46px; background: var(--road); margin: 0 -14px; }
.road::after { content: ''; position: absolute; left: 0; right: 0; top: 22px; border-top: 2px dashed var(--road-line); }
.walkers { position: absolute; inset: 0 14px; z-index: 1; } /* people walk over the road markings, not under them */
.dot { position: relative; box-sizing: border-box; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font: 700 11px/1 var(--sans); color: #fff; border: 2px solid var(--paper); box-shadow: 0 1px 2px #0004; cursor: pointer; }
.dot.sleep { opacity: .55; }
.dot.sleep::after { content: 'z'; position: absolute; top: -9px; right: -7px; font-size: 10px; color: var(--muted); }
.walkers .dot { position: absolute; top: 10px; margin-left: -12px; transition: left .25s linear; }
.dot.talk { box-shadow: 0 0 0 2px var(--accent); } /* just spoke: a ring, never a size change */

.street { margin-bottom: 16px; }
.card { position: fixed; z-index: 10; width: 300px; max-width: calc(100vw - 16px); overflow-y: auto; overscroll-behavior: contain; border-radius: 12px; box-shadow: 0 10px 30px #0003; }
.card .tile { box-shadow: none; }
.card[hidden] { display: none; }
.tile { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 7px; border-top: 4px solid var(--c); box-shadow: 0 10px 30px #0003; }
.talk { list-style: none; margin: 2px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.talk li { display: grid; grid-template-columns: 38px 1fr; gap: 6px; }
.talk time { font: 11px/1.7 var(--mono); color: var(--muted); }
.talk .via { font: 600 10px var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.quiet { margin: 0; font-size: 12px; color: var(--muted); }
.card-actions { display: flex; gap: 14px; }
.inspect { position: fixed; z-index: 20; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--paper); border-left: 1px solid var(--line); box-shadow: -10px 0 40px #0003; display: flex; flex-direction: column; }
.inspect[hidden] { display: none; }
.inspect header { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.inspect header h2 { margin: 0 auto 0 0; font: 600 18px var(--serif); }
.inspect header button { border: 1px solid var(--line); background: none; border-radius: 6px; width: 30px; height: 30px; font-size: 16px; }
.inspect-body { flex: 1; overflow-y: auto; padding: 12px 16px 40px; font-size: 13px; overscroll-behavior: contain; }
.meter-h { margin-bottom: 6px; } .meter-h b { font: 600 20px var(--mono); }
.bar.big { height: 8px; }
.stacked { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12px; margin-top: 6px; }
.facts { display: grid; grid-template-columns: 80px 1fr; gap: 4px 10px; margin: 14px 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.inspect details { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; }
.inspect summary { cursor: pointer; padding: 8px 10px; display: flex; justify-content: space-between; font-weight: 600; }
.inspect .tok { font: 12px var(--mono); color: var(--muted); font-weight: 400; }
.inspect details > :not(summary) { margin: 0 10px 10px; }
.inspect pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 var(--mono); margin: 0; }
.msg { border-left: 3px solid var(--line); padding: 4px 0 4px 10px; margin: 8px 0; }
.msg.user { border-color: var(--road-line); } .msg.assistant { border-color: var(--thought); } .msg.tool { border-color: var(--good); }
.msg-h { display: flex; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 2px; }
.msg.assistant pre { color: var(--thought); font-style: italic; font-family: var(--sans); font-size: 13px; }
.call { font: 12px/1.5 var(--mono); padding: 1px 0; }
.rels { border-collapse: collapse; width: 100%; font-size: 12px; }
.rels td, .rels th { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.open { align-self: flex-start; border: 0; background: none; padding: 2px 0; color: var(--accent); font-weight: 600; font-size: 13px; }
.tile header { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.tile h2 { margin: 0; font: 600 18px/1.1 var(--serif); }
.tile .meta { color: var(--muted); font-size: 12px; }
.tile .where { font-weight: 500; font-size: 13px; }
.tile .doing { font-size: 13px; color: var(--muted); min-height: 1.4em; }
.bars { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; align-items: center; font-size: 11px; color: var(--muted); }
.bar { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--good); }
.bar i.mid { background: var(--warn); } .bar i.low { background: var(--bad); }
.money { font: 12px var(--mono); color: var(--muted); }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.feed-head { flex: none; display: flex; align-items: baseline; gap: 12px; padding: 12px 16px 10px; border-bottom: 1px solid var(--line); }
.feed-head h2 { margin: 0; font: 600 18px/1.2 var(--serif); }
#feed-clear { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 13px; }
#feed-clear[hidden] { display: none; }
.feed-box { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.bld { cursor: pointer; }
.bld:hover, .bld.sel { border-color: var(--accent); }
.admin { margin-left: auto; font: 12px var(--mono); color: var(--thought); }
.feed { list-style: none; margin: 0; padding: 4px 0; }
.feed li { display: grid; grid-template-columns: 52px 14px 1fr; gap: 8px; padding: 5px 16px; align-items: baseline; }
.feed li + li { border-top: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
.feed time { font: 12px var(--mono); color: var(--muted); }
.feed .c { width: 10px; height: 10px; border-radius: 50%; align-self: center; }
.feed .speech { font-weight: 500; }
.feed .world { color: var(--muted); font-style: italic; }
.feed .thought { color: var(--thought); font-style: italic; }
.feed .who { font-style: normal; font-weight: 600; }
.feed .act { color: var(--thought); font: 12px var(--mono); opacity: .8; }
.feed li.empty { display: block; padding: 20px 16px; color: var(--muted); }

@media (max-width: 900px) {
  .buildings { gap: 3px; }
  .bld small { display: none; }
  .bld h3 { font-size: 10px; }
  .dot { width: 20px; height: 20px; font-size: 9px; }
  .occ { --d: 20px; }
}
@media (max-width: 520px) {
  .bld { min-height: 64px; padding: 3px; }
  .bld.house { margin-top: 16px; } .bld.house::after { height: 16px; } .roof { height: 15.25px; }
  .bld .ln { display: none; } .bld .sn { display: inline; }
  .bld h3 { font-size: 9px; text-overflow: clip; }
  .bld.big { min-height: 76px; }
  .dot { width: 16px; height: 16px; font-size: 8px; border-width: 1px; }
  .occ { --d: 16px; }
  .feed li { grid-template-columns: 44px 10px 1fr; padding: 5px 10px; }
}
