/* ==========================================================================
   Memmy World — breakpoints, RTL touch-ups, reduced motion
   ========================================================================== */

/* Tablet landscape: the acts get tighter before they stack. */
@media (max-width: 1120px) {
  /* Below this width the 108px rail gutter costs more than the hover labels are
     worth, so the rail stays a slim column of numbers and the gutter shrinks. */
  :root {
    --rail-gutter: 64px;
  }

  /* The gutter is now narrower than the rail's *expanded* width, so expanding it
     on hover or focus would slide the panel over the kicker, headline and blurb
     of the act behind it. Numbers only at this size: each act's own
     "Chapitre 05 · Flora" kicker already names the chapter. */
  .rail__label,
  .rail:hover .rail__label,
  .rail:focus-within .rail__label,
  .rail__chip:focus-visible .rail__label {
    max-width: 0;
    opacity: 0;
  }

  .rail:hover,
  .rail:focus-within {
    box-shadow: none;
  }

  .act[data-act]:not(.act--intro):not(.act--finale) {
    height: 260vh;
  }

  .act--intro {
    height: 150vh;
  }

  .act__content {
    width: min(88%, 640px);
  }

  .stories {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .finale__grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Four stories on a desktop shelf: keep them on one row. Two rows of cards are
   taller than the sticky stage on a short laptop window, which used to push the
   last stories under the bottom edge where nobody could reach them. */
@media (min-width: 1100px) {
  .stories[data-count='4'] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(7px, 0.85vw, 13px);
  }

  .stories[data-count='4'] .story__title {
    font-size: 0.86rem;
  }

  .stories[data-count='4'] .story__cta {
    font-size: 0.6rem;
    letter-spacing: 0.07em;
  }
}

/* Laptop widths (861–1099px): the portrait still takes a column, so four cards
   on one row are only ~150px wide. They become cover-led tiles — the science
   teaser lives in the story sheet at this size — which keeps every title
   readable and the whole shelf inside the pinned stage. */
@media (min-width: 861px) and (max-width: 1099px) {
  .stories[data-count='4'] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  /* A square cover inside a ~130px card leaves the body too short: a two-line
     title pushed the "open the story" line under the card's clipped bottom edge.
     A shallow cover keeps both title lines and the CTA inside the card. */
  .stories[data-count='4'] .story__cover {
    aspect-ratio: 16 / 10;
  }

  .stories[data-count='4'] .story__title {
    font-size: 0.76rem;
  }

  .stories[data-count='4'] .story__body {
    padding: 8px 8px 9px;
  }

  /* "OUVRIR L'HISTOIRE" is wider than a ~110px card, so it used to break in two
     and push the card past the stage's bottom edge. One line, no arrow: the whole
     card is the button, the arrow is decoration we cannot afford at this width. */
  .stories[data-count='4'] .story__cta {
    padding-top: 5px;
    font-size: 0.52rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
  }

  .stories[data-count='4'] .story__cta svg {
    display: none;
  }
}

/* Portrait tablets and phones: one column, the portrait above the copy. */
@media (max-width: 860px) {
  :root {
    --shell: clamp(14px, 4.4vw, 26px);
    /* The rail moves to the bottom of the screen, so the copy gets the full
       width back. */
    --rail-gutter: 0px;
  }

  .act[data-act]:not(.act--intro):not(.act--finale) {
    height: 230vh;
  }

  .act--intro {
    height: 130vh;
  }

  .stage {
    padding: calc(var(--topbar-h) + 8px) var(--shell) 16px;
    overflow: hidden;
  }

  .act__inner {
    height: 100%;
  }

  /* One column on a phone: the copy owns the width, and the film's mascot sits
     behind it as the backdrop it is. */
  .act__content,
  .act[data-side='end'] .act__content {
    width: 100%;
    margin-inline: 0;
  }

  .act__character {
    width: clamp(64px, 17vw, 84px);
  }

  .act__stage-hint {
    display: none;
  }

  /* The desktop wash is a *horizontal* gradient: it darkens one column, the
     side the mascot is not on. A phone has no such column — the copy runs the
     full width — so that gradient left the tail of every line sitting on the
     raw film, and the blurb and the tags went grey over the bright bee beat.
     Darken the band the copy occupies instead, and let the film breathe again
     under the story cards. */
  .act__wash::before,
  .act[data-side='end'] .act__wash::before {
    background:
      linear-gradient(
        to bottom,
        rgba(7, 5, 11, 0.86) 0%,
        rgba(7, 5, 11, 0.74) 34%,
        rgba(7, 5, 11, 0.52) 56%,
        rgba(7, 5, 11, 0.22) 76%,
        rgba(7, 5, 11, 0.04) 92%,
        transparent 100%
      );
  }

  .stories {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 9px;
  }

  .story__cta {
    font-size: 0.6rem;
  }

  .rail {
    inset-inline-start: 50%;
    top: auto;
    bottom: 8px;
    transform: translateX(-50%);
    flex-direction: row;
    gap: 4px;
    padding: 5px;
    max-height: none;
    max-width: calc(100vw - 20px);
    overflow-x: auto;
  }

  [dir='rtl'] .rail {
    transform: translateX(50%);
  }

  .rail__label,
  .rail:hover .rail__label,
  .rail__chip.is-active .rail__label {
    display: none;
  }

  .rail__num {
    min-width: 22px;
    height: 22px;
  }

  .act--finale {
    padding-top: calc(var(--topbar-h) + 24px);
  }

  .packs {
    grid-template-columns: minmax(0, 1fr);
    max-width: none;
  }

  /* `justify-items: start` sized the control column to its max-content width, so
     the deep-link line — one long, unbreakable-looking URL — pushed the whole
     column past the panel's edge instead of wrapping inside it. The column now
     fills the grid; only the QR card stays start-aligned. */
  .qr-panel__body {
    grid-template-columns: minmax(0, 1fr);
    justify-items: stretch;
  }

  .qr-panel__frame {
    width: min(190px, 58vw);
    justify-self: start;
  }

  .finale__cta {
    align-items: stretch;
  }

  .modal__panel {
    grid-template-columns: minmax(0, 1fr);
    max-height: min(90vh, 780px);
  }

  .modal__media {
    min-height: 0;
    aspect-ratio: 16 / 9;
  }

  .modal__media img {
    object-position: 50% 32%;
  }

  .modal__body {
    padding: 18px 18px 22px;
  }

  .site-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Phones */
@media (max-width: 560px) {
  .topbar__actions {
    gap: 6px;
  }

  .ambient-toggle {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
  }

  .lang__btn {
    padding-inline: 8px;
  }

  #topbar-cta {
    padding: 8px 11px;
    font-size: 0.76rem;
  }

  .act[data-act]:not(.act--intro):not(.act--finale) {
    height: 210vh;
  }

  .intro__title {
    font-size: clamp(1.95rem, 9.4vw, 2.9rem);
    max-width: 100%;
  }

  .intro__sub {
    font-size: 0.9rem;
  }

  .intro__chip {
    font-size: 0.74rem;
    padding: 7px 13px 7px 10px;
  }

  .scroll-hint {
    font-size: 0.62rem;
  }

  .act__title {
    font-size: clamp(1.4rem, 6.6vw, 1.8rem);
  }

  /* Two lines, not three: on a 390×844 phone the act's stack (portrait, kicker,
     title, blurb, tags, two rows of cards) is taller than the pinned stage, and
     the third story ended up half-clipped under the bottom chapter rail. */
  .act__blurb {
    font-size: 0.8rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }

  /* Clearance for the rail, which is pinned to the bottom of the screen at this
     width — the last row of cards used to run under it. */
  .act__inner {
    gap: 8px;
    padding-bottom: 44px;
  }

  .act__character {
    width: clamp(58px, 15vw, 72px);
  }

  .act__glow {
    font-size: 0.58rem;
    letter-spacing: 0.1em;
  }

  .stories {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 2px;
  }

  .story__title {
    font-size: 0.78rem;
  }

  /* A 4/3 cover made each card ~30px taller than the shelf could afford; the
     cover is a thumbnail on a phone, the story sheet is where it gets read. */
  .story__cover {
    aspect-ratio: 16 / 10;
  }

  .story__body {
    padding: 8px 9px 9px;
  }

  .story__cta {
    padding-top: 5px;
    font-size: 0.56rem;
    letter-spacing: 0.04em;
  }

  .story__cta svg {
    width: 11px;
    height: 11px;
  }

  .act__meta {
    gap: 6px;
  }

  .act__tag {
    padding: 4px 10px;
    font-size: 0.62rem;
  }

  /* The featured single-story card stacks on a phone: at 390px a side-by-side
     split would shrink the cover to a stamp. */
  .stories:has(.story:only-child) {
    max-width: none;
  }

  .stories:has(.story:only-child) .story {
    flex-direction: column;
    min-height: 0;
  }

  .stories:has(.story:only-child) .story__cover {
    flex: none;
    aspect-ratio: 16 / 10;
  }

  .stories:has(.story:only-child) .story__body {
    padding: 8px 9px 9px;
  }

  .stories:has(.story:only-child) .story__title {
    font-size: 0.78rem;
  }

  .calendar__item b {
    font-size: 0.66rem;
  }

  .finale__title,
  .finale__cta h3 {
    font-size: 1.5rem;
  }

  .qr-panel {
    padding: 16px;
  }

  .store-badge--play {
    width: 158px;
  }

  .store-badge--apple {
    width: 150px;
  }
}

/* Short desktop windows (laptops, split screens): scale the type down with the
   height so the hero stack and a character act both fit without clipping. */
@media (min-width: 861px) and (max-height: 780px) {
  .stage--intro {
    gap: clamp(8px, 1.4vh, 14px);
  }

  .intro__title {
    font-size: clamp(1.9rem, 7.2vh, 3.5rem);
    max-width: 18ch;
  }

  .intro__sub {
    font-size: 0.94rem;
    max-width: 44ch;
  }

  .intro__chip {
    padding: 7px 13px 7px 10px;
    font-size: 0.76rem;
  }

  .scroll-hint {
    margin-top: 6px;
    font-size: 0.64rem;
  }

  .act__title {
    font-size: clamp(1.45rem, 4.8vh, 2.5rem);
  }

  .act__blurb {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    font-size: 0.88rem;
  }

  .story__cover {
    aspect-ratio: 16 / 9;
  }

  .story__body {
    padding: 9px 11px 10px;
  }

  /* The pinned stage is only as tall as the window: trim the stack so the whole
     shelf (four cards on one row) fits inside it instead of being clipped by a
     few dozen pixels and needing an inner scroll. */
  .act__content {
    gap: 8px;
  }

  .act__blurb {
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  .stories {
    margin-top: 2px;
  }

  .act__character {
    width: clamp(64px, 7.6vw, 96px);
  }

  .act__meta {
    gap: 6px;
  }
}

/* Arabic sets taller line boxes than Latin at the same size (Noto Naskh carries
   a deep descender), so on a 900×600 laptop window the hero stack grew ~40px and
   pushed the scroll hint under the stage's clipped bottom edge — the wheel was
   cut in half. The Arabic hero is a touch smaller and tighter at that height. */
@media (min-width: 861px) and (max-height: 780px) {
  [dir='rtl'] .intro__title {
    font-size: clamp(1.7rem, 6.1vh, 2.95rem);
    line-height: 1.26;
  }

  [dir='rtl'] .intro__kicker,
  [dir='rtl'] .intro__chip {
    font-size: 0.72rem;
  }

  [dir='rtl'] .intro__sub {
    font-size: 0.88rem;
    max-width: 40ch;
  }

  [dir='rtl'] .scroll-hint {
    margin-top: 4px;
    font-size: 0.6rem;
  }
}

/* ---------------------------------------------------------------- RTL ---- */
[dir='rtl'] .film__grain {
  animation-direction: reverse;
}

[dir='rtl'] .brand,
[dir='rtl'] .topbar,
[dir='rtl'] .site-footer {
  direction: rtl;
}

/* ------------------------------------------------------- reduced motion -- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .film__grain,
  .act__halo,
  .act__portrait img,
  .intro__chip-dot,
  .scroll-hint__wheel::after {
    animation: none !important;
  }

  .act__lantern {
    display: none;
  }

  .act__inner,
  .story {
    transform: none !important;
  }
}
