/* ---------- theme ---------- */
/* Light is the default; the Theme button flips data-theme on <body>. */
:root {
  --bg-deep: #dde3ea;
  --bg-void: #c8d0da;
  --panel: #f2f4f7;
  --raised: #ffffff;
  --raised-hover: #e2e9f2;
  --border: #c4cedb;
  --border-2: #a8b6c8;
  --border-soft: #d8e0ea;
  --border-soft-0: #d8e0ea00;
  --text: #333d4e;
  --text-hi: #1c2432;
  --text-soft: #4a5566;
  --dim: #64738a;
  --dim-2: #8494aa;
  --accent: #3565b8;
  --accent-hi: #2a53a0;
  --accent-hover: #4a78cc;
  --brand: #2a53a0;
  --link: #2f62c0;
  --head: #4a6284;
  --gold: #9a6d08;
  --panel-a: rgba(248,250,252,.97);
  --float-a: rgba(255,255,255,.95);
  --hud-a: rgba(245,248,251,.88);
  --btn-on-text: #ffffff;
}
body[data-theme="dark"] {
  --bg-deep: #10141c;
  --bg-void: #0a0d13;
  --panel: #1a2130;
  --raised: #222b3d;
  --raised-hover: #2c3852;
  --border: #2c3648;
  --border-2: #3a465c;
  --border-soft: #242e42;
  --border-soft-0: #242e4200;
  --text: #d7dde8;
  --text-hi: #e8edf5;
  --text-soft: #b9c6da;
  --dim: #93a0b5;
  --dim-2: #6b7890;
  --accent: #3d63a8;
  --accent-hi: #5580c9;
  --accent-hover: #4a74c0;
  --brand: #8fb7ff;
  --link: #7fa8e8;
  --head: #9fb4d4;
  --gold: #ffd97a;
  --panel-a: rgba(22,28,40,.97);
  --float-a: rgba(28,36,52,.95);
  --hud-a: rgba(20,26,38,.85);
  --btn-on-text: #ffffff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  font-size: 13px;
  user-select: none;
}
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  flex-wrap: wrap;
}
#brand { font-weight: 800; letter-spacing: 2px; color: var(--brand); font-size: 14px; }
#build-tag { font-weight: 400; letter-spacing: 0; color: var(--dim-2); font-size: 10px; }
#cityname {
  background: var(--bg-deep); border: 1px solid var(--border); color: var(--text-hi);
  padding: 3px 8px; border-radius: 4px; width: 130px; font-size: 13px;
}
/* Read-only stats are plain text; only the treasury invites a click. */
.stat { padding: 3px 4px; background: none; border-radius: 4px; white-space: nowrap; color: var(--text-soft); }
.stat.money {
  cursor: pointer; color: var(--gold); font-weight: 600;
  background: var(--raised); box-shadow: 0 1px 2px rgba(10,16,28,0.12); padding: 3px 8px;
}
.stat.money:hover { background: var(--raised-hover); }
.spacer { flex: 1; }
#happy-bar {
  display: inline-block; width: 60px; height: 8px; background: var(--bg-deep);
  border-radius: 4px; overflow: hidden; vertical-align: middle; margin-left: 4px;
}
#happy-fill { display: block; height: 100%; width: 50%; background: #6fcf6f; transition: width .5s, background .5s; }
#speed-controls { display: flex; gap: 2px; }
button {
  background: var(--raised); color: var(--text); border: none;
  box-shadow: 0 1px 2px rgba(10, 16, 28, 0.14);
  border-radius: 5px; padding: 3px 9px; cursor: pointer; font-size: 12px;
  font-family: inherit;
}
.icon-btn {
  background: none; box-shadow: none; padding: 2px 4px; color: var(--dim);
}
.icon-btn:hover { color: var(--text-hi); background: none; }
button:hover { background: var(--raised-hover); }
button.spd.on { background: var(--accent); border-color: var(--accent-hi); color: #fff; }
select {
  background: var(--raised); color: var(--text); border: none;
  box-shadow: 0 1px 2px rgba(10,16,28,0.14);
  border-radius: 4px; padding: 3px 5px; font-size: 12px; font-family: inherit;
}
.linkish {
  background: none; border: none; color: var(--link); cursor: pointer;
  font-size: 11px; padding: 0 2px; float: right;
}
.linkish:hover { background: none; text-decoration: underline; }

/* App menu: the topbar overflow, SaaS style. */
#btn-menu { display: flex; align-items: center; padding: 3px 7px; }
#app-menu {
  position: absolute; top: 40px; right: 8px; z-index: 45;
  display: flex; flex-direction: column; gap: 2px; min-width: 172px;
  background: var(--panel-a); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
#app-menu.hidden { display: none; }
#app-menu button {
  text-align: left; background: none; border: none; padding: 6px 8px;
  border-radius: 5px; font-size: 12px;
}
#app-menu button:hover { background: var(--raised-hover); }
#app-menu .menu-sec {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim-2); padding: 5px 8px 1px;
}

