body[data-page="traffic-escape"] .te-play {
  --te-shell-width: 900px;
}

body[data-page="traffic-escape"] .te-play > .stats-grid,
body[data-page="traffic-escape"] .te-stage {
  width: 100%;
  max-width: var(--te-shell-width);
  margin-inline: auto;
}

body[data-page="traffic-escape"] .te-stage {
  position: relative;
}

body[data-page="traffic-escape"] .te-card {
  box-sizing: border-box;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

body[data-page="traffic-escape"] .te-control-hint {
  max-width: 760px;
  margin: -.2rem auto .62rem;
  color: var(--text-soft, #c9c4e0);
  font: 600 .78rem/1.35 var(--font-main, "Outfit"), sans-serif;
  letter-spacing: .01em;
  opacity: .86;
}

body[data-page="traffic-escape"] .te-board {
  width: var(--te-grid-size, 96%);
  max-width: none;
  isolation: isolate;
  touch-action: pan-y;
}

body[data-page="traffic-escape"] .te-car {
  overflow: visible;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

body[data-page="traffic-escape"] .te-car:active,
body[data-page="traffic-escape"] .te-car.dragging {
  cursor: grabbing;
}


body[data-page="traffic-escape"] .te-car.driving {
  z-index: 30;
  transform: translate(var(--fx, 0), var(--fy, 0));
  opacity: 1;
  transition: transform var(--te-drive-ms, 720ms) cubic-bezier(.22, .61, .36, 1);
  will-change: transform;
}

body[data-page="traffic-escape"] .te-car:focus-visible {
  outline: 3px solid rgba(125, 211, 252, .9);
  outline-offset: 2px;
}

body[data-page="traffic-escape"] .te-car.dragging {
  z-index: 24;
  transform: translate(var(--drag-x, 0), var(--drag-y, 0));
  filter: brightness(1.12) drop-shadow(0 8px 12px rgba(0, 0, 0, .28));
  transition: filter .12s ease;
}

body[data-page="traffic-escape"] .te-car-art {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  pointer-events: none;
  transform-origin: center;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .42));
}

body[data-page="traffic-escape"] .te-car-fallback {
  position: absolute;
  inset: 5% 12%;
  width: 76%;
  height: 90%;
}

body[data-page="traffic-escape"] .te-car-fallback {
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--car-dark) 78%, black);
  border-radius: 25% 25% 20% 20%;
  background:
    linear-gradient(90deg, transparent 8%, rgba(255,255,255,.22) 11%, transparent 17%),
    linear-gradient(145deg, var(--car-light), var(--car-dark));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.32),
    inset 0 -5px 10px rgba(0,0,0,.2);
}

body[data-page="traffic-escape"] .te-car-fallback::before,
body[data-page="traffic-escape"] .te-car-fallback::after {
  content: "";
  position: absolute;
  top: 2%;
  width: 18%;
  height: 7%;
  border-radius: 999px;
  background: #fff4b8;
  box-shadow: 0 0 6px rgba(255, 236, 153, .72);
}

body[data-page="traffic-escape"] .te-car-fallback::before { left: 13%; }
body[data-page="traffic-escape"] .te-car-fallback::after { right: 13%; }

body[data-page="traffic-escape"] .te-windshield,
body[data-page="traffic-escape"] .te-rear-window {
  position: absolute;
  left: 13%;
  width: 74%;
  border-radius: 22%;
  background: linear-gradient(150deg, rgba(226,245,255,.85), rgba(13,31,54,.88));
  border: 1px solid rgba(255,255,255,.22);
}

body[data-page="traffic-escape"] .te-windshield {
  top: 21%;
  height: 19%;
}

body[data-page="traffic-escape"] .te-rear-window {
  bottom: 13%;
  height: 14%;
  opacity: .82;
}

