/* Flowtown — interface. The map is the page; everything else is road signage on top of it. */
:root {
  /* Layout: full-bleed map canvas, sign plates across the top, round service buttons down the right edge, tools on an asphalt dock at the bottom, details in a bottom sheet (side panel on wide screens). */
  --asphalt: #1b2027;
  --asphalt-2: #272e38;
  --asphalt-3: #37404c;
  --paint: #f4f1e6;
  --paint-dim: #a9b1b9;
  --sign-green: #0d6b4c;
  --sign-blue: #1b5aa6;
  --sign-yellow: #ffc21a;
  --sign-red: #d93a2f;
  --go: #35e07c;
  --ink: #15191e;
  --font: 'Overpass', 'Helvetica Neue', Arial, system-ui, sans-serif;
  --mono: 'Overpass Mono', ui-monospace, Menlo, Consolas, monospace;
  --gl: max(16px, env(safe-area-inset-left, 0px));
  --gr: max(16px, env(safe-area-inset-right, 0px));
  --st: 0px;
  --sb: 0px;
  color-scheme: dark;
}
:root.standalone { --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px); }

[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--asphalt); color: var(--paint);
  font-family: var(--font); font-size: 14px; line-height: 1.35;
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  font-variant-numeric: tabular-nums;
}
#app { position: relative; height: 100%; overflow: hidden; background: var(--asphalt); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#cv.build { cursor: crosshair; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--sign-yellow); outline-offset: 2px; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; padding-block: calc(10px + var(--st)) 0; padding-left: var(--gl); padding-right: var(--gr); }
#hud > * { pointer-events: auto; }
#top { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; max-width: 560px; }
.plate {
  --bg: var(--sign-green); --fg: var(--paint);
  border: 0; border-radius: 9px; background: var(--bg); color: var(--fg); text-align: left;
  padding: 7px 10px 6px; min-width: 0; display: grid; gap: 0;
  box-shadow: inset 0 0 0 2px var(--bg), inset 0 0 0 3.5px var(--fg), 0 3px 0 rgba(0, 0, 0, .35), 0 8px 18px rgba(0, 0, 0, .28);
}
.plate .lab { font-size: 10px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate b { font-size: 21px; font-weight: 900; line-height: 1.05; white-space: nowrap; }
.plate i { font-style: normal; font-size: 11px; font-weight: 700; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate.money { --bg: var(--sign-yellow); --fg: var(--ink); }
.plate.flow { --bg: var(--sign-blue); }
.plate .bar { display: block; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, .28); margin-top: 4px; overflow: hidden; }
.plate .bar u { display: block; height: 100%; width: 0; background: var(--paint); border-radius: 3px; transition: width .4s; }
.plate b.bump { animation: bump .25s; }
@keyframes bump { 40% { transform: scale(1.08); } }

#sub { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.chip {
  border: 0; border-radius: 999px; background: rgba(27, 32, 39, .9); color: var(--paint);
  padding: 6px 12px; font-weight: 800; font-size: 13px; display: inline-flex; gap: 7px; align-items: center;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.chip svg { width: 15px; height: 15px; }
#bSpeed { min-width: 58px; justify-content: center; }
#bSpeed.paused { background: var(--sign-red); }
#satur { background: var(--sign-red); }

#side { position: absolute; right: var(--gr); top: calc(96px + var(--st)); display: grid; gap: 9px; }
.rnd {
  position: relative; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--asphalt); color: var(--paint);
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 2px var(--asphalt), inset 0 0 0 3.5px rgba(244, 241, 230, .85), 0 3px 0 rgba(0, 0, 0, .35), 0 6px 14px rgba(0, 0, 0, .3);
}
.rnd svg { width: 22px; height: 22px; }
.rnd.on { background: var(--sign-yellow); color: var(--ink); box-shadow: inset 0 0 0 2px var(--sign-yellow), inset 0 0 0 3.5px var(--ink), 0 3px 0 rgba(0, 0, 0, .35); }
.rnd em {
  position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--sign-red); color: #fff;
  font-style: normal; font-size: 11px; font-weight: 900; display: grid; place-items: center; padding: 0 4px; box-sizing: border-box;
}

#toasts { position: absolute; left: 50%; top: calc(104px + var(--st)); transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; pointer-events: none; width: min(78%, 420px); z-index: 30; }
.toast {
  background: var(--asphalt); color: var(--paint); border-radius: 8px; padding: 8px 14px; font-weight: 700; font-size: 13px; text-align: center;
  box-shadow: inset 0 0 0 2px var(--asphalt), inset 0 0 0 3px rgba(244, 241, 230, .5), 0 6px 16px rgba(0, 0, 0, .4);
  animation: toastIn .25s ease-out;
}
.toast.good { background: var(--sign-green); }
.toast.bad { background: var(--sign-red); }
.toast.gold { background: var(--sign-yellow); color: var(--ink); box-shadow: inset 0 0 0 2px var(--sign-yellow), inset 0 0 0 3px var(--ink), 0 6px 16px rgba(0, 0, 0, .4); }
.toast.out { opacity: 0; transition: opacity .4s; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } }

