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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  --bg: #fbfdff;
  --stage-pad-top: 1rem;
  --stage-pad-bottom: 5.5rem;
  --slide: min(calc(100dvh - 8.5rem), 50vw);
  --peek: calc((100vw - var(--slide)) / 2);
  --gap: 0.85rem;
  background: var(--bg);
  color: #222;
}

.stage {
  position: relative;
  display: flex;
  justify-content: center;
  height: 100dvh;
  overflow: hidden;
}

.slider {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--slide);
  gap: var(--gap);
  align-items: center;
  width: min(100%, calc(var(--slide) + var(--peek) * 2));
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  padding-inline: var(--peek);
  padding-top: var(--stage-pad-top);
  padding-bottom: var(--stage-pad-bottom);
}

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

.slider img {
  width: var(--slide);
  height: var(--slide);
  object-fit: contain;
  background: #fff;
  scroll-snap-align: center;
  box-shadow: 0 4px 12px rgb(0 0 0 / 28%);
  user-select: none;
  pointer-events: none;
  transform-origin: center center;
  animation: slide-focus linear both;
  animation-timeline: view(inline);
  animation-range: cover;
}

@keyframes slide-focus {
  0%,
  100% {
    opacity: 0.82;
    transform: scale(0.94);
  }

  45%,
  55% {
    opacity: 1;
    transform: scale(1);
  }
}

.edge-fade {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    to right,
    rgb(251 253 255 / 0.28) 0%,
    rgb(251 253 255 / 0) 4%,
    rgb(251 253 255 / 0) 96%,
    rgb(251 253 255 / 0.28) 100%
  );
}

.nav {
  position: fixed;
  top: calc(
    (100% + var(--stage-pad-top) - var(--stage-pad-bottom)) / 2
  );
  z-index: 2;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: 0;
  border-radius: 0.55rem;
  background: rgb(40 44 52 / 72%);
  color: #fff;
  cursor: pointer;
  transform: translateY(-50%);
  transition:
    background 160ms ease,
    opacity 160ms ease;
}

.nav:hover:not(:disabled) {
  background: rgb(40 44 52 / 88%);
}

.nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.nav-prev {
  left: 1rem;
}

.nav-next {
  right: 1rem;
}

.nav svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dots {
  position: fixed;
  bottom: 1.75rem;
  left: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  background: rgb(40 44 52 / 55%);
  color: #fff;
  transform: translateX(-50%);
}

.dots-label {
  font: 500 0.8rem/1 system-ui, sans-serif;
  letter-spacing: 0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  opacity: 0.92;
}

.dots-window {
  --dot: 0.55rem;
  --dot-gap: 0.8rem;
  --dots-shown: 7;

  width: calc(var(--dot) * var(--dots-shown) + var(--dot-gap) * (var(--dots-shown) - 1));
  overflow: hidden;
  -webkit-mask-image: linear-gradient(
    to right,
    transparent,
    #000 18%,
    #000 82%,
    transparent
  );
  mask-image: linear-gradient(
    to right,
    transparent,
    #000 18%,
    #000 82%,
    transparent
  );
}

.dots-track {
  display: flex;
  align-items: center;
  gap: var(--dot-gap);
  width: max-content;
  will-change: transform;
}

.dot {
  flex: 0 0 var(--dot);
  width: var(--dot);
  height: var(--dot);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 42%);
  cursor: pointer;
  transition: background 160ms ease;
}

.dot:hover {
  background: rgb(255 255 255 / 75%);
}

.dot.is-active {
  background: #fff;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 35%);
}

.controls {
  display: contents;
}

@media (max-width: 768px) and (orientation: portrait) {
  body {
    --stage-pad-top: 4.25rem;
    --stage-pad-bottom: 4.25rem;
    --slide: min(90vw, calc(100dvh - 9rem));
    --peek: 5vw;
    --gap: 0.6rem;
  }

  .controls {
    display: grid;
    position: fixed;
    top: calc(50% + var(--slide) / 2 + 1.75rem);
    right: 0;
    left: 0;
    z-index: 2;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    row-gap: 0.85rem;
    padding: 0 1.25rem;
  }

  .nav {
    position: static;
    top: auto;
    width: 2.6rem;
    height: 2.6rem;
    transform: none;
  }

  .nav-prev {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    left: auto;
    right: auto;
  }

  .nav-next {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    left: auto;
    right: auto;
  }

  .dots {
    grid-column: 1 / -1;
    grid-row: 2;
    position: static;
    bottom: auto;
    left: auto;
    transform: none;
    justify-self: center;
    gap: 0.7rem;
    padding: 0.55rem 0.95rem;
    width: min(100%, 16.5rem);
  }

  .dots-window {
    --dots-shown: 6;
    --dot-gap: 0.7rem;
    flex: 1;
    width: auto;
    max-width: none;
  }

  .edge-fade {
    background: linear-gradient(
      to right,
      rgb(251 253 255 / 0.22) 0%,
      rgb(251 253 255 / 0) 5%,
      rgb(251 253 255 / 0) 95%,
      rgb(251 253 255 / 0.22) 100%
    );
  }
}

@media (min-width: 769px) and (max-width: 1100px) and (orientation: portrait) {
  body {
    --slide: min(calc(100dvh - 8.5rem), 70vw);
    --peek: min(4.5rem, 10vw);
  }
}

@media (orientation: landscape) and (max-height: 720px) {
  body {
    --stage-pad-top: 0.75rem;
    --stage-pad-bottom: 4rem;
    --slide: min(calc(100dvh - 5.25rem), 58vw);
    --peek: 3.25rem;
    --gap: 0.65rem;
  }

  .controls {
    display: contents;
  }

  .nav {
    position: fixed;
    top: calc((100% + var(--stage-pad-top) - var(--stage-pad-bottom)) / 2);
    width: 2.6rem;
    height: 2.6rem;
    transform: translateY(-50%);
  }

  .nav-prev {
    grid-column: auto;
    grid-row: auto;
    justify-self: auto;
    left: 1rem;
    right: auto;
  }

  .nav-next {
    grid-column: auto;
    grid-row: auto;
    justify-self: auto;
    left: auto;
    right: 1rem;
  }

  .dots {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    grid-column: auto;
    grid-row: auto;
    justify-self: auto;
    transform: translateX(-50%);
    width: auto;
  }

  .dots-window {
    --dots-shown: 7;
    flex: initial;
    width: calc(var(--dot) * var(--dots-shown) + var(--dot-gap) * (var(--dots-shown) - 1));
  }
}

@media (prefers-reduced-motion: reduce) {
  .slider {
    scroll-behavior: auto;
  }

  .slider img {
    animation: none;
  }
}
