/* ==========================================================================
   THE PHONICS EXPRESS - COMPREHENSIVE RESPONSIVE STYLESHEET
   Target Letters: Ii, Pp, Nn | Vocabulary: 9 Words
   ========================================================================== */

:root {
  --primary-blue: #0284c7;
  --sky-top: #7dd3fc;
  --sky-bottom: #e0f2fe;
  --grass-light: #86efac;
  --grass-dark: #22c55e;
  
  /* Letter Colors */
  --color-i: #3b82f6;
  --color-i-bg: #eff6ff;
  --color-i-border: #2563eb;

  --color-p: #ec4899;
  --color-p-bg: #fdf2f8;
  --color-p-border: #db2777;

  --color-n: #10b981;
  --color-n-bg: #ecfdf5;
  --color-n-border: #059669;

  --train-metal: #334155;
  --train-accent: #f59e0b;
  --wood-brown: #b45309;

  --font-title: 'Fredoka', cursive, sans-serif;
  --font-body: 'Nunito', sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  font-family: var(--font-body);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 55%, var(--grass-light) 75%, var(--grass-dark) 100%);
  color: #1e293b;
  overscroll-behavior: none;
}

/* ==========================================================================
   BACKGROUND ANIMATED SCENERY
   ========================================================================== */
.sky-scenery {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.sun {
  position: absolute;
  top: 25px;
  right: 50px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, #fef08a 0%, #facc15 65%, #f59e0b 100%);
  box-shadow: 0 0 35px #fde047;
  animation: sunPulse 4s ease-in-out infinite alternate;
}

@keyframes sunPulse {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.08); opacity: 1; }
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 50px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.05));
}

.cloud::before, .cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud-1 {
  top: 40px;
  left: -120px;
  width: 140px;
  height: 45px;
  animation: floatCloud 32s linear infinite;
}
.cloud-1::before { width: 50px; height: 50px; top: -20px; left: 25px; }
.cloud-1::after { width: 40px; height: 40px; top: -14px; left: 70px; }

.cloud-2 {
  top: 80px;
  left: -200px;
  width: 180px;
  height: 55px;
  animation: floatCloud 45s linear infinite 10s;
}
.cloud-2::before { width: 65px; height: 65px; top: -26px; left: 35px; }
.cloud-2::after { width: 55px; height: 55px; top: -18px; left: 95px; }

.cloud-3 {
  top: 130px;
  left: -150px;
  width: 120px;
  height: 40px;
  animation: floatCloud 38s linear infinite 18s;
}
.cloud-3::before { width: 45px; height: 45px; top: -18px; left: 25px; }
.cloud-3::after { width: 35px; height: 35px; top: -12px; left: 60px; }

@keyframes floatCloud {
  0% { transform: translateX(0); }
  100% { transform: translateX(calc(100vw + 250px)); }
}

.hills {
  position: absolute;
  bottom: 0;
  width: 100%;
}

.back-hills {
  height: 38vh;
  background: radial-gradient(ellipse at 50% 100%, #86efac 0%, #4ade80 70%, transparent 72%);
  opacity: 0.7;
}

.front-hills {
  height: 30vh;
  background: radial-gradient(ellipse at 50% 100%, #22c55e 0%, #16a34a 90%);
}

/* ==========================================================================
   GAME MAIN CONTAINER
   ========================================================================== */
.game-wrapper {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px;
}

/* ==========================================================================
   TOP HEADER
   ========================================================================== */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 10px 18px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  border: 2px solid #ffffff;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* School Logo Link */
.school-logo-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}

.school-logo-link:hover {
  transform: scale(1.06);
  opacity: 0.95;
}

.school-logo {
  height: 44px;
  width: auto;
  object-fit: contain;
}

.title-box .main-title {
  font-family: var(--font-title);
  font-size: 1.55rem;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.5px;
}

.title-box .sub-title {
  font-size: 0.9rem;
  color: #475569;
}

.title-box .sub-title strong {
  color: #0284c7;
  font-weight: 800;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Phone Rotate Tip Badge */
.phone-rotate-tip {
  display: none;
  align-items: center;
  gap: 4px;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  color: #166534;
  cursor: pointer;
  animation: tipPulse 2.5s infinite;
}

@keyframes tipPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* Helper Bee in Header */
.bee-helper-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fef08a;
  border: 2px solid #eab308;
  border-radius: 30px;
  padding: 6px 14px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(234, 179, 8, 0.25);
  transition: transform 0.2s, box-shadow 0.2s;
}

.bee-helper-btn:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 6px 14px rgba(234, 179, 8, 0.35);
}

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

