/* =========================================================
   MOTION SYSTEM — Animations, reveals, and scroll-driven transitions
   ========================================================= */

/* --- Respect user motion preferences globally --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* =========================================================
   TIMING & EASING VARIABLES
   ========================================================= */
:root {
    /* Durations */
    --duration-fast:     0.15s;
    --duration-normal:   0.3s;
    --duration-slow:     0.6s;
    --duration-slower:   0.9s;

    /* Easing curves */
    --ease-in-out-cubic: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out-quad:     cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --ease-out-cubic:    cubic-bezier(0.215, 0.61, 0.355, 1);
    --ease-out-quart:    cubic-bezier(0.165, 0.84, 0.44, 1);
}

/* =========================================================
   KEYFRAME ANIMATIONS
   ========================================================= */

/* --- Fade animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* --- Slide animations --- */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(32px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-32px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideLeft {
    from { opacity: 0; transform: translateX(32px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideRight {
    from { opacity: 0; transform: translateX(-32px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* --- Combined fade + move --- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(28px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeUpSmall {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Scale animations --- */
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes scaleUpIn {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}

/* --- Blur to sharp (for text reveals) --- */
@keyframes blurToSharp {
    from { opacity: 0.2; filter: blur(8px); }
    50%  { opacity: 0.6; filter: blur(4px); }
    to   { opacity: 1; filter: blur(0); }
}

/* --- Mask reveal (edge inward) --- */
@keyframes maskRevealLR {
    from { 
        -webkit-mask-image: linear-gradient(to right, transparent 0%, transparent 0%, black 100%);
        mask-image: linear-gradient(to right, transparent 0%, transparent 0%, black 100%);
    }
    to { 
        -webkit-mask-image: linear-gradient(to right, black 0%, black 100%, black 100%);
        mask-image: linear-gradient(to right, black 0%, black 100%, black 100%);
    }
}

@keyframes maskRevealTB {
    from { 
        -webkit-mask-image: linear-gradient(to bottom, transparent 0%, transparent 0%, black 100%);
        mask-image: linear-gradient(to bottom, transparent 0%, transparent 0%, black 100%);
    }
    to { 
        -webkit-mask-image: linear-gradient(to bottom, black 0%, black 100%, black 100%);
        mask-image: linear-gradient(to bottom, black 0%, black 100%, black 100%);
    }
}

/* --- Scroll bounce (chevrons) --- */
@keyframes scrollBounce {
    0%, 100% { opacity: 0.25; }
    50%       { opacity: 0.9; }
}

@keyframes chevronBounce {
    0%   { transform: translateY(0); opacity: 0.3; }
    50%  { opacity: 0.8; }
    100% { transform: translateY(8px); opacity: 0.3; }
}

/* --- Glow animations (for accents) --- */
@keyframes glowPulse {
    0%, 100% { opacity: 0.4; box-shadow: 0 0 20px rgba(232,160,18,0.4); }
    50%      { opacity: 0.8; box-shadow: 0 0 32px rgba(232,160,18,0.7); }
}

@keyframes borderGlow {
    0%, 100% { border-color: rgba(232,160,18,0.3); }
    50%      { border-color: rgba(232,160,18,0.8); }
}

/* --- Line draw (for dividers & borders) --- */
@keyframes lineDraw {
    from { 
        width: 0;
        opacity: 0;
    }
    to { 
        width: 100%;
        opacity: 1;
    }
}

/* --- Float (subtle floating motion for CTAs) --- */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50%      { transform: translateY(-8px); }
}

/* --- Shimmer (for loading placeholders) --- */
@keyframes shimmer {
    0% { background-position: -1000px 0; }
    100% { background-position: 1000px 0; }
}

/* --- Toast flow (forms notification) --- */
@keyframes toastSlideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastSlideDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(16px);
    }
}

/* =========================================================
   REVEAL UTILITY CLASSES
   ========================================================= */

/* --- Basic fade reveal --- */
.reveal-fade {
    opacity: 0;
    animation: fadeIn var(--duration-slow) var(--ease-in-out-cubic) forwards;
}

/* --- Slide up reveal --- */
.reveal-slide-up {
    opacity: 0;
    transform: translateY(32px);
    animation: slideUp var(--duration-slow) var(--ease-out-cubic) forwards;
}

.reveal-slide-up-small {
    opacity: 0;
    transform: translateY(16px);
    animation: slideUp var(--duration-normal) var(--ease-out-cubic) forwards;
}

/* --- Scale reveal --- */
.reveal-scale {
    opacity: 0;
    transform: scale(0.92);
    animation: scaleIn var(--duration-slow) var(--ease-out-cubic) forwards;
}

.reveal-scale-up {
    opacity: 0;
    transform: scale(0.85);
    animation: scaleUpIn var(--duration-slow) var(--ease-out-cubic) forwards;
}

/* --- Blur to sharp (text focus) --- */
.reveal-blur-to-sharp {
    opacity: 0.2;
    filter: blur(8px);
    animation: blurToSharp var(--duration-slow) var(--ease-in-out-cubic) forwards;
}

/* --- Mask reveal (image enters from top) --- */
.reveal-mask-tb {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 100%);
    mask-image: linear-gradient(to bottom, transparent 0%, black 100%);
    animation: maskRevealTB var(--duration-slow) var(--ease-in-out-cubic) forwards;
}

.reveal-mask-lr {
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 100%);
    mask-image: linear-gradient(to right, transparent 0%, black 100%);
    animation: maskRevealLR var(--duration-slow) var(--ease-in-out-cubic) forwards;
}

/* =========================================================
   STAGGER DELAYS (apply with data-stagger-delay or class)
   ========================================================= */

/* Auto-stagger children by index (apply to parent) */
.reveal-stagger > * {
    opacity: 0;
    animation: slideUp var(--duration-slow) var(--ease-out-cubic) forwards;
}

.reveal-stagger > *:nth-child(1) { animation-delay: 0ms; }
.reveal-stagger > *:nth-child(2) { animation-delay: 80ms; }
.reveal-stagger > *:nth-child(3) { animation-delay: 160ms; }
.reveal-stagger > *:nth-child(4) { animation-delay: 240ms; }
.reveal-stagger > *:nth-child(5) { animation-delay: 320ms; }
.reveal-stagger > *:nth-child(6) { animation-delay: 400ms; }
.reveal-stagger > *:nth-child(7) { animation-delay: 480ms; }
.reveal-stagger > *:nth-child(8) { animation-delay: 560ms; }
.reveal-stagger > *:nth-child(n+9) { animation-delay: 640ms; }

/* Tighter stagger (60ms between items) */
.reveal-stagger-tight > * {
    opacity: 0;
    animation: slideUp var(--duration-slow) var(--ease-out-cubic) forwards;
}

.reveal-stagger-tight > *:nth-child(1) { animation-delay: 0ms; }
.reveal-stagger-tight > *:nth-child(2) { animation-delay: 60ms; }
.reveal-stagger-tight > *:nth-child(3) { animation-delay: 120ms; }
.reveal-stagger-tight > *:nth-child(4) { animation-delay: 180ms; }
.reveal-stagger-tight > *:nth-child(5) { animation-delay: 240ms; }
.reveal-stagger-tight > *:nth-child(6) { animation-delay: 300ms; }
.reveal-stagger-tight > *:nth-child(7) { animation-delay: 360ms; }
.reveal-stagger-tight > *:nth-child(n+8) { animation-delay: 420ms; }

/* Looser stagger (150ms between items) */
.reveal-stagger-loose > * {
    opacity: 0;
    animation: slideUp var(--duration-slow) var(--ease-out-cubic) forwards;
}

.reveal-stagger-loose > *:nth-child(1) { animation-delay: 0ms; }
.reveal-stagger-loose > *:nth-child(2) { animation-delay: 150ms; }
.reveal-stagger-loose > *:nth-child(3) { animation-delay: 300ms; }
.reveal-stagger-loose > *:nth-child(n+4) { animation-delay: 450ms; }

/* =========================================================
   HOVER & INTERACTION EFFECTS
   ========================================================= */

/* --- Image hover: subtle lift + sharpen --- */
.img-hover-lift img {
    transition: transform var(--duration-fast) var(--ease-out-quad),
                filter var(--duration-fast) var(--ease-out-quad);
}

.img-hover-lift:hover img {
    transform: translateY(-8px);
    filter: brightness(1.08) contrast(1.05);
}

.img-hover-lift:active img {
    transform: translateY(-4px);
}

/* --- Image hover: scale + glow --- */
.img-hover-scale img {
    transition: transform var(--duration-fast) var(--ease-out-quad),
                filter var(--duration-fast) var(--ease-out-quad),
                box-shadow var(--duration-fast) var(--ease-out-quad);
}

.img-hover-scale:hover img {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* --- Text hover: color shift + underline grow --- */
.text-hover-accent {
    position: relative;
    transition: color var(--duration-fast) var(--ease-out-quad);
}

.text-hover-accent::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--color-accent);
    transition: width var(--duration-normal) var(--ease-out-quad);
}

.text-hover-accent:hover {
    color: var(--color-accent-hover);
}

.text-hover-accent:hover::after {
    width: 100%;
}

/* --- Card hover: lift + glow --- */
.card-hover-lift {
    transition: transform var(--duration-fast) var(--ease-out-quad),
                box-shadow var(--duration-fast) var(--ease-out-quad),
                border-color var(--duration-fast) var(--ease-out-quad);
}

.card-hover-lift:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 48px rgba(0,0,0,0.4), 
                0 0 32px rgba(232,160,18,0.15);
    border-color: rgba(232,160,18,0.6);
}

.card-hover-lift:active {
    transform: translateY(-4px);
}

/* --- Button hover: scale + glow --- */
.btn-hover-glow {
    transition: transform var(--duration-fast) var(--ease-out-quad),
                box-shadow var(--duration-fast) var(--ease-out-quad),
                background var(--duration-fast) var(--ease-out-quad);
}

.btn-hover-glow:hover {
    transform: scale(1.04);
    box-shadow: 0 0 24px rgba(232,160,18,0.4);
}

.btn-hover-glow:active {
    transform: scale(0.98);
}

/* --- Focus states (keyboard accessibility) --- */
.focus-ring:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
    border-radius: var(--radius);
}

.focus-ring-inner:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

/* =========================================================
   SCROLL-DRIVEN TRANSFORMS
   ========================================================= */

/* --- Parallax effect (background moves slower) --- */
.parallax-bg {
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

@media (max-width: 768px) {
    .parallax-bg {
        background-attachment: scroll;
    }
}

/* --- Scroll hint (animated chevrons) --- */
.scroll-hint {
    animation: chevronBounce 2s ease-in-out infinite;
}

.scroll-hint span:nth-child(2) { animation-delay: 0.2s; }
.scroll-hint span:nth-child(3) { animation-delay: 0.4s; }

/* =========================================================
   SPECIAL REVEALS (Content type specific)
   ========================================================= */

/* --- Heading reveal: blur to sharp with slight delay --- */
.heading-reveal {
    opacity: 0.1;
    filter: blur(6px);
    animation: blurToSharp var(--duration-slow) var(--ease-in-out-cubic) forwards;
}

/* --- Paragraph block reveal: fade + upward --- */
.block-reveal {
    opacity: 0;
    transform: translateY(20px);
    animation: slideUp var(--duration-normal) var(--ease-out-cubic) forwards;
}

/* --- Quote reveal: left border draws in, text fades --- */
.quote-reveal {
    opacity: 0;
    border-left-width: 0;
    animation: slideUp var(--duration-slow) var(--ease-out-cubic) forwards;
}

.quote-reveal::before {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 0;
    background: var(--color-accent);
    animation: slideDown var(--duration-slow) var(--ease-out-cubic) forwards;
}

/* --- Divider reveal: line draws from left --- */
.divider-reveal {
    width: 0;
    animation: lineDraw var(--duration-normal) var(--ease-out-cubic) forwards 0.2s;
}

/* --- CTA reveal: scale up + glow entry --- */
.cta-reveal {
    opacity: 0;
    transform: scale(0.92);
    animation: scaleIn var(--duration-slow) var(--ease-out-cubic) forwards;
}

.cta-reveal::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(232,160,18,0.3) 0%, transparent 70%);
    opacity: 0;
    animation: glowPulse var(--duration-normal) var(--ease-in-out-cubic) forwards 0.3s;
}

