:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    overflow: hidden;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-touch-callout: none;
}

body {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
   /* height: 100vh; */
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    background-color: #f0f0f0;
    box-sizing: border-box;
}

#mtitle {
            font-size: 24px;
            font-family: Arial, sans-serif;
            color: #333;
            text-align: center;
            padding: 10px;
        }
#currentLetters {
    position: fixed;
    top: 1vh;
    left: 0;
    right: 0;
    width: 100%;
    font-size: 48px;
    font-weight: bold;
    color: blue;
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
    padding: 15px 25px;
    border-radius: 10px;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3), 
                  0 0 4px rgba(255, 255, 255, 0.5);
    box-sizing: border-box;
    max-width: 100vw;
}

 #highScoreOverlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(255, 255, 255, 0.95);
        justify-content: center;
        align-items: center;
        z-index: 1000;
        font-family: Arial, sans-serif;
    }

    .highscore-box {
        background: white;
        padding: 15px;
        border-radius: 10px;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
        width: 90%;
        max-width: 400px;
        max-height: 60vh;
        overflow-y: auto;
    }
#highScoreList {
    max-height: 340px;
    max-width: 380px;/* Limit the height to 500px */
    overflow-y: auto; /* Enable vertical scrolling if content exceeds 500px */
    padding-right: 10px; /* Optional: Space for scrollbar */
}

    .highscore-entry {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px;
        margin: 8px 0;
        background: #f8f9fa;
        border-radius: 6px;
    }

    .highscore-entry div {
        display: flex;
        align-items: center;
        gap: 15px;
    }
    /* Added styles for the Facebook login prompt */
         #fbLoginOverlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.85);
            z-index: 10000;
            justify-content: center;
            align-items: center;
        }
        
        .fb-login-box {
            background: white;
            border-radius: 15px;
            padding: 30px;
            width: 90%;
            max-width: 400px;
            text-align: center;
            box-shadow: 0 10px 40px rgba(0,0,0,0.3);
        }
        
        .fb-login-box h3 {
            color: #4267B2;
            margin-bottom: 15px;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .fb-login-box p {
            margin-bottom: 25px;
            color: #555;
            line-height: 1.6;
            font-size: 1.1rem;
        }
        
        .fb-login-buttons {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        
        .fb-login-btn {
            background: #4267B2;
            color: white;
            border: none;
            border-radius: 50px;
            padding: 14px 20px;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }
        
        .fb-login-btn:hover {
            background: #365899;
            transform: translateY(-2px);
        }
        
        .fb-login-btn i {
            margin-right: 12px;
            font-size: 1.4rem;
        }
        
        .fb-login-cancel {
            background: #f5f5f5;
            color: #555;
        }
        
        .fb-login-cancel:hover {
            background: #e0e0e0;
        }
        
        /* Share preview styling */
        .share-preview {
            background: #f0f2f5;
            border-radius: 8px;
            padding: 15px;
            margin: 20px 0;
            text-align: left;
            border: 1px solid #dddfe2;
        }
        
        .share-preview img {
            width: 60px;
            height: 60px;
            border-radius: 5px;
            float: left;
            margin-right: 15px;
            background: #4267B2;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 1.8rem;
        }
        
        .share-preview-content {
            overflow: hidden;
        }
        
        .share-preview h4 {
            margin: 0 0 5px 0;
            color: #1d2129;
            font-size: 1.1rem;
        }
        
        .share-preview p {
            margin: 0;
            color: #606770;
            font-size: 0.95rem;
            line-height: 1.4;
        }

    .view-words-btn {
        background: #007bff;
        color: white;
        border: none;
        padding: 6px 12px;
        border-radius: 4px;
        cursor: pointer;
        font-size: 0.9em;
    }

    .view-words-btn:hover {
        background: #0056b3;
    }
.btn-close {
        background: #007bff;
        color: white;
        border: none;
        padding: 6px 12px;
        margin-top: 10px;
        border-radius: 4px;
        cursor: pointer;
        font-size: 0.9em;
    }

    .close-btn {
        color: #495057;
        font-size: 28px;
        position: absolute;
        top: 10px;
        right: 15px;
        cursor: pointer;
    }

    /* Name input styling */
    #nameEntry {
        margin: 20px 0;
        text-align: center;
    }

    #playerName {
        padding: 10px;
        margin: 10px;
        width: 250px;
        border: 1px solid #ddd;
        border-radius: 4px;
        font-size: 16px;
    }
