:root {
    /* Default theme (Pink) */
    --primary-color: #ff00ff;
    --primary-glow: #ff00ff;
    --primary-shadow: #ff00ff;
    --secondary-color: #cc00cc;
    --accent-color: #ff0000;
    --border-color: #ff00ff;
    --text-color: #ff00ff;
    --background-color: #000000;
    --hover-background: #110011;
    --active-background: #050005;
}

/* Theme variations */
.theme-medium {
    --primary-color: #00ffff;
    --primary-glow: #00ffff;
    --primary-shadow: #00ffff;
    --secondary-color: #00cccc;
    --accent-color: #ff0000;
    --border-color: #00ffff;
    --text-color: #00ffff;
    --background-color: #000000;
    --hover-background: #001111;
    --active-background: #000505;
}

.theme-hard {
    --primary-color: #ff0040;
    --primary-glow: #ff0040;
    --primary-shadow: #ff0040;
    --secondary-color: #cc0033;
    --accent-color: #ff0000;
    --border-color: #ff0040;
    --text-color: #ff0040;
    --background-color: #000000;
    --hover-background: #110005;
    --active-background: #050002;
}

.theme-bananas {
    --primary-color: #ffff00;
    --primary-glow: #ffff00;
    --primary-shadow: #ffff00;
    --secondary-color: #cccc00;
    --accent-color: #ff0000;
    --border-color: #ffff00;
    --text-color: #ffff00;
    --background-color: #000000;
    --hover-background: #111100;
    --active-background: #050500;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    font-family: 'Courier New', monospace;
    background: var(--background-color);
    height: 100vh;
    width: 100vw;
    color: var(--text-color);
    overflow: hidden;
    margin: 0;
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--background-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    color: var(--text-color);
    animation: loadingPulse 2s ease-in-out infinite;
}

.snake-emoji {
    font-size: 4rem;
    margin-bottom: 20px;
    text-shadow: 0 0 20px var(--primary-glow);
    animation: snakeWiggle 1.5s ease-in-out infinite;
}

.game-name-line1 {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 10px;
    text-shadow: 0 0 15px var(--primary-glow);
    font-family: 'Courier New', monospace;
    animation: fadeInUp 0.8s ease-out 0.3s both;
}

.game-name-line2 {
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 0 0 15px var(--primary-glow);
    font-family: 'Courier New', monospace;
    animation: fadeInUp 0.8s ease-out 0.6s both;
}

/* Loading Animations */
@keyframes loadingPulse {
    0%, 100% {
        transform: scale(1);
        text-shadow: 0 0 15px var(--primary-glow);
    }
    50% {
        transform: scale(1.05);
        text-shadow: 0 0 25px var(--primary-glow);
    }
}

@keyframes snakeWiggle {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-10deg);
    }
    75% {
        transform: rotate(10deg);
    }
}

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

.game-container {
    background: var(--background-color);
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    border: 2px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
}

/* Fixed Header */
.fixed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--background-color);
    border-bottom: 2px solid var(--border-color);
    position: relative;
    z-index: 100;
}

.title-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.game-title {
    font-size: 1.8rem;
    color: var(--text-color);
    text-shadow: 0 0 20px var(--primary-glow);
    font-family: 'Courier New', monospace;
    margin: 0;
}