/* ---------- layout ---------- */
#main { display: flex; flex: 1 1 auto; min-height: 0; }
#btn-nav {
  background: none; border: none; padding: 2px 6px; cursor: pointer;
  color: var(--dim); display: flex; align-items: center;
}
#btn-nav:hover { color: var(--text-hi); }
body.nav-collapsed #toolbar { display: none; }
#toolbar {
  flex: 0 0 118px; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 6px; display: flex; flex-direction: column; gap: 4px;
}
.tool-group-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim-2); margin: 6px 2px 1px;
}
.tool-cat { display: flex; flex-direction: column; gap: 4px; }
.tool-cat-head {
  display: flex; justify-content: space-between; align-items: center;
  background: none; border: none; border-top: 1px solid var(--border-soft);
  padding: 6px 3px 3px; cursor: pointer; width: 100%;
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim-2); text-align: left;
}
.tool-cat-head:hover { color: var(--text-hi); }
.tool-cat.open .tool-cat-head { color: var(--head); }
.tool-cat-body { display: none; flex-direction: column; gap: 4px; }
.tool-cat.open .tool-cat-body { display: flex; }
.tool {
  display: flex; align-items: center; gap: 6px;
  background: var(--raised); border: none; box-shadow: 0 1px 2px rgba(10,16,28,0.12); border-radius: 5px;
  padding: 4px; cursor: pointer; text-align: left; width: 100%;
}
.tool:hover { background: var(--raised-hover); }
.tool.on { background: var(--accent); border-color: var(--accent-hi); }
.tool.on .t-name, .tool.on .t-cost { color: var(--btn-on-text); }
.tool.locked { opacity: .38; cursor: not-allowed; }
.tool canvas { flex: 0 0 26px; border-radius: 3px; background: #55794a; }
.tool .t-name { font-size: 11px; line-height: 1.15; }
.tool .t-cost { font-size: 10px; color: var(--gold); }
.tool.locked .t-cost { color: var(--dim); }

#viewport { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; background: var(--bg-void); }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }

/* ---------- HUD widgets ---------- */
#tooltip {
  position: absolute; pointer-events: none; z-index: 30;
  background: var(--float-a); border: 1px solid var(--border-2); border-radius: 5px;
  padding: 5px 8px; font-size: 11.5px; max-width: 230px; line-height: 1.35;
}
#tooltip .bad { color: #ff8f8f; }
#tooltip .good { color: #8fe89f; }
#tooltip b { color: var(--text-hi); }

#rci-panel {
  position: absolute; right: 10px; bottom: 10px; z-index: 20;
  display: flex; gap: 7px; align-items: flex-end;
  background: var(--hud-a); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px 4px;
}
.rci-col { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rci-bar {
  width: 13px; height: 56px; background: var(--bg-deep); border-radius: 3px;
  display: flex; align-items: flex-end; overflow: hidden;
}
.rci-fill { width: 100%; height: 0%; transition: height .6s; }
#rci-r { background: #4caf6d; } #rci-c { background: #4c86d8; } #rci-i { background: #cfa23c; } #rci-o { background: #a56ee0; }
.rci-lab { font-size: 10px; font-weight: 700; }

#minimap {
  touch-action: none;
  position: absolute; left: 10px; bottom: 10px; z-index: 20;
  border: 1px solid var(--border-2); border-radius: 4px; cursor: pointer;
  image-rendering: pixelated; width: 128px; height: 128px;
  background: var(--bg-void);
}

#notif-advisor:not(:empty) {
  border-bottom: 1px solid var(--border-soft); padding: 4px 0 6px; margin-bottom: 4px;
}
.advisor-item { color: var(--text-soft); font-size: 11.5px; line-height: 1.4; padding: 2px 0; }
.advisor-item b { color: var(--gold); }
.advisor-item svg { color: var(--dim-2); }

