:root {
  --bg: #0d1117;
  --bg2: #121822;
  --panel: #161d29;
  --panel2: #1c2534;
  --line: #263142;
  --text: #dfe6f0;
  --muted: #8494aa;
  --accent: #7ee0b5;
  --accent2: #6cb8ff;
  --warn: #ffcb6b;
  --bad: #ff7a85;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #15233a 0%, transparent 60%), var(--bg);
  color: var(--text); font: 14px/1.45 var(--sans);
  display: flex; flex-direction: column; min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #3a4a62; background: #212c3e; }
button.primary { background: #1f4d3c; border-color: #2e7a5d; color: #d8ffee; }
button.primary:hover { background: #256049; }
button.primary.running { background: #4a3a1d; border-color: #8a6a2a; color: #ffe9bf; }
button.danger { background: #4a1f27; border-color: #7a2e3a; color: #ffd8dc; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: rgba(13,17,23,.85); backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.dish { width: 34px; height: 34px; }
.dish circle:first-child { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: .7; }
.dish circle:not(:first-child) { fill: var(--accent); opacity: .75; }
.town { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.clock { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.kpis { display: flex; gap: 6px; flex-wrap: wrap; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; }
.kpi b { font-family: var(--mono); font-size: 15px; }
.kpi span { color: var(--muted); font-size: 11px; margin-left: 4px; }
.controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.delay { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.delay input { width: 90px; accent-color: var(--accent); }
.delay output { font-family: var(--mono); min-width: 32px; color: var(--text); }
.llm { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); max-width: 260px; }
.llm .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.llm.ok .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.llm.bad .dot { background: var(--bad); }
.llm .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner { margin: 10px 16px 0; padding: 10px 14px; border-radius: 8px; background: #3a1d22; border: 1px solid #6e2e38; color: #ffd8dc; }

/* ---- layout ----------------------------------------------------------- */
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr);
  gap: 14px; padding: 14px 16px; min-height: 0;
}
.col-left { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; font-weight: 600; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 8px; font-weight: 600; }
.map-panel { position: relative; padding: 0; overflow: hidden; }
#map { display: block; width: 100%; height: clamp(320px, 48vh, 560px); cursor: pointer; }
.map-hint { position: absolute; right: 10px; bottom: 8px; font-size: 11px; color: var(--muted); pointer-events: none; }
.charts { display: block; width: 100%; height: 200px; }

.roster { display: flex; flex-wrap: wrap; gap: 6px; }
.rchip {
  display: flex; align-items: center; gap: 7px; padding: 4px 10px 4px 5px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 13px;
}
.rchip.sel { border-color: var(--warn); }
.rchip.dead { opacity: .45; text-decoration: line-through; }
.av { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #0d1117; flex: none; }
.st { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.st.thinking { background: var(--accent2); animation: pulse 1s infinite; }
.st.starving { background: var(--bad); }
@keyframes pulse { 50% { opacity: .25; } }

/* ---- right column ----------------------------------------------------- */
.col-right { display: flex; flex-direction: column; padding: 0; height: calc(100vh - 90px); position: sticky; top: 76px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 12px; color: var(--muted); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { background: none; color: var(--text); }
.tabpane { flex: 1; overflow: auto; min-height: 0; display: flex; flex-direction: column; }
.feed-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.chips { display: flex; gap: 4px; }
.chip { padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.chip.active { background: #23364f; border-color: var(--accent2); }
.check { display: flex; gap: 5px; align-items: center; font-size: 12px; color: var(--muted); cursor: pointer; }
.feed { padding: 6px 12px 20px; }

.ev { padding: 9px 0; border-bottom: 1px solid #1f2836; animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }
.ev-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tick { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 34px; }
.who { font-weight: 700; cursor: pointer; }
.who:hover { text-decoration: underline; }
.act { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #222c3b; color: #b8c6da; }
.ev-text { color: #c4cfdd; margin: 2px 0 0 42px; }
.speech { margin: 6px 0 0 42px; padding: 6px 10px; background: #1d2a3d; border-left: 3px solid var(--accent2); border-radius: 0 8px 8px 0; }
.dm { margin: 6px 0 0 42px; padding: 6px 10px; background: #2b2438; border-left: 3px solid #b48cff; border-radius: 0 8px 8px 0; }
.thought { margin: 6px 0 0 42px; color: #a9b7c9; font-style: italic; }
details.reasoning { margin: 6px 0 0 42px; }
details.reasoning summary { cursor: pointer; color: var(--muted); font-size: 12px; }
pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 var(--mono); color: #b9c6d6; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0 0; max-height: 320px; overflow: auto; }
.meta { margin: 4px 0 0 42px; font-size: 11px; color: #66768c; font-family: var(--mono); }
.ev.milestone { background: linear-gradient(90deg, rgba(126,224,181,.07), transparent); border-left: 3px solid var(--accent); padding-left: 8px; }
.ev.milestone .ev-text { margin-left: 0; }
.ev.err { border-left: 3px solid var(--bad); padding-left: 8px; }
.ev.err .ev-text { margin-left: 0; color: #ffb3ba; }
.hide-reasoning details.reasoning { display: none; }

/* ---- inspector -------------------------------------------------------- */
.inspector, .society { padding: 14px; }
.ins-head { display: flex; gap: 12px; align-items: center; }
.ins-head .av { width: 46px; height: 46px; font-size: 20px; }
.ins-name { font-size: 20px; font-weight: 700; }
.ins-sub { color: var(--muted); font-size: 13px; }
.bars { display: grid; grid-template-columns: 70px 1fr 40px; gap: 6px 10px; align-items: center; margin-top: 14px; font-size: 12px; }
.bar { height: 8px; border-radius: 4px; background: #222c3b; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.inv { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.inv div { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.inv b { font-family: var(--mono); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; margin-top: 8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.box { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.mem { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.mem li { padding: 4px 0; border-bottom: 1px dashed #263142; color: #c4cfdd; }
.rel { display: grid; grid-template-columns: 1fr 120px 30px; gap: 4px 8px; align-items: center; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.row input { flex: 1; min-width: 160px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
select { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

/* ---- society ---------------------------------------------------------- */
.graph { display: block; width: 100%; height: 300px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; }
.law { padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--panel2); border-radius: 0 8px 8px 0; margin-bottom: 6px; }
.law small, .prop small { color: var(--muted); display: block; margin-top: 2px; }
.prop { padding: 8px 10px; border-left: 3px solid var(--muted); background: var(--panel2); border-radius: 0 8px 8px 0; margin-bottom: 6px; }
.prop.open { border-left-color: var(--warn); }
.prop.rejected, .prop.expired { opacity: .6; }
.places { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.place { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.place small { color: var(--muted); display: block; }

/* ---- dialogs ---------------------------------------------------------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(460px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label.check { flex-direction: row; }
dialog input:not([type=checkbox]), dialog textarea, dialog select { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; color: var(--text); }
dialog small { color: #66768c; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 6px 0 0; }
dialog .spacer { flex: 1; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .col-right { height: 75vh; position: static; }
  .controls { margin-left: 0; }
}

/* ---- roles: public viewers vs admin ---------------------------------------- */
body:not(.admin) .admin-only { display: none !important; }
body:not(.viewer) .viewer-only { display: none !important; }
.tagline { font-weight: 500; font-size: 12px; color: var(--accent); letter-spacing: .04em; margin-left: 4px; }
.badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: 2px 7px; border-radius: 999px; background: #4a3a1d; color: #ffe9bf; border: 1px solid #8a6a2a; vertical-align: 2px; margin-left: 6px; }
.live { display: flex; align-items: center; gap: 7px; margin-left: auto; font-size: 13px; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); animation: pulse 1.6s infinite; }
.intro { margin: 12px 16px 0; padding: 14px 16px; border-radius: var(--radius); background: linear-gradient(120deg, rgba(126,224,181,.10), rgba(108,184,255,.06)); border: 1px solid #2c4a45; display: flex; gap: 16px; align-items: flex-start; }
.intro h2 { color: var(--accent); margin-bottom: 6px; }
.intro p { margin: 0 0 6px; max-width: 900px; color: #c9d4e2; }
.intro button { flex: none; }
.ro { color: var(--muted); }

/* ---- God, reflections ------------------------------------------------------- */
.ev.reflect .ev-text { font-style: italic; color: #c9d4e2; }
.ev.godev { background: linear-gradient(90deg, rgba(170,120,255,.10), transparent); border-left: 3px solid #a37bff; padding-left: 8px; }
.ev.godev .ev-text { margin-left: 0; }
.god-act { background: #33264f; color: #e2d4ff; }
.gbody { margin: 6px 0 0 0; }
.ev.godev .gbody { margin-left: 42px; }
.gline { margin: 3px 0; color: #c9d4e2; font-size: 13px; }
.gline.lesson { color: #e6dcff; }
.god-head { display: flex; gap: 12px; align-items: center; }
.god-head button { margin-left: auto; }
.god-eye { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: radial-gradient(circle, #3b2a63, #1b1430); border: 1px solid #5b4594; }
.god-eye.busy { animation: pulse 1.2s infinite; }
.lessons { margin: 0; padding-left: 20px; }
.lessons li { margin: 4px 0; }
.mtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.mtable td { padding: 4px 6px; border-bottom: 1px solid #222c3b; }
.mtable .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.mtable .up { color: var(--accent); }
.mtable .down { color: var(--bad); }
.mtable tr.changed td:first-child { color: #e2d4ff; }
.small { font-size: 12px; }
.gentry { padding: 10px 0; border-bottom: 1px solid #1f2836; }
