/* ============================================================================
   CSS VARIABLES
   ============================================================================ */

:root {
    --main: Arya, sans-serif;
    --accent: #3ecb1ebf;
    --bg-color: #ffffff;
    --text-main: #000000;
    --text-secondary: rgba(0, 0, 0, 0.7);
    --text-muted: rgba(0, 0, 0, 0.5);
    --nav-scrolled-bg: rgba(0, 0, 0, 0.5);
    --loader-bg: #000000;
    --border-main: #ffffff;
    --wall-bg: url('../resources/wall-light.svg');
    --bg-opacity: 0.55;
    /* Cursor-reveal variables */
    --cursor-x: -100vw;
    --cursor-y: -100vh;
    --reveal-radius: 140px;
    --reveal-softness: 60px;
}

/* Dark Mode Variables */
body.dark-mode {
    --bg-color: #000000;
    --text-main: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.5);
    --wall-bg: url('../resources/wall-dark.svg');
    --bg-opacity: 0.4;
}

/* ============================================================================
   GLOBAL RESET
   ============================================================================ */

*, *::before, *::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

/* ============================================================================
   BASE STYLES
   ============================================================================ */

html {
    height: 100%;
    min-height: 100vh;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    position: relative;
    height: 100%;
    min-height: 100vh;
    color: var(--text-main);
    background: var(--bg-color) !important;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: var(--main);
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background-image: var(--bg-image, url('../resources/MAIN.png'));
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: var(--bg-opacity);
    z-index: 0;
    transition: opacity 0.3s ease;
}

@keyframes backgroundFloat {
    0%, 100% {
        transform: rotate(0deg) scale(1);
        opacity: 1;
    }
    25% {
        transform: rotate(45deg) scale(1.05);
        opacity: 0.7;
    }
    50% {
        transform: rotate(90deg) scale(1.1);
        opacity: 0.9;
    }
    75% {
        transform: rotate(45deg) scale(1.05);
        opacity: 0.7;
    }
}

/* ============================================================================
   FRONT WALL LAYERS
   ============================================================================ */

.front-wall {
    background-image: var(--wall-bg);
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    position: fixed;
    height: 100vh;
    width: 100vw;
    z-index: 0;
    opacity: 0.5;
    transition: background-image 0.3s ease;
}

/* Inverse overlay revealed around the cursor */
.front-wall-inverse {
    background-image: var(--wall-bg);
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    position: fixed;
    height: 100vh;
    width: 100vw;
    z-index: 1; /* above the base wall, below UI */
    pointer-events: none;
    /* Create an inverse look without needing a second asset */
    -webkit-filter: invert(1) hue-rotate(180deg);
    filter: invert(1) hue-rotate(180deg);
    opacity: 0; /* default hidden; shown via .active */
    /* Soft circular reveal using mask (with -webkit- prefix for Safari) */
    /* Soft blur edge using a feathered radial gradient */
    -webkit-mask-image: radial-gradient(
        circle at var(--cursor-x) var(--cursor-y),
        rgba(0, 0, 0, 0.6) 0 calc(var(--reveal-radius) - var(--reveal-softness)),
        rgba(0, 0, 0, 0) var(--reveal-radius)
    );
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: 100% 100%;
    mask-image: radial-gradient(
        circle at var(--cursor-x) var(--cursor-y),
        rgba(0, 0, 0, 0.6) 0 calc(var(--reveal-radius) - var(--reveal-softness)),
        rgba(0, 0, 0, 0) var(--reveal-radius)
    );
    mask-repeat: no-repeat;
    mask-size: 100% 100%;
    /* Hard-edge fallback for browsers without mask support */
    -webkit-clip-path: circle(var(--reveal-radius) at var(--cursor-x) var(--cursor-y));
    clip-path: circle(var(--reveal-radius) at var(--cursor-x) var(--cursor-y));
    -webkit-transition: opacity 0.8s ease-out, -webkit-filter 0.2s ease;
    transition: opacity 0.8s ease-out, filter 0.2s ease;
    /* Safari-specific: avoid will-change on mask properties as it can cause issues */
}

.front-wall-inverse.active {
    opacity: 0.9;
}

@media (prefers-reduced-motion: reduce) {
    .front-wall-inverse {
        -webkit-transition: opacity 0.1s linear, -webkit-filter 0.1s linear;
        transition: opacity 0.1s linear, filter 0.1s linear;
        animation: none;
    }
}

/* Safari-specific optimization: disable expensive cursor overlay on desktop Safari */
@media not all and (min-resolution:.001dpcm) {
    @supports (-webkit-appearance:none) {
        .front-wall-inverse {
            display: none !important;
        }
    }
}

