: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; touch-action: none; }
#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); white-space: nowrap; }
.label .abbr { display: none; }   /* short label swapped in on phones */

/* 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; }
#clock .mer { display: block; font-size: 10px; font-weight: 600; color: var(--dim); line-height: 1; margin-top: 1px; }
.speeds { display: flex; gap: 8px; align-items: center; }
#speed-slider { width: 96px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
#speed-label { min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; color: var(--text); }
.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 (info bar) — tops aligned so every label sits on the same line and every
   value sits on the same line below it (the clock is the intentional exception). */
#stats {
  top: 12px; right: 12px;
  display: flex; gap: 12px; align-items: flex-start;
}
.stat { text-align: center; min-width: 44px; }
#stats .stat .label { line-height: 1.25; margin-bottom: 3px; }
.clock.stat .big { line-height: 1.25; }
.bar {
  width: 74px; height: 9px; border-radius: 5px;
  background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 3px 0 4px;
}
.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; z-index: 12; }
.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 (tap to collapse/expand) */
#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; cursor: pointer;
}
#objective .oicon { margin-right: 5px; }
#objective .olabel { font-weight: 700; }
#objective .oprog { display: block; color: var(--accent); font-size: 12px; }
#objective.collapsed .obody { display: none; }   /* just the 🎯 icon when collapsed */
#eventbar { cursor: pointer; }
#eventbar.collapsed .etext { display: none; }     /* icon + time only when collapsed */

/* 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: 120px;
  overflow: hidden; font-size: 12px; line-height: 1.5;
  padding-bottom: 14px;   /* headroom so the last line isn't cut mid-glyph */
  /* fade the oldest entry out rather than hard-clipping it */
  -webkit-mask-image: linear-gradient(to bottom, #000 82%, transparent);
  mask-image: linear-gradient(to bottom, #000 82%, transparent);
}
#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 — scrollable so nothing clips on short/mobile screens */
#intro, #endscreen {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(10, 12, 16, 0.82); backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 24px 14px;
}
.intro-card { margin: auto; }   /* centres when it fits, scrolls when it doesn't */

/* guided steps */
.step-h { font-size: 15px; font-weight: 700; margin: 4px 0 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.step-n { display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; }
.cta { background: var(--good); color: #06210f; border: none; border-radius: 10px;
  padding: 11px 20px; font-size: 15px; font-weight: 800; cursor: pointer; margin-top: 14px; width: 100%; }
.pick-hint { font-size: 13px; color: var(--accent); margin: 0 0 12px; font-weight: 600; }
.linkbtn { background: none; border: none; color: var(--dim); font-size: 12px; cursor: pointer;
  text-decoration: underline; padding: 0; margin-left: auto; }
.linkbtn:hover { color: var(--text); }
#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 & down: the two top bars can't fit side by side once the clock lives in
   the info bar — stack them, INFO row on top, CONTROLS row below. */
@media (max-width: 1180px) {
  .brand { display: none; }
  #stats {
    top: 12px; left: 12px; right: 12px; gap: 14px; padding: 8px 12px;
    justify-content: flex-start; overflow-x: auto;
  }
  #stats .stat { flex: 0 0 auto; min-width: max-content; }
  #stats .label { white-space: nowrap; }
  .clock.stat { text-align: left; }
  #topbar {
    top: 64px; left: 12px; right: 12px; gap: 10px; padding: 8px 12px;
    justify-content: flex-start; overflow-x: auto;
  }
  #topbar .speeds, #topbar .spd { flex: 0 0 auto; }
  .spd { padding: 5px 7px; }
  #minimap-wrap { top: 116px; }
  #objective { top: 114px; }
  #eventbar { top: 156px; }
}

@media (max-width: 720px) {
  #stats { gap: 10px; }
  .stat .big { font-size: 16px; }
  .stat .tiny { display: none; }
  .bar { width: 52px; }
  #ticker { width: 200px; }
  #hint { display: none; }
}

/* phones: stack full-width — INFO row on top, CONTROLS row below it */
@media (max-width: 600px) {
  /* row 1: info (clock + stats) */
  #stats {
    top: 6px; left: 6px; right: 6px; padding: 6px 6px; gap: 6px;
    justify-content: space-between; overflow-x: auto;
  }
  #stats .stat { min-width: max-content; flex: 0 0 auto; }
  .stat.phone-hide { display: none; }      /* drop "On road" so Trouble & Works fit */
  .clock.stat { min-width: 0; text-align: left; }
  #daylabel { display: none; }
  .clock .big { font-size: 16px; white-space: nowrap; }
  .bar { width: 46px; }
  /* swap to short labels to save space */
  .label .full { display: none; }
  .label .abbr { display: inline; }

  /* row 2: controls — tightened so the 🏠 menu button never clips off the edge */
  #topbar {
    top: 56px; left: 6px; right: 6px; padding: 6px 6px; gap: 5px;
    justify-content: flex-start; overflow-x: auto;
  }
  .speeds { gap: 4px; flex: 0 0 auto; }
  #speed-slider { width: 58px; }
  #speed-label { min-width: 26px; }
  .spd { flex: 0 0 auto; padding: 5px 6px; }

  #minimap-wrap { display: none; }         /* reclaim space on small screens */

  /* target + status collapse to compact chips below the bars, left-aligned */
  #objective {
    top: 104px; left: 6px; right: auto; transform: none; width: max-content;
    max-width: calc(100vw - 12px); padding: 6px 10px; font-size: 12px; text-align: left;
  }
  #objective.collapsed { min-width: 46px; text-align: center; padding: 9px 8px; }
  #objective.collapsed .oicon { margin: 0; font-size: 16px; }
  #objective:not(.collapsed) .oicon { margin-right: 5px; }
  #objective .olabel { display: inline; }
  #objective .oprog { display: block; margin-top: 3px; }
  #eventbar {
    top: 150px; left: 6px; right: auto; transform: none; width: max-content;
    max-width: calc(100vw - 12px); padding: 5px 10px; gap: 8px;
  }
  #eventbar .etime { font-weight: 700; }   /* collapsed = icon + minutes; tap to see full text */

  #ticker { width: 170px; max-height: 78px; }
  #actions { bottom: 92px; }
}
