/* -----------------------------------------------
  EVENTS

  The events carousel and the pixel-art bike scene
  that rides along the top of it.
------------------------------------------------ */

.events-section {
  /* Pixel-art sizes for the bike sprite and scenery strip */
  --pixel-art-size: 64px;
  --scenery-width: 1920px;
  --scenery-height: 128px;
}

/* On phones, the pixel art is drawn at 75% size */
@media (max-width: 575.98px) {
  .events-section {
    --pixel-art-size: 48px;
    --scenery-width: 1440px;
    --scenery-height: 96px;
  }
}

/* -----------------------------------------------
  CAROUSEL
------------------------------------------------ */

/* Each slide takes 2.4s, the same length as the bike's pedal
   animation (0.6s x 4). Bootstrap reads this duration and
   waits for it before finishing the slide. */
.events-carousel .carousel-item {
  transition-duration: 2.4s;
}

/* Every slide is exactly the height of the space below the bike
   scene, so the section stays the same size from event to event.
   The padding matches the other sections. */
.event-slide {
  height: calc(100svh - var(--nav-height) - var(--scenery-height));
  padding-block: 3rem;
}

/* On phones, where everything is stacked, a long event scrolls
   as a whole: title, image, and text together. */
@media (max-width: 767.98px) {
  .event-slide {
    overflow-y: auto;
  }
}

/* Previous/next arrows: narrow strips at the edges with solid
   white triangles. The width matches the icon size so the icon
   doesn't stick out past the edge of the screen. */
.events-carousel .carousel-control-prev,
.events-carousel .carousel-control-next {
  width: 4.5rem;
  opacity: 1;
  font-size: 4.5rem;
}

/* -----------------------------------------------
  EVENT SLIDE CONTENT

  Laid out with named grid areas:
  - Phones: title, image, and text stacked. The layout
    is at least as tall as the slide, so short events
    are centered, and long events make the whole slide
    scroll.
  - Wider screens: image on the left, text on the right
    (the title moves into the text column). The layout
    is exactly as tall as the slide, and only the
    details scroll, while the title and image stay in
    place.
------------------------------------------------ */

.event-layout {
  display: grid;
  grid-template-areas:
    "title"
    "image"
    "text";
  align-content: center;
  gap: 1.5rem;
  min-height: 100%;
}

/* The text row is sized minmax(0, auto). When there's room, it
   grows to fit all the text. When there isn't, it only gets the
   space that's left and the details scroll. */
@media (min-width: 768px) {
  .event-layout {
    grid-template-areas: "image text";
    grid-template-columns: 5fr 7fr;
    grid-template-rows: minmax(0, auto);
    height: 100%;
  }

  /* The side padding keeps the scrollbar from sitting right
     against the text */
  .event-details {
    overflow-y: auto;
    padding-inline: 1rem;
  }
}

@media (min-width: 992px) {
  .event-layout {
    grid-template-columns: 4fr 8fr;
  }
}

.event-layout > .event-title {
  grid-area: title;
}

.event-title {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
}

.event-image {
  grid-area: image;
  align-self: center;
  max-width: 100%;
  max-height: 45vh;
  margin: 0 auto;
  object-fit: contain;
}

@media (max-width: 767.98px) {
  .event-image {
    max-height: 30vh;
  }
}

/* The text column fills its grid row. Its title keeps its size,
   and on wider screens the details shrink to fit the rest of the
   space. Short text is centered next to the image. */
.event-text {
  grid-area: text;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.5rem;
  min-height: 0;
}

.event-details {
  min-height: 0;
  font-size: clamp(1rem, 1.5vw, 1.15rem);
}

.event-details ol,
.event-details ul {
  text-align: left;
}

/* -----------------------------------------------
  BIKE SCENE

  Three stacked layers: the sky, the scenery, and
  the bike sprite on top. bike-scene.js switches
  these classes on the .bike-scene element:

  - is-idle / is-pedaling: which bike animation plays
  - facing-forward / facing-backward: which way the bike
    faces and which way the background scrolls

  The background only moves while the bike is pedaling.
------------------------------------------------ */

.bike-scene {
  position: relative;
  flex: none;
  height: var(--scenery-height);
  overflow: hidden;
}

.scene-layer {
  /* Where the background starts when its animation begins.
     bike-scene.js updates this before every ride so the
     scenery picks up from where it stopped. */
  --bg-start-x: 0px;

  position: absolute;
  inset: 0;
  background-repeat: repeat-x;
  background-position: var(--bg-start-x) top;
  background-size: var(--scenery-width) var(--scenery-height);
  image-rendering: pixelated;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  animation-play-state: paused;
}

.sky-layer {
  background-image: url("../assets/animation/sky.png");
  animation-duration: 80s;
}

.scenery-layer {
  background-image: url("../assets/animation/scenery.png");
  animation-duration: 20s;
}

.bike-scene.facing-forward .scene-layer {
  animation-name: scroll-forward;
}

.bike-scene.facing-backward .scene-layer {
  animation-name: scroll-backward;
}

.bike-scene.is-pedaling .scene-layer {
  animation-play-state: running;
}

/* The sprite sheets are a row of square frames. The animations
   step through the frames by sliding the background left. */
.bike-sprite {
  position: absolute;
  bottom: 4px;
  left: calc(50% - var(--pixel-art-size) / 2);
  width: var(--pixel-art-size);
  height: var(--pixel-art-size);
  background-repeat: no-repeat;
  background-size: auto var(--pixel-art-size);
  image-rendering: pixelated;
}

.bike-scene.facing-backward .bike-sprite {
  transform: scaleX(-1);
}

/* Idle: 4 frames, looping */
.bike-scene.is-idle .bike-sprite {
  background-image: url("../assets/animation/bike-idle-red.png");
  animation: bike-idle 1.2s steps(4) infinite;
}

/* Pedaling: 16 frames, played 4 times (2.4s total) */
.bike-scene.is-pedaling .bike-sprite {
  background-image: url("../assets/animation/bike-pedal-red.png");
  animation: bike-pedal 0.6s steps(16) 4;
}

@keyframes bike-idle {
  from {
    background-position: 0 0;
  }
  to {
    background-position: calc(-4 * var(--pixel-art-size)) 0;
  }
}

@keyframes bike-pedal {
  from {
    background-position: 0 0;
  }
  to {
    background-position: calc(-16 * var(--pixel-art-size)) 0;
  }
}

/* Each loop moves the background by exactly one image width,
   so the repeating image lines up seamlessly. */
@keyframes scroll-forward {
  from {
    background-position: var(--bg-start-x) top;
  }
  to {
    background-position: calc(var(--bg-start-x) - var(--scenery-width)) top;
  }
}

@keyframes scroll-backward {
  from {
    background-position: var(--bg-start-x) top;
  }
  to {
    background-position: calc(var(--bg-start-x) + var(--scenery-width)) top;
  }
}
