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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(45deg, #8e44ad 0%, #3498db 50%, #e74c3c 100%);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    color: white;
    overflow-x: hidden;
    padding: 0;
}

.game-container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 500px;
    width: 100%;
    text-align: center;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
}

.game-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    pointer-events: none;
}

.header {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.title {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 255, 255, 0.3); }
    to { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5), 0 0 30px rgba(255, 255, 255, 0.5); }
}

.navigation {
    margin-bottom: 0.8rem;
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    flex-wrap: wrap;
}

.nav-button {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    text-decoration: none;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    font-size: 0.75rem;
    backdrop-filter: blur(5px);
}

.nav-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    color: white;
}

.button-container {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.game-mode-selector {
    position: relative;
    z-index: 1;
    margin-bottom: 0.8rem;
    display: flex;
    gap: 0.4rem;
    justify-content: center;
}

.mode-button {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    font-weight: bold;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.mode-button.active {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.mode-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* Main game area that scrolls if needed */
.game-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-height: 0; /* Important for flex child to shrink */
}

.game-info {
    position: relative;
    z-index: 1;
    margin-bottom: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.attempts-left {
    font-size: 0.9rem;
    font-weight: bold;
    color: #ffeb3b;
}

.word-length {
    font-size: 0.75rem;
    color: #e0e0e0;
}

.message {
    position: relative;
    z-index: 1;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.6rem;
    margin-bottom: 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.message.success {
    background: rgba(76, 175, 80, 0.3);
    border-color: rgba(76, 175, 80, 0.5);
    animation: pulse 0.5s ease-in-out;
}

.message.error {
    background: rgba(244, 67, 54, 0.3);
    border-color: rgba(244, 67, 54, 0.5);
    animation: shake 0.5s ease-in-out;
}

.message.info {
    background: rgba(255, 193, 7, 0.3);
    border-color: rgba(255, 193, 7, 0.5);
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.game-board {
    position: relative;
    z-index: 1;
    margin-bottom: 1rem;
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 6px;
    max-width: 330px;
    margin: 0 auto 1rem auto;
    flex-shrink: 0;
}

.guess-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.letter-tile {
    width: 55px;
    height: 55px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transition: all 0.3s ease;
}

.letter-tile.filled {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.letter-tile.correct {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    border-color: #27ae60;
    animation: bounce 0.5s ease-in-out;
}

.letter-tile.present {
    background: linear-gradient(45deg, #d1c93f, #d1c93f);
    border-color: #f3fa00;
    animation: bounce 0.5s ease-in-out;
}

.letter-tile.absent {
    background: linear-gradient(45deg, #7f8c8d, #95a5a6);
    border-color: #7f8c8d;
    animation: bounce 0.5s ease-in-out;
}

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

/* Fixed keyboard at bottom */
.keyboard {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    padding: 0.8rem;
    z-index: 1000;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 3px;
    margin-bottom: 4px;
}

.keyboard-row:last-child {
    margin-bottom: 0;
}

.key {
    padding: 12px 8px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
    min-width: 32px;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.3);
    touch-action: manipulation; /* Prevents zoom on double-tap */
}

.key:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

.key.wide {
    min-width: 55px;
    font-size: 0.7rem;
}

.key.correct {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
}

.key.present {
    background: linear-gradient(45deg, #d1c93f, #d1c93f);
}

.key.absent {
    background: linear-gradient(45deg, #7f8c8d, #95a5a6);
}

/* Bottom stats and button */
.bottom-section {
    padding-bottom: 180px; /* Space for fixed keyboard */
    flex-shrink: 0;
}

.stats {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.stat-item {
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 70px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: bold;
    color: #ffd700;
}

.stat-label {
    font-size: 0.65rem;
    color: #e0e0e0;
    margin-top: 0.25rem;
}



.new-game-button:active {
    transform: scale(0.95);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}


.share-button:active {
    transform: scale(0.95);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.new-game-button,
.share-button,
.definition-button {
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    font-weight: bold;
    border: none;
    border-radius: 15px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    touch-action: manipulation;
    flex: 1;
    min-width: 0;
    max-width: 120px;
}

.new-game-button {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
}

.share-button {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    display: inline-block; /* Override the display: none */
}

.definition-button {
    background: linear-gradient(45deg, #3498db, #2980b9);
    display: inline-block; /* Override the display: none */
}

.definition-button:active {
    transform: scale(0.95);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* Mobile-specific optimizations */
@media (max-width: 600px) {
    body {
        padding: 0;
    }
    
    .game-container {
        border-radius: 0;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        padding: 0.8rem;
    }
    
    .title {
        font-size: 1.6rem;
        margin-bottom: 0.4rem;
    }
    
    .navigation {
        margin-bottom: 0.6rem;
        gap: 0.3rem;
    }
    
    .nav-button {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .game-mode-selector {
        margin-bottom: 0.6rem;
        gap: 0.3rem;
    }
    
    .mode-button {
        padding: 0.35rem 0.7rem;
        font-size: 0.75rem;
    }
    
    .game-info {
        margin-bottom: 0.6rem;
        padding: 0.5rem;
    }
    
    .attempts-left {
        font-size: 0.85rem;
    }
    
    .word-length {
        font-size: 0.7rem;
    }
    
    .game-board {
        max-width: 300px;
        gap: 5px;
        margin-bottom: 0.8rem;
    }
    
    .guess-row {
        gap: 5px;
    }
    
    .letter-tile {
        width: 55px;
        height: 55px;
        font-size: 1.2rem;
    }
    
    .message {
        font-size: 0.8rem;
        padding: 0.5rem;
        margin-bottom: 0.6rem;
        min-height: 35px;
    }
    
    .keyboard {
        padding: 0.2rem;
    }
    
    .keyboard-row {
        gap: 2px;
        margin-bottom: 3px;
    }
    
    .key {
        padding: 15px 10px;
        font-size: 1.5rem;
        min-width: 28px;
    }
    
    .key.wide {
        min-width: 60px;
        font-size: 0.65rem;
    }
    
    .bottom-section {
        padding-bottom: 160px;
    }
    
    .stats {
        gap: 0.6rem;
        margin-bottom: 0.8rem;
    }
    
    .stat-item {
        padding: 0.35rem 0.5rem;
        min-width: 65px;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .stat-label {
        font-size: 0.6rem;
    }

    .share-button:active {
        transform: scale(0.95);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    }

    .button-container {
        gap: 0.3rem;
        margin-bottom: 0.8rem;
    }
    
    .new-game-button,
    .share-button,
    .definition-button {
        padding: 0.5rem 0.6rem;
        font-size: 0.65rem;
        border-radius: 12px;
        letter-spacing: 0.3px;
        max-width: 100px;
    }

    .definition-button:active {
        transform: scale(0.95);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    }
}

/* Extra small screens */
@media (max-width: 375px) {
    .game-container {
        padding: 0.6rem;
    }
    
    .title {
        font-size: 1.4rem;
    }
    
    .game-board {
        max-width: 270px;
        gap: 4px;
    }
    
    .guess-row {
        gap: 4px;
    }
    
    .letter-tile {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
    
    .key {
        padding: 9px 5px;
        font-size: 0.7rem;
        min-width: 26px;
    }
    
    .key.wide {
        min-width: 45px;
        font-size: 0.6rem;
    }
    
    .bottom-section {
        padding-bottom: 150px;
    }
    .button-container {
        gap: 0.25rem;
    }
    
    .new-game-button,
    .share-button,
    .definition-button {
        padding: 0.45rem 0.5rem;
        font-size: 0.6rem;
        max-width: 85px;
    }

}

/* Landscape orientation on mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .game-container {
        height: 100vh;
        padding: 0.4rem;
    }
    
    .header {
        margin-bottom: 0.5rem;
    }
    
    .title {
        font-size: 1.2rem;
        margin-bottom: 0.3rem;
    }
    
    .navigation {
        margin-bottom: 0.3rem;
    }
    
    .game-mode-selector {
        margin-bottom: 0.3rem;
    }
    
    .game-info {
        margin-bottom: 0.4rem;
        padding: 0.4rem;
    }
    
    .message {
        margin-bottom: 0.4rem;
        padding: 0.4rem;
        min-height: 30px;
    }
    
    .game-board {
        margin-bottom: 0.5rem;
        gap: 3px;
        max-width: 250px;
    }
    
    .guess-row {
        gap: 3px;
    }
    
    .letter-tile {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .keyboard {
        padding: 0.4rem;
    }
    
    .key {
        padding: 8px 5px;
        font-size: 0.7rem;
    }
    
    .bottom-section {
        padding-bottom: 140px;
    }
    
    .stats {
        margin-bottom: 0.5rem;
    }
}

/* Stats Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none; /* Changed to none by default */
    align-items: center;
    justify-content: center;
    z-index: 2000; /* Ensure it's on top */
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #2c2c2e;
    color: #fff;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 480px;
    position: relative;
    text-align: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
}

.modal-close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin: 20px 0;
}

.distribution-grid {
    display: grid;
    gap: 8px;
    margin-top: 15px;
    text-align: left;
}

.dist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
}

.dist-bar {
    background-color: #4a4a4c;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    text-align: right;
    min-width: 25px;
    transition: width 0.5s ease-in-out;
}

.dist-bar.highlight {
    background-color: #538d4e; /* Green for the current game's guess count */
}

/* Add this to style the new Stats button like the others */
.control-button {
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    font-weight: bold;
    border: none;
    border-radius: 15px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    touch-action: manipulation;
    flex: 1;
    min-width: 0;
    max-width: 120px;
    background: linear-gradient(45deg, #8e44ad, #9b59b6);
}