/* Moved all CSS from HTML to this file */
body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background: #050505;
    font-family: 'Space Grotesk', sans-serif;
    color: #e0e0e0;
    overflow: hidden;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        rgba(100,100,100,0.02) 0%,
        rgba(150,150,150,0.03) 50%,
        rgba(100,100,100,0.02) 100%
    );
    animation: flow 80s linear infinite;
    z-index: -1;
    opacity: 1;
}

/* Add CRT screen effect */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(transparent 50%, rgba(0,100,255,0.01) 50%);
    background-size: 100% 2px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.3;
}

@keyframes scanlines {
    0% { transform: translateY(0px); }
    100% { transform: translateY(4px); }
}

/* CRT glow filter - reduced intensity */
/* Removed global filter to improve performance */
/* 
* {
    filter: 
        drop-shadow(0 0 1px rgba(0,150,255,0.1))
        drop-shadow(0 0 2px rgba(0,100,255,0.05))
        brightness(1.02)
        contrast(1.05);
}
*/
@keyframes flow {
    0% { transform: translate(0%, 0%) rotate(45deg); }
    25% { transform: translate(-25%, 25%) rotate(45deg); }
    50% { transform: translate(-50%, 50%) rotate(45deg); }
    75% { transform: translate(-25%, 25%) rotate(45deg); }
    100% { transform: translate(0%, 0%) rotate(45deg); }
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000; /* Solid black for a cryptic feel */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 1s ease-out; /* Fade out for loading screen */
    overflow: hidden; /* Hide overflowing glitch numbers */
}

#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

@keyframes fadeInLoading {
    from { opacity: 0; }
    to { opacity: 1; }
}

.loading-content {
    text-align: center;
    position: relative;
}

.loading-title {
    font-family: 'Space Grotesk', monospace;
    font-size: 5rem;
    font-weight: 700;
    letter-spacing: 0.5em;
    color: #e0e0e0;
    text-transform: lowercase;
    opacity: 0;
    animation: title-fade 4s ease-in-out forwards;
    text-shadow: 0 0 10px #e0e0e0, 0 0 20px #e0e0e0;
}