.header-bee-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  animation: beeWiggle 2.5s ease-in-out infinite;
}

@keyframes beeWiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}

.bee-bubble {
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 700;
  color: #854d0e;
}

/* Progress Star Box */
.progress-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 20px;
  padding: 6px 14px;
  font-weight: 800;
  color: #1e293b;
  font-size: 0.95rem;
}

.progress-star {
  font-size: 1.25rem;
}

/* Control Buttons (Sound, etc.) */
.ctrl-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid #e2e8f0;
  background: #ffffff;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
  transition: all 0.2s;
}

.ctrl-btn:hover {
  transform: scale(1.08);
  border-color: #0284c7;
}

/* ==========================================================================
   TRAIN & RAILROAD STAGE
   ========================================================================== */
.train-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 10px 0 6px;
  min-height: 240px;
}

.train-track-scenery {
  position: absolute;
  bottom: 22px;
  left: 0;
  width: 100%;
  height: 36px;
  z-index: 1;
}

.rail-ties {
  position: absolute;
  bottom: 4px;
  left: 0;
  width: 100%;
  height: 18px;
  background: repeating-linear-gradient(
    90deg,
    #78350f 0px,
    #78350f 12px,
    transparent 12px,
    transparent 28px
  );
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
}

.rail-bar {
  position: absolute;
  left: 0;
  width: 100%;
  height: 6px;
  background: linear-gradient(180deg, #94a3b8 0%, #475569 100%);
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.rail-top { bottom: 18px; }
.rail-bottom { bottom: 4px; }

/* Train Assembly Container */
.train-assembly {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: flex-end; /* All vehicle wheels sit flush on the rails! */
  justify-content: center;
  gap: 4px;
  width: 100%;
  max-width: 1250px;
  padding: 10px 5px 32px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
}

.train-assembly::-webkit-scrollbar {
  display: none;
}

/* ==========================================================================
   LOCOMOTIVE ENGINE (FACING FORWARD TO THE LEFT)
   Wheels flush on track baseline; Chimney securely attached to boiler roof
   ========================================================================== */
.locomotive {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: 180px;
  height: 175px; /* Matches .cargo-car height! */
  flex-shrink: 0;
  margin-right: 6px;
  scroll-snap-align: center;
}

.engine-body {
  position: relative;
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: 135px; /* Matches cargo car body height! */
}

/* Cowcatcher at the front (left) */
.cowcatcher {
  position: absolute;
  left: -14px;
  bottom: 0;
  width: 18px;
  height: 38px;
  background: repeating-linear-gradient(
    -45deg,
    #1e293b,
    #1e293b 4px,
    #f59e0b 4px,
    #f59e0b 8px
  );
  clip-path: polygon(100% 0, 0 100%, 100% 100%);
}

/* Boiler with badge in front-middle */
.boiler {
  position: relative;
  width: 95px;
  height: 85px;
  background: linear-gradient(180deg, #dc2626 0%, #991b1b 100%);
  border-top-left-radius: 20px;
  border-bottom-left-radius: 8px;
  border: 3px solid #7f1d1d;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 4px 8px rgba(255, 255, 255, 0.2);
}

/* Smoke stack securely mounted directly on boiler roof (no floating black box!) */
.smoke-stack {
  position: absolute;
  top: -24px;
  left: 20px;
  width: 22px;
  height: 26px;
  background: linear-gradient(180deg, #334155 0%, #0f172a 100%);
  border-top: 3px solid #f59e0b;
  border-radius: 4px 4px 2px 2px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  z-index: 5;
}

/* Smoke puffs rising from chimney top and drifting back to the right */
.smoke-puff {
  position: absolute;
  top: -16px;
  left: 1px;
  width: 20px;
  height: 20px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  opacity: 0;
  animation: puffSmoke 2.6s ease-out infinite;
}

.puff-1 { animation-delay: 0s; }
.puff-2 { animation-delay: 0.8s; }
.puff-3 { animation-delay: 1.6s; }

@keyframes puffSmoke {
  0% { transform: translateY(0) scale(0.6); opacity: 0.7; }
  50% { opacity: 0.5; }
  100% { transform: translateY(-40px) translateX(30px) scale(2); opacity: 0; }
}

.engine-badge {
  background: #fbbf24;
  color: #78350f;
  font-family: var(--font-title);
  font-size: 0.9rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 12px;
  border: 2px solid #b45309;
}

/* Cab at rear (right), connecting to cargo cars */
.engine-cab {
  position: relative;
  width: 80px;
  height: 125px;
  background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  border: 3px solid #7f1d1d;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 14px;
  box-shadow: inset 0 4px 8px rgba(255, 255, 255, 0.25);
}

.cab-window {
  width: 46px;
  height: 42px;
  background: #bae6fd;
  border: 3px solid #fef08a;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.15);
}

/* Conductor Bear looking forward (to the left) */
.conductor-icon {
  display: inline-block;
  transform: scaleX(-1);
}

/* Whistle button cleanly mounted on cab roof so wheels touch the track! */
.whistle-on-cab {
  position: absolute;
  top: -30px;
  right: 4px;
  margin: 0;
  z-index: 10;
  background: #f59e0b;
  border: 2px solid #b45309;
  border-radius: 14px;
  padding: 3px 12px;
  font-family: var(--font-title);
  font-size: 0.82rem;
  font-weight: 800;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(180, 83, 9, 0.3);
  transition: transform 0.15s;
  white-space: nowrap;
}

.whistle-on-cab:hover {
  transform: scale(1.08);
  background: #fbbf24;
}

.whistle-on-cab:active {
  transform: scale(0.95);
}

/* Locomotive Wheels: Exactly aligned on track baseline */
.engine-wheels {
  display: flex;
  justify-content: space-around;
  width: 88%;
  margin: -10px auto 0; /* Matches .cargo-car .wheels-wrap */
}

.wheel {
  width: 36px;
  height: 36px;
  background: radial-gradient(circle, #64748b 30%, #1e293b 65%, #0f172a 100%);
  border: 3px solid #cbd5e1;
  border-radius: 50%;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.35);
  position: relative;
}

.wheel::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  background: #facc15;
  border-radius: 50%;
}

/* Coupler between cars */
.coupler {
  width: 16px;
  height: 8px;
  background: #475569;
  border-radius: 4px;
  margin-bottom: 24px;
  flex-shrink: 0;
  border: 1px solid #1e293b;
}

/* ==========================================================================
   CARGO CARS (I, P, N)
   ========================================================================== */
.cargo-car {
  position: relative;
  display: flex;
  flex-direction: column;
  width: clamp(230px, 24vw, 300px);
  height: 175px;
  border-radius: 18px 18px 12px 12px;
  border: 4px solid;
  padding: 8px 10px 6px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
  flex-shrink: 0;
  cursor: pointer;
  scroll-snap-align: center;
}

.cargo-car:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.2);
}

/* Letter Car Color Themes */
.car-i {
  background: linear-gradient(180deg, #bfdbfe 0%, #60a5fa 60%, #2563eb 100%);
  border-color: var(--color-i-border);
}

.car-p {
  background: linear-gradient(180deg, #fbcfe8 0%, #f472b6 60%, #db2777 100%);
  border-color: var(--color-p-border);
}

.car-n {
  background: linear-gradient(180deg, #a7f3d0 0%, #34d399 60%, #059669 100%);
  border-color: var(--color-n-border);
}

/* Car Header Badge / Sign Plate (Clickable to hear letter sound!) */
.car-sign-plate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 14px;
  padding: 4px 12px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
  border: 2px solid #ffffff;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
}

.car-sign-plate:hover {
  transform: scale(1.05);
  background: #ffffff;
}

.sound-wave-icon {
  font-size: 1.15rem;
}

.car-sign-plate .letter-label {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
}

.car-i .letter-label { color: var(--color-i-border); }
.car-p .letter-label { color: var(--color-p-border); }
.car-n .letter-label { color: var(--color-n-border); }

.sound-hint {
  font-size: 0.85rem;
  font-weight: 700;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 10px;
  color: #475569;
}

/* Cargo Bay (Where items drop into) */
.car-cargo-bay {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 6px;
  flex: 1;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  margin: 6px 0;
  padding: 4px;
  border: 2px dashed rgba(255, 255, 255, 0.6);
  transition: all 0.2s;
}

/* Drag over highlight on car */
.cargo-car.drag-target-active .car-cargo-bay {
  background: rgba(254, 240, 138, 0.5);
  border: 3px dashed #eab308;
  transform: scale(1.02);
}

.cargo-car.highlight-target {
  box-shadow: 0 0 25px rgba(250, 204, 21, 0.9);
  animation: carGlow 1.2s infinite alternate;
}

@keyframes carGlow {
  0% { transform: translateY(-4px) scale(1); }
  100% { transform: translateY(-6px) scale(1.03); }
}

.cargo-slot {
  width: clamp(52px, 6vw, 68px);
  height: clamp(52px, 6vw, 68px);
  background: rgba(255, 255, 255, 0.4);
  border: 2px dashed rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.25s;
}

/* Filled Cargo Item inside Slot */
.cargo-slot.filled {
  background: #ffffff;
  border: 2px solid #22c55e;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  animation: slotPopIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slotPopIn {
  0% { transform: scale(0.3) rotate(-15deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.cargo-slot.filled img {
  width: 82%;
  height: 82%;
  object-fit: contain;
}

.cargo-slot.filled .slot-check {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: #22c55e;
  color: #ffffff;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
}

/* Chassis & Status Tag */
.car-chassis {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.car-status-tag {
  background: rgba(15, 23, 42, 0.75);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 10px;
  letter-spacing: 0.5px;
}

.cargo-car.is-full .car-status-tag {
  background: #22c55e;
  color: #ffffff;
}

.cargo-car .wheels-wrap {
  display: flex;
  justify-content: space-around;
  width: 85%;
  margin: -10px auto 0;
}

.cargo-car .wheel {
  width: 36px;
  height: 36px;
}

/* Sound Ripple Animation when letter car is clicked */
.car-sound-wave-active {
  animation: soundPulseCar 0.5s ease-out;
}

@keyframes soundPulseCar {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.8); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 16px rgba(255, 255, 255, 0); }
  100% { transform: scale(1); }
}

/* ==========================================================================
   BOTTOM STATION CARGO TRAY (DISPLAYS ALL 9 CARDS)
   ========================================================================== */
.cargo-tray-section {
  position: relative;
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  padding: 12px 18px 14px;
  box-shadow: 0 -6px 25px rgba(0, 0, 0, 0.1);
  border: 3px solid #ffffff;
  margin-top: 8px;
  touch-action: none;
}

.tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid #f1f5f9;
}

.tray-instructions {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-title);
  font-size: 1.05rem;
  color: #0f172a;
}

.instruction-icon {
  font-size: 1.3rem;
  animation: pointBounce 1.5s infinite;
}

@keyframes pointBounce {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(5px); }
}

.tray-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-reset-cards {
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 700;
  color: #475569;
  padding: 5px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reset-cards:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* ==========================================================================
   CARDS VIEWPORT & ALL 9 CARDS
   ========================================================================== */
.tray-viewport {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.cards-rail.mode-all {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 4px;
  touch-action: none;
}

/* ==========================================================================
   VOCABULARY CARD STYLES
   ========================================================================== */
.vocab-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: clamp(96px, 9.6vw, 122px);
  height: clamp(118px, 11.8vw, 138px);
  background: #ffffff;
  border-radius: 18px;
  border: 3px solid #e2e8f0;
  padding: 7px 6px;
  cursor: grab;
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: element;
  user-drag: element;
}

.vocab-card * {
  pointer-events: none;
}

.vocab-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
  border-color: #38bdf8;
}

.vocab-card:active {
  cursor: grabbing;
}

/* Card Selection Glow (for tap-to-select mode) */
.vocab-card.is-selected {
  border-color: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.35), 0 8px 20px rgba(245, 158, 11, 0.4);
  transform: translateY(-6px) scale(1.05);
  animation: cardSelectedPulse 1.2s infinite alternate;
}

@keyframes cardSelectedPulse {
  0% { transform: translateY(-5px) scale(1.04); }
  100% { transform: translateY(-8px) scale(1.07); }
}

/* Dragging state */
.vocab-card.is-dragging {
  opacity: 0.45;
  transform: scale(0.92);
}

/* Loaded state (already placed in train car) */
.vocab-card.is-loaded {
  opacity: 0.35;
  pointer-events: none;
  filter: grayscale(0.8);
  border-style: dashed;
}

.vocab-card.is-loaded::after {
  content: '✓ Loaded';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg);
  background: #22c55e;
  color: #ffffff;
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.card-img-wrap {
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.2s;
  pointer-events: none;
}

.vocab-card:hover .card-img {
  transform: scale(1.1);
}

.card-word-title {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
  text-transform: capitalize;
  margin-top: 2px;
}

.card-sound-pill {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 8px;
  background: #f1f5f9;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 3px;
}

/* Card Speaker Icon */
.card-speaker-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  pointer-events: none;
}

