:root {
  color-scheme: dark;
  --bg: #17211c;
  --bg2: #1d2a24;
  --panel: #223229;
  --panel2: #2b3f34;
  --line: #36503f;
  --text: #eef2e6;
  --muted: #9db1a2;
  --accent: #f2c14e;
  --accent2: #7ed6a6;
  --danger: #e8715f;
  --good: #7ed6a6;
  --mid: #f2c14e;
  --bad: #e8715f;
  --radius: 14px;
  font-family: "Segoe UI", "Trebuchet MS", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #24382d 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}
a { color: var(--accent2); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1400px; margin: 0 auto; padding: 16px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 40px; filter: drop-shadow(0 2px 0 rgba(0,0,0,.3)); }
h1 { margin: 0; font-size: clamp(22px, 4vw, 30px); letter-spacing: .3px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.clock { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; font-weight: 600; }
.clock-weather { font-size: 20px; }
.conn { font-size: 12px; color: var(--bad); }
.conn.is-on { color: var(--good); }

.eras { max-width: 1400px; margin: 0 auto; padding: 4px 16px 10px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; }
.era {
  flex: 1 0 auto; min-width: 104px; padding: 6px 10px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line);
  color: var(--muted); font-size: 13px; text-align: center; white-space: nowrap; position: relative; overflow: hidden;
}
.era .era-fill { position: absolute; inset: 0 auto 0 0; background: rgba(126,214,166,.18); width: 0; transition: width .6s; }
.era span { position: relative; }
.era.past { color: var(--text); border-color: var(--accent2); }
.era.current { color: #1b2a20; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.era.current .era-fill { background: rgba(255,255,255,.35); }
.era.future { opacity: .6; }

.layout { max-width: 1400px; margin: 0 auto; padding: 0 16px 16px; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; }
.stage, .side { min-width: 0; }
.stage { display: flex; flex-direction: column; gap: 10px; }

.hud { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 600; }
.era-chip { background: var(--accent); color: #1b2a20; border-color: var(--accent); }

.research { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.research-text { font-weight: 600; }
.research-sub { color: var(--muted); font-size: 13px; margin-top: 4px; min-height: 1em; }
.bar { height: 10px; background: #14201a; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 99px; transition: width .8s; }

.canvas-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 2px solid var(--line); background: #2f6f9f; line-height: 0; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
#map { width: 100%; height: auto; display: block; cursor: pointer; image-rendering: auto; touch-action: manipulation; }
.zoom-btn { position: absolute; top: 10px; right: 10px; z-index: 3; line-height: 1.2; background: rgba(15,22,18,.78); border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.zoom-btn:hover { border-color: var(--accent); }
.tooltip { position: absolute; pointer-events: none; background: rgba(15,22,18,.92); border: 1px solid var(--line); padding: 4px 8px; border-radius: 8px; font-size: 13px; line-height: 1.3; white-space: nowrap; z-index: 2; }

.detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; position: relative; }
.detail h3 { margin: 0 0 2px; font-size: 18px; }
.detail .sub { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.detail .close { position: absolute; top: 8px; right: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; }
.detail .thought { background: var(--bg2); border-left: 3px solid var(--accent); padding: 6px 10px; border-radius: 6px; margin: 8px 0; font-style: italic; }
.meters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.meter { font-size: 12px; color: var(--muted); }
.meter .bar { height: 8px; margin-top: 3px; }
.meter .bar-fill.good { background: var(--good); } .meter .bar-fill.mid { background: var(--mid); } .meter .bar-fill.bad { background: var(--bad); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 13px; }
button.tag { cursor: pointer; }
button.tag:hover { border-color: var(--accent2); }

.god { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.god-title { font-weight: 700; font-size: 17px; }
.god-hint { margin: 2px 0 8px; color: var(--muted); font-size: 13px; }
.god-row { display: flex; gap: 8px; }
.god input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #14201a; }
.god button[type=submit] { padding: 10px 18px; border-radius: 10px; border: 0; background: var(--accent); color: #1b2a20; font-weight: 700; cursor: pointer; }
.god button[disabled] { opacity: .55; cursor: not-allowed; }
.god-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.god-chips button { background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.god-chips button:hover { border-color: var(--accent); }
.god-msg { margin: 8px 0 0; min-height: 1.3em; font-size: 14px; color: var(--accent2); }
.god-msg.is-error { color: var(--danger); }

.side { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 520px; max-height: calc(100vh - 150px); position: sticky; top: 12px; align-self: start; height: calc(100vh - 150px); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); background: var(--bg2); }
.tab { background: none; border: 0; padding: 10px 4px; font-size: 13px; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 700; }
.panel { display: none; flex: 1; min-height: 0; }
.panel.is-active { display: flex; }
.feed { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; scrollbar-width: thin; }

.msg { display: grid; grid-template-columns: 34px 1fr; gap: 8px; animation: pop .35s ease-out; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 14px; text-shadow: 0 1px 1px rgba(0,0,0,.4); border: 2px solid rgba(255,255,255,.25); }
.bubble { background: var(--panel2); border-radius: 4px 12px 12px 12px; padding: 6px 10px; min-width: 0; overflow-wrap: anywhere; }
.bubble .who { font-weight: 700; font-size: 13px; cursor: pointer; }
.bubble .who small { color: var(--muted); font-weight: 400; }
.bubble .text { font-size: 14px; }
.bubble .when { color: var(--muted); font-size: 11px; margin-top: 2px; }
.msg.kind-quarrel .bubble { background: #4a2f2c; }
.msg.kind-love .bubble, .msg.kind-friend .bubble { background: #43324a; }
.msg.kind-peace .bubble { background: #2d4a3c; }
.msg.kind-tech .bubble, .msg.kind-era .bubble { background: #4b4426; }
.msg.kind-sleep .bubble { background: #26323f; opacity: .85; }
.msg.kind-night .bubble { background: #25303f; }
.msg.kind-hungry .bubble, .msg.kind-starving .bubble { background: #4a3a26; }
.msg.kind-god .bubble { background: #3a2f55; }

.entry { display: grid; grid-template-columns: 30px 1fr; gap: 8px; padding: 8px 10px; background: var(--bg2); border-radius: 10px; border-left: 3px solid var(--line); animation: pop .35s ease-out; }
.entry .ico { font-size: 22px; line-height: 1.1; }
.entry .when { color: var(--muted); font-size: 12px; }
.entry.kind-tech { border-left-color: var(--accent); }
.entry.kind-era { border-left-color: var(--accent2); background: #2c4034; }
.entry.kind-death { border-left-color: #8a8f99; }
.entry.kind-birth, .entry.kind-love { border-left-color: #d68fb0; }
.entry.kind-god { border-left-color: #a78bf0; }
.entry.kind-colony { border-left-color: #6fb3ff; }

.person { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 10px; cursor: pointer; background: var(--bg2); border: 1px solid transparent; text-align: left; width: 100%; }
.person:hover, .person.is-selected { border-color: var(--accent); }
.person .name { font-weight: 700; font-size: 14px; }
.person .meta { color: var(--muted); font-size: 12px; }
.era-block h4 { margin: 8px 0 4px; font-size: 14px; }
.era-block ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.era-block li { background: var(--panel2); border-radius: 99px; padding: 2px 10px; font-size: 13px; }
.era-block li.todo { opacity: .45; }
.empty { color: var(--muted); text-align: center; padding: 20px 10px; font-size: 14px; }

.foot { max-width: 1400px; margin: 0 auto; padding: 4px 16px 28px; color: var(--muted); font-size: 14px; }
.stats { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; }
.about summary { cursor: pointer; font-weight: 600; color: var(--text); }
.about p { max-width: 70ch; }
.foot-note { margin-top: 12px; }

@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: 520px; max-height: none; }
}
@media (max-width: 520px) {
  .brand p { display: none; }
  .tab { font-size: 12px; padding: 10px 2px; }
  .meters { grid-template-columns: 1fr 1fr; }
}