@keyframes title-fade {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

.glitch-container {
    position: relative;
}

.glitch-text {
    font-family: 'Space Grotesk', monospace;
    font-size: 5rem;
    font-weight: 700;
    letter-spacing: 0.5em;
    color: #e0e0e0;
    text-transform: lowercase;
    display: flex; /* Use flex to align spans */
}

.glitch-text span {
    display: inline-block;
    opacity: 0;
    animation: letter-flicker 3s forwards;
    position: relative;
}

.glitch-text span::before {
    content: '0'; /* Initial content */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    color: var(--primary-color);
    text-shadow: 0 0 15px var(--primary-glow);
    animation: glitch-numbers 0.5s steps(10) infinite;
    opacity: 1;
}

/* Staggered animation delays for each letter */
.glitch-text span:nth-child(1) { animation-delay: 0.2s; }
.glitch-text span:nth-child(2) { animation-delay: 0.4s; }
.glitch-text span:nth-child(3) { animation-delay: 0.6s; }
.glitch-text span:nth-child(4) { animation-delay: 0.8s; }
.glitch-text span:nth-child(5) { animation-delay: 1.0s; }
.glitch-text span:nth-child(6) { animation-delay: 1.2s; }
.glitch-text span:nth-child(7) { animation-delay: 1.4s; }
.glitch-text span:nth-child(8) { animation-delay: 1.6s; }
.glitch-text span:nth-child(9) { animation-delay: 1.8s; }

/* Staggered delays for the number glitching */
.glitch-text span:nth-child(1)::before { animation-delay: 0.1s; }
.glitch-text span:nth-child(2)::before { animation-delay: 0.3s; }
.glitch-text span:nth-child(3)::before { animation-delay: 0.2s; }
.glitch-text span:nth-child(4)::before { animation-delay: 0.5s; }
.glitch-text span:nth-child(5)::before { animation-delay: 0.4s; }
.glitch-text span:nth-child(6)::before { animation-delay: 0.1s; }
.glitch-text span:nth-child(7)::before { animation-delay: 0.6s; }
.glitch-text span:nth-child(8)::before { animation-delay: 0.3s; }
.glitch-text span:nth-child(9)::before { animation-delay: 0.2s; }

@keyframes glitch-numbers {
    0% { content: '1'; }
    10% { content: '7'; }
    20% { content: '3'; }
    30% { content: '9'; }
    40% { content: '5'; }
    50% { content: '8'; }
    60% { content: '2'; }
    70% { content: '6'; }
    80% { content: '4'; }
    90% { content: '0'; }
    100% { content: '1'; }
}

@keyframes letter-flicker {
    0% { opacity: 0; transform: translateY(20px) scale(0.8); text-shadow: none; }
    30% { opacity: 0; } /* Keep letter hidden while numbers glitch */
    40% { 
        opacity: 1; 
        transform: translateY(0) scale(1); 
        text-shadow: 0 0 15px #66ffff, 0 0 30px #66ffff;
    }
    40.1% {
        /* Hide the number glitch pseudo-element */
    }
    45% { opacity: 0.6; transform: translateY(-5px) scale(1.05); }
    50% { opacity: 1; transform: translateY(0) scale(1); }
    80% { opacity: 1; text-shadow: 0 0 15px #66ffff, 0 0 30px #66ffff; }
    100% { opacity: 1; text-shadow: 0 0 10px #e0e0e0, 0 0 20px #e0e0e0; }
}

/* Hide pseudo-element when letter appears */
.glitch-text span {
    animation-name: letter-flicker, hide-pseudo;
    animation-duration: 3s, 3s;
    animation-fill-mode: forwards, forwards;
}

@keyframes hide-pseudo {
    0%, 40% {
        --pseudo-opacity: 1;
    }
    40.1%, 100% {
        --pseudo-opacity: 0;
    }
}

.glitch-text span::before {
    opacity: var(--pseudo-opacity, 1);
}

#glitch-numbers-container {
    display: none;
}

.glitch-number {
    display: none;
}

.loading-logo-container {
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.loading-logo-icon {
    width: 100px; /* Larger icon */
    height: 100px;
    position: relative;
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    background: rgba(20, 20, 20, 0.3);
    border: 3px solid #66ffff; /* Cyan border */
    box-shadow: 0 0 30px rgba(102, 255, 255, 0.8), inset 0 0 20px rgba(50, 200, 200, 0.5);
    animation: loading-pulse 2s infinite alternate;
}

@keyframes loading-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 30px rgba(102, 255, 255, 0.8), inset 0 0 20px rgba(50, 200, 200, 0.5); }
    50% { transform: scale(1.08); box-shadow: 0 0 50px rgba(102, 255, 255, 1), inset 0 0 30px rgba(50, 200, 200, 0.7); }
}

.loading-face-container {
    position: relative;
    width: 60px; /* Larger face */
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.loading-eye {
    position: absolute;
    width: 10px; /* Larger eyes */
    height: 10px;
    background: #66ffff; /* Cyan eyes */
    border-radius: 50%;
    box-shadow: 0 0 15px rgba(102, 255, 255, 0.8);
}

.loading-left-eye {
    left: 8px;
    top: 15px;
}

.loading-right-eye {
    right: 8px;
    top: 15px;
}

.loading-mouth {
    position: absolute;
    bottom: 10px;
    width: 30px; /* Wider mouth */
    height: 5px;
    background: #66ffff; /* Cyan mouth */
    border-radius: 3px;
    box-shadow: 0 0 15px rgba(102, 255, 255, 0.8);
}

.loading-text {
    font-size: 4rem; /* Larger text */
    font-weight: 700;
    letter-spacing: 0.25em;
    text-transform: lowercase;
    color: #cccccc;
    position: relative;
    text-shadow: 
        0 0 30px rgba(102, 255, 255, 0.8),
        0 0 60px rgba(102, 255, 255, 0.6);
}

.loading-text::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;  
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
    box-shadow: 0 0 20px rgba(102, 255, 255, 0.8);
}

.loading-message {
    font-size: 1.5em;
    color: #cccccc;
    margin-top: 3rem; /* Space between logo and message */
    letter-spacing: 0.1em;
    text-shadow: 0 0 15px rgba(200, 200, 200, 0.5);
}

.loading-message span {
    opacity: 0;
    animation: dot-fade 1.5s infinite steps(1, end);
}

.loading-message .dot-1 { animation-delay: 0s; }
.loading-message .dot-2 { animation-delay: 0.5s; }
.loading-message .dot-3 { animation-delay: 1s; }

@keyframes dot-fade {
    0% { opacity: 0; }
    33% { opacity: 1; }
    66% { opacity: 1; }
    100% { opacity: 0; }
}

.logo-container {
    position: relative;
    margin-bottom: 7rem;  
    display: flex;
    flex-direction: column;
    align-items: center;
}

.speech-bubble {
    position: absolute;
    top: -10px;
    left: 120px;
    background: rgba(20, 20, 20, 0.95);
    border: 2px solid var(--primary-border);
    border-radius: 15px;
    padding: 16px 20px;
    max-width: 300px;
    min-width: 200px;
    font-size: 1.05em;
    color: #cccccc;
    text-shadow: 0 0 10px rgba(200,200,200,0.5);
    box-shadow: 
        0 0 20px rgba(100,100,100,0.4),
        inset 0 0 10px rgba(50,50,50,0.2);
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.5s ease-in-out;
    pointer-events: none;
    z-index: 10;
}

.speech-bubble.visible {
    opacity: 1;
    transform: translateX(0);
}

.speech-bubble::before {
    content: '';
    position: absolute;
    left: -10px; /* Points left from the bubble */
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 10px solid var(--primary-border); /* Arrow points left */
}

.speech-bubble::after {
    content: '';
    position: absolute;
    left: -8px; /* Inner triangle */
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 8px solid rgba(20, 20, 20, 0.95); /* Arrow points left */
}

.logo-icon {
    width: 90px;
    height: 90px;
    position: relative;
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    background: rgba(20, 20, 20, 0.3);
    border: 2px solid var(--primary-border);
    transition: all 0.3s ease;
}

.face-container {
    position: relative;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.eye {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #cccccc;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(200, 200, 200, 0.8);
    transition: all 0.3s ease;
}

.left-eye {
    left: 18px;
    top: 15px;
}

.right-eye {
    right: 18px;
    top: 15px;
}

.mouth {
    position: absolute;
    bottom: 12px;
    width: 30px;
    height: 4px;
    background: #cccccc; /* Default straight mouth color */
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(200, 200, 200, 0.8);
    transition: all 0.3s ease; /* For smooth transitions between shapes */
    transform: none; /* Ensure no rotation by default */
}

/* Random circle mouth state */
.mouth.circle-random {
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: #cccccc; /* Use white for circle mouth */
    box-shadow: 0 0 15px rgba(200, 200, 200, 0.8); /* White glow */
}

/* Reactive states (these override random states when face-container has happy/sad) */
.face-container.happy .mouth {
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: #cccccc; /* Use white for happy mouth */
    box-shadow: 0 0 15px rgba(200, 200, 200, 0.8); /* White glow */
    transform: none;
}

.face-container.happy .eye {
    background: #cccccc; /* Use white for happy eyes */
    box-shadow: 0 0 15px rgba(200, 200, 200, 0.8); /* White glow */
}

.face-container.sad .mouth {
    height: 8px;
    border-radius: 10px 10px 0 0;
    background: #ff4444;
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.8);
    transform: rotate(180deg);
}

.face-container.sad .eye {
    background: #ff4444;
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.8);
}

