:root {
  --game-bg: linear-gradient(180deg, #b3e5fc 0%, #81d4fa 40%, #c8e6c9 75%, #81c784 100%);
}

.train-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  padding: 10px 16px 20px;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

/* Station Banner */
.station-banner {
  background: rgba(255, 255, 255, 0.95);
  border: 3px solid #ffa000;
  border-radius: 24px;
  padding: 6px 22px;
  box-shadow: 0 4px 14px rgba(255, 160, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
  color: #d84315;
  z-index: 25;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.station-banner.banner-bounce {
  transform: scale(1.12);
}

.station-icon {
  font-size: 24px;
  line-height: 1;
}

/* Scenery Layer */
.scenery-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.sky-elements {
  position: absolute;
  top: 15px;
  left: 0;
  right: 0;
  height: 90px;
}

.scenery-sun {
  position: absolute;
  top: 10px;
  right: 25px;
  font-size: 48px;
  line-height: 1;
  animation: sun-spin 16s linear infinite;
  filter: drop-shadow(0 4px 10px rgba(255, 179, 0, 0.4));
}

@keyframes sun-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.scenery-cloud {
  position: absolute;
  font-size: 38px;
  line-height: 1;
  opacity: 0.85;
}

.sc-1 { top: 20px; left: 10%; animation: cloud-float-1 20s linear infinite; }
.sc-2 { top: 40px; left: 55%; animation: cloud-float-2 26s linear infinite; }

@keyframes cloud-float-1 {
  0% { transform: translateX(0); }
  50% { transform: translateX(30px); }
  100% { transform: translateX(0); }
}

@keyframes cloud-float-2 {
  0% { transform: translateX(0); }
  50% { transform: translateX(-30px); }
  100% { transform: translateX(0); }
}

.landscape {
  position: absolute;
  bottom: 125px;
  left: 0;
  width: 200%;
  display: flex;
  opacity: 0.85;
  pointer-events: none;
  will-change: transform;
}

.landscape-track {
  width: 50%;
  display: flex;
  justify-content: space-around;
  font-size: 36px;
  line-height: 1;
}

.scenery-rolling .landscape {
  animation: landscape-loop 2.8s linear infinite;
}

@keyframes landscape-loop {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* Train Track & Convey */
.train-track {
  position: relative;
  width: 100%;
  max-width: 580px;
  height: 220px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 25px;
  box-sizing: border-box;
  z-index: 10;
}

.steam-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 15;
}

.steam-puff {
  position: absolute;
  font-size: 34px;
  line-height: 1;
  pointer-events: none;
  will-change: transform, opacity;
  animation: puff-rise 1.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes puff-rise {
  0% { transform: translate(0, 0) scale(0.5); opacity: 0.95; }
  100% { transform: translate(var(--dx, 35px), -70px) scale(1.45); opacity: 0; }
}

.train-convoy {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  z-index: 12;
  transition: transform 0.3s ease;
}

.convoy-chugging {
  animation: chug-bob 0.38s infinite ease-in-out alternate;
}

@keyframes chug-bob {
  0% { transform: translateY(0); }
  100% { transform: translateY(-5px); }
}

.convoy-rolling-anim {
  animation: convoy-travel 2.8s cubic-bezier(0.3, 0, 0.2, 1) forwards;
}

@keyframes convoy-travel {
  0% { transform: translateX(0); }
  14% { transform: translateX(-16px); }
  86% { transform: translateX(-16px); }
  100% { transform: translateX(0); }
}

/* Locomotive */
.locomotive {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.smokestack-btn {
  position: absolute;
  top: -28px;
  left: 10px;
  min-width: 48px;
  min-height: 48px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  outline: none;
  transition: transform 0.15s ease;
}

.smokestack-btn:hover {
  transform: scale(1.15);
}

.smokestack-btn:active {
  transform: scale(0.92);
}

.smokestack-btn:focus-visible {
  outline: 3px solid #ffb300;
  border-radius: 8px;
}

.stack-cap {
  font-size: 26px;
  line-height: 1;
  animation: cap-wobble 2s infinite ease-in-out;
}

.stack-pipe {
  width: 14px;
  height: 9px;
  background: #37474f;
  border-radius: 3px 3px 0 0;
  margin-top: -2px;
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.25);
}

@keyframes cap-wobble {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.loco-body {
  position: relative;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  outline: none;
  transition: transform 0.15s ease;
}

.loco-body:active {
  transform: scale(0.95);
}

.loco-body:focus-visible {
  outline: 3px solid #ffb300;
  border-radius: 12px;
}

.loco-icon {
  font-size: 88px;
  line-height: 1;
  display: inline-block;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.2));
}

/* Wagons */
.wagon-btn {
  position: relative;
  width: 90px;
  height: 76px;
  border-radius: 18px 18px 8px 8px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  outline: none;
  z-index: 12;
}

.wagon-btn:hover {
  transform: translateY(-4px) scale(1.04);
}

.wagon-btn:active {
  transform: scale(0.96);
}

.wagon-btn:focus-visible {
  outline: 3px solid #ffb300;
  outline-offset: 3px;
}

.wagon-roof {
  position: absolute;
  top: -6px;
  left: 8px;
  right: 8px;
  height: 8px;
  border-radius: 6px 6px 0 0;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.wagon-red {
  background: linear-gradient(180deg, #ff7043 0%, #d84315 100%);
  border: 3px solid #bf360c;
}

.wagon-blue {
  background: linear-gradient(180deg, #42a5f5 0%, #1565c0 100%);
  border: 3px solid #0d47a1;
}

.wagon-window {
  width: 58px;
  height: 44px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15);
}

.passenger-emoji {
  font-size: 38px;
  line-height: 1;
  display: inline-block;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.passenger-emoji.waving {
  animation: passenger-wave 0.6s ease-in-out;
}

@keyframes passenger-wave {
  0%, 100% { transform: rotate(0deg) scale(1); }
  30% { transform: rotate(-14deg) scale(1.18); }
  70% { transform: rotate(14deg) scale(1.18); }
}

.wheels-row {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

.train-wheel {
  font-size: 16px;
  line-height: 1;
  display: inline-block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.wheel-spinning .train-wheel {
  animation: wheel-spin 0.4s linear infinite;
}

@keyframes wheel-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Railway Track */
.rail-line {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  height: 14px;
  background: repeating-linear-gradient(90deg, #3e2723 0px, #3e2723 16px, transparent 16px, transparent 28px), #5d4037;
  border-top: 3px solid #bcaaa4;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  border-radius: 2px;
}

/* Controls */
.train-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 20;
}

.train-ctrl-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  border: none;
  border-radius: 30px;
  padding: 10px 22px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s, opacity 0.2s;
  outline: none;
}

.train-ctrl-btn:hover:not([aria-disabled="true"]) {
  transform: translateY(-2px) scale(1.05);
}

.train-ctrl-btn:active:not([aria-disabled="true"]) {
  transform: scale(0.95);
}

.train-ctrl-btn:focus-visible {
  outline: 3px solid #ffb300;
  outline-offset: 3px;
}

.whistle-btn {
  background: linear-gradient(135deg, #0288d1 0%, #01579b 100%);
  border: 2px solid #81d4fa;
}

.bell-btn {
  background: linear-gradient(135deg, #fbc02d 0%, #f57f17 100%);
  color: #212121;
  border: 2px solid #fff59d;
}

.go-btn {
  background: linear-gradient(135deg, #43a047 0%, #2e7d32 100%);
  border: 2px solid #a5d6a7;
  padding: 10px 26px;
}

.go-btn[aria-disabled="true"] {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none !important;
}

/* Particles Container */
.particles-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

.train-spark {
  position: absolute;
  font-size: 24px;
  pointer-events: none;
  animation: spark-fade 0.9s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes spark-fade {
  0% { transform: translate(0, 0) scale(0.5); opacity: 1; }
  100% { transform: translate(var(--tx, 0px), var(--ty, -50px)) scale(1.2); opacity: 0; }
}

@media (max-width: 480px) {
  .train-convoy { gap: 8px; }
  .wagon-btn { width: 76px; height: 66px; }
  .wagon-window { width: 48px; height: 38px; }
  .passenger-emoji { font-size: 30px; }
  .loco-icon { font-size: 74px; }
  .smokestack-btn { top: -24px; left: 8px; }
  .train-ctrl-btn { font-size: 16px; padding: 8px 16px; }
  .station-banner { font-size: 17px; padding: 5px 16px; }
}

@media (max-height: 600px) {
  .train-track { height: 170px; padding-bottom: 16px; }
  .landscape { bottom: 95px; }
  .landscape-track { font-size: 28px; }
  .loco-icon { font-size: 68px; }
  .wagon-btn { width: 72px; height: 60px; }
  .wagon-window { width: 46px; height: 34px; }
  .passenger-emoji { font-size: 28px; }
  .station-banner { font-size: 15px; padding: 4px 14px; }
  .train-ctrl-btn { font-size: 14px; padding: 6px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .scenery-sun,
  .scenery-cloud,
  .scenery-rolling .landscape,
  .convoy-chugging,
  .convoy-rolling-anim,
  .train-wheel,
  .passenger-emoji,
  .train-spark,
  .steam-puff,
  .stack-cap {
    animation: none !important;
    transition: none !important;
  }
}
