/* ==========================================================================
   Millwards Digital - Animation Styles
   Cinematic opening, 3D effects, scroll animations, transitions
   ========================================================================== */

/* ---------- Cinematic Opening Overlay ---------- */
.cinematic-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: radial-gradient(ellipse at center, #0d0d1a 0%, #0a0a0f 100%);
    display: none;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.cinematic-overlay.active {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

.cinematic-overlay.hidden {
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reduced-motion overlay: still visible, but animations are near-instant via
   prefers-reduced-motion media query. JS sets this class when the user
   prefers reduced motion so the overlay can be shown without complex effects. */
.cinematic-overlay.reduced-motion {
    /* No special display override needed — .active handles visibility.
       The prefers-reduced-motion media query already speeds up all child
       animations via animation-duration: 0.01ms !important. */
}

.cinematic-content {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Blocks Container — z-index ensures blocks always render above the grid */
.cinematic-blocks-container {
    position: absolute;
    inset: 0;
    z-index: 2;
}

/* Base Block Style */
.cinematic-block {
    position: absolute;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    opacity: 0;
    will-change: transform, opacity;
}

/* Nav block - thin horizontal bar */
.cinematic-block-nav {
    background: linear-gradient(90deg, rgba(0, 212, 255, 0.1), rgba(124, 58, 237, 0.1));
    border-color: rgba(0, 212, 255, 0.25);
}

/* Hero block - large area */
.cinematic-block-hero {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.06), rgba(124, 58, 237, 0.1), rgba(236, 72, 153, 0.04));
    border-color: rgba(0, 212, 255, 0.18);
}

/* Service card blocks - medium squares */
.cinematic-block-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    border-color: rgba(124, 58, 237, 0.25);
}

.cinematic-block-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.5), transparent);
    border-radius: 0 0 2px 2px;
}

/* Pricing blocks - tall cards */
.cinematic-block-pricing {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
    border-color: rgba(255, 255, 255, 0.1);
    border-radius: 14px;
}

