/*
  Pampu Phase 4: photographic scroll-driven condo cinema (#condo-story).
  Wrapped in @layer pages. Every color comes from site.css @layer tokens.

  Default styles (scripts off, or prefers-reduced-motion: reduce) show the four plates as a
  calm static sequence with the #closing waitlist fully visible over the golden bokeh plate.
  The pinned, camera-driven cinema only switches on when cinema.js adds .cinema--interactive
  and the visitor has not asked for reduced motion. When a frame sequence is available,
  cinema.js adds .cinema--frames and a canvas fly-through replaces the first three plates.
*/
@layer pages {
  /* -------------------------------------------------------------------------
     Static sequence (default): facade, window, close-up, then the waitlist
  ------------------------------------------------------------------------- */
  .cinema {
    position: relative;
    padding-block: clamp(3rem, 7vw, 5.5rem);
    background:
      radial-gradient(80% 55% at 50% 88%, var(--cinema-bokeh), transparent 72%),
      linear-gradient(180deg, var(--cinema-sky-top), var(--cinema-sky-mid) 54%, var(--cinema-sky-top));
    color: #F5F0E8;
    /* The stage is always night, whatever the page theme: native scrollbars and controls follow suit */
    color-scheme: dark;
  }

  .cinema__sticky {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "p1"
      "p2"
      "p3"
      "finale";
    gap: clamp(1rem, 2.5vw, 1.5rem);
    inline-size: min(100% - 2 * var(--gutter), var(--page-max));
    margin-inline: auto;
  }

  @media (min-width: 56rem) {
    .cinema__sticky {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      grid-template-areas:
        "p1 p1"
        "p2 p3"
        "finale finale";
    }
  }

  /* The stage's children join the grid directly in the static sequence */
  .cinema__stage {
    display: contents;
  }

  .cinema__plate {
    position: relative;
    overflow: hidden;
    margin: 0;
    border: 1px solid var(--cinema-hud-brd);
    border-radius: var(--radius-card);
    background: var(--cinema-sky-mid);
    box-shadow: var(--shadow-card);
  }

  .cinema__plate--facade {
    grid-area: p1;
  }
  .cinema__plate--window {
    grid-area: p2;
  }
  .cinema__plate--closeup {
    grid-area: p3;
  }
  .cinema__plate--bokeh {
    grid-area: finale;
    z-index: 0;
  }

  .cinema__img {
    inline-size: 100%;
    block-size: auto;
    aspect-ratio: 1376 / 768;
    object-fit: cover;
  }

  .cinema__plate--bokeh .cinema__img {
    position: absolute;
    inset: 0;
    block-size: 100%;
    aspect-ratio: auto;
  }

  .cinema__frames,
  .cinema__bloom,
  .cinema__vignette,
  .cinema__grain {
    display: none;
  }

  .cinema__finale {
    position: relative;
    z-index: 1;
    grid-area: finale;
    display: grid;
    place-items: center;
    padding: clamp(1.25rem, 5vw, 3.5rem) clamp(0.75rem, 3vw, 2.5rem);
  }

  /* -------------------------------------------------------------------------
     Waitlist finale card: opaque surface card (.surface-card recipe).
     Glass is reserved for floating overlays; the form itself sits on a crisp
     opaque surface with a 1px hairline border and standard card radius.
  ------------------------------------------------------------------------- */
  .cinema__finale-card {
    position: relative;
    inline-size: min(100%, 40rem);
    margin-inline: auto;
    padding: clamp(1.5rem, 5vw, 2.5rem);
    /* The waitlist card follows the page theme, so its form controls and autofill match it */
    color-scheme: var(--page-scheme);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-card);
    background-color: var(--color-surface);
    background-image: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: var(--shadow-card);
    color: var(--color-text);
  }

  .cinema__finale-title {
    letter-spacing: var(--tracking-heading);
  }

  .cinema__finale-card .waitlist {
    max-inline-size: none;
    margin-block-start: 1.5rem;
  }

  /* A block-level eyebrow, so the gap to the title is exactly the title's margin */
  .cinema__finale-card .eyebrow {
    display: flex;
  }

  /* Frameless controls: soft filled surfaces in place of outlines, all on the 12px control radius and all spanning
     the card's full measure so their edges line up. Each keeps a 1px transparent border, which forced-colours
     mode paints and "more contrast" colours. */
  .cinema__finale-card .switch {
    display: grid;
    padding: 0.1875rem;
    border-color: transparent;
    border-radius: var(--radius-control);
    background: var(--field-fill);
  }

  .cinema__finale-card .switch::before {
    inset-block: 0.1875rem;
    inset-inline-start: 0.1875rem;
    inline-size: calc(50% - 0.1875rem);
    border-radius: calc(var(--radius-control) - 0.1875rem);
  }

  .cinema__finale-card .switch__option {
    border-radius: calc(var(--radius-control) - 0.1875rem);
  }

  .cinema__finale-card .field__input {
    min-block-size: 3.5rem;
    padding-inline: 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    background-color: var(--field-fill);
    background-image: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
    color: var(--color-text);
    font-size: 1.0625rem;
  }

  @media (prefers-reduced-motion: no-preference) {
    .cinema__finale-card .field__input {
      transition:
        box-shadow var(--dur-snap) var(--ease-snap),
        background-color var(--dur-snap) var(--ease-snap);
    }
  }

  .cinema__finale-card .field__input:focus-visible {
    border-color: transparent;
    background-color: var(--field-fill);
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
  }

  /* Errors: tinted fill plus an inset ring, beside the icon and message under the field */
  .cinema__finale-card .field__input:is(:user-invalid, .user-invalid-fallback, [aria-invalid="true"]) {
    border-width: 1px;
    border-color: transparent;
    background-color: color-mix(in oklab, var(--color-danger) 10%, var(--color-surface));
    box-shadow: inset 0 0 0 1.5px var(--color-danger);
  }

  /* Browser-autofilled values: an inset accent ring plus the field fill, so the state never relies on colour alone */
  .cinema__finale-card .field__input:autofill {
    border-color: transparent;
    box-shadow: inset 0 0 0 1.5px var(--color-accent), inset 0 0 0 100vmax var(--field-fill);
    -webkit-text-fill-color: var(--color-text);
  }

  .cinema__finale-card .field__input:autofill:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
  }

  /* The phone input lies unseen over its tiles in every state; the tiles carry the look (site.css) */
  .cinema__finale-card .phone-tiles.is-tiled .phone-tiles__input,
  .cinema__finale-card .phone-tiles.is-tiled .phone-tiles__input:is(:focus-visible, :autofill, :user-invalid, .user-invalid-fallback, [aria-invalid="true"]) {
    border-color: transparent;
    background-color: transparent;
    box-shadow: none;
    outline-color: transparent;
    -webkit-text-fill-color: transparent;
  }

  .cinema__finale-card .waitlist__submit {
    border-color: transparent;
  }

  /* Step 2 speaks the same language: filled chips and a filled secondary button */
  .cinema__finale-card .choice:not(:has(:checked)) {
    border-color: transparent;
    background: var(--field-fill);
  }

  .cinema__finale-card .choice:not(:has(:checked)):hover:not(:has(:disabled)) {
    background: color-mix(in oklab, var(--color-text) 12%, var(--color-surface));
  }

  .cinema__finale-card .field[data-invalid="true"] .choice {
    border-color: var(--color-danger);
  }

  .cinema__finale-card .button--quiet {
    border-color: transparent;
    background: var(--field-fill);
  }

  .cinema__finale-card .button--quiet:hover:not(:disabled) {
    background: color-mix(in oklab, var(--color-text) 12%, var(--color-surface));
  }

  @media (prefers-contrast: more) {
    .cinema__finale-card :is(.switch, .field__input, .choice, .button--quiet, .waitlist__status:not(:empty)) {
      border-color: var(--field-border);
    }
  }

  /* Narrow phones: a tighter card, so the ten tiles keep their width and the eyebrow stays on one line */
  @media (max-width: 26rem) {
    .cinema__finale {
      padding-inline: 0.5rem;
    }

    .cinema__finale-card {
      padding: 1.25rem 1.125rem;
    }

    .cinema__finale-card .eyebrow {
      gap: 0.5rem;
      letter-spacing: 0.08em;
    }
  }

  @media (max-width: 22.5rem) {
    .cinema__finale-card .eyebrow {
      font-size: 0.71875rem;
      letter-spacing: 0.04em;
    }

    .cinema__finale-card .eyebrow::before {
      display: none;
    }
  }

  .cinema__finale-card .waitlist__status:not(:empty) {
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    background: var(--field-fill);
    box-shadow: none;
    color: var(--color-text);
  }

  /* Step 2 follow-up: a 1px hairline divider inside the opaque card rather than a nested card */
  .cinema__finale-card .waitlist__followup {
    margin-block-start: 1.25rem;
    padding: 1.25rem 0 0;
    border: 0;
    border-block-start: 1px solid var(--color-hairline);
    border-radius: 0;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
  }

  /* -------------------------------------------------------------------------
     Skip link: floating overlay (.liquid-glass recipe), hidden until keyboard focus
  ------------------------------------------------------------------------- */
  .cinema__skip {
    position: absolute;
    inset-block-start: 1rem;
    inset-inline-start: 1rem;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    min-block-size: 2.75rem;
    padding-inline: 1.125rem;
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-filter);
    backdrop-filter: var(--glass-filter);
    box-shadow: inset 0 1px 0 var(--glass-edge), var(--glass-shadow);
    color: var(--color-text);
    font-size: var(--fs-small);
    font-weight: 800;
    text-decoration: none;
    /* Room for the whole focus ring when the browser scrolls the link into view */
    scroll-margin-block: 1.5rem;
  }

  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .cinema__skip {
      background: var(--color-canvas);
    }
  }

  @media (prefers-reduced-transparency: reduce) {
    .cinema__skip {
      background: var(--color-canvas);
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
    }
  }

  .cinema__skip:not(:focus, :focus-visible) {
    clip-path: inset(50%);
    overflow: hidden;
    inline-size: 1px;
    block-size: 1px;
    min-block-size: 0;
    margin: -1px;
    padding: 0;
    border: 0;
    white-space: nowrap;
  }

  .cinema__skip:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 3px;
  }

  /* -------------------------------------------------------------------------
     Pinned cinema (cinema.js + motion allowed). Only transform and opacity animate.
  ------------------------------------------------------------------------- */
  @media (prefers-reduced-motion: no-preference) {
    .cinema.cinema--interactive {
      padding-block: 0;
      block-size: 640vh;
      block-size: 640lvh;
      background: var(--cinema-sky-top);
    }

    @media (max-width: 47.99rem) {
      .cinema.cinema--interactive {
        block-size: 580vh;
        block-size: 580lvh;
      }
    }

    .cinema--interactive .cinema__sticky {
      position: sticky;
      inset-block-start: 0;
      display: block;
      inline-size: 100%;
      max-inline-size: none;
      block-size: 100vh;
      block-size: 100dvh;
      margin: 0;
      overflow: clip;
      isolation: isolate;
      container-type: size;
      background: var(--cinema-sky-top);
    }

    .cinema--interactive .cinema__skip {
      inset-block-start: calc(5.25rem + env(safe-area-inset-top, 0px));
      inset-inline-start: var(--gutter);
    }

    /* Once the finale is up, the link moves to the free band at the bottom of the stage,
       and the finale keeps that band clear while the link has focus. */
    .cinema--interactive.is-finale-ready .cinema__skip {
      inset-block-start: auto;
      inset-block-end: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    }

    .cinema--interactive.is-finale-ready:has(.cinema__skip:focus-visible) .cinema__finale {
      inset-block-end: calc(4.75rem + env(safe-area-inset-bottom, 0px));
    }

    .cinema--interactive .cinema__stage {
      position: absolute;
      inset: 0;
      display: block;
      overflow: clip;
      pointer-events: none;
    }

    .cinema--interactive .cinema__plate {
      position: absolute;
      inset: 0;
      overflow: visible;
      border: 0;
      border-radius: 0;
      background: transparent;
      box-shadow: none;
    }

    .cinema--interactive .cinema__plate--facade {
      z-index: 1;
    }
    .cinema--interactive .cinema__plate--window {
      z-index: 2;
    }
    .cinema--interactive .cinema__plate--closeup {
      z-index: 3;
    }
    .cinema--interactive .cinema__plate--bokeh {
      z-index: 4;
    }

    /* Each plate is sized to "cover" the stage; cinema.js moves the camera with one transform */
    .cinema--interactive .cinema__img,
    .cinema--interactive .cinema__plate--bokeh .cinema__img {
      position: absolute;
      inset-block-start: 0;
      inset-inline-start: 0;
      inline-size: max(100cqi, 179.1667cqb);
      block-size: max(100cqb, 55.8140cqi);
      max-inline-size: none;
      aspect-ratio: auto;
      object-fit: cover;
      transform-origin: 0 0;
      backface-visibility: hidden;
    }

    .cinema--interactive :is(.cinema__plate--window, .cinema__plate--closeup, .cinema__plate--bokeh) .cinema__img {
      opacity: 0;
    }

    .cinema--interactive.cinema--live .cinema__img,
    .cinema--interactive.cinema--live .cinema__bloom,
    .cinema--interactive.cinema--live .cinema__finale-card {
      will-change: transform, opacity;
    }

    /* Fly-through frames: the canvas takes over from the first three plates */
    .cinema--interactive.cinema--frames .cinema__frames {
      position: absolute;
      inset: 0;
      z-index: 1;
      display: block;
      inline-size: 100%;
      block-size: 100%;
      max-inline-size: none;
    }

    .cinema--interactive.cinema--frames :is(.cinema__plate--facade, .cinema__plate--window, .cinema__plate--closeup) {
      display: none;
    }

    /* Warm light bloom into the bokeh (and through the window in the four-plate cinema) */
    .cinema--interactive .cinema__bloom {
      position: absolute;
      inset: 0;
      z-index: 5;
      display: block;
      opacity: 0;
      background: radial-gradient(
        62% 58% at 50% 50%,
        color-mix(in oklab, var(--cinema-window-core) 88%, transparent),
        color-mix(in oklab, var(--cinema-window-warm) 42%, transparent) 46%,
        transparent 78%
      );
    }

    /* Photographic depth: lens vignette plus quiet top and bottom falloff for the header */
    .cinema--interactive .cinema__vignette {
      position: absolute;
      inset: 0;
      z-index: 6;
      display: block;
      background:
        linear-gradient(180deg, color-mix(in oklab, var(--cinema-sky-top) 46%, transparent), transparent 18%),
        linear-gradient(0deg, color-mix(in oklab, var(--cinema-sky-top) 40%, transparent), transparent 18%),
        radial-gradient(125% 95% at 50% 48%, transparent 58%, color-mix(in oklab, var(--cinema-sky-top) 58%, transparent) 100%);
    }

    /* Static film grain (no animation, nothing loops) */
    .cinema--interactive .cinema__grain {
      position: absolute;
      inset: 0;
      z-index: 7;
      display: block;
      opacity: 0.09;
      mix-blend-mode: overlay;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
      background-size: 220px 220px;
    }

    /* The waitlist finale rises over the bokeh plate. The card carries the scroll-linked
       rise (cinema.js writes --fin-o/--fin-y/--fin-s on the finale; they inherit). */
    .cinema--interactive .cinema__finale {
      position: absolute;
      inset: 0 0 calc(4.75rem + env(safe-area-inset-bottom, 0px)) 0;
      z-index: 8;
      display: grid;
      place-items: safe center;
      padding-inline: var(--gutter);
      padding-block: clamp(5rem, 9dvh, 6rem) 0.75rem;
      overflow-y: auto;
      overscroll-behavior-y: contain;
      /* Classic scrollbars: reserve both gutters, so the centred card never shifts sideways when the
         finale becomes scrollable (step 2, or the card's rise briefly overhanging the frame) */
      scrollbar-gutter: stable both-edges;
      pointer-events: none;
    }

    .cinema--interactive .cinema__finale-card {
      opacity: var(--fin-o, 0);
      transform: translate3d(0, var(--fin-y, 44px), 0) scale(var(--fin-s, 0.965));
    }

    /* Wide screens: the centered card never meets the back-to-top button */
    @media (min-width: 64rem) {
      .cinema--interactive .cinema__finale {
        inset-block-end: 1.5rem;
      }
    }

    body:has(.site-header.is-hidden) .cinema--interactive .cinema__finale {
      padding-block-start: clamp(1rem, 3dvh, 2rem);
    }

    .cinema--interactive.is-finale-ready .cinema__finale {
      pointer-events: auto;
    }

    /* Anything focused inside the finale is always visible and usable */
    .cinema--interactive .cinema__finale:focus-within {
      pointer-events: auto;
    }

    .cinema--interactive .cinema__finale:focus-within .cinema__finale-card {
      opacity: 1;
      transform: none;
    }

    /* Step 2 of the waitlist: compact so both actions stay in view */
    .cinema--interactive .cinema__finale:has([data-waitlist-step="2"]:not([hidden])) {
      padding-block: 1rem 0.75rem;
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) {
      inline-size: min(100%, 54rem);
      padding: clamp(1.125rem, 2.2vw, 1.75rem) clamp(1.125rem, 3vw, 2.25rem);
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .cinema__finale-title {
      margin-block-start: 0.35rem;
      font-size: clamp(1.25rem, 1rem + 0.9vw, 1.625rem);
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist {
      max-inline-size: none;
      margin-block-start: 0.75rem;
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__status {
      margin-block-start: 0.5rem;
      padding: 0.5rem 0.875rem;
      font-size: var(--fs-small);
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__followup {
      margin-block-start: 0.75rem;
      padding: 0.875rem 0 0;
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__followup .field {
      margin-block-start: 0.75rem;
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__followup .field__input {
      min-block-size: 3rem;
      font-size: 1rem;
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__followup .choice {
      min-block-size: 2.75rem;
      padding-block: 0.375rem;
      padding-inline: 0.75rem 1rem;
      font-size: 0.9375rem;
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__actions {
      margin-block-start: 1rem;
    }

    .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__actions .button {
      min-block-size: 3rem;
    }

    @media (min-width: 48rem) {
      .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__followup {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem 1.25rem;
        align-items: start;
      }
      .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__followup > :not(.field--group) {
        grid-column: 1 / -1;
      }
      .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__followup .field {
        margin-block-start: 0;
      }
      .cinema--interactive .cinema__finale-card:has([data-waitlist-step="2"]:not([hidden])) .waitlist__actions {
        margin-block-start: 0.25rem;
      }
    }

    /* Narrow phones: a compact card so Step 1 fits above the back-to-top button */
    @media (max-width: 26rem) {
      .cinema--interactive .cinema__finale {
        padding-inline: 0.75rem;
      }

      .cinema--interactive .cinema__finale-card {
        padding: 1.25rem 1.125rem;
      }

      .cinema--interactive .cinema__finale-title {
        margin-block-start: 0.5rem;
        font-size: clamp(1.3125rem, 1.05rem + 1.5vw, 1.5625rem);
        line-height: 1.18;
      }

      .cinema--interactive .cinema__finale-card .waitlist {
        margin-block-start: 1.25rem;
      }

      /* One control height (52px) for the switch, the tiles, the email field and the button, so the card stays
         compact and switching between Mobile and Email never shifts it */
      .cinema--interactive .cinema__finale-card .switch {
        --ctl-h-md: 2.75rem;
      }

      .cinema--interactive .cinema__finale-card :is(.field__input, .phone-tiles__prefix, .phone-tiles__slot, .waitlist__submit) {
        min-block-size: 3.25rem;
      }

      .cinema--interactive .cinema__finale-card :is(.field__input, .waitlist__submit) {
        font-size: 1rem;
      }

      .cinema--interactive .cinema__finale-card .waitlist__note {
        font-size: 0.84375rem;
      }
    }
  }

  /* Forced colors: keep the skip link and card edges crisp */
  @media (forced-colors: active) {
    .cinema__skip:focus-visible {
      border: 2px solid ButtonText;
      background: Canvas;
      color: CanvasText;
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
      box-shadow: none;
    }

    .cinema__finale-card {
      border: 2px solid CanvasText;
      background-color: Canvas;
    }
  }
}
