/* ==========================================================
   BEINC — Track Record Section
   Full section: hero text shrink → facts stack → scroll-driven
   stat boxes → progress bar. Parallax entry.

   Depends on: global.css (colours, fonts, spacing)
   Animation: js/components/track-boxes.js (GSAP ScrollTrigger)
   ========================================================== */

/* ── SECTION ── */
.tr-section {
    position: relative;
    height: 400vh;
    z-index: 2;
    margin-top: -100vh;
}


/* ── STICKY INNER ── */
.tr-sticky {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    background: var(--color-white);
    display: flex;
    flex-direction: column;
    padding: 10vh 2% 0 2%; /* no bottom padding — progress bar handles it */
}

/* ==========================================================
   SPACED LINES
   ========================================================== */
.tr-spaced-lines {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: clamp(20px, 2.5vw, 37px);
    z-index: 5;
}

.tr-spaced-line {
    position: absolute;
    top: 0;
    height: 100%;
    background: var(--color-black2);
}

/* ==========================================================
   FACTS ROW — contains hero text + asterisk + number
   During hero phase: hero text fills this row centered.
   During facts phase: row is flex space-between at top.
   ========================================================== */
.tr-facts-row {
    display: flex;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
    position: relative;
    /* JS toggles between centered (hero) and space-between (facts) */
}

/* ── HERO TEXT / FACTS LABEL — same element ── */
.tr-hero-text {
    font-family: var(--font-heading);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tight);
    line-height: 1.05;
    color: var(--color-black2);
    /* Initial state: big, centered. JS animates fontSize, position */
}

/* ── ASTERISK — absolutely centered in the row ── */
.tr-facts-asterisk {
    width: clamp(20px, 2.5vw, 40px);
    height: auto;
    color: var(--color-black2);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    /* JS controls translateY for slide-up + rotation */
}

/* ── NUMBER ── */
.tr-facts-number {
    font-family: var(--font-heading);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tight);
    font-size: clamp(24px, 3vw, 48px);
    line-height: 1.1;
    color: var(--color-greyish);
    min-width: 2.5ch;
    text-align: right;
    flex-shrink: 0;
    /* Starts off-screen below, JS slides up */
}

/* ── DASHED LINE ── */
.tr-facts-line {
    height: 1px;
    border-top: 1px dashed var(--color-greyish);
    transform-origin: left;
    transform: scaleX(0);
    flex-shrink: 0;
    /* Edge to edge — break out of padding */
    margin-left: -2%;
    margin-right: -2%;
    width: calc(100% + 4%);
}

/* ==========================================================
   TRACK CONTENT — boxes grid + right text
   ========================================================== */
.tr-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    min-height: 0;
    /* JS controls translateY for slide-up entrance */
}

/* ── GRID WRAPPER ── */
.tr-boxes-grid-wrap {
    position: relative;
    width: min(55vw, 80vh);
    aspect-ratio: 3 / 2;
}

/* ── GRID ── */
.tr-boxes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: 1fr 1fr;
    width: 100%;
    height: 100%;
    position: relative;
}

.tr-boxes-grid::before {
    content: '';
    position: absolute;
    inset: -1px;
    border: 1px dashed var(--color-greyish);
    z-index: 4;
    pointer-events: none;
}

/* ── BOX ── */
.tr-box {
    position: relative;
    padding: clamp(14px, 1.5vw, 20px);
    background: var(--color-white);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* ── SHARED FILL ── */
.tr-box__shared-fill {
    position: absolute;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    overflow: visible;
}

/* ── INNER BORDERS ── */
.tr-box::after {
    content: '';
    position: absolute;
    inset: 0;
    border-right: 1px dashed var(--color-greyish);
    border-bottom: 1px dashed var(--color-greyish);
    z-index: 4;
    pointer-events: none;
}
.tr-box:nth-child(3n)::after { border-right: none; }
.tr-box:nth-child(n+4)::after { border-bottom: none; }

/* ── CONTENT ── */
.tr-box__number,
.tr-box__bottom { position: relative; }

.tr-box__number {
    font-family: var(--font-heading);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tight);
    line-height: 1;
    color: var(--color-black2);
    text-align: right;
    align-self: flex-end;
    font-size: clamp(18px, 2vw, 28px);
}