/* Footer block - thin bar at bottom */
.cinematic-block-footer {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
    border-color: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

/* Drop Animation - triggered by .dropping class */
.cinematic-block.dropping {
    animation: blockDrop 0.5s cubic-bezier(0.25, 0.1, 0.25, 1) both;
}

/* ---------- Block Animation Keyframes ---------- */

@keyframes blockDrop {
    0% {
        transform: translateY(var(--drop-offset, -120vh));
        opacity: 0.12;
    }
    25% {
        opacity: 0.5;
    }
    55% {
        transform: translateY(12px);
        opacity: 1;
    }
    75% {
        transform: translateY(-4px);
    }
    90% {
        transform: translateY(2px);
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}


/* ---------- Cinematic Grid Background ---------- */
.cinematic-grid {
    position: absolute;
    inset: 0;
    z-index: 1;
    background-image:
        linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    opacity: 0;
    transform: perspective(800px) rotateX(30deg) translateY(20%);
    transform-origin: center bottom;
}

.cinematic-grid.active {
    animation: gridReveal 2s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

@keyframes gridReveal {
    0% {
        opacity: 0;
        transform: perspective(800px) rotateX(50deg) translateY(30%);
    }
    40% {
        opacity: 1;
    }
    100% {
        opacity: 0.6;
        transform: perspective(800px) rotateX(25deg) translateY(10%);
    }
}

.cinematic-grid.fade-out {
    animation: gridFade 0.5s ease-out forwards;
}

@keyframes gridFade {
    to {
        opacity: 0;
    }
}

/* ---------- Cinematic Color Sweep ---------- */
.cinematic-sweep {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(0, 212, 255, 0.08) 30%,
        rgba(124, 58, 237, 0.08) 70%,
        transparent 100%
    );
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

.cinematic-sweep.active {
    animation: colorSweep 1.5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

@keyframes colorSweep {
    0% {
        transform: translateX(-100%);
        opacity: 1;
    }
    80% {
        opacity: 1;
    }
    100% {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ---------- Cinematic Flash ---------- */
.cinematic-flash {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(0, 212, 255, 0.3), transparent 70%);
    opacity: 0;
    pointer-events: none;
    z-index: 15;
}

.cinematic-flash.active {
    animation: flashPulse 0.6s ease-out forwards;
}

@keyframes flashPulse {
    0% { opacity: 0; }
    30% { opacity: 1; }
    100% { opacity: 0; }
}

/* ---------- Cinematic Title Reveal ---------- */
.cinematic-title {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
}

.cinematic-title.reveal {
    animation: titleReveal 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.cinematic-title-text {
    font-family: 'Inter', sans-serif;
    font-size: clamp(2rem, 6vw, 5rem);
    font-weight: 900;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #00d4ff, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
}

@keyframes titleReveal {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
        filter: blur(10px);
    }
    60% {
        opacity: 1;
        filter: blur(0);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
        filter: blur(0);
    }
}

/* ---------- Cinematic Screen Shake ---------- */
@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-2px, -1px); }
    20% { transform: translate(2px, 1px); }
    30% { transform: translate(-1px, 2px); }
    40% { transform: translate(1px, -1px); }
    50% { transform: translate(-1px, 1px); }
    60% { transform: translate(1px, 0); }
    70% { transform: translate(0, -1px); }
    80% { transform: translate(-1px, 0); }
    90% { transform: translate(1px, 1px); }
}

.cinematic-content.shake {
    animation: screenShake 0.3s ease-out;
}

/* ---------- Scroll Reveal Animations ---------- */
.animate-ready[data-animate] {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.7s cubic-bezier(0.25, 0.1, 0.25, 1),
                transform 0.7s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.animate-ready[data-animate="fade-up"].visible {
    opacity: 1;
    transform: translateY(0);
}

.animate-ready[data-animate="fade-left"] {
    transform: translateX(-40px);
}

.animate-ready[data-animate="fade-left"].visible {
    opacity: 1;
    transform: translateX(0);
}

.animate-ready[data-animate="fade-right"] {
    transform: translateX(40px);
}

.animate-ready[data-animate="fade-right"].visible {
    opacity: 1;
    transform: translateX(0);
}

.animate-ready[data-animate="scale-in"] {
    transform: scale(0.9);
}

.animate-ready[data-animate="scale-in"].visible {
    opacity: 1;
    transform: scale(1);
}

/* ---------- 3D Card Hover Effects ---------- */
.service-card {
    transform-style: preserve-3d;
    will-change: transform;
}

.service-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(
        600px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
        rgba(0, 212, 255, 0.06),
        transparent 40%
    );
    opacity: 0;
    transition: opacity var(--transition-base);
    pointer-events: none;
}

.service-card:hover::after {
    opacity: 1;
}

/* ---------- Animated Background Shapes ---------- */
.hero-bg-shapes .shape {
    --shape-base-transform: translate(0, 0);
    animation: shape-float 20s ease-in-out infinite;
}

.shape-1 {
    animation-delay: 0s;
}

.shape-2 {
    animation-delay: -7s;
}

.shape-3 {
    --shape-base-transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes shape-float {
    0%, 100% {
        transform: var(--shape-base-transform) translate(0, 0) rotate(0deg) scale(1);
    }
    25% {
        transform: var(--shape-base-transform) translate(30px, -30px) rotate(5deg) scale(1.05);
    }
    50% {
        transform: var(--shape-base-transform) translate(-20px, 20px) rotate(-3deg) scale(0.95);
    }
    75% {
        transform: var(--shape-base-transform) translate(15px, 15px) rotate(3deg) scale(1.02);
    }
}

/* ---------- Gradient Border Animation ---------- */
.service-card::before,
.why-card::before {
    transition: transform 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* ---------- Parallax Layer Effects ---------- */
.parallax-layer {
    will-change: transform;
    transition: transform 0.1s linear;
}

/* ---------- Stat Counter Animation ---------- */
.stat-number {
    font-variant-numeric: tabular-nums;
}

/* ---------- Pricing Card 3D Tilt ---------- */
.pricing-card {
    transform-style: preserve-3d;
    will-change: transform;
    transition: transform var(--transition-base);
}

.pricing-card:not(.pricing-card-popular):hover {
    transform: translateY(-8px) rotateX(3deg);
}

.pricing-card-popular:hover {
    transform: scale(1.05) translateY(-4px);
}

@media (max-width: 768px), (hover: none), (pointer: coarse) {
    .pricing-card,
    .pricing-card:not(.pricing-card-popular):hover,
    .pricing-card-popular:hover {
        transform: none;
        transform-style: flat;
        will-change: auto;
    }
}

/* ===== Mobile Animation Reduction =====
   Disable continuous keyframe animations on phones to free the compositor. */
@media (max-width: 768px) {
    /* Stop infinite shape float animation */
    .hero-bg-shapes .shape {
        animation: none;
    }

    /* Remove hover-intent 3D card transforms — they do nothing on touch anyway */
    .service-card {
        transform-style: flat;
        will-change: auto;
    }

    .service-card::after {
        display: none;
    }

    /* Reduce cinematic block complexity on mobile */
    .cinematic-block {
        border-radius: 8px;
        border: none;
    }
    .cinematic-block-pricing,
    .cinematic-block-footer {
        display: none;
    }

    /* Stop glow-pulse on buttons */
    .btn-glow:hover {
        animation: none;
    }

    /* Stop shimmer loading effect */
    .shimmer {
        animation: none;
    }

    /* Disable hover-based transforms that do nothing on touch */
    .service-card:hover {
        transform: none;
    }

    .service-card:hover .service-icon {
        transform: none;
    }
}

/* ---------- Glow Pulse Animation ---------- */
@keyframes glow-pulse {
    0%, 100% {
        box-shadow: 0 0 20px rgba(0, 212, 255, 0.2),
                    0 0 40px rgba(0, 212, 255, 0.1);
    }
    50% {
        box-shadow: 0 0 30px rgba(0, 212, 255, 0.3),
                    0 0 60px rgba(0, 212, 255, 0.15);
    }
}

.btn-glow:hover {
    animation: glow-pulse 2s ease-in-out infinite;
}



/* ---------- Loading Shimmer ---------- */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.shimmer {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.05) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 2s ease-in-out infinite;
}

/* ---------- Ripple Effect on Button Click ---------- */
.btn-primary .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: ripple-anim 0.6s ease-out forwards;
    pointer-events: none;
}

@keyframes ripple-anim {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ---------- Navbar Scroll Transition ---------- */
.navbar {
    transition: background 0.4s ease, backdrop-filter 0.4s ease, border-color 0.4s ease;
}

.navbar.scrolled .nav-link {
    color: var(--color-text-secondary);
}

/* ---------- Smooth Section Transitions ---------- */
.section {
    transition: opacity 0.3s ease;
}

/* ---------- Mobile Menu Overlay ---------- */
.navbar::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
    z-index: 1;
}

.navbar.menu-open::before {
    opacity: 1;
    pointer-events: auto;
}

/* ---------- Accessibility: Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .animate-ready[data-animate] {
        opacity: 1;
        transform: none;
    }

    /* Don't hide the overlay — let JS decide.
       Reduced-motion users still see the overlay but with simplified animations. */

    /* Speed up block drop for reduced-motion */
    .cinematic-block.dropping {
        animation-duration: 0.05s !important;
    }

    /* Speed up grid reveal for reduced-motion */
    .cinematic-grid.active {
        animation-duration: 0.05s !important;
    }

    /* Speed up title reveal for reduced-motion */
    .cinematic-title.reveal {
        animation-duration: 0.05s !important;
    }

    html {
        scroll-behavior: auto;
    }

    /* Also disable GPU-heavy effects for reduced-motion users */
    #three-canvas {
        display: none !important;
    }

    .hero-bg-shapes .shape {
        animation: none;
    }

    .glass-card {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

/* ---------- Print Styles ---------- */
@media print {
    .cinematic-overlay,
    #three-canvas,
    .hero-bg-shapes,
    .hero-scroll-indicator {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .glass-card {
        background: #f5f5f5;
        border: 1px solid #ddd;
        backdrop-filter: none;
    }
}