.logo-icon::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.logo-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(255,255,255,0.8);
}

.dot1 { transform: translateX(-10px); animation: moveDot 3s infinite; }
.dot2 { transform: translateX(0px); animation: moveDot 3s infinite 0.5s; }
.dot3 { transform: translateX(10px); animation: moveDot 3s infinite 1s; }

@keyframes moveDot {
    0%, 100% { transform: translateY(0) translateX(var(--x-offset)); }
    50% { transform: translateY(-10px) translateX(var(--x-offset)); }
}

.dot1 { --x-offset: -10px; }
.dot2 { --x-offset: 0px; }
.dot3 { --x-offset: 10px; }

.logo-text {
    font-size: 3.6rem;
    font-weight: 300;
    letter-spacing: 0.2em;
    text-transform: lowercase;
    color: #cccccc;
    position: relative;
    text-shadow: 
        0 0 20px var(--primary-text-shadow),
        0 0 40px hsla(var(--level-hue), 50%, 50%, 0.4);
}

.logo-text::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;  
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
}

#scaling-wrapper {
    transition: transform 0.5s ease-in-out;
    width: 100vw;
    height: 100vh;
    display: flex;            /* Ensure the game stays centered in the viewport */
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    will-change: transform;   /* Hint for smoother scaling */
    touch-action: manipulation; /* Improve touch interactions (prevents double-tap zoom) */
}

.game-container {
    background: rgba(10, 10, 10, 0.95);
    padding: 3rem;  
    border-radius: 20px;  
    border: 3px solid #f0f0f0;
    box-shadow: 
        0 0 70px hsla(var(--level-hue), 60%, 50%, 0.4),
        inset 0 0 50px rgba(20,20,20,0.1);  
    text-align: center;
    color: #cccccc;
    transition: width 0.5s ease-in-out, height 0.7s ease-in-out, opacity 0.7s ease-in-out, transform 0.5s ease-in-out; /* Added opacity and transform transition */
    position: relative;
    z-index: 1;
    margin: 0; /* Changed from margin: -2rem auto; */
    padding-bottom: 5rem; 
    transform-origin: center center; 
    visibility: hidden;
    max-width: 100%;
    max-height: 100%;
}

/* Glitch-in Animation */
.glitch-in {
    visibility: visible !important;
    animation: smoothFadeScale 1.2s ease-out forwards;
    will-change: opacity, transform;
}