body[data-page="traffic-escape"] .te-headlights {
  position: absolute;
  left: 14%;
  right: 14%;
  bottom: 2%;
  height: 5%;
  border-radius: 999px;
  background:
    radial-gradient(circle at 8% 50%, #ef4444 0 28%, transparent 32%),
    radial-gradient(circle at 92% 50%, #ef4444 0 28%, transparent 32%);
}

body[data-page="traffic-escape"] .te-car[data-vehicle$="-truck"] .te-car-fallback {
  border-radius: 18% 18% 11% 11%;
  background:
    repeating-linear-gradient(0deg, transparent 0 10%, rgba(255,255,255,.1) 11% 13%),
    linear-gradient(145deg, var(--car-light), var(--car-dark));
}

body[data-page="traffic-escape"] .te-car[data-vehicle$="-truck"] .te-rear-window {
  bottom: 8%;
  height: 31%;
  border-radius: 8%;
  background: rgba(20, 27, 38, .38);
}

body[data-page="traffic-escape"] .te-vehicle-png {
  z-index: 2;
  object-fit: contain;
  opacity: 0;
  transition: opacity .18s ease;
  user-select: none;
  -webkit-user-drag: none;
}


body[data-page="traffic-escape"] .te-car-art > .te-vehicle-png {
  position: absolute;
  left: 50%;
  top: 50%;
  width: auto;
  height: 100%;
  max-width: none !important;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center;
}

body[data-page="traffic-escape"] .te-vehicle-png.is-loaded,
body[data-page="traffic-escape"] .te-wall-png.is-loaded {
  opacity: 1;
}

body[data-page="traffic-escape"] .te-car-art.has-png .te-car-fallback,
body[data-page="traffic-escape"] .te-police.has-png .te-police-fallback,
body[data-page="traffic-escape"] .te-wall.has-png .te-wall-fallback {
  opacity: 0;
  visibility: hidden;
}

body[data-page="traffic-escape"] .te-vehicle-png.is-missing,
body[data-page="traffic-escape"] .te-wall-png.is-missing {
  display: none;
}

body[data-page="traffic-escape"] .te-wall {
  position: absolute;
  z-index: 8;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transform-origin: center;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.48));
}

body[data-page="traffic-escape"] .te-wall-fallback,
body[data-page="traffic-escape"] .te-wall-png {
  position: absolute;
  pointer-events: none;
}

body[data-page="traffic-escape"] .te-wall-fallback {
  border: 1px solid rgba(226, 232, 240, .5);
  border-radius: 999px;
  background: repeating-linear-gradient(135deg, #94a3b8 0 5px, #64748b 5px 10px);
  box-shadow:
    0 2px 7px rgba(0,0,0,.45),
    inset 0 1px 0 rgba(255,255,255,.34);
}

body[data-page="traffic-escape"] .te-wall.horizontal .te-wall-fallback {
  left: 4%;
  right: 4%;
  top: 41%;
  height: 18%;
}

body[data-page="traffic-escape"] .te-wall.vertical .te-wall-fallback {
  top: 4%;
  bottom: 4%;
  left: 41%;
  width: 18%;
}

body[data-page="traffic-escape"] .te-wall-png {
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none !important;
  object-fit: contain;
  opacity: 0;
  transition: opacity .18s ease;
  user-select: none;
  -webkit-user-drag: none;
}

body[data-page="traffic-escape"] .te-wall.vertical .te-wall-png {
  transform: rotate(90deg);
}

body[data-page="traffic-escape"] .te-wall.crashed-into {
  animation: teWallHit .32s ease;
}

@keyframes teWallHit {
  35% { filter: brightness(1.7); box-shadow: 0 0 15px rgba(248,113,113,.8); }
  70% { filter: brightness(.82); }
}

body[data-page="traffic-escape"] .te-police {
  position: absolute;
  z-index: 12;
  width: calc(var(--police-size, 10%) * 1.1);
  aspect-ratio: .54 / 1;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(var(--police-deg, 0deg));
  transform-origin: center;
  transition: none;
  will-change: left, top, transform;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.52));
}

body[data-page="traffic-escape"] .te-police-fallback,
body[data-page="traffic-escape"] .te-police .te-vehicle-png {
  position: absolute;
  left: 50%;
  top: 50%;
}

