:root {
  --bg: #1b1d22;
  --panel: rgba(30, 33, 40, 0.92);
  --panel-b: rgba(255, 255, 255, 0.08);
  --text: #e7eaf0;
  --dim: #9aa0ac;
  --accent: #4a8fe8;
  --good: #4ad46a;
  --warn: #f0b000;
  --bad: #e8433a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  user-select: none; -webkit-user-select: none;
}
#app { position: fixed; inset: 0; }
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map.grabbing { cursor: grabbing; }

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--panel-b);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  padding: 10px 14px;
  z-index: 5;
}
.hidden { display: none !important; }
.tiny { font-size: 11px; color: var(--dim); }
.big { font-size: 20px; font-weight: 700; line-height: 1.1; }
.label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }

/* top bar */
#topbar {
  top: 12px; left: 12px;
  display: flex; align-items: center; gap: 12px;
}
.brand { font-size: 16px; font-weight: 800; white-space: nowrap; }
.brand .sub { font-size: 11px; font-weight: 500; color: var(--dim); margin-left: 4px; }
.clock { text-align: center; min-width: 84px; }
.clock .big { font-variant-numeric: tabular-nums; }
.speeds { display: flex; gap: 4px; }
.spd {
  background: rgba(255, 255, 255, 0.06); color: var(--text);
  border: 1px solid var(--panel-b); border-radius: 8px;
  padding: 6px 8px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.spd.active { background: var(--accent); border-color: var(--accent); }
.spd.build { margin-left: 6px; }
.spd.build.active { background: var(--warn); border-color: var(--warn); color: #241a00; font-weight: 700; }
#map.build { cursor: crosshair; }

/* stats */
#stats {
  top: 12px; right: 12px;
  display: flex; gap: 12px; align-items: center;
}
.stat { text-align: center; min-width: 44px; }
.bar {
  width: 74px; height: 9px; border-radius: 5px;
  background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 3px 0;
}
.fill { height: 100%; width: 8%; background: var(--good); transition: width 0.3s, background 0.3s; }

/* actions */
#actions { bottom: 84px; left: 50%; transform: translateX(-50%); min-width: 260px; text-align: center; }
.act-title { font-weight: 700; margin-bottom: 3px; }
.act-btns { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.act-btns button {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 12px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.act-btns button.ghost { background: rgba(255, 255, 255, 0.08); }
.act-btns button:disabled { opacity: 0.4; cursor: not-allowed; }
.act-btns button.on { background: var(--good); color: #06210f; }
#grp-road button, #grp-signal button { background: rgba(255, 255, 255, 0.1); }
#grp-road button.on { background: var(--warn); color: #241a00; }

/* regulations & budget panel */
#rules {
  top: 92px; left: 12px; width: 320px;
}
#rules .act-title { text-align: left; margin-bottom: 8px; }
#rules-ledger { margin-bottom: 10px; line-height: 1.5; color: var(--dim); }
#rules-ledger b { color: var(--text); }
.reg-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-top: 1px solid var(--panel-b);
}
.reg-row .rl { flex: 1; font-size: 12px; }
.reg-row .lvl { font-size: 11px; font-weight: 700; width: 58px; text-align: center; }
.reg-row button {
  background: rgba(255,255,255,0.1); color: var(--text); border: none;
  border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 14px;
}
.reg-row .amt { width: 62px; text-align: right; font-size: 11px; color: var(--good); }
#rules-hint { margin: 8px 0 4px; line-height: 1.45; }
#corruption-row { margin: 10px 0 4px; }
#corruption-row .cbar { display: inline-block; width: 120px; height: 8px; border-radius: 4px;
  background: rgba(255,255,255,0.1); overflow: hidden; vertical-align: middle; margin-left: 6px; }
#corruption-row .cfill { height: 100%; background: var(--warn); }
#hirecop { background: var(--accent); }
#vigilance { background: #9a6ad4; }

/* active-event banner */
#eventbar {
  top: 80px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 16px; padding: 8px 16px; font-size: 13px; font-weight: 600;
  border-color: rgba(240, 134, 58, 0.5);
}

/* mini-map */
#minimap-wrap { top: 110px; right: 12px; padding: 6px; line-height: 0; }
#minimap { display: block; cursor: pointer; border-radius: 6px; width: 150px; height: 150px; }
@media (max-width: 1180px) { #minimap, #minimap-wrap canvas { width: 120px; height: 120px; } }

/* scenario objective banner */
#objective {
  top: 120px; left: 50%; transform: translateX(-50%);
  padding: 8px 16px; font-size: 13px; text-align: center;
  border-color: rgba(74, 143, 232, 0.5); max-width: 380px;
}
#objective .olabel { font-weight: 700; }
#objective .oprog { color: var(--accent); font-size: 12px; }