/* Disable heavy overlay layers for a cleaner effect */
.glitch-in::before,
.glitch-in::after {
    content: none;
}

/* New smoother intro animation */
@keyframes smoothFadeScale {
    0% {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
        filter: blur(2px);
    }
    50% {
        opacity: 1;
        transform: translateY(0) scale(1.01);
        filter: blur(0.5px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@keyframes glitch-in-base {
    0% {
        opacity: 0;
        transform: scale(0.9) skew(5deg);
    }
    20% {
        opacity: 1;
        transform: scale(1) skew(0deg);
    }
    80% {
        opacity: 1;
        transform: scale(1) skew(0deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) skew(0deg);
    }
}

@keyframes glitch-effect-1 {
    0% { transform: translate(0, 0); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); }
    5% { transform: translate(-10px, 5px); clip-path: polygon(0 15%, 100% 15%, 100% 20%, 0 20%); }
    10% { transform: translate(10px, -5px); clip-path: polygon(0 80%, 100% 80%, 100% 85%, 0 85%); }
    15% { transform: translate(-5px, 10px); clip-path: polygon(0 45%, 100% 45%, 100% 50%, 0 50%); }
    20% { transform: translate(5px, -10px); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); }
    30% { transform: translate(-8px, 4px); clip-path: polygon(0 50%, 100% 50%, 100% 55%, 0 55%); }
    40% { transform: translate(8px, -4px); clip-path: polygon(0 10%, 100% 10%, 100% 12%, 0 12%); }
    50% { transform: translate(0, 0); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); }
    80% { transform: translate(0, 0); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); opacity: 1; }
    100% { transform: translate(0, 0); opacity: 0; }
}

@keyframes glitch-effect-2 {
    0% { transform: translate(0, 0); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); }
    7% { transform: translate(12px, -6px); clip-path: polygon(0 30%, 100% 30%, 100% 33%, 0 33%); }
    14% { transform: translate(-12px, 6px); clip-path: polygon(0 90%, 100% 90%, 100% 95%, 0 95%); }
    21% { transform: translate(6px, -12px); clip-path: polygon(0 60%, 100% 60%, 100% 62%, 0 62%); }
    28% { transform: translate(-6px, 12px); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); }
    40% { transform: translate(10px, -5px); clip-path: polygon(0 70%, 100% 70%, 100% 72%, 0 72%); }
    50% { transform: translate(-10px, 5px); clip-path: polygon(0 25%, 100% 25%, 100% 27%, 0 27%); }
    60% { transform: translate(0, 0); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); }
    80% { transform: translate(0, 0); clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%); opacity: 1; }
    100% { transform: translate(0, 0); opacity: 0; }
}

/* New class for fading the game container */
.game-container.fade-game-out {
    opacity: 0.2; /* Faded state */
    pointer-events: none; /* Disable interactions */
}

.insertion-point {
    width: 70px;  
    height: 100px;  
    background-color: rgba(30, 30, 30, 0.8);
    border: 2px dashed var(--primary-border);
    border-radius: 15px;  
    cursor: pointer;
    margin: 0 5px;  
    transition: all 0.3s ease-in-out;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.insertion-point:hover {
    background-color: rgba(100,100,100,0.2);
    border: 2px solid var(--primary-color);
    box-shadow: 
        0 0 20px var(--primary-glow),
        inset 0 0 10px hsla(var(--level-hue), 50%, 50%, 0.2);
    transform: scale(1.05);
    transition: all 0.3s ease-in-out;
}

.insertion-point::before {
    content: '+';
    font-size: 32px;
    color: var(--primary-color);
    text-shadow: 
        0 0 15px var(--primary-glow),
        0 0 30px var(--primary-text-shadow);
    transition: all 0.3s;
}

.insertion-point:hover::before {
    transform: scale(1.2);
    text-shadow: 
        0 0 25px var(--primary-glow),
        0 0 50px var(--primary-text-shadow);
}

.number-box {
    width: 70px;  
    height: 100px;  
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    font-size: 28px;  
    background: #111111;
    border: 3px solid var(--primary-border);  
    min-width: 70px;  
    color: #cccccc;
    text-shadow: 
        0 0 15px var(--primary-text-shadow),
        0 0 30px hsla(var(--level-hue), 50%, 50%, 0.4);
    border-radius: 12px;  
    /* animation: pulse 2s ease-in-out infinite;  Disabled for performance */
    box-shadow: 
        0 0 20px hsla(var(--level-hue), 50%, 50%, 0.4),
        inset 0 0 10px rgba(50,50,50,0.2);
    font-family: 'Space Grotesk', sans-serif;
    margin: 0 5px;  
    box-sizing: border-box;
}

.number-box.filled {
    background: #1a1a1a;
    border-color: var(--primary-border);
    color: #cccccc;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

#sequence-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin: 30px auto;
    padding: 10px 15px;
    min-height: 120px;
    position: relative;
    border: 2px solid #f0f0f0;
    border-radius: 10px;
    /* animation: container-glow 2s ease-in-out infinite; Disabled for performance */
    width: fit-content;
    background: rgba(20,20,20,0.2);
}

@keyframes container-glow {
    0%, 100% { 
        box-shadow: 
            0 0 20px hsla(var(--level-hue), 50%, 50%, 0.3),
            inset 0 0 20px rgba(50,50,50,0.1);
    }
    50% { 
        box-shadow: 
            0 0 40px var(--primary-glow),
            inset 0 0 30px hsla(var(--level-hue), 50%, 50%, 0.2);
    }
}

#messages {
    margin: 30px 0;
    padding: 15px;
    border-radius: 8px;
    font-size: 1.1em;
    text-shadow: 
        0 0 10px var(--primary-text-shadow),
        0 0 20px hsla(var(--level-hue), 50%, 50%, 0.3);
    font-family: 'Space Grotesk', sans-serif;
    color: #cccccc;
    white-space: pre-line;
    transition: all 0.6s ease-in-out;
}