#highS {
        background: #A8A8A8;
        padding: 8px 8px;
        color: white;
        margin: 2px;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-size: 14px;
        transition: opacity 0.2s;
    }

 .score-submit-btn {
            padding: 8px 20px;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-size: 14px;
        transition: opacity 0.2s;
        }

        .score-submit-btn:hover {
            background: #45a049;
        }




        #scorePanel {
            position: absolute;
            top: 0px;
            display: block;
            
            justify-content:space-between;
            align-items:center;
            padding: 0 15px;
        }
        
        #undoButton {
            display: none;
        font-size: 32px;
        width: 30px;
        height: 30px;
        padding: 0;
        border-radius: 50%; 
        /*background: #007bff; */
        color: black;
        border: none;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 0px;
        font-family: Arial, sans-serif;
    }

    #undoButton:disabled {
        background: #6c757d;
        cursor: not-allowed;
        opacity: 0.7;
    }

    #undoButton:hover:not(:disabled) {
        background: white;
        transform: scale(1.1);
        transition: transform 0.2s;
    }

        #score, #turns {
            font-size: 18px;
            font-weight: bold;
            font-family: Arial, sans-serif;
            color: #333;
        }
.canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 2px auto;
    width: fit-content;
    transition: all 0.3s ease-out;
}

.glow-effect {
    animation: borderGlow 2.5s ease-out;
}

@keyframes borderGlow {
    0% {
        box-shadow: 0 0 5px rgba(0, 255, 0, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(0, 255, 0, 0.9), 
                   0 0 30px rgba(0, 255, 0, 0.6);
    }
    100% {
        box-shadow: 0 0 5px rgba(0, 255, 0, 0.3);
    }
}

        #gameContainer {
            position: relative;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        #gameCanvas {
            display: block;
            touch-action: none;
            user-select: none;
            max-width: 100%;
            max-height: 70vh;
            image-rendering: crisp-edges;
        }
        #wordList {
            /*height: 20vh; 
            height: calc(15vh - 40px); */
            height: calc(100vh - 80vh - 60px - 20px); 
            overflow-y: auto;
            background: rgba(255,255,255,0.9);
            padding: 10px;
            margin: 5px 10px 10px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
            font-size: 18px;
        }
        #gameOver {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            display: none;
            z-index: 5;
        }
        #startButton {
            padding: 15px 30px;
            font-size: 24px;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        
        .wordCounter {
        margin-right: 8px;
        color: #666;
        min-width: 30px;
        display: inline-block;
    }

        .wordEntry {
            display: flex;
            justify-content: space-between;
            padding: 2px 0;
        }
         #shareButtons {
        margin-top: 15px;
        display: flex;
        gap: 10px;
        justify-content: center;
    }
    
    .share-btn {
        padding: 8px 20px;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-size: 14px;
        transition: opacity 0.2s;
    }
    
    .share-btn:hover {
        opacity: 0.9;
    }
    
    #emailScore {
        background: #4CAF50;
        color: white;
        margin: 2px;
    }
    #facebookShare {
        background: #425E9A;
        color: white;
        margin: 2px;
    }
    
    #textScore {
        background: #2196F3;
        color: white;
        margin: 2px;
    }

        @media (max-width: 600px) {
            #gameCanvas {
                max-height: 65vh;
            }
             body {
            grid-template-rows: auto auto auto auto;
            align-content: start;
        }
            #currentLetters {
        font-size: 36px;
        top: 1vh;
        padding: 5px 5px;
        border-radius: 8px;
        width: calc(100% - 20px);
        margin: 0 10px;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3), 
                     0 0 3px rgba(255, 255, 255, 0.5);
    }
            
            #wordList {
                height: 15vh;
                font-size: 16px;
            }
            
            #mtitle {
                font-size: 20px;
            }
            
            #score, #turns {
                font-size: 18px;
                font-weight: bold;
            }
        }
         .overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.7);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }

        /* Directions Box */
       .directions-box {
    max-height: 70vh; /* Limits height to 80% of viewport */
    display: flex;
    flex-direction: column;
    background: white;
    padding: 20px;
    border-radius: 10px;
    max-width: 90%;
    width: 500px;
    position: relative;
}

