* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0c101c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #f8fafc;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #0f1422;
  overflow: hidden;
}

/* --- HUD Header --- */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: linear-gradient(180deg, #182236 0%, #101726 100%);
  border-bottom: 2px solid #23314d;
  height: 60px;
  z-index: 10;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

#level-badge {
  background: #3b82f6;
  color: #ffffff;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.4);
}

#score-badge {
  background: #1e293b;
  border: 1px solid #334155;
  color: #fbbf24;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 4px;
}

.hud-center {
  flex: 1;
  max-width: 320px;
  margin: 0 10px;
}

#queue-container {
  display: flex;
  flex-direction: column;
  background: #090d16;
  border: 1px solid #25334c;
  border-radius: 10px;
  padding: 3px 8px;
}

#queue-label {
  font-size: 9px;
  font-weight: 900;
  color: #94a3b8;
  letter-spacing: 1px;
  margin-bottom: 2px;
}

#queue-track {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  overflow: hidden;
}

.queue-pill {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
  animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.queue-pill.pill-red { background: #ef4444; }
.queue-pill.pill-blue { background: #3b82f6; }
.queue-pill.pill-green { background: #10b981; }
.queue-pill.pill-yellow { background: #f59e0b; }
.queue-pill.pill-purple { background: #8b5cf6; }

@keyframes popIn {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #f8fafc;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.hud-btn:hover {
  background: #334155;
  transform: translateY(-1px);
}

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

.booster-btn {
  width: auto;
  padding: 0 8px;
  gap: 4px;
  font-size: 13px;
  font-weight: 800;
  background: #b45309;
  border-color: #f59e0b;
}

/* --- Waiting Bays Section --- */
#bays-station {
  background: linear-gradient(180deg, #101726 0%, #0d1320 100%);
  border-bottom: 2px solid #23314d;
  padding: 6px 12px 10px 12px;
  z-index: 5;
}

.bays-header {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

#bays-track {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-width: 600px;
  margin: 0 auto;
}

.bay-slot {
  position: relative;
  aspect-ratio: 1 / 1.25;
  max-height: 75px;
  background: #090e18;
  border: 2px dashed #2d3b55;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.bay-slot.occupied {
  border-style: solid;
  border-color: #3b82f6;
  background: #141c2c;
}

.bay-slot.full-match {
  border-color: #10b981;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.slot-tag {
  position: absolute;
  bottom: 4px;
  font-size: 11px;
  font-weight: 900;
  color: #475569;
}

/* Bus in waiting bay */
.parked-bus-card {
  position: absolute;
  inset: 4px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 4px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  animation: parkIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes parkIn {
  from { transform: translateY(40px) scale(0.8); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.parked-bus-card.bus-red { background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%); }
.parked-bus-card.bus-blue { background: linear-gradient(180deg, #3b82f6 0%, #1d4ed8 100%); }
.parked-bus-card.bus-green { background: linear-gradient(180deg, #10b981 0%, #047857 100%); }
.parked-bus-card.bus-yellow { background: linear-gradient(180deg, #f59e0b 0%, #b45309 100%); }
.parked-bus-card.bus-purple { background: linear-gradient(180deg, #8b5cf6 0%, #6d28d9 100%); }
.parked-bus-card.bus-rainbow { background: linear-gradient(135deg, #ec4899, #f59e0b, #10b981, #3b82f6); }

.bus-roof-badge {
  font-size: 10px;
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.bus-seats-row {
  display: flex;
  gap: 3px;
}

.seat-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #1e293b;
  border: 1.5px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: #cbd5e1;
}

.seat-dot.filled {
  background: #ffffff;
  color: #0f172a;
  font-weight: 900;
  animation: seatPop 0.2s ease-out;
}

@keyframes seatPop {
  0% { transform: scale(0.5); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* --- Main Stage & Canvas --- */
#stage {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* --- Footer Instructions --- */
#footer-bar {
  padding: 8px 14px;
  background: #090d16;
  border-top: 1px solid #1e293b;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
}

/* --- Modals & Overlays --- */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 22, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  transition: opacity 0.25s ease;
}

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

.modal-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid #334155;
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(30px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.danger-card {
  border-color: #ef4444;
}

.modal-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.hero-bus {
  width: 50px;
  height: 100px;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
  transform: rotate(-10deg);
}

.hero-pass {
  width: 65px;
  height: 80px;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
  transform: rotate(6deg);
}

.game-title {
  font-size: 26px;
  font-weight: 900;
  color: #f8fafc;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.game-subtitle {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.4;
  margin-bottom: 16px;
}

.rules-box {
  background: #090e1a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 12px;
  text-align: left;
  font-size: 12px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.rule-item b {
  color: #f1f5f9;
}

.action-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.5px;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.primary-btn {
  background: linear-gradient(180deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.6);
}

.secondary-btn {
  background: #334155;
  color: #f8fafc;
  margin-top: 10px;
}

.secondary-btn:hover {
  background: #475569;
}

/* Stars & Level Complete */
.stars-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.star-icon {
  font-size: 38px;
  color: #334155;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.star-icon.star-active {
  color: #f59e0b;
  text-shadow: 0 0 16px rgba(245, 158, 11, 0.6);
  animation: starPop 0.4s ease-out;
}

@keyframes starPop {
  0% { transform: scale(0.2); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.modal-title {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 6px;
}

.modal-desc {
  font-size: 13px;
  color: #94a3b8;
  margin-bottom: 16px;
}

.stats-box {
  background: #090e1a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 14px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  color: #94a3b8;
}

.stat-row b {
  color: #f8fafc;
}

.danger-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

/* Tutorial Pointer */
.tutorial-pointer {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -100%);
  animation: bouncePointer 1.4s infinite ease-in-out;
  transition: opacity 0.3s ease;
}

.tutorial-pointer.hidden {
  display: none !important;
}

.pointer-hand {
  font-size: 28px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
}

.pointer-text {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid #3b82f6;
  color: #60a5fa;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 9999px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  margin-top: 2px;
}

@keyframes bouncePointer {
  0%, 100% { transform: translate(-50%, -100%) translateY(0); }
  50% { transform: translate(-50%, -100%) translateY(-10px); }
}

@media (max-width: 480px) {
  #hud {
    height: 48px;
    padding: 4px 8px;
  }
  #level-badge, #score-badge {
    padding: 3px 8px;
    font-size: 11px;
  }
  .hud-btn {
    width: 30px;
    height: 30px;
    font-size: 13px;
  }
  .booster-btn {
    padding: 0 6px;
    font-size: 11px;
  }
  #bays-station {
    padding: 4px 8px 6px;
  }
  .bays-header {
    font-size: 9px;
    margin-bottom: 3px;
  }
  .bay-slot {
    aspect-ratio: 1 / 1.1;
    max-height: 56px;
    border-radius: 8px;
  }
  .bus-roof-badge {
    font-size: 8px;
  }
  .bus-seats-dots .seat-dot {
    width: 5px;
    height: 5px;
  }
  #footer-bar {
    padding: 4px 8px;
    font-size: 11px;
  }
}
