/*
 * Landing v3 · templates (decision D16). Lane file: only `.tpl` rules live here.
 * Benchmark: ManyChat "From simple welcome messages to optimized sales & marketing funnels"
 * (measured 2026-11-18): colour panel, template list on the left, one tall looping DM video at a
 * time, switched by click with a 500ms rise. Ours keeps the structure and changes three things:
 *  - full-bleed ink stage (min 100svh on laptops) with the unread-dot field, not a boxed panel
 *  - every template has its own phone on one track that runs off the right edge, so the next
 *    flows are already in view and the switch is a slide, not a swap
 *  - left alone, the list advances when a loop ends (red bar = how far the loop is)
 *  - only the current phone moves; the others show their poster (v4, Steve 11-18: neighbours typing
 *    at the same time made the stage chaotic)
 * Each video is a transparent 660x960 stage (design units) with the phone body drawn in it, so
 * product cards, the expanded notification and the tags can leave the phone. The stage is wider
 * than the phone; items overlap their neighbours' empty margins so the phones keep their spacing.
 */

.tpl {
    --tpl-ph: 560px;                                  /* phone body height, set per breakpoint */
    --tpl-pw: calc(var(--tpl-ph) * 0.4770);           /* phone body width (414 / 868) */
    --tpl-sw: calc(var(--tpl-ph) * 0.7604);           /* stage width (660 / 868) */
    --tpl-sh: calc(var(--tpl-ph) * 1.1060);           /* stage height (960 / 868) */
    --tpl-m: calc(var(--tpl-ph) * 0.1417);            /* stage margin beside the phone */
    --tpl-pt: calc(var(--tpl-ph) * 0.0530);           /* stage margin above the phone */
    --tpl-bz: calc(var(--tpl-pw) * 0.029);            /* bezel (fallback phone) */
    --tpl-gap: 28px;
    position: relative;
    color: #fff;
    background-color: var(--nb-ink);
    /* The unread-dot field: small dots on ink, one every 24px. */
    background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .085) 1px, transparent 1.6px);
    background-size: 24px 24px;
    padding: clamp(72px, 9vw, 120px) 0;
    overflow: clip;
}
.tpl__in { display: grid; gap: 36px; }

