.traffic-page {
  --road: #30343b;
  --road-dark: #24272e;
  --paint: rgba(255, 255, 255, 0.62);
  --curb: #f6c945;
  --success: #0f9f6e;
  --danger: #dc2626;
  --traffic-line: rgba(16, 19, 26, 0.12);
}

.traffic-layout {
  display: grid;
  gap: 1rem;
  padding: 1rem 0 4rem;
}

.traffic-titlebar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.traffic-titlebar h1 {
  font-size: clamp(2.3rem, 5vw, 5rem);
}

.traffic-game {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.traffic-toolbar,
.traffic-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem;
  border-bottom: 1px solid var(--line);
}

.traffic-toolbar {
  background:
    linear-gradient(90deg, rgba(246, 201, 69, 0.16), transparent 34%),
    linear-gradient(270deg, rgba(13, 148, 136, 0.12), transparent 28%),
    #ffffff;
}

.traffic-actions,
.level-tabs,
.overlay-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.level-tab,
.traffic-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.78rem;
  color: var(--text);
  background: #ffffff;
  font-weight: 850;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.level-tab:hover,
.level-tab:focus-visible,
.traffic-button:hover,
.traffic-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(13, 148, 136, 0.45);
  background: #f3fffc;
}

.level-tab.is-active,
.traffic-button.primary {
  color: #ffffff;
  border-color: #10131a;
  background: #10131a;
}

.traffic-hud {
  flex-wrap: wrap;
  background: #f9fafb;
}

.traffic-stat {
  display: grid;
  gap: 0.1rem;
  min-width: 112px;
}

.traffic-stat span,
.panel-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.traffic-stat strong,
.panel-heading strong {
  color: var(--text);
  font-size: 1rem;
}

.traffic-status {
  flex: 1 1 220px;
  min-height: 1.5rem;
  margin: 0;
  color: var(--muted);
  font-weight: 750;
  text-align: right;
}

.traffic-status.is-good {
  color: var(--success);
}

.traffic-status.is-alert {
  color: var(--danger);
}

.traffic-stage {
  display: grid;
  grid-template-columns: minmax(220px, 0.32fr) minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  background:
    linear-gradient(135deg, rgba(50, 105, 216, 0.08), transparent 20rem),
    linear-gradient(315deg, rgba(232, 72, 122, 0.08), transparent 18rem),
    #eef3f7;
}

.traffic-side {
  display: grid;
  align-content: start;
  gap: 1rem;
}

.traffic-panel {
  border: 1px solid rgba(16, 19, 26, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 20px rgba(26, 31, 44, 0.08);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 48px;
  padding: 0.75rem;
  border-bottom: 1px solid rgba(16, 19, 26, 0.08);
}

.passenger-queue {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  gap: 0.5rem;
  min-height: 152px;
  padding: 0.75rem;
}

.passenger,
.passenger-more {
  display: grid;
  place-items: center;
  min-height: 38px;
  border-radius: 8px;
}

.passenger {
  position: relative;
  background: var(--piece);
  box-shadow:
    inset 0 -6px 0 rgba(0, 0, 0, 0.12),
    0 6px 10px rgba(26, 31, 44, 0.12);
}

.passenger::before {
  content: "";
  width: 13px;
  height: 13px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 14px 0 2px rgba(255, 255, 255, 0.8);
}

.passenger-more {
  color: var(--muted);
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.68);
  font-weight: 850;
}

.bay-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  padding: 0.75rem;
}

.bay-slot {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 72px;
  overflow: hidden;
  border: 2px dashed rgba(16, 19, 26, 0.2);
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      45deg,
      rgba(16, 19, 26, 0.04) 0,
      rgba(16, 19, 26, 0.04) 8px,
      transparent 8px,
      transparent 16px
    ),
    rgba(255, 255, 255, 0.58);
}

.bay-bus {
  position: relative;
  width: min(78px, 88%);
  height: 42px;
  border-radius: 8px;
  background: var(--piece);
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.16);
}

.bay-bus::before,
.bay-bus::after {
  content: "";
  position: absolute;
  bottom: -5px;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  background: #10131a;
}

.bay-bus::before {
  left: 12px;
}

.bay-bus::after {
  right: 12px;
}

.bay-window {
  position: absolute;
  top: 9px;
  left: 13px;
  width: 42px;
  height: 13px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.76);
}

.board-area {
  position: relative;
  min-width: 0;
}

.traffic-grid {
  --cols: 6;
  --rows: 6;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: clamp(4px, 0.8vw, 8px);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  aspect-ratio: var(--cols) / var(--rows);
  min-height: 390px;
  overflow: hidden;
  border: 10px solid var(--curb);
  border-radius: 8px;
  padding: clamp(0.45rem, 1.1vw, 0.8rem);
  background:
    linear-gradient(90deg, transparent 48%, rgba(255, 255, 255, 0.18) 48%, rgba(255, 255, 255, 0.18) 52%, transparent 52%),
    linear-gradient(0deg, transparent 48%, rgba(255, 255, 255, 0.15) 48%, rgba(255, 255, 255, 0.15) 52%, transparent 52%),
    linear-gradient(135deg, var(--road), var(--road-dark));
  box-shadow:
    inset 0 0 0 2px rgba(16, 19, 26, 0.16),
    0 16px 28px rgba(26, 31, 44, 0.18);
}

