:root {
    --bg: #121213;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --border: #3a3a3c;
    --text: #ffffff;
    /* Responsive tile size: adjusts between 45px and 60px based on screen width */
    --tile-size: clamp(45px, 12vw, 60px);
}

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

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding-top: 20px;
    overflow-x: hidden; /* Prevent horizontal scrolling on mobile */
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    height: 100%;
    padding: 0 10px;
}

header h1 {
    font-size: clamp(1.8rem, 8vw, 2.5rem);
    letter-spacing: 0.1rem;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    width: 100%;
    text-align: center;
    padding-bottom: 10px;
}

/* --- THE BOARD --- */
#board {
    display: grid;
    gap: 5px;
    margin-bottom: 20px;
    perspective: 1000px; /* Provides 3D depth for the flip */
}

.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.2rem, 5vw, 2rem);
    font-weight: bold;
    text-transform: uppercase;
    transition: none !important; /* Prevents CSS transitions from breaking JS animations */
}

/* --- UPDATED KEYBOARD LAYOUT --- */
#keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px 5px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    width: 100%;
}

/* This creates the 'stagger' for the middle row (A-L) */
.keyboard-row:nth-child(2) {
    padding: 0 5%;
}

#keyboard button {
    appearance: none;
    background-color: #818384;
    color: white;
    border: 0;
    border-radius: 4px;
    height: 58px;
    flex: 1; /* This makes keys expand to fill space equally */
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    text-transform: uppercase;
}

/* Make Enter and Backspace wider than standard letters */
#keyboard button[data-key="Enter"],
#keyboard button[data-key="Backspace"] {
    flex: 1.5;
    font-size: 0.7rem;
}

button {
    grid-column: span 2;
    height: 58px;
    border-radius: 4px;
    border: 0;
    background-color: #818384;
    color: white;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    user-select: none; /* Prevents highlighting text on long-press */
    -webkit-tap-highlight-color: transparent; /* Removes blue box on mobile tap */
}

button[data-key="Enter"], 
button[data-key="Backspace"] {
    grid-column: span 3;
    font-size: 0.75rem;
}

/* --- OVERLAY MODAL (Optimized for Mobile) --- */
#modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.8); /* Dims the board behind the modal */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: #1a1a1b;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 4px 23px 0 rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease-out;
}

.hidden { 
    display: none !important; 
}

#modal h2 {
    margin-bottom: 15px;
}

#modal button {
    margin-top: 20px;
    padding: 10px 20px;
    background-color: var(--correct);
    width: 100%;
}

/* --- ANIMATIONS & COLORS --- */
.correct { background-color: var(--correct) !important; border-color: var(--correct) !important; }
.present { background-color: var(--present) !important; border-color: var(--present) !important; }
.absent { background-color: var(--absent) !important; border-color: var(--absent) !important; }

button.correct { background-color: var(--correct); }
button.present { background-color: var(--present); }
button.absent { background-color: var(--absent); opacity: 0.5; }

.tile:not(:empty):not(.flip) {
    border-color: #565758;
    animation: pop 0.1s ease-in-out;
}

.tile.flip {
    animation: flip-reveal 0.6s ease-in-out forwards;
}

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

@keyframes flip-reveal {
    0% { transform: scaleY(1); }
    50% { transform: scaleY(0); }
    100% { transform: scaleY(1); }
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* --- SHAKE ANIMATION --- */
.tile.shake {
    /* We add !important to ensure it overrides the 'pop' animation */
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both !important;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

.tile.bounce {
    /* !important ensures it breaks the 'flip' or 'pop' animation cycle */
    animation: bounce 0.6s ease-in-out !important;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}