/* Single-slot notification pill: replaces itself, never stacks. */
#toast-pill {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 40; pointer-events: none;
  background: var(--float-a); border: 1px solid var(--accent); border-radius: 16px;
  padding: 6px 16px; font-size: 12px; max-width: min(420px, 80%);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: toast-in .2s ease-out;
  box-shadow: 0 3px 14px rgba(0,0,0,.4);
}
#toast-pill b { color: var(--gold); }
#toast-pill.pill-warn { border-color: #c86a3a; }
#toast-pill.pill-big { border-color: var(--gold); font-size: 13px; }
#toast-pill.hidden { display: none; }
@keyframes toast-in { from { transform: translate(-50%, -8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* Bell + badge in the topbar. */
#btn-notif { position: relative; padding: 3px 8px; }
#notif-badge {
  position: absolute; top: -5px; right: -5px;
  background: #d84838; color: #fff; font-size: 9.5px; font-weight: 700;
  border-radius: 8px; padding: 1px 4.5px; pointer-events: none;
}
#notif-panel {
  position: absolute; right: 10px; top: 6px; z-index: 41; width: 320px;
  background: var(--panel-a); border: 1px solid var(--border-2); border-radius: 8px;
  padding: 10px 13px; max-height: 70%; overflow-y: auto; font-size: 12px;
}
.notif-row {
  padding: 5px 0; border-bottom: 1px solid var(--border-soft); line-height: 1.4;
  color: var(--text-soft);
}
.notif-row:last-child { border-bottom: none; }
.notif-row b { color: var(--gold); }
.notif-row.warn .notif-msg { color: #e8a888; }
.notif-row.big .notif-msg { color: var(--gold); }
.notif-when {
  float: right; color: var(--dim-2); font-size: 10px; margin-left: 8px;
}
#notif-tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.notif-tab {
  flex: 1; padding: 4px; font-size: 11px; background: var(--panel);
  border: 1px solid var(--border); color: var(--dim);
}
.notif-tab.on { background: var(--accent); border-color: var(--accent-hi); color: #fff; }
#notif-pulse-list .pulse-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}

/* ---------- panels ---------- */
#info-panel, #budget-panel, #checklist {
  position: absolute; z-index: 25;
  background: var(--panel-a); border: 1px solid var(--border-2); border-radius: 7px;
  padding: 9px 11px; font-size: 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,.45);
}
#info-panel { right: 10px; top: 10px; width: 245px; }
#budget-panel { left: 50%; top: 60px; transform: translateX(-50%); width: 290px; }
#checklist { left: 10px; top: 10px; width: 235px; }
.panel-title { font-weight: 700; color: var(--text-hi); margin-bottom: 6px; font-size: 12.5px; }
#info-body .row, #budget-body .row, .wm-body .row {
  display: flex; justify-content: space-between; padding: 1.5px 0;
}
#info-body .row span:last-child, #budget-body .row span:last-child, .wm-body .row span:last-child { color: var(--text-hi); }
#info-body .sec, .wm-body .sec { margin-top: 6px; font-weight: 600; color: var(--head); }
#info-body .names, .wm-body .names { color: var(--text-soft); font-size: 11px; line-height: 1.4; }
#budget-body .row.total { border-top: 1px solid var(--border-2); margin-top: 4px; padding-top: 4px; font-weight: 700; }
.budget-tax { margin-top: 8px; }
.budget-tax input { width: 100%; }
#checklist ul { list-style: none; margin: 0 0 5px; }
#checklist li { padding: 2px 0 2px 18px; position: relative; color: var(--text-soft); }
#checklist li::before {
  content: ""; position: absolute; left: 2px; top: 6px; width: 9px; height: 9px;
  border: 1px solid var(--dim-2); border-radius: 2px;
}
#checklist li.done { color: #6fcf6f; text-decoration: line-through; }
#checklist li.done::before { background: #4caf6d; border-color: #4caf6d; }

/* ---------- help ---------- */
#help-overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(8,10,15,.72);
  display: flex; align-items: center; justify-content: center;
}
#help-card {
  background: var(--panel); border: 1px solid var(--accent); border-radius: 10px;
  max-width: 560px; width: 92%; max-height: 86%; overflow-y: auto;
  padding: 18px 22px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
#help-card .panel-title { font-size: 17px; color: var(--brand); }
#help-body p, #help-body ol { margin: 8px 0; line-height: 1.5; }
#help-body ol { padding-left: 20px; }
#help-body b { color: var(--gold); }
#help-autopilot {
  display: block; width: 100%; margin-top: 10px; padding: 9px;
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
#help-autopilot:hover { filter: brightness(1.1); }
#help-close {
  margin-top: 12px; width: 100%; padding: 8px;
  background: var(--accent); border-color: var(--accent-hi); color: #fff; font-size: 14px; font-weight: 600;
}
#help-close:hover { background: var(--accent-hover); }