.difficulty-text {
    font-size: 0.7rem;
    color: var(--text-color);
    text-shadow: 0 0 5px var(--primary-glow);
    font-family: 'Courier New', monospace;
    font-style: italic;
    margin-top: 2px;
    opacity: 0.8;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.header-button {
    background: var(--background-color);
    color: var(--text-color);
    border: 2px solid var(--border-color);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 10px var(--primary-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.header-button:hover {
    background: var(--hover-background);
    box-shadow: 0 0 20px var(--primary-glow);
    transform: scale(1.05);
}

.header-button:active {
    background: var(--active-background);
    transform: scale(0.95);
}

/* Main Game Area */
.main-game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
    min-height: 0;
    height: calc(100vh - 80px); /* Account for fixed header height */
}

/* Use 100svh for mobile browsers (small viewport height) */
@supports (height: 100svh) {
    .main-game-area {
        height: calc(100svh - 80px);
    }
}

/* Use 100dvh for better mobile support when available */
@supports (height: 100dvh) and (not (height: 100svh)) {
    .main-game-area {
        height: calc(100dvh - 80px);
    }
}

/* Fallback for mobile browsers with problematic viewport */
@media (max-width: 768px) {
    .main-game-area {
        height: calc(var(--vh, 1vh) * 100 - 75px) !important;
        max-height: calc(var(--vh, 1vh) * 100 - 75px) !important;
    }
}

/* Bottom info panel containing power-ups and scores */
.bottom-info-panel {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 15px;
    margin-top: 10px;
    flex-shrink: 0;
    background: var(--background-color);
    padding: 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 0 10px var(--primary-glow);
    align-items: center;
    min-height: 60px;
}

.score, .high-score {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    text-shadow: 0 0 5px var(--primary-glow);
    white-space: nowrap;
}

.high-score {
    text-align: right;
    justify-self: end;
}

.score span, .high-score span {
    color: var(--text-color);
    text-shadow: 0 0 10px var(--primary-glow);
}

.powerup-effects {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    min-height: 30px;
    flex-wrap: wrap;
    overflow: hidden;
}

.powerup-effects:empty {
    display: flex;
    visibility: hidden;
}

.powerup-effect {
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 0.8rem;
    color: var(--text-color);
    text-shadow: 0 0 5px var(--primary-glow);
    box-shadow: 0 0 10px var(--primary-glow);
    display: flex;
    align-items: center;
    gap: 5px;
    animation: powerupPulse 1s ease-in-out infinite;
}

.powerup-effect.speed {
    border-color: #ffff00;
    color: #ffff00;
    text-shadow: 0 0 5px #ffff00;
    box-shadow: 0 0 10px #ffff00;
}

.powerup-effect.slow {
    border-color: #00ffff;
    color: #00ffff;
    text-shadow: 0 0 5px #00ffff;
    box-shadow: 0 0 10px #00ffff;
}

.powerup-effect.chaos {
    border-color: #9900ff;
    color: #9900ff;
    text-shadow: 0 0 5px #9900ff;
    box-shadow: 0 0 10px #9900ff;
}

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

.game-area {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 10px;
}

#gameCanvas {
    border: 4px solid var(--border-color);
    background: var(--background-color);
    box-shadow: 0 0 30px var(--primary-glow);
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}


/* Popovers */
.popover {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 0 30px var(--primary-glow);
    z-index: 200;
    max-width: 90vw;
    max-height: 80vh;
    width: 400px;
    transition: all 0.3s ease;
}

.popover.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.9);
}

.popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.popover-header h3 {
    color: var(--text-color);
    font-size: 1.3rem;
    text-shadow: 0 0 10px var(--primary-glow);
    margin: 0;
}

.close-button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border-radius: 50%;
}

.close-button:hover {
    background: var(--hover-background);
    text-shadow: 0 0 10px var(--primary-glow);
    transform: scale(1.1);
}

.popover-content {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.popover-buttons {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.popover-buttons .game-button {
    margin: 0;
}

.high-scores-list {
    max-height: 400px;
    overflow-y: auto;
}

.high-score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin: 5px 0;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-color);
    border-radius: 4px;
}

.high-score-item.rank-1 {
    background: var(--hover-background);
    border-color: var(--border-color);
    box-shadow: 0 0 10px var(--primary-glow);
}

.high-score-item.rank-2 {
    background: #080008;
    border-color: #cc00cc;
}

.high-score-item.rank-3 {
    background: #050005;
    border-color: #990099;
}

.high-score-name {
    font-weight: bold;
    color: var(--text-color);
}

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

.server-status {
    text-align: center;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 5px;
    font-size: 0.9rem;
    font-weight: bold;
}

.server-status.online {
    background: #001100;
    color: #00ff00;
    border: 1px solid #00ff00;
    text-shadow: 0 0 5px #00ff00;
}

.server-status.offline {
    background: #110000;
    color: #ff6600;
    border: 1px solid #ff6600;
    text-shadow: 0 0 5px #ff6600;
}

.no-scores {
    text-align: center;
    color: #aa00aa;
    font-style: italic;
    padding: 20px;
}

.control-info p {
    margin: 8px 0;
    color: var(--text-color);
    font-size: 0.9rem;
    text-shadow: 0 0 5px var(--primary-glow);
}

.control-info p:first-child {
    font-weight: bold;
    margin-bottom: 12px;
    color: var(--text-color);
    text-shadow: 0 0 10px var(--primary-glow);
    font-size: 1rem;
}

/* Difficulty Selector Styles */
.difficulty-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #ff00ff;
}

