/* ==========================================================================
   media-2027.css — shared media mechanisms (websites.html + apps.html)
   --------------------------------------------------------------------------
   Provides three primitives that BOTH new pages need, so neither page owns
   them and neither page may fork them:

     1. Phone frame       .cy27-phones / .cy27-phone / __speaker / __screen
                          / .cy27-phone--lift
     2. Screenshot carousel   [data-cy27-carousel] / [data-cy27-slide]
                          / .cy27-carousel__stage / [data-cy27-dots]
                          / .cy27-dot / [data-cy27-count]
     3. Scripted screencast   [data-cy27-demo] / [data-cy27-frame]
                          / [data-cy27-shot-img] + the cursor, ripple and
                          badge that js/media-2027.js injects

   Depends on css/site-2027.css for the token layer, the focus treatment and
   the .cy27-shot striped placeholder + .cy27-shot__caption pair. Nothing here
   redefines a token, a button, a section rhythm or a hairline row — those all
   already exist in the shared file. Behaviour lives in js/media-2027.js.

   Load order on a page:  site-2027.css -> media-2027.css -> <slug>-2027.css
   so the page file can still tune a frame's ratio or padding for its layout.

   Progressive enhancement: every mechanism here has a readable no-JS state.
   Slide 1 / frame 1 paints from CSS alone; the dot row and the demo cursor
   simply never appear. Nothing is left as a blank box.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. Phone frame
   --------------------------------------------------------------------------
   A device shell, not a card — the fill is deliberately darker than
   --cy27-bg (#07090d) so the screen reads as a separate object sitting on
   the page rather than a hole cut into it. Those literals come straight from
   the design file; they are device chrome, not part of the token scale, so
   they are not promoted to custom properties.
   -------------------------------------------------------------------------- */

.cy27-phones {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 28px;
    max-width: 820px;
    margin: 0 auto;
}

.cy27-phone {
    border-radius: 26px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .14);
    background: #0b0f17;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}

/* The speaker bar is drawn as a pseudo-element, so the markup is a single
   empty <div class="cy27-phone__speaker" aria-hidden="true"></div>. Two
   reasons: the bar can never be forgotten page-side, and it cannot reach the
   accessibility tree as a stray unlabelled element. An empty <span> written
   inside anyway stays inert — it has no styling and no dimensions. */
.cy27-phone__speaker {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 9px;
}

.cy27-phone__speaker::before {
    content: "";
    width: 34%;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, .14);
}

/* width:100% is not decoration. An element with aspect-ratio and no definite
   width back-computes its width from its height, and any min-height a page
   later adds would then blow the frame wider than its grid column. */
.cy27-phone__screen {
    position: relative;
    width: 100%;
    aspect-ratio: 9 / 17;
    overflow: hidden;
}

/* Centre frame of a trio. Declared after .cy27-phone so the equal-specificity
   border-color and box-shadow overrides land. */
.cy27-phone--lift {
    transform: translateY(-24px);
    border-color: rgba(0, 192, 250, .28);
    box-shadow: 0 30px 70px rgba(0, 0, 0, .55);
}


/* --------------------------------------------------------------------------
   2. Screenshot carousel
   --------------------------------------------------------------------------
   Two variants off one implementation:

     data-cy27-carousel           dots variant   — control row + n/total counter
     data-cy27-carousel="tap"     dot-less       — the frame itself is the button

   Markup, dots variant:
       <div class="…" data-cy27-carousel>
           <div class="cy27-carousel__stage">
               <div data-cy27-slide>…</div>   (x2-4)
           </div>
           <div class="cy27-carousel__dots" data-cy27-dots>
               <span class="cy27-carousel__count" data-cy27-count></span>
           </div>
       </div>

   Markup, tap variant (a phone screen IS the carousel — one element, both
   hooks, no stage needed because there is no dot row to keep clear):
       <div class="cy27-phone__screen" data-cy27-carousel="tap">
           <div data-cy27-slide>…</div>   (x2-3)
       </div>
   -------------------------------------------------------------------------- */

