/* Bootstrap Integration & Custom Styles */

/* Reset and base styles */
:root {
    --primary-cyan: #00ffff;
    --primary-blue: #0080ff;
    --dark-bg: #000;
    --card-bg: rgba(0, 0, 0, 0.5);
    --text-light: rgba(255, 255, 255, 0.8);
    --border-glow: rgba(0, 255, 255, 0.2);
    --navbar-height: 72px;
    --max-content-width: 68ch;
}

/* Safari-specific root and html fixes */
@supports (-webkit-appearance: none) and (not (contain: paint)) {
    html {
        height: 100%;
        height: -webkit-fill-available;
    }

    html,
    body {
        /* Prevent Safari's address bar from causing layout shifts */
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
}

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--dark-bg);
    color: #fff;
    font-size: clamp(16px, 1.1vw + 14px, 18px);
    line-height: 1.7;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-top: var(--navbar-height);
    /* Account for fixed navbar */
}

/* Wireframe Background Animation */
.wireframe-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.wireframe-grid {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        linear-gradient(90deg, transparent 98%, rgba(0, 255, 255, 0.1) 100%),
        linear-gradient(0deg, transparent 98%, rgba(0, 255, 255, 0.1) 100%);
    background-size: 50px 50px;
    animation: gridMove 20s linear infinite;
    opacity: 0.15;
}

.wireframe-nodes {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(0, 255, 255, 0.4) 2px, transparent 2px),
        radial-gradient(circle at 40% 60%, rgba(0, 255, 255, 0.3) 1px, transparent 1px),
        radial-gradient(circle at 60% 40%, rgba(0, 255, 255, 0.5) 1.5px, transparent 1.5px),
        radial-gradient(circle at 80% 20%, rgba(0, 255, 255, 0.2) 1px, transparent 1px);
    background-size: 200px 200px, 150px 150px, 100px 100px, 250px 250px;
    animation: nodePulse 4s ease-in-out infinite;
}

@keyframes gridMove {
    0% {
        transform: translateX(0) translateY(0);
    }

    100% {
        transform: translateX(-50px) translateY(-25px);
    }
}

@keyframes nodePulse {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 0.8;
    }
}

/* Custom Bootstrap Navbar */
.custom-navbar {
    background-color: rgba(20, 20, 20, 0.9);
    /* Fallback for older browsers */
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

@supports (backdrop-filter: blur(18px)) or (-webkit-backdrop-filter: blur(18px)) {
    .custom-navbar {
        background-color: rgba(10, 10, 10, 0.75);
        backdrop-filter: blur(18px) saturate(150%);
        -webkit-backdrop-filter: blur(18px) saturate(150%);
    }
}

.custom-navbar.scrolled {
    background-color: rgba(0, 0, 0, 0.95) !important;
}

/* Logo Styles */
.navbar-brand.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    padding: 0;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.logo-text span {
    display: inline-block;
}

.logo .v {
    color: #9400d3;
}

.logo .i {
    color: #4b0082;
}

.logo .b {
    color: #0000ff;
}

.logo .g {
    color: #00ff00;
}

.logo .y {
    color: #ffff00;
}

.logo .o {
    color: #ff7f00;
}

.logo .r {
    color: #ff0000;
}

.tagline {
    font-size: 0.7rem;
    font-weight: 300;
    color: var(--text-light);
    letter-spacing: 2px;
}

/* Bootstrap Nav Customizations */
.navbar-nav .nav-link {
    color: var(--text-light) !important;
    font-weight: 400;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    position: relative;
    margin: 0 0.5rem;
}

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link.active {
    color: var(--primary-cyan) !important;
}

.navbar-nav .nav-link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary-cyan), transparent);
    transition: width 0.3s ease;
}

.navbar-nav .nav-link:hover::after,
.navbar-nav .nav-link.active::after {
    width: 100%;
}

/* Hero Section */
.hero {
    min-height: calc(100vh - var(--navbar-height));
    position: relative;
    padding: 0;
}

/* Safari-specific fixes for viewport issues */
@supports (-webkit-appearance: none) and (not (contain: paint)) {
    .hero {
        min-height: calc(100vh - var(--navbar-height));
        /* Use -webkit-fill-available for Safari */
        min-height: calc(-webkit-fill-available - var(--navbar-height));
    }

    body {
        /* Prevent Safari's bounce scroll from showing white space */
        background-attachment: fixed;
    }

    .wireframe-background {
        /* Ensure background covers full Safari viewport */
        height: 100vh;
        height: -webkit-fill-available;
    }
}