/* ---------- v2 panels ---------- */
#event-card {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 52px; z-index: 35;
  width: 360px; background: var(--panel-a);
  border: 1px solid #d8b84a; border-radius: 8px; padding: 11px 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
  animation: toast-in .3s ease-out;
}
#event-card .panel-title { color: var(--gold); }
#event-body { font-size: 12px; line-height: 1.45; color: var(--text-soft); margin-bottom: 9px; }
#event-buttons { display: flex; gap: 7px; }
.ev-btn { flex: 1; padding: 6px 8px; font-size: 12px; line-height: 1.25; }
.ev-btn.yes { background: var(--accent); border-color: var(--accent-hi); color: #fff; }
.ev-btn.yes:hover { background: var(--accent-hover); }

#follow-panel {
  position: absolute; left: 150px; bottom: 10px; z-index: 22; width: 230px;
  background: var(--panel-a); border: 1px solid var(--border-2); border-radius: 7px;
  padding: 8px 11px; font-size: 12px;
}
#follow-body { color: var(--text-soft); line-height: 1.45; }
#follow-body b { color: var(--gold); }

#policies-panel {
  position: absolute; left: 50%; top: 60px; transform: translateX(-50%); z-index: 26;
  width: 330px; background: var(--panel-a); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 10px 13px; max-height: 75%; overflow-y: auto;
}
.policy-row { display: block; padding: 6px 0; border-bottom: 1px solid var(--border-soft-0); cursor: pointer; }
.policy-row b { color: var(--text-hi); font-size: 12px; }
.policy-row .p-cost { color: var(--gold); font-size: 11px; margin-left: 4px; }
.policy-row .p-desc { color: var(--dim); font-size: 11px; }

#times-panel {
  position: absolute; inset: 0; z-index: 45;
  background: rgba(8,10,15,.7);
  display: flex; align-items: center; justify-content: center;
}
#times-inner {
  background: #ece5d3; color: #2a2620; width: 470px; max-width: 94%;
  max-height: 86%; overflow-y: auto; padding: 18px 24px;
  font-family: Georgia, "Times New Roman", serif;
  box-shadow: 0 12px 44px rgba(0,0,0,.6);
  border: 1px solid #b8ae96;
}
#times-masthead {
  font-size: 23px; font-weight: 700; letter-spacing: 2px; text-align: center;
  border-bottom: 2.5px solid #2a2620; padding-bottom: 5px;
}
#times-date { text-align: center; font-size: 11px; padding: 4px 0 8px; border-bottom: 1px solid #2a2620; }
#times-headline { font-size: 19px; font-weight: 700; line-height: 1.25; padding: 10px 0 8px; }
#times-columns { display: flex; gap: 14px; font-size: 12px; line-height: 1.5; padding-bottom: 10px; }
.times-col { flex: 1; border-top: 1px solid #8a8272; padding-top: 6px; }
#times-stats {
  font-size: 10.5px; border-top: 2px solid #2a2620; padding-top: 5px; text-align: center;
}
#times-close {
  margin-top: 10px; width: 100%; background: #2a2620; color: #ece5d3;
  border: none; padding: 7px; font-family: inherit;
}

#endgame-overlay {
  position: absolute; inset: 0; z-index: 55;
  background: rgba(8,10,15,.78);
  display: flex; align-items: center; justify-content: center;
}
#endgame-card {
  background: var(--panel); border: 1px solid var(--gold); border-radius: 10px;
  width: 420px; max-width: 92%; padding: 20px 24px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
#endgame-card .panel-title { font-size: 18px; color: var(--gold); }
#endgame-body { font-size: 13px; line-height: 1.5; color: var(--text-soft); margin: 8px 0 14px; }
#endgame-card button { width: 100%; margin-top: 6px; padding: 8px; font-size: 13px; }
#endgame-continue { background: var(--accent); border-color: var(--accent-hi); color: #fff; }

