/* Enhanced CSS Custom Properties for Consistent Scaling and Theming */
:root {
    /* Navigation system */
    --nav-height: 60px;
    --nav-height-mobile: 60px;
    
    /* Base sizing system */
    --game-max-width: min(31.25rem, 95vw);
    --board-max-width: min(21.875rem, 90vw);
    --tile-base-size: clamp(2rem, min(8vw, 6vh), 4rem);
    --keyboard-min-height: clamp(160px, 25vh, 200px);
    
    /* Spacing system */
    --gap-base: clamp(0.15rem, 1vw, 0.25rem);
    --gap-small: clamp(0.08rem, 0.5vw, 0.15rem);
    --gap-large: clamp(0.25rem, 1.5vw, 0.375rem);
    --gap-xl: clamp(0.5rem, 2vw, 0.75rem);
    --container-padding: clamp(0.5rem, 2vw, 1rem);
    
    /* Typography system */
    --font-base: clamp(1rem, min(4vw, 3vh), 2rem);
    --font-small: clamp(0.7rem, 2vw, 0.85rem);
    --font-large: clamp(1.5rem, 5vw, 2.25rem);
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-bold: 700;
    --letter-spacing-normal: 0;
    --letter-spacing-wide: 0.05em;
    
    /* Visual system */
    --border-width: clamp(1px, 0.3vw, 2px);
    --border-width-thick: clamp(2px, 0.4vw, 3px);
    --border-radius: clamp(0.2rem, 0.5vw, 0.25rem);
    --border-radius-large: clamp(0.375rem, 1vw, 0.5rem);
    --shadow-base: 0 2px 0 rgba(0,0,0,0.1);
    --shadow-hover: 0 3px 0 rgba(0,0,0,0.15);
    --shadow-focus: 0 0 0 3px rgba(59, 130, 246, 0.3);
    --shadow-active: inset 0 2px 0 rgba(0,0,0,0.1);
    
    /* Timing system */
    --transition-fast: 0.15s;
    --transition-medium: 0.3s;
    --transition-slow: 0.5s;
    --easing-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --easing-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    
    /* Touch targets */
    --touch-target-min: 44px;
    --touch-target-preferred: clamp(2.2rem, 6vh, 2.75rem);
    
    /* Color variants */
    --opacity-disabled: 0.4;
    --opacity-hover: 0.8;
    --opacity-active: 0.9;
    
    /* Z-index system */
    --z-nav: 1000;
    --z-nav-toggle: 1001;
    --z-modal: 1100;
    --z-tooltip: 1200;
}

/* Enhanced Dark mode custom properties */
@media (prefers-color-scheme: dark) {
    :root {
        /* Background colors */
        --bg-primary: #121213;
        --bg-secondary: #1e1e1e;
        --bg-tile-empty: #3a3a3c;
        --bg-tile-filled: #565758;
        --bg-key: #818384;
        --bg-key-hover: #a4a6a7;
        
        /* Text colors */
        --text-primary: #d7dadc;
        --text-secondary: #a0a3a5;
        --text-on-dark: #ffffff;
        --text-on-light: #000000;
        
        /* Border colors */
        --border-color: #3a3a3c;
        --border-tile-empty: #3a3a3c;
        --border-tile-filled: #565758;
        
        /* Game state colors */
        --color-correct: #538d4e;
        --color-present: #b59f3b;
        --color-absent: #3a3a3c;
        --color-error: #dc2626;
        --color-focus: #3b82f6;
        
        /* Navigation */
        --nav-bg: rgba(18, 18, 19, 0.95);
        --nav-text: #d7dadc;
        --nav-border: rgba(58, 58, 60, 0.8);
    }
}

/* Enhanced Light mode custom properties */
@media (prefers-color-scheme: light) {
    :root {
        /* Background colors */
        --bg-primary: #f5f5f5;
        --bg-secondary: #ffffff;
        --bg-tile-empty: #ffffff;
        --bg-tile-filled: #f0f0f0;
        --bg-key: #d3d6da;
        --bg-key-hover: #b8bdc4;
        
        /* Text colors */
        --text-primary: #333333;
        --text-secondary: #666666;
        --text-on-dark: #ffffff;
        --text-on-light: #000000;
        
        /* Border colors */
        --border-color: #d3d6da;
        --border-tile-empty: #d3d6da;
        --border-tile-filled: #999999;
        
        /* Game state colors */
        --color-correct: #6aaa64;
        --color-present: #c9b458;
        --color-absent: #787c7e;
        --color-error: #dc2626;
        --color-focus: #3b82f6;
        
        /* Navigation */
        --nav-bg: rgba(255, 255, 255, 0.95);
        --nav-text: #333333;
        --nav-border: rgba(211, 214, 218, 0.8);
    }
}

/* Navigation integration - minimal styles for game layout only */
.site-header {
    /* Let nav-menu.css handle all styling, just ensure z-index compatibility */
    z-index: var(--z-nav);
}

/* Auto-hide state - keep this for JavaScript integration */
.site-header.nav-hidden {
    transform: translateY(-100%);
}

