:root {
    /* Warm Beige / Cream Light Palette — Hajster-Inspired */
    --background: #fffdfa;
    --background-elevated: #e4dfdac1;
    --surface: #ffffffbf;
    --surface-light: #f5f2eec0;
    --surface-hover: #ede9e3;

    /* Primary — Dark Accent */
    --primary: #1a1a1a;
    --primary-light: #4a4a4a;
    --primary-dark: #000000;
    --primary-glow: rgba(26, 26, 26, 0.06);

    /* Accent — Warm Cream Highlights */
    --accent-warm: #f5ecd7;
    --accent-purple: #7a7a7a;
    --accent-pink: #7a7a7a;
    --accent-cyan: #7a7a7a;
    --success: #3d6b50;
    --warning: #9a7b2f;
    --error: #c0392b;

    /* Text Hierarchy */
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #7a7a7a;
    --text-subtle: #a0a0a0;

    /* Borders & Dividers */
    --border: rgba(0, 0, 0, 0.10);
    --border-light: rgba(0, 0, 0, 0.05);
    --border-focus: var(--primary);

    /* Gradients — Flat / None */
    --gradient-primary: #1a1a1a;
    --gradient-accent: #1a1a1a;
    --gradient-success: #3d6b50;
    /* Ambient Gradient: Light center, Dark bottom-right, Base top-left */
    --gradient-ambient: radial-gradient(circle at 50% 50%, rgba(208, 208, 208, 0.727) 0%, transparent 50%), linear-gradient(135deg, transparent 40%, rgba(0, 0, 0, 0.512) 100%);

    /* Shadows — Elevated & Layered */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10), 0 4px 8px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 16px 40px rgba(0, 0, 0, 0.12), 0 6px 12px rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 0 30px rgba(200, 180, 140, 0.15);

    /* Card-specific accent colours for gradient glows */
    --card-glow-1: rgba(180, 160, 120, 0.25);
    --card-glow-2: rgba(140, 170, 150, 0.20);

    /* Border Radius */
    --radius-sm: 0.5rem;
    --radius-md: 0.625rem;
    --radius-lg: 0.875rem;
    --radius-xl: 1.25rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;
    --radius-pill: 9999px;

    /* Spacing System */
    --container-max: 1320px;
    /* Increased base max-width for modern screens */
    --spacing-xs: clamp(0.2rem, 0.25rem + 0.125vh, 0.3rem);
    --spacing-sm: clamp(0.4rem, 0.5rem + 0.25vh, 0.6rem);
    --spacing-md: clamp(0.8rem, 1rem + 0.5vh, 1.2rem);
    --spacing-lg: clamp(1.2rem, 1.5rem + 0.75vh, 1.8rem);
    --spacing-xl: clamp(1.6rem, 2rem + 1vh, 2.4rem);
    --spacing-2xl: clamp(2.4rem, 3rem + 1.5vh, 3.6rem);
    --spacing-3xl: clamp(3.2rem, 4rem + 2vh, 4.8rem);

    /* Typography */
    --font-heading: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Animations — Custom Easing Curves */
    --ease-smooth: cubic-bezier(0.4, 0.0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);
    --ease-in-out: cubic-bezier(0.4, 0.0, 0.2, 1);

    --duration-fast: 150ms;
    --duration-medium: 300ms;
    --duration-slow: 500ms;
    --duration-slower: 700ms;

    /* Z-index layers */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal: 1040;
    --z-toast: 1050;
}

/* Global Reset & Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--background);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Ambient Gradient Background - Fixed and Isolated */
body::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -2;
    background-image: var(--gradient-ambient);
    background-color: var(--background);
}

/* Subtle Film Grain Effect */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* Text style */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--text-primary);
}

h1 {
    font-size: clamp(2.5rem, 5vw + 2.5vh, 4.5rem);
    font-weight: 800;
}

h2 {
    font-size: clamp(2rem, 4vw + 2vh, 3.5rem);
}

h3 {
    font-size: clamp(1.5rem, 3vw + 1.5vh, 2.5rem);
}

/* Selection styling */
::selection {
    background-color: var(--accent-warm);
    color: var(--text-primary);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-elevated);
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ==========================================================================
   GLOBAL LOADING SCREEN (AIRA INTRO)
   ========================================================================== */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--background) !important;
    /* White background during intro */
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.8s cubic-bezier(0.7, 0, 0.3, 1), opacity 0.8s ease;
    will-change: background-color, opacity;
}

