/* Choo-Choo Island look: vintage railway enamel signs and tickets, chunky
   cartoon buttons with rivets, Lilita One headings over Baloo 2 body text. */
:root {
  --ink: #2d3142;
  --paper: #fff8e8;
  --paper-2: #fdebc8;
  --tomato: #f25c54;
  --mustard: #ffc43d;
  --leaf: #5cb85c;
  --leaf-dark: #3f8f3f;
  --sky: #4ea8de;
  --plum: #8e6bd9;
  --muted: #6b6f80;
  --bg: #8fd3f4;
  --dots: rgba(255, 255, 255, 0.28);
  --radius: 22px;
  --display: 'Lilita One', 'Baloo 2', ui-rounded, system-ui, sans-serif;
  --body: 'Baloo 2', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  font-family: var(--body);
  font-weight: 600;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background-color: var(--bg);
  background-image: radial-gradient(var(--dots) 3px, transparent 3.5px), radial-gradient(var(--dots) 2px, transparent 2.5px);
  background-size: 44px 44px, 44px 44px;
  background-position: 0 0, 22px 22px;
  transition: background-color 0.8s;
}
body[data-phase='night'] { --bg: #2f3a6b; --dots: rgba(255, 249, 219, 0.14); }

button { font: inherit; color: inherit; cursor: pointer; }
.ico-el { width: 1.4em; height: 1.4em; flex: none; vertical-align: middle; overflow: visible; }

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- HUD ---------- */
#hud { display: flex; align-items: center; gap: 14px; padding: 8px 16px; height: 66px; flex: none; }
.logo { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo .ico-el { width: 40px; height: 40px; filter: drop-shadow(0 3px 0 rgba(45, 49, 66, 0.25)); }
.logo-text {
  font-family: var(--display); font-size: 28px; letter-spacing: 0.5px; color: #fff;
  -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
}
.logo-text b { color: var(--mustard); font-weight: inherit; }

/* Ticket: notched ends + perforation */
.hud-day {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--display); font-size: 18px; letter-spacing: 0.4px; white-space: nowrap;
  background: var(--mustard); color: var(--ink);
  padding: 4px 22px 4px 18px; border-radius: 6px;
  -webkit-mask: radial-gradient(circle at 0 50%, #0000 9px, #000 10px) left / 51% 100% no-repeat,
                radial-gradient(circle at 100% 50%, #0000 9px, #000 10px) right / 51% 100% no-repeat;
          mask: radial-gradient(circle at 0 50%, #0000 9px, #000 10px) left / 51% 100% no-repeat,
                radial-gradient(circle at 100% 50%, #0000 9px, #000 10px) right / 51% 100% no-repeat;
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 -5px 0 rgba(0, 0, 0, 0.12);
}
.hud-day .ico-el { width: 26px; height: 26px; }
.hud-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.hud-stars {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--display); font-size: 24px; min-width: 84px; justify-content: center;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  padding: 0 16px 0 6px; height: 44px;
  box-shadow: inset 0 -4px 0 var(--paper-2), 0 4px 0 var(--ink);
}
.hud-stars .ico-el { width: 34px; height: 34px; }
.hud-stars.bump { animation: bump 0.5s; }
.icon-btn {
  width: 50px; height: 50px; padding: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--paper); border: 3px solid var(--ink);
  box-shadow: inset 0 -5px 0 var(--paper-2), 0 4px 0 var(--ink);
  transition: transform 0.1s, box-shadow 0.1s;
}
.icon-btn .ico-el { width: 32px; height: 32px; }
.icon-btn:hover .ico-el { animation: spin 2s linear infinite; }
.icon-btn:active { transform: translateY(3px); box-shadow: inset 0 -5px 0 var(--paper-2), 0 1px 0 var(--ink); }

/* ---------- layout ---------- */
#main { flex: 1; display: flex; gap: 14px; padding: 0 14px 14px; min-height: 0; }
#stage-wrap { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }
#stage {
  width: 100%; height: 100%; max-height: 100%;
  touch-action: none; user-select: none; -webkit-user-select: none;
  border-radius: var(--radius);
}
/* Full-screen map: the stage fills the window, the HUD floats on top. */
body[data-phase='map'] #hud { position: fixed; top: 0; left: 0; right: 0; z-index: 3; pointer-events: none; }
body[data-phase='map'] #hud > * { pointer-events: auto; }
body[data-phase='map'] #main { padding: 0; }
.map-cam { position: fixed !important; inset: 0; overflow: hidden; background: #3a9fd8; }
.map-cam #stage {
  position: absolute; left: 0; top: 0; max-height: none; border-radius: 0;
  transform-origin: 0 0; will-change: transform; backface-visibility: hidden;
}

/* Enamel sign panel */
#panel, .modal-card, .job-hud {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 5px var(--paper), inset 0 0 0 8px var(--paper-2), 0 6px 0 rgba(45, 49, 66, 0.3);
}
#panel { width: 340px; flex: none; padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 900px) {
  #main { flex-direction: column; }
  #stage-wrap { flex: none; aspect-ratio: 16 / 9; width: 100%; }
  #panel { width: 100%; flex: 1; min-height: 0; }
  .logo-text { font-size: 22px; }
  #hud { gap: 8px; }
}
@media (max-width: 560px) { .logo-text { display: none; } }

