/* Root Variables */
:root {
    --cosmos-dark: #0A0E2A;
    --cosmos-purple: #1B143F;
    --neon-blue: #00D4FF;
    --neon-blue-dark: #00a3cc;
    --neon-magenta: #FF00E5;
    --neon-magenta-dark: #cc00b8;
    --neon-green: #22c55e;
    --cosmos-gradient: linear-gradient(135deg, #1B143F, #007A99);
    --shadow-neon: 0 0 15px rgba(0, 212, 255, 0.5);
}

/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--cosmos-dark);
    color: #e2e8f0;
    font-family: 'Exo 2', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Ensure main content is pushed below the fixed header */
main {
    padding-top: 60px; /* Match the header height */
}

/* Loading Spinner */
.loader {
    border-top-color: var(--neon-blue);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading Animation Classes */
.initially-hidden {
    opacity: 0;
    visibility: hidden;
}

.fade-in {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.5s ease-in;
}

.hidden {
    display: none !important;
}

/* Background Effects */
#particle-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.8;
}

/* Header */
header {
    background: var(--cosmos-gradient);
    box-shadow: var(--shadow-neon);
    position: fixed;
    top: 0;
    width: 100%;
    height: 60px;
    z-index: 1;
}

header .container {
    pointer-events: auto;
}

.logo-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90px;
    height: 90px;
    background: var(--cosmos-dark);
    border-radius: 50%;
    padding: 10px;
    box-shadow: var(--shadow-neon);
    overflow: hidden;
    z-index: 10;
}

/* Logo Pulse Glow */
.animate-pulse-glow {
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0% { box-shadow: 0 0 10px rgba(0, 212, 255, 0.3); }
    50% { box-shadow: 0 0 20px rgba(0, 212, 255, 0.7); }
    100% { box-shadow: 0 0 10px rgba(0, 212, 255, 0.3); }
}

/* Background GIF */
.background-gif {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
    opacity: 0.5;
}

/* Logo */
.logo {
    position: relative;
    z-index: 2;
    max-width: 60px;
    max-height: 60px;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.logo:hover {
    transform: scale(1.1) rotate(360deg);
}

/* Marquee */
.marquee-container {
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    margin-left: clamp(0.5rem, 1vw, 1rem);
    margin-right: clamp(0.5rem, 1vw, 1rem);
}

#scoreMarquee {
    display: inline-block;
    padding-left: 100%;
    animation: marquee 30s linear infinite;
    font-family: 'Roboto Mono', monospace;
    color: #e2e8f0;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.8), 0 0 12px rgba(0, 212, 255, 0.5);
    font-size: clamp(0.6rem, 2vw, 0.8rem);
}

#scoreMarquee:hover {
    animation-play-state: paused;
    transform: scale(1.05);
    transition: transform 0.3s ease;
}

.top-scores {
    font-weight: bold;
    color: #000000;
    text-shadow: 0 0 8px rgba(255, 255, 255, 1), 0 0 12px rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.2);
    padding: 0 4px;
    border-radius: 2px;
}

/* Button Glow */
.animate-glow {
    animation: button-glow 1.5s ease-in-out infinite;
}

@keyframes button-glow {
    0% { box-shadow: 0 0 5px var(--neon-blue); }
    50% { box-shadow: 0 0 15px var(--neon-blue), 0 0 25px var(--neon-magenta); }
    100% { box-shadow: 0 0 5px var(--neon-blue); }
}

/* Game List Section */
#gameListSection {
    padding-top: 0;
    padding-bottom: 2rem;
}

#gameListSection h2 {
    margin-top: 1rem;
}

#gameList .game-card {
    transition: all 0.3s ease;
    position: relative;
    height: 16rem;
}

#gameList .game-card img {
    transition: opacity 0.3s ease;
    object-position: center;
}

#gameList .game-card.opacity-50 {
    opacity: 0.5;
}

#gameList .game-card.cursor-not-allowed {
    cursor: not-allowed;
}

#gameList .game-card .text-neon-magenta {
    color: var(--neon-magenta);
    text-shadow: 0 0 5px var(--neon-magenta);
}

#gameList .game-card .font-bold {
    font-weight: bold;
}

#gameList .game-card .mt-2 {
    margin-top: 0.5rem;
}

#gameList .game-card:hover:not(.opacity-50) {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--neon-magenta), 0 0 30px var(--neon-blue);
    animation: card-glow 1.5s ease-in-out infinite;
}

#gameList .game-card:hover img {
    opacity: 0.8;
}

#gameList .game-card h3 {
    text-shadow: 0 0 5px var(--neon-blue);
}

#gameList .game-card:hover h3 {
    text-shadow: 0 0 10px var(--neon-blue), 0 0 15px var(--neon-magenta);
}

