/* City Works UI theme — a compact dark "control room" over the map canvas. */
:root {
  --bg: #0e1116;
  --panel: rgba(20, 26, 34, 0.92);
  --panel-solid: #141a22;
  --edge: #2a3340;
  --edge-soft: #222a35;
  --ink: #d6deea;
  --ink-dim: #8b97a8;
  --accent: #4caf6a;
  --accent-blue: #3f86d0;
  --accent-amber: #d8b73e;
  --danger: #d9483a;
  --warn: #e6913a;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  font-size: 13px;
}
#view { position: fixed; inset: 0; display: block; cursor: crosshair; touch-action: none; }
#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }

.panel {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 10px;
  box-shadow: var(--shadow); backdrop-filter: blur(8px);
}

/* ---- Top bar ---- */
#topbar {
  position: absolute; top: 8px; left: 8px; right: 8px; height: 40px;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 10px;
  box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.brand { font-weight: 800; letter-spacing: 1px; color: #fff; font-size: 14px; padding-right: 6px; }
/* City Works logo mark (favicon.svg) shown before the wordmark; scales with the
   surrounding font-size, so it fits both the 14px toolbar brand and the 30px menu title. */
.logo-mark { height: 1.1em; width: 1.1em; vertical-align: -0.2em; margin-right: 0.36em; }
.stat {
  background: #0f141b; border: 1px solid var(--edge-soft); border-radius: 7px;
  padding: 4px 9px; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600;
}
.stat.funds { color: var(--accent); min-width: 86px; text-align: center; }
.stat.funds.broke { color: var(--danger); }
.stat.warn { color: var(--danger); border-color: var(--danger); }
.spacer { flex: 1; }
.speed { display: flex; gap: 3px; }
.sp {
  width: 32px; height: 28px; border: 1px solid var(--edge); background: #0f141b; color: var(--ink-dim);
  border-radius: 6px; cursor: pointer; font-size: 10px; line-height: 1;
}
.sp.active { background: var(--accent); color: #06210f; border-color: var(--accent); font-weight: 700; }
.sp:hover { color: var(--ink); }

/* ---- Buttons ---- */
.btn {
  background: #1c2531; color: var(--ink); border: 1px solid var(--edge); border-radius: 8px;
  padding: 9px 12px; cursor: pointer; font-size: 13px; font-weight: 600; text-align: left;
}
.btn:hover { border-color: #3d4b5e; background: #232e3d; }
.btn.primary { background: var(--accent); color: #06210f; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: #3a1c1c; border-color: #5a2b2b; color: #f0b3b3; }
.btn.danger:hover { background: #4a2222; }
.btn.big { padding: 12px; text-align: center; font-size: 14px; }
.btn.small { padding: 6px 9px; font-size: 12px; }
.menu-btn { padding: 6px 12px; }

/* ---- Toolbar (left categories) ---- */
#toolbar {
  position: absolute; left: 8px; top: 56px; width: 62px;
  display: flex; flex-direction: column; gap: 5px;
}
.cat {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 9px;
  color: var(--ink-dim); cursor: pointer; padding: 7px 2px; backdrop-filter: blur(8px);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.cat:hover { color: var(--ink); border-color: #3d4b5e; }
.cat.active { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }
.cat-ico { font-size: 17px; line-height: 1; }
.cat-lbl { font-size: 9.5px; font-weight: 600; }

/* ---- Palette ---- */
#palette {
  position: absolute; left: 78px; top: 56px; width: 210px;
  max-height: calc(100vh - 130px); overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.palette-title { font-size: 11px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; padding: 2px 4px 4px; }
.item {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px;
  background: #0f141b; border: 1px solid var(--edge-soft); border-radius: 7px;
  cursor: pointer; color: var(--ink); text-align: left;
}
.item:hover { border-color: #3d4b5e; background: #182230; }
.item.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.item.cant { opacity: 0.5; }
.item.cant .item-cost { color: var(--danger); }
.item.locked { opacity: 0.6; }
.item.locked:hover { border-color: var(--edge-soft); background: #0f141b; cursor: not-allowed; }
.item.locked .item-cost { color: var(--accent-amber); font-size: 10px; font-weight: 700; }
.item-swatch { width: 13px; height: 13px; border-radius: 3px; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.4); }
.item-name { flex: 1; font-weight: 600; font-size: 12.5px; }
.item-cost { color: var(--ink-dim); font-variant-numeric: tabular-nums; font-size: 11.5px; }

/* ---- RCI demand meter ---- */
#rci { position: absolute; left: 8px; bottom: 36px; padding: 8px 10px; width: 96px; }
.rci-title { font-size: 9.5px; letter-spacing: 1px; color: var(--ink-dim); margin-bottom: 6px; }
.rci-bars { display: flex; gap: 10px; justify-content: center; }
.rci-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rci-track { position: relative; width: 14px; height: 50px; background: #0f141b; border: 1px solid var(--edge-soft); border-radius: 4px; }
.rci-track::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--edge); }
.rci-fill { position: absolute; left: 1px; right: 1px; border-radius: 2px; transition: height .25s, top .25s; }
.rci-lbl { font-size: 11px; font-weight: 800; }

/* ---- Overlays ---- */
#overlays {
  position: absolute; bottom: 36px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 6px; flex-wrap: wrap; justify-content: center; max-width: 70vw;
}
.ov {
  background: #0f141b; border: 1px solid var(--edge-soft); color: var(--ink-dim);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.ov:hover { color: var(--ink); }
.ov.active { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }
.budget-toggle { background: #14241a; color: #9fd9b1; border-color: #275437; }

/* ---- Minimap ---- */
#minimap { position: absolute; right: 8px; top: 56px; padding: 5px; line-height: 0; }
#minimap canvas { display: block; width: 176px; height: 176px; border-radius: 5px; cursor: pointer; image-rendering: pixelated; }

/* ---- Budget panel ---- */
#budget { position: absolute; right: 8px; top: 240px; width: 250px; padding: 12px; }
.panel-title, h1, h2 { color: #fff; }
.panel-title { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.b-row { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.b-row.pos span:last-child { color: var(--accent); }
.b-row.neg span:last-child { color: #e08b8b; }
.b-row.total { border-top: 1px solid var(--edge); margin-top: 6px; padding-top: 7px; font-weight: 800; font-size: 13.5px; }
.tax-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; }
.tax-row span:first-child { width: 86px; color: var(--ink-dim); }
.tax-slider { flex: 1; accent-color: var(--accent); }
.tax-val { width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
#budget .btn { width: 100%; text-align: center; margin-top: 12px; }

/* ---- Policies panel ---- */
.policy-toggle { background: #1b2740; color: #bcd6f0; border-color: #314a6e; }
#policies { position: absolute; right: 8px; top: 240px; width: 264px; padding: 12px; max-height: calc(100vh - 260px); overflow-y: auto; }
.policy { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--edge-soft); cursor: pointer; }
.policy-main { flex: 1; }
.policy-name { font-weight: 600; font-size: 12.5px; }
.policy-desc { font-size: 11px; color: var(--ink-dim); line-height: 1.35; }
.policy-cost { font-size: 11px; color: #e08b8b; font-variant-numeric: tabular-nums; white-space: nowrap; }
.policy input { width: 16px; height: 16px; accent-color: var(--accent); flex: 0 0 auto; }
.policy.on .policy-name { color: var(--accent); }
#policies .btn { width: 100%; text-align: center; margin-top: 10px; }

/* ---- Goals panel ---- */
.goal-toggle { background: #2a2440; color: #d8cdf0; border-color: #473a6e; }
#goals { position: absolute; right: 8px; top: 240px; width: 272px; padding: 12px; max-height: calc(100vh - 260px); overflow-y: auto; }
.goal-progress { font-size: 11.5px; color: var(--ink-dim); margin-bottom: 6px; }
.goal { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--edge-soft); }
.goal-check { width: 16px; text-align: center; color: var(--ink-dim); font-weight: 700; }
.goal.done .goal-check, .goal.done .goal-name { color: var(--accent); }
.goal-main { flex: 1; }
.goal-name { font-weight: 600; font-size: 12.5px; }
.goal-desc { font-size: 11px; color: var(--ink-dim); line-height: 1.35; }
.goal-reward { font-size: 11px; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
#goals .btn { width: 100%; text-align: center; margin-top: 10px; }

/* ---- Building inspector ---- */
#inspect { position: absolute; right: 8px; bottom: 80px; width: 212px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.i-status { font-size: 11.5px; font-weight: 700; padding: 4px 8px; border-radius: 6px; margin-bottom: 6px; text-align: center; }
.i-status.good { background: #16351f; color: #8fe0a4; }
.i-status.bad { background: #3a1c1c; color: #f0b3b3; }
.i-status.mid { background: #3a3320; color: #e6cf8a; }
#inspect .btn { text-align: center; }
#inspect .row { margin-top: 4px; }

/* ---- Status bar ---- */
#statusbar {
  position: absolute; bottom: 0; left: 0; right: 0; height: 28px;
  display: flex; align-items: center; padding: 0 12px; font-size: 12px; color: var(--ink-dim);
  background: rgba(10, 13, 18, 0.82); border-top: 1px solid var(--edge-soft);
  font-variant-numeric: tabular-nums;
}

/* ---- Tier chip ---- */
.stat.tier { color: #bfe0ff; background: #15233c; border-color: #2c456e; letter-spacing: .3px; }

/* ---- Alerts feed (bottom-right, stacks upward, out of the play area) ---- */
#alerts { position: absolute; right: 8px; bottom: 40px; display: flex; flex-direction: column-reverse; gap: 5px; align-items: flex-end; z-index: 11; }
.alert { display: flex; align-items: center; gap: 8px; padding: 6px 13px; border-radius: 9px; font-size: 12.5px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow); border: 1px solid; max-width: 320px; backdrop-filter: blur(8px); }
.alert .alert-ico { font-size: 15px; line-height: 1; }
.alert.sev2 { background: rgba(58,28,28,0.92); border-color: #6e2f2f; color: #ffcfc8; }
.alert.sev1 { background: rgba(51,48,28,0.92); border-color: #5e552a; color: #f0e4b0; }
.alert:hover { filter: brightness(1.13); }

/* ---- Toasts (bottom-center, above the overlay bar) ---- */
#toasts { position: absolute; bottom: 130px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toast {
  background: var(--panel-solid); border: 1px solid var(--edge); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 600; font-size: 12.5px;
  opacity: 0; transform: translateY(-8px); transition: opacity .35s, transform .35s; max-width: 60vw;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.bad { border-color: var(--danger); color: #ffc9c2; }

/* ---- Modals ---- */
#modal { position: absolute; inset: 0; background: rgba(6, 9, 13, 0.7); display: flex; align-items: center; justify-content: center; z-index: 50; backdrop-filter: blur(3px); }
.modal-box {
  background: var(--panel-solid); border: 1px solid var(--edge); border-radius: 14px;
  box-shadow: var(--shadow); padding: 22px; width: min(440px, 92vw); max-height: 90vh; overflow-y: auto;
}
.start { display: flex; flex-direction: column; gap: 12px; text-align: center; }
.start h1 { font-size: 30px; letter-spacing: 2px; }
.start .sub { color: var(--ink-dim); font-size: 13px; line-height: 1.5; }
.copyright { color: #5c6773; font-size: 11px; letter-spacing: 0.3px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--edge-soft); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; }
.field-row > span { color: var(--ink-dim); flex: 0 0 90px; }
.field { flex: 1; background: #0f141b; border: 1px solid var(--edge); color: var(--ink); border-radius: 8px; padding: 9px 10px; font-size: 13px; font-family: inherit; }
.check { display: flex; align-items: center; gap: 8px; justify-content: flex-start; color: var(--ink-dim); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.warn-text { color: var(--warn); font-size: 11.5px; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu h1 { font-size: 26px; }
.menu h2 { font-size: 18px; margin-bottom: 4px; }
.menu p { color: var(--ink-dim); line-height: 1.5; font-size: 12.5px; }
.menu .btn { text-align: center; }
.menu-label { color: var(--ink-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin-top: 6px; }
.submenu { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.saves { display: flex; flex-direction: column; gap: 6px; max-height: 34vh; overflow-y: auto; }
.save-row { display: flex; align-items: center; gap: 8px; padding: 7px 9px; background: #0f141b; border: 1px solid var(--edge-soft); border-radius: 8px; }
.save-row.current { border-color: var(--accent); }
.save-main { flex: 1; text-align: left; }
.save-name { font-weight: 600; font-size: 13px; }
.save-meta { font-size: 11px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.save-row .btn.small { padding: 5px 10px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; text-align: center; }
.help { font-size: 11.5px; }
.bankrupt h1 { color: var(--danger); }

@media (max-width: 720px) {
  .stat.warn, #s-water, #s-power { display: none; }
  #palette { width: 170px; }
}