#bottom { margin-top: auto; margin-left: calc(-1 * var(--gl)); margin-right: calc(-1 * var(--gr)); }
#hint { margin: 0 auto 8px; width: fit-content; max-width: calc(100% - 32px); background: rgba(27, 32, 39, .92); border-radius: 8px; padding: 6px 12px; font-size: 12.5px; font-weight: 700; text-align: center; }
#hint:empty { display: none; }
#hint .z { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 3px 0 8px; vertical-align: -1px; }
#dock {
  background: var(--asphalt); padding-block: 9px calc(9px + var(--sb)); padding-left: var(--gl); padding-right: var(--gr);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background-image: repeating-linear-gradient(90deg, rgba(244, 241, 230, .55) 0 18px, transparent 18px 34px);
  background-size: 100% 3px; background-repeat: no-repeat; background-position: 0 0;
  box-shadow: 0 -6px 18px rgba(0, 0, 0, .3);
}
.tool {
  border: 0; border-radius: 9px; background: var(--asphalt-2); color: var(--paint); padding: 7px 4px 6px; display: grid; justify-items: center; gap: 1px; min-width: 0;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .4);
}
.tool svg { width: 26px; height: 26px; }
.tool span { font-size: 12px; font-weight: 800; }
.tool small { font-size: 10.5px; font-weight: 700; color: var(--paint-dim); }
.tool.on { background: var(--sign-yellow); color: var(--ink); box-shadow: inset 0 0 0 2px var(--sign-yellow), inset 0 0 0 3.5px var(--ink), 0 2px 0 rgba(0, 0, 0, .4); }
.tool.on small { color: rgba(21, 25, 30, .75); }
.tool.locked { opacity: .5; }

/* ---------- sheet ---------- */
#sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 64%; display: flex; flex-direction: column; z-index: 20;
  background: var(--asphalt); border-radius: 16px 16px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
  animation: sheetIn .22s ease-out;
}
@keyframes sheetIn { from { transform: translateY(24px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding-block: 12px 8px; padding-left: var(--gl); padding-right: var(--gr); }
.sheet-head h2 {
  margin: 0; font-size: 15px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; background: var(--sign-green); color: var(--paint);
  padding: 6px 12px 5px; border-radius: 6px; box-shadow: inset 0 0 0 2px var(--sign-green), inset 0 0 0 3px var(--paint); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-head .x { margin-left: auto; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--asphalt-2); font-size: 20px; font-weight: 800; line-height: 1; flex: none; }
#sheetBody { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-block: 4px calc(16px + var(--sb)); padding-left: var(--gl); padding-right: var(--gr); display: grid; gap: 12px; align-content: start; }
#sheetBody p { margin: 0; color: var(--paint-dim); font-weight: 500; }
#sheetBody h3 { margin: 4px 0 0; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--paint-dim); }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.kv > div { background: var(--asphalt-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.kv span { display: block; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--paint-dim); }
.kv b { font-size: 17px; font-weight: 900; white-space: nowrap; }

.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt {
  border: 0; border-radius: 9px; background: var(--asphalt-2); padding: 9px 10px; text-align: left; display: grid; gap: 2px; align-content: start; min-width: 0;
  grid-template-columns: 1fr auto;
}
.opt b { font-size: 14px; font-weight: 900; }
.opt i { font-style: normal; font-weight: 800; font-size: 12px; color: var(--sign-yellow); white-space: nowrap; }
.opt small { grid-column: 1 / -1; font-size: 11.5px; color: var(--paint-dim); font-weight: 500; line-height: 1.3; }
.opt.on { background: var(--sign-green); box-shadow: inset 0 0 0 2px var(--sign-green), inset 0 0 0 3.5px var(--paint); }
.opt.on small { color: rgba(244, 241, 230, .85); }
.opt.on i { color: var(--paint); }
.opt:disabled { opacity: .45; cursor: default; }

.btn {
  border: 0; border-radius: 9px; background: var(--sign-blue); color: var(--paint); padding: 10px 14px; font-weight: 900; font-size: 14px;
  box-shadow: inset 0 0 0 2px var(--sign-blue), inset 0 0 0 3.5px var(--paint), 0 2px 0 rgba(0, 0, 0, .4);
}
.btn.gold { background: var(--sign-yellow); color: var(--ink); box-shadow: inset 0 0 0 2px var(--sign-yellow), inset 0 0 0 3.5px var(--ink), 0 2px 0 rgba(0, 0, 0, .4); }
.btn.red { background: var(--sign-red); box-shadow: inset 0 0 0 2px var(--sign-red), inset 0 0 0 3.5px var(--paint), 0 2px 0 rgba(0, 0, 0, .4); }
.btn.plain { background: var(--asphalt-2); box-shadow: 0 2px 0 rgba(0, 0, 0, .4); }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 140px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--asphalt-2); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 8px 6px; font-weight: 800; font-size: 13px; color: var(--paint-dim); }
.seg button.on { background: var(--paint); color: var(--ink); }