.hero-title {
    font-size: clamp(2rem, 5.5vw, 4.5rem);
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
    background: linear-gradient(135deg, #fff, var(--primary-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2rem !important;
}

/* Safari fallback for hero title */
@supports not (-webkit-background-clip: text) {
    .hero-title {
        color: var(--primary-cyan) !important;
        background: none !important;
    }
}

.typing-text {
    display: inline-block;
    position: relative;
    overflow: visible;
    white-space: nowrap;
    /* Performance optimizations for Chrome */
    transform: translateZ(0);
    will-change: clip-path, opacity;
    /* Apply gradient to the actual text node for Safari reliability */
    background-image: linear-gradient(135deg, #ffffff, var(--primary-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: typing 2.5s steps(30, end);
    opacity: 0;
    /* Initially hidden, JS will reveal */
}

.typing-text::after {
    content: '';
    position: absolute;
    top: 0;
    width: 3px;
    height: 100%;
    background-color: var(--primary-cyan);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.8);
    /* The cursor moves with the text, then holds at the end */
    animation:
        typing-cursor 2.5s steps(30, end) forwards,
        blink-caret 1s step-end infinite;
    animation-delay: 0s, 2.5s;
    z-index: 10;
}

@keyframes typing {
    from {
        clip-path: inset(0 100% 0 0);
    }

    to {
        clip-path: inset(0 0% 0 0);
    }
}

@keyframes typing-cursor {
    from {
        left: 0;
        opacity: 1;
    }

    99% {
        opacity: 1;
    }

    to {
        left: calc(100% + 4px);
        opacity: 1;
    }
}

@keyframes blink-caret {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

/* JS fallback mode (Safari) – disable clip-path typing but keep cursor blink */
.js-typing-active {
    animation: none !important;
    clip-path: none !important;
}

.js-typing-active::after {
    animation: blink-caret 1s step-end infinite !important;
    left: calc(100% + 4px) !important;
    opacity: 1 !important;
}

/* Additional cursor element for Safari JS fallback */
.typing-cursor {
    display: inline-block;
    color: var(--primary-cyan);
    font-weight: 300;
    margin-left: 2px;
    animation: blink-caret 1s step-end infinite;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.8);
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    -webkit-text-fill-color: var(--primary-cyan);
    color: var(--primary-cyan);
}

.hero-subtitle {
    font-size: clamp(1.0625rem, 2.4vw, 1.5rem);
    color: var(--text-light);
    line-height: 1.75;
}

.content-max {
    max-width: var(--max-content-width);
}

.hero-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.hero-actions .btn {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    border-radius: 0.875rem;
}

.btn-primary {
    position: relative;
    isolation: isolate;
    background: linear-gradient(90deg, #09f6ff 0%, #0e7cff 100%);
    border: 0;
    color: #041015;
    font-weight: 800;
    letter-spacing: 2px;
    padding: 1rem 2rem;
    border-radius: 0.9rem;
    overflow: hidden;
    /* Contain the aurora */
    box-shadow:
        0 10px 24px rgba(0, 255, 255, 0.25),
        0 4px 10px rgba(0, 0, 0, 0.25);
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 70%);
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.btn-primary:hover::before {
    opacity: 1;
}

.btn-primary:hover {
    background: linear-gradient(90deg, #39f4ff 0%, #2a90ff 100%);
    transform: translateY(-2px);
    box-shadow:
        0 14px 28px rgba(0, 255, 255, 0.3),
        0 6px 14px rgba(0, 0, 0, 0.28);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
}

.btn-primary:focus-visible {
    outline: none;
    box-shadow:
        0 0 0 3px rgba(0, 255, 255, 0.4),
        0 10px 24px rgba(0, 255, 255, 0.25),
        0 4px 10px rgba(0, 0, 0, 0.25);
}

.btn-outline-info {
    border: 2px solid rgba(0, 255, 255, 0.6);
    color: #00e8ff;
    padding: 0.8125rem 1.5rem;
}

.btn-outline-info:hover {
    background-color: rgba(0, 255, 255, 0.08);
    border-color: #00ffff;
    color: #00ffff;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 255, 255, 0.2);
}

/* Optimized scroll snap container */
.scroll-snap-y {
    scroll-snap-type: y mandatory;
    overflow-y: auto;
    max-height: 100vh;
    scroll-padding-top: var(--navbar-height);
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    /* Improved performance */
    will-change: scroll-position;
}

/* Safari-specific scroll container fixes */
@supports (-webkit-appearance: none) and (not (contain: paint)) {
    .scroll-snap-y {
        max-height: 100vh;
        max-height: -webkit-fill-available;
        /* Prevent Safari's elastic scrolling issues */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: none;
    }
}

.snap-section {
    min-height: 100vh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
}

/* Section Titles */
.section-title {
    position: relative;
    display: inline-block;
    padding-bottom: 0.5rem;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 3px;
    background: var(--primary-cyan);
    transition: all 0.3s ease-in-out;
}

.section-title:hover::after {
    width: 100%;
    left: 0;
}

/* Safari fallback for section titles */
@supports not (-webkit-background-clip: text) {
    .section-title {
        color: var(--primary-cyan) !important;
        background: none !important;
    }
}

/* Game Cards */
.game-card,
.news-item {
    background: rgba(255, 255, 255, 0.05);
    /* Fallback for older browsers */
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 1rem !important;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    transition: all 0.3s ease;
}

/* Game card links */
a .game-card {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

a:hover .game-card,
a:focus .game-card {
    border-color: rgba(0, 255, 255, 0.5) !important;
    box-shadow: 0 20px 40px rgba(0, 255, 255, 0.2) !important;
}

a:focus .game-card {
    outline: 2px solid rgba(0, 255, 255, 0.6);
    outline-offset: 2px;
}

@supports (backdrop-filter: blur(15px)) or (-webkit-backdrop-filter: blur(15px)) {

    .game-card,
    .news-item {
        background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
        backdrop-filter: blur(15px) saturate(150%);
        -webkit-backdrop-filter: blur(15px) saturate(150%);
    }
}

.game-card.in-view {
    opacity: 1;
    transform: translateY(0);
}

.game-card:hover {
    transform: translateY(-10px);
    border-color: rgba(0, 255, 255, 0.5) !important;
    box-shadow: 0 20px 40px rgba(0, 255, 255, 0.2) !important;
}

.game-card-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(0, 255, 255, 0.1), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.game-card:hover .game-card-bg {
    opacity: 1;
}

.game-card .card-body {
    position: relative;
    z-index: 2;
    background: transparent !important;
}

.game-title {
    color: #fff !important;
    font-weight: 600;
}

.game-description {
    color: var(--text-light) !important;
}

.game-card-shine {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    background: linear-gradient(135deg,
            rgba(255, 255, 255, 0.25) 0%,
            rgba(255, 255, 255, 0) 60%);
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    pointer-events: none;
    /* Allows clicks to pass through */
}

.game-card:hover .game-card-shine {
    opacity: 1;
    background-position:
        calc(var(--x) - 100px) calc(var(--y) - 100px);
}

/* News Cards */
.news-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-5px);
}

.news-title {
    color: #fff !important;
    font-weight: 600;
}

.news-meta {
    color: rgba(0, 255, 255, 0.7) !important;
}

.news-excerpt {
    color: var(--text-light) !important;
}

/* News Section */
.news-section {
    background: linear-gradient(-45deg, #000000, #0c0c1a, #000000, #1a0c0c);
    background-size: 400% 400%;
    animation: gradient-bg 15s ease infinite;
}

@keyframes gradient-bg {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* Footer */
.footer {
    background-color: rgba(0, 0, 0, 0.9) !important;
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-glow);
    color: var(--text-light);
}

/* Responsive Breakpoints */
@media (max-width: 991.98px) {
    .navbar-collapse {
        position: fixed;
        top: 0;
        left: -100%;
        /* Start off-screen */
        width: 100%;
        height: 100%;
        background: rgba(10, 10, 10, 0.98);
        z-index: 1040;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: left 0.35s ease-in-out;
    }

    .navbar-collapse.show {
        left: 0;
        /* Slide in */
    }

    .navbar-toggler {
        z-index: 1041;
        /* Ensure toggler is above the menu */
    }

    .navbar-brand.logo {
        margin-bottom: 0;
        /* Reset margin */
    }

    .navbar-nav {
        text-align: center;
        width: 100%;
    }

    .navbar-nav .nav-link {
        margin: 1.5rem 0;
        font-size: 1.75rem;
        font-weight: 600;
    }

    .hero {
        min-height: 80vh;
    }

    body {
        padding-top: calc(var(--navbar-height) - 8px);
    }
}

@media (max-width: 767.98px) {
    .hero-title {
        font-size: clamp(2.2rem, 10vw, 3rem);
    }

    .section-title {
        font-size: 1.8rem;
    }

    section.py-5 {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }

    .logo-text {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.6rem;
        letter-spacing: 1px;
    }

    .hero-actions .btn {
        width: 100%;
        /* Make buttons full-width */
        margin-bottom: 1rem;
        /* Add space between stacked buttons */
    }

    .hero-actions .btn:last-child {
        margin-bottom: 0;
        /* Remove margin from the last button */
    }

    .wireframe-grid,
    .wireframe-nodes {
        animation-duration: 30s;
    }
}

@media (max-width: 575.98px) {
    .hero-actions .btn {
        padding: 0.9rem 1.25rem;
        font-size: 1rem;
    }

    body {
        padding-top: calc(var(--navbar-height) - 16px);
    }

    .custom-navbar {
        padding: 0.5rem 1rem;
    }

    .hero {
        min-height: 70vh;
    }

    .hero-title {
        font-size: 2.5rem;
    }

    .hero-subtitle {
        font-size: 1.1rem;
    }
}

/* Accessible skip link */
.skip-link {
    position: absolute;
    left: -9999px;
    top: -9999px;
}

.skip-link:focus-visible {
    left: 12px;
    top: 12px;
    z-index: 10000;
    background: #000;
    color: #00ffff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    outline: 2px solid #00ffff;
}

/* High DPI displays */
@media (min-resolution: 192dpi) {
    .wireframe-grid {
        background-size: 25px 25px;
    }

    .wireframe-nodes {
        background-size: 100px 100px, 75px 75px, 50px 50px, 125px 125px;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {

    .wireframe-grid,
    .wireframe-nodes,
    .typing-text {
        animation: none;
    }

    .game-card:hover,
    .news-item:hover,
    .btn:hover {
        transform: none;
    }
}

/* Dark theme for Bootstrap components */
.bg-dark {
    background-color: rgba(0, 0, 0, 0.8) !important;
}

.text-muted {
    color: rgba(255, 255, 255, 0.6) !important;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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