body {
    /* Modern gradient background */
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    color: white;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    touch-action: manipulation;
    -webkit-overflow-scrolling: touch;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Login styles with enhanced visuals */
#login {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(255, 87, 34, 0.5);
    text-align: center;
    width: 90%;
    max-width: 400px;
    border: 2px solid #3a7bd5;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    backdrop-filter: blur(5px);
    animation: fadeIn 1s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -55%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}

img {
    width: 40px;
}

#login h1 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    background-image: linear-gradient(to right, #ff4b1f, #ff9068);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

#cont {
    margin-bottom: 1.5rem;
}

#input {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#name {
    padding: 0.8rem 1rem;
    border-radius: 10px;
    background-color: rgba(36, 52, 71, 0.8);
    border: 1px solid #3a7bd5;
    color: white;
    font-size: 1rem;
    width: 100%;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

#name:focus {
    outline: none;
    border-color: #00b4db;
    box-shadow: 0 0 15px rgba(0, 180, 219, 0.7), inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

#name::placeholder {
    color: #a0a0a0;
}

#NameBut {
    padding: 0.8rem 1rem;
    border-radius: 10px;
    background: linear-gradient(to right, #ff4b1f, #ff9068);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
    text-transform: uppercase;
    box-shadow: 0 4px 15px rgba(255, 75, 31, 0.4);
    position: relative;
    overflow: hidden;
}

#NameBut::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: 0.5s;
}

#NameBut:hover::before {
    left: 100%;
}

#NameBut:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 20px rgba(255, 75, 31, 0.6);
}

#NameBut:active {
    transform: translateY(0);
}

body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(255, 87, 34, 0.2) 0%, transparent 25%),
        radial-gradient(circle at 80% 70%, rgba(58, 123, 213, 0.2) 0%, transparent 25%),
        radial-gradient(circle at 50% 50%, rgba(0, 180, 219, 0.1) 0%, transparent 50%);
    z-index: -1;
}


/* Game page styles with modern visuals */
.header {
    background: linear-gradient(to right, #ff4b1f, #ff9068);
    color: white;
    text-align: center;
    padding: 15px 0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

.game-title {
    font-size: 28px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    position: relative;
    display: inline-block;
}

.game-title::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 25%;
    width: 50%;
    height: 3px;
    background: white;
    border-radius: 3px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

.content-container {
    display: flex;
    flex-grow: 1;
}

.game-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #203a43 0%, #2c5364 100%);
    position: relative;
}

.game-area::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%233a7bd5' fill-opacity='0.05' fill-rule='evenodd'%3E%3Ccircle cx='3' cy='3' r='3'/%3E%3Ccircle cx='13' cy='13' r='3'/%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

.game-canvas {
    width: 100%;
    max-width: 700px;
    aspect-ratio: 1 / 1;
    background: linear-gradient(135deg, #243b55 0%, #141e30 100%);
    border: 3px solid #3a7bd5;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(58, 123, 213, 0.5);
    border-radius: 5px;
    z-index: 1;
}

.chat-sidebar {
    width: 300px;
    background: linear-gradient(135deg, #162839 0%, #1e3246 100%);
    padding: 15px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #3a7bd5;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.3);
}

.message-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 15px;
    overflow-y: auto;
    max-height: calc(100vh - 150px);
    padding-right: 5px;
    scrollbar-width: thin;
    scrollbar-color: #ff4b1f #243447;
}

.message-container::-webkit-scrollbar {
    width: 5px;
}

.message-container::-webkit-scrollbar-track {
    background: #243447;
    border-radius: 5px;
}

.message-container::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, #ff4b1f, #ff9068);
    border-radius: 5px;
}

.message {
    padding: 12px;
    border-radius: 10px;
    background-color: rgba(36, 52, 71, 0.8);
    border: 1px solid #3a7bd5;
    margin-bottom: 10px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.message:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(58, 123, 213, 0.3);
}

.player-name {
    font-weight: bold;
    color: #00b4db;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
}

.player-name::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #00b4db;
    border-radius: 50%;
    margin-right: 8px;
    box-shadow: 0 0 8px #00b4db;
}

.message-text {
    color: #ffffff;
    word-wrap: break-word;
    line-height: 1.4;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid #3a7bd5;
}