.loader-overlay.hidden {
    background-color: transparent !important;
    opacity: 0;
    pointer-events: none;
}

.loader-scene {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.9s cubic-bezier(0.7, 0, 0.2, 1), opacity 0.6s ease 0.2s;
    will-change: transform, opacity;
}

.loader-scene.zoom-out {
    transform: scale(0);
    opacity: 0;
}

.loader-box {
    position: absolute;
    background: #000000 !important;
    /* Box is black */
    border: none !important;
    width: 55%;
    height: 140px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    will-change: left, width, height, transform;
    backface-visibility: hidden;
}

.loader-text {
    position: absolute;
    font-family: var(--font-heading);
    font-size: clamp(3rem, 6vw, 6rem);
    font-weight: 300;
    letter-spacing: 0.06em;
    color: var(--text-primary);
    opacity: 0;
    white-space: nowrap;
    user-select: none;
    will-change: opacity, left, top, transform;
    left: 12%;
    top: 50%;
    transform: translateY(-50%);
}

.main-content.loader-active {
    opacity: 0;
    transform: scale(2.5);
    transition: transform 1.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.8s ease 0.1s;
    will-change: transform, opacity;
}

.main-content.loader-active.reveal {
    opacity: 1;
    transform: scale(1);
}

/* Loader Keyframes */
@keyframes loaderSnapToLeft {
    0% {
        transform: translate(-50%, -50%);
        width: 55%;
        height: 140px;
        left: 50%;
    }

    100% {
        transform: translate(-50%, -50%);
        width: 120px;
        height: 120px;
        left: var(--l2-box-left);
    }
}

@keyframes loaderSnapToRight {
    0% {
        transform: translate(-50%, -50%);
        width: 120px;
        height: 120px;
        left: var(--l2-box-left);
    }

    100% {
        transform: translate(-50%, -50%);
        width: 120px;
        height: 120px;
        left: var(--l3-box-left);
    }
}

@keyframes loaderTextReveal {
    0% {
        opacity: 0;
        left: var(--l3-text-left);
        transform: translateY(-50%) translateX(-20px);
    }

    100% {
        opacity: 1;
        left: var(--l3-text-left);
        transform: translateY(-50%) translateX(0);
    }
}

@keyframes loaderBoxToFinal {
    0% {
        transform: translate(-50%, -50%);
        width: 120px;
        height: 120px;
        left: var(--l3-box-left);
    }

    100% {
        transform: translate(-50%, -50%);
        width: 120px;
        height: 120px;
        left: var(--l4-box-left);
    }
}

@keyframes loaderTextToFinal {
    0% {
        opacity: 1;
        left: var(--l3-text-left);
        transform: translateY(-50%);
    }

    100% {
        opacity: 1;
        left: var(--l4-text-left);
        transform: translateY(-50%);
    }
}