/* Game container positioning - centralized nav height management */
.site-header.nav-hidden ~ #game-container,
body.nav-hidden #game-container {
    margin-top: 0;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    overflow-x: hidden;
    padding: 0;
    margin: 0;
    /* Prevent scroll bounce on mobile */
    overscroll-behavior: none;
    /* Better font rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Consistent text rendering */
    text-rendering: optimizeLegibility;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: calc(100vh - var(--nav-height));
    min-height: calc(var(--vh, 1vh) * 100 - var(--nav-height));
    max-width: var(--game-max-width);
    margin: var(--nav-height) auto 0;
    padding: calc(var(--container-padding) * 0.5) var(--container-padding) var(--container-padding);
    box-sizing: border-box;
    justify-content: flex-start;
    position: relative;
    gap: clamp(0.75rem, 2vh, 1.5rem);
}

/* Game Header with Controls */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: var(--board-max-width);
    flex: 0 0 auto;
    padding: calc(var(--container-padding) * 0.25) 0;
    margin-top: env(safe-area-inset-top, 0);
}

h1 {
    color: var(--text-primary);
    margin: 0;
    font-size: var(--font-large);
    font-weight: var(--font-weight-bold);
    text-align: center;
    letter-spacing: var(--letter-spacing-wide);
    transition: color var(--transition-medium) var(--easing-smooth);
    flex: 1;
}

.game-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--bg-key);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast) var(--easing-smooth);
    box-shadow: var(--shadow-base);
}

.control-btn:hover {
    background-color: var(--bg-key-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.control-btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-active);
}

.control-btn svg {
    width: 1.25rem;
    height: 1.25rem;
}

#game-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: var(--gap-base);
    width: 100%;
    max-width: var(--board-max-width);
    flex: 0 1 auto;
    height: min(
        calc(100vh - var(--nav-height) - var(--keyboard-min-height) - 200px),
        calc(var(--vh, 1vh) * 100 - var(--nav-height) - var(--keyboard-min-height) - 200px),
        calc(85vw * 1.2)
    );
    max-height: min(
        calc(100vh - var(--nav-height) - var(--keyboard-min-height) - 200px),
        calc(var(--vh, 1vh) * 100 - var(--nav-height) - var(--keyboard-min-height) - 200px),
        calc(85vw * 1.2)
    );
    aspect-ratio: 5/6;
    justify-content: center;
}

.board-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--gap-base);
    width: 100%;
    height: 100%;
}

.tile {
    aspect-ratio: 1;
    border: var(--border-width) solid var(--border-tile-empty);
    display: flex;
    justify-content: center;
    align-items: center;
    /* Improved responsive font sizing */
    font-size: var(--font-base);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    background-color: var(--bg-tile-empty);
    color: var(--text-primary);
    transition: all var(--transition-medium) var(--easing-smooth);
    width: 100%;
    height: 100%;
    /* Smart minimum height that adapts to container */
    min-height: var(--tile-base-size);
    /* Better border scaling */
    border-width: var(--border-width);
    border-radius: var(--border-radius);
    /* Better text rendering */
    letter-spacing: var(--letter-spacing-normal);
    /* Subtle depth and focus support */
    position: relative;
    outline: none;
}

.tile.filled {
    border-color: var(--border-tile-filled);
    background-color: var(--bg-tile-filled);
}

/* Enhanced focus state for accessibility */
.tile:focus,
.tile.focused {
    box-shadow: var(--shadow-focus);
    z-index: 1;
}

/* Better visual feedback for letter input */
.tile.typing {
    transform: scale(1.02);
    border-color: var(--color-focus);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.tile.correct {
    background-color: var(--color-correct);
    color: var(--text-on-dark);
    border-color: var(--color-correct);
    animation: flip var(--transition-slow) var(--easing-smooth);
}

.tile.present {
    background-color: var(--color-present);
    color: var(--text-on-dark);
    border-color: var(--color-present);
    animation: flip var(--transition-slow) var(--easing-smooth);
}

.tile.absent {
    background-color: var(--color-absent);
    color: var(--text-on-dark);
    border-color: var(--color-absent);
    animation: flip var(--transition-slow) var(--easing-smooth);
}

.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-0.625rem); }
    20%, 40%, 60%, 80% { transform: translateX(0.625rem); }
}

#keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
    width: 100%;
    max-width: min(31.25rem, 95vw);
    flex: 0 0 var(--keyboard-min-height);
    height: var(--keyboard-min-height);
    min-height: var(--keyboard-min-height);
    max-height: var(--keyboard-min-height);
    padding: clamp(0.25rem, 1vh, 0.5rem) 0;
    padding-bottom: calc(env(safe-area-inset-bottom, 0) + clamp(0.25rem, 1vh, 0.5rem));
    position: relative;
    z-index: 10;
}

.keyboard-row {
    display: flex;
    gap: var(--gap-base);
    margin: clamp(0.08rem, 0.3vh, 0.15rem) 0;
    width: 100%;
    justify-content: center;
    /* Ensure rows scale properly */
    max-width: 100%;
}