#newgame-modal {
  position: absolute; inset: 0; z-index: 55;
  background: rgba(8,10,15,.78);
  display: flex; align-items: center; justify-content: center;
}
#newgame-card {
  background: var(--panel); border: 1px solid var(--accent); border-radius: 10px;
  width: 480px; max-width: 94%; max-height: 88%; overflow-y: auto;
  padding: 16px 20px;
}
#scenario-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.scen {
  text-align: left; padding: 8px 11px; line-height: 1.4; font-size: 12px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--raised);
}
.scen b { color: var(--text-hi); font-size: 13px; }
.scen span { color: var(--dim); }
.scen .scen-goal { color: var(--gold); }
.scen.on { border-color: var(--accent-hi); background: #2c3c5c; }
#disasters-row { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 10px; cursor: pointer; }
#newgame-buttons { display: flex; gap: 8px; }
#newgame-start { flex: 1; background: var(--accent); border-color: var(--accent-hi); color: #fff; padding: 8px; font-size: 13px; }
#newgame-cancel { padding: 8px 14px; }

/* ---------- AI mayor panel ---------- */
#mayor-panel {
  position: absolute; right: 10px; top: 10px; z-index: 27; width: 320px;
  background: var(--panel-a); border: 1px solid var(--border-2); border-radius: 8px;
  padding: 10px 13px; max-height: 84%; overflow-y: auto; font-size: 12px;
}
#mayor-mode-row { display: flex; gap: 12px; margin-bottom: 7px; }
#mayor-mode-row label { cursor: pointer; color: var(--text-soft); }
#mayor-profile-row { margin-bottom: 4px; color: var(--dim); }
#mayor-profile-row select { margin-left: 4px; }
.mayor-sec {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim-2); margin: 9px 0 4px;
}
.need-row { display: flex; align-items: center; gap: 6px; padding: 1.5px 0; }
.need-name { flex: 0 0 92px; font-size: 11px; color: var(--text-soft); }
.need-bar {
  flex: 1; height: 7px; background: var(--bg-deep); border-radius: 3px; overflow: hidden;
}
.need-fill { display: block; height: 100%; width: 0; transition: width .4s; }
.need-score { flex: 0 0 22px; text-align: right; font-size: 10px; color: var(--dim); }
.need-w { flex: 0 0 52px; height: 10px; }
#mayor-gov { color: var(--text-soft); line-height: 1.5; }
#mayor-gov b { color: var(--gold); }
.mlog { color: var(--dim); font-size: 11px; padding: 1.5px 0; line-height: 1.35; }

/* ---------- living city ---------- */
.pulse-item { color: var(--text-soft); padding: 1.5px 0; line-height: 1.35; }
.pulse-dot { display: inline-block; width: 6px; height: 6px; border-radius: 3px;
  margin-right: 5px; vertical-align: middle; }

#citizens-panel, #firms-panel {
  position: absolute; left: 128px; top: 10px; z-index: 26; width: 300px;
  background: var(--panel-a); border: 1px solid var(--border-2); border-radius: 8px;
  padding: 10px 13px; max-height: 82%; overflow-y: auto; font-size: 12px;
}
#citizen-list, #firm-list { max-height: 52vh; overflow-y: auto; }
#citizen-search, #firm-search {
  width: 100%; background: var(--bg-deep); border: 1px solid var(--border); color: var(--text-hi);
  padding: 4px 8px; border-radius: 4px; margin-bottom: 6px; font-size: 12px;
}
.firm-zone {
  display: inline-block; padding: 0 5px; border-radius: 3px; font-size: 9.5px;
  font-weight: 700; margin-right: 4px; vertical-align: 1px; color: var(--bg-deep);
}
.cit-row { padding: 5px 4px; border-radius: 5px; cursor: pointer; line-height: 1.3; }
.cit-row:hover { background: var(--raised-hover); }
.cit-row b { color: var(--text-hi); }
.cit-stage { float: right; color: var(--dim-2); font-size: 10px; text-transform: uppercase; }
.cit-last { color: var(--dim); font-size: 11px; }
.cit-name { font-size: 15px; font-weight: 700; color: var(--gold); margin: 6px 0 3px; }
.cit-meta { color: var(--text-soft); line-height: 1.5; margin-bottom: 6px; }
.cit-mood { color: var(--dim); margin-bottom: 8px; }
.cit-mood-bar { display: inline-block; width: 70px; height: 8px; background: var(--bg-deep);
  border-radius: 4px; overflow: hidden; vertical-align: middle; }
.cit-mood-bar span { display: block; height: 100%; }
#cit-follow { width: 100%; padding: 6px; background: var(--accent); border-color: var(--accent-hi); color: #fff; }
.linklike { color: var(--link); cursor: pointer; text-decoration: underline; font-size: 11px; }

#stats-panel {
  position: absolute; left: 50%; top: 54px; transform: translateX(-50%); z-index: 26;
  width: 300px; background: var(--panel-a); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 10px 13px; max-height: 84%; overflow-y: auto; font-size: 12px;
}
.chart-row { margin-bottom: 7px; }
.chart-label { color: var(--dim); font-size: 11px; margin-bottom: 2px; }
.chart-label b { color: var(--text-hi); }
.chart-row canvas { border-radius: 4px; display: block; }
#stats-employers .row { display: flex; justify-content: space-between; padding: 2px 0;
  color: var(--text-soft); font-size: 11.5px; }
#stats-employers .row span:last-child { color: var(--gold); }