[data-cy27-carousel] {
    position: relative;
    display: flex;
    flex-direction: column;
    /* Flex/grid children refuse to shrink below their content by default,
       which a wide mono caption would happily exploit. */
    min-width: 0;
}

/* The slides' positioning box in the dots variant. Without it the absolute
   slides would cover the dot row. min-height keeps the box from collapsing
   to nothing — every slide is out of flow — and width:100% is the definite
   width that min-height + a page-supplied aspect-ratio require. */
.cy27-carousel__stage {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-height: 240px;
    overflow: hidden;
}

[data-cy27-slide] {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity .7s var(--cy27-ease);
}

[data-cy27-slide].is-active {
    opacity: 1;
}

/* No-JS and pre-init: nothing ever gets .is-active, so the whole box would
   paint empty. Un-hide the first slide until JS takes over. The :has() form
   stops matching the instant a slide goes active, so it cannot fight the
   running carousel; the .no-js form is the same insurance for engines
   without :has(). */
[data-cy27-carousel]:not(:has([data-cy27-slide].is-active)) [data-cy27-slide]:first-child,
.no-js [data-cy27-slide]:first-child {
    opacity: 1;
}

/* Hidden until js/media-2027.js has built real <button> dots. With scripting
   off an empty hairline strip and a counter promising slides you cannot
   reach are both worse than no control row at all. Costs one small reflow at
   init, which is the right trade. */
[data-cy27-dots] {
    display: none;
    align-items: center;
    gap: 0;
    /* No vertical padding: the 44px dot targets set the row height. */
    padding: 0 22px;
    border-top: 1px solid var(--cy27-line-soft);
    /* Above the absolutely-positioned slides even if a page omits the stage. */
    position: relative;
    z-index: 2;
    margin-top: auto;
}

[data-cy27-carousel].is-live [data-cy27-dots] {
    display: flex;
}

/* The bar the design asks for is 26x4px — an unhittable target on a phone.
   The button is a transparent 44x44 square with the bar drawn inside it, and
   the row gap is 0 so neighbouring targets touch without overlapping. That
   spaces the bars 44px apart instead of the mockup's 34px; the extra 10px is
   the cost of a real touch target and is a deliberate deviation. */
.cy27-dot {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-appearance: none;
            appearance: none;
}

.cy27-dot::before {
    content: "";
    width: 26px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, .16);
    transition: background .3s ease;
}

.cy27-dot[aria-current="true"]::before {
    background: var(--cy27-accent);
}

.cy27-carousel__count,
[data-cy27-count] {
    margin-left: auto;
    font-family: var(--cy27-mono);
    font-size: .68rem;
    letter-spacing: .1em;
    color: var(--cy27-subtle);
}

/* Only the live tap variant advertises itself as clickable. Under .no-js the
   cursor would be a lie — there is nothing to click. */
/* The shared focus treatment draws `outline-offset: 3px`, i.e. OUTSIDE the box.
   Both of these controls sit inside an ancestor with overflow:hidden (the phone
   screen's rounded clip, and the featured card's 18px radius), so an outside
   ring is clipped away entirely and the control looks unfocusable to a keyboard
   user. Pull the ring inside for these two only. */
[data-cy27-carousel="tap"]:focus-visible {
    outline-offset: -3px;
}

.cy27-dot:focus-visible {
    outline-offset: -3px;
}

[data-cy27-carousel="tap"].is-live {
    cursor: pointer;
}


/* --------------------------------------------------------------------------
   3. Scripted screencast player
   --------------------------------------------------------------------------
   A stack of real captures cross-fading while a synthetic cursor travels and
   clicks. Decoration, not a control: nothing in here is interactive, and the
   cursor, ripple and corner badge are injected by js/media-2027.js with
   aria-hidden so they never reach the accessibility tree.

   Ratio is a custom property because the two pages differ: Websites uses
   16/11, Apps uses 16/10. Set it from the page file, e.g.
       .cy27-webhero__demo { --cy27-demo-ratio: 16 / 11; }
   -------------------------------------------------------------------------- */