/* Touch drag clone element */
.touch-drag-clone {
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25) !important;
  border-color: #f59e0b !important;
  transform: scale(1.1) !important;
}

/* ==========================================================================
   MODAL DIALOGS (START & VICTORY)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  position: relative;
  background: #ffffff;
  border-radius: 28px;
  padding: 28px 30px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  border: 4px solid #ffffff;
  animation: modalPop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-school-logo {
  height: 40px;
  margin-bottom: 12px;
}

.modal-mascot-frame {
  margin-bottom: 12px;
}

.modal-bee-bounce {
  width: 100px;
  height: 100px;
  object-fit: contain;
  animation: floatBee 2s ease-in-out infinite alternate;
}

@keyframes floatBee {
  0% { transform: translateY(0) rotate(-4deg); }
  100% { transform: translateY(-12px) rotate(4deg); }
}

.modal-title {
  font-family: var(--font-title);
  font-size: 1.85rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 1.05rem;
  color: #475569;
  line-height: 1.5;
  margin-bottom: 18px;
}

.modal-rules-grid {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.rule-chip {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.9rem;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-primary-action {
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  border: none;
  border-bottom: 4px solid #15803d;
  color: #ffffff;
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 800;
  padding: 14px 32px;
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(22, 163, 74, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s;
}

.btn-primary-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(22, 163, 74, 0.5);
  background: linear-gradient(180deg, #4ade80 0%, #16a34a 100%);
}

.btn-primary-action:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

/* ==========================================================================
   VICTORY & BEE CELEBRATION
   ========================================================================= */
