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

:root {
    --color-correct: #6aaa64;
    --color-present: #b59f3b;
    --color-absent: #3a3a3c;
    --color-border: #3a3a3c;
    --color-border-filled: #565758;
    --color-key: #818384;
    --color-bg: #121213;
    --color-text: #ffffff;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    display: flex;
    justify-content: center;
    touch-action: manipulation;
}

.container {
    width: 100%;
    max-width: 500px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 8px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
}

header {
    flex-shrink: 0;
    width: 100%;
    border-bottom: 1px solid var(--color-border);
    padding: 8px 0;
}

h1 {
    text-align: center;
    font-size: clamp(24px, 6vw, 36px);
    font-weight: 700;
    letter-spacing: 0.2rem;
    text-transform: uppercase;
}

#message {
    flex-shrink: 0;
    height: 28px;
    font-size: clamp(14px, 3.5vw, 16px);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

#message.error {
    color: #ff6b6b;
}

#message.success {
    color: var(--color-correct);
}

/* Game Board - Dynamic sizing */
#board {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 1vw, 5px);
    padding: 10px 0;
    min-height: 0;
}

.row {
    display: flex;
    gap: clamp(4px, 1vw, 5px);
}

.tile {
    /* Dynamic tile size based on viewport */
    width: clamp(48px, 14vw, 62px);
    height: clamp(48px, 14vw, 62px);
    border: 2px solid var(--color-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(24px, 7vw, 32px);
    font-weight: bold;
    text-transform: uppercase;
    user-select: none;
    transition: transform 0.1s ease;
}

.tile.filled {
    border-color: var(--color-border-filled);
    animation: pop 0.1s ease;
}

.tile.revealed {
    animation: flip 0.5s ease forwards;
}

.tile.correct {
    background-color: var(--color-correct);
    border-color: var(--color-correct);
}

.tile.present {
    background-color: var(--color-present);
    border-color: var(--color-present);
}

.tile.absent {
    background-color: var(--color-absent);
    border-color: var(--color-absent);
}

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

@keyframes flip {
    0% { transform: rotateX(0deg); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

.row.shake {
    animation: shake 0.5s ease;
}

/* Keyboard - Dynamic sizing */
#keyboard {
    flex-shrink: 0;
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: clamp(4px, 1.5vw, 8px);
    padding: 8px 0;
    margin: 0 auto;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: clamp(4px, 1.2vw, 6px);
    width: 100%;
}

#keyboard button {
    background-color: var(--color-key);
    color: var(--color-text);
    border: none;
    border-radius: 4px;
    padding: 0;
    height: clamp(50px, 12vw, 58px);
    flex: 1;
    max-width: clamp(36px, 9vw, 43px);
    font-size: clamp(12px, 3vw, 14px);
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.1s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

#keyboard button.wide {
    flex: 1.5;
    max-width: clamp(56px, 14vw, 65px);
    font-size: clamp(10px, 2.5vw, 12px);
}

#keyboard button:hover {
    opacity: 0.9;
}

#keyboard button:active {
    opacity: 0.7;
}

#keyboard button.correct {
    background-color: var(--color-correct);
}

#keyboard button.present {
    background-color: var(--color-present);
}

#keyboard button.absent {
    background-color: var(--color-absent);
}

/* New Game Button */
#new-game {
    flex-shrink: 0;
    background-color: var(--color-correct);
    color: white;
    border: none;
    border-radius: 4px;
    padding: clamp(10px, 2.5vw, 12px) clamp(18px, 5vw, 24px);
    font-size: clamp(14px, 3.5vw, 16px);
    font-weight: bold;
    cursor: pointer;
    margin: 8px auto;
    -webkit-tap-highlight-color: transparent;
}

#new-game:hover {
    background-color: #5a9a54;
}

#new-game:active {
    background-color: #4a8a44;
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .container {
        flex-direction: row;
        flex-wrap: wrap;
        max-width: 100%;
        padding: 4px;
    }
    
    header {
        width: 100%;
        padding: 4px 0;
    }
    
    h1 {
        font-size: 20px;
    }
    
    #message {
        width: 100%;
        height: 20px;
    }
    
    #board {
        flex: 1;
        padding: 4px;
    }
    
    .tile {
        width: clamp(32px, 8vh, 45px);
        height: clamp(32px, 8vh, 45px);
        font-size: clamp(16px, 5vh, 24px);
    }
    
    #keyboard {
        width: 50%;
        padding: 4px;
    }
    
    #keyboard button {
        height: clamp(30px, 10vh, 45px);
    }
    
    #new-game {
        position: absolute;
        bottom: 8px;
        right: 8px;
        margin: 0;
        padding: 8px 16px;
        font-size: 12px;
    }
}

/* Small phones (iPhone SE, etc) */
@media (max-width: 350px) {
    .tile {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }
    
    #keyboard button {
        height: 48px;
        max-width: 30px;
        font-size: 11px;
    }
    
    #keyboard button.wide {
        max-width: 48px;
        font-size: 9px;
    }
}

/* Tablets and larger */
@media (min-width: 600px) {
    .container {
        padding: 16px;
    }
    
    header {
        padding: 12px 0;
    }
    
    #board {
        padding: 20px 0;
    }
    
    .tile {
        width: 62px;
        height: 62px;
        font-size: 32px;
    }
    
    #keyboard button {
        height: 58px;
        max-width: 43px;
        font-size: 14px;
    }
    
    #keyboard button.wide {
        max-width: 65px;
        font-size: 12px;
    }
}
