/* ======================
 * CSS Variables
 * Defines all theme variables and design tokens
 * ====================== */
/*
 * Theme Variables:
 * --background-color: Main page background
 * --text-color: Primary text color
 * --tile-default: Default tile background
 * --tile-correct: Correct letter position
 * --tile-present: Correct letter wrong position
 * --tile-absent: Letter not in word
 */
:root {
    --background-color: #f0f0f0;
    --text-color: #333;
    --tile-bg-empty: #ffffff;
    --tile-border-empty: #d3d6da;
    --tile-bg-correct: #6aaa64;
    --tile-bg-present: #c9b458;
    --tile-bg-absent: #787c7e;
    --tile-text-color: #ffffff;
    --key-bg: #d3d6da;
    --key-text: #000000;
    --key-bg-absent: #a7adc1;
    --font-size: 16px;
    --tile-size: 55px;
    --key-padding-y: 15px;
    --key-padding-x: 10px;
}

[data-theme="dark"] {
    --background-color: #121212;
    --text-color: #f0f0f0;
    --tile-bg-empty: #121212;
    --tile-border-empty: #3a3a3c;
    --key-bg: #818384;
    --key-text: #ffffff;
    --key-bg-absent: #4b5168;
}

/* ======================
 * Base Styles
 * Fundamental HTML element styling and reset
 * ====================== */


html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    touch-action: none;
    -ms-touch-action: none;
    font-family: Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    font-size: var(--font-size);
    box-sizing: border-box;
    touch-action: manipulation; /* Remove 300ms tap delay */
}

*, *:before, *:after {
    box-sizing: inherit;
}

/* ======================
 * Layout Structure
 * Main page structure and positioning
 * ====================== */


body {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
}

body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top);
    background: var(--background-color);
    pointer-events: none;
    z-index: 10;
}

.header {
    width: 100%;
    max-width: 500px;
    padding: 0 10px;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.header h1 {
    font-size: 2rem;
    margin: 0 auto;
    text-align: center;
}

.controls {
    display: flex;
    gap: 15px;
    margin-left: auto;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    flex-grow: 1;
    justify-content: center;
}

/* ======================
 * Game Board Components
 * Styles for the Wordle game grid and tiles
 * ====================== */


#guess-container {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
}

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

.guess-tile {
    width: var(--tile-size);
    height: var(--tile-size);
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid var(--tile-border-empty);
    font-size: 1.8rem;
    font-weight: normal;
    text-transform: uppercase;
    background-color: var(--tile-bg-empty);
}

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

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

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


/* ======================
 * On-screen Keyboard
 * Virtual keyboard styling and states
 * ====================== */


#keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.keyboard-button {
    font-family: inherit;
    font-weight: normal;
    padding: var(--key-padding-y) var(--key-padding-x);
    flex: 1 1 0;
    min-width: 0; /* allow buttons to shrink so the row never exceeds viewport width */
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background-color: var(--key-bg);
    color: var(--key-text);
    text-transform: uppercase;
    font-size: var(--font-size);
}

/* Prevent inner icon span from blocking button taps */
.keyboard-button span {
    pointer-events: none;
}

.keyboard-button.wide {
    padding: var(--key-padding-y) 18px;
    flex: 1.5 1 0; /* give Enter/Backspace a bit more space */
}

.keyboard-button.tile-correct {
    background-color: var(--tile-bg-correct);
    color: var(--tile-text-color);
}

.keyboard-button.tile-present {
    background-color: var(--tile-bg-present);
    color: var(--tile-text-color);
}

.keyboard-button.tile-absent {
    background-color: var(--key-bg-absent);
    color: var(--tile-text-color);
}

/* ======================
 * User Feedback
 * Message display and notifications
 * ====================== */


#message-container {
    font-size: 1.2rem;
    font-weight: normal;
    min-height: 1.5rem;
}

/* ======================
 * Game Controls
 * Buttons and interactive elements
 * ====================== */


.controls button, #new-game-button {
    background: var(--key-bg);
    border: none;
    cursor: pointer;
    color: var(--text-color);
}

.controls button {
    font-size: 1.5rem;
    width: 44px; /* Set a fixed width */
    height: 44px; /* Set a fixed height */
    border-radius: 50%; /* Make it circular */
    padding: 0; /* Remove padding to maintain circle shape */
    display: flex;
    justify-content: center;
    align-items: center;
}

#new-game-button {
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}


/* ======================
 * Modal Dialogs
 * Popup windows and overlays
 * ====================== */


.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--background-color);
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 400px;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 25px;
    text-align: center;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

#close-settings-button {
    display: block;
    margin: 20px auto 0;
    padding: 10px 25px;
    background-color: var(--tile-bg-correct);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* ======================
 * Utility Classes
 * Reusable helper classes
 * ====================== */


.hidden {
    display: none !important;
}

.bold-text *,
.bold-text {
    font-weight: bold !important;
}

/* ======================
 * Responsive Adjustments
 * Mobile-specific adaptations
 *
 * Breakpoints:
 * - 768px: Tablet layout adjustments
 * - 500px: Mobile landscape/small tablet
 * - 350px: Small mobile devices
 *
 * Approach:
 * - Mobile-first design
 * - Minimum 44px touch targets (WCAG)
 * - Progressive enhancement
 * ====================== */

@media (max-width: 768px) {
    :root {
        --tile-size: 50px;     /* Slightly smaller tiles */
        --font-size: 14px;     /* Smaller base font */
    }
    
    .header h1 {
        font-size: 1.8rem;     /* Reduce header size */
    }
}

@media (max-width: 500px) {
    .keyboard-row {
        gap: 4px;
    }
    .keyboard-button {
        padding: var(--key-padding-y) 6px;
        min-width: 28px;       /* Ensure minimum touch target */
    }
    .keyboard-button.wide {
        flex: 1.2 1 0;
    }
}

@media (max-width: 350px) {
    :root {
        --tile-size: 45px;     /* Very small screens */
        --key-padding-y: 12px; /* Reduce vertical padding */
    }
    
    .guess-tile {
        font-size: 1.6rem;     /* Smaller tile text */
    }
}
