/* Design tokens: one set of colors, sizes and spacing for every screen. */
:root {
  --bg: #161b20;
  --text: #e8edf1;
  --muted: #9aa7b2;
  --accent: #5fb3ff;
  --accent-ink: #08243b;
  --danger: #ff7a6b;
  --ok: #6cc76c;

  /* Zones, used wherever a zone shows up. */
  --zone-r: #5fb85f;
  --zone-c: #5b93e6;
  --zone-i: #d9b33f;
  --zone-m: #b48ade;

  /* Floating panels over the map. */
  --glass: rgba(22, 28, 34, 0.8);
  --glass-solid: #1e262d;
  --glass-hover: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.13);
  --field: rgba(0, 0, 0, 0.3);
  --blur: blur(12px) saturate(1.2);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 14px;

  /* Spacing scale. */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;

  /* Type scale. */
  --fs-s: 0.75rem;
  --fs-m: 0.875rem;
  --fs-l: 1rem;
  --fs-xl: 1.25rem;

  --tap: 44px;
  --status-h: 56px;
  --edge: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); font-size: var(--fs-m); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select { font: inherit; }

/* The shared panel look: dark, a little see-through, rounded, soft shadow. */
.panel {
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
}

button {
  min-height: 36px;
  padding: var(--s1) var(--s3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: var(--glass-hover); border-color: rgba(255, 255, 255, 0.28); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #7cc2ff; }
input, select {
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  padding: 6px var(--s2);
  min-height: 36px;
}
input::placeholder { color: var(--muted); }
input[type="checkbox"] { min-height: 0; accent-color: var(--accent); }
select option { background: var(--glass-solid); }
.icon { width: 1.5em; height: 1.5em; display: block; flex: none; }

.screen { position: fixed; inset: 0; }

/* Sign in */
#screen-login {
  display: flex; padding: 16px; overflow-y: auto;
  background: linear-gradient(rgba(12, 16, 20, 0.55), rgba(12, 16, 20, 0.7)), url("login-bg.webp") center / cover no-repeat #24303a;
}
.card { background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); border: 1px solid var(--glass-border); box-shadow: var(--shadow); padding: var(--s5); border-radius: var(--radius-l); max-width: 420px; width: 100%; }
#screen-login .card { margin: auto; }
.card form { display: flex; flex-direction: column; gap: 12px; }
.card label { display: flex; flex-direction: column; gap: 4px; }
.card h2 { font-size: var(--fs-xl); margin-bottom: var(--s2); }
.card p { margin: var(--s2) 0; }
.card input, .card button, .btn-link { min-height: var(--tap); font-size: 16px; }
.auth-view { display: flex; flex-direction: column; gap: var(--s3); }
.auth-view > p, .auth-view > h2 { margin: 0; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.auth-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: 0; color: var(--accent); text-decoration: underline; min-height: var(--tap); }
button.link:hover { background: none; }
button.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(255, 122, 107, 0.15); border-color: var(--danger); }
.btn-link {
  display: flex; align-items: center; justify-content: center; padding: var(--s1) var(--s3);
  border: 1px solid var(--glass-border); border-radius: var(--radius-s); background: rgba(255, 255, 255, 0.06);
  color: var(--text); text-decoration: none;
}
.btn-link:hover { background: var(--glass-hover); border-color: rgba(255, 255, 255, 0.28); }
.btn-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-or { display: flex; align-items: center; gap: var(--s3); color: var(--muted); margin: var(--s1) 0 var(--s3); }
.auth-or::before, .auth-or::after { content: ""; flex: 1; border-top: 1px solid var(--glass-border); }
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; padding: 16px; overflow-y: auto;
  background: rgba(8, 11, 14, 0.7);
}
.overlay .card { margin: auto; background: var(--glass-solid); }
.account-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.account-head h2 { margin: 0; }
.account-info { display: grid; grid-template-columns: max-content 1fr; gap: var(--s1) var(--s3); margin: 0 0 var(--s4); }
.account-info dt { color: var(--muted); }
.account-info dd { margin: 0; overflow-wrap: anywhere; }
.account-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.account-actions button { flex: 1 1 auto; }
.topbar-right { display: flex; align-items: center; gap: var(--s3); }
@media (max-height: 520px) {
  #screen-login { padding: 8px; }
  .card { padding: var(--s3) var(--s4); }
  #auth-view-start > p { display: none; }
  .auth-view, .card form { gap: var(--s2); }
  .card input, .card button, .btn-link, button.link { min-height: 40px; }
}