.victory-card {
  max-width: 600px;
  background: linear-gradient(180deg, #ffffff 0%, #fefce8 100%);
}

.victory-confetti-header {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.victory-bee-wrap {
  position: relative;
  display: inline-block;
  margin-bottom: 12px;
}

.celebration-bee-mascot {
  width: 120px;
  height: 120px;
  object-fit: contain;
  animation: beeVictoryDance 1.8s ease-in-out infinite alternate;
}

@keyframes beeVictoryDance {
  0% { transform: translateY(0) rotate(-6deg) scale(1); }
  50% { transform: translateY(-16px) rotate(6deg) scale(1.08); }
  100% { transform: translateY(0) rotate(-6deg) scale(1); }
}

.bee-speech-bubble {
  position: absolute;
  top: -16px;
  right: -90px;
  background: #ffffff;
  border: 3px solid #eab308;
  border-radius: 18px;
  padding: 8px 14px;
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 800;
  color: #854d0e;
  box-shadow: 0 6px 14px rgba(234, 179, 8, 0.3);
  white-space: nowrap;
}

.bee-speech-bubble::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 6px 10px 6px 0;
  border-style: solid;
  border-color: transparent #eab308 transparent transparent;
}

.victory-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 900;
  color: #15803d;
  letter-spacing: -0.5px;
}

