*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background: #0a1530;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 486px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 calc(12px + env(safe-area-inset-right))
    calc(20px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
  background: #0a1530 url("../images/bg.webp") center top / 100% auto no-repeat;
  background-size: cover;
}

/* Carousel: native scroll-snap, full-bleed within the page column */
.carousel {
  position: relative;
  width: calc(
    100% + 24px + env(safe-area-inset-left) + env(safe-area-inset-right)
  );
  margin: 0 calc(-12px - env(safe-area-inset-right)) 0
    calc(-12px - env(safe-area-inset-left));
}

.carousel__track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  touch-action: pan-y pinch-zoom; /* JS handles horizontal swipes */
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

@media (pointer: fine) {
  .carousel__track {
    cursor: grab;
  }
}

.carousel__track.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
  scroll-behavior: auto;
  user-select: none;
}

.carousel__track::-webkit-scrollbar {
  display: none;
}

.carousel__track img {
  flex: 0 0 100%;
  width: 100%;
  scroll-snap-align: center;
}

.carousel__dots {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.carousel__dots button {
  width: 8px;
  height: 8px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition:
    width 0.25s,
    background 0.25s;
}

.carousel__dots button[aria-current="true"] {
  width: 22px;
  border-radius: 4px;
  background: #f3c86a;
}

/* Action buttons: 2 per row */
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  width: 100%;
  list-style: none;
}

.actions li {
  flex: 1 1 calc(50% - 5px);
}

.actions a {
  display: block;
  transition:
    transform 0.2s ease,
    filter 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.actions a:hover,
.actions a:focus-visible {
  transform: scale(1.03);
  filter: brightness(1.12);
}

.actions a:active {
  transform: scale(0.97);
}

.actions img {
  width: 100%;
}

.footer {
  width: 100%;
  /* margin-top: auto; */
}

/* Tall phones (taller than 9:18, e.g. iPhone X and newer) */
@media (max-aspect-ratio: 9/18) {
  .footer {
    margin-bottom: 15%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .carousel__track {
    scroll-behavior: auto;
  }
  .actions a {
    transition: none;
  }
}

/* ===== Route picker modal =====
   Everything scales from --w (modal width) against the 1403px-wide artwork,
   so 1 design px = var(--u). */
.routes {
  --w: min(94vw, 600px);
  --u: calc(var(--w) / 1403);
  width: var(--w);
  max-width: none;
  max-height: 94vh;
  max-height: 94dvh;
  margin: auto;
  padding: calc(300 * var(--u)) calc(70 * var(--u)) calc(30 * var(--u));
  border: 0 solid transparent;
  /* Frame artwork: header/footer slices stay fixed, middle stretches
     so the modal grows with any number of routes. */
  border-image: url("../images/modal/modal-bg.webp") 300 50 165 50 fill /
    calc(300 * var(--u)) calc(50 * var(--u)) calc(165 * var(--u)) stretch;
  background: none;
  overflow: visible;
}

.routes::backdrop {
  background: rgba(3, 8, 20, 0.7);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Invisible hit area over the X drawn in the artwork */
.routes__close {
  position: absolute;
  top: calc(55 * var(--u));
  right: calc(62 * var(--u));
  width: calc(80 * var(--u));
  height: calc(80 * var(--u));
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.routes__list {
  display: flex;
  flex-direction: column;
  gap: calc(22 * var(--u));
  max-height: calc(94dvh - 480 * var(--u));
  overflow-y: auto;
  list-style: none;
}

.route {
  display: flex;
  align-items: center;
  aspect-ratio: 1044 / 96;
  background: url("../images/modal/row-normal.png") center / 100% 100% no-repeat;
  color: #fff;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    filter 0.15s,
    transform 0.15s;
}

.route.is-best {
  background-image: url("../images/modal/row-best.png");
}

.route:hover,
.route:focus-visible {
  filter: brightness(1.12);
}
.route:active {
  transform: scale(0.98);
}

.route__ms {
  flex: 0 0 13%;
  margin-left: 10.5%;
  font-size: calc(36 * var(--u));
  white-space: nowrap;
}

.route__url {
  flex: 0 0 41%;
  margin-left: 9.5%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Left-aligned so every domain starts on the same line, with an inset
     that keeps the group visually centred in its column. */
  text-align: left;
  padding-left: calc(140 * var(--u));
  box-sizing: border-box;
  font-family: "Libre Baskerville", "Times New Roman", serif;
  font-weight: 500;
  font-size: calc(54 * var(--u));
  letter-spacing: 0.02em;
  color: #f5ecd9;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.route.is-best .route__ms {
  flex-basis: 12%;
}
/* Make up the 1% the narrower ms column gives away so URLs stay aligned */
.route.is-best .route__url {
  margin-left: 10.5%;
}

.routes__foot {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: calc(40 * var(--u));
  height: calc(120 * var(--u));
  margin-top: calc(40 * var(--u));
}

.routes__foot button,
.routes__foot a {
  display: block;
  border: 0;
  background: none;
  cursor: pointer;
}

.routes__retest img {
  width: calc(190 * var(--u));
}
.routes__service img {
  width: calc(560 * var(--u));
}

.routes__foot hr {
  width: 1px;
  height: calc(50 * var(--u));
  border: 0;
  background: rgba(217, 169, 78, 0.6);
}

/* Open / close animation */
.routes[open] {
  animation: routes-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.routes[open]::backdrop {
  animation: routes-fade 0.28s ease;
}
.routes.is-closing {
  animation: routes-out 0.2s ease-in forwards;
}
.routes.is-closing::backdrop {
  animation: routes-fade 0.2s ease-in reverse forwards;
}
@keyframes routes-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
}
@keyframes routes-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
}
@keyframes routes-fade {
  from {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .routes[open],
  .routes[open]::backdrop {
    animation: none;
  }
}