/* ── Copy column ── */
.tpl__side { padding: 0 var(--gutter); display: grid; gap: 28px; align-content: start; }
.tpl__title { margin: 0; word-break: keep-all; } /* type: .nb-h2 (landing.css) */
.tpl__tabs { display: flex; gap: 8px; margin: 0 calc(var(--gutter) * -1); padding: 2px var(--gutter); overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
.tpl__tabs::-webkit-scrollbar { display: none; }
.tpl__tabs li { flex: none; scroll-snap-align: start; }
.tpl__tab {
    position: relative; display: grid; gap: 4px; width: 100%;
    min-height: 44px; padding: 10px 16px;
    border: 0; border-radius: 999px;
    background: rgba(255, 255, 255, .08); color: rgba(255, 255, 255, .72);
    font: inherit; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; text-align: left;
    cursor: pointer; overflow: hidden;
    transition: background-color var(--nb-dur-2) ease, color var(--nb-dur-2) ease;
}
.tpl__tab[aria-current="true"] { background: #fff; color: var(--nb-ink); }
.tpl__name { white-space: nowrap; }
.tpl__flow, .tpl__bar { display: none; }
.tpl .nb-l :focus-visible, .tpl :focus-visible { outline-color: #fff; }
.tpl__cta { justify-self: start; display: none; }

/* ── Track ── */
.tpl__track {
    overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.tpl__track::-webkit-scrollbar { display: none; }
.tpl__list { display: flex; padding: 0 calc((100vw - var(--tpl-sw)) / 2); width: max-content; }
.tpl__item {
    position: relative; width: var(--tpl-sw); flex: none;
    margin-right: calc(var(--tpl-gap) - 2 * var(--tpl-m));
    scroll-snap-align: center; scroll-snap-stop: always;
}
.tpl__item:last-child { margin-right: 0; }
.tpl__item.is-current { z-index: 2; }
.tpl__stage {
    position: relative; height: var(--tpl-sh);
    transition: transform var(--nb-dur-4) var(--nb-ease), opacity var(--nb-dur-4) var(--nb-ease);
}
/* Fallback phone (no videos): the same body the videos draw, in CSS. */
.tpl__phone {
    position: absolute; left: var(--tpl-m); top: var(--tpl-pt);
    width: var(--tpl-pw); height: var(--tpl-ph);
    padding: var(--tpl-bz);
    border-radius: calc(var(--tpl-pw) * .155);
    background: #050506;
    box-shadow: 0 0 0 1.5px #2c2c31, 0 30px 60px -30px rgba(0, 0, 0, .7);
}
.tpl__screen {
    position: relative; height: 100%;
    border-radius: calc(var(--tpl-pw) * .125);
    overflow: hidden; background: #fff;
    isolation: isolate;
}
/* Dynamic island over the screen's status bar. */
.tpl__screen::after {
    content: ""; position: absolute; z-index: 3; left: 50%; top: calc(var(--tpl-pw) * .028);
    width: 31%; height: calc(var(--tpl-pw) * .088); transform: translateX(-50%);
    border-radius: 999px; background: #050506;
}
/* Home indicator (the loops leave the bottom 34 design units for it). */
.tpl__screen::before {
    content: ""; position: absolute; z-index: 3; left: 50%; bottom: calc(var(--tpl-pw) * .022);
    width: 35%; height: calc(var(--tpl-pw) * .013); min-height: 3px; transform: translateX(-50%);
    border-radius: 999px; background: #111113;
}
.tpl__poster, .tpl__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.tpl__video { opacity: 0; transition: opacity var(--nb-dur-2) ease; }
.tpl__video.is-on { opacity: 1; }
.tpl__cap { margin: 4px var(--tpl-m) 0; font-size: 14px; line-height: 1.45; color: rgba(255, 255, 255, .62); text-align: center; text-wrap: balance; word-break: keep-all; }
.tpl__cap b { display: block; margin-bottom: 2px; color: #fff; font-size: 16px; font-weight: 700; }

/* Non-current phones step back a little once the script runs (without it, all are equal). */
.nb-js .tpl__item:not(.is-current) .tpl__stage { opacity: .55; transform: scale(.94); }
.nb-js .tpl__item:not(.is-current) .tpl__cap { opacity: 0; }
.tpl__cap { transition: opacity var(--nb-dur-3) ease; }

/* HTML end state (videos not on the CDN yet). */
.tpl__still {
    position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px;
    padding: 18% 7% 12%; background: #fff; color: var(--nb-ink); font-size: calc(var(--tpl-pw) * .045);
}
.tpl__msg--out { align-self: flex-end; max-width: 80%; padding: .6em .9em; border-radius: 1.2em 1.2em .35em 1.2em; background: var(--nb-ink); color: #fff; font-weight: 500; }
.tpl__card { display: grid; gap: 2px; width: 78%; padding-bottom: .9em; border-radius: 1.1em; overflow: hidden; background: #fff; box-shadow: 0 2px 6px rgba(17, 17, 20, .06), 0 8px 24px rgba(17, 17, 20, .07); }
.tpl__card b, .tpl__card > span:last-child:not(.tpl__tile) { padding: 0 .9em; }
.tpl__card b { margin-top: .6em; font-weight: 700; }
.tpl__tile { aspect-ratio: 4 / 3.4; border-radius: 0; }

/* ── Phones and tablets (< 1024): heading, chip row, centred swipe track, caption. ── */
@media (max-width: 1023.98px) {
    .tpl { --tpl-ph: clamp(440px, min(calc(100svh - 300px), 152vw), 640px); }
}
@media (max-width: 380px) {
    .tpl { --tpl-ph: clamp(420px, 148vw, 560px); --tpl-gap: 20px; }
}

/* ── Laptops and up: full-viewport stage, list left, track bleeding off the right edge. ── */
@media (min-width: 1024px) {
    .tpl {
        --tpl-ph: clamp(460px, calc((100svh - 120px) / 1.106), 760px);
        --tpl-gap: 40px;
        min-height: 100svh;
        display: grid; align-items: center;
        padding: 60px 0;
    }
    .tpl__in {
        grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
        column-gap: max(clamp(40px, 5vw, 96px), calc(var(--tpl-m) + 24px)); /* the stage's empty margin never covers the list */
        align-items: center;
        padding-left: var(--edge);
    }
    /* Above the track: its first stage's transparent margin reaches under the list (en titles are wider). */
    .tpl__side { padding: 0; gap: 32px; position: relative; z-index: 3; }
    .tpl__tabs { display: grid; gap: 2px; margin: 0; padding: 0; overflow: visible; }
    .tpl__tab {
        padding: 14px 16px 16px; border-radius: 16px;
        background: transparent; color: rgba(255, 255, 255, .56);
        font-size: 18px;
    }
    .tpl__tab[aria-current="true"] { background: rgba(255, 255, 255, .07); color: #fff; }
    @media (hover: hover) { .tpl__tab:not([aria-current="true"]):hover { color: rgba(255, 255, 255, .86); } }
    .tpl__name { white-space: normal; }
    .tpl__flow {
        display: block; max-height: 0; opacity: 0; overflow: hidden;
        font-size: 15px; font-weight: 500; line-height: 1.45; color: rgba(255, 255, 255, .64);
        transition: max-height var(--nb-dur-3) var(--nb-ease), opacity var(--nb-dur-3) ease;
    }
    .tpl__tab[aria-current="true"] .tpl__flow { max-height: 3em; opacity: 1; }
    .tpl__bar { display: block; position: absolute; left: 16px; right: 16px; bottom: 0; height: 2px; background: rgba(255, 255, 255, .1); opacity: 0; transition: opacity var(--nb-dur-2) ease; }
    .tpl__bar i { display: block; height: 100%; width: 100%; background: var(--nb-accent); transform: scaleX(var(--tpl-p, 0)); transform-origin: 0 50%; }
    .tpl__tab[aria-current="true"] .tpl__bar { opacity: 1; }
    .tpl__cta { display: inline-flex; }
    .tpl__track { scroll-snap-type: x mandatory; cursor: grab; margin-left: calc(var(--tpl-m) * -1); }
    .tpl__track.is-drag { cursor: grabbing; scroll-snap-type: none; }
    .tpl__track.is-drag * { user-select: none; }
    .tpl__list { padding: 0 calc(100% - var(--tpl-sw)) 0 0; }
    .tpl__item { scroll-snap-align: start; }
    .tpl__cap { display: none; }
    .tpl__title .nb-line { white-space: nowrap; }
}
@media (min-width: 1024px) and (max-height: 700px) {
    .tpl { --tpl-ph: clamp(420px, calc((100svh - 80px) / 1.106), 560px); padding: 40px 0; }
    .tpl__side { gap: 22px; }
    .tpl__tab { padding: 10px 14px 12px; font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .tpl__stage, .tpl__cap, .tpl__flow, .tpl__video { transition: none; }
    .nb-js .tpl__item:not(.is-current) .tpl__stage { transform: none; }
}