.success {
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    text-shadow: 
        0 0 15px var(--primary-glow),
        0 0 30px var(--primary-text-shadow);
}

.error {
    color: #ff8888;
    border: 2px solid #ff8888;
    animation: error-shake 0.5s;
    text-shadow: 
        0 0 15px #ff8888,
        0 0 30px rgba(255,136,136,0.5);
}

@keyframes error-shake {
    0%, 100% { transform: translateX(0); animation-timing-function: ease-in-out; } 
    20%, 40%, 60%, 80% { transform: translateX(10px); animation-timing-function: ease-in-out; }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); animation-timing-function: ease-in-out; }
}

.progress-info {
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 1.1em;
    text-shadow: 
        0 0 10px var(--primary-text-shadow),
        0 0 20px hsla(var(--level-hue), 50%, 50%, 0.3);
    color: #cccccc;
    justify-content: center; /* Center items horizontally */
    width: 100%; /* Ensure it spans full container so centering is consistent */
}

.progress-indicator {
    position: absolute;
    left: -60px; /* Shifted further left to accommodate extra length */
    top: 50%;
    transform: translateY(-50%);
    width: 20px; /* Slightly thicker */
    height: 700px; /* Made 40% longer */
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    border: 2px solid var(--primary-border);
    display: flex;
    flex-direction: column-reverse; /* Stacks segments from bottom (level 1) to top */
    justify-content: flex-start; /* Ensures segments start from the bottom */
    padding: 2px; /* Small padding inside the bar */
    overflow: hidden;
    transition: border-color 0.5s ease-in-out, box-shadow 0.5s ease-in-out; 
    z-index: 1; 
}

/* Remove the old ::after pseudo-element from progress-indicator as it's replaced by dynamic elements */
.progress-indicator::after {
    content: none; 
}

/* Styles for individual level segments within the progress indicator */
.level-segment {
    width: 100%;
    /* Height will be set dynamically in JS */
    border-radius: 5px;
    margin-bottom: 2px; /* Small gap between segments */
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
    position: relative; /* For inner fill positioning */
    overflow: hidden; /* Ensure fill doesn't overflow */
    transition: background 0.5s ease-in-out, border 0.5s ease-in-out, box-shadow 0.5s ease-in-out;
}

/* Style for the 'liquid' fill within the current level's segment */
.current-level-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    /* Height set dynamically by JS --round-progress-height */
    box-shadow: 
        0 0 10px var(--primary-glow),
        0 0 20px var(--primary-glow) inset;
    transition: height 0.1s linear, background 0.5s ease-in-out, box-shadow 0.5s ease-in-out; 
    background-size: 100% 10px;
    background-repeat: repeat-y;
    /* animation: silverFlow 3s linear infinite; Disabled for performance */
    border-radius: inherit; /* Inherit border radius from .level-segment */
}

/* Original silverFlow animation (for normal mode) */
@keyframes silverFlow {
    0% { background-position: 0 0; }
    100% { background-position: 0 10px; }
}

:root {
    --level-hue: 210; /* Default blue hue */
    --primary-color: hsl(var(--level-hue), 70%, 60%);
    --primary-glow: hsl(var(--level-hue), 70%, 60%);
    --primary-border: hsl(var(--level-hue), 50%, 50%);
    --primary-text-shadow: hsla(var(--level-hue), 70%, 60%, 0.8);
}

