body {  
    /* Refined modern blue-dominated color palette */  
    --background-color: #f7fafc;  
    --background-gradient: linear-gradient(135deg, #f7fafc 0%, #e2e8f0 50%, #cbd5e0 100%);
    --wall-color: #1a202c;  
    --wall-shadow: #0d1117;
    --joystick-color: #2d3748;  
    --joystick-head-color: #fd7f28;  
    --ball-color: #fd7f28;  
    --end-color: #0bc5ea;  
    --text-color: #1a202c;  
    --accent-color: #3182ce;
    --card-background: rgba(255, 255, 255, 0.95);
    --shadow-light: 0 2px 10px rgba(44, 62, 80, 0.1);
    --shadow-medium: 0 4px 20px rgba(44, 62, 80, 0.15);
    --shadow-heavy: 0 8px 30px rgba(44, 62, 80, 0.2);
    --header-height: 90px; /* Increased for proper spacing with single-line top bar */
    font-family: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;  
    background: var(--background-gradient);
    font-weight: 400;
    letter-spacing: -0.01em;
}

html,  
body {  
    height: 100vh;  
    margin: 0;  
    padding: 0;
    overflow: hidden;
    touch-action: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Corner-positioned floating displays */
.top-bar-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: min(8vh, 80px);
    z-index: 1000;
    pointer-events: none;
    background: transparent;
}

.floating-display {
    position: absolute;
    top: min(3vh, 25px);
    font-weight: 600;
    color: white;
    pointer-events: auto;
    z-index: 1001;
}

#score-display {
    left: min(4vw, 30px);
}

#timer-display {
    right: min(4vw, 30px);
}

#score-display, #timer-display {
    color: white;
    padding: 14px 24px;
    border-radius: 18px;
    font-size: min(3.5vw, 20px);
    font-weight: 800;
    overflow: hidden;
    transition: all 0.3s ease;
    white-space: nowrap;
    min-width: 120px;
    text-align: center;
}

#score-display::before, #timer-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s;
}

#score-display:hover::before, #timer-display:hover::before {
    left: 100%;
}

#score-display {
    background: linear-gradient(135deg, rgba(49, 130, 206, 0.95), rgba(26, 32, 44, 0.95));
    backdrop-filter: blur(25px);
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 
        0 8px 32px rgba(49, 130, 206, 0.3),
        0 4px 16px rgba(0, 0, 0, 0.1);
}

#timer-display {
    background: linear-gradient(135deg, rgba(11, 197, 234, 0.95), rgba(0, 150, 136, 0.95));
    backdrop-filter: blur(25px);
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 
        0 8px 32px rgba(11, 197, 234, 0.3),
        0 4px 16px rgba(0, 0, 0, 0.1);
}


/* Mode Selection Screen Styles */
.mode-selection-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--background-color) 0%, #f8f4f1 100%);
    padding: 20px;
    box-sizing: border-box;
}