/* map picker */
#maps { display: flex; gap: 10px; margin: 14px 0 6px; flex-wrap: wrap; }
.map-btn {
  flex: 1; min-width: 200px; text-align: left; cursor: pointer;
  background: rgba(255, 255, 255, 0.05); color: var(--text);
  border: 1px solid var(--panel-b); border-radius: 10px; padding: 10px 12px;
}
.map-btn b { font-size: 14px; }
.map-btn span { display: block; font-size: 11px; color: var(--dim); line-height: 1.4; margin-top: 3px; }
.map-btn.active { border-color: var(--accent); background: rgba(74, 143, 232, 0.15); }

/* scenario picker */
.intro-wide { max-width: 640px; }
#scenarios { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.scen-card {
  text-align: left; background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-b); border-radius: 12px; padding: 12px 14px;
  cursor: pointer; transition: transform 0.1s, border-color 0.1s, background 0.1s;
}
.scen-card:hover { transform: translateY(-2px); border-color: var(--accent); background: rgba(74, 143, 232, 0.12); }
.scen-card .st { font-size: 15px; font-weight: 700; }
.scen-card .st .em { margin-right: 6px; }
.scen-card .sb { font-size: 12px; color: var(--dim); line-height: 1.4; margin-top: 4px; }
.scen-card .sgoal { font-size: 11px; color: var(--warn); margin-top: 6px; }
.scen-card .sbest { font-size: 11px; color: var(--good); margin-top: 5px; font-weight: 600; }
.newbest { color: var(--good); font-weight: 800; font-size: 15px; margin-bottom: 8px; }
#howto { margin-top: 8px; font-size: 13px; color: #cbd0da; }
#howto summary { cursor: pointer; color: var(--accent); font-weight: 600; }
#howto ul { list-style: none; margin: 8px 0 0; line-height: 1.9; }
@media (max-width: 640px) { #scenarios { grid-template-columns: 1fr; } }
#eventbar .evt { display: flex; align-items: center; gap: 6px; }
#eventbar .evt .g { font-size: 16px; }

/* unlock */
#unlock {
  bottom: 84px; right: 12px;
  background: var(--good); color: #06210f; border: none;
  font-weight: 800; cursor: pointer; font-size: 14px;
  animation: pulse 1.4s infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* ticker */
#ticker {
  bottom: 12px; left: 12px; width: 340px; max-height: 96px;
  overflow: hidden; font-size: 12px; line-height: 1.5;
}
#ticker .ev { opacity: 0.9; }
#ticker .ev .tm { color: var(--dim); font-variant-numeric: tabular-nums; margin-right: 6px; }
.ev.good { color: var(--good); }
.ev.bad { color: var(--bad); }
.ev.warn { color: var(--warn); }

#hint { bottom: 12px; left: 50%; transform: translateX(-50%); text-align: center; }

/* intro + end screen */
#intro, #endscreen {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(10, 12, 16, 0.82); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
#end-stats { line-height: 1.7; margin: 8px 0 18px; font-size: 13px; color: #cbd0da; }
#end-stats b { color: var(--text); }
#restart {
  background: var(--good); color: #06210f; border: none; border-radius: 10px;
  padding: 12px 22px; font-size: 15px; font-weight: 800; cursor: pointer; width: 100%;
}
#endscreen.win .intro-card { border-color: rgba(74, 212, 106, 0.5); }
#endscreen.lose .intro-card { border-color: rgba(232, 67, 58, 0.5); }
.intro-card {
  background: var(--panel); border: 1px solid var(--panel-b);
  border-radius: 16px; padding: 28px 30px; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.intro-card h1 { font-size: 30px; }
.intro-card .area { color: var(--accent); font-weight: 600; margin: 2px 0 14px; }
.intro-card p { color: #cbd0da; line-height: 1.55; margin-bottom: 12px; font-size: 14px; }
.intro-card ul { list-style: none; margin: 4px 0 20px; font-size: 13px; line-height: 1.9; color: #cbd0da; }
#start {
  background: var(--good); color: #06210f; border: none; border-radius: 10px;
  padding: 12px 22px; font-size: 15px; font-weight: 800; cursor: pointer; width: 100%;
}

/* medium screens: tighten both top panels so they don't collide */
@media (max-width: 1180px) {
  #topbar, #stats { gap: 8px; padding: 8px 10px; }
  .brand { display: none; }
  .stat { min-width: 40px; }
  .stat .big { font-size: 17px; }
  .bar { width: 60px; }
  .spd { padding: 5px 6px; }
}

@media (max-width: 720px) {
  #stats { gap: 6px; }
  .stat { min-width: 34px; }
  .stat .big { font-size: 15px; }
  .stat .tiny { display: none; }
  .bar { width: 48px; }
  #ticker { width: 200px; }
  #hint { display: none; }
}