/* Text Overlay with Black Background */
#gameList .game-card .text-overlay {
    background: rgba(0, 0, 0, 0.7);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

@keyframes card-glow {
    0% { box-shadow: 0 0 10px var(--neon-magenta); }
    50% { box-shadow: 0 0 20px var(--neon-magenta), 0 0 30px var(--neon-blue); }
    100% { box-shadow: 0 0 10px var(--neon-magenta); }
}

/* Partners Section */
#partnersSection {
    margin-top: 0.5rem;
}

/* Logo Hover Animation */
.logo-hover:hover {
    transform: rotate(10deg) scale(1.1);
    box-shadow: 0 0 15px var(--neon-blue);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Game Section */
#gameSection {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: none;
}

#gameSection:not(.hidden) {
    display: block;
    z-index: 10;
}

#gameSection:not(.hidden) #gameContainer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--cosmos-dark);
}

#gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Payment Overlay */
#paymentLoading.active {
    opacity: 1;
    visibility: visible;
}

#paymentLoading .message,
#paymentLoading .confirmation {
    animation: text-glow 2s infinite;
}

/* Footer */
footer {
    background: var(--cosmos-gradient);
    box-shadow: var(--shadow-neon);
    padding: 1rem;
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 3.5rem;
}

.footer-content {
    text-align: center;
}

footer .version-text {
    font-family: 'VT323', 'Roboto Mono', monospace;
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    color: #000000;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    box-shadow: 0 0 5px var(--neon-magenta);
    position: absolute;
    bottom: 0.5rem;
    right: 1rem;
    animation: none;
}