/* ---------- window manager ---------- */
.wm-window {
  position: absolute; z-index: 60;
  background: var(--panel-a); border: 1px solid var(--border-2);
  border-radius: 8px; font-size: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  min-width: 220px;
}
.wm-head {
  touch-action: none;
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 8px 6px 12px; cursor: move; user-select: none;
  border-bottom: 1px solid var(--border);
}
.wm-title {
  font-weight: 700; color: var(--gold); font-size: 12.5px; pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 230px;
}
.wm-btns { display: flex; gap: 3px; flex: 0 0 auto; }
.wm-btns button {
  width: 20px; height: 18px; padding: 0; font-size: 12px; line-height: 1;
  background: none; box-shadow: none; color: var(--dim);
}
.wm-btns button:hover { color: var(--text-hi); background: var(--raised-hover); }
.wm-btns button:hover { background: var(--raised-hover); }
.wm-body {
  padding: 9px 12px 11px;
  max-height: 62vh; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--dim-2) transparent;
}
.wm-body::-webkit-scrollbar { width: 8px; }
.wm-body::-webkit-scrollbar-thumb { background: var(--dim-2); border-radius: 4px; }
.wm-body::-webkit-scrollbar-track { background: transparent; }
.wm-body canvas { border-radius: 5px; display: block; border: 1px solid #3a3026; }
#wm-dock {
  position: absolute; bottom: 10px; left: 150px; z-index: 24;
  display: flex; gap: 5px; flex-wrap: wrap; max-width: 45%;
}
.wm-chip {
  background: var(--float-a); border: 1px solid var(--border-2); border-radius: 5px;
  padding: 4px 10px; font-size: 11px; color: var(--gold);
  max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wm-chip:hover { background: var(--raised-hover); }
.cw-actions { display: flex; gap: 5px; margin-bottom: 7px; }
.cw-actions button { flex: 1; padding: 5px 4px; font-size: 11px; }
.cw-actions .cw-follow { background: var(--accent); border-color: var(--accent-hi); color: #fff; }
.hw-activity { margin-top: 7px; }
.home-line { color: #e8d8b0; font-size: 12px; padding: 1.5px 0; font-style: italic; }
.home-inv { color: var(--text-soft); line-height: 1.5; }
.home-meta { color: var(--dim-2); font-size: 11px; margin-top: 4px; }
#cit-home { width: 100%; padding: 6px; margin-top: 5px; }

/* ---------- save manager ---------- */
#saves-panel {
  position: absolute; left: 50%; top: 54px; transform: translateX(-50%); z-index: 29;
  width: 380px; background: var(--panel-a); border: 1px solid var(--border-2);
  border-radius: 8px; padding: 10px 13px; max-height: 84%; overflow-y: auto; font-size: 12px;
}
#saves-new-row { display: flex; gap: 6px; margin-bottom: 8px; }
#save-name {
  flex: 1; background: var(--bg-deep); border: 1px solid var(--border); color: var(--text-hi);
  padding: 4px 8px; border-radius: 4px; font-size: 12px;
}
#save-new { background: var(--accent); border-color: var(--accent-hi); color: #fff; }
.save-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 4px; border-bottom: 1px solid #26304466;
}
.save-info b { color: var(--text-hi); }
.save-info span { color: var(--dim); font-size: 11px; line-height: 1.35; }
.save-btns { display: flex; gap: 4px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.save-btns button { padding: 3px 7px; font-size: 11px; }
.save-del { color: #ff8f8f; }
#save-io {
  width: 100%; height: 54px; background: var(--bg-deep); border: 1px solid var(--border);
  color: var(--dim); border-radius: 4px; font-size: 10px; font-family: monospace;
  padding: 5px; resize: vertical; margin-bottom: 6px;
}
#saves-io-row { display: flex; gap: 6px; }

.hidden { display: none !important; }


/* ---------- on-screen zoom (touch) ---------- */
#zoom-ctl {
  position: absolute; right: 10px; bottom: 116px; z-index: 20;
  display: none; flex-direction: column; gap: 6px;
}
#zoom-ctl button {
  width: 40px; height: 40px; font-size: 20px; line-height: 1;
  background: var(--float-a); border: 1px solid var(--border-2); border-radius: 8px;
}
@media (pointer: coarse) {
  #zoom-ctl { display: flex; }
  #tooltip { display: none !important; }
}
body.touch #zoom-ctl { display: flex; }
body.touch #tooltip { display: none !important; }

