#game-app, .modal-backdrop {
  --bg-board: #fffaf0;
  --board-border: #000000;
  --slot-empty-bg: rgba(0, 0, 0, 0.045);
  --slot-empty-border: #bec6ce;
  --text-main: #222222;
  --text-muted: #555555;
  --accent-blue: #3a7ede;
  --accent-yellow: #f7e55f;
  --match-green: #589a56;
  --coral: #ec8d6f;
  --purple: #dcb0ed;
  --aqua: #82dee6;
  --logo-red: #ad4242;
  --bay-unit: 44px;
  --bay-h: 64px;
}

#game-app, #game-app *, #game-app *::before, #game-app *::after,
.modal-backdrop, .modal-backdrop *, .modal-backdrop *::before, .modal-backdrop *::after {
  box-sizing: border-box;
}

#game-app {
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-family: "Comic Relief", system-ui, sans-serif;
  color: var(--text-main);
}

/* Standard Centered Game Header */
.game-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 6px;
  gap: 8px 12px;
}

.title-group {
  display: contents;
}

.title-group h1 {
  flex-basis: 100%;
  font-size: 2em;
  margin: 0 0 4px;
  font-weight: 700;
  color: #000;
  text-align: center;
}

.level-badge {
  font-size: 1rem;
  padding: 8px 22px;
  cursor: default;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

button.icon-btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 !important;
  border: 2px solid #000;
  border-radius: 50% !important;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s ease, background-color 0.1s;
}