/* Blink Animation for Version Text */
.animate-blink {
    animation: blink 1s step-start infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

@font-face {
    font-family: 'Press Start 2P';
    src: url('/static/fonts/PressStart2P-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* Hangman Terminal */
.hangman-terminal {
    padding: clamp(2px, 0.8vw, 8px);
    max-width: 100vw;
    min-height: 100vh;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: clamp(3px, 1vw, 6px);
    align-items: center;
    background: #1a1a1a;
    color: #fff;
    position: relative;
    font-family: 'Roboto Mono', monospace;
}

.hangman-terminal .word-display {
    font-size: clamp(0.9rem, 4.5vw, 1.8rem);
    letter-spacing: clamp(0.5px, 0.8vw, 3px);
    margin: clamp(3px, 0.8vw, 6px) 0;
    color: var(--neon-blue);
    text-shadow: 0 0 3px rgba(0, 212, 255, 0.7);
    word-break: break-all;
    text-align: center;
    white-space: nowrap;
}

.hangman-terminal .hint,
.hangman-terminal .category {
    font-style: italic;
    color: var(--neon-magenta);
    margin: clamp(2px, 0.5vw, 5px) 0;
    font-size: clamp(0.7rem, 2.8vw, 1rem);
    text-align: center;
    max-width: 95%;
}

.hangman-terminal .category {
    font-weight: bold;
}

.hangman-terminal .input-area {
    margin: clamp(3px, 1vw, 8px) 0;
    text-align: center;
    width: 100%;
}

.hangman-terminal .input-area input {
    font-size: clamp(0.7rem, 3vw, 0.9rem);
    padding: clamp(1px, 0.8vw, 4px);
    width: clamp(20px, 7vw, 30px);
    text-align: center;
    background: #333;
    color: #fff;
    border: 1px solid var(--neon-blue);
    border-radius: 3px;
}

.hangman-terminal .stats {
    margin: clamp(3px, 1vw, 6px) 0;
    font-size: clamp(0.6rem, 2vw, 0.9rem);
    line-height: 1.2;
    text-align: center;
    color: #ccc;
}

.hangman-terminal pre {
    background: rgba(0, 0, 0, 0.8);
    padding: clamp(3px, 1vw, 6px);
    border: 1px dashed var(--neon-blue);
    display: inline-block;
    margin: clamp(3px, 1vw, 6px) 0;
    box-shadow: 0 0 4px rgba(0, 212, 255, 0.6);
    font-size: clamp(0.5rem, 1.8vw, 0.8rem);
    line-height: 1;
    white-space: pre;
    max-width: 90%;
}

.hangman-terminal .message {
    color: #55ff55;
    font-style: italic;
    margin: clamp(2px, 0.5vw, 5px) 0;
    font-size: clamp(0.7rem, 2.8vw, 1rem);
    text-align: center;
}

.hangman-terminal .streak-text {
    color: var(--neon-magenta);
    font-size: clamp(1rem, 5vw, 2rem);
    font-weight: bold;
    text-shadow: 0 0 6px rgba(255, 0, 229, 0.9), 0 0 12px rgba(255, 0, 229, 0.7);
    margin: clamp(2px, 0.5vw, 5px) 0;
    text-align: center;
    animation: pulse 1.5s ease-in-out infinite;
    background: linear-gradient(45deg, var(--neon-magenta), #FF66FF);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hangman-terminal .terminal-button {
    background: var(--neon-blue);
    color: #000;
    border: none;
    padding: clamp(3px, 1vw, 8px) clamp(6px, 1.5vw, 12px);
    cursor: pointer;
    font-family: 'Roboto Mono', monospace;
    font-size: clamp(0.6rem, 2vw, 0.9rem);
    border-radius: 3px;
    transition: background 0.3s ease;
}

.hangman-terminal .terminal-button:hover {
    background: var(--neon-magenta);
}

.hangman-terminal h1 {
    font-size: clamp(1rem, 4.5vw, 2rem);
    color: var(--neon-blue);
    margin: clamp(2px, 0.5vw, 5px) 0;
    text-align: center;
    font-family: 'Orbitron', sans-serif;
}

.hangman-terminal a.back-to-alan {
    color: var(--neon-blue);
    text-decoration: none;
    font-size: clamp(0.6rem, 2vw, 0.9rem);
}

.hangman-terminal a.back-to-alan:hover {
    color: var(--neon-magenta);
}

/* Animations */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes text-glow {
    0% { text-shadow: 0 0 5px var(--neon-blue); }
    50% { text-shadow: 0 0 15px var(--neon-blue), 0 0 25px var(--neon-magenta); }
    100% { text-shadow: 0 0 5px var(--neon-blue); }
}

@keyframes marquee {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

/* Accessibility: Disable Animations for Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .animate-pulse-glow,
    .animate-glow,
    .animate-blink,
    #scoreMarquee,
    .logo:hover,
    .logo-hover:hover,
    #gameList .game-card:hover:not(.opacity-50) {
        animation: none !important;
        transform: none !important;
        transition: none !important;
    }
}

/* Media Queries */
@media (max-width: 768px) {
    header .logo {
        max-height: 64px;
        max-width: 64px;
        object-fit: contain;
    }

    .logo-container {
        width: 100px;
        height: 100px;
        padding: 12px;
    }

    main {
        padding-top: 60px;
    }

    #gameList {
        grid-template-columns: 1fr;
    }

    #gameContainer {
        max-height: 60vh;
    }

    footer .version-text {
        font-size: clamp(0.7rem, 2vw, 1rem);
        padding: 0.15rem 0.4rem;
        right: 0.5rem;
        bottom: 0.3rem;
    }

    .marquee-container {
        margin-left: clamp(0.3rem, 0.8vw, 0.5rem);
        margin-right: clamp(0.3rem, 0.8vw, 0.5rem);
    }

    #scoreMarquee {
        font-size: clamp(0.5rem, 1.8vw, 0.7rem);
    }

    .hangman-terminal {
        padding: clamp(1px, 0.5vw, 6px);
        gap: clamp(2px, 0.8vw, 5px);
    }

    .hangman-terminal pre {
        padding: clamp(2px, 0.8vw, 5px);
        font-size: clamp(0.4rem, 1.5vw, 0.7rem);
    }

    .hangman-terminal .input-area input {
        width: clamp(18px, 6.5vw, 28px);
    }

    .hangman-terminal .streak-text {
        font-size: clamp(0.9rem, 4.5vw, 1.8rem);
    }
}

@media (max-width: 480px) {
    .hangman-terminal {
        padding: clamp(1px, 0.3vw, 4px);
        max-height: calc(100vh - 40px);
    }

    .hangman-terminal .streak-text {
        font-size: clamp(0.8rem, 4vw, 1.6rem);
    }

    .hangman-terminal pre {
        padding: clamp(2px, 0.5vw, 4px);
        max-width: 85%;
    }

    .hangman-terminal .word-display {
        letter-spacing: clamp(0.3px, 0.5vw, 2px);
        font-size: clamp(0.8rem, 4vw, 1.6rem);
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .hangman-terminal {
        justify-content: flex-start;
        padding: clamp(1px, 0.3vw, 6px);
        gap: clamp(1px, 0.5vw, 4px);
        max-height: 100vh;
    }

    .hangman-terminal .streak-text {
        font-size: clamp(0.8rem, 3.5vw, 1.4rem);
    }

    .hangman-terminal pre {
        font-size: clamp(0.3rem, 1vw, 0.6rem);
        padding: clamp(2px, 0.5vw, 4px);
    }

    .hangman-terminal .word-display {
        font-size: clamp(0.7rem, 3vw, 1.6rem);
    }

    .hangman-terminal .stats {
        font-size: clamp(0.5rem, 1.8vw, 0.8rem);
    }
}