.chat-input {
    flex-grow: 1;
    padding: 12px;
    border-radius: 20px;
    background-color: rgba(36, 52, 71, 0.8);
    border: 1px solid #3a7bd5;
    color: white;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

.chat-input:focus {
    outline: none;
    border-color: #00b4db;
    box-shadow: 0 0 10px rgba(0, 180, 219, 0.5), inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

.send-button {
    padding: 10px 15px;
    border-radius: 20px;
    background: linear-gradient(to right, #ff4b1f, #ff9068);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(255, 75, 31, 0.3);
    min-width: 70px;
    font-weight: bold;
}

.send-button:hover {
    background: linear-gradient(to right, #ff5e3a, #ff9d77);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 75, 31, 0.5);
}

.send-button:active {
    transform: translateY(0);
}

.footer {
    background: linear-gradient(to right, #ff4b1f, #ff9068);
    color: #fff;
    padding: 15px;
    height: auto;
    min-height: 100px;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
    border-top: 2px solid #3a7bd5;
    position: relative;
    overflow: hidden;
}

.footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
}

@keyframes footerShine {
    0% { left: -100%; }
    100% { left: 200%; }
}

.footer-content {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 1000px;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 5px;
    z-index: 1;
}

.footer-section {
    flex: 1;
    min-width: 200px;
    background: rgba(0, 0, 0, 0.1);
    padding: 10px 15px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
}

.lives-section img.heart-icon {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-left: 5px;
    filter: drop-shadow(0 0 5px rgba(255, 0, 0, 0.7));
    animation: heartbeat 2s infinite;
}

.connected-players {
    list-style: none;
    padding-left: 0;
    margin-top: 5px;
    font-size: 13px;
}

.connected-players li {
    color: #ffe0b2;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.connected-players li:last-child {
    border-bottom: none;
}

.connected-players li:hover {
    color: white;
    padding-left: 5px;
}

.status-section p {
    font-style: italic;
    color: #fff8e1;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    font-weight: bold;
}

.player {
    z-index: 1;
    width: 27px; 
    height: 40px;
    /* filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.7)); */
    /* transition: all 0.2s ease; */
}

.tile {
    position: relative;
    transition: transform 0.2s ease;
}

.tile img {
    transition: all 0.2s ease;
}

.tile:has(img[src*="wall.png"]) img {
    filter: brightness(1.1) contrast(1.1);
    box-shadow: 0 0 5px rgba(58, 123, 213, 0.3);
}

.bomb {
    background-size: 275%;
    animation: bomb-sprite 800ms steps(2) infinite;
}

@keyframes bomb-sprite {
    0% { background-position: 0 42px; }
    100% { background-position: 72px 42px; }
}

.damage {
    width: 38px;
    height: 38px;
    background-image: url('../images/explosion.png');
    background-size: 500%;
    filter: brightness(1.2) drop-shadow(0 0 15px rgba(255, 200, 0, 0.8));
}

.game-container {
    max-width: 700px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: center center;
    filter: drop-shadow(0 0 20px rgba(58, 123, 213, 0.3));
}

.power-notification {
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 5px;
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    animation: fadeInOut 3s forwards;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translateX(20px);
    }
    10% {
        opacity: 1;
        transform: translateX(0);
    }
    80% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

.popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: #fff;
    padding: 30px 50px;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(58, 123, 213, 0.3);
    
    font-size: 24px;
    font-weight: bold;
    text-align: center;

    border: 1px solid #3a7bd5;
    
    z-index: 1000;
    animation: popupAnimation 0.5s ease-out forwards;
}

@keyframes popupAnimation {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
    backdrop-filter: blur(5px); /* This creates the blur effect */
    z-index: 9999; 
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Game-themed Play Again button */
.play-again-btn {
    background: linear-gradient(to right, #ff4b1f, #ff9068);;
    color: #333;
    font-family: 'Press Start 2P', 'Arcade', sans-serif; /* Game-like font */
    font-size: 16px;
    font-weight: bold;
    padding: 12px 24px;
    border: 3px solid #333;
    border-radius: 8px;
    box-shadow: 
        0 6px 0 #cc7700,
        0 8px 10px rgba(0, 0, 0, 0.3);
    position: relative;
    cursor: pointer;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4);
    margin-top: 20px;
    transition: all 0.1s ease;
    animation: heartbeat 2s infinite;
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 8px 0 #cc7700,
        0 10px 15px rgba(0, 0, 0, 0.3);
}

.play-again-btn:active {
    transform: translateY(4px);
    box-shadow: 
        0 2px 0 #cc7700,
        0 4px 6px rgba(0, 0, 0, 0.3);
}

/* For the popup overall */
.popup {
    background-color: #333;
    border: 5px solid #ff4b1f;
    border-radius: 12px;
    color: white;
    text-align: center;
    padding: 25px;
    box-shadow: 0 0 20px rgba(255, 204, 0, 0.6);
    z-index: 99999; 
    width: max-content;
}

.popup h2 {
    color: #ff9068;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 20px;
}

/* Enhanced Media Queries for Better Responsiveness */
@media (max-width: 1200px) {
    .content-container {
        flex-direction: column;
    }
    
    .chat-sidebar {
        width: 100%;
        max-height: 250px;
        border-left: none;
        border-top: 1px solid #3a7bd5;
    }
    
    .message-container {
        max-height: 150px;
    }
    
    .footer {
        padding: 12px;
    }
}

@media (max-width: 900px) {
    .game-container {
        transform: scale(0.9);
    }
    
    .footer-content {
        flex-direction: column;
    }
    
    .footer-section {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .message-container {
        max-height: calc(100vh - 450px);
    }
}

@media (max-width: 768px) {
    .content-container {
        flex-direction: column;
    }
    
    .chat-sidebar {
        width: 100%;
        height: 250px;
        border-left: none;
        border-top: 1px solid #3a7bd5;
    }
    
    .message-container {
        max-height: 150px;
    }
    
    .footer {
        height: auto;
        padding: 10px;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 15px;
    }
    
    .footer-section {
        text-align: center;
        min-width: 100%;
    }
    
    .game-container {
        transform: scale(0.8);
    }
    
    .header {
        padding: 10px 0;
    }
    
    .game-title {
        font-size: 22px;
    }
}

@media (max-width: 600px) {
    .game-container {
        transform: scale(0.7);
    }
    
    #login {
        width: 90%;
        padding: 1.5rem;
    }
    
    .game-area {
        padding: 5px;
    }
    
    /* Optimize chat for small screens */
    .chat-input {
        font-size: 14px;
        padding: 8px;
    }
    
    .send-button {
        min-width: 60px;
        font-size: 14px;
        padding: 8px 12px;
    }
    
    .message {
        padding: 10px;
        margin-bottom: 8px;
    }
    
    .footer-section {
        padding: 8px;
    }
    
    .footer {
        min-height: auto;
        padding: 10px;
    }
}

@media (max-width: 480px) {
    #login {
        width: 95%;
        padding: 1.5rem;
    }
    
    #login h1 {
        font-size: 1.8rem;
    }
    
    .game-title {
        font-size: 20px;
    }
    
    .game-area {
        padding: 5px;
    }
    
    .chat-input-area {
        gap: 5px;
    }
    
    .chat-input, .send-button {
        padding: 8px;
        font-size: 14px;
    }
    
    .game-container {
        transform: scale(0.6);
    }
    
    /* Make notifications more visible on mobile */
    #power-notifications {
        width: 200px !important;
        top: 60px !important;
        right: 10px !important;
        font-size: 14px;
    }
    
    /* Optimize popup for mobile */
    .popup {
        width: 90% !important;
        padding: 15px !important;
        font-size: 16px !important;
    }
    
    .play-again-btn {
        padding: 8px 16px;
        font-size: 14px;
    }
    
    .footer-section {
        min-height: auto;
    }
}

@media (max-width: 380px) {
    .game-container {
        transform: scale(0.5);
    }
    
    /* Further reduce elements */
    .game-title {
        font-size: 18px;
    }
    
    .chat-sidebar {
        max-height: 200px;
    }
    
    .message-container {
        max-height: 130px;
    }
    
    .connected-players li {
        font-size: 12px;
    }
    
    .connected-players li img {
        width: 24px;
        height: 24px;
    }
}

@media (max-width: 320px) {
    .game-container {
        transform: scale(0.4);
    }
    
    /* Minimal UI for very small screens */
    .message-container {
        max-height: 120px;
    }
    
    #login h1 {
        font-size: 1.6rem;
    }
    
    .footer {
        padding: 5px;
    }
    
    .footer-section {
        padding: 6px;
        margin-bottom: 5px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger hit areas for touch */
    .send-button {
        padding: 12px 15px;
        min-width: 70px;
    }
    
    #NameBut {
        padding: 12px 24px;
    }
    
    /* Remove hover effects that might cause issues on touch devices */
    .message:hover {
        transform: none;
    }
    
    /* Better focus states for touch */
    input:focus, button:focus {
        outline: 2px solid #00b4db;
    }
    
    .connected-players li:hover {
        padding-left: 0;
    }
}

/* Orientation handling */
@media (orientation: landscape) and (max-height: 500px) {
    .content-container {
        flex-direction: row;
    }
    
    .chat-sidebar {
        width: 30%;
        height: auto;
        max-height: none;
    }
    
    .game-container {
        height: 80vh;
    }
    
    .footer {
        padding: 5px;
        min-height: auto;
    }
    
    .footer-content {
        flex-direction: row;
    }
    
    .message-container {
        max-height: calc(100vh - 130px);
    }
}

@keyframes heartbeat{
    0%, 100% {
        transform: scale(1);
        filter: drop-shadow(0 0 5px rgba(255, 0, 0, 0.7));
    }
    50% {
        transform: scale(1.3); 
        filter: drop-shadow(0 0 8px rgba(255, 0, 0, 0.9));
    }
}