/* Essential Variables */
:root {
    --primary-dark: #0D1117;
    --primary-darker: #161B22;
    --accent-gold: #D4AF37;
    --user-accent: #40E0D0;
    --text-color: #E6E6E6;
    --border-color: rgba(64, 224, 208, 0.2);
    --accent-color: #40E0D0;
}

/* 2. Base Overlay - Simplified */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transform: translateZ(0);
}

.auth-overlay::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url('/media/images/background-pattern.webp');
    background-size: cover;
    background-position: center;
    filter: brightness(1.15) invert(75%) sepia(0%) saturate(0%) hue-rotate(20deg) brightness(74%) contrast(175%);
    transition: filter 1.5s cubic-bezier(0.22, 0.61, 0.36, 1);
    pointer-events: none;
}

.auth-overlay:not(.no-access):focus-within::before {
    filter: brightness(1.15) invert(75%) sepia(0%) saturate(100%) hue-rotate(20deg) brightness(77%) contrast(175%);
}

/* 3. Main Container - Optimized */
.auth-container {
    position: relative;
    width: 90%;
    max-width: 360px;
    padding: 2.5rem 2rem;
    background: var(--primary-darker);
    border-radius: 16px;
    border: 1px solid rgba(64, 224, 208, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transform: translateZ(0);
    overflow: hidden;
    animation: fadeIn 0.2s ease-out;
}

/* White Sigil with Focus Animation */
.auth-container::before {
    content: '';
    position: absolute;
    top: -28%;
    right: -68%;
    width: 150%;
    height: 150%;
    background-image: url('/media/images/auth-sigil-top-right.png');
    background-size: auto;
    background-repeat: no-repeat;
    background-position: bottom left;
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
    transform: translateZ(0);
    will-change: transform;
    mix-blend-mode: screen;
    filter: brightness(0) saturate(100%) invert(100%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(100%) contrast(100%);
}

.auth-container:focus-within::before {
    opacity: 0.25;
    animation: fadeToBlue 0.1s ease-out forwards, 
               breatheEffectBlue 2.9s ease-in-out infinite alternate;
    /* animation-delay: 0s, 0.18s; */
}

@keyframes fadeToBlue {
    0% {
        filter: none;
        opacity: 0.15;
    }
    100% {
        filter: brightness(0) saturate(100%) invert(75%) sepia(29%) saturate(757%) hue-rotate(140deg) brightness(95%) contrast(101%);
        opacity: 0.2;
    }
}

@keyframes breatheEffectBlue {
    0% {
        filter: brightness(0) saturate(100%) invert(75%) sepia(29%) saturate(757%) hue-rotate(140deg) brightness(95%) contrast(101%);
        opacity: 0.2;
    }
    100% {
        filter: brightness(0) saturate(100%) invert(83%) sepia(29%) saturate(757%) hue-rotate(140deg) brightness(95%) contrast(101%);
        opacity: 0.3;
    }
}

/* Red Outline Effect */
.auth-container::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
        circle at bottom right, 
        rgba(255, 20, 60, 0.2) 0%,
        transparent 70%
    );
    opacity: 0.35;
    pointer-events: none;
    z-index: 1;
    border-radius: 16px;
}

/* Error State Animation */
.auth-container.error::before {
    animation: flashRed 0.2s ease-out forwards,
              errorShake 0.2s cubic-bezier(.36,.07,.19,.97) both !important;
    /* Ensure error state overrides focus state */
    filter: brightness(0) saturate(100%) invert(27%) sepia(91%) saturate(1857%) hue-rotate(335deg) brightness(95%) contrast(101%) !important;
}

.auth-container.error:focus-within::before {
    animation: flashRed 0.2s ease-out forwards,
              errorShake 0.2s cubic-bezier(.36,.07,.19,.97) both,
              fadeToBlue 0.1s ease-out forwards 0.2s,
              breatheEffectBlue 2.9s ease-in-out infinite alternate 0.3s !important;
}

@keyframes flashRed {
    0% {
        filter: brightness(0) saturate(100%) invert(100%) sepia(91%) saturate(6449%) hue-rotate(343deg) brightness(103%) contrast(127%);
        opacity: 0.5;
    }
    100% {
        filter: brightness(0) saturate(100%) invert(27%) sepia(91%) saturate(1857%) hue-rotate(335deg) brightness(95%) contrast(101%);
        opacity: 0.3;
    }
}

@keyframes errorShake {
    0%, 100% {
        transform: translateX(0) translateZ(0);
    }
    25% {
        transform: translateX(-4px) translateZ(0);
    }
    75% {
        transform: translateX(4px) translateZ(0);
    }
}

/* 4. Form Elements - Simplified */
.auth-input {
    width: 100%;
    padding: 12px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.auth-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.89rem;
}

.auth-input:focus {
    outline: none;
    border-color: var(--accent-color);
    background: rgba(0, 0, 0, 0.4);
    color: #7FDBCA;
    box-shadow: 0 0 0 2px rgba(127, 219, 202, 0.2);
}

.auth-input:focus::placeholder {
    color: rgba(127, 219, 202, 0.6);
}

.auth-input.error {
    animation: inputErrorShake 0.2s cubic-bezier(.36,.07,.19,.97) both,
               inputErrorFlash 0.2s ease-out forwards;
    border-color: rgba(220, 20, 60, 0.5);
}

@keyframes inputErrorShake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-4px);
    }
    75% {
        transform: translateX(4px);
    }
}

@keyframes inputErrorFlash {
    0% {
        box-shadow: 0 0 0 2px rgba(220, 20, 60, 0);
    }
    100% {
        box-shadow: 0 0 0 2px rgba(220, 20, 60, 0.2);
    }
}