.slider { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.slider label { font-weight: 800; font-size: 13px; }
.slider output { font-family: var(--mono); font-weight: 700; color: var(--go); }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--go); height: 28px; margin: 0; }

.list { display: grid; gap: 8px; }
.item { background: var(--asphalt-2); border-radius: 10px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; min-width: 0; }
.item > div { min-width: 0; }
.item b { font-weight: 900; font-size: 14px; }
.item small { display: block; color: var(--paint-dim); font-size: 12px; font-weight: 500; }
.item .btn { padding: 8px 12px; font-size: 13px; white-space: nowrap; min-width: 82px; }
.pips { display: flex; gap: 2px; margin-top: 5px; flex-wrap: wrap; }
.pips u { width: 9px; height: 5px; border-radius: 2px; background: var(--asphalt-3); }
.pips u.f { background: var(--go); }
.prog { grid-column: 1 / -1; height: 7px; border-radius: 4px; background: var(--asphalt-3); overflow: hidden; }
.prog u { display: block; height: 100%; background: var(--go); border-radius: 4px; width: 0; transition: width .3s; }
.prog.gold u { background: var(--sign-yellow); }
.chart { width: 100%; height: 96px; display: block; background: var(--asphalt-2); border-radius: 10px; }
.note { font-size: 12px; color: var(--paint-dim); }
textarea.code { width: 100%; box-sizing: border-box; min-height: 84px; background: var(--asphalt-2); color: var(--paint); border: 0; border-radius: 8px; padding: 8px; font-family: var(--mono); font-size: 11px; -webkit-user-select: text; user-select: text; resize: vertical; }
.tog { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--asphalt-2); border-radius: 10px; padding: 9px 12px; font-weight: 800; }
.tog button { border: 0; border-radius: 999px; min-width: 62px; padding: 6px 12px; font-weight: 900; background: var(--asphalt-3); color: var(--paint-dim); }
.tog button.on { background: var(--go); color: var(--ink); }
.help { display: grid; gap: 8px; }
.help div { display: grid; grid-template-columns: 26px 1fr; gap: 10px; align-items: start; color: var(--paint); font-weight: 500; }
.help div b { width: 24px; height: 24px; border-radius: 6px; background: var(--sign-yellow); color: var(--ink); display: grid; place-items: center; font-weight: 900; font-size: 13px; }

/* ---------- modal ---------- */
#modal { position: absolute; inset: 0; z-index: 40; background: rgba(10, 14, 20, .62); display: grid; place-items: center; padding-block: 16px; padding-left: var(--gl); padding-right: var(--gr); }
.modal-card {
  width: min(100%, 400px); max-height: 100%; overflow-y: auto; box-sizing: border-box; background: var(--sign-green); border-radius: 14px; padding: 22px 20px 18px; display: grid; gap: 12px;
  box-shadow: inset 0 0 0 3px var(--sign-green), inset 0 0 0 5.5px var(--paint), 0 20px 50px rgba(0, 0, 0, .5);
  animation: sheetIn .25s ease-out;
}
.modal-card h1 { margin: 0; font-size: 30px; font-weight: 900; letter-spacing: .01em; line-height: 1; text-wrap: balance; }
.modal-card .eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; opacity: .85; }
.modal-card p { margin: 0; font-weight: 500; }
.modal-card .big { font-size: 34px; font-weight: 900; color: var(--sign-yellow); line-height: 1; }
.modal-card .help div { color: var(--paint); }
#confetti { position: absolute; inset: 0; pointer-events: none; z-index: 35; overflow: hidden; }
#confetti i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- wide screens: the sheet becomes a side panel ---------- */
@media (min-width: 860px) {
  #sheet { left: auto; right: calc(var(--gr) + 58px); bottom: 104px; top: 96px; width: 390px; max-height: none; border-radius: 14px; }
  #dock { grid-template-columns: repeat(4, 120px); justify-content: center; }
  #top { max-width: 520px; }
}
@media (max-height: 520px) {
  #side { top: calc(8px + var(--st)); grid-auto-flow: column; right: calc(var(--gr)); left: auto; }
  #top { max-width: 420px; }
  #sheet { max-height: 86%; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01s !important; transition-duration: .01s !important; }
}