.victory-desc {
  font-size: 1.1rem;
  color: #475569;
  margin-bottom: 12px;
}

.stars-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
}

.gold-star {
  font-size: 2.8rem;
  animation: starPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

.star-1 { animation-delay: 0.1s; }
.star-2 { animation-delay: 0.3s; }
.star-3 { animation-delay: 0.5s; }

@keyframes starPop {
  0% { transform: scale(0) rotate(-60deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Recap of 3 Cars */
.recap-container {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.recap-card {
  flex: 1;
  min-width: 140px;
  border-radius: 16px;
  padding: 10px 8px;
  border: 2px solid;
  text-align: left;
}

.recap-i { background: #eff6ff; border-color: #3b82f6; }
.recap-p { background: #fdf2f8; border-color: #ec4899; }
.recap-n { background: #ecfdf5; border-color: #10b981; }

.recap-badge {
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.recap-i .recap-badge { color: #1d4ed8; }
.recap-p .recap-badge { color: #be185d; }
.recap-n .recap-badge { color: #047857; }

.recap-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
}

/* Error Shake Animation for incorrect placement */
.cargo-car.shake-error {
  animation: carErrorShake 0.45s ease-in-out;
  border-color: #ef4444 !important;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.8) !important;
}

@keyframes carErrorShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px) rotate(-1deg); }
  40%, 80% { transform: translateX(8px) rotate(1deg); }
}

/* Confetti Canvas */
.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2000;
}

/* ==========================================================================
   RESPONSIVE DESIGN BREAKPOINTS & PHONE SCALING
   ========================================================================== */
@media (max-width: 1024px) {
  .game-wrapper {
    padding: 8px 12px;
  }
  .cargo-car {
    width: 220px;
    height: 165px;
  }
  .locomotive {
    width: 160px;
    height: 165px;
  }
  .engine-body {
    height: 125px;
  }
}

/* Phone Portrait Adjustments (< 768px) */
@media (max-width: 768px) {
  .phone-rotate-tip {
    display: flex;
    padding: 2px 8px;
    font-size: 0.72rem;
  }
  .game-wrapper {
    padding: 6px 8px;
  }
  .game-header {
    padding: 6px 12px;
    border-radius: 16px;
  }
  .title-box .main-title {
    font-size: 1.15rem;
  }
  .title-box .sub-title {
    display: none;
  }
  .bee-bubble {
    display: none;
  }
  .bee-helper-btn {
    padding: 4px;
  }
  .train-stage {
    min-height: 180px;
    margin: 4px 0 2px;
  }
  .train-track-scenery {
    bottom: 16px;
  }
  .train-assembly {
    justify-content: flex-start;
    padding-bottom: 24px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .cargo-car {
    width: 175px;
    height: 138px;
    padding: 5px 6px 4px;
  }
  .locomotive {
    width: 140px;
    height: 138px;
  }
  .engine-body {
    height: 105px;
  }
  .boiler {
    width: 74px;
    height: 68px;
  }
  .engine-cab {
    width: 65px;
    height: 98px;
  }
  .whistle-on-cab {
    top: -26px;
    padding: 2px 8px;
    font-size: 0.75rem;
  }
  .car-sign-plate {
    padding: 2px 8px;
  }
  .car-sign-plate .letter-label {
    font-size: 1.4rem;
  }
  .sound-hint {
    font-size: 0.75rem;
    padding: 1px 6px;
  }
  .cargo-slot {
    width: 42px;
    height: 42px;
  }
  .cargo-tray-section {
    padding: 6px 8px 8px;
    border-radius: 16px;
    margin-top: 4px;
  }
  .tray-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    padding-bottom: 3px;
    gap: 4px;
  }
  .tray-instructions {
    font-size: 0.82rem;
    line-height: 1.2;
  }
  .btn-reset-cards {
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 8px;
    white-space: nowrap;
  }
  .cards-rail.mode-all {
    gap: 5px;
    padding: 2px;
  }
  .vocab-card {
    width: calc(33.333% - 4px);
    max-width: 86px;
    height: 80px;
    border-radius: 12px;
    border-width: 2px;
    padding: 3px 2px;
  }
  .card-img-wrap {
    width: 34px;
    height: 34px;
  }
  .card-word-title {
    font-size: 0.82rem;
    font-weight: 800;
    margin-top: 0px;
    line-height: 1.1;
  }
  .card-sound-pill {
    font-size: 0.58rem;
    padding: 1px 4px;
    line-height: 1.1;
  }
  .card-speaker-badge {
    width: 17px;
    height: 17px;
    font-size: 0.6rem;
    top: 2px;
    right: 2px;
  }
}

/* Very Narrow Phone Screens (< 480px) */
@media (max-width: 480px) {
  .school-logo {
    display: none;
  }
  .progress-box {
    padding: 3px 6px;
    font-size: 0.75rem;
  }
  .cargo-car {
    width: 170px;
    height: 135px;
  }
  .locomotive {
    width: 135px;
    height: 135px;
  }
  .cards-rail.mode-all {
    gap: 4px;
  }
  .vocab-card {
    width: calc(33.333% - 4px);
    max-width: 84px;
    height: 78px;
    padding: 2px 2px;
  }
  .card-img-wrap {
    width: 32px;
    height: 32px;
  }
  .card-word-title {
    font-size: 0.8rem;
  }
}

/* Phone Landscape Mode (Sideways: Height < 520px) - Gives Instant Laptop Quality! */
@media (max-height: 520px) and (orientation: landscape) {
  .phone-rotate-tip {
    display: none;
  }
  .game-wrapper {
    padding: 4px 8px;
    justify-content: space-around;
  }
  .game-header {
    padding: 4px 12px;
    border-radius: 12px;
  }
  .school-logo {
    height: 30px;
  }
  .title-box .main-title {
    font-size: 1.15rem;
  }
  .train-stage {
    min-height: 155px;
    margin: 4px 0 2px;
  }
  .cargo-car {
    width: 175px;
    height: 135px;
    padding: 4px 6px;
  }
  .locomotive {
    width: 135px;
    height: 135px;
  }
  .engine-body {
    height: 100px;
  }
  .boiler {
    width: 70px;
    height: 65px;
  }
  .engine-cab {
    width: 65px;
    height: 95px;
  }
  .car-sign-plate .letter-label {
    font-size: 1.3rem;
  }
  .cargo-slot {
    width: 40px;
    height: 40px;
  }
  .cargo-tray-section {
    padding: 6px 12px;
    border-radius: 16px;
    margin-top: 2px;
  }
  .tray-header {
    margin-bottom: 4px;
    padding-bottom: 2px;
  }
  .tray-instructions {
    font-size: 0.85rem;
  }
  .cards-rail.mode-all {
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }
  .vocab-card {
    width: 88px;
    height: 100px;
    padding: 4px;
    flex-shrink: 0;
  }
  .card-img-wrap {
    width: 38px;
    height: 38px;
  }
  .card-word-title {
    font-size: 0.88rem;
  }
}


/* Banner when all cards have been loaded into train cars */
.all-loaded-tray-banner {
  font-family: var(--font-title);
  font-size: 1.05rem;
  font-weight: 800;
  color: #15803d;
  padding: 16px 20px;
  background: #f0fdf4;
  border: 2px dashed #86efac;
  border-radius: 14px;
  text-align: center;
  width: 100%;
  animation: bannerFadeIn 0.3s ease-out;
}

@keyframes bannerFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
