/* =========================================================================
   H-Performance Exhaust System — home page layer
   3D hero, 3D intake + brake sections, 3D call-to-action and the motion effects for the home page.
   Loaded only by index.php (after styles.css). Other pages are untouched.
   ========================================================================= */

:root {
    --hp-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --hp-ease-io: cubic-bezier(0.77, 0, 0.18, 1);
}

/* ---------- smooth scroll (Lenis) ---------- */
html.lenis, html.lenis body { height: auto; }
html.lenis.lenis-smooth { scroll-behavior: auto !important; }
html.lenis.lenis-stopped { overflow: hidden; }

/* ---------- scroll progress line ---------- */
.hp-progress {
    position: fixed; left: 0; right: 0; top: 0; z-index: 1200; height: 2px;
    background: var(--gold-gradient); transform-origin: 0 50%; transform: scaleX(0);
    pointer-events: none;
}

/* ---------- navbar: keep the off-screen mobile menu from widening the page ---------- */
.navbar { overflow-x: clip; }

/* ---------- 3D canvas host (one canvas, moved between the hero and the CTA) ---------- */
.h3d-host { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.h3d-canvas { display: block; width: 100%; height: 100%; opacity: 0; transition: opacity 1.4s ease; }
.h3d-canvas.is-ready { opacity: 1; }

/* =========================================================================
   1. HERO (3D)
   ========================================================================= */
.hero--3d {
    min-height: max(660px, calc(100vh - 118px));
    background: #0a0a0a;
}
.hero--3d::before {
    content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background:
        linear-gradient(90deg, rgba(10, 10, 10, 0.94) 0%, rgba(10, 10, 10, 0.78) 30%, rgba(10, 10, 10, 0.18) 54%, rgba(10, 10, 10, 0) 64%),
        linear-gradient(0deg, #141414 0%, rgba(20, 20, 20, 0) 14%),
        radial-gradient(ellipse at 82% 0%, rgba(212, 175, 55, 0.12) 0%, transparent 55%);
}
.hero--3d .hero-content { width: 100%; max-width: var(--container); }
.hero--3d .hero-copy { max-width: 640px; }
.hero--3d .hero-title {
    font-size: clamp(2.6rem, 4.6vw, 4rem);
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1.05;
}
.hero--3d .hero-subtitle { max-width: 560px; }
.hero--3d .hero-stats { max-width: 600px; }
.hero--3d .hero-scroll { z-index: 3; }
.h3d-hero-anchor { position: absolute; top: 0; right: 0; bottom: 0; width: 46%; pointer-events: none; }

/* no WebGL (very old browsers): the original hero photo comes back */
.no-webgl .hero--3d { background: url('../../images/h-performance-005.jpg') center / cover; }
.no-webgl .hero--3d::before {
    background:
        radial-gradient(ellipse at top right, rgba(212, 175, 55, 0.15) 0%, transparent 50%),
        linear-gradient(135deg, rgba(10, 10, 10, 0.88) 0%, rgba(10, 10, 10, 0.62) 50%, rgba(10, 10, 10, 0.88) 100%);
}
.no-webgl .h3d-host { display: none; }

/* =========================================================================
   2. CALL TO ACTION (3D) — the full exhaust; heat runs from the downpipe to the tips
   ========================================================================= */
.cta--3d {
    position: relative;
    overflow: hidden;
    padding: 50px 0 110px;
    background: #0a0a0a;
    text-align: center;
}
.cta--3d::before {
    content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background:
        linear-gradient(180deg, #0a0a0a 0%, rgba(10, 10, 10, 0) 10%),
        linear-gradient(0deg, rgba(10, 10, 10, 0.97) 0%, rgba(10, 10, 10, 0.8) 30%, rgba(10, 10, 10, 0) 52%),
        radial-gradient(ellipse at 50% 30%, rgba(212, 175, 55, 0.08) 0%, transparent 60%);
}
.cta--3d::after {
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; z-index: 2;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0.6;
}
.cta-run { position: relative; z-index: 2; }
.cta-run-stage { position: relative; height: clamp(320px, 46vh, 480px); }
.cta-3d-anchor { position: absolute; inset: 0; pointer-events: none; }
.cta--3d .cta-inner { max-width: 760px; margin: 34px auto 0; }
.cta--3d .cta-title {
    font-size: clamp(2rem, 4vw, 3.2rem);
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1.1;
}
.cta--3d .cta-buttons { justify-content: center; }

/* the heat track under the exhaust (placed under the real parts by home-3d.js) */
.cta-run-track { position: absolute; z-index: 2; left: 12%; width: 76%; top: 46vh; pointer-events: none; }
.cta-run-line { position: relative; height: 2px; background: rgba(255, 255, 255, 0.1); }
.cta-run-line i {
    position: absolute; inset: 0; transform-origin: 0 50%; transform: scaleX(var(--heat-p, 0));
    background: linear-gradient(90deg, #c4c6cc 0%, #e8c25a 18%, #c47c2c 36%, #8a3fa0 58%, #2e6bd8 80%, #9cc0f0 100%);
}
.cta-run-line b {
    position: absolute; top: 50%; left: calc(var(--heat-p, 0) * 100%); width: 12px; height: 12px; margin: -6px 0 0 -6px;
    border-radius: 50%; background: #ffcf8a; opacity: var(--heat-on, 0); transition: opacity 0.4s;
    box-shadow: 0 0 14px 5px rgba(255, 140, 40, 0.65), 0 0 40px 10px rgba(255, 90, 20, 0.35);
}
.cta-run-track ol { position: relative; height: 34px; margin: 0; padding: 0; list-style: none; }
.cta-run-track li {
    position: absolute; top: 14px; left: calc(var(--at) * 100%); transform: translateX(-50%); white-space: nowrap;
    font-size: 11px; font-weight: 600; letter-spacing: 2.5px; text-transform: uppercase; color: var(--gray);
    transition: color 0.5s;
}
.cta-run-track li::before {
    content: ""; position: absolute; left: 50%; top: -19px; width: 8px; height: 8px; margin-left: -4px;
    background: #0a0a0a; border: 1px solid rgba(255, 255, 255, 0.25); transform: rotate(45deg);
    transition: background 0.5s, border-color 0.5s, box-shadow 0.5s;
}
.cta-run-track li.is-hot { color: var(--white); }
.cta-run-track li.is-hot::before { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 12px rgba(212, 175, 55, 0.8); }

/* hold-to-rev (sits under the exhaust tips in the hero) */
.rev--hero {
    position: absolute; z-index: 3;
    left: 72%; bottom: clamp(28px, 8vh, 72px);
    transform: translateX(-50%);
}
@media (min-width: 901px) and (max-width: 1299px) {
    .rev--hero { left: 77%; }
}
.rev {
    display: inline-flex; align-items: center; gap: 14px;
    padding: 8px 22px 8px 8px; border-radius: 999px;
    border: 1px solid rgba(212, 175, 55, 0.4);
    background: rgba(10, 10, 10, 0.6);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    color: var(--white); font-size: 13px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase;
    -webkit-user-select: none; user-select: none; touch-action: none; -webkit-touch-callout: none;
    transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}
.rev:hover, .rev.is-down { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.12); }
.rev__dial {
    position: relative; width: 44px; height: 44px; border-radius: 50%;
    background: conic-gradient(from 225deg, var(--gold) 0deg, #ff6a1a calc(var(--rev, 0) * 270deg), rgba(255, 255, 255, 0.1) calc(var(--rev, 0) * 270deg), rgba(255, 255, 255, 0.1) 270deg, transparent 270deg);
}
.rev__dial::before { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: #0d0d0d; }
.rev__dial i {
    position: absolute; left: 50%; top: 50%; width: 2px; height: 15px; margin-left: -1px;
    background: #ff5a1f; box-shadow: 0 0 8px rgba(255, 90, 31, 0.8);
    transform-origin: 50% 100%;
    transform: translateY(-100%) rotate(calc(-135deg + var(--rev, 0) * 270deg));
}

/* =========================================================================
   2b. PART SECTIONS (3D) — the air intake and the brake upgrade, under the services.
   Stage (drag to spin) + copy; .part3d--flip puts the stage on the right.
   ========================================================================= */
.part3d {
    position: relative;
    overflow: hidden;
    padding: 110px 0;
    background: #0b0b0b;
}
.part3d::before {
    content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background:
        linear-gradient(270deg, rgba(11, 11, 11, 0.94) 0%, rgba(11, 11, 11, 0.72) 34%, rgba(11, 11, 11, 0) 56%),
        linear-gradient(180deg, #0b0b0b 0%, rgba(11, 11, 11, 0) 12%, rgba(11, 11, 11, 0) 88%, #0a0a0a 100%),
        radial-gradient(ellipse at 26% 50%, rgba(212, 175, 55, 0.07) 0%, transparent 60%);
}
.part3d--flip::before {
    background:
        linear-gradient(90deg, rgba(11, 11, 11, 0.94) 0%, rgba(11, 11, 11, 0.72) 34%, rgba(11, 11, 11, 0) 56%),
        linear-gradient(180deg, #0b0b0b 0%, rgba(11, 11, 11, 0) 12%, rgba(11, 11, 11, 0) 88%, #0a0a0a 100%),
        radial-gradient(ellipse at 74% 50%, rgba(212, 175, 55, 0.07) 0%, transparent 60%);
}
.part3d--flip.part3d--cold::before {
    background:
        linear-gradient(90deg, rgba(11, 11, 11, 0.94) 0%, rgba(11, 11, 11, 0.72) 34%, rgba(11, 11, 11, 0) 56%),
        linear-gradient(180deg, #0b0b0b 0%, rgba(11, 11, 11, 0) 12%, rgba(11, 11, 11, 0) 88%, #0a0a0a 100%),
        radial-gradient(ellipse at 74% 50%, rgba(70, 130, 255, 0.09) 0%, transparent 60%);
}
.part3d::after {
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; z-index: 2;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.part3d-grid {
    position: relative; z-index: 2;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
    gap: 60px; align-items: center; min-height: 560px;
}
@media (min-width: 901px) {
    .part3d--flip .part3d-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
    .part3d--flip .part3d-stage { order: 2; }
}
.part3d-stage {
    position: relative; align-self: stretch; min-height: 520px;
    cursor: grab; touch-action: pan-y; -webkit-user-select: none; user-select: none;
}
.part3d-stage:active { cursor: grabbing; }
.part3d-anchor { position: absolute; inset: 0 0 40px 0; pointer-events: none; }
.part3d-hint {
    position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; width: max-content;
    display: flex; align-items: center; gap: 12px; pointer-events: none;
    font-size: 12px; font-weight: 600; letter-spacing: 2.5px; text-transform: uppercase; color: var(--gray);
}
.part3d-hint i { position: relative; width: 34px; height: 1px; background: var(--gold); opacity: 0.7; }
.part3d-hint i::before, .part3d-hint i::after {
    content: ""; position: absolute; top: -3px; width: 7px; height: 7px; border-top: 1px solid var(--gold);
}
.part3d-hint i::before { left: 0; border-left: 1px solid var(--gold); transform: rotate(-45deg); transform-origin: 0 0; top: 0; }
.part3d-hint i::after { right: 0; border-right: 1px solid var(--gold); transform: rotate(45deg); transform-origin: 100% 0; top: 0; }
.part3d-copy .service-pills { margin: 8px 0 32px; }
.part3d-ctas { display: flex; gap: 16px; flex-wrap: wrap; }

/* last frame of a part, kept on screen while its section scrolls away (see home-3d.js) */
.h3d-poster { position: absolute; inset: 0; display: block; width: 100%; height: 100%; visibility: hidden; pointer-events: none; }

.no-webgl .part3d-stage { display: none; }
.no-webgl .part3d-grid { grid-template-columns: minmax(0, 1fr); min-height: 0; }

.no-webgl .cta--3d {
    background:
        linear-gradient(135deg, rgba(10, 10, 10, 0.92), rgba(10, 10, 10, 0.85)),
        url('../../images/h-performance-035.jpg') center / cover;
    text-align: center;
}
.no-webgl .cta--3d { padding: 100px 0; }
.no-webgl .cta-run-stage, .no-webgl .cta-run-track { display: none; }
.no-webgl .cta--3d .cta-inner { margin: 0 auto; }

/* =========================================================================
   3. MOTION (only when html.hp-motion is set; reduced-motion users see the page as normal)
   ========================================================================= */

/* generic reveal: fade + rise (uses the `translate` property so hover transforms still work) */
.hp-motion [data-hp-reveal] {
    opacity: 0;
    translate: 0 28px;
    transition: opacity 0.9s ease var(--d, 0s), translate 1.1s var(--hp-ease) var(--d, 0s);
}
.hp-motion [data-hp-reveal].is-in { opacity: 1; translate: none; }

/* headlines: words rise out of a mask */
.hp-w { display: inline-block; overflow: hidden; vertical-align: top; padding: 0 0.03em 0.14em; margin: 0 -0.03em -0.14em; }
.hp-wi { display: inline-block; }
.hp-split-gold { background: none !important; }
.hp-motion .hp-split .hp-wi {
    transform: translateY(112%);
    transition: transform 1.05s var(--hp-ease);
    transition-delay: calc(var(--i, 0) * 60ms + var(--d, 0s));
}
.hp-motion .hp-split.is-in .hp-wi { transform: none; }

/* section tags: the gold lines draw out from the text, letters settle */
.hp-motion .section-tag { letter-spacing: 7px; transition: opacity 0.9s ease var(--d, 0s), translate 1.1s var(--hp-ease) var(--d, 0s), letter-spacing 1.4s var(--hp-ease) var(--d, 0s); }
.hp-motion .section-tag.is-in { letter-spacing: 3px; }
.hp-motion .section-tag::before,
.hp-motion .section-tag::after { transform: scaleX(0); transition: transform 1s var(--hp-ease) calc(var(--d, 0s) + 0.25s); }
.hp-motion .section-tag::before { transform-origin: 100% 50%; }
.hp-motion .section-tag::after { transform-origin: 0 50%; }
.hp-motion .section-tag.is-in::before,
.hp-motion .section-tag.is-in::after { transform: scaleX(1); }

/* hero intro */
.hp-motion .hero--3d .hero-title:not(.hp-split) { opacity: 0; }
.hp-motion .hero--3d [data-hp-intro] {
    opacity: 0;
    translate: 0 24px;
    transition: opacity 1s ease var(--d, 0s), translate 1.2s var(--hp-ease) var(--d, 0s);
}
.hp-motion .hero--3d.hp-intro [data-hp-intro] { opacity: 1; translate: none; }
.hp-motion .hero--3d .hero-stats { transition-property: opacity, translate, border-color; }

/* about: the photo opens like a shutter, then drifts with the scroll */
.hp-motion .about-image {
    clip-path: inset(0 0 100% 0 round 12px);
    transition: clip-path 1.5s var(--hp-ease-io);
}
.hp-motion .about-image.is-in { clip-path: inset(0 0 0 0 round 12px); }
.hp-motion .about-image.hp-done { clip-path: none; }
.hp-motion .about-image img {
    scale: 1.25;
    transition: scale 1.9s var(--hp-ease), transform 0.8s;
}
.hp-motion .about-image.is-in img { scale: 1.08; }
.hp-motion .about-image-badge {
    opacity: 0;
    translate: 24px 24px;
    transition: opacity 0.8s ease 0.95s, translate 1s var(--hp-ease) 0.95s;
}
.hp-motion .about-image.is-in .about-image-badge { opacity: 1; translate: none; }

/* services: photos settle as each card rises; cards tilt toward the pointer */
.hp-motion .service-card .service-card-image img {
    scale: 1.18;
    transition: scale 1.7s var(--hp-ease), transform 0.6s ease;
}
.hp-motion .service-card.visible .service-card-image img { scale: 1; }
.hp-motion .service-card.hp-tilt {
    transform: perspective(1000px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(-8px) !important;
    transition: transform 0.15s ease-out, border-color 0.3s, box-shadow 0.3s !important;
}

/* gallery: tiles ripple in */
.hp-motion .hp-stagger .gallery-item {
    opacity: 0;
    translate: 0 40px;
    scale: 0.94;
    transition: opacity 0.9s ease, translate 1.1s var(--hp-ease), scale 1.1s var(--hp-ease);
    transition-delay: calc(var(--i, 0) * 70ms);
}
.hp-motion .hp-stagger.is-in .gallery-item { opacity: 1; translate: none; scale: 1; }

/* reviews: the Google badge pops in */
.hp-motion .google-badge { scale: 0.92; transition: scale 1s var(--hp-ease) calc(var(--d, 0s) + 0.1s); }
.hp-motion .reviews-rating.is-in .google-badge { scale: 1; }

/* =========================================================================
   4. RESPONSIVE
   ========================================================================= */
@media (max-width: 900px) {
    .hero--3d { align-items: flex-end; min-height: 0; }
    .hero--3d .hero-content { padding-top: calc(min(38vh, 300px) + 46px); padding-bottom: 76px; }
    .h3d-hero-anchor { left: 0; width: auto; bottom: auto; top: 6px; height: calc(min(38vh, 300px) - 46px); }
    .rev--hero {
        left: 0; right: 0; bottom: auto; margin: 0 auto; width: max-content; transform: none;
        top: calc(min(38vh, 300px) - 36px);
    }

    .part3d { padding: 70px 0 80px; }
    .part3d::before,
    .part3d--flip::before,
    .part3d--flip.part3d--cold::before {
        background:
            linear-gradient(0deg, rgba(11, 11, 11, 0.96) 0%, rgba(11, 11, 11, 0.85) 48%, rgba(11, 11, 11, 0) 64%),
            linear-gradient(180deg, #0b0b0b 0%, rgba(11, 11, 11, 0) 10%);
    }
    .part3d-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; min-height: 0; }
    .part3d-stage { min-height: 360px; }
    .hero--3d::before {
        background:
            linear-gradient(0deg, #141414 0%, rgba(10, 10, 10, 0.94) 22%, rgba(10, 10, 10, 0.78) 52%, rgba(10, 10, 10, 0) 72%),
            radial-gradient(ellipse at 50% 10%, rgba(212, 175, 55, 0.12) 0%, transparent 55%);
    }
    .hero--3d .hero-title { font-size: clamp(2.1rem, 8.6vw, 3rem); letter-spacing: -1px; }

    .cta--3d { padding: 30px 0 90px; }
    .cta--3d::before {
        background:
            linear-gradient(0deg, rgba(10, 10, 10, 0.97) 0%, rgba(10, 10, 10, 0.86) 46%, rgba(10, 10, 10, 0) 64%),
            linear-gradient(180deg, #0a0a0a 0%, rgba(10, 10, 10, 0) 10%);
    }
    .cta-run-stage { height: 320px; }
    .cta-run-track { display: none; }
    .cta--3d .cta-inner { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .h3d-canvas { transition: none; }
}
