:root {
  --bg: #0b1016;
  --glass: rgba(18, 24, 33, 0.78);
  --glass-strong: rgba(22, 29, 40, 0.94);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #eef2f7;
  --muted: #93a0b2;
  --accent: #5eb1ff;
  --accent-soft: rgba(94, 177, 255, 0.16);
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 1.125rem;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  --safe-l: env(safe-area-inset-left);
  --safe-r: env(safe-area-inset-right);
  --hud-h: 120px;
  --dock-h: 90px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* Text size: all interface sizes are in rem, so the root size scales text and controls together. */
html { font-size: 16px; }
html[data-text="large"] { font-size: 18px; }
html[data-text="xl"] { font-size: 20px; }

html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1; -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

#game { position: fixed; inset: 0; touch-action: none; display: block; }

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; pointer-events: none;
  padding: calc(var(--safe-t) + 0.5rem) calc(var(--safe-r) + 0.625rem) 0 calc(var(--safe-l) + 0.625rem);
  display: flex; flex-direction: column; gap: 0.5rem;
}
#hud > * { pointer-events: auto; }
.hud-top {
  display: flex; align-items: center; gap: 0.875rem; padding: 0.5rem 0.5rem 0.5rem 0.875rem; border-radius: var(--radius);
}
.treasury { display: flex; flex-direction: column; min-width: 0; }
.date { font-size: 0.8438rem; color: var(--muted); font-weight: 500; letter-spacing: .01em; }
.money-line { display: flex; align-items: baseline; gap: 0.5rem; }
.money { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.money.neg { color: var(--bad); }
.delta { font-size: 0.8438rem; font-weight: 600; padding: 0.125rem 0.4375rem; border-radius: 62.4375rem; }
.delta.pos { color: var(--good); background: rgba(74, 222, 128, .12); }
.delta.neg { color: var(--bad); background: rgba(248, 113, 113, .12); }

.people { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; font-size: 0.9375rem; color: var(--muted); }
.kv { display: inline-flex; gap: 0.3125rem; align-items: center; white-space: nowrap; }
.kv b { color: var(--text); font-weight: 600; }
.rci { display: inline-flex; gap: 0.25rem; }
.tab .l .short { display: none; }
.rci-bar {
  position: relative; width: 1rem; height: 1.875rem; border-radius: 0.375rem; overflow: hidden;
  background: rgba(255, 255, 255, .07); display: flex; align-items: flex-end; justify-content: center;
}
.rci-bar .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; border-radius: 0.375rem; transition: height .4s ease; }
.rci-bar .fill.up { background: linear-gradient(#6ee7a0, #22c55e); }
.rci-bar .fill.down { background: linear-gradient(#fca5a5, #ef4444); }
.rci-bar i { position: relative; font-style: normal; font-size: 0.75rem; font-weight: 700; color: rgba(255,255,255,.85); padding-bottom: 0.125rem; }

.controls { display: flex; align-items: center; gap: 0.5rem; }
.seg { display: flex; background: rgba(255, 255, 255, .06); border-radius: 0.75rem; padding: 0.1875rem; }
.seg button {
  appearance: none; border: 0; background: transparent; height: 2rem; min-width: 2.125rem; padding: 0 0.375rem;
  border-radius: 0.5625rem; font-size: 0.75rem; letter-spacing: -2px; color: var(--muted); transition: background .15s, color .15s;
}
.seg button.on { background: var(--accent); color: #06121f; box-shadow: 0 2px 8px rgba(94,177,255,.4); }
.round-btn {
  appearance: none; border: 0; width: 2.375rem; height: 2.375rem; border-radius: 0.75rem; display: grid; place-items: center;
  background: rgba(255, 255, 255, .08); color: var(--text); padding: 0; font-size: 1.0625rem;
}
.round-btn:active, .seg button:active { transform: scale(.94); }

/* stat chips: one horizontally scrolling row */
.chips {
  display: flex; gap: 0.375rem; overflow-x: auto; scrollbar-width: none; padding: 0 0.125rem 0.125rem;
  mask-image: linear-gradient(90deg, #000 92%, transparent); -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  appearance: none; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 0.375rem;
  height: 2.125rem; padding: 0 0.6875rem 0 0.5625rem; border-radius: 62.4375rem; white-space: nowrap;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 0.9375rem; color: var(--text); transition: background .15s, border-color .15s;
}
.chip > span:first-child { font-size: 1rem; }
.chip b { font-weight: 650; }
.chip small { font-size: 0.7812rem; color: var(--muted); }
.chip b.warn { color: var(--warn); }
.chip b.bad { color: var(--bad); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
.chip.on small { color: #cfe6ff; }
.chip:active:not(.static) { transform: scale(.96); }
.chip-sep { flex: 0 0 1px; background: var(--line-strong); margin: 0.4375rem 0.125rem; }
.chip.tax { padding: 0 0.25rem; gap: 0.25rem; }
.tax-v { display: inline-flex; align-items: baseline; gap: 0.25rem; padding: 0 0.125rem; }
.step {
  appearance: none; border: 0; width: 1.625rem; height: 1.625rem; border-radius: 62.4375rem; padding: 0;
  background: rgba(255, 255, 255, .1); font-size: 1.0625rem; line-height: 1.625rem;
}
.step:active { background: rgba(255, 255, 255, .25); }

@media (max-width: 560px) {
  .hud-top { flex-wrap: wrap; row-gap: 0.25rem; column-gap: 0.5rem; padding: 0.5rem 0.5rem 0.5rem 0.75rem; }
  .treasury { flex: 1; }
  .money { font-size: 1.3125rem; }
  .people { order: 3; flex-basis: 100%; padding-right: 0.125rem; }
  .rci-bar { height: 1.375rem; width: 0.9375rem; }
  .seg button { min-width: 1.8125rem; padding: 0 0.25rem; height: 1.875rem; }
  .round-btn { width: 2.125rem; height: 2.125rem; }
  .chip small { display: none; }
  .tab { min-width: 3.25rem; padding: 0.375rem 0.3125rem 0.3125rem; }
  .tool { min-width: 4rem; }
}

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; top: calc(var(--hud-h) + 0.5rem); transform: translate(-50%, -6px);
  background: var(--glass-strong); border: 1px solid var(--line-strong);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  padding: 0.625rem 1rem; border-radius: 0.875rem; font-size: 1rem; line-height: 1.35;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 7;
  width: max-content; max-width: min(88vw, 32.5rem); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- inspector card ---------- */
#info {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--dock-h) + 0.625rem); width: min(92vw, 26.25rem);
  border-radius: var(--radius); padding: 0.875rem 1rem; animation: rise .18s ease-out;
}
.info-title { font-size: 1.0625rem; font-weight: 650; padding-right: 1.875rem; }
.info-sub { font-size: 0.8438rem; color: var(--muted); margin-top: 0.125rem; }
.info-body { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.625rem; }
.info-body:empty { display: none; }
.fact { font-size: 0.8438rem; padding: 0.25rem 0.5625rem; border-radius: 62.4375rem; background: rgba(255,255,255,.07); color: #d7dee8; }
.fact.good { background: rgba(74,222,128,.13); color: #a7f3c3; }
.fact.warn { background: rgba(251,191,36,.13); color: #fde68a; }
.fact.bad { background: rgba(248,113,113,.14); color: #fecaca; }
.info-close {
  position: absolute; top: 0.625rem; right: 0.625rem; appearance: none; border: 0; width: 1.75rem; height: 1.75rem;
  border-radius: 62.4375rem; background: rgba(255,255,255,.08); font-size: 0.8438rem; padding: 0;
}

/* ---------- dock (tool categories + tool tray) ---------- */
#dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 0 calc(var(--safe-r) + 0.625rem) calc(var(--safe-b) + 0.625rem) calc(var(--safe-l) + 0.625rem);
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem; pointer-events: none;
}
#dock > * { pointer-events: auto; }
#tabs {
  display: flex; gap: 0.125rem; padding: 0.3125rem; border-radius: 1.25rem; max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
#tabs::-webkit-scrollbar, #tray::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: transparent; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 0.125rem; min-width: 3.625rem;
  padding: 0.375rem 0.5rem 0.3125rem; border-radius: 0.9375rem; color: var(--muted); transition: background .15s, color .15s;
}
.tab .i { font-size: 1.375rem; line-height: 1.375rem; filter: saturate(.85); }
.tab .l { font-size: 0.7812rem; font-weight: 600; letter-spacing: .01em; }
.tab.on { background: rgba(255,255,255,.1); color: var(--text); }
.tab.on .i { filter: none; }
.tab.danger.on { background: rgba(248,113,113,.18); color: #fecaca; }

#tray {
  display: flex; gap: 0.375rem; padding: 0.375rem; border-radius: 1.25rem; max-width: 100%; overflow-x: auto; scrollbar-width: none;
  animation: rise .16s ease-out;
}
.tool {
  appearance: none; flex: 0 0 auto; border: 1px solid transparent; background: rgba(255,255,255,.05);
  display: flex; flex-direction: column; align-items: center; gap: 0.0625rem; min-width: 4.375rem;
  padding: 0.4375rem 0.5rem 0.375rem; border-radius: 0.875rem; transition: background .15s, border-color .15s;
}
.tool .i { font-size: 1.5rem; line-height: 1.5625rem; }
.tool .l { font-size: 0.7812rem; font-weight: 600; white-space: nowrap; }
.tool .c { font-size: 0.75rem; color: var(--muted); }
.tool.active { background: var(--accent-soft); border-color: var(--accent); }
.tool.active .c { color: #cfe6ff; }
.tool:active, .tab:active { transform: scale(.95); }
.tool .badge-hwy { font-size: 0.7812rem; font-weight: 800; background: #2f6b3a; color: #fff; border-radius: 0.3125rem; padding: 0.0625rem 0.25rem; line-height: 1.125rem; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#info { animation-name: rise-x; }
@keyframes rise-x { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- sheet (dialogs, reports, menu) ---------- */
#sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
#sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(4, 8, 12, .5); animation: fade .2s; }
.sheet-panel {
  position: relative; width: min(100%, 32.5rem); max-height: 82vh; display: flex; flex-direction: column;
  background: var(--glass-strong); border: 1px solid var(--line-strong); border-bottom: 0;
  backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-radius: 1.5rem 1.5rem 0 0; padding: 0.375rem 1.125rem calc(var(--safe-b) + 1rem);
  box-shadow: 0 -20px 60px rgba(0,0,0,.45); animation: slide-up .24s cubic-bezier(.2,.8,.2,1);
  -webkit-user-select: text; user-select: text;
}
@media (min-width: 700px) {
  #sheet { align-items: center; }
  .sheet-panel { border-radius: 1.5rem; border-bottom: 1px solid var(--line-strong); padding-bottom: 1.125rem; animation: pop .2s ease-out; }
  .sheet-grab { display: none; }
}
.sheet-grab { width: 2.375rem; height: 0.3125rem; border-radius: 0.1875rem; background: rgba(255,255,255,.2); margin: 0.25rem auto 0.375rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.375rem 0 0.625rem; }
.sheet-head h2 { margin: 0; font-size: 1.3125rem; font-weight: 700; letter-spacing: -.01em; }
.sheet-close { width: 2rem; height: 2rem; font-size: 0.9375rem; }
.sheet-body { overflow-y: auto; font-size: 1rem; line-height: 1.45; color: #d7dee8; }
.sheet-actions { display: flex; gap: 0.5rem; padding-top: 0.875rem; }
.sheet-actions:empty { display: none; }
.btn {
  appearance: none; flex: 1; border: 0; height: 2.875rem; border-radius: 0.875rem; font-size: 1.0625rem; font-weight: 650;
  background: rgba(255,255,255,.09);
}
.btn.primary { background: var(--accent); color: #06121f; }
.btn.danger { background: #ef4444; color: #fff; }
.btn:active { transform: scale(.98); }

.card { background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 1rem; padding: 0.75rem 0.875rem; margin-bottom: 0.625rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.375rem; }
.card-head h3 { margin: 0; font-size: 1rem; font-weight: 650; display: flex; gap: 0.5rem; align-items: center; }
.pill { font-size: 0.7812rem; font-weight: 700; padding: 0.1875rem 0.5rem; border-radius: 62.4375rem; letter-spacing: .03em; text-transform: uppercase; }
.pill.good { background: rgba(74,222,128,.15); color: var(--good); }
.pill.warn { background: rgba(251,191,36,.15); color: var(--warn); }
.pill.bad { background: rgba(248,113,113,.16); color: var(--bad); }
.row-kv { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.3125rem 0; border-top: 1px solid var(--line); font-size: 0.9688rem; }
.row-kv:first-of-type { border-top: 0; }
.row-kv span:first-child { color: var(--muted); }
.row-kv b { font-weight: 600; text-align: right; }
.row-kv b.good { color: var(--good); }
.row-kv b.bad { color: var(--bad); }
.row-kv.total { font-size: 1.0625rem; padding-top: 0.5rem; }
.row-kv.total span:first-child { color: var(--text); font-weight: 600; }
.meter { height: 0.375rem; border-radius: 0.1875rem; background: rgba(255,255,255,.08); overflow: hidden; margin: 0.375rem 0 0.25rem; }
.meter > i { display: block; height: 100%; border-radius: 0.1875rem; background: var(--good); }
.meter > i.warn { background: var(--warn); }
.meter > i.bad { background: var(--bad); }
.note { font-size: 0.875rem; color: var(--muted); margin: 0.5rem 0.125rem 0.125rem; }

.menu-list { display: flex; flex-direction: column; gap: 0.25rem; }
.menu-item {
  appearance: none; border: 0; background: rgba(255,255,255,.05); text-align: left;
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 0.875rem; border-radius: 0.875rem; font-size: 1.0625rem;
}
.menu-item .mi { font-size: 1.25rem; width: 1.5rem; text-align: center; }
.menu-item small { margin-left: auto; color: var(--muted); font-size: 0.875rem; }
.menu-item.danger { color: #fca5a5; }
.menu-item:active { background: rgba(255,255,255,.12); }
.seg.wide { width: 100%; margin: 0.25rem 0 0.5rem; }
.seg.wide button { flex: 1; font-size: 0.9375rem; letter-spacing: 0; height: 2.25rem; }
textarea.save {
  width: 100%; height: 7.5rem; border-radius: 0.75rem; border: 1px solid var(--line-strong); background: rgba(0,0,0,.25);
  color: var(--text); padding: 0.625rem; font: 0.8438rem ui-monospace, Menlo, monospace; resize: none;
}

@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

/* ---------- map buttons (view toggle, fit) ---------- */
#mapBtns {
  position: fixed; z-index: 5; right: calc(var(--safe-r) + 0.75rem); top: calc(var(--hud-h) + 0.625rem);
  display: flex; flex-direction: column; gap: 0.5rem;
}
.map-btn {
  appearance: none; width: 2.75rem; height: 2.75rem; border-radius: 0.875rem; padding: 0;
  font-size: 0.9375rem; font-weight: 800; letter-spacing: .02em; color: var(--text);
}
.map-btn:active { transform: scale(.94); }

/* ---------- how to play ---------- */
.howto h4 { margin: 0 0 0.25rem; font-size: 1rem; }
.howto p { margin: 0 0 0.25rem; font-size: 0.9688rem; color: #cfd7e2; }
.howto ul { margin: 0.25rem 0 0; padding-left: 1.125rem; font-size: 0.9688rem; color: #cfd7e2; }
.howto li { margin: 0.1875rem 0; }
.toggle-state { margin-left: auto; font-size: 0.875rem; font-weight: 700; padding: 0.1875rem 0.5625rem; border-radius: 62.4375rem; }
.toggle-state.on { background: rgba(74,222,128,.15); color: var(--good); }
.toggle-state.off { background: rgba(255,255,255,.08); color: var(--muted); }
#toast.tip { border-color: rgba(251,191,36,.45); }

/* ---------- city picker ---------- */
.field { display: flex; flex-direction: column; gap: 0.375rem; margin: 0.125rem 0 0.625rem; }
.field > span { font-size: 0.8438rem; font-weight: 600; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; }
.select {
  appearance: none; -webkit-appearance: none; width: 100%; height: 3.125rem; padding: 0 2.75rem 0 0.875rem;
  border-radius: 0.875rem; border: 1px solid var(--line-strong); color: var(--text); font: inherit; font-size: 1.0625rem; font-weight: 600;
  background: rgba(255,255,255,.06) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%2393a0b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 16px center;
}
.select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.select option { background: #1b2330; color: var(--text); }
.city-blurb { font-size: 1rem; line-height: 1.45; color: #d7dee8; margin: 0.25rem 0.125rem 0; }

/* text size control in the menu */
.menu-item.text-size { flex-wrap: wrap; row-gap: 0.5rem; cursor: default; }
.text-seg { margin-left: auto; }
.text-seg button { font-size: 0.8125rem; letter-spacing: 0; min-width: 0; padding: 0 0.625rem; color: var(--text); }

/* ---------- phone layout (fits every text size) ---------- */
.money-line { white-space: nowrap; }
@media (max-width: 560px) {
  .hud-top {
    display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "treasury treasury menu" "people rci speed"; align-items: center; column-gap: 0.5rem; row-gap: 0.375rem;
  }
  .controls { display: contents; }
  .treasury { grid-area: treasury; }
  #menuBtn { grid-area: menu; justify-self: end; }
  .people { grid-area: people; flex-basis: auto; gap: 0.625rem; flex-wrap: wrap; row-gap: 0.25rem; font-size: 0.875rem; overflow: hidden; }
  #speedSeg { grid-area: speed; justify-self: end; }
  .rci { grid-area: rci; margin-left: 0; }
  .tab .l .long { display: none; }
  .tab .l .short { display: inline; }
  /* six categories always fit across the screen */
  #tabs { width: 100%; justify-content: space-between; }
  .tab { flex: 1 1 0; min-width: 0; padding: 0.375rem 0.125rem 0.3125rem; }
  .tab .i { font-size: min(1.375rem, 6.4vw); line-height: 1.2; }
  .tab .l { font-size: min(0.78rem, 3.3vw); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