/* 5. Button - Performance Optimized */
.auth-button {
    width: 100%;
    background: var(--user-accent);
    color: var(--primary-darker);
    border: none;
    border-radius: 10px;
    padding: 0.9rem;
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: 1.5rem;
    transform: translateZ(0);
    transition: transform 0.2s ease;
}

.auth-button:hover {
    transform: translateY(-1px);
}

.auth-button:active {
    transform: translateY(1px);
}

/* 6. Register Link - Simplified */
.auth-register-link {
    margin-top: 1.2rem;
    text-align: center;
    font-size: 0.9rem;
}

.auth-register-link a {
    color: var(--user-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* 7. No Access Screen - Optimized */
.auth-overlay.no-access::before {
    filter: brightness(1.15) invert(75%) sepia(0%) saturate(100%) hue-rotate(145deg) brightness(90%) contrast(180%);
}

.auth-overlay.no-access .auth-container {
    width: 85%;
    max-width: min(450px, 85vw);
    max-height: min(600px, 80vh);
    padding: clamp(1rem, 3vw, 2rem);
    background: var(--primary-darker);
    border-color: rgba(212, 175, 55, 0.3);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(0.5rem, 2vh, 1.5rem);
}

/* Red Sigil Effect for No Access */
.auth-overlay.no-access .auth-container::before {
    content: '';
    position: absolute;
    top: -67%;
    right: -50%;
    width: 150%;
    height: 150%;
    background-image: url('/media/images/auth-sigil-top-right.png');
    background-size: auto;
    background-repeat: no-repeat;
    background-position: bottom left;
    opacity: 0.3;
    pointer-events: none;
    z-index: 0;
    filter: brightness(0) saturate(100%) sepia(9%) saturate(4160%) hue-rotate(343deg) brightness(91%) contrast(126%);   
    transform: translateZ(0);
    will-change: transform;
    mix-blend-mode: screen;
    animation: breatheEffect 2.9s ease-in-out infinite alternate;
}

@keyframes breatheEffect {
    0% {
        filter: brightness(0) saturate(100%) invert(15%) sepia(91%) saturate(4160%) hue-rotate(343deg) brightness(91%) contrast(126%);
    }
    100% {
        filter: brightness(0) saturate(100%) invert(4%) sepia(91%) saturate(4160%) hue-rotate(343deg) brightness(91%) contrast(126%);
    }
}

.auth-overlay.no-access .auth-container::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
        circle at bottom right, 
        rgba(220, 20, 60, 0.25) 0%,
        transparent 70%
    );
    opacity: 0.5;
    pointer-events: none;
    z-index: 1;
    border-radius: 16px;
    mix-blend-mode: screen;
}

.auth-overlay.no-access .no-access-image {
    width: min(280px, 70%);
    aspect-ratio: 1;
    position: relative;
    margin: clamp(0.5rem, 2vh, 1.5rem) 0;
}

.auth-overlay.no-access .highlander-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}

.auth-overlay.no-access .highlander-base {
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.9;
}

.auth-overlay.no-access h2 {
    font-size: clamp(1.2rem, 4vw, 1.7rem);
    margin: 0;
    text-align: center;
}

.auth-overlay.no-access p {
    font-size: clamp(0.9rem, 3vw, 1rem);
    margin: 0;
    text-align: center;
    opacity: 0.8;
    line-height: 1.5;
}

.auth-overlay.no-access .auth-button {
    margin-top: clamp(0.5rem, 2vh, 1.5rem);
}

@supports (-webkit-touch-callout: none) {
    .auth-overlay.no-access .auth-container {
        width: 85%;
        max-width: min(400px, 85vw);
        max-height: min(550px, 75vh);
        padding: clamp(0.8rem, 2.5vw, 1.8rem);
        margin: 0 auto;
        transform: translateZ(0);
        gap: clamp(0.4rem, 1.5vh, 1.2rem);
    }
    
    .auth-overlay.no-access .no-access-image {
        width: min(240px, 65%);
        margin: clamp(0.4rem, 1.5vh, 1.2rem) 0;
    }

    .auth-overlay.no-access .auth-container::before,
    .auth-overlay.no-access .auth-container::after {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        -webkit-backface-visibility: hidden;
    }
}

/* 8. Error States - Simplified */
.auth-error {
    color: #DC143C;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* 9. Animations - Minimal & Performance Focused */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* iOS-specific optimizations */
@supports (-webkit-touch-callout: none) {
    .auth-container {
        -webkit-transform: translateZ(0);
        -webkit-backface-visibility: hidden;
    }
    
    /* Optimize background image rendering */
    .auth-container::before,
    .auth-container::after {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Title and Diamond Styling */
.title-container {
    margin: 0 0 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: calc(var(--vw) * 2);
}

.title-decoration {
    display: flex;
    align-items: center;
    gap: calc(var(--vw) * 2);
}

.title-line {
    height: 2px;
    width: calc(var(--vw) * 12);
    background: linear-gradient(90deg, transparent, var(--accent-gold) 20%, var(--accent-gold) 80%, transparent);
}

.diamond-cluster {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    transform: translateY(1px);
}

.diamond-row {
    display: flex;
    gap: 3px;
    transform: translateY(-1px);
}

.single-diamond,
.title-diamond {
    color: var(--accent-gold);
    font-size: calc(var(--vh) * 1.8);
    opacity: 0.8;
    line-height: 0.7;
}

.title-container h2 {
    color: var(--accent-gold);
    font-size: 1.7rem;
    font-weight: 400;
    margin: 0;
    white-space: nowrap;
}

.auth-message {
    color: var(--text-color);
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 2rem;
    opacity: 0.8;
    font-style: italic;
}