/* ── WHITE GRID ── */
.tr-boxes-grid--white {
    position: absolute;
    inset: 0;
    width: 100%;
    z-index: 3;
    pointer-events: none;
    clip-path: inset(0 100% 100% 0);
    border-color: transparent !important;
}
.tr-boxes-grid--white .tr-box { background: transparent; border-color: transparent !important; }
.tr-boxes-grid--white .tr-box__number,
.tr-boxes-grid--white .tr-box__heading { color: var(--color-white); }
.tr-boxes-grid--white .tr-box__body { color: var(--color-greyish); }

.tr-box__bottom {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    gap: 4px;
}

.tr-box__heading {
    font-family: var(--font-heading);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tight);
    font-size: clamp(18px, 2.2vw, 32px);
    line-height: 1.1;
    color: var(--color-black2);
}

.tr-box__body {
    font-family: var(--font-heading);
    font-weight: var(--font-weight-medium);
    letter-spacing: var(--tracking-tight);
    font-size: clamp(10px, 0.85vw, 13px);
    line-height: 1.3;
    color: var(--color-greyish);
    position: relative;
    z-index: 1;
}

/* ==========================================================
   RIGHT CONTENT — polaroid + R-rated button
   ========================================================== */
.tr-content-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(16px, 2vw, 30px);
    flex: 1;
    min-width: 0;
}

/* ── POLAROID STACK ── */
.tr-polaroid-stack {
    position: relative;
    width: clamp(220px, 24vw, 360px);
    aspect-ratio: 423 / 481;
    flex-shrink: 0;
}

.tr-polaroid {
    position: absolute;
    left: var(--ox, 0%);
    top: var(--oy, 0%);
    transform: rotate(var(--rot, 0deg));
    opacity: 0;
    /* JS animates opacity + scale for entry */
}

.tr-polaroid__frame {
    background: var(--color-black2);
    padding: clamp(8px, 0.8vw, 12px);
    padding-bottom: clamp(8px, 0.8vw, 12px);
    width: clamp(150px, 17vw, 260px);
    border-radius: 2px;
}

.tr-polaroid__image-wrap {
    width: 100%;
    aspect-ratio: 278 / 310;
    overflow: hidden;
    position: relative;
}

.tr-polaroid__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
}

.tr-polaroid__text {
    display: block;
    text-align: center;
    font-family: 'marydale', serif;
    font-weight: 900;
    font-size: clamp(10px, 1.1vw, 18px);
    letter-spacing: -0.075em;
    color: var(--color-white);
    margin-top: clamp(4px, 0.5vw, 8px);
    text-transform: uppercase;
    /* Labels currently hidden — visibility:hidden keeps the layout space
       (line-height + margin-top) reserved beneath each polaroid so the
       frame stays the right size, but the text itself doesn't render.
       Remove this line when you want the labels back. */
    visibility: hidden;
}

/* ── R-RATED BUTTON in section ── */
.tr-rr-btn {
    align-self: center;
}

/* ==========================================================
   PROGRESS BAR — desktop & tablet only.
   10px container with cream background and a dashed top stroke.
   The black bar inside grows scaleX 0→1 as the user moves through
   the box phase. 5 vertical dashed dividers sit ON TOP of the bar
   and split it into 6 equal segments — each segment maps to one
   box (Box 0…Box 5) so the user can read the bar like a scrubber:
   the fill edge tells them which box is active, the next divider
   shows where the next box transition fires.
   ========================================================== */