button.icon-btn svg, .icon-btn svg {
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

.icon-btn:hover {
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

.game-instructions {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 10px;
  max-width: 640px;
  line-height: 1.4;
}

/* Status Bar */
.status-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  max-width: 620px;
  background: #f3f4f6;
  border: 2px solid #bec6ce;
  border-radius: 12px;
  padding: 7px 16px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  gap: 10px;
}

.status-bar strong {
  color: #000;
}

/* Main Stage Stack */
.stage-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Passenger Queue Strip */
.queue-strip {
  width: 100%;
  max-width: 720px;
  min-height: calc(var(--bay-h) + 20px);
  background: var(--bg-board);
  border: 2px solid #000;
  border-radius: 18px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.bus-stop-post {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 8px;
  border-right: 2px dashed #bec6ce;
}

.passenger-queue {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  overflow: hidden;
}

.queue-empty-msg {
  font-size: 0.95rem;
  color: var(--match-green);
  font-weight: 700;
}

.passenger-pip {
  width: clamp(18px, calc(var(--bay-h) * 0.56), 28px);
  height: clamp(24px, calc(var(--bay-h) * 0.72), 36px);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.passenger-pip svg {
  width: 100%;
  height: 100%;
  display: block;
}

.passenger-pip.is-front {
  transform: scale(1.1);
}

.passenger-pip.boarding-hidden {
  opacity: 0;
}

.queue-more-badge {
  flex-shrink: 0;
  background: #ffffff;
  border: 2px solid #bec6ce;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #444;
}

/* Pickup Bays (Fixed-position slots — never jump or shift; matches queue strip width) */
.pickup-bays {
  width: 100%;
  max-width: 720px;
  min-height: calc(var(--bay-h) + 22px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-board);
  border: 2px solid #000;
  border-radius: 18px;
  overflow: visible;
}

.pickup-bays.bays-shake {
  animation: bays-shake 0.26s ease;
}

@keyframes bays-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.bay-slot {
  width: var(--bay-slot-w, 160px);
  height: var(--bay-h);
  flex: 0 0 auto;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: visible;
  background: var(--slot-empty-bg);
  border: 2px dotted var(--slot-empty-border);
}

.bay-slot.occupied {
  background: rgba(0, 0, 0, 0.02);
  border: 2px dotted rgba(190, 198, 206, 0.55);
}

.bay-vehicle-wrap {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.36s cubic-bezier(0.3, 0, 0.2, 1), opacity 0.32s ease;
}

/* Exact 1:1 pixel match with lot vehicles (set dynamically from cellSize & gap) */
.bay-vehicle-wrap.len-1 { width: var(--bay-w-1, 54px); }
.bay-vehicle-wrap.len-2 { width: var(--bay-w-2, 114px); }
.bay-vehicle-wrap.len-3 { width: var(--bay-w-3, 174px); }
.bay-vehicle-wrap.len-4 { width: var(--bay-w-4, 234px); }

.bay-vehicle-wrap.is-placeholder {
  opacity: 0;
}

.bay-vehicle-wrap.departing {
  transform: translateX(90px) scale(0.92);
  opacity: 0;
}

.bay-vehicle-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* Poof sparkles when a full vehicle leaves */
.poof-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.poof-star {
  position: absolute;
  font-size: 1.05rem;
  animation: poof-pop 0.52s ease-out forwards;
}

@keyframes poof-pop {
  0% { transform: translate(0, 0) scale(0.5); opacity: 1; }
  100% { transform: translate(var(--px), var(--py)) scale(1.15); opacity: 0; }
}

/* Calm Jammed Banner */
.jam-banner {
  width: 100%;
  max-width: 620px;
  background: #fff3d6;
  border: 2px solid #000;
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 700;
}

.jam-banner .button {
  padding: 5px 16px;
  font-size: 0.9rem;
}

/* Playfield & Parking Lot */
.playfield-container {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 4px;
}

.board-frame {
  position: relative;
  padding: 14px;
  background: var(--bg-board);
  border: 2px solid var(--board-border);
  border-radius: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
}

.lot-grid {
  display: grid;
  position: relative;
  overflow: visible;
}

/* Vehicles in the Parking Lot (SVG-driven, wheels can peek cleanly) */
.lot-vehicle {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 0;
  transition: transform 0.14s ease, filter 0.14s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: visible;
}

.lot-vehicle svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  pointer-events: none;
}

.lot-vehicle:hover {
  filter: brightness(1.06);
  z-index: 10;
}

.lot-vehicle:active {
  transform: scale(0.97);
}

/* Flying / gliding animation sprites */
.anim-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9000;
  will-change: transform, left, top, width, height, opacity;
}

.anim-ghost svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* Gentle Bonk Rebound Animations (when blocked) */
@keyframes bonk-up {
  0% { transform: translateY(0); }
  40% { transform: translateY(-7px); }
  100% { transform: translateY(0); }
}

@keyframes bonk-down {
  0% { transform: translateY(0); }
  40% { transform: translateY(7px); }
  100% { transform: translateY(0); }
}

@keyframes bonk-left {
  0% { transform: translateX(0); }
  40% { transform: translateX(-7px); }
  100% { transform: translateX(0); }
}

@keyframes bonk-right {
  0% { transform: translateX(0); }
  40% { transform: translateX(7px); }
  100% { transform: translateX(0); }
}

.bonk-up { animation: bonk-up 0.22s cubic-bezier(0.2, 0.8, 0.4, 1.2); }
.bonk-down { animation: bonk-down 0.22s cubic-bezier(0.2, 0.8, 0.4, 1.2); }
.bonk-left { animation: bonk-left 0.22s cubic-bezier(0.2, 0.8, 0.4, 1.2); }
.bonk-right { animation: bonk-right 0.22s cubic-bezier(0.2, 0.8, 0.4, 1.2); }

/* Hint Glow Animation (soft ambient glow, no jumping) */
@keyframes hint-glow {
  0%, 100% {
    filter: drop-shadow(0 0 2px rgba(58, 126, 222, 0.3)) brightness(1);
  }
  50% {
    filter: drop-shadow(0 0 8px rgba(58, 126, 222, 0.85)) brightness(1.12);
  }
}

.hint-pulse {
  animation: hint-glow 0.75s infinite ease-in-out;
  z-index: 20;
}

/* Bottom Toolbar (~10px gap to #footer) */
.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 8px 10px;
  flex-wrap: wrap;
  margin-top: 4px;
  margin-bottom: 10px;
}

