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

/* Prevent text selection and improve touch interaction */
body, .tile, .key, .restart-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #121213;
    color: #ffffff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
}

.container {
    max-width: 500px;
    width: 100%;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

h1 {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    margin-bottom: 10px;
    color: #ffffff;
}

header p {
    color: #818384;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
}

.game-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: clamp(3px, 1vw, 5px);
    margin-bottom: 20px;
    justify-content: center;
    flex-grow: 1;
    align-content: center;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: clamp(3px, 1vw, 5px);
    justify-content: center;
}

.tile {
    width: clamp(45px, 12vw, 62px);
    height: clamp(45px, 12vw, 62px);
    border: 2px solid #3a3a3c;
    background-color: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.2rem, 4vw, 2rem);
    font-weight: bold;
    text-transform: uppercase;
    color: #ffffff;
    transition: all 0.3s ease;
    border-radius: 4px;
}

.tile.filled {
    border-color: #565758;
    animation: pop 0.1s ease-in-out;
}

.tile.correct {
    background-color: #538d4e;
    border-color: #538d4e;
}

.tile.present {
    background-color: #b59f3b;
    border-color: #b59f3b;
}

.tile.absent {
    background-color: #3a3a3c;
    border-color: #3a3a3c;
}

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

.keyboard {
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    gap: clamp(4px, 2vw, 8px);
    margin-bottom: 20px;
    flex-shrink: 0;
}

.keyboard-row {
    display: flex;
    gap: clamp(3px, 1.5vw, 6px);
    justify-content: center;
}

.key {
    background-color: #818384;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    font-size: clamp(0.8rem, 3vw, 1.25rem);
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.1s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    touch-action: manipulation;
    user-select: none;
}

.key:hover, .key:active {
    background-color: #565758;
}

.key.letter {
    width: clamp(28px, 8vw, 43px);
    height: clamp(42px, 12vw, 58px);
}

.key.enter {
    width: clamp(48px, 15vw, 65px);
    height: clamp(42px, 12vw, 58px);
    font-size: clamp(0.7rem, 2.5vw, 1rem);
}

.key.backspace {
    width: clamp(48px, 15vw, 65px);
    height: clamp(42px, 12vw, 58px);
    font-size: clamp(0.7rem, 2.5vw, 1rem);
}

.key.correct {
    background-color: #538d4e;
}

.key.present {
    background-color: #b59f3b;
}

.key.absent {
    background-color: #3a3a3c;
}

.message {
    text-align: center;
    font-size: clamp(1rem, 3vw, 1.2rem);
    font-weight: bold;
    margin-bottom: 15px;
    height: clamp(25px, 8vw, 30px);
    display: flex;
    justify-content: center;
    align-items: center;
}

.message.success {
    color: #538d4e;
}

.message.error {
    color: #f5793a;
}

.restart-btn {
    display: block;
    width: clamp(180px, 50vw, 200px);
    margin: 0 auto;
    padding: clamp(10px, 3vw, 12px) clamp(20px, 6vw, 24px);
    background-color: #538d4e;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease;
    touch-action: manipulation;
}

.restart-btn:hover, .restart-btn:active {
    background-color: #466a3f;
}

.restart-btn:disabled {
    background-color: #3a3a3c;
    cursor: not-allowed;
}

/* Mobile-first responsive design */

/* Small phones (portrait) */
@media (max-width: 480px) {
    body {
        padding: 5px;
        align-items: flex-start;
    }
    
    .container {
        padding: 10px;
        min-height: 100vh;
        justify-content: space-evenly;
    }
    
    header {
        margin-bottom: 15px;
    }
    
    .game-board {
        margin-bottom: 15px;
    }
    
    .keyboard {
        margin-bottom: 15px;
    }
    
    .tile {
        min-width: 40px;
        min-height: 40px;
    }
    
    .key.letter {
        min-width: 26px;
        min-height: 40px;
    }
    
    .key.enter, .key.backspace {
        min-width: 45px;
        min-height: 40px;
    }
}

/* Medium phones (landscape) and small tablets */
@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .tile {
        min-width: 50px;
        min-height: 50px;
    }
}

/* Large tablets and small desktops */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 20px;
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 600px) {
    body {
        align-items: flex-start;
        padding: 5px;
    }
    
    .container {
        min-height: auto;
        justify-content: flex-start;
        padding: 10px;
    }
    
    header {
        margin-bottom: 10px;
    }
    
    h1 {
        font-size: clamp(1.5rem, 4vw, 2rem);
        margin-bottom: 5px;
    }
    
    header p {
        font-size: clamp(0.8rem, 2.5vw, 1rem);
    }
    
    .game-board {
        margin-bottom: 10px;
    }
    
    .keyboard {
        margin-bottom: 10px;
    }
    
    .tile {
        height: clamp(35px, 8vw, 45px);
        width: clamp(35px, 8vw, 45px);
    }
    
    .key.letter {
        height: clamp(35px, 9vw, 45px);
    }
    
    .key.enter, .key.backspace {
        height: clamp(35px, 9vw, 45px);
    }
}

/* Very small screens (older phones) */
@media (max-width: 320px) {
    .tile {
        font-size: 1rem;
        min-width: 35px;
        min-height: 35px;
    }
    
    .key {
        font-size: 0.7rem;
    }
    
    .key.letter {
        min-width: 22px;
        min-height: 35px;
    }
    
    .key.enter, .key.backspace {
        min-width: 40px;
        min-height: 35px;
        font-size: 0.6rem;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .key {
        /* Larger touch targets for mobile */
        min-height: 44px;
        min-width: 44px;
    }
    
    .restart-btn {
        min-height: 44px;
    }
    
    /* Prevent zoom on double tap */
    .tile, .key, .restart-btn {
        touch-action: manipulation;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .tile {
        border-width: 1px;
    }
}