/* ---------- panel content ---------- */
.panel-title { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-size: 30px; letter-spacing: 0.4px; line-height: 1; }
.panel-title .ico-el { width: 40px; height: 40px; }
.panel-sub { margin: 0; color: var(--muted); font-size: 17px; line-height: 1.3; }
.job-list { display: flex; flex-direction: column; gap: 12px; }

/* Visual job strip: vehicle › place › place */
.strip { display: flex; align-items: center; gap: 6px; }
.strip-veh { width: 88px; height: 48px; margin: 0; }
.strip-arrow { display: grid; place-items: center; }
.strip-arrow .ico-el { width: 22px; height: 22px; }
.stop-tile {
  position: relative; width: 62px; height: 62px; flex: none;
  display: grid; place-items: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: inset 0 -5px 0 #eee3cf;
}
.stop-tile.now { background: #fff3bf; box-shadow: inset 0 -5px 0 #ffe08a, 0 0 0 5px var(--mustard); animation: pulse-tile 1s ease-in-out infinite; }
.stop-tile.done { background: #e3f7d8; opacity: 0.75; }
.stop-done { position: absolute; top: -12px; right: -12px; width: 28px; height: 28px; }
.glyph-el { width: 46px; height: 46px; }
.stop-cargo {
  position: absolute; bottom: -12px; right: -12px;
  background: #fff; border: 3px solid var(--ink); border-radius: 50%;
  width: 34px; height: 34px; display: grid; place-items: center;
}
.stop-cargo .ico-el { width: 26px; height: 26px; }
.job-list .strip { background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 10px 16px 14px; box-shadow: 0 4px 0 #eee3cf; }

/* The single job card floating over the map */
.job-hud {
  position: absolute; top: 78px; left: 14px; z-index: 2;
  padding: 12px 18px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.jh-dots { display: flex; gap: 6px; }
.jh-dot { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; }
.jh-dot.now { background: var(--mustard); }
.jh-dot.done { background: var(--leaf); }
.jh-home { padding: 8px 26px 10px; }
.jh-home .ico-el { width: 40px; height: 40px; }
.jh-home:disabled { filter: grayscale(0.6); opacity: 0.6; }
body[data-phase='map'] #panel { display: none; }
@keyframes pulse-tile { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* Chunky riveted button */
.big-btn {
  --btn: var(--leaf); --btn-dark: var(--leaf-dark);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--display); font-size: 26px; letter-spacing: 0.6px; color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
  background: var(--btn);
  border: 3px solid var(--ink); border-radius: 20px 20px 24px 24px;
  padding: 10px 34px 14px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.35), inset 0 -7px 0 var(--btn-dark), 0 6px 0 var(--ink);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
}
.big-btn::before, .big-btn::after {
  content: ''; position: absolute; top: calc(50% - 6px); width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.75); border: 2px solid rgba(45, 49, 66, 0.6);
}
.big-btn::before { left: 10px; }
.big-btn::after { right: 10px; }
.big-btn .ico-el { width: 34px; height: 34px; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.2)); }
.big-btn:hover { filter: brightness(1.06); }
.big-btn:active { transform: translateY(4px); box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.35), inset 0 -4px 0 var(--btn-dark), 0 2px 0 var(--ink); }
.big-btn.warm { --btn: var(--tomato); --btn-dark: #c8433d; }
.big-btn.night { --btn: var(--plum); --btn-dark: #6a4bb3; }
.link-btn { background: none; border: none; color: var(--muted); font-size: 17px; text-decoration: underline; text-underline-offset: 3px; }

.done-box {
  background: #fff3bf; border: 3px dashed var(--ink); border-radius: 18px;
  padding: 14px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center;
}
.done-box[hidden] { display: none; }
.done-text { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 22px; }
.done-text .ico-el { width: 36px; height: 36px; }

/* Parking sign: green enamel road sign */
.board {
  background: #2f8f4e; color: #fff;
  border: 4px solid var(--ink); border-radius: 18px;
  box-shadow: inset 0 0 0 4px #2f8f4e, inset 0 0 0 7px #fff, 0 6px 0 rgba(45, 49, 66, 0.3);
  padding: 16px 14px 14px; display: flex; flex-direction: column; gap: 8px;
}
.board-head { display: flex; align-items: center; justify-content: center; gap: 8px; font-family: var(--display); font-size: 24px; letter-spacing: 1.5px; }
.board-head .ico-el { width: 32px; height: 32px; }
.board-group { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-size: 17px; letter-spacing: 0.5px; margin-top: 4px; }
.board-group .ico-el { width: 26px; height: 26px; }
.board-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 14px; padding: 4px 10px;
  box-shadow: inset 0 -4px 0 var(--paper-2);
}
.board-row.on { background: #fff3bf; box-shadow: 0 0 0 4px var(--mustard); }
.board-row.parked { opacity: 0.55; }
.board-arrow .ico-el { width: 24px; height: 24px; }
.board-check { margin-left: auto; visibility: hidden; }
.board-check .ico-el { width: 28px; height: 28px; }
.board-row.parked .board-check { visibility: visible; }
.badge-icon { width: 44px; height: 44px; }
.veh-icon { width: 76px; height: 40px; flex: none; }

/* ---------- toast: speech bubble ---------- */
#toast {
  position: absolute; bottom: 18px; left: 50%;
  transform: translate(-50%, 20px);
  display: flex; align-items: center; gap: 8px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px;
  box-shadow: 0 5px 0 rgba(45, 49, 66, 0.3);
  padding: 8px 22px; font-family: var(--display); font-size: 22px; letter-spacing: 0.3px;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap; max-width: 95%;
}
#toast .ico-el { width: 34px; height: 34px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 10; padding: 16px;
  background: rgba(45, 49, 66, 0.5);
  display: flex; align-items: center; justify-content: center;
}
#modal[hidden] { display: none; }
.modal-card {
  padding: 26px; width: min(480px, 100%); max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px; align-items: stretch; text-align: center;
}
.modal-title { margin: 0; display: flex; align-items: center; justify-content: center; gap: 10px; font-family: var(--display); font-weight: 400; font-size: 34px; letter-spacing: 0.5px; }
.modal-title .ico-el { width: 46px; height: 46px; }
.modal-sub { margin: 0; color: var(--muted); font-size: 18px; }
.settings { display: flex; flex-direction: column; gap: 10px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 8px 12px;
  box-shadow: inset 0 -4px 0 #eee3cf;
}
.setting-label { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 19px; letter-spacing: 0.3px; text-align: left; }
.setting-label .ico-el { width: 32px; height: 32px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.step-btn {
  width: 42px; height: 42px; border-radius: 50%; padding: 0; display: grid; place-items: center;
  border: 3px solid var(--ink); background: var(--mustard);
  box-shadow: inset 0 -4px 0 #e0a21f, 0 3px 0 var(--ink);
}
.step-btn .ico-el { width: 22px; height: 22px; }
.step-btn:active { transform: translateY(2px); box-shadow: inset 0 -4px 0 #e0a21f, 0 1px 0 var(--ink); }
.step-btn:disabled { opacity: 0.35; cursor: default; }
.step-val { min-width: 30px; font-family: var(--display); font-size: 26px; }
.seg { display: flex; gap: 4px; }
.seg-btn {
  display: flex; align-items: center; gap: 2px;
  border: 3px solid var(--ink); border-radius: 12px; background: #f4ecdc;
  padding: 3px 10px; font-family: var(--display); font-size: 16px; letter-spacing: 0.3px;
  box-shadow: inset 0 -3px 0 #e0d4bc;
}
.seg-btn .ico-el { width: 22px; height: 22px; }
.seg-btn.on { background: var(--sky); color: #fff; box-shadow: inset 0 -3px 0 #2f7fb0; }
.seg-btn.on .ico-el path { stroke: #fff; }

/* ---------- SVG bits ---------- */
#stage text { pointer-events: none; }
.sign-text { font-family: var(--display); paint-order: stroke; stroke: var(--ink); stroke-width: 4px; }
.fx { pointer-events: none; }
.clickable { cursor: pointer; }
.draggable { cursor: grab; }
.place.clickable:hover .place-label rect { fill: #fff9db; }
.mveh { transition: opacity 0.6s; }
.mveh.gone { opacity: 0; pointer-events: none; }
.veh.selected > g { filter: drop-shadow(0 0 6px #ffd43b) drop-shadow(0 0 3px #ffd43b); }

.pulse { animation: pulse 1s ease-in-out infinite; }
.shake { animation: shake 0.45s; transform-box: fill-box; transform-origin: center; }
.bob { animation: bob 1.2s ease-in-out infinite; transform-box: fill-box; }
.zzz { animation: zzz 2.6s ease-in-out infinite; transform-box: fill-box; font-family: var(--display); }
.twinkle { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px) rotate(-3deg); }
  40% { transform: translateX(12px) rotate(3deg); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes zzz {
  0% { opacity: 0; transform: translate(0, 6px); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: translate(12px, -18px); }
}
@keyframes bump { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.3); } }

/* ---------- hi-fi art animation ---------- */
.spin { transform-box: fill-box; transform-origin: center; }
.moving .spin { animation: spin 0.5s linear infinite; }
.moving .beacon { animation: blink 0.5s steps(2, jump-none) infinite; }
.lamp .halo { opacity: 0; transition: opacity 0.6s; }
.night .lamp .halo, .dusk .lamp .halo { opacity: 0.9; }
.sway { transform-box: fill-box; transform-origin: 50% 100%; animation: sway 4s ease-in-out infinite; }
.sway:nth-child(3n) { animation-duration: 5.2s; animation-delay: -1s; }
.flag { animation: flag 1.4s ease-in-out infinite; }
.blades { animation: spin 6s linear infinite; }
.crane { animation: crane 9s ease-in-out infinite; }
.bat { transform-box: fill-box; transform-origin: center; animation: flap 0.35s ease-in-out infinite alternate; }
.flap { transform-box: fill-box; transform-origin: center; animation: flap 0.4s ease-in-out infinite alternate; }
.beam { transform-box: view-box; animation: pulse 2.4s ease-in-out infinite; }
.wave { animation: wave 3.2s ease-in-out infinite; }
.glint { animation: pulse 2.6s ease-in-out infinite; }
.foam { animation: foam 6s linear infinite; }
.flow { animation: flow 3s linear infinite; }
.flow.slow { animation-duration: 5s; }
.blink { animation: blink 1s steps(2, jump-none) infinite; }
.blink.alt { animation-delay: -0.5s; }
.mist { animation: mist 12s ease-in-out infinite; }
.flicker { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 0.5s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scale(1, 1); } to { transform: scale(0.9, 1.12); } }
.cloud { opacity: 0.55; pointer-events: none; }
.shed.empty, .car-bay.empty { opacity: 0.6; }
.sunrays { transform-box: view-box; transform-origin: 1600px 0; animation: rays 14s ease-in-out infinite; }
.firefly { animation: firefly 6s ease-in-out infinite; }
.cloud-shadow { opacity: 0.1; pointer-events: none; }
.layer-sky, .layer-cloudShadows, .layer-fx, .layer-boats, .layer-decor, .layer-ranges, .layer-portals { pointer-events: none; }
.puff { pointer-events: none; }

@keyframes rays { 0%, 100% { transform: rotate(0deg); opacity: 0.8; } 50% { transform: rotate(4deg); opacity: 1; } }
@keyframes firefly { 0%, 100% { opacity: 0; transform: translate(0, 0); } 30% { opacity: 1; } 50% { transform: translate(24px, -18px); } 70% { opacity: 0.8; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0% { opacity: 1; } 100% { opacity: 0.25; } }
@keyframes sway { 0%, 100% { transform: rotate(-1.6deg); } 50% { transform: rotate(1.6deg); } }
@keyframes flag { 0%, 100% { transform: skewY(0deg) scaleX(1); } 50% { transform: skewY(-6deg) scaleX(0.9); } }
@keyframes crane { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(-4deg); } }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(0.35); } }
@keyframes wave { 0%, 100% { transform: translateX(0); opacity: 0.25; } 50% { transform: translateX(14px); opacity: 0.8; } }
@keyframes foam { to { stroke-dashoffset: -112; } }
@keyframes flow { to { stroke-dashoffset: -164; } }
@keyframes mist { 0%, 100% { transform: translateX(-30px); opacity: 0.25; } 50% { transform: translateX(30px); opacity: 0.5; } }

/* ---------- map overlays ---------- */
.evening {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: linear-gradient(180deg, rgba(255, 146, 43, 0.04), rgba(255, 110, 70, 0.16));
  transition: opacity 2s;
}
.edge-arrow {
  position: absolute; z-index: 2; margin: -38px 0 0 -38px;
  width: 76px; height: 76px; border-radius: 50%;
  background: #fff9db; border: 4px solid var(--ink); box-shadow: 0 0 0 6px rgba(252, 196, 25, 0.6);
  display: grid; place-items: center; padding: 0; animation: bob 1.2s ease-in-out infinite;
}
.edge-arrow[hidden] { display: none; }
.ea-icon { display: grid; place-items: center; }
.ea-icon svg { width: 46px; height: 46px; }
.ea-point { position: absolute; inset: -30px; display: flex; align-items: center; justify-content: flex-end; color: var(--ink); pointer-events: none; }
.ea-point svg { width: 26px; height: 26px; }
body[data-phase='map'] #stage { cursor: grab; }
body[data-phase='map'] #stage:active { cursor: grabbing; }

@media (prefers-reduced-motion: reduce) {
  .pulse, .bob, .zzz, .twinkle, .sway, .flag, .blades, .crane, .bat, .flap, .wave, .glint, .foam, .flow, .mist, .flicker, .beam, .edge-arrow, .sunrays, .firefly, .spin { animation: none !important; }
}