.keyboard-key {
    background-color: var(--bg-key);
    color: var(--text-on-light);
    border: none;
    border-radius: var(--border-radius);
    height: var(--touch-target-preferred);
    min-width: clamp(1.8rem, 4vw, 2rem);
    flex: 1;
    max-width: clamp(3rem, 8vw, 3.5rem);
    font-size: var(--font-small);
    font-weight: var(--font-weight-medium);
    padding: 0 clamp(0.15rem, 0.5vw, 0.25rem);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    touch-action: manipulation;
    user-select: none;
    transition: all var(--transition-fast) var(--easing-smooth);
    box-shadow: var(--shadow-base);
    /* Ensure minimum touch target size with scaling */
    min-height: max(var(--touch-target-min), var(--touch-target-preferred));
    letter-spacing: var(--letter-spacing-wide);
    text-transform: uppercase;
    /* Better visual depth with fallback */
    background: var(--bg-key);
    background: linear-gradient(180deg, 
        color-mix(in srgb, var(--bg-key) 90%, white 10%) 0%, 
        var(--bg-key) 100%);
    position: relative;
}

.keyboard-key:hover {
    background: var(--bg-key-hover);
    background: linear-gradient(180deg, 
        color-mix(in srgb, var(--bg-key-hover) 90%, white 10%) 0%, 
        var(--bg-key-hover) 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.keyboard-key:active {
    transform: translateY(1px);
    box-shadow: var(--shadow-active);
    background: var(--bg-key-hover);
    background: linear-gradient(180deg, 
        color-mix(in srgb, var(--bg-key-hover) 80%, black 20%) 0%, 
        color-mix(in srgb, var(--bg-key-hover) 90%, black 10%) 100%);
    opacity: var(--opacity-active);
}

/* Enhanced focus state for accessibility */
.keyboard-key:focus {
    outline: none;
    box-shadow: var(--shadow-focus), var(--shadow-base);
    z-index: 1;
}

.keyboard-key.wide {
    flex: 1.5;
    min-width: clamp(2.5rem, 6vw, 3rem);
    max-width: clamp(4rem, 10vw, 5rem);
    font-size: clamp(0.6rem, 1.8vw, 0.75rem);
    font-weight: var(--font-weight-bold);
}

/* Enhanced keyboard game state colors */
.keyboard-key.correct {
    background: var(--color-correct);
    background: linear-gradient(180deg, 
        color-mix(in srgb, var(--color-correct) 90%, white 10%) 0%, 
        var(--color-correct) 100%);
    color: var(--text-on-dark);
    box-shadow: 0 2px 0 var(--color-correct);
    box-shadow: 0 2px 0 color-mix(in srgb, var(--color-correct) 80%, black 20%);
}

.keyboard-key.present {
    background: var(--color-present);
    background: linear-gradient(180deg, 
        color-mix(in srgb, var(--color-present) 90%, white 10%) 0%, 
        var(--color-present) 100%);
    color: var(--text-on-dark);
    box-shadow: 0 2px 0 var(--color-present);
    box-shadow: 0 2px 0 color-mix(in srgb, var(--color-present) 80%, black 20%);
}

.keyboard-key.absent {
    background: var(--color-absent);
    background: linear-gradient(180deg, 
        color-mix(in srgb, var(--color-absent) 90%, white 10%) 0%, 
        var(--color-absent) 100%);
    color: var(--text-on-dark);
    box-shadow: 0 2px 0 var(--color-absent);
    box-shadow: 0 2px 0 color-mix(in srgb, var(--color-absent) 80%, black 20%);
    opacity: var(--opacity-hover);
}

/* Hover states for game state keys */
.keyboard-key.correct:hover,
.keyboard-key.present:hover,
.keyboard-key.absent:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 0 currentColor;
    box-shadow: 0 3px 0 color-mix(in srgb, currentColor 70%, black 30%);
}
@keyframes flip {
    0% { 
        transform: rotateX(0);
        background-color: var(--bg-tile-empty);
    }
    50% { 
        transform: rotateX(90deg);
        background-color: var(--bg-tile-empty);
    }
    100% { 
        transform: rotateX(0);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-0.5rem); }
    20%, 40%, 60%, 80% { transform: translateX(0.5rem); }
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.02);
        opacity: 0.85;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-0.5rem);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% {
        transform: translateY(0);
    }
    40%, 43% {
        transform: translateY(-0.5rem);
    }
    70% {
        transform: translateY(-0.25rem);
    }
    90% {
        transform: translateY(-0.125rem);
    }
}

@keyframes firework-particle {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--end-x), var(--end-y)) scale(0);
        opacity: 0;
    }
}

/* Enhanced tile states with better animations and visual feedback */
.tile.filled {
    border-color: var(--border-tile-filled);
    background-color: var(--bg-tile-filled);
    animation: popIn calc(var(--transition-fast) * 1.5) var(--easing-bounce);
    box-shadow: 
        inset 0 0 0 1px rgba(255,255,255,0.1),
        0 2px 4px rgba(0,0,0,0.05);
}