body[data-page="traffic-escape"] .te-police-fallback {
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  overflow: hidden;
  border: 2px solid #0f172a;
  border-radius: 24%;
  background:
    linear-gradient(90deg, #2563eb 0 42%, #f8fafc 42% 58%, #ef4444 58%),
    #f8fafc;
}

body[data-page="traffic-escape"] .te-police-fallback::before {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 23%;
  height: 19%;
  border-radius: 18%;
  background: #13223a;
}

body[data-page="traffic-escape"] .te-police-fallback i {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 45%;
  height: 9%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8 0 45%, #f8fafc 45% 55%, #fb7185 55%);
  box-shadow: 0 0 9px rgba(96, 165, 250, .9);
  animation: tePoliceLights .7s steps(2, end) infinite;
}

body[data-page="traffic-escape"] .te-police .te-vehicle-png {
  width: auto;
  height: 100%;
  max-width: none !important;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center;
}

@keyframes tePoliceLights {
  50% { filter: hue-rotate(160deg) brightness(1.35); }
}

body[data-page="traffic-escape"] .te-police.crashed-into {
  animation: tePoliceHit .32s ease;
}

@keyframes tePoliceHit {
  40% { filter: brightness(1.75) drop-shadow(0 0 14px #60a5fa); }
}

body[data-page="traffic-escape"] .te-car.crashing {
  z-index: 22;
  animation-name: teCrashContact;
  animation-timing-function: cubic-bezier(.35,.05,.22,1);
  animation-fill-mode: both;
}

@keyframes teCrashContact {
  0% { transform: translate(0, 0); }
  43% { transform: translate(var(--bx, 0), var(--by, 0)); }
  50% { transform: translate(var(--bx, 0), var(--by, 0)) scale(.985); }
  72% { transform: translate(calc(var(--bx, 0) * .36), calc(var(--by, 0) * .36)); }
  88% { transform: translate(calc(var(--bx, 0) * .08), calc(var(--by, 0) * .08)); }
  100% { transform: translate(0, 0); }
}

body[data-page="traffic-escape"] .te-float.wait {
  color: #bfdbfe;
  text-shadow: 0 2px 8px rgba(0,0,0,.65), 0 0 18px rgba(59,130,246,.9);
}

body[data-page="traffic-escape"] .te-car.reversing .te-car-art {
  filter:
    drop-shadow(0 3px 6px rgba(0,0,0,.42))
    drop-shadow(0 0 5px rgba(248,113,113,.5));
}

body[data-page="traffic-escape"] #te-stage:fullscreen .te-card,
body[data-page="traffic-escape"] #te-stage.te-fs .te-card {
  width: min(92vw, calc(100vh - 132px));
  max-width: var(--te-shell-width);
  flex: 0 0 auto;
}

body[data-page="traffic-escape"] #te-stage:fullscreen .te-board,
body[data-page="traffic-escape"] #te-stage.te-fs .te-board {
  width: var(--te-grid-size, 96%);
  max-width: none;
}

@supports (height: 100dvh) {
  body[data-page="traffic-escape"] #te-stage:fullscreen .te-card,
  body[data-page="traffic-escape"] #te-stage.te-fs .te-card {
    width: min(92vw, calc(100dvh - 132px));
  }
}

@media (max-width: 520px) {
  body[data-page="traffic-escape"] .te-play {
    --te-shell-width: 100%;
  }

  body[data-page="traffic-escape"] .te-control-hint {
    padding: 0 .4rem;
    font-size: .7rem;
  }

  body[data-page="traffic-escape"] .te-board[data-n="11"],
  body[data-page="traffic-escape"] .te-board[data-n="12"] {
    gap: 3px;
  }

  body[data-page="traffic-escape"] .te-car-fallback {
    border-width: 1px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body[data-page="traffic-escape"] .te-police-fallback i {
    animation: none;
  }

  body[data-page="traffic-escape"] .te-car.crashing,
  body[data-page="traffic-escape"] .te-wall.crashed-into,
  body[data-page="traffic-escape"] .te-police.crashed-into {
    animation-duration: .12s !important;
  }
}