#current-level,
#current-round,
#total-fails {
    color: #cccccc;
    margin: 1rem 0;
    font-size: 1.2em;
    font-weight: 600;
    text-shadow: 
        0 0 10px var(--primary-text-shadow),
        0 0 20px hsla(var(--level-hue), 50%, 50%, 0.4);
}

.button-container {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 0;
    width: auto;
}

#next-level-btn {
    padding: 15px 30px;
    background: linear-gradient(45deg, #00ff00, #00aa00);
    color: #fff;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1.1em;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: all 0.3s;
    font-family: 'Space Grotesk', sans-serif;
    margin: 0;
    display: none; /* Keeps this button hidden by default */
}

#next-level-btn:hover {
    background: linear-gradient(45deg, #00cc00, #008800);
}

#restart-btn {
    padding: 15px 30px;
    position: relative;
    overflow: hidden;
    background-color: hsla(var(--level-hue), 80%, 10%, 1);
    border: 2px solid var(--primary-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--primary-color);
    border-radius: 25px;
    cursor: pointer;
    font-size: 1.1em;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-family: 'Space Grotesk', sans-serif;
    animation: restart-glow 2s infinite;
    text-shadow: 0 0 10px var(--primary-glow);
    display: inline-block; /* Ensure this button is always visible */
    margin: 0;
}

#restart-btn:hover {
    transform: scale(1.05) rotate(-2deg);
    box-shadow: 
        0 0 30px var(--primary-glow),
        inset 0 0 20px hsla(var(--level-hue), 50%, 30%, 0.2);
}

@keyframes restart-glow {
    0% { 
        box-shadow: 
            0 0 5px hsla(var(--level-hue), 70%, 50%, 0.4),
            inset 0 0 10px hsla(var(--level-hue), 80%, 20%, 0.1);
    }
    100% { 
        box-shadow: 
            0 0 20px var(--primary-glow),
            inset 0 0 20px hsla(var(--level-hue), 60%, 40%, 0.2);
    }
}

#number-odds {
    color: #cccccc;
    margin: 1rem 0;
    font-size: 1.2em;
    text-shadow: 
        0 0 15px var(--primary-text-shadow),
        0 0 30px hsla(var(--level-hue), 50%, 50%, 0.4);
    font-weight: 500;
    letter-spacing: 0.05em;
    transition: opacity 0.6s ease-in-out, transform 0.6s ease-in-out;
}

#new-number-box {
    font-size: 3em;
    font-weight: bold;
    color: #cccccc;
    text-shadow: 
        0 0 15px var(--primary-text-shadow),
        0 0 30px hsla(var(--level-hue), 50%, 60%, 0.6),
        0 0 45px hsla(var(--level-hue), 40%, 40%, 0.4);
    border: 3px solid var(--primary-border);
    border-radius: 15px;
    padding: 20px;
    margin: 20px auto;
    width: fit-content;
    animation: glow 1.5s ease-in-out alternate;
    font-family: 'Space Grotesk', sans-serif;
    transition: opacity 0.6s ease-in-out, transform 0.6s ease-in-out;
    opacity: 1;
    transform: translateY(0);
    background: rgba(20,20,20,0.3);
    box-shadow: 
        0 0 30px hsla(var(--level-hue), 50%, 50%, 0.4),
        inset 0 0 20px rgba(50,50,50,0.2);
}

.hide-smooth {
    opacity: 0 !important;
    transform: translateY(-20px) !important;
    transition: opacity 0.6s ease-in-out, transform 0.6s ease-in-out;
}

#how-to-play-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(45deg, var(--primary-color), var(--primary-border));
    border: 3px solid #fff;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 
        0 0 25px hsla(var(--level-hue), 70%, 70%, 0.8),
        inset 0 0 15px rgba(50,50,50,0.5);
    transition: all 0.3s;
    text-shadow: 0 0 15px rgba(255,255,255,1);
    font-size: 2em;
    display: flex;
    justify-content: center;
    align-items: center;
}

#how-to-play-btn:hover {
    transform: scale(1.15);
    box-shadow: 
        0 0 35px var(--primary-glow),
        inset 0 0 20px hsla(var(--level-hue), 50%, 50%, 0.6);
    background: linear-gradient(45deg, var(--primary-glow), hsla(var(--level-hue), 60%, 40%, 1));
}

#how-to-play-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-in-out;
}

.popup-content {
    background: rgba(10,10,10,0.95);
    padding: 2rem;
    border-radius: 15px;
    border: 2px solid var(--primary-border);
    max-width: 480px; /* Reduced max-width */
    width: 90%; /* Ensure it's responsive on smaller screens */
    max-height: 80vh; /* Set max height for scrolling */
    display: flex; /* Use flexbox for layout */
    flex-direction: column; /* Stack children vertically */
    position: relative;
    box-shadow: 
        0 0 50px hsla(var(--level-hue), 50%, 50%, 0.6),
        inset 0 0 30px rgba(50,50,50,0.2);
    color: #cccccc;
    text-shadow: 0 0 10px rgba(200,200,200,0.3);
    text-align: left; /* Align text left for better readability */
}