/* ---------- small screens: phone / narrow tablet ---------- */
@media (max-width: 860px) {
  body { font-size: 12px; }

  /* Top bar: one scrollable row, no wrapping into a tall block. */
  #topbar {
    flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding: 5px 6px;
    scrollbar-width: none;
  }
  #topbar::-webkit-scrollbar { display: none; }
  #brand { font-size: 12px; letter-spacing: 1px; }
  #cityname { width: 84px; flex: 0 0 auto; }
  .stat, button, select { flex: 0 0 auto; }
  button { padding: 5px 9px; }
  #stat-jobs, #stat-happy { display: none; }

  /* Portrait: toolbar docks to the bottom as a horizontal strip. */
  @media (orientation: portrait) {
    #main { flex-direction: column; }
    #toolbar {
      order: 2;
      flex: 0 0 62px;
      flex-direction: row; align-items: stretch;
      overflow-x: auto; overflow-y: hidden;
      border-right: none; border-top: 1px solid var(--border);
      padding: 5px 6px;
      scrollbar-width: none;
    }
    #toolbar::-webkit-scrollbar { display: none; }
    .tool-group-label {
      writing-mode: vertical-rl; margin: 0 1px; font-size: 8.5px;
      flex: 0 0 auto; align-self: center;
    }
    .tool-cat { flex-direction: row; align-items: stretch; flex: 0 0 auto; gap: 4px; }
    .tool-cat-head {
      writing-mode: vertical-rl; width: auto; border-top: none;
      border-left: 1px solid var(--border-soft);
      padding: 2px 1px; font-size: 8px; letter-spacing: 0;
      max-height: 100%; overflow: hidden;
    }
    .tool-cat-head .tc-arrow { display: none; }
    .tool-cat.open .tool-cat-body { display: flex; flex-direction: row; gap: 4px; }
    .tool {
      width: auto; flex: 0 0 auto; flex-direction: column; gap: 2px;
      padding: 3px 7px; justify-content: center;
    }
    .tool canvas { flex: 0 0 20px; width: 20px; height: 20px; }
    .tool .t-name { font-size: 9px; text-align: center; max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .tool .t-cost { display: none; }
  }

  /* Landscape: vertical space is scarce, so the toolbar stays a slim left
     sidebar and detail windows become a right-hand drawer. */
  @media (orientation: landscape) {
    #toolbar {
      flex: 0 0 96px;
      overflow-y: auto; overflow-x: hidden;
      scrollbar-width: none;
      padding: 4px;
    }
    #toolbar::-webkit-scrollbar { display: none; }
    .tool { padding: 3px 4px; gap: 4px; }
    .tool canvas { flex: 0 0 20px; width: 20px; height: 20px; }
    .tool .t-name { font-size: 9.5px; }
    .tool .t-cost { display: none; }
    .tool-group-label { font-size: 8.5px; margin: 4px 2px 0; }
    .tool-cat-head { font-size: 8.5px; padding: 4px 2px 2px; }
  }

  /* HUD widgets shrink out of the way of thumbs. */
  #minimap { width: 84px; height: 84px; left: 6px; bottom: 6px; }

  #rci-panel { right: 6px; bottom: 6px; padding: 5px 7px 3px; gap: 5px; }
  .rci-bar { height: 38px; width: 11px; }
  #zoom-ctl { bottom: 96px; left: 6px; right: auto; }
  #checklist { width: 190px; font-size: 11px; }
  #pulse-items { max-height: 96px; overflow: hidden; }
  #toast-pill { max-width: 88%; font-size: 11.5px; }

  /* Detail windows become bottom sheets. */
  .wm-window {
    left: 0 !important; right: 0 !important;
    top: auto !important; bottom: 0 !important;
    width: auto !important; max-width: none;
    border-radius: 14px 14px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    transition: transform .16s ease-out;
    box-shadow: 0 -6px 28px rgba(0,0,0,.5);
    background: var(--panel);
  }
  .wm-window .wm-head {
    padding-top: 14px; position: relative; cursor: default;
  }
  .wm-window .wm-head::before {
    content: ""; position: absolute; top: 5px; left: 50%;
    transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 2px; background: #4a5a78;
  }
  .wm-window .wm-btns button {
    width: 34px; height: 30px; padding: 0;
    display: flex; align-items: center; justify-content: center;
  }
  .wm-window .wm-body {
    max-height: 42vh; overflow-y: auto;
    padding-bottom: calc(11px + env(safe-area-inset-bottom));
  }

  /* The chip bar of tucked-away windows: one scrollable row. */
  #wm-dock {
    left: 6px; right: 6px; bottom: 8px; max-width: none;
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    z-index: 88;
  }
  #wm-dock::-webkit-scrollbar { display: none; }
  .wm-chip { flex: 0 0 auto; padding: 7px 12px; font-size: 12px; }

  /* Tool panels anchor to the bottom as sheets too. */
  #budget-panel, #policies-panel, #mayor-panel, #citizens-panel,
  #firms-panel, #notif-panel, #stats-panel, #saves-panel {
    left: 0; right: 0; top: auto; bottom: 0; transform: none;
    width: auto; max-width: none; max-height: 62vh;
    border-radius: 14px 14px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    z-index: 46;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 28px rgba(0,0,0,.5);
  }
  #event-card {
    width: auto; left: 8px; right: 8px; transform: none; bottom: 74px;
  }
  #follow-panel { max-width: 60vw; }
}