.mode-selection-content {
    text-align: center;
    max-width: 650px;
    width: 100%;
    background: var(--card-background);
    border-radius: 24px;
    padding: 50px 40px;
    box-shadow: var(--shadow-heavy);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.game-title {
    font-size: min(8vw, 52px);
    color: var(--text-color);
    margin: 0 0 20px 0;
    font-weight: 800;
    background: linear-gradient(135deg, var(--text-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.game-description {
    font-size: min(4vw, 20px);
    color: var(--text-color);
    margin: 0 0 40px 0;
    opacity: 0.7;
    font-weight: 500;
    line-height: 1.5;
}

.mode-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 30px 0 20px 0;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 18px 36px;
    font-size: min(4vw, 22px);
    font-weight: 700;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 180px;
    box-shadow: var(--shadow-heavy);
    border: 2px solid rgba(255, 255, 255, 0.3);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

.mode-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}
.mode-btn:hover::before {
    left: 100%;
}

.countdown-display {
    text-align: center;
    font-size: min(3.2vw, 16px);
    font-weight: 500;
    color: #7f8c8d;
    margin: 15px 0;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(149, 165, 166, 0.2);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    animation: subtleGlow 2s ease-in-out infinite alternate;
}

@keyframes subtleGlow {
    0% { 
        transform: scale(1);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    }
    100% { 
        transform: scale(1.01);
        box-shadow: 0 4px 15px rgba(52, 152, 219, 0.15);
    }
}

.easy-btn {
    background: linear-gradient(135deg, var(--accent-color) 0%, #2b77cb 100%);
    color: white;
}

.easy-btn:hover {
    background: linear-gradient(135deg, #2b77cb 0%, var(--accent-color) 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
}

.hard-btn {
    background: linear-gradient(135deg, var(--end-color) 0%, #0097a7 100%);
    color: white;
}

.hard-btn:hover {
    background: linear-gradient(135deg, #0097a7 0%, var(--end-color) 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
}

.mode-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 30px;
}

.mode-detail {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(248, 249, 250, 0.6));
    padding: 24px;
    border-radius: 16px;
    border: 1px solid rgba(44, 62, 80, 0.1);
    box-shadow: var(--shadow-light);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.mode-detail:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.mode-detail h3 {
    margin: 0 0 12px 0;
    color: var(--text-color);
    font-size: min(3.5vw, 18px);
    font-weight: 700;
    letter-spacing: 0.3px;
}

.mode-detail p {
    margin: 0;
    font-size: min(3vw, 15px);
    color: var(--text-color);
    opacity: 0.8;
    line-height: 1.5;
    font-weight: 500;
}

#center {  
    display: flex;  
    align-items: center;  
    justify-content: center;  
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    width: 100%;
    width: 100vw;
    z-index: 1;
    overflow: hidden;
    /* Mobile-first optimization */
    -webkit-overflow-scrolling: touch;
    touch-action: none;
}


#game {  
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    perspective: 600px;
    position: relative;
    width: 100%;
    height: 100%;
    max-width: none;
}

#maze {  
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px !important;  
    height: 290px !important;  
    display: flex;  
    justify-content: center;  
    align-items: center;
    border: 3px solid var(--wall-color);
    background: linear-gradient(135deg, var(--background-color) 0%, #edf2f7 50%, var(--background-color) 100%);
    border-radius: 24px;
    box-shadow: 
        0 12px 40px rgba(26, 32, 44, 0.25), 
        inset 0 4px 20px rgba(255, 255, 255, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.9);
    transform-origin: center center;
    backface-visibility: hidden;
    will-change: transform;
    contain: layout style paint;
    overflow: hidden;
    z-index: 10;
    flex-shrink: 0;
    min-width: 320px;
    min-height: 290px;
    /* Mobile touch optimization */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#maze::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, var(--wall-color), var(--accent-color), var(--wall-color));
    border-radius: 22px;
    z-index: -1;
    opacity: 0.1;
}

#end {  
    width: 65px;  
    height: 65px;  
    background: radial-gradient(circle, var(--end-color) 0%, #00b894 100%);
    border: 4px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    box-shadow: var(--shadow-medium), inset 0 2px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    animation: targetPulse 2s ease-in-out infinite;
}

#end::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

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

#joystick {  
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--joystick-color), #1a202c);  
    border-radius: 50%;  
    width: 60px;  
    height: 60px;  
    display: flex;  
    align-items: center;  
    justify-content: center;  
    margin: 0;
    box-shadow: 
        0 8px 25px rgba(26, 32, 44, 0.3),
        inset 0 2px 10px rgba(255, 255, 255, 0.1),
        inset 0 -2px 8px rgba(0, 0, 0, 0.3);
    z-index: 10;
    /* Mobile touch optimization */
    touch-action: manipulation;
    cursor: pointer;
}

#joystick-head {  
    position: relative;  
    background: radial-gradient(circle at 30% 30%, #ff9500, var(--joystick-head-color));  
    border-radius: 50%;  
    width: 28px;  
    height: 28px;  
    cursor: grab;  
    animation-name: modernGlow;  
    animation-duration: 2s;  
    animation-iteration-count: infinite;  
    animation-direction: alternate;  
    transition: all 0.2s ease;
    box-shadow: 
        0 6px 20px rgba(253, 127, 40, 0.5),
        inset 0 2px 8px rgba(255, 255, 255, 0.4),
        inset 0 -1px 4px rgba(0, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    /* Mobile touch optimization */
    touch-action: none;
}

#joystick-head:active {
    cursor: grabbing;
    transform: scale(0.95);
}

@keyframes modernGlow {  
    0% {  
        transform: scale(1);
        box-shadow: var(--shadow-light), inset 0 1px 4px rgba(255, 255, 255, 0.3);  
    }  
    100% {  
        transform: scale(1.1);
        box-shadow: var(--shadow-medium), inset 0 1px 6px rgba(255, 255, 255, 0.5), 0 0 20px rgba(231, 76, 60, 0.3);  
    }  
}

@keyframes glow {  
    0% {  
        transform: scale(1);  
    }  
    100% {  
        transform: scale(1.2);  
    }  
}

.joystick-arrow:nth-of-type(1) {  
    position: absolute;  
    bottom: 65px;  
    width: 0;  
    height: 0;  
    border-left: 8px solid transparent;  
    border-right: 8px solid transparent;  
    border-bottom: 12px solid rgba(255, 255, 255, 0.7);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.joystick-arrow:nth-of-type(2) {  
    position: absolute;  
    top: 65px;  
    width: 0;  
    height: 0;  
    border-left: 8px solid transparent;  
    border-right: 8px solid transparent;  
    border-top: 12px solid rgba(255, 255, 255, 0.7);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.joystick-arrow:nth-of-type(3) {  
    position: absolute;  
    left: 65px;  
    width: 0;  
    height: 0;  
    border-top: 8px solid transparent;  
    border-bottom: 8px solid transparent;  
    border-left: 12px solid rgba(255, 255, 255, 0.7);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.joystick-arrow:nth-of-type(4) {  
    position: absolute;  
    right: 65px;  
    width: 0;  
    height: 0;  
    border-top: 8px solid transparent;  
    border-bottom: 8px solid transparent;  
    border-right: 12px solid rgba(255, 255, 255, 0.7);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

#note {  
    text-align: center;  
    font-size: min(3.5vw, 16px);  
    color: var(--text-color);  
    transition: opacity 0.5s ease;
    line-height: 1.3;
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: var(--card-background);
    padding: 12px 24px;
    border-radius: 16px;
    box-shadow: var(--shadow-medium);
    border: 1px solid rgba(44, 62, 80, 0.1);
    backdrop-filter: blur(10px);
    font-weight: 500;
    margin: 0;
    width: min(85vw, 360px);
    max-width: 360px;
    min-width: 300px;
    /* Mobile optimization */
    font-size: 15px;
}

a:visited {  
    color: inherit;  
}

.ball {  
    position: absolute;  
    margin-top: -5px;  
    margin-left: -5px;  
    border-radius: 50%;  
    background: radial-gradient(circle at 30% 30%, #ff6b6b, var(--ball-color), #c0392b);  
    width: 10px;  
    height: 10px;
    box-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.3),
        inset 1px 1px 2px rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.wall {  
    position: absolute;  
    background: linear-gradient(135deg, var(--wall-color), var(--wall-shadow));  
    transform-origin: top center;  
    margin-left: -5px;
    border-radius: 2px;
    box-shadow: 
        2px 2px 6px rgba(0, 0, 0, 0.2),
        inset 1px 1px 2px rgba(255, 255, 255, 0.1),
        inset -1px -1px 2px rgba(0, 0, 0, 0.1);
}

.wall::before,  
.wall::after {  
    display: block;  
    content: "";  
    width: 10px;  
    height: 10px;  
    background: radial-gradient(circle, var(--wall-color), var(--wall-shadow));  
    border-radius: 50%;  
    position: absolute;
    box-shadow: 
        1px 1px 3px rgba(0, 0, 0, 0.3),
        inset 1px 1px 1px rgba(255, 255, 255, 0.1);
}

.wall::before {  
    top: -5px;  
}

.wall::after {  
    bottom: -5px;  
}

.black-hole {  
    position: absolute;  
    margin-top: -9px;  
    margin-left: -9px;  
    border-radius: 50%;  
    background: radial-gradient(circle, #000000 30%, #1a1a1a 70%, #333333 100%);  
    width: 18px;  
    height: 18px;  
    transition: all 0.3s ease;
    box-shadow: 
        inset 0 0 8px rgba(0, 0, 0, 0.8),
        0 2px 6px rgba(0, 0, 0, 0.4);
    border: 2px solid #2c3e50;
    animation: blackHolePulse 3s ease-in-out infinite;
}


/* Mobile responsive styles */
@media (max-width: 768px) {
    .mode-selection-content {
        margin: 10px;
    }
    
    .mode-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .mode-btn {
        width: 100%;
        max-width: 250px;
    }
    
    .mode-info {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    :root {
        --header-height: 95px; /* Adequate header height for mobile */
    }
    
    #header {
        padding: 15px 20px;
        font-size: 16px;
    }
    
    .floating-display {
        top: min(2vh, 15px);
    }
    
    #score-display {
        left: min(3vw, 15px);
    }
    
    #timer-display {
        right: min(3vw, 15px);
    }
    
    #score-display, #timer-display {
        padding: 10px 16px;
        font-size: min(4vw, 16px);
        min-width: 100px;
    }
    
    #center {
        padding: 0;
        height: 100vh;
        margin: 0;
    }
    
    #game {
        gap: 25px;
        width: 100%;
        height: 100%;
        max-width: none;
    }
    
    #maze {
        width: 320px !important;
        height: 290px !important;
        transform-origin: center center;
        transform: translate(-50%, -50%);
        min-width: 320px;
        min-height: 290px;
    }
    
    #joystick {
        bottom: 100px;
        width: 68px;
        height: 68px;
    }
    
    #joystick-head {
        width: 32px;
        height: 32px;
    }
    
    #note {
        font-size: 14px;
        top: 70px;
        width: min(90vw, 340px);
        max-width: 340px;
        min-width: 280px;
        padding: 10px 20px;
        line-height: 1.2;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    :root {
        --header-height: 85px; /* Adequate header height for very small screens */
    }
    
    .mode-selection-content {
        padding: 20px 15px;
    }
    
    .mode-btn {
        padding: 12px 20px;
        font-size: 16px;
    }
    
    #maze {
        width: 320px !important;
        height: 290px !important;
        transform-origin: center center;
        transform: translate(-50%, -50%);
        min-width: 320px;
        min-height: 290px;
    }
    
    #header {
        padding: 8px 15px;
        font-size: 14px;
    }
    
    #center {
        height: 100vh;
        margin: 0;
        padding: 0;
    }
}

/* Landscape orientation optimization */
@media (orientation: landscape) and (max-height: 600px) {
    #game {
        gap: 20px;
    }
    
    #maze {
        width: 320px !important;
        height: 290px !important;
        transform: translate(-50%, -50%);
        min-width: 320px;
        min-height: 290px;
    }
    
    #joystick {
        bottom: 80px;
        width: 65px;
        height: 65px;
    }
    
    #joystick-head {
        width: 30px;
        height: 30px;
    }
    
    #note {
        font-size: 13px;
        top: 60px;
        width: min(95vw, 320px);
        max-width: 320px;
        min-width: 260px;
        padding: 8px 18px;
        line-height: 1.2;
    }
}

/* Game blur effect */
.game-blur {
    filter: blur(3px);
    transition: filter 0.5s ease;
    pointer-events: none;
}

/* Ensure game elements are hidden initially */
.game-element {
    transition: opacity 0.5s ease;
}

.game-element.show {
    display: block !important;
    opacity: 1;
}

.mode-selection-screen.hide {
    display: none;
}