[data-cy27-demo] {
    position: relative;
    width: 100%;
    aspect-ratio: var(--cy27-demo-ratio, 16 / 10);
    overflow: hidden;
}

[data-cy27-frame] {
    position: absolute;
    inset: 0;
    opacity: 0;
    overflow: hidden;
    transition: opacity .5s var(--cy27-ease);
}

[data-cy27-frame].is-active {
    opacity: 1;
}

/* Same no-JS / pre-init guarantee as the carousel: frame 1 paints from CSS
   alone, so a scripting-disabled visitor sees the opening capture rather than
   an empty 16/10 hole. */
[data-cy27-demo]:not(:has([data-cy27-frame].is-active)) [data-cy27-frame]:first-child,
.no-js [data-cy27-frame]:first-child {
    opacity: 1;
}

/* The capture layer. Deliberately sets no background: pair it with
   .cy27-shot (or .cy27-shot--cyan) from site-2027.css to get the striped
   placeholder and .cy27-shot__caption for the monospace description of the
   shot this slot still needs. Installing a real capture is then one edit —
   replace the background with url('../assets/demo/<data-shot>.png') and drop
   the caption span. */
[data-cy27-shot-img] {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: top center;
    transition: transform 2.4s linear;
}

/* A panned capture drifts UPWARD, which would expose a transparent band along
   the bottom of the frame. Give it height to drift into: 125% covers any pan
   value up to 20% with the seam still off-screen. */
[data-cy27-frame][data-pan] [data-cy27-shot-img] {
    bottom: auto;
    height: 125%;
}

/* left/top are the arrow TIP — there is deliberately no centering transform,
   because the transform belongs to the press (scale(.84)) and cannot be
   shared. line-height:0 stops the inline SVG contributing descender space,
   which would push the tip off the target by a couple of pixels. */
.cy27-demo__cursor {
    position: absolute;
    left: 50%;
    top: 60%;
    z-index: 4;
    line-height: 0;
    opacity: 0;
    pointer-events: none;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .6));
}

.cy27-demo__cursor :where(svg) {
    display: block;
}

.cy27-demo__ripple {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid rgba(0, 192, 250, .9);
    transform: translate(-50%, -50%) scale(.3);
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

.cy27-demo__badge {
    position: absolute;
    right: 12px;
    bottom: 10px;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border-radius: 7px;
    background: rgba(7, 9, 13, .72);
    -webkit-backdrop-filter: blur(6px);
            backdrop-filter: blur(6px);
    border: 1px solid var(--cy27-line);
    font-family: var(--cy27-mono);
    font-size: .62rem;
    letter-spacing: .08em;
    color: var(--cy27-body);
    pointer-events: none;
}

.cy27-demo__badge::before {
    content: "";
    flex: 0 0 auto;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #7ce0a1;
}


/* --------------------------------------------------------------------------
   4. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 760px) {
    /* Three phone frames side by side ON a phone is absurd. One column, and
       the centre frame's lift goes with it — a 24px offset with nothing
       beside it just looks like a rendering fault. */
    .cy27-phones {
        grid-template-columns: 1fr;
        max-width: 280px;
    }

    .cy27-phone--lift {
        transform: none;
    }

    .cy27-carousel__stage {
        min-height: 200px;
    }

    [data-cy27-dots] {
        padding: 0 16px;
    }
}


/* --------------------------------------------------------------------------
   5. Reduced motion
   --------------------------------------------------------------------------
   The JS already skips carousel auto-advance and the whole screencast
   choreography. What is left is the cross-fade on a MANUAL advance (a dot
   click, a tap on a phone frame), which still needs to be instant.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    [data-cy27-slide],
    [data-cy27-frame],
    [data-cy27-shot-img],
    .cy27-dot::before {
        transition: none;
    }
}