/* =========================================================
   RETURN-TO-TOP BUTTON STYLES
   ========================================================= */

.scroll-to-top {
    position: fixed;
    bottom: 32px;
    right: max(32px, env(safe-area-inset-right));
    z-index: 99;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #000;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(232,160,18,0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px);
    transition: opacity var(--duration-normal) var(--ease-in-out-cubic),
                visibility var(--duration-normal) var(--ease-in-out-cubic),
                transform var(--duration-normal) var(--ease-in-out-cubic),
                background var(--duration-fast) var(--ease-out-quad);
}

.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-to-top:hover {
    background: var(--color-accent-hover);
    box-shadow: 0 8px 28px rgba(232,160,18,0.5);
    transform: translateY(-4px);
}

.scroll-to-top:active {
    transform: translateY(-2px);
}

.scroll-to-top svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

/* Mobile adjustments */
@media (max-width: 900px) {
    .scroll-to-top {
        bottom: 16px;
        right: max(20px, env(safe-area-inset-right));
    }
}

@media (max-width: 480px) {
    .scroll-to-top {
        bottom: 16px;
        right: max(20px, env(safe-area-inset-right));
        width: 44px;
        height: 44px;
    }
}

/* =========================================================
   SCROLL PROGRESS INDICATOR
   ========================================================= */