.traffic-cell {
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent),
    rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.traffic-cell::after {
  content: "";
  display: block;
  width: 46%;
  height: 4px;
  margin: 50% auto 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.traffic-blocker {
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid rgba(16, 19, 26, 0.2);
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      -45deg,
      #f6c945 0,
      #f6c945 10px,
      #10131a 10px,
      #10131a 20px
    );
  box-shadow: 0 10px 18px rgba(16, 19, 26, 0.18);
}

.bus {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--piece);
  box-shadow:
    inset 0 -10px 0 rgba(0, 0, 0, 0.16),
    0 10px 18px rgba(16, 19, 26, 0.2);
  cursor: pointer;
  transition:
    transform 140ms ease,
    filter 140ms ease,
    box-shadow 140ms ease;
}

.bus:hover,
.bus:focus-visible {
  transform: translateY(-2px);
  filter: saturate(1.08);
  box-shadow:
    inset 0 -10px 0 rgba(0, 0, 0, 0.16),
    0 14px 24px rgba(16, 19, 26, 0.26);
}

.bus.is-blocked {
  animation: traffic-shake 260ms ease;
}

.bus-window {
  position: absolute;
  top: 16%;
  left: 18%;
  width: 50%;
  height: 24%;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 18px 0 0 -2px rgba(255, 255, 255, 0.5);
}

.bus-wheels {
  position: absolute;
  inset: auto 14% -5px;
  display: flex;
  justify-content: space-between;
}

.bus-wheels::before,
.bus-wheels::after {
  content: "";
  width: clamp(10px, 2vw, 16px);
  height: clamp(10px, 2vw, 16px);
  border-radius: 999px;
  background: #10131a;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.16);
}

.bus-arrow {
  position: relative;
  z-index: 1;
  width: 0;
  height: 0;
  border-top: clamp(6px, 1.2vw, 9px) solid transparent;
  border-bottom: clamp(6px, 1.2vw, 9px) solid transparent;
  border-left: clamp(10px, 1.8vw, 15px) solid rgba(255, 255, 255, 0.94);
  filter: drop-shadow(0 1px 1px rgba(16, 19, 26, 0.25));
}

.bus[data-dir="up"] .bus-arrow {
  transform: rotate(-90deg);
}

.bus[data-dir="down"] .bus-arrow {
  transform: rotate(90deg);
}

.bus[data-dir="left"] .bus-arrow {
  transform: rotate(180deg);
}

.bus[data-dir="right"] .bus-arrow {
  transform: rotate(0deg);
}

.traffic-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  border-radius: 8px;
  background: rgba(16, 19, 26, 0.54);
  backdrop-filter: blur(8px);
}

.traffic-overlay[hidden] {
  display: none;
}

.traffic-dialog {
  width: min(420px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  padding: clamp(1rem, 3vw, 1.5rem);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 22px 44px rgba(16, 19, 26, 0.26);
}

.traffic-dialog h2 {
  font-size: clamp(1.7rem, 4vw, 2.4rem);
}

.traffic-dialog p:not(.eyebrow) {
  color: var(--muted);
}

.overlay-actions {
  margin-top: 1rem;
}

.color-red {
  --piece: #ef4444;
}

.color-blue {
  --piece: #3b82f6;
}

.color-yellow {
  --piece: #f59e0b;
}

.color-green {
  --piece: #22c55e;
}

.color-purple {
  --piece: #a855f7;
}

.color-orange {
  --piece: #f97316;
}

.color-teal {
  --piece: #14b8a6;
}

.color-pink {
  --piece: #ec4899;
}

@keyframes traffic-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  50% {
    transform: translateX(5px);
  }

  75% {
    transform: translateX(-3px);
  }
}

@media (max-width: 920px) {
  .traffic-stage {
    grid-template-columns: 1fr;
  }

  .traffic-side {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .traffic-grid {
    min-height: 0;
  }
}

@media (max-width: 680px) {
  .traffic-titlebar,
  .traffic-toolbar,
  .traffic-hud {
    align-items: flex-start;
    flex-direction: column;
  }

  .traffic-status {
    text-align: left;
  }

  .traffic-side {
    grid-template-columns: 1fr;
  }

  .passenger-queue {
    min-height: 112px;
  }
}

@media (max-width: 480px) {
  .traffic-stage {
    padding: 0.75rem;
  }

  .traffic-grid {
    border-width: 7px;
    gap: 3px;
    padding: 0.35rem;
  }

  .bay-row {
    grid-template-columns: 1fr;
  }
}