/* ============================================================================
   LOADER
   ============================================================================ */

.loader-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000000;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.loader-circle {
    position: absolute;
    width: 10rem;
    height: 10rem;
    background-size: contain;
    background-repeat: no-repeat;
    animation: loaderSpin 2s ease-in-out infinite;
}

.circle-1 {
    background-image: url('../resources/loading-l.png');
    animation-delay: 0s;
}

.circle-2 {
    background-image: url('../resources/loading-m.png');
    animation-delay: 0.1s;
}

.circle-3 {
    background-image: url('../resources/loading-s.png');
    animation-delay: 0.2s;
}

@keyframes loaderSpin {
    0%, 100% {
        transform: scale(1) rotate(0deg);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.2) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(360deg);
        opacity: 0.8;
    }
}

/* ============================================================================
   RESPONSIVE DESIGN - MEDIA QUERIES
   ============================================================================ */

/* TABLET OPTIMIZATIONS */
@media (max-width: 1024px) {
    body::before {
        background-size: cover;
        /* filter: blur(150px) contrast(1.8); */
    }

    .front-wall,
    .front-wall-inverse {
        background-size: cover;
        height: 100vh;
        width: 100vw;
    }

    .loader-circle {
        width: 8rem;
        height: 8rem;
    }
}

/* MOBILE OPTIMIZATIONS */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    body::before {
        background-size: cover;
        /* filter: blur(100px) contrast(1.5); */
        /* animation: backgroundFloatMobile 20s ease-in-out infinite; */
    }

    @keyframes backgroundFloatMobile {
        0%, 100% {
            transform: rotate(0deg) scale(1);
            opacity: 0.8;
        }
        50% {
            transform: rotate(45deg) scale(1.05);
            opacity: 0.6;
        }
    }

    .front-wall,
    .front-wall-inverse {
        background-size: cover;
        height: 100vh;
        width: 100vw;
        background-position: center center;
    }

    .front-wall-inverse {
        -webkit-filter: invert(1) hue-rotate(180deg);
        filter: invert(1) hue-rotate(180deg);
        -webkit-transition: opacity 0.4s ease-out;
        transition: opacity 0.4s ease-out;
    }

    .loader-circle {
        width: 6rem;
        height: 6rem;
    }

    :root {
        --reveal-radius: 100px;
        --reveal-softness: 40px;
    }
}

/* SMALL MOBILE OPTIMIZATIONS */
@media (max-width: 480px) {
    html {
        font-size: 13px;
    }

    body::before {
        background-size: cover;
        /* filter: blur(80px) contrast(1.3); */
    }

    .front-wall,
    .front-wall-inverse {
        height: 100vh;
        width: 100vw;
    }

    .loader-circle {
        width: 5rem;
        height: 5rem;
    }

    :root {
        --reveal-radius: 80px;
        --reveal-softness: 30px;
    }
}

/* PERFORMANCE OPTIMIZATIONS FOR MOBILE */
@media (max-width: 768px) {
    @media (prefers-reduced-motion: reduce) {
        body::before {
            animation: none;
            /* filter: blur(60px) contrast(1.2); */
        }

        .front-wall-inverse {
            transition: opacity 0.2s linear;
        }

        .loader-circle {
            animation: none;
        }
    }
}

/* LANDSCAPE MOBILE */
@media (max-width: 926px) and (orientation: landscape) {
    body::before {
        background-size: cover;
        /* filter: blur(120px) contrast(1.6); */
    }

    .front-wall,
    .front-wall-inverse {
        height: 100vh;
        width: 100vw;
    }

    .loader-circle {
        width: 5.5rem;
        height: 5.5rem;
    }
}

/* ======================================================================
   SAFARI DESKTOP QUALITY FIXES
   ====================================================================== */

/* Target Safari (WebKit) but not iOS */
@supports (-webkit-appearance: none) and (not (-webkit-touch-callout: none)) {
    body::before {
        background-size: cover;
        /* filter: blur(150px) contrast(1.4); */
    }

    .front-wall-inverse {
        -webkit-filter: invert(0.8) hue-rotate(150deg);
        filter: invert(0.8) hue-rotate(150deg);

        /* keep mask/clip-path from base rule so cursor reveal still works */
        opacity: 0; /* default hidden; shown via .active */
        -webkit-transition: opacity 0.4s ease-out;
        transition: opacity 0.4s ease-out;
    }

    .front-wall-inverse.active {
        opacity: 0.85;
    }
}