.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--color-accent) 0%, var(--color-accent-hover) 100%);
    width: 0%;
    z-index: 101;
    opacity: 0.6;
    transition: width var(--duration-fast) linear, opacity var(--duration-normal) ease;
}

.scroll-progress.visible {
    opacity: 0.8;
}

/* =========================================================
   REDUCED MOTION SAFE ANIMATIONS
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    /* Disable all animations, use instant transitions instead */
    .reveal-fade,
    .reveal-slide-up,
    .reveal-slide-up-small,
    .reveal-scale,
    .reveal-scale-up,
    .reveal-blur-to-sharp,
    .reveal-mask-tb,
    .reveal-mask-lr,
    .heading-reveal,
    .block-reveal,
    .quote-reveal,
    .divider-reveal,
    .cta-reveal {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
        -webkit-mask-image: none !important;
        mask-image: none !important;
        border-left-width: 4px !important;
        width: 100% !important;
    }

    .reveal-stagger > *,
    .reveal-stagger-tight > *,
    .reveal-stagger-loose > * {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        animation-delay: 0 !important;
    }

    /* Simplify interactions */
    .img-hover-lift img,
    .img-hover-scale img,
    .card-hover-lift,
    .btn-hover-glow {
        transition: none !important;
    }

    /* Return to top still visible but no animation */
    .scroll-to-top {
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
}