.tile.correct {
    background-color: var(--color-correct);
    color: var(--text-on-dark);
    border-color: var(--color-correct);
    animation: flip var(--transition-slow) var(--easing-smooth);
    box-shadow: 0 2px 8px rgba(106, 170, 100, 0.3);
}

.tile.present {
    background-color: var(--color-present);
    color: var(--text-on-dark);
    border-color: var(--color-present);
    animation: flip var(--transition-slow) var(--easing-smooth);
    box-shadow: 0 2px 8px rgba(201, 180, 88, 0.3);
}

.tile.absent {
    background-color: var(--color-absent);
    color: var(--text-on-dark);
    border-color: var(--color-absent);
    animation: flip var(--transition-slow) var(--easing-smooth);
    box-shadow: 0 2px 8px rgba(120, 124, 126, 0.3);
}

.shake {
    animation: shake var(--transition-slow) var(--easing-smooth);
    border-color: var(--color-error) !important;
}

/* Loading state for tiles */
.tile.loading {
    animation: pulse 1.5s var(--easing-smooth) infinite;
    background-color: var(--border-tile-empty);
    opacity: var(--opacity-hover);
}

/* Success state with celebration animation */
.tile.celebration {
    animation: bounce 0.6s var(--easing-bounce);
}


/* Enhanced keyboard key states */
.keyboard-key.correct {
    background: linear-gradient(180deg, #7bb76d 0%, #6aaa64 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(106, 170, 100, 0.3);
}

.keyboard-key.present {
    background: linear-gradient(180deg, #d4c260 0%, #c9b458 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(201, 180, 88, 0.3);
}

.keyboard-key.absent {
    background: linear-gradient(180deg, #8a8e90 0%, #787c7e 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(120, 124, 126, 0.3);
}

/* Wordle-inspired responsive design */

/* Mobile Responsive Adjustments for New UI */
@media screen and (max-width: 480px) {
    .game-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: center;
    }
    
    .control-btn {
        width: 2.25rem;
        height: 2.25rem;
    }
    
    .modal-content {
        margin: 1rem;
        max-width: calc(100vw - 2rem);
    }
    
    .modal-header,
    .modal-body {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
    
    .stats-actions {
        flex-direction: column;
    }
    
    .primary-btn,
    .secondary-btn {
        width: 100%;
    }
    
    .example-row {
        justify-content: center;
    }
}

/* Mobile devices - touch optimized */
@media (hover: none) and (pointer: coarse) {
    .keyboard-key:hover {
        background-color: #d3d6da; /* Reset hover on touch devices */
        transform: none;
        box-shadow: 0 2px 0 rgba(0,0,0,0.1);
    }
    
    .control-btn:hover {
        background-color: var(--bg-key);
        transform: none;
        box-shadow: var(--shadow-base);
    }
    
    .keyboard-key:active {
        background-color: #999;
        transform: translateY(1px);
        box-shadow: 0 1px 0 rgba(0,0,0,0.1);
    }
}

/* Enhanced mobile screens - optimized scaling */
@media screen and (max-width: 480px) {
    #game-container {
        padding: 0 clamp(0.25rem, 1vw, 0.5rem);
        max-height: 100vh;
        max-height: calc(var(--vh, 1vh) * 100);
        gap: clamp(0.25rem, 1vh, 0.5rem);
    }
    
    h1 {
        font-size: clamp(1.1rem, 4vw, 1.25rem);
        padding: clamp(0.5rem, 2vh, 0.75rem) 0 0 0;
        flex: 0 0 auto;
    }
    
    #game-board {
        max-width: var(--board-max-width);
        gap: clamp(0.1rem, 0.8vw, 0.2rem);
        /* Fixed height calculation with proper buffer space */
        height: min(
            calc(100vh - var(--nav-height-mobile) - var(--keyboard-min-height) - 140px),
            calc(var(--vh, 1vh) * 100 - var(--nav-height-mobile) - var(--keyboard-min-height) - 140px),
            calc(80vw * 1.2)
        );
        max-height: min(
            calc(100vh - var(--nav-height-mobile) - var(--keyboard-min-height) - 140px),
            calc(var(--vh, 1vh) * 100 - var(--nav-height-mobile) - var(--keyboard-min-height) - 140px),
            calc(80vw * 1.2)
        );
    }
    
    .board-row {
        gap: clamp(0.1rem, 0.8vw, 0.2rem);
    }
    
    .tile {
        font-size: clamp(0.9rem, 3.2vw, 1.5rem);
        min-height: clamp(1.8rem, 6.5vw, 3rem);
        border-width: clamp(1px, 0.2vw, 1.5px);
    }

    .keyboard-key {
        height: clamp(2.2rem, 6vh, 2.5rem);
        font-size: clamp(0.7rem, 2.2vw, 0.8rem);
        min-height: max(44px, clamp(2.2rem, 6vh, 2.5rem));
    }
    
    .keyboard-row {
        gap: clamp(0.1rem, 0.6vw, 0.2rem);
        margin: clamp(0.05rem, 0.3vh, 0.1rem) 0;
    }
    
    .keyboard-key.wide {
        font-size: clamp(0.6rem, 2vw, 0.7rem);
    }
}

/* Very small screens - intelligent scaling */
@media screen and (max-width: 400px) {
    #game-container {
        padding: 0 clamp(0.15rem, 0.8vw, 0.25rem);
    }
    
    h1 {
        font-size: clamp(1rem, 3.5vw, 1.1rem);
        padding: clamp(0.3rem, 1.5vh, 0.5rem) 0 clamp(0.1rem, 0.8vh, 0.25rem) 0;
    }
    
    #game-board {
        max-width: min(15.625rem, 80vw);
        gap: clamp(0.08rem, 0.6vw, 0.15rem);
        /* More aggressive height constraint for small screens */
        max-height: min(
            calc(100vh - 240px),
            calc(var(--vh, 1vh) * 100 - 240px),
            calc(80vw * 1.2)
        );
    }
    
    .board-row {
        gap: clamp(0.08rem, 0.6vw, 0.15rem);
    }
    
    .tile {
        font-size: clamp(0.8rem, 2.8vw, 1.25rem);
        min-height: clamp(1.5rem, 5.5vw, 2.5rem);
        border-width: clamp(0.5px, 0.15vw, 1px);
    }

    .keyboard-key {
        height: clamp(2rem, 5.5vh, 2.25rem);
        font-size: clamp(0.65rem, 2vw, 0.75rem);
        min-height: max(44px, clamp(2rem, 5.5vh, 2.25rem));
    }
    
    .keyboard-row {
        gap: clamp(0.08rem, 0.5vw, 0.15rem);
        margin: clamp(0.04rem, 0.25vh, 0.08rem) 0;
    }
    
    .keyboard-key.wide {
        font-size: clamp(0.55rem, 1.8vw, 0.65rem);
    }
}