/* Landscape phones: right-hand drawer for windows and panels. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .wm-window {
    left: auto !important; right: 0 !important;
    top: 0 !important; bottom: 0 !important;
    width: 300px !important;
    border-radius: 0;
    border-top: none;
    box-shadow: -6px 0 28px rgba(0,0,0,.5);
  }
  .wm-window { background: var(--panel); }
  .wm-window .wm-head { padding-top: 8px; }
  .wm-window .wm-head::before { display: none; }
  .wm-window .wm-body {
    max-height: none;
    height: calc(100% - 38px);
  }
  #wm-dock { left: 6px; right: 316px; }
  #budget-panel, #policies-panel, #mayor-panel, #citizens-panel,
  #firms-panel, #notif-panel, #stats-panel, #saves-panel {
    left: auto; right: 0; top: 0; bottom: 0; transform: none;
    width: 320px; max-height: none; border-radius: 0;
  }
  #zoom-ctl { bottom: 8px; left: 6px; }
  #minimap { display: none; }
  #checklist { display: none; }
}


/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 9px;
  font-size: 10px; font-weight: 700; color: #fff; vertical-align: 1px;
  line-height: 1.5;
}
.wm-body .sec svg, .mayor-sec svg { vertical-align: -2px; margin-right: 4px; }
.cdot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 4px; vertical-align: -0.5px; border: 1px solid rgba(0,0,0,0.2);
}

/* Stats window: category tabs. */
#stats-tabs { display: flex; gap: 4px; margin: 2px 0 8px; }
.stats-tab {
  flex: 1; padding: 5px 4px; font-size: 11px;
  background: var(--raised); border: none; box-shadow: 0 1px 2px rgba(10,16,28,0.12); border-radius: 5px;
}
.stats-tab.on { background: var(--accent); color: #fff; border-color: var(--accent-hi); }

/* Legacy panels living inside WM windows: neutralize their fixed styling. */
.wm-embedded {
  position: static !important; inset: auto !important;
  display: block !important; width: auto !important; max-width: none !important;
  max-height: none !important; background: none !important;
  border: none !important; box-shadow: none !important; padding: 0 !important;
  transform: none !important; z-index: auto !important;
}
.wm-embedded > .panel-title { display: none; }

.wm-ctl { font-weight: 700; min-width: 26px; }

/* Resource-window hero image. */
.win-hero {
  display: block; width: 100%; height: auto; border-radius: 7px;
  margin-bottom: 8px; background: var(--bg-deep);
}

.menu-select { display: block; width: 100%; margin: 2px 0 6px; padding: 5px 8px; }

#trend-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.trend-chip {
  font-size: 10px; padding: 2px 7px; border-radius: 9px; opacity: 0.45;
  display: inline-flex; align-items: center; gap: 4px;
}
.trend-chip.on { opacity: 1; }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
#trend-line, #trend-stack, #commute-donut, #trade-bars, #digital-line {
  border-radius: 8px; display: block; margin: 4px 0;
}

#mapsize-row { display: flex; gap: 6px; margin: 8px 0; }
#mapsize-row .mapsize { flex: 1; text-align: center; padding: 6px 4px; }

/* In-game dialog (replaces browser prompt/confirm). */
#ui-dialog {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(10, 14, 24, 0.45);
  display: flex; align-items: center; justify-content: center;
}
.dlg-box {
  background: var(--panel); border-radius: 10px; padding: 16px 18px;
  min-width: 260px; max-width: 84vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.dlg-title { font-weight: 700; color: var(--head); margin-bottom: 8px; }
.dlg-label { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; }
.dlg-input {
  width: 100%; padding: 6px 8px; font-size: 13px; border: none;
  background: var(--bg-deep); color: var(--text-hi); border-radius: 6px;
  margin-bottom: 12px;
}
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-ok { background: var(--accent); color: #fff; padding: 5px 14px; }
.wm-taction {
  background: none; box-shadow: none; padding: 2px 5px; color: var(--dim);
  margin-left: 4px; margin-right: auto;
}
.wm-taction:hover { color: var(--text-hi); background: none; }

/* Chronicle timeline. */
.chron-year {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim-2); margin: 8px 0 3px; border-bottom: 1px solid var(--border-soft);
  padding-bottom: 2px;
}
.chron-entry { font-size: 11.5px; color: var(--text-soft); padding: 2px 0; line-height: 1.4; }