/* Buttons Base & Design System Palette */
#game-app .button, .modal-backdrop .button {
  font-family: "Comic Relief", system-ui, sans-serif;
  font-size: 1rem;
  font-weight: bold;
  border: 2px solid #000;
  border-radius: 24px;
  padding: 8px 22px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #000;
  text-decoration: none;
  transition: transform 0.1s ease, background-color 0.1s ease;
}

#game-app .button:hover, .modal-backdrop .button:hover {
  transform: translateY(-1px);
}

#game-app .button:active, .modal-backdrop .button:active {
  transform: translateY(1px);
}

#game-app .button.aqua, .modal-backdrop .button.aqua {
  background-color: #82dee6;
  color: #000000;
}
#game-app .button.aqua:hover, .modal-backdrop .button.aqua:hover {
  background-color: #46ceda;
}

#game-app .button.grey, .modal-backdrop .button.grey {
  background-color: #bec6ce;
  color: #000000;
}
#game-app .button.grey:hover, .modal-backdrop .button.grey:hover {
  background-color: #a7b2bd;
}

#game-app .button.yellow, .modal-backdrop .button.yellow {
  background-color: #f7e55f;
  color: #000000;
}
#game-app .button.yellow:hover, .modal-backdrop .button.yellow:hover {
  background-color: #f4da1e;
}

#game-app .button.green, .modal-backdrop .button.green {
  background-color: #589a56;
  color: #000000;
}
#game-app .button.green:hover, .modal-backdrop .button.green:hover {
  background-color: #4f8b4d;
}

#game-app .button.coral, .modal-backdrop .button.coral {
  background-color: #ec8d6f;
  color: #000000;
}
#game-app .button.coral:hover, .modal-backdrop .button.coral:hover {
  background-color: #e87550;
}

#game-app .button.red, .modal-backdrop .button.red {
  background-color: #ad4242;
  color: #ffffff;
}
#game-app .button.red:hover, .modal-backdrop .button.red:hover {
  background-color: #8f3434;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  padding: 20px;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: #ffffff;
  border: 2px solid #000;
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  position: relative;
  animation: modal-pop 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-pop {
  from { transform: scale(0.88); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.celebration-icon {
  font-size: 2.8rem;
  margin-bottom: 8px;
}

.modal-card h2 {
  font-size: 1.7rem;
  margin: 0 0 8px;
  color: #000;
}

.modal-subtext {
  color: #555;
  margin-bottom: 18px;
  font-size: 1rem;
}

.modal-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 22px;
  padding: 12px 18px;
  background: #f4f8fa;
  border: 2px solid #bec6ce;
  border-radius: 16px;
}

.modal-stats div {
  font-size: 0.9rem;
  color: #555;
  display: flex;
  flex-direction: column;
}

.modal-stats strong {
  font-size: 1.45rem;
  color: #000;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

/* Settings Card */
.settings-card {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  text-align: left;
}

.settings-card h2 {
  text-align: center;
  margin-bottom: 18px;
}

.setting-row {
  margin-bottom: 16px;
}

.setting-row label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
  font-size: 0.95rem;
  color: #333;
}

.setting-row select {
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  font-family: "Comic Relief", system-ui, sans-serif;
  border: 2px solid #000;
  border-radius: 16px;
  background: #ffffff;
  color: #000;
  outline: none;
}

.hidden {
  display: none !important;
}

/* Responsive adjustments */
@media (max-width: 720px) {
  #game-app {
    --bay-unit: 34px;
    --bay-h: 54px;
  }
}

@media (max-width: 540px) {
  .board-frame {
    padding: 8px;
  }
  .queue-strip {
    min-height: calc(var(--bay-h) + 16px);
    padding: 6px 10px;
  }
  .pickup-bays {
    display: grid;
    grid-template-columns: repeat(2, var(--bay-slot-w));
    justify-content: center;
    gap: 6px;
    padding: 8px;
  }
}