/* Region */
#screen-region { display: flex; flex-direction: column; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; background: var(--glass-solid); }
.topbar h1 { font-size: 1.2rem; margin: 0; }
.region-layout { display: flex; gap: 16px; padding: 16px; flex-wrap: wrap; }
.region-list { flex: 0 0 240px; }
.region-list ul { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.region-list li button { width: 100%; text-align: left; }
.region-list form { display: flex; gap: 6px; }
.region-list form input { flex: 1; min-width: 0; }
.region-main { flex: 1 1 360px; min-width: 0; }
.region-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  max-width: 560px;
  aspect-ratio: 1;
}
.plot {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end;
  min-height: 120px; overflow: hidden; border-radius: var(--radius-l); font-size: var(--fs-m);
  border: 2px solid var(--glass-border); background: #4f7a3e; box-shadow: var(--shadow);
}
.plot-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.plot-body {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: var(--s2) var(--s3);
  background: linear-gradient(transparent, rgba(12, 16, 20, 0.85) 45%);
  padding-top: var(--s5);
}
.plot-body span { color: #d8dee3; font-size: var(--fs-s); }
.plot-body > div { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s1); }
.plot-body button { min-height: 36px; }
.plot-badge {
  position: absolute; top: var(--s2); left: var(--s2); padding: 2px var(--s2); border-radius: 999px;
  font-size: var(--fs-s); font-weight: 600; background: rgba(12, 16, 20, 0.75); color: #fff; border: 1px solid var(--glass-border);
}
.plot.mine { border-color: var(--accent); }
.plot.mine .plot-badge { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.plot.other { border-color: #9a86c8; }
.plot.other .plot-badge { background: #6a5a8c; }
.plot.stub { border-style: dashed; border-color: #c9b87a; }
.plot.free { border-style: dashed; border-color: var(--ok); }
.plot.free .plot-badge { background: rgba(60, 120, 60, 0.9); }
.plot strong { font-size: var(--fs-l); }
.region-deals { margin-top: 16px; max-width: 760px; }
.region-deals ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.region-deals li { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; background: var(--glass-solid); padding: 6px 8px; border-radius: 6px; }
.region-deals li span { flex: 1 1 260px; }
.deal-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.deal-form input { width: 100px; }
.region-settings { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.region-settings h3 { width: 100%; margin: 0; }
code { background: var(--field); padding: 2px 6px; border-radius: 4px; word-break: break-all; }

/* City */
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.tools {
  position: absolute; left: var(--edge); top: var(--edge);
  max-height: calc(100% - var(--status-h) - 3 * var(--edge));
  display: flex; flex-direction: column; gap: var(--s1);
  padding: var(--s1); overflow-y: auto; scrollbar-width: none;
}
.tool-btn, .menu-item {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 48px; padding: 0 var(--s2);
  border-color: transparent; background: transparent;
}
.tool-btn { width: 48px; justify-content: center; position: relative; }
.tool-btn .icon { width: 26px; height: 26px; }
/* A small corner mark shows that a button opens a flyout. */
.tool-btn[data-group]::after {
  content: ""; position: absolute; right: 4px; bottom: 4px;
  border: 4px solid transparent; border-right-color: currentColor; border-bottom-color: currentColor; opacity: 0.55;
}
.tool-btn.open { background: var(--glass-hover); border-color: var(--glass-border); }
.tool-btn.active, .menu-item.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
[data-zone="r"] { --tint: var(--zone-r); }
[data-zone="c"] { --tint: var(--zone-c); }
[data-zone="i"] { --tint: var(--zone-i); }
[data-zone="m"] { --tint: var(--zone-m); }
.tool-btn[data-zone]:not(.active) .icon, .menu-item[data-zone]:not(.active) .icon { color: var(--tint); }
.tool-btn.active[data-zone], .menu-item.active[data-zone] { background: var(--tint); border-color: var(--tint); color: #0c1a24; }
.flyout {
  position: absolute; z-index: 5; min-width: 200px;
  display: flex; flex-direction: column; gap: 2px; padding: var(--s1);
}
.menu-item { width: 100%; text-align: left; font-size: var(--fs-m); }
.menu-item span { flex: 1; }
.menu-item kbd {
  font: inherit; font-size: var(--fs-s); min-width: 1.6em; text-align: center;
  padding: 1px 5px; border: 1px solid var(--glass-border); border-radius: 4px; opacity: 0.7;
}
button.found-btn {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--status-h) + 2 * var(--edge) + 44px);
  display: flex; align-items: center; gap: var(--s2);
  min-height: 52px; padding: 0 var(--s5); font-size: var(--fs-l);
  border-radius: var(--radius-l); box-shadow: var(--shadow);
  background: var(--ok); border-color: var(--ok); color: #0c2a0c;
}
button.found-btn:hover { background: #82d782; }
.tool-options {
  position: absolute; left: 76px; top: var(--edge);
  padding: var(--s1);
  display: flex; gap: var(--s1); flex-wrap: wrap; max-width: calc(100vw - 100px);
}
.tool-options button { min-height: var(--tap); border-color: transparent; background: transparent; }
.tool-options button.active { background: var(--tint, var(--accent)); border-color: var(--tint, var(--accent)); color: #0c1a24; }
.tool-options .option-check {
  display: flex; align-items: center; gap: var(--s2); min-height: var(--tap);
  margin-left: var(--s2); padding: 0 var(--s2) 0 var(--s3); border-left: 1px solid var(--glass-border); cursor: pointer;
}
.tool-options .option-check input { width: 20px; height: 20px; }
.side {
  position: absolute; right: var(--edge); top: var(--edge);
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--s2);
  max-height: calc(100% - var(--status-h) - 3 * var(--edge)); pointer-events: none;
}
.side > * { pointer-events: auto; }
.overlays {
  flex-shrink: 0;
  padding: var(--s1);
  display: flex; gap: var(--s1); flex-wrap: nowrap;
  /* Never reach under the tool bar on the left (about 64px); scroll sideways instead. */
  max-width: calc(100vw - 84px); overflow-x: auto; scrollbar-width: none;
}
.overlays button { flex-shrink: 0; width: var(--tap); min-height: var(--tap); padding: 0; display: flex; align-items: center; justify-content: center; border-color: transparent; background: transparent; }
.overlays button:hover { background: var(--glass-hover); }
.overlays button.active { background: var(--accent); border-color: var(--accent); }
.overlays .icon { width: 24px; height: 24px; }
.legend {
  padding: var(--s2) var(--s3); font-size: var(--fs-s); min-width: 150px; min-height: 0; overflow-y: auto;
}
.legend h4 { margin: 0 0 var(--s1); font-size: var(--fs-m); }
.legend div { display: flex; align-items: center; gap: var(--s2); padding: 2px 0; }
.legend i {
  width: 18px; height: 12px; border-radius: 3px; flex: none;
  background: linear-gradient(var(--c), var(--c)), #5a8a45;
  border: 1px solid var(--glass-border);
}
.legend { max-width: 240px; }
.legend .layer-switch { display: flex; flex-wrap: wrap; gap: var(--s1); margin-bottom: var(--s1); }
.legend .layer-switch button {
  flex: 1 1 auto; padding: 2px var(--s2); font-size: var(--fs-s); border-radius: 6px; cursor: pointer;
  color: inherit; background: var(--glass-hover); border: 1px solid var(--glass-border);
}
.legend .layer-switch button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.legend p.muted { margin: var(--s1) 0 0; white-space: normal; }
.ticker {
  position: absolute; z-index: 6; left: 76px; right: var(--edge); bottom: calc(var(--status-h) + 2 * var(--edge));
  width: fit-content; max-width: calc(100vw - 84px);
  padding: var(--s1) var(--s1) var(--s1) var(--s3); font-size: var(--fs-m); overflow: hidden;
  display: flex; align-items: center; gap: var(--s2);
}
#ticker-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticker .icon-btn { min-width: 32px; min-height: 32px; flex: none; }
.ticker:has(#ticker-text:empty) { display: none; }
.hover-info {
  position: absolute; right: var(--edge); bottom: calc(var(--status-h) + 2 * var(--edge));
  padding: var(--s1) var(--s2); font-size: var(--fs-s); pointer-events: none; white-space: pre;
}
.hover-info:empty { display: none; }
.guide, .inbox {
  width: 300px; max-width: calc(100vw - 100px); overflow-y: auto; min-height: 0;
  padding: var(--s3) var(--s4); font-size: var(--fs-m);
}
.guide h3, .inbox h3 { margin: 0; font-size: var(--fs-l); }
.guide ul { list-style: none; padding: 0; margin: 0; }
.guide li { display: flex; align-items: flex-start; gap: var(--s2); padding: 2px 0; }
.guide li .icon, .guide li .todo { flex: none; width: 16px; height: 16px; margin-top: 2px; }
.guide li .todo { border: 1.5px solid var(--muted); border-radius: 50%; box-sizing: border-box; }
.guide li.done { color: var(--muted); }
.guide li.done .icon { color: var(--ok); }
.guide-titles { flex: 1; min-width: 0; }
.guide-next { display: none; margin: 0; font-size: var(--fs-s); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide:not(.expanded) .guide-next { display: block; }
.guide:not(.expanded) #guide-steps, .guide:not(.expanded) h3 { display: none; }
.guide:not(.expanded) .panel-head { margin-bottom: 0; }
.guide .panel-head { gap: var(--s1); }
.inbox .panel-head { margin-bottom: var(--s1); }
.cost-tip { position: absolute; z-index: 5; padding: var(--s1) var(--s2); font-size: var(--fs-s); white-space: pre; pointer-events: none; }
.cost-tip.bad { color: var(--danger); border-color: var(--danger); }
.info-card { width: 290px; flex-shrink: 1; min-height: 0; overflow-y: auto; max-width: calc(100vw - 100px); padding: var(--s3); font-size: var(--fs-m); border-left: 3px solid var(--tint, var(--glass-border)); }
.info-card .panel-head { margin-bottom: var(--s1); }
.info-card h3 { font-size: var(--fs-l); }
.info-lines { display: grid; grid-template-columns: fit-content(55%) minmax(0, 1fr); gap: 2px var(--s3); margin: 0; }
.info-lines dt { color: var(--muted); }
.info-lines dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.info-card[data-zone="r"] { --tint: var(--zone-r); }
.info-card[data-zone="c"] { --tint: var(--zone-c); }
.info-card[data-zone="i"] { --tint: var(--zone-i); }
.info-card[data-zone="m"] { --tint: var(--zone-m); }
.inbox ul { padding-left: 16px; max-height: 40vh; overflow-y: auto; }
.statusbar {
  /* Backdrop blur can hide these controls when scrollable panels repaint. */
  background: var(--glass-solid); -webkit-backdrop-filter: none; backdrop-filter: none;
  position: absolute; left: 50%; transform: translateX(-50%); bottom: var(--edge);
  width: max-content; max-width: calc(100% - 2 * var(--edge));
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s1) var(--s3);
  padding: var(--s2) var(--s3); font-size: var(--fs-m);
}
.statusbar .grow { flex: 1; }
.row-break { display: none; }
.st-city { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; max-width: 11em; }
.st-city b { font-size: var(--fs-l); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-city .muted { font-size: var(--fs-s); }
.speed { display: inline-flex; gap: 2px; }
.speed button, .icon-btn { min-width: 40px; min-height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-color: transparent; background: transparent; }
.speed button .icon { width: 18px; height: 18px; }
.speed button:hover, .icon-btn:hover { background: var(--glass-hover); }
.speed button.active { background: var(--accent); color: var(--accent-ink); }
.icon-btn { position: relative; }
.icon-btn.open { background: var(--glass-hover); border-color: var(--glass-border); }
.icon-btn.warn::after {
  content: ""; position: absolute; top: 6px; right: 6px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--danger);
}
#btn-inbox b {
  position: absolute; top: 2px; right: 2px; min-width: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 0.68rem; line-height: 16px; text-align: center;
}
#btn-inbox b:is(:empty, [data-n="0"]) { display: none; }
.stat, .stat-btn { display: inline-flex; align-items: center; gap: var(--s1); white-space: nowrap; }
.stat .icon, .stat-btn .icon { width: 18px; height: 18px; color: var(--muted); }
.stat-btn { min-height: 40px; padding: 0 var(--s2); border-color: transparent; background: transparent; font-weight: 600; }
.stat-btn:hover, .stat-btn.open { background: var(--glass-hover); }
.stat-btn small { font-weight: 500; font-size: var(--fs-s); }
.stats { display: inline-flex; gap: var(--s3); }
.stat.short, .stat.short .icon, .bad { color: var(--danger); }
.good { color: var(--ok); }
.stat-btn.bad span { color: var(--danger); }
.rci { display: inline-flex; align-items: flex-end; gap: var(--s1); }
.rci-col { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.rci-col small { font-size: 0.68rem; font-weight: 600; color: var(--tint); line-height: 1; }
.rci-bar { position: relative; width: 12px; height: 34px; background: var(--field); border-radius: 3px; overflow: hidden; }
.rci-bar::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(255, 255, 255, 0.55); }
.rci-bar i { position: absolute; left: 0; right: 0; bottom: 50%; height: 0; background: var(--tint); }

.popup { position: absolute; z-index: 6; min-width: 220px; padding: var(--s3); }
.popup h3 { font-size: var(--fs-l); margin: 0 0 var(--s2); }
.popup .muted { margin: 0 0 var(--s2); font-size: var(--fs-s); }
.tax-row { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.tax-row span:first-child { flex: 1; }
.tax-row input { width: 3.5em; text-align: center; }
.tax-row .icon-btn { border: 1px solid var(--glass-border); }
.budget-lines { display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s4); margin: 0; }
.budget-lines dt { color: var(--muted); }
.budget-lines dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.budget-lines .total { border-top: 1px solid var(--glass-border); padding-top: var(--s1); font-weight: 600; }
.budget-lines dt.total { color: var(--text); }
#city-menu { display: flex; flex-direction: column; gap: 2px; }
#city-menu .menu-item { width: 100%; cursor: pointer; }
.file-button { border: 1px solid transparent; border-radius: var(--radius-s); }
.file-button:hover { background: var(--glass-hover); }


/* Radio */
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); }
.panel-head h3 { margin: 0; font-size: var(--fs-l); }
.radio { width: 320px; max-width: calc(100vw - 2 * var(--edge)); }
.radio-top { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.radio-power { min-height: var(--tap); display: inline-flex; align-items: center; gap: var(--s2); }
.radio-status { display: flex; flex-direction: column; min-width: 0; font-size: var(--fs-m); }
.radio-status .muted { font-size: var(--fs-s); overflow-wrap: anywhere; }
.radio[data-status="nosignal"] .radio-status .muted { color: var(--danger); }
.radio-dial {
  position: relative; height: 56px; margin: 0 var(--s2) var(--s2); cursor: pointer; touch-action: none;
  border-bottom: 1px solid var(--glass-border);
}
.radio-dial .tick { position: absolute; bottom: 0; width: 1px; height: 12px; background: var(--muted); }
.radio-dial .tick::after { content: attr(data-label); position: absolute; top: -16px; left: -10px; width: 20px; text-align: center; font-size: 10px; font-style: normal; color: var(--muted); }
.radio-dial .mark { position: absolute; bottom: 0; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--accent); }
.radio-dial .needle { position: absolute; top: 8px; bottom: 0; width: 2px; margin-left: -1px; background: var(--danger); pointer-events: none; }
.radio-tuner { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); }
.radio-step { min-width: var(--tap); min-height: var(--tap); padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.radio-freq { font-size: var(--fs-l); font-weight: 600; }
.radio-volume { display: flex; align-items: center; gap: var(--s2); }
.radio-volume input { flex: 1; min-height: var(--tap); accent-color: var(--accent); }
.dialog {
  position: absolute; z-index: 7; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 420px; max-width: calc(100vw - 2 * var(--edge)); max-height: calc(100% - 4 * var(--edge)); overflow-y: auto;
  padding: var(--s3) var(--s4);
}
.credits-body h4 { margin: var(--s3) 0 var(--s1); font-size: var(--fs-m); }
.credits-body ul { margin: 0; padding-left: 18px; font-size: var(--fs-s); }
.credits-body a { color: var(--accent); }

@media (max-width: 640px) {
  .region-list { flex-basis: 100%; }
  /* One plot per row: the cards are too small to read in a 3 x 3 grid. */
  .region-grid { grid-template-columns: 1fr !important; aspect-ratio: auto; }
  .plot { min-height: 150px; }
  .ticker .icon-btn { min-width: var(--tap); min-height: var(--tap); }
  #ticker-text { white-space: normal; }
  .statusbar { width: calc(100% - 2 * var(--edge)); gap: var(--s1) var(--s2); }
  /* Three rows: name + meters + buttons; speed + money; people + utilities. */
  .st-city { order: 1; flex: 1; max-width: none; }
  .rci { order: 2; }
  #btn-radio { order: 3; }
  #btn-inbox { order: 4; }
  #btn-menu { order: 5; }
  .icon-btn { min-width: var(--tap); min-height: var(--tap); }
  .row-break { display: block; order: 6; flex-basis: 100%; height: 0; }
  .speed { order: 7; }
  .speed button { min-width: var(--tap); min-height: var(--tap); }
  #btn-budget { order: 8; flex: 1; justify-content: flex-end; min-height: var(--tap); padding: 0 var(--s1); display: grid; grid-template-columns: auto auto; column-gap: var(--s1); text-align: right; line-height: 1.2; }
  #btn-budget .icon { grid-row: 1 / 3; align-self: center; }
  .stat .cap { display: none; }
  .row-break.second { order: 9; }
  #stat-popbox { order: 10; }
  .stats { order: 11; flex: 1; justify-content: space-between; gap: var(--s2); font-size: var(--fs-s); }
  .statusbar .grow { display: none; }
  .tool-options { top: calc(var(--edge) + var(--tap) + 3 * var(--s1)); left: auto; right: var(--edge); max-width: calc(100vw - 84px); justify-content: flex-end; }
  #screen-city:has(#tool-options:not(.hidden)) .legend { margin-top: calc(var(--tap) + 3 * var(--s1)); }
  /* A toast sits above the status bar; the cards stop above it so it never hides them. */
  #screen-city:has(#ticker-text:not(:empty)) .side { max-height: calc(100% - var(--status-h) - 3 * var(--edge) - 4.5rem); }
  .guide, .inbox { position: fixed; right: var(--edge); bottom: calc(var(--status-h) + 2 * var(--edge)); }
}

.info-lines .info-section { grid-column: 1 / -1; color: var(--text); font-weight: 600; margin-top: var(--s2); border-top: 1px solid var(--glass-border); padding-top: var(--s1); }
.line-chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.line-chip { padding: 1px var(--s2); border-radius: 10px; background: var(--c); font-size: var(--fs-s); font-weight: 600; border: 1px solid rgba(12,16,20,0.5); }
.info-lines .info-reasons { grid-column: 1 / -1; line-height: 1.4; }

/* Developer readout, clear of the left toolbar on phones. */
#perf-readout {
  position: absolute; right: 8px; top: 110px; z-index: 8;
  max-width: calc(100% - 90px); margin: 0; padding: 6px;
  background: #101820e8; color: #fff; font: 11px/1.4 monospace;
  pointer-events: none; white-space: pre-wrap;
}

.people-title { margin: var(--s3) 0 var(--s2); padding-top: var(--s2); border-top: 1px solid var(--glass-border); font-size: var(--fs-m); }
.age-box { display: grid; gap: 2px; }
.age-bar { display: flex; height: 8px; min-width: 90px; border-radius: 4px; overflow: hidden; }
.age-bar i { flex-basis: 0; min-width: 1px; }
.age-bar i[data-group="0"] { background: #4cc3e6; }
.age-bar i[data-group="1"] { background: #52c28e; }
.age-bar i[data-group="2"] { background: #d7c94c; }
.age-bar i[data-group="3"] { background: #e0903c; }
.age-bar i[data-group="4"] { background: #b455b4; }
.age-bar i[data-group="5"] { background: #8a8f98; }
.info-lines .info-wide { grid-column: 1 / -1; text-align: left; }
.age-numbers { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; text-align: center; }
.age-numbers span { display: grid; line-height: 1.15; }
.age-numbers small { color: var(--muted); font-size: 10px; }
.age-bar.levels i[data-level="0"] { background: #8a8f98; }
.age-bar.levels i[data-level="1"] { background: #e0a03c; }
.age-bar.levels i[data-level="2"] { background: #64c878; }
.age-bar.levels i[data-level="3"] { background: #3c96e6; }
.age-numbers.four { grid-template-columns: repeat(4, 1fr); }

/* Wide but short screens (a phone on its side): two-column tool bar, one-row status bar. */
@media (max-height: 520px) and (min-width: 641px) {
  :root { --status-h: 48px; --toolbar-w: 120px; }
  .tools { display: grid; grid-template-columns: repeat(2, 48px); grid-auto-rows: 44px; align-content: start; }
  .tool-btn { min-height: 44px; padding: 0; }
  .tool-options { left: calc(var(--toolbar-w) + var(--edge)); max-width: calc(100vw - var(--toolbar-w) - 24px); }
  .overlays { max-width: calc(100vw - var(--toolbar-w) - 24px); }
  .overlays button { min-height: 40px; }
  .ticker { left: calc(var(--toolbar-w) + var(--edge)); max-width: calc(100vw - var(--toolbar-w) - 24px); }
  .legend { flex-shrink: 0; font-size: 0.7rem; padding: var(--s1) var(--s2); max-width: 200px; }
  .legend h4 { font-size: var(--fs-s); }
  .legend div { padding: 0; }
  .guide, .inbox { max-width: calc(100vw - var(--toolbar-w) - 24px); }
  .statusbar { flex-wrap: nowrap; gap: var(--s2); padding: 2px var(--s2); font-size: var(--fs-s); max-width: calc(100% - 2 * var(--edge)); }
  .statusbar .grow { display: none; }
  .statusbar { overflow-x: auto; scrollbar-width: none; }
  .statusbar > * { flex-shrink: 0; }
  .st-city { max-width: 6em; }
  .st-city b { font-size: var(--fs-m); }
  .speed button, .icon-btn { min-width: 36px; min-height: 36px; }
  .speed button { min-width: 32px; }
  .stat-btn { min-height: 36px; }
  .stats { gap: var(--s2); }
  .rci-bar { height: 28px; }
  .rci-col small { display: none; }
  #stat-delta { display: none; }
  .stat .icon, .stat-btn .icon { width: 15px; height: 15px; }
}
@media (max-height: 520px) and (min-width: 641px) and (max-width: 820px) {
  .statusbar { gap: var(--s1); }
  #stat-jobs, #stat-commute { display: none; }
}

/* Demand dialog */
.rci { cursor: pointer; border-radius: var(--radius-s); }
.rci:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rci-dialog { width: 460px; top: var(--edge); transform: translateX(-50%); max-height: calc(100% - var(--status-h, 0px) - 3 * var(--edge)); font-size: var(--fs-m); }
.rci-zone { border-left: 3px solid var(--tint); padding-left: var(--s3); margin-bottom: var(--s3); }
.rci-zone-head { display: flex; justify-content: space-between; align-items: baseline; }
.rci-zone-head b { color: var(--tint); }
.rci-number { font-size: var(--fs-l); font-weight: 600; font-variant-numeric: tabular-nums; }
.rci-wide-bar { position: relative; display: block; height: 10px; margin: var(--s1) 0; background: var(--field); border-radius: 3px; overflow: hidden; }
.rci-wide-bar::after { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: rgba(255, 255, 255, 0.55); }
.rci-wide-bar i { position: absolute; top: 0; bottom: 0; width: 0; background: var(--tint); }
.rci-lines { margin: 0; font-size: var(--fs-s); }
.rci-line-row { display: flex; justify-content: space-between; gap: var(--s3); padding: 1px 0; }
.rci-line-row dt, .rci-line-row dd { margin: 0; }
.rci-line-row dd { font-variant-numeric: tabular-nums; }
.rci-line-row.factor { color: var(--muted); }
.rci-line-row.factor.bad, .rci-line-row.cap { color: var(--danger); }
.rci-hint { margin: var(--s1) 0 0; font-size: var(--fs-s); font-style: italic; }
.rci-hint[hidden] { display: none; }
.rci-plot { margin-top: var(--s1); }
.rci-chart { border-top: 1px solid var(--glass-border); padding-top: var(--s2); }
.rci-svg { display: block; width: 100%; height: 90px; background: var(--field); border-radius: 3px; }
.rci-svg[hidden], .rci-empty[hidden] { display: none; }
.rci-zero { stroke: rgba(255, 255, 255, 0.4); stroke-width: 1; vector-effect: non-scaling-stroke; }
.rci-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.rci-line-r { stroke: var(--zone-r); }
.rci-line-c { stroke: var(--zone-c); }
.rci-line-c { stroke-dasharray: 6 3; }
.rci-line-i { stroke: var(--zone-i); stroke-dasharray: 2 3; }
.rci-plot { position: relative; }
.rci-axis { position: absolute; right: 4px; font-size: 0.65rem; color: var(--muted); pointer-events: none; }
.rci-axis.top { top: 2px; }
.rci-axis.bottom { bottom: 2px; }
.rci-legend { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s1) 0 0; font-size: var(--fs-s); }
.rci-key { font-weight: 600; color: var(--tint); }
@media (max-height: 520px) {
  .rci-dialog { padding: var(--s2) var(--s3); }
  .rci-zone { margin-bottom: var(--s2); }
}
.rci-ask { min-height: 28px; margin-top: var(--s1); padding: 0 var(--s2); font-size: var(--fs-s); }
.rci-ask[hidden] { display: none; }
/* The dialog is tall: hide the found button while it is open. */
#screen-city:has(#rci-dialog:not(.hidden)) #btn-found { display: none; }

/* Fare slider in the budget panel */
#budget, #trade { bottom: calc(var(--status-h) + 2 * var(--edge)); max-height: calc(100% - var(--status-h) - 3 * var(--edge)); overflow-y: auto; }
.fare-row { display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s3); align-items: center; margin-bottom: var(--s3); }
.fare-row output { font-variant-numeric: tabular-nums; }
.fare-row input { grid-column: 1 / -1; width: 100%; min-height: var(--tap); accent-color: var(--accent); }

/* Bus line panel; the guide would sit on the same spot. */
#screen-city:has(#lines:not(.hidden)) .guide { display: none; }
.lines {
  width: 320px; max-width: calc(100vw - 100px); min-height: 0; overflow-y: auto;
  padding: var(--s3) var(--s4); font-size: var(--fs-m);
}
.lines h4 { margin: 0 0 var(--s1); font-size: var(--fs-m); }
.lines .muted { margin: 0; font-size: var(--fs-s); }
.lines-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.line-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.line-row { padding: var(--s2); border-radius: var(--radius-s); background: var(--field); }
.line-head { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.line-swatch { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 1px solid rgba(255, 255, 255, 0.6); }
.line-btn { min-height: 32px; padding: 0 var(--s2); font-size: var(--fs-s); }
.line-status-row { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s1); font-size: var(--fs-s); }
.line-status-row > span { flex: 1; }
.line-stats { display: grid; grid-template-columns: 1fr auto; gap: 0 var(--s3); margin: var(--s1) 0 0; font-size: var(--fs-s); }
.line-stats dt { color: var(--muted); }
.line-stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.line-picked, .line-shape, .line-field, .line-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s2); }
.line-picked span { flex: 1; }
.line-field input[type="text"] { width: 100%; min-height: var(--tap); }
.line-stops { list-style: none; margin: var(--s2) 0 0; padding: 0; max-height: 200px; overflow-y: auto; }
.line-stop { display: flex; align-items: center; gap: var(--s1); padding: 2px 0; }
.line-stop.inserting { outline: 2px solid var(--accent, currentColor); border-radius: var(--radius-s); }
.line-stop-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-stop .line-btn { min-width: 36px; padding: 0 var(--s1); }
.line-name { overflow-wrap: anywhere; }
.line-field { flex-direction: column; align-items: stretch; gap: var(--s1); }
.line-field select, .line-field input[type="range"] { width: 100%; min-height: var(--tap); }
.line-field input[type="range"] { accent-color: var(--accent); }
.line-radio { display: inline-flex; align-items: center; gap: var(--s1); min-height: var(--tap); cursor: pointer; }
.line-colors { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: var(--s1); margin-top: var(--s2); }
.line-color { width: 100%; min-width: 0; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid transparent; aspect-ratio: 1; }
.line-color[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--accent); }
.line-message { margin: var(--s2) 0 0; font-size: var(--fs-s); }
.line-actions button { flex: 1; min-height: var(--tap); }
.lines .primary { min-height: var(--tap); }
@media (max-width: 640px) {
  .lines { position: fixed; right: var(--edge); bottom: calc(var(--status-h) + 2 * var(--edge)); max-height: 44vh; }
}
@media (max-height: 520px) and (min-width: 641px) {
  .lines { max-width: calc(100vw - var(--toolbar-w) - 24px); padding: var(--s2) var(--s3); width: 300px; }
}

/* Trade panel */
.trade { max-width: calc(100vw - 16px); }
.trade-table { border-collapse: collapse; font-size: var(--fs-s); width: 100%; }
.trade-table th, .trade-table td { padding: 2px var(--s1); text-align: right; font-variant-numeric: tabular-nums; }
.trade-table th { font-weight: 500; color: var(--muted); }
.trade-table th:first-child { text-align: left; }
.trade-edge { border-top: 1px solid var(--glass-border); margin-top: var(--s2); padding-top: var(--s2); font-size: var(--fs-s); }
.trade-edge p { margin: 0 0 var(--s1); }
.trade-bar-row { display: grid; grid-template-columns: 2.2em 1fr; gap: 0 var(--s2); align-items: center; margin: 2px 0; }
.trade-bar-row small { grid-column: 2; color: var(--muted); }
.trade-bar { display: block; height: 8px; background: var(--field); border-radius: 3px; overflow: hidden; }
.trade-bar i { display: block; height: 100%; background: var(--accent); }
.trade-help-btn { width: 1.5em; height: 1.5em; padding: 0; border-radius: 50%; border: 1px solid var(--glass-border); background: var(--field); color: var(--muted); font-size: var(--fs-s); cursor: pointer; vertical-align: middle; }
.trade-help, .trade-missing { margin: 0 0 var(--s2); font-size: var(--fs-s); }
.trade-room { margin: var(--s2) 0 0; font-size: var(--fs-s); font-weight: 600; }
.rci-line-row.info { color: var(--muted); padding-left: var(--s3); }