/* Short screens - prioritize keyboard visibility */
@media screen and (max-height: 650px) {
    #game-container {
        padding: 0.25rem 1rem;
        gap: 0.5rem;
    }
    
    h1 {
        font-size: 1.1rem;
        padding: 0.5rem 0 0 0;
        flex: 0 0 auto;
    }
    
    #game-board {
        /* Fixed height constraint with more buffer space */
        height: calc(100vh - var(--nav-height) - var(--keyboard-min-height) - 100px);
        max-height: calc(100vh - var(--nav-height) - var(--keyboard-min-height) - 100px);
        gap: 0.2rem;
    }
    
    .board-row {
        gap: 0.2rem;
    }
    
    .tile {
        font-size: clamp(1rem, 3.5vw, 1.4rem);
        min-height: clamp(1.8rem, 6.5vw, 2.75rem);
    }
    
    .keyboard-key {
        height: 2.25rem;
        font-size: 0.75rem;
        min-height: 44px;
    }
}

/* Extra short screens - compact layout with keyboard priority */
@media screen and (max-height: 550px) {
    #game-container {
        padding: 0.15rem 1rem;
        gap: 0.25rem;
    }
    
    h1 {
        font-size: 1rem;
        padding: 0.25rem 0 0 0;
        flex: 0 0 auto;
    }
    
    #game-board {
        gap: 0.1rem;
        /* Fixed height for very short screens with more buffer space */
        height: calc(100vh - var(--nav-height) - var(--keyboard-min-height) - 80px);
        max-height: calc(100vh - var(--nav-height) - var(--keyboard-min-height) - 80px);
    }
    
    .board-row {
        gap: 0.1rem;
    }
    
    .tile {
        font-size: clamp(0.8rem, 3vw, 1.1rem);
        min-height: clamp(1.5rem, 5.5vw, 2.25rem);
    }
    
    .keyboard-key {
        height: 2rem;
        font-size: 0.7rem;
        min-height: 44px;
    }
    
    .keyboard-row {
        margin: 0.05rem 0;
    }
}