.difficulty-section h4 {
    color: var(--text-color);
    font-size: 1.1rem;
    margin-bottom: 15px;
    text-shadow: 0 0 10px var(--primary-glow);
    font-family: 'Courier New', monospace;
}

.difficulty-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.difficulty-option {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.difficulty-option:hover {
    background: var(--hover-background);
    box-shadow: 0 0 10px var(--primary-glow);
}

.difficulty-option.selected {
    background: var(--hover-background);
    border-color: var(--border-color);
    box-shadow: 0 0 15px var(--primary-glow);
}

.difficulty-option input[type="radio"] {
    margin-right: 10px;
    accent-color: var(--primary-color);
}

.difficulty-option label {
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
    text-shadow: 0 0 5px var(--primary-glow);
    font-family: 'Courier New', monospace;
}

.current-difficulty {
    text-align: center;
    color: var(--text-color);
    font-size: 0.9rem;
    text-shadow: 0 0 5px var(--primary-glow);
    font-family: 'Courier New', monospace;
}

.current-difficulty span {
    font-weight: bold;
    color: var(--text-color);
    text-shadow: 0 0 10px var(--primary-glow);
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    border: 4px solid var(--border-color);
    border-radius: 8px;
    transition: opacity 0.3s ease;
    z-index: 10;
    /* Prevent layout shifts */
    transform: translateZ(0);
    will-change: opacity;
}

.game-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    color: var(--text-color);
    background: var(--background-color);
    padding: 30px;
    border: 2px solid var(--border-color);
    box-shadow: 0 0 20px var(--primary-glow);
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 10px;
    color: var(--text-color);
    text-shadow: 0 0 10px var(--primary-glow);
    font-family: 'Courier New', monospace;
}

.overlay-content p {
    font-size: 1.1rem;
    margin-bottom: 20px;
    color: var(--text-color);
    text-shadow: 0 0 5px var(--primary-glow);
}