.loader-box.snap-left {
    animation: loaderSnapToLeft 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.loader-box.snap-right {
    animation: loaderSnapToRight 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.loader-text.show {
    animation: loaderTextReveal 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.loader-box.to-final {
    animation: loaderBoxToFinal 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.loader-text.to-final {
    animation: loaderTextToFinal 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* Aira Spinning Loader - Generation Mode */
.aira-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 253, 250, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.4s var(--ease-smooth);
    pointer-events: none;
}

.aira-loading-overlay.active {
    display: flex;
    opacity: 1;
    pointer-events: all;
}

.aira-loading-card {
    background: var(--surface);
    padding: 3rem 5rem;
    border-radius: var(--radius-2xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 90%;
    max-width: 500px;
    transform: translateY(20px);
    transition: transform 0.4s var(--ease-spring);
}

.aira-loading-overlay.active .aira-loading-card {
    transform: translateY(0);
}

.aira-loading-scene {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aira-loading-square {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 4px;
    z-index: 2;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.aira-loading-orbit {
    position: absolute;
    width: 100%;
    height: 100%;
    animation: aira-spin 1.5s linear infinite;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aira-loading-dot {
    position: absolute;
    top: 0;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
}

/* The trail effect using multiple dots at different rotations and opacities */
.aira-loading-trail {
    position: absolute;
    width: 100%;
    height: 100%;
}

.aira-loading-trail-dot {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    opacity: 0;
}

.aira-loading-trail-dot:nth-child(1) {
    transform: translateX(-50%) rotate(-10deg);
    opacity: 0.7;
    width: 7px;
    height: 7px;
    transform-origin: center 40px;
}

.aira-loading-trail-dot:nth-child(2) {
    transform: translateX(-50%) rotate(-20deg);
    opacity: 0.5;
    width: 6px;
    height: 6px;
    transform-origin: center 40px;
}

.aira-loading-trail-dot:nth-child(3) {
    transform: translateX(-50%) rotate(-30deg);
    opacity: 0.3;
    width: 5px;
    height: 5px;
    transform-origin: center 40px;
}

.aira-loading-trail-dot:nth-child(4) {
    transform: translateX(-50%) rotate(-40deg);
    opacity: 0.1;
    width: 4px;
    height: 4px;
    transform-origin: center 40px;
}

@keyframes aira-spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.aira-loading-text {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.aira-progress-container {
    width: 100%;
    height: 4px;
    background: var(--background-elevated);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.aira-progress-bar {
    width: 0%;
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease-out;
}


/* Nav Stats Styles */
.nav-stat-pill {
    display: flex;
    flex-direction: row !important;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: default;
    user-select: none;
    height: 40px;
    white-space: nowrap;
}

.nav-stat-pill:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.nav-stat-pill.star {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.nav-stat-pill.xp {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.25);
}

.nav-stat-value {
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    line-height: 1;
}

.nav-stat-label {
    font-weight: 900;
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

@keyframes pulseRed {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
        border-color: rgba(239, 68, 68, 0.5);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
        border-color: rgba(239, 68, 68, 0.8);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
        border-color: rgba(239, 68, 68, 0.5);
    }
}

.pulse-red {
    animation: pulseRed 2s infinite;
    border: 1px solid #ef4444 !important;
}

.boost-tag {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-pill);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-right: 0.5rem;
}

.boost-tag-xp {
    background: rgba(245, 158, 11, 0.15);
    color: #92400E;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.boost-tag-elo {
    background: rgba(16, 185, 129, 0.15);
    color: #065F46;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.nav-stats-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 0.5rem;
}

@media (max-width: 768px) {

    .nav-stats-group,
    .nav-stats-separator {
        display: none !important;
    }
}

/* Layout Components */
.navbar {
    height: clamp(66px, 7vh, 80px);
    display: flex;
    align-items: center;
    border: 2px solid rgba(255, 255, 255, 0.7);
    border-radius: 9999px;
    margin: 15px auto; /* Centered with auto margin */
    width: max-content; /* Ensure it wraps the content precisely */
    max-width: calc(100% - 40px); /* Leave some side padding */
    min-width: 200px;
    backdrop-filter: blur(12px) saturate(180%);
    background: rgba(216, 210, 201, 0.85);
    position: sticky;
    top: 15px;
    z-index: var(--z-sticky);
    transition: all var(--duration-medium) var(--ease-smooth);
    padding: 0 4rem; /* Additional internal horizontal spacing */
}

.navbar.scrolled {
    background: rgba(230, 226, 220, 0.82);
    border-color: transparent;
    backdrop-filter: blur(14px) saturate(185%);
    box-shadow: var(--shadow-sm);
}

.navbar:hover {
    background: rgba(216, 210, 201, 0.95);
    box-shadow: var(--shadow-md);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 2rem; /* Increased gap between individual buttons */
    white-space: nowrap; /* Prevent wrapping inside the link container */
}

/* More Dropdown Styles */
.nav-dropdown {
    position: relative;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.dropdown-parent {
    cursor: pointer;
}

.dropdown-menu-custom {
    position: absolute;
    top: calc(100% + 10px); /* Slightly reduced gap */
    right: 0;
    min-width: 180px;
    background: rgba(255, 253, 250, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 0.75rem;
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1001;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s var(--ease-spring);
}

/* Hover bridge to prevent closing when crossing the gap */
.dropdown-menu-custom::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    width: 100%;
    height: 10px;
}

.nav-dropdown:hover .dropdown-menu-custom {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.dropdown-menu-custom .btn {
    width: 100%;
    justify-content: flex-start;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* User Avatar Circle */
.user-avatar-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s var(--ease-smooth);
    border: 3px solid rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
}

.user-avatar-circle:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

.user-desktop-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    white-space: nowrap; /* Prevent display name and buttons from wrapping */
}

/* Ensure no burger menu on desktop (already handled by hiding toggle usually, but let's be explicit) */
@media (min-width: 769px) {
    .menu-toggle {
        display: none !important;
    }
}

.container {
    max-width: clamp(800px, 90vw, 1400px);
    margin: 0 auto;
    padding: 0 var(--spacing-xl);
    width: 100%;
}

@media (min-width: 1200px) {
    .container {
        padding: 0 var(--spacing-2xl);
        max-width: clamp(1000px, 85vw, 1600px);
    }
}

.nav-content {
    display: flex;
    align-items: center;
    gap: 6rem; /* Substantial gap between brand and links */
    width: auto;
}

.brand {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    transition: all var(--duration-medium) var(--ease-smooth);
    position: relative;
}

.brand:hover {
    color: var(--primary-light);
    transform: translateY(-1px);
}

.brand-dot {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
}

/* Main Content Area */
.main-content {
    padding-top: clamp(var(--spacing-2xl), var(--spacing-3xl) + 2vh, 6rem);
    padding-bottom: clamp(var(--spacing-2xl), var(--spacing-3xl) + 2vh, 6rem);
    animation: fadeInFast var(--duration-medium) var(--ease-out);
    position: relative;
}

@keyframes fadeInFast {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Enhanced Card Component — Premium Elevated Style */
.card {
    background: var(--surface);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-2xl);
    padding: clamp(var(--spacing-lg), var(--spacing-xl) + 1vh, var(--spacing-2xl));
    transition: transform var(--duration-medium) var(--ease-smooth),
        box-shadow var(--duration-medium) var(--ease-smooth),
        border-color var(--duration-medium) var(--ease-smooth);
    box-shadow: var(--shadow-md);
    position: relative;
    /* Hardware acceleration and 3D rendering */
    transform-style: preserve-3d;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Subtle warm gradient glow accent — top-left corner */
.card::before {
    content: '';
    position: absolute;
    top: -40%;
    left: -30%;
    width: 60%;
    height: 80%;
    background: radial-gradient(ellipse at center, var(--card-glow-1), transparent 70%);
    pointer-events: none;
    opacity: 0.5;
    transition: opacity var(--duration-medium) var(--ease-smooth);
}

.card:hover {
    border-color: rgba(0, 0, 0, 0.12);
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl), var(--shadow-glow);
}

.card:hover::before {
    opacity: 0.8;
}


/* Premium Button System */
.btn {
    padding: clamp(0.75rem, 0.875rem + 0.5vh, 1rem) 1.75rem;
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 0.9375rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all var(--duration-medium) var(--ease-smooth);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    font-family: var(--font-body);
    /* Force 3D context to prevent subpixel snapping at the end of the animation */
    transform: translateZ(0) scale(1);
    transform-style: preserve-3d;
    backface-visibility: hidden;
    white-space: nowrap; /* Ensure button text never wraps */
}

@keyframes btnJump {
    0% {
        transform: translateZ(0) translateY(0) scale(1);
    }

    40% {
        transform: translateZ(0) translateY(-4px) scale(1.02);
    }

    100% {
        transform: translateZ(0) translateY(0) scale(1);
    }
}

.btn:hover {
    animation: btnJump 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

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

.btn-primary {
    background: var(--primary);
    color: #ffffff;
    box-shadow: none;
}

.btn-primary:hover {
    background: var(--primary-light);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--primary-dark);
    box-shadow: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.04);
}

/* Enhanced Form Elements */
.form-card {
    max-width: clamp(400px, 50vw, 600px);
    margin: 0 auto;
    isolation: isolate;
    transform: translateZ(0); /* Force GPU compositing to prevent backdrop-filter flicker */
}

.input-group {
    margin-bottom: 1.5rem;
    position: relative;
}

label:not(.mcq-label):not(.option-label) {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color var(--duration-fast) var(--ease-smooth);
}

/* Explicitly disable for result values and MCQ options to prevent ß -> SS */
.mcq-option,
.option-card,
.answer-value,
.ans,
.manual-answer,
.q-text {
    text-transform: none !important;
}

input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: clamp(0.8rem, 1rem + 0.5vh, 1.2rem) 1.25rem;
    background: var(--background-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-body);
    transition: all var(--duration-medium) var(--ease-smooth);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.08);
}

input:focus+label,
select:focus+label,
textarea:focus+label {
    color: var(--primary);
}

/* Flash Messages with Enhanced Animation */
.flash-wrapper {
    position: fixed;
    top: 90px;
    right: var(--spacing-xl);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 400px;
}

.alert {
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-xl);
    animation: slideInRight var(--duration-medium) var(--ease-spring);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
}

.alert.success {
    border-left-color: var(--success);
    background: #f6faf7;
}

.alert.error {
    border-left-color: var(--error);
    background: #fdf5f4;
}

.alert.warning {
    border-left-color: var(--warning);
    background: #fdfaf2;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* Grid Layouts */
.grid-cols {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--spacing-xl);
}

.grid-cols>* {
    animation: fadeInUp var(--duration-slow) var(--ease-smooth);
    animation-fill-mode: both;
}

.grid-cols>*:nth-child(1) {
    animation-delay: 0ms;
}

.grid-cols>*:nth-child(2) {
    animation-delay: 100ms;
}

.grid-cols>*:nth-child(3) {
    animation-delay: 200ms;
}

.grid-cols>*:nth-child(4) {
    animation-delay: 300ms;
}

.grid-cols>*:nth-child(5) {
    animation-delay: 400ms;
}

.grid-cols>*:nth-child(6) {
    animation-delay: 500ms;
}

/* Premium Progress Bar */
.progress-root {
    height: 6px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 1rem 0;
    position: relative;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.6s var(--ease-smooth);
    width: 0%;
    border-radius: var(--radius-full);
}

/* Enhanced Badge Component */
.badge {
    padding: 0.375rem 0.875rem;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-light);
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    transition: all var(--duration-fast) var(--ease-smooth);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.badge:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Utility Classes */
.text-muted {
    color: var(--text-muted);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-subtle {
    color: var(--text-subtle);
}

.text-center {
    text-align: center;
}

.text-gradient {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mt-8 {
    margin-top: var(--spacing-xl);
}

.mb-8 {
    margin-bottom: var(--spacing-xl);
}

.mb-4 {
    margin-bottom: var(--spacing-md);
}

.w-full {
    width: 100%;
}

/* Topic/Sub Card Enhancements */
.topic-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sub-card {
    padding: 1.25rem;
    background: var(--surface-light);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: all var(--duration-medium) var(--ease-smooth);
    box-shadow: var(--shadow-sm);
}

.sub-card:hover {
    background: var(--surface-hover);
    border-color: rgba(0, 0, 0, 0.10);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ===== Responsive Design ===== */

/* Hamburger Menu Button (hidden on desktop) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    position: relative;
    z-index: calc(var(--z-modal) + 10);
}

.menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    margin: 6px 0;
    border-radius: 2px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.menu-toggle.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.menu-toggle.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* Tablet Breakpoint */
@media (max-width: 1024px) {
    .container {
        padding: 0 var(--spacing-lg);
    }

    .grid-cols {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }
}

/* Mobile Breakpoint */
@media (max-width: 768px) {
    :root {
        --container-max: 100%;
    }

    .container {
        padding: 0 var(--spacing-md);
    }

    /* --- Navbar: Hamburger --- */
    .menu-toggle {
        display: block;
    }

    .nav-links {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--background);
        backdrop-filter: none;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 2rem !important;
        z-index: var(--z-modal);
        padding: 2rem;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-20px);
        transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
        pointer-events: none;
    }

    .nav-links.open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        pointer-events: all;
    }

    .nav-links a {
        font-size: 1.5rem;
        font-weight: 700;
        opacity: 0;
        transform: translateY(10px);
        transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .nav-links.open a {
        opacity: 1;
        transform: translateY(0);
    }

    /* Staggered delay for links */
    .nav-links.open a:nth-child(1) {
        transition-delay: 0.1s;
    }

    .nav-links.open a:nth-child(2) {
        transition-delay: 0.15s;
    }

    .nav-links.open a:nth-child(3) {
        transition-delay: 0.2s;
    }

    .nav-links.open a:nth-child(4) {
        transition-delay: 0.25s;
    }

    .nav-links.open .user-info {
        transition-delay: 0.3s;
    }

    .nav-links .user-info {
        flex-direction: column !important;
        border-left: none !important;
        padding-left: 0 !important;
        border-top: 1px solid var(--border);
        padding-top: 1.5rem !important;
        text-align: center;
    }

    .navbar {
        height: 56px;
    }

    /* --- Main Content --- */
    .main-content {
        padding-top: var(--spacing-lg);
        padding-bottom: var(--spacing-lg);
    }

    /* --- Typography --- */
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.4rem;
    }

    h3 {
        font-size: 1.15rem;
    }

    /* --- Card --- */
    .card {
        padding: var(--spacing-lg);
        border-radius: var(--radius-lg);
    }

    .card:hover {
        transform: none;
    }

    /* --- Grids --- */
    .grid-cols {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    /* --- Buttons --- */
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.875rem;
    }

    /* --- Forms --- */
    .form-card {
        max-width: 100%;
    }

    input[type="text"],
    input[type="password"],
    input[type="email"],
    select,
    textarea {
        padding: 0.875rem 1rem;
    }

    /* --- Flash --- */
    .flash-wrapper {
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        top: 70px;
        max-width: none;
    }

    /* --- Dashboard headers --- */
    .dashboard-header,
    .command-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem;
        margin-bottom: 2rem !important;
    }

    .dashboard-header>div,
    .command-header>div {
        width: 100%;
    }

    .level-badge {
        text-align: left !important;
    }

    /* --- Badges --- */
    .badge {
        font-size: 0.625rem;
        padding: 0.25rem 0.625rem;
    }

    /* --- Tabs (manage_exercises) --- */
    .tabs {
        flex-wrap: wrap;
        gap: 0.25rem !important;
    }

    .tabs .tab {
        flex: 1;
        min-width: 0;
        text-align: center;
        font-size: 0.8125rem;
        padding: 0.625rem 0.5rem;
        white-space: nowrap;
    }

    /* --- Filter bar (manage_exercises) --- */
    form[style*="align-items: flex-end"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    /* --- Exercise list cards grid → stack --- */
    .challenge-stack .card {
        grid-template-columns: 40px 1fr !important;
    }

    .challenge-stack .card>div:last-child {
        grid-column: 1 / -1;
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        margin-top: 0.5rem;
    }

    /* --- Bulk add rows → stack --- */
    .bulk-header,
    .bulk-row {
        grid-template-columns: 1fr !important;
        gap: 0.5rem !important;
    }

    /* --- AI generator grid → stack --- */
    div[style*="grid-template-columns: 1fr 120px"] {
        grid-template-columns: 1fr !important;
    }

    /* --- AI results grid --- */
    .ai-grid {
        grid-template-columns: 1fr !important;
    }

    /* --- AI example rows --- */
    .ai-example-row {
        grid-template-columns: 1fr 1fr 40px !important;
    }

    /* --- Bulk delete bar --- */
    .bulk-delete-bar {
        flex-direction: column !important;
        gap: 1rem !important;
        text-align: center;
    }

    /* --- Edit overlay --- */
    .edit-overlay .card {
        width: 95% !important;
        max-width: none !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* --- Profile / info stats grid --- */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* --- Sub cards / topic cards --- */
    .sub-card {
        padding: 1rem;
    }
}

/* ===== Ultra-Wide Screen Support ===== */
@media (min-width: 1600px) {
    :root {
        --container-max: 1600px;
    }

    .navbar .container {
        max-width: 95% !important;
        padding-left: 4vw;
        padding-right: 4vw;
    }

    .exercise-container,
    .result-container {
        max-width: 1300px !important;
    }

    .form-card {
        max-width: 900px !important;
    }

    .page-wrapper,
    .summary-page,
    .exam-container {
        max-width: 1600px !important;
    }

    .result-card-unified {
        max-width: 1600px !important;
        width: 94vw !important;
    }

    .nav-logo {
        font-size: 1.75rem !important;
    }

    .navbar .btn {
        padding: 0.7rem 1.4rem !important;
        font-size: 1rem !important;
    }
}

@media (min-width: 2200px) {
    :root {
        --container-max: 1840px;
    }

    .navbar .container {
        max-width: 96% !important;
        padding-left: 3vw;
        padding-right: 3vw;
    }

    .exercise-container,
    .result-container {
        max-width: 1500px !important;
    }

    .form-card {
        max-width: 1100px !important;
    }

    .page-wrapper,
    .summary-page,
    .exam-container {
        max-width: 1800px !important;
    }

    .result-card-unified {
        max-width: 1800px !important;
        width: 92vw !important;
    }

    .nav-logo {
        font-size: 2rem !important;
    }

    .navbar .btn {
        padding: 0.8rem 1.6rem !important;
        font-size: 1.1rem !important;
    }
}


/* 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;
    }
}

/* Focus Visible for Accessibility */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* --- FOOTER --- */
.site-footer {
    padding: 1.25rem var(--spacing-md);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    background: var(--background-elevated);
    border-top: 1px solid var(--border);
    margin-top: auto;
    width: 100%;
    z-index: 10;
    font-family: var(--font-body);
}

.site-footer-content {
    max-width: var(--container-max);
    margin: 0 auto;
    opacity: 0.7;
    transition: opacity 0.3s var(--ease-smooth);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.site-footer-content:hover {
    opacity: 1;
}

.site-footer .credits {
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
}

.online-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-primary);
    display: inline-block;
}

@keyframes pulse-green {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}