/* Enhanced landscape mode for phones with better space utilization */
@media screen and (max-height: 500px) and (orientation: landscape) and (max-width: 900px) {
    :root {
        --nav-height-landscape: 50px;
    }
    
    #game-container {
        flex-direction: row;
        justify-content: center;
        align-items: stretch;
        gap: clamp(0.5rem, 2vw, 1.5rem);
        padding: clamp(0.15rem, 1vh, 0.5rem) clamp(0.5rem, 2vw, 1rem);
        margin-top: var(--nav-height-landscape);
        height: calc(100vh - var(--nav-height-landscape));
        height: calc(var(--vh, 1vh) * 100 - var(--nav-height-landscape));
    }
    
    /* When nav is hidden in landscape */
    .site-header.nav-hidden ~ #game-container,
    body.nav-hidden #game-container {
        margin-top: 0;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }
    
    h1 {
        writing-mode: vertical-lr;
        transform: rotate(180deg);
        margin: 0;
        font-size: clamp(0.8rem, 2vh, 1rem);
        flex: 0 0 auto;
        padding: 0;
        width: clamp(1.5rem, 4vh, 2rem);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    #game-board {
        flex: 0 0 auto;
        max-width: min(40vh, 50vw);
        max-height: 90vh;
        max-height: calc(var(--vh, 1vh) * 90);
        aspect-ratio: 5/6;
        margin-bottom: 0;
    }
    
    #keyboard {
        flex: 1 1 auto;
        max-width: min(50vw, 25rem);
        margin-top: 0;
        min-height: auto;
        justify-content: center;
        padding: clamp(0.25rem, 1vh, 0.5rem) 0;
    }
    
    .tile {
        font-size: clamp(0.7rem, 2.5vh, 1.1rem);
        min-height: clamp(1.2rem, 4vh, 2rem);
    }
    
    .keyboard-key {
        height: clamp(1.5rem, 4vh, 2rem);
        font-size: clamp(0.5rem, 1.5vh, 0.7rem);
        min-height: max(36px, clamp(1.5rem, 4vh, 2rem));
    }
    
    .keyboard-row {
        margin: clamp(0.03rem, 0.2vh, 0.08rem) 0;
        gap: clamp(0.1rem, 0.3vw, 0.2rem);
    }
    
    .keyboard-key.wide {
        font-size: clamp(0.45rem, 1.3vh, 0.65rem);
        min-width: clamp(2rem, 5vw, 3rem);
    }
}

/* Advanced responsive enhancements */

/* Large screens - optimal desktop experience */
@media screen and (min-width: 1200px) {
    #game-container {
        max-width: 35rem;
        padding: 0 2rem;
    }
    
    h1 {
        font-size: 2rem;
        padding: 1rem 0 0.5rem 0;
    }
    
    #game-board {
        max-width: 25rem;
        gap: 0.375rem;
    }
    
    .board-row {
        gap: 0.375rem;
    }
    
    .tile {
        font-size: 2.25rem;
        min-height: 3.5rem;
        border-width: 2.5px;
    }
    
    .keyboard-key {
        height: 2.75rem;
        font-size: 1rem;
        border-radius: 0.375rem;
    }
    
    .keyboard-row {
        gap: 0.375rem;
        margin: 0.15rem 0;
    }
    
    .keyboard-key.wide {
        font-size: 0.9rem;
    }
}

/* Tablet portrait mode optimization */
@media screen and (min-width: 481px) and (max-width: 768px) and (orientation: portrait) {
    #game-container {
        max-width: 28rem;
        padding: 0 1.5rem;
    }
    
    h1 {
        font-size: 1.75rem;
        padding: 1rem 0 0.75rem 0;
    }
    
    #game-board {
        max-width: 22rem;
        gap: 0.3rem;
    }
    
    .board-row {
        gap: 0.3rem;
    }
    
    .tile {
        font-size: 1.8rem;
        min-height: 3.5rem;
        border-width: 2px;
    }
    
    .keyboard-key {
        height: 3rem;
        font-size: 0.9rem;
        min-height: 48px;
    }
    
    .keyboard-row {
        gap: 0.3rem;
        margin: 0.2rem 0;
    }
    
    .keyboard-key.wide {
        font-size: 0.8rem;
    }
}

/* Tablet landscape mode optimization */
@media screen and (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
    #game-container {
        flex-direction: row;
        gap: 2rem;
        max-width: none;
        padding: 1rem 2rem;
        align-items: center;
        justify-content: center;
    }
    
    h1 {
        writing-mode: vertical-lr;
        transform: rotate(180deg);
        font-size: 1.5rem;
        width: 3rem;
        flex: 0 0 auto;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    #game-board {
        flex: 0 0 auto;
        max-width: 20rem;
        max-height: 24rem;
    }
    
    #keyboard {
        flex: 0 0 auto;
        max-width: 30rem;
        min-height: auto;
    }
    
    .tile {
        font-size: 1.6rem;
        min-height: 3.2rem;
    }
    
    .keyboard-key {
        height: 2.8rem;
        font-size: 0.85rem;
        min-height: 44px;
    }
}

/* Base layout and behavior */

html, body {
    overflow-x: hidden;
    position: relative;
    width: 100%;
    /* Allow vertical scroll when needed */
    overflow-y: auto;
    /* Prevent bounce/scroll on mobile */
    overscroll-behavior-x: none;
    -webkit-overflow-scrolling: touch;
}

/* Prevent zoom on double tap */
* {
    touch-action: manipulation;
}

/* Enhanced focus styles for accessibility */
.keyboard-key:focus {
    outline: 3px solid #007acc;
    outline-offset: 2px;
    /* Ensure focus is visible on all backgrounds */
    box-shadow: var(--shadow-base), 0 0 0 2px rgba(0, 122, 204, 0.2);
}

.keyboard-key:focus:not(:focus-visible) {
    outline: none;
    box-shadow: var(--shadow-base);
}

.keyboard-key:focus-visible {
    outline: 3px solid #007acc;
    outline-offset: 2px;
    box-shadow: var(--shadow-base), 0 0 0 2px rgba(0, 122, 204, 0.2);
}