/* Hide overlay content initially to prevent flashing */
.game-overlay .overlay-content {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.game-overlay .overlay-content.loaded {
    opacity: 1;
}

.game-button {
    background: var(--background-color);
    color: var(--text-color);
    border: 2px solid var(--border-color);
    padding: 12px 30px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 10px var(--primary-glow);
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 5px var(--primary-glow);
}

.game-button:hover {
    background: var(--hover-background);
    box-shadow: 0 0 20px var(--primary-glow);
    text-shadow: 0 0 10px var(--primary-glow);
}

.game-button:active {
    background: var(--active-background);
}

.controls {
    background: var(--background-color);
    padding: 15px;
    border: 1px solid var(--border-color);
    margin-top: auto;
}

.control-info p {
    margin: 3px 0;
    color: #ff00ff;
    font-size: 0.8rem;
    text-shadow: 0 0 5px #ff00ff;
}

.control-info p:first-child {
    font-weight: bold;
    margin-bottom: 8px;
    color: #ff00ff;
    text-shadow: 0 0 10px #ff00ff;
    font-size: 0.9rem;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .snake-emoji {
        font-size: 3rem;
        margin-bottom: 15px;
    }
    
    .game-name-line1 {
        font-size: 2rem;
        margin-bottom: 8px;
    }
    
    .game-name-line2 {
        font-size: 1.5rem;
    }
    
    .fixed-header {
        padding: 8px 15px;
    }
    
    .game-title {
        font-size: 1.2rem;
    }
    
    .difficulty-text {
        font-size: 0.6rem;
        margin-top: 1px;
    }
    
    .header-button {
        width: 40px;
        height: 40px;
        font-size: 0.9rem;
    }
    
    .main-game-area {
        padding: 8px;
        height: calc(100vh - 60px); /* Smaller header on mobile */
        display: flex;
        flex-direction: column;
    }
    
    /* Use small viewport height for mobile */
    @supports (height: 100svh) {
        .main-game-area {
            height: calc(100svh - 60px);
        }
    }
    
    /* Use dynamic viewport height for mobile */
    @supports (height: 100dvh) and (not (height: 100svh)) {
        .main-game-area {
            height: calc(100dvh - 60px);
        }
    }
    
    .game-area {
        flex: 1;
        min-height: 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .bottom-info-panel {
        gap: 10px;
        margin-top: auto;
        padding: 12px;
        grid-template-columns: auto 1fr auto;
        min-height: 50px;
        flex-shrink: 0;
    }
    
    .score, .high-score {
        font-size: 0.8rem;
    }
    
    .game-area {
        padding: 3px;
        min-height: 0;
        flex: 1;
    }
    
    .popover {
        width: 95vw;
        max-width: 400px;
    }
    
    .overlay-content h2 {
        font-size: 1.3rem;
    }
    
    .overlay-content p {
        font-size: 0.9rem;
    }
    
    .game-button {
        padding: 8px 20px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .fixed-header {
        padding: 6px 12px;
    }
    
    .game-title {
        font-size: 1.1rem;
    }
    
    .difficulty-text {
        font-size: 0.5rem;
        margin-top: 1px;
    }
    
    .header-button {
        width: 35px;
        height: 35px;
        font-size: 0.8rem;
    }
    
    .main-game-area {
        padding: 6px;
        height: calc(100vh - 50px); /* Even smaller header on small mobile */
        display: flex;
        flex-direction: column;
    }
    
    /* Use small viewport height for small mobile */
    @supports (height: 100svh) {
        .main-game-area {
            height: calc(100svh - 50px);
        }
    }
    
    /* Use dynamic viewport height for small mobile */
    @supports (height: 100dvh) and (not (height: 100svh)) {
        .main-game-area {
            height: calc(100dvh - 50px);
        }
    }
    
    .game-area {
        flex: 1;
        min-height: 0;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .bottom-info-panel {
        gap: 8px;
        margin-top: auto;
        padding: 10px;
        grid-template-columns: auto 1fr auto;
        min-height: 45px;
        flex-shrink: 0;
    }
    
    .score, .high-score {
        font-size: 0.7rem;
    }
    
    .game-area {
        padding: 2px;
    }
    
    .popover-header {
        padding: 15px;
    }
    
    .popover-content {
        padding: 15px;
    }
    
    .popover-header h3 {
        font-size: 1.1rem;
    }
    
    .control-info p {
        font-size: 0.8rem;
    }
    
    .difficulty-section h4 {
        font-size: 1rem;
        margin-bottom: 12px;
    }
    
    .difficulty-option {
        padding: 6px 10px;
    }
    
    .difficulty-option label {
        font-size: 0.8rem;
    }
    
    .current-difficulty {
        font-size: 0.8rem;
    }
    
    .high-score-item {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .header-button:hover {
        background: #000000;
        box-shadow: 0 0 10px #ff00ff;
        transform: none;
    }
    
    .header-button:active {
        background: #110011;
        transform: scale(0.95);
    }
    
    .close-button:hover {
        background: none;
        text-shadow: 0 0 5px #ff00ff;
        transform: none;
    }
    
    .close-button:active {
        background: #110011;
        transform: scale(0.9);
    }
    
    .game-button:hover {
        background: #000000;
        box-shadow: 0 0 10px #ff00ff;
        text-shadow: 0 0 5px #ff00ff;
    }
    
    .game-button:active {
        background: #050005;
        transform: scale(0.95);
    }
}

/* Animation for score updates */
@keyframes scoreUpdate {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.score-update {
    animation: scoreUpdate 0.3s ease;
}

/* Modal styles */
.modal {
    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: 1000;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--background-color);
    padding: 30px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 0 20px var(--primary-glow);
    border: 2px solid var(--border-color);
}

.modal-content h3 {
    color: var(--text-color);
    margin-bottom: 15px;
    font-size: 1.5rem;
    text-shadow: 0 0 10px var(--primary-glow);
    font-family: 'Courier New', monospace;
}

.modal-content p {
    color: var(--text-color);
    margin-bottom: 10px;
    text-shadow: 0 0 5px var(--primary-glow);
}

#playerNameInput {
    width: 100%;
    padding: 12px;
    margin: 15px 0;
    border: 2px solid var(--border-color);
    background: var(--background-color);
    color: var(--text-color);
    font-size: 1rem;
    text-align: center;
    transition: all 0.3s ease;
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 5px var(--primary-glow);
    box-shadow: 0 0 10px var(--primary-glow);
}

#playerNameInput:focus {
    outline: none;
    box-shadow: 0 0 20px var(--primary-glow);
    text-shadow: 0 0 10px var(--primary-glow);
}

#playerNameInput::placeholder {
    color: var(--secondary-color);
    opacity: 0.7;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.game-button.secondary {
    background: var(--background-color);
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
    box-shadow: 0 0 10px var(--secondary-color);
}

.game-button.secondary:hover {
    background: var(--hover-background);
    box-shadow: 0 0 20px var(--secondary-color);
    text-shadow: 0 0 10px var(--secondary-color);
}