.directions-header {
    position: relative;
    padding-right: 30px; /* Space for close button */
    flex-shrink: 0; /* Prevents header from shrinking */
    border-bottom: 1px solid #ddd; /* Optional separator */
    margin-bottom: 10px;
}

.directions-content {
    overflow-y: auto; /* Enables vertical scroll */
    flex-grow: 1; /* Fills remaining space */
    padding-right: 10px; /* Prevents content from overlapping scrollbar */
}

.close-btn {
    position: absolute;
    top: -10px;
    right: 0;
    cursor: pointer;
    font-size: 24px;
    background: none;
    border: none;
    padding: 5px;
}

        .close-btn:hover {
            color: #d9534f;
        }

        /* Section Headings */
        .directions-box h2 {
            margin-top: 0;
            font-size: 22px;
            text-align: center;
            border-bottom: 2px solid #007bff;
            padding-bottom: 5px;
        }

        .directions-box h3 {
            font-size: 18px;
            margin-top: 15px;
            border-bottom: 1px solid #ddd;
            padding-bottom: 4px;
        }

        /* Text Styling */
        .directions-box p {
            font-size: 16px;
            line-height: 1.5;
            margin: 10px 0;
        }

        .directions-box ul {
            list-style-type: none;
            padding: 0;
            margin: 10px 0;
        }

        .directions-box ul li {
            font-size: 16px;
            padding: 4px 0;
        }

        /* Fade-In Animation */
        @keyframes fadeIn {
            from { opacity: 0; transform: scale(0.95); }
            to { opacity: 1; transform: scale(1); }
        }

        /* Button Styling */
        .open-btn {
            position: absolute;
            width: 120px;
            top: 35px;
            right: 5px;
            padding: 5px 10px;
            font-size: 16px;
            cursor: pointer;
            border: none;
            background: #007bff;
            color: white;
            border-radius: 5px;
        }

        .open-btn:hover {
            background: #0056b3;
        }
        #soundToggle1 {
        position: fixed;
        top: 2px;
        right: 35px;
        background: none;
        border: none;
        font-size: 24px;
        
    }
        #soundToggle {
        position: fixed;
        top: 2px;
        right: 35px;
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        z-index: 1000;
    }
         @media (min-width: 601px) {
        #gameContainer {
            justify-content: center;
            margin: 0 auto;
            max-width: calc(8 * 70px); /* cols * cellSize */
        }
        
        #gameCanvas {
            margin: 0 auto;
        }
        
        body {
            grid-template-rows: auto auto auto auto;
            align-content: start;
        }
    }

    /* Keep existing mobile styles */
    @media (max-width: 600px) {
        #gameCanvas {
            max-height: 65vh;
        }
        .open-btn {
            position: absolute;
            width: 100px;
            top: 55px;
            right: 2px;
            padding: 2px 2px;
            font-size: 15px;
            cursor: pointer;
            border: none;
            background: #007bff;
            color: white;
            border-radius: 5px;
        }
        #soundToggle {
        position: fixed;
        top: 2px;
        right: 10px;
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        z-index: 1000;
    }
        /* ... other mobile styles ... */
    }