/* Enhanced tile focus for keyboard navigation */
.tile:focus {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

/* Better keyboard navigation support */
.game-board:focus-within .tile {
    position: relative;
}

.game-board:focus-within .tile:focus::before {
    content: '';
    position: absolute;
    inset: -4px;
    border: 2px solid #007acc;
    border-radius: 4px;
    pointer-events: none;
}

/* Improve text readability */
@media (prefers-reduced-motion: reduce) {
    .tile,
    .keyboard-key {
        transition: none;
        animation: none;
    }
    
    .shake {
        animation: none;
        border: 2px solid #ff4444;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tile {
        border-width: 3px;
    }
    
    .keyboard-key {
        border: 2px solid #000;
    }
}

/* Safe area support for notched devices */
body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Enhanced emergency fallback for extremely small screens */
@media screen and (max-height: 450px) {
    :root {
        --gap-base: 0.05rem;
        --font-base: clamp(0.7rem, 2.5vw, 1rem);
        --tile-base-size: clamp(1.3rem, 5vw, 2rem);
        --keyboard-min-height: 140px;
        --touch-target-preferred: 1.8rem;
    }
    
    #game-container {
        padding: 0.1rem 0.5rem;
    }
    
    h1 {
        font-size: 0.9rem;
        padding: 0.2rem 0 0.1rem 0;
    }
    
    #game-board {
        max-height: calc(100vh - 160px);
        max-height: calc(var(--vh, 1vh) * 100 - 160px);
    }
    
    .tile {
        border-width: 1px;
    }

    #keyboard {
        padding: 0.25rem 0;
    }
    
    .keyboard-key {
        min-height: max(40px, var(--touch-target-preferred));
    }
    
    .keyboard-row {
        margin: 0.03rem 0;
    }
}

/* Enhanced absolute minimum fallback with fixed keyboard */
@media screen and (max-height: 400px) {
    :root {
        --keyboard-min-height: 120px;
    }
    
    #game-container {
        gap: 0.15rem;
    }
    
    #keyboard {
        min-height: 120px;
        height: 120px;
        max-height: 120px;
        flex: 0 0 120px;
        position: relative;
        background: var(--bg-primary);
        padding: 0.2rem 0;
        /* Ensure keyboard maintains space */
        margin-top: auto;
    }
    
    #game-board {
        height: calc(100vh - var(--nav-height) - 140px);
        max-height: calc(100vh - var(--nav-height) - 140px);
        flex: 0 1 auto;
    }
    
    h1 {
        padding: 0.15rem 0 0 0;
        flex: 0 0 auto;
    }
}

/* Game Status */
.game-status {
    width: 100%;
    max-width: var(--board-max-width);
    flex: 0 0 auto;
    text-align: center;
    margin: 0.5rem 0;
    min-height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-message {
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-large);
    font-weight: var(--font-weight-medium);
    font-size: var(--font-small);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
    transition: all var(--transition-medium) var(--easing-smooth);
    animation: slideIn var(--transition-medium) var(--easing-smooth);
}

.status-message.success {
    background-color: var(--color-correct);
    color: var(--text-on-dark);
}

.status-message.error {
    background-color: var(--color-error);
    color: var(--text-on-dark);
}

.status-message.info {
    background-color: var(--color-focus);
    color: var(--text-on-dark);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    backdrop-filter: blur(4px);
    animation: fadeIn var(--transition-medium) var(--easing-smooth);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius-large);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: min(90vw, 500px);
    max-height: 90vh;
    overflow-y: auto;
    animation: slideInUp var(--transition-medium) var(--easing-bounce);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast) var(--easing-smooth);
}

.close-btn:hover {
    background-color: var(--bg-tile-empty);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    color: var(--text-primary);
    line-height: 1.6;
}

.modal-body p {
    margin-bottom: 1rem;
}

.modal-body ul {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
}

/* Examples Section */
.examples {
    margin-top: 1.5rem;
}

.examples h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: var(--font-weight-bold);
}

.example-row {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
    justify-content: flex-start;
}

.example-tile {
    width: 2rem;
    height: 2rem;
    border: 2px solid var(--border-tile-empty);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-bold);
    font-size: 0.9rem;
    text-transform: uppercase;
    background-color: var(--bg-tile-empty);
    color: var(--text-primary);
    border-radius: var(--border-radius);
}

.example-tile.correct {
    background-color: var(--color-correct);
    border-color: var(--color-correct);
    color: var(--text-on-dark);
}

.example-tile.present {
    background-color: var(--color-present);
    border-color: var(--color-present);
    color: var(--text-on-dark);
}

.example-tile.absent {
    background-color: var(--color-absent);
    border-color: var(--color-absent);
    color: var(--text-on-dark);
}

/* Statistics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
    text-align: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
}

/* Guess Distribution */
.guess-distribution {
    margin-bottom: 2rem;
}

.guess-distribution h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: var(--font-weight-bold);
}

