* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  background: #bfe3a0;
  color: #1f2a37;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.gold { color: #f2a900; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: none; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }
.screen.factory { background: #dfe7ef; }
#line { background: #c2ccd7; }
.screen.bakery { background: #fdf3df; }
#line .bar { background: #e4ebf2; }

.bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; flex: none; }
.title { font-size: clamp(18px, 3.4vw, 28px); font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  background: #fff; border-radius: 999px;
  padding: 10px 18px; min-height: 46px;
  font-weight: 800; font-size: 18px; white-space: nowrap;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .15);
  display: inline-flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums;
}
button.pill:active, .level:active, .cmd:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .15); }
.pill.off { opacity: .45; text-decoration: line-through; }
.pill.primary { background: #ffd43b; }
.pill.big { font-size: 20px; padding: 14px 26px; }
.pill.streak { background: #ffd43b; }
.pill.low { background: #ffd8d6; }

/* ---------- map ---------- */
#map-svg { flex: 1 1 0; height: 0; min-height: 0; width: 100%; }
.street { font-size: 15px; font-weight: 700; fill: #6b5c38; }
.lm { cursor: pointer; outline: none; }
.lm:active { filter: brightness(.9); }
.lm:focus-visible .label rect { stroke: #1f2a37; stroke-width: 3; }
.label rect { fill: #fff; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .18)); }
.label text { font-size: 19px; font-weight: 800; text-anchor: middle; fill: #1f2a37; }
.lm.ready .label rect { fill: #ffd43b; }
.lm.ready .label { animation: bob 1.2s ease-in-out infinite alternate; }
.smoke { animation: puff 2.4s ease-in-out infinite alternate; }
@keyframes bob { to { translate: 0 -6px; } }
@keyframes puff { to { translate: 6px -8px; opacity: .5; } }

/* ---------- level picker ---------- */
.levels {
  flex: 1; min-height: 0; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px; padding: 18px; align-content: center;
  max-width: 1100px; width: 100%; margin: 0 auto;
}
.level {
  background: #fff; border-radius: 26px; padding: 22px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .15);
  display: flex; flex-direction: column; gap: 8px; text-align: left; min-height: 200px;
}
.level-age { align-self: flex-start; border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 800; color: #fff; }
.level:nth-child(1) .level-age { background: #2f7d3f; }
.level:nth-child(2) .level-age { background: #2a6fbf; }
.level:nth-child(3) .level-age { background: #b8440a; }
.level:nth-child(4) .level-age { background: #6f4fc0; }
.level[data-guide] .level-best { font-size: 18px; }
.level-name { font-size: 30px; font-weight: 800; }
.level-desc { font-size: 17px; line-height: 1.35; color: #4b5563; flex: 1; }
.level-best { font-size: 22px; font-weight: 800; color: #5b6673; }
.level-best .dim { color: #c3ccd6; }

/* ---------- stages ---------- */
.stage { flex: 1 1 0; height: 0; min-height: 0; width: 100%; display: block; }
#ln-stage { touch-action: none; }
.belt { animation: belt 1s linear infinite; }
@keyframes belt { to { stroke-dashoffset: -60; } }

.paintable { transition: fill .35s; }
.hole { fill: rgba(31, 42, 55, .42); stroke: #fff; stroke-width: 2.5; stroke-dasharray: 6 5; }
.hole.hint { stroke: #ffd43b; stroke-width: 5; stroke-dasharray: none; animation: blink .6s ease-in-out infinite alternate; }
@keyframes blink { to { fill: rgba(255, 212, 59, .8); } }
.part.pop { transform-box: fill-box; transform-origin: center; animation: pop .3s cubic-bezier(.3, 1.6, .6, 1); }
@keyframes pop { from { transform: scale(1.6); opacity: .2; } }

.card-label { font-size: 18px; font-weight: 800; letter-spacing: 3px; fill: #fff; text-anchor: middle; }
.can { cursor: pointer; }
.can .ring { opacity: 0; }
.can.on .ring { opacity: 1; }
.can:active { filter: brightness(.9); }
.bin { cursor: grab; }
.bin-box { fill: #eef2f6; stroke: #9aa5b1; stroke-width: 3; }
.bin.lifted .bin-art { opacity: .25; }
.ghost { pointer-events: none; filter: drop-shadow(0 8px 6px rgba(0, 0, 0, .3)); }
.puff { transform-box: fill-box; transform-origin: center; animation: spray .55s ease-out forwards; }
@keyframes spray { from { transform: scale(.2); opacity: .9; } to { transform: scale(1.6); opacity: 0; } }
.float { font-size: 44px; font-weight: 800; text-anchor: middle; fill: #1f2a37; stroke: #fff; stroke-width: 6; paint-order: stroke; animation: floatup 1s ease-out forwards; }
@keyframes floatup { to { translate: 0 -60px; opacity: 0; } }
.shake { animation: shake .3s; }
@keyframes shake { 25% { translate: -8px 0; } 75% { translate: 8px 0; } }

/* ---------- robot coder panel ---------- */
.panel { flex: none; background: #fff; border-radius: 26px 26px 0 0; padding: 12px 14px 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 -4px 0 rgba(0, 0, 0, .08); }
.ticket { display: flex; align-items: center; gap: 10px; min-height: 44px; flex-wrap: wrap; }
.ticket-label { font-weight: 800; font-size: 16px; color: #4b5563; }
.ticket-items { display: flex; gap: 6px; }
.tk { width: 44px; height: 44px; border-radius: 12px; background: #eef2f6; padding: 5px; opacity: .55; }
.tk svg { width: 100%; height: 100%; display: block; }
.tk.now { opacity: 1; background: #ffd43b; transform: scale(1.12); }
.tk.done { opacity: 1; background: #c8ebcf; }
.say { font-weight: 800; font-size: 17px; margin-left: 6px; }
.say.bad { color: #b3261e; }
.tray { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }

#rb-arm, #rb-claw { transition: transform .35s ease-in-out; }
.prog {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: 52px; padding: 6px; border-radius: 16px; background: #eef2f6;
}
.prog:empty::before { content: "Your steps will line up here."; color: #4b5563; font-weight: 700; padding: 0 8px; }
.chip { min-width: 44px; height: 40px; padding: 0 10px; border-radius: 11px; font-weight: 800; font-size: 17px; color: #fff; }
.chip.L, .chip.R, .cmd.move { background: #2a6fbf; color: #fff; }
.chip.G, .cmd.grab { background: #2f7d3f; color: #fff; }
.chip.D, .cmd.drop { background: #b8440a; color: #fff; }
.chip.active { outline: 4px solid #1f2a37; transform: scale(1.12); }
.cmd {
  min-width: 70px; height: 62px; padding: 0 18px;
  border-radius: 18px; font-weight: 800; font-size: 21px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .18);
}
.cmd.plain { background: #eef2f6; }
.cmd.run { background: #ffd43b; }

/* ---------- downtown shop ---------- */
.shop-sign { font-size: 30px; font-weight: 800; letter-spacing: 6px; fill: #fff3dc; text-anchor: middle; }
.tag { font-size: 19px; font-weight: 800; text-anchor: middle; fill: #1f2a37; }
.rc { font-size: 21px; font-weight: 700; fill: #1f2a37; }
.rc.b { font-size: 23px; font-weight: 800; }
.rc.end { text-anchor: end; font-variant-numeric: tabular-nums; }
.rc-title { font-size: 22px; font-weight: 800; letter-spacing: 4px; text-anchor: middle; fill: #4b5563; }
.paid-label { font-size: 15px; font-weight: 800; letter-spacing: 2px; text-anchor: middle; fill: #fff3dc; }
.coin-text { font-size: 20px; font-weight: 800; text-anchor: middle; }
.note-text { font-size: 26px; font-weight: 800; text-anchor: middle; fill: #fff; }
#sh-customer.enter { animation: walkin .45s ease-out; }
#sh-customer.hop { animation: hop .5s ease-in-out 2; }
@keyframes walkin { from { translate: -140px 0; opacity: 0; } }
@keyframes hop { 50% { translate: 0 -12px; } }
.till-money, .tray-coins { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* The tray row and message line have fixed heights so the panel never moves as coins are added. */
#till .ticket { flex-wrap: nowrap; height: 66px; }
.tray-coins { gap: 3px; flex: 1 1 0; min-width: 0; height: 66px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tray-coins::-webkit-scrollbar { display: none; }
.tray-coins .money { flex: none; }
.till-say { margin: 0; height: 24px; line-height: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The till itself may wrap on narrow screens: its contents never change mid-game, so it cannot shift. */
.money { background: none; padding: 5px; border-radius: 16px; line-height: 0; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .2)); }
.money:active { transform: translateY(3px); filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .2)); }
.money.small { padding: 1px; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .2)); }
.money svg { display: block; }
.tray-total { background: #eef2f6; box-shadow: none; font-size: 22px; min-width: 96px; justify-content: center; }
.say.good { color: #1f6f35; }
.cmd.run.ready { animation: nudge .5s ease-in-out infinite alternate; }
@keyframes nudge { to { transform: scale(1.07); } }

/* ---------- Boyne River ---------- */
.screen.riverbank { background: #bfe3a0; }
.stage-wrap { position: relative; flex: 1 1 0; min-height: 0; display: flex; }
.stage-wrap > .stage { height: auto; align-self: stretch; }
#rv-stage { touch-action: none; cursor: ns-resize; }
.animal { cursor: pointer; }
.animal .hit { fill: transparent; }
.animal .ring { fill: rgba(255, 255, 255, .2); stroke: #fff; stroke-width: 2.5; animation: ringpulse .8s ease-in-out infinite alternate; }
.animal.shot .cam { opacity: 0; }
.animal .tick { opacity: 0; }
.animal.shot { cursor: default; }
.animal.shot .ring { fill: none; stroke: #2f7d3f; animation: none; opacity: .8; }
.animal.shot .tick { opacity: 1; }
@keyframes ringpulse { to { opacity: .35; } }
#rv-flash.go { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .45; } to { opacity: 0; } }
.finish-text { font-size: 22px; font-weight: 800; letter-spacing: 4px; text-anchor: middle; fill: #fff; }
.float.small { font-size: 28px; stroke-width: 5; }
.pill.mission { background: #ffd43b; gap: 8px; padding-top: 4px; padding-bottom: 4px; }
#rv-card {
  position: absolute; left: 50%; top: 44px; translate: -50% -12px;
  display: flex; align-items: center; gap: 12px;
  background: #fff; border-radius: 20px; padding: 8px 20px 8px 10px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .18); opacity: 0; pointer-events: none; transition: opacity .15s, translate .15s;
  max-width: 92%;
}
#rv-card.open { opacity: 1; translate: -50% 0; }
#rv-card span { display: flex; flex-direction: column; }
#rv-card b { font-size: 20px; font-weight: 800; }
#rv-card small { font-size: 15px; font-weight: 700; color: #2f6b3a; }
.guide {
  flex: 1; min-height: 0; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px;
  padding: 8px 18px 24px; max-width: 1100px; width: 100%; margin: 0 auto; align-content: start;
}
.gcard { background: #fff; border-radius: 24px; padding: 16px; box-shadow: 0 5px 0 rgba(0, 0, 0, .12); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.gcard svg { background: #dff1e4; border-radius: 20px; padding: 6px; }
.gcard h3 { font-size: 20px; font-weight: 800; }
.gcard p { font-size: 16px; line-height: 1.35; color: #4b5563; flex: 1; }
.gcard .seen { font-size: 14px; font-weight: 800; color: #2f6b3a; }
.gcard.unknown svg { filter: brightness(0); opacity: .22; }
.gcard.unknown h3 { color: #5b6673; }

/* ---------- overlay + toast ---------- */
#overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(31, 42, 55, .55); padding: 20px; z-index: 10; }
#overlay.open { display: flex; }
.card { background: #fff; border-radius: 30px; padding: 28px; text-align: center; max-width: 460px; width: 100%; animation: pop .3s ease-out; }
.card h2 { font-size: 30px; font-weight: 800; }
.card p { font-size: 18px; color: #4b5563; margin-top: 8px; }
.card p:empty { display: none; }
.ov-stars { font-size: 56px; letter-spacing: 6px; color: #d5dce4; line-height: 1.2; }
.ov-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.ov-buttons .pill { background: #eef2f6; }
.ov-buttons .pill.primary { background: #ffd43b; }

#toast {
  position: fixed; left: 50%; top: calc(76px + env(safe-area-inset-top)); translate: -50% 0;
  background: #1f2a37; color: #fff; font-weight: 800; font-size: 18px;
  padding: 12px 22px; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20;
  max-width: 90vw; text-align: center;
}
#toast.open { opacity: 1; }

@media (max-height: 520px) {
  .bar { padding: 6px 12px; }
  .pill { min-height: 40px; padding: 6px 14px; }
  .cmd { height: 50px; font-size: 18px; }
  .panel { padding: 8px 12px 10px; gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .lm.ready .label, .smoke, .belt, .hole.hint { animation: none; }
}