.popup-scroll-content {
    flex-grow: 1; /* Allow this section to grow and take available space */
    overflow-y: auto; /* Enable vertical scrolling */
    padding-right: 15px; /* Add padding for scrollbar */
    margin-top: 1rem; /* Space between title and scrollable content */
    scroll-behavior: smooth; /* Smooth scrolling */
}

/* Custom scrollbar styling for WebKit browsers */
.popup-scroll-content::-webkit-scrollbar {
    width: 8px;
}

.popup-scroll-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

.popup-scroll-content::-webkit-scrollbar-thumb {
    background: hsla(var(--level-hue), 50%, 60%, 0.7);
    border-radius: 10px;
    border: 1px solid hsla(var(--level-hue), 50%, 70%, 0.8);
    box-shadow: 0 0 8px hsla(var(--level-hue), 50%, 60%, 0.5);
}

.popup-scroll-content::-webkit-scrollbar-thumb:hover {
    background: hsla(var(--level-hue), 50%, 70%, 0.9);
}

.popup-content h2 {
    font-size: 2.5em;
    color: var(--primary-color);
    text-align: center;
    margin-top: 0;
    margin-bottom: 0.5rem; /* Reduced margin bottom as scroll content has top margin */
    text-shadow: 0 0 15px var(--primary-glow);
    flex-shrink: 0; /* Prevent title from shrinking */
}

.popup-content h3 {
    font-size: 1.4em;
    color: #e0e0e0;
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
    text-shadow: 0 0 8px rgba(200,200,200,0.5);
    display: flex;
    align-items: center;
    gap: 10px;
}

.popup-content p {
    font-size: 1.1em;
    line-height: 1.6;
    margin-bottom: 1em;
}

.popup-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.popup-content li {
    font-size: 1.05em;
    line-height: 1.8;
    margin-bottom: 0.5em;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.popup-section {
    background: rgba(30,30,30,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.3);
}

.popup-icon {
    font-size: 1.8em;
    color: var(--primary-color);
    text-shadow: 0 0 10px var(--primary-glow);
}

.popup-icon-small {
    font-size: 1.2em;
    color: var(--primary-color);
    text-shadow: 0 0 5px var(--primary-glow);
    flex-shrink: 0; /* Prevent icon from shrinking */
    width: 1.2em; /* Ensure consistent width */
    text-align: center;
}

.highlight {
    color: var(--primary-color);
    font-weight: bold;
    text-shadow: 0 0 8px var(--primary-glow);
}

.plus-icon {
    font-weight: bold;
    color: var(--primary-color);
    text-shadow: 0 0 5px var(--primary-glow);
}

#close-popup {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 1.8em;
    color: #cccccc;
    cursor: pointer;
    transition: all 0.2s;
    text-shadow: 0 0 10px rgba(200,200,200,0.5);
}

#close-popup:hover {
    color: #ff4444;
    transform: scale(1.2);
    text-shadow: 0 0 15px #ff4444;
}

#settings-btn {
    position: fixed;
    bottom: 30px;
    right: 100px; /* Positioned next to the how-to-play button */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(45deg, #888, #555);
    border: 3px solid #fff;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 
        0 0 25px rgba(200,200,200,0.6),
        inset 0 0 15px rgba(50,50,50,0.5);
    transition: all 0.3s;
    text-shadow: 0 0 15px rgba(255,255,255,1);
    font-size: 2em;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1; /* Ensure icon is vertically centered by removing extra line height */
}

#settings-btn:hover {
    transform: scale(1.15) rotate(45deg);
    box-shadow: 
        0 0 35px rgba(200,200,200,0.8),
        inset 0 0 20px rgba(80,80,80,0.6);
    background: linear-gradient(45deg, #aaa, #666);
}

#settings-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-in-out;
}

#close-settings-popup {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 1.8em;
    color: #cccccc;
    cursor: pointer;
    transition: all 0.2s;
    text-shadow: 0 0 10px rgba(200,200,200,0.5);
}

#close-settings-popup:hover {
    color: #ff4444;
    transform: scale(1.2);
    text-shadow: 0 0 15px #ff4444;
}

.settings-tabs {
    display: flex;
    border-bottom: 2px solid var(--primary-border);
    margin-bottom: 1.5rem;
}