.distribution-chart {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.distribution-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.distribution-row > span:first-child {
    width: 1rem;
    text-align: center;
    font-weight: var(--font-weight-medium);
}

.distribution-bar {
    flex: 1;
    height: 1.25rem;
    background-color: var(--bg-tile-empty);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
}

.distribution-fill {
    height: 100%;
    background-color: var(--color-correct);
    transition: width var(--transition-medium) var(--easing-smooth);
    min-width: 0;
    border-radius: var(--border-radius);
}

.distribution-count {
    width: 1.5rem;
    text-align: center;
    font-weight: var(--font-weight-medium);
}

/* Next Game Timer */
.next-game-timer {
    text-align: center;
    margin-bottom: 2rem;
}

.next-game-timer h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    font-weight: var(--font-weight-bold);
}

#countdown-timer {
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
    color: var(--color-focus);
    font-family: 'Courier New', monospace;
}

/* Action Buttons */
.stats-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.primary-btn,
.secondary-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-weight: var(--font-weight-medium);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast) var(--easing-smooth);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
    min-width: 6rem;
}

.primary-btn {
    background-color: var(--color-correct);
    color: var(--text-on-dark);
    box-shadow: var(--shadow-base);
}

.primary-btn:hover {
    background-color: color-mix(in srgb, var(--color-correct) 90%, black 10%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.secondary-btn {
    background-color: var(--bg-key);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.secondary-btn:hover {
    background-color: var(--bg-key-hover);
    border-color: var(--text-secondary);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Animation Keyframes */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        transform: translateY(2rem);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Enhanced Accessibility Features */

/* Focus management for keyboard navigation */
.tile:focus,
.keyboard-key:focus {
    outline: none;
    box-shadow: var(--shadow-focus);
    z-index: 1;
    position: relative;
}

/* Game board focus container */
#game-board:focus-within {
    outline: 2px solid var(--color-focus);
    outline-offset: 4px;
    border-radius: var(--border-radius);
}

/* Screen reader improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .tile,
    .keyboard-key {
        transition: none;
    }
    
    .shake {
        animation: none;
        border-color: var(--color-error) !important;
        box-shadow: 0 0 0 2px var(--color-error);
    }
}

/* Additional Accessibility Enhancements */

/* Screen reader announcements */
.sr-announcer {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Focus management for modals */
.modal[aria-hidden="false"] {
    display: flex;
}

.modal[aria-hidden="true"] {
    display: none;
}

/* Improved focus indicators */
.control-btn:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.primary-btn:focus-visible,
.secondary-btn:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.close-btn:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-width: 3px;
        --shadow-base: 0 3px 0 rgba(0,0,0,0.3);
        --shadow-hover: 0 4px 0 rgba(0,0,0,0.4);
        --shadow-focus: 0 0 0 4px var(--color-focus);
    }
    
    .tile {
        border-width: var(--border-width-thick);
    }
    
    .keyboard-key {
        border: var(--border-width) solid var(--text-primary);
        font-weight: var(--font-weight-bold);
    }
    
    .tile.correct,
    .tile.present,
    .tile.absent {
        border: var(--border-width-thick) solid var(--text-on-dark);
    }
}

/* Dark mode specific optimizations */
@media (prefers-color-scheme: dark) {
    .keyboard-key {
        background: linear-gradient(180deg, 
            color-mix(in srgb, var(--bg-key) 85%, white 15%) 0%, 
            var(--bg-key) 100%);
        color: var(--text-primary);
    }
    
    .keyboard-key:hover {
        background: linear-gradient(180deg, 
            color-mix(in srgb, var(--bg-key-hover) 85%, white 15%) 0%, 
            var(--bg-key-hover) 100%);
    }
    
    .tile {
        background-color: var(--bg-tile-empty);
        border-color: var(--border-tile-empty);
    }
    
    /* Better visibility for empty tiles in dark mode */
    .tile:not(.filled):not(.correct):not(.present):not(.absent) {
        border-color: var(--border-tile-empty);
        background-color: var(--bg-tile-empty);
    }
}

/* Print styles */
@media print {
    * {
        color: black !important;
        background: white !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    .site-header,
    #keyboard {
        display: none !important;
    }
    
    #game-container {
        margin-top: 0;
        height: auto;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .keyboard-key:hover {
        background: var(--bg-key);
        transform: none;
        box-shadow: var(--shadow-base);
    }
    
    .keyboard-key:active {
        background: var(--bg-key-hover);
        transform: scale(0.95);
        box-shadow: var(--shadow-active);
    }
    
    /* Larger touch targets on small screens */
    @media screen and (max-width: 480px) {
        .keyboard-key {
            min-height: 48px;
            height: clamp(2.5rem, 7vh, 3rem);
        }
    }
}

/* Performance optimizations */
.tile,
.keyboard-key {
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Prevent content jumping during animations */
#game-board,
#keyboard {
    contain: layout style;
}

/* Loading state */
.game-loading {
    opacity: var(--opacity-disabled);
    pointer-events: none;
}

.game-loading .tile {
    animation: pulse 1.5s var(--easing-smooth) infinite;
}

/* Success celebration effects */
.game-success .tile.correct {
    animation: bounce 0.6s var(--easing-bounce);
}

.game-success h1 {
    color: var(--color-correct);
    animation: pulse 2s var(--easing-smooth) infinite;
}