.tr-progress {
    height: 10px;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-white);
    border-top: var(--guide-width) var(--guide-style) var(--color-greyish);
    overflow: hidden;
    z-index: 5;
}

.tr-progress__bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-black2);
    transform-origin: left center;
    transform: scaleX(0);
    z-index: 1;
}

/* 5 vertical dashed dividers split the bar into 6 equal segments.
   Positioned absolutely so they stay put regardless of the fill's scaleX.
   Default: greyish — readable on the cream container.
   When the black fill has crossed the divider (`.-covered` toggled by JS),
   the divider flips to cream so it remains readable on the dark fill. */
.tr-progress__divider {
    position: absolute;
    top: 0;
    height: 100%;
    width: 0;
    border-left: var(--guide-width) var(--guide-style) var(--color-greyish);
    z-index: 2;        /* above the black fill */
    pointer-events: none;
    transition: border-color 80ms linear;
}
.tr-progress__divider.-covered {
    border-left-color: var(--color-white);
}
.tr-progress__divider--1 { left: calc(100% / 6 * 1); }
.tr-progress__divider--2 { left: calc(100% / 6 * 2); }
.tr-progress__divider--3 { left: calc(100% / 6 * 3); }
.tr-progress__divider--4 { left: calc(100% / 6 * 4); }
.tr-progress__divider--5 { left: calc(100% / 6 * 5); }

/* ==========================================================
   TABLET
   ========================================================== */
@media (min-width: 768px) and (max-width: 1024px) {
    .tr-sticky { padding: 10vh 4% 0 4%; }

    .tr-facts-line { margin-left: -4%; margin-right: -4%; width: calc(100% + 8%); }

    .tr-boxes-grid-wrap { width: min(50vw, 53vh); aspect-ratio: 2 / 3; }
    .tr-boxes-grid { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(3, 1fr); }

    .tr-box::after { border-right: 1px dashed var(--color-greyish); border-bottom: 1px dashed var(--color-greyish); }
    .tr-box:nth-child(3n)::after { border-right: 1px dashed var(--color-greyish); }
    .tr-box:nth-child(n+4)::after { border-bottom: 1px dashed var(--color-greyish); }
    .tr-box:nth-child(2n)::after { border-right: none; }
    .tr-box:nth-child(n+5)::after { border-bottom: none; }

    .tr-polaroid-stack { width: clamp(250px, 30vw, 380px); }
    .tr-polaroid__frame { width: clamp(180px, 22vw, 280px); }
    .tr-content-right { gap: clamp(60px, 10vw, 120px); }
}

/* ==========================================================
   MOBILE
   ========================================================== */
@media (max-width: 767px) {
    /* Mobile: formation + autoplay handoff with NO sticky pin.
       Section height equals sticky child height (100vh) → sticky engages
       and disengages at the same scroll moment, so the section never
       actually pins. Section scrolls past smoothly while autoplay
       cycles boxes on its own timer. See track-boxes.js mobile branch. */
    .tr-section { height: 100vh; }

    .tr-sticky { padding: 10vh 4% 0 4%; }

    .tr-facts-line { margin-left: -4%; margin-right: -4%; width: calc(100% + 8%); }

    .tr-content { flex-direction: column; gap: 15px; flex: none; align-items: center; margin-top: auto; margin-bottom: 10vh; }
    .tr-boxes-grid-wrap { width: 100%; }
    .tr-box:nth-child(n+4)::after { border-bottom: none; }

    /* Progress bar hidden on mobile — no scroll-driven box cycling */
    .tr-progress { display: none; }

    /* Mobile reorder: polaroid → boxes → button */
    .tr-content-right {
        display: contents;
    }
    .tr-polaroid-stack { order: -2; margin: 0 auto; width: clamp(220px, 60vw, 300px); }
    .tr-polaroid__frame { width: clamp(150px, 42vw, 220px); }
    .tr-rr-btn { order: 10; }
}