.tab-btn {
    background: none;
    border: none;
    color: #888;
    padding: 1rem 1.5rem;
    font-size: 1.1em;
    font-family: 'Space Grotesk', sans-serif;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    top: 2px; /* Align with bottom border */
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: #ccc;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    text-shadow: 0 0 10px var(--primary-glow);
}

.settings-scroll-content {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 15px;
    scroll-behavior: smooth;
}

.settings-scroll-content::-webkit-scrollbar {
    width: 8px;
}

.settings-scroll-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

.settings-scroll-content::-webkit-scrollbar-thumb {
    background: hsla(var(--level-hue), 50%, 60%, 0.7);
    border-radius: 10px;
    border: 1px solid hsla(var(--level-hue), 50%, 70%, 0.8);
    box-shadow: 0 0 8px hsla(var(--level-hue), 50%, 60%, 0.5);
}

.settings-scroll-content::-webkit-scrollbar-thumb:hover {
    background: hsla(var(--level-hue), 50%, 70%, 0.9);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.settings-section {
    background: rgba(30,30,30,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.setting-item label {
    font-size: 1.1em;
}

.setting-note {
    font-size: 0.9em;
    color: #999;
    margin-top: -0.5rem;
    font-style: italic;
    line-height: 1.4;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #888;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 150px;
    height: 8px;
    background: #444;
    border-radius: 5px;
    outline: none;
    transition: opacity .2s;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #111;
    box-shadow: 0 0 10px var(--primary-glow);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #444;
    transition: .4s;
}

.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: #ccc;
    transition: .4s;
}

.toggle-switch input:checked + .slider {
    background-color: var(--primary-color);
    box-shadow: 0 0 8px var(--primary-glow);
}

.toggle-switch input:checked + .slider:before {
    transform: translateX(22px);
    background-color: white;
}

.toggle-switch .slider.round {
    border-radius: 34px;
}

.toggle-switch .slider.round:before {
    border-radius: 50%;
}

#reset-progress-btn {
    background-color: #8B0000;
    color: white;
    border: 2px solid #ff4444;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.9em;
    transition: all 0.3s;
}

#reset-progress-btn:hover {
    background-color: #B22222;
    transform: scale(1.05);
    box-shadow: 0 0 15px #ff4444;
}

/* High Contrast Mode Styles */
body.high-contrast * {
    filter: none;
    text-shadow: none !important;
    box-shadow: none !important;
}
body.high-contrast {
    background: #000;
    color: #fff;
}
body.high-contrast .game-container, 
body.high-contrast .popup-content {
    background: #000;
    border-color: #fff;
}
body.high-contrast .number-box,
body.high-contrast #new-number-box,
body.high-contrast .insertion-point {
    background: #111;
    border-color: #fff;
    color: #fff;
}
body.high-contrast .insertion-point:hover {
    background: #333;
}
body.high-contrast .insertion-point::before {
    color: #fff;
}
body.high-contrast .logo-text,
body.high-contrast #restart-btn,
body.high-contrast .highlight,
body.high-contrast .popup-icon {
    color: #fff;
}
body.high-contrast #restart-btn,
body.high-contrast .tab-btn.active {
    border-color: #fff;
}

/* Reduce Motion Styles */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
    animation: none !important;
    transition: none !important;
}
body.reduce-motion .insertion-point:hover {
    transform: none; /* Disable hover scaling */
}
body.reduce-motion #restart-btn:hover {
    transform: none; /* Disable hover scaling/rotation */
}

.particle-overlay {
    display: none !important;
}

.particle {
    display: none !important;
}

.glow-line {
    display: none !important;
}

#next-level-btn, #restart-btn {
    transition: opacity 0.6s ease-in-out, transform 0.6s ease-in-out, display 0.3s linear 0.6s;
}

.flash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.flash-overlay.active {
    opacity: 1;
}

.flash-content {
    text-align: center;
    animation: flashPulse 1.5s ease-in-out;
}

.flash-text {
    font-size: 4rem;
    font-weight: 700;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    background: linear-gradient(45deg, #00ff88, #00ddff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 
        0 0 30px rgba(0,255,136,0.8),
        0 0 60px rgba(0,200,255,0.6);
    animation: glowFlash 1s ease-in-out infinite alternate;
}

.flash-overlay.error .flash-text {
    background: linear-gradient(45deg, #ff4444, #ff00ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 
        0 0 30px rgba(255,68,68,0.8),
        0 0 60px rgba(255,0,255,0.6);
}

@keyframes flashPulse {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes glowFlash {
    from { 
        text-shadow: 
            0 0 30px rgba(0,255,136,0.8),
            0 0 60px rgba(0,200,255,0.6);
    }
    to { 
        text-shadow: 
            0 0 50px rgba(0,255,136,1),
            0 0 100px rgba(0,200,255,0.8);
    }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}