/* Nav-menu isolation fixes */
.site-header,
.site-header *,
.main-nav,
.main-nav *,
.mobile-menu-toggle,
.mobile-menu-toggle * {
    box-sizing: border-box !important;
    font-family: Arial, sans-serif !important;
    user-select: auto !important;
    -webkit-user-select: auto !important;
    -moz-user-select: auto !important;
    -ms-user-select: auto !important;
}

/* Ensure nav has proper layering */
.site-header {
    position: relative !important;
    z-index: 1000 !important;
    margin-bottom: 1.5rem !important;
    width: 100% !important;
}

.main-nav {
    position: relative !important;
    z-index: 999 !important;
}

.mobile-menu-toggle {
    z-index: 1001 !important;
}

/* Mobile nav specific fixes */
@media screen and (max-width: 768px) {
    .site-header {
        padding-top: 4rem !important;
    }
    
    .main-nav {
        position: absolute !important;
        top: 3.5rem !important;
        left: 1rem !important;
        right: 1rem !important;
        width: calc(100% - 2rem) !important;
        background-color: #333 !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
        max-width: none !important;
        min-width: auto !important;
    }
    
    .main-nav.nav-open {
        display: block !important;
    }
    
    .main-nav ul {
        width: 100% !important;
        flex-direction: column !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .main-nav li {
        width: 100% !important;
        display: block !important;
        margin: 0 !important;
    }
    
    .main-nav a {
        width: 100% !important;
        padding: 1rem !important;
        text-align: left !important;
        display: block !important;
        box-sizing: border-box !important;
    }
    
    .mobile-menu-toggle {
        position: absolute !important;
        top: 1rem !important;
        right: 1rem !important;
        background-color: #333 !important;
        color: #fff !important;
        border: none !important;
        padding: 0.5rem !important;
        border-radius: 0.25rem !important;
        cursor: pointer !important;
    }
}

/* Prevent game styles from affecting nav buttons and links */
.site-header button,
.site-header a,
.main-nav button,
.main-nav a,
.mobile-menu-toggle {
    font-size: 1rem !important;
    line-height: normal !important;
    letter-spacing: normal !important;
    text-transform: none !important;
    font-weight: normal !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
}

/* Ensure nav content is clickable/touchable */
.main-nav a,
.mobile-menu-toggle {
    -webkit-tap-highlight-color: rgba(0,0,0,0.1) !important;
    tap-highlight-color: rgba(0,0,0,0.1) !important;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f5f5f5;
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    padding-top: 1rem;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 31.25rem;
    padding: 0 1rem;
}

h1 {
    color: #333;
    margin-bottom: 1.25rem;
    font-size: 2rem;
    border-bottom: 2px solid #ddd;
    padding-bottom: 0.625rem;
}

#game-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 0.3125rem;
    width: 100%;
    max-width: 21.875rem;
}

.board-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.3125rem;
}

.tile {
    aspect-ratio: 1;
    border: 0.125rem solid #d3d6da;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: min(2rem, 5vmin);
    font-weight: bold;
    text-transform: uppercase;
    background-color: white;
    color: #333;
    transition: all 0.3s ease;
}

.tile.filled {
    border-color: #999;
}

.tile.correct {
    background-color: #6aaa64;
    color: white;
    border: none;
    animation: flip 0.5s ease;
}

.tile.present {
    background-color: #c9b458;
    color: white;
    border: none;
    animation: flip 0.5s ease;
}

.tile.absent {
    background-color: #787c7e;
    color: white;
    border: none;
    animation: flip 0.5s ease;
}

.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 {
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
    width: 100%;
    max-width: 31.25rem;
}

.keyboard-row {
    display: flex;
    gap: 0.25rem;
    margin: 0.3125rem 0;
    width: 100%;
    justify-content: center;
}

.keyboard-key {
    background-color: #d3d6da;
    border: none;
    border-radius: 0.25rem;
    margin: 0 0.0625rem;
    height: min(3.5rem, 8vmin);
    min-width: min(2.5rem, 6vmin);
    font-size: 0.875rem;
    padding: 0 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.keyboard-key:hover {
    background-color: #bbb;
}

.keyboard-key.wide {
    width: auto;
    flex-grow: 1;
}

@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

.keyboard-key.correct {
    background-color: #6aaa64;
    color: white;
}

.keyboard-key.present {
    background-color: #c9b458;
    color: white;
}

.keyboard-key.absent {
    background-color: #787c7e;
    color: white;
}

@media screen and (max-width: 30em) {
    .tile {
        font-size: 2rem;
    }

    .keyboard-key {
        height: 3.5rem;
        min-width: 2.25rem;
        font-size: 0.8rem;
        padding: 0 0.3rem;
    }
    
    h1 {
        font-size: 1.75rem;
    }
    
    .keyboard-row {
        gap: 0.2rem;
    }
    
    .keyboard-key {
        margin: 0 0.05rem;
    }
    
    .keyboard-key.wide {
        font-size: 0.75rem;
    }
}

@media screen and (max-width: 20em) {
    .tile {
        font-size: 1.75rem;
    }

    .keyboard-key {
        height: 3rem;
        min-width: 2rem;
        font-size: 0.8rem;
        padding: 0 0.4rem;
    }
}

@media screen and (max-height: 37.5em) {
    body {
        padding-top: 0.5rem;
    }

    h1 {
        margin-bottom: 0.75rem;
    }

    #keyboard {
        margin-top: 0.75rem;
    }

    .keyboard-key {
        height: 2.75rem;
    }
}

@media screen and (-webkit-min-device-pixel-ratio: 2), 
       screen and (min-resolution: 192dpi) {
    .tile {
        font-size: 2rem;
    }

    .keyboard-key {
        height: 3.5rem;
        font-size: 1rem;
    }
}

@media (hover: none) and (pointer: coarse) {
    .keyboard-key {
        font-size: 1.125rem;
    }
}

@media screen and (max-height: 37.5em) and (orientation: landscape) {
    #game-container {
        flex-direction: row;
        justify-content: center;
        align-items: flex-start;
        max-width: none;
        gap: 1rem;
    }
    
    h1 {
        writing-mode: vertical-lr;
        transform: rotate(180deg);
        margin-bottom: 0;
        margin-right: 0.5rem;
        padding-bottom: 0;
        border-bottom: none;
        border-left: 2px solid #ddd;
        padding-left: 0.5rem;
    }
    
    #keyboard {
        margin-top: 0;
    }
}

@media (prefers-color-scheme: dark) {
    body {
        background-color: #121213;
        color: #d7dadc;
    }
    
    h1 {
        color: #d7dadc;
        border-bottom-color: #3a3a3c;
    }
    
    .tile {
        border-color: #3a3a3c;
        color: #d7dadc;
        background-color: #121213;
    }
    
    .keyboard-key {
        background-color: #818384;
        color: #d7dadc;
    }
    
    .keyboard-key:hover {
        background-color: #565758;
    }
}

@media screen and (max-height: 28.125em) { /* ~450px */
    body {
        padding-top: 0.25rem;
    }

    h1 {
        margin-bottom: 0.5rem;
        font-size: 1.5rem;
    }

    #game-board {
        gap: 0.25rem;
    }

    .keyboard-row {
        margin: 0.125rem 0;
        gap: 0.25rem;
    }

    #keyboard {
        margin-top: 0.5rem;
    }

    .keyboard-key {
        height: 2.25rem;
    }
}

/* Add this fix for the config button positioning conflict */

/* Adjust config button position to avoid nav menu overlap */
#settings-button {
    position: fixed;
    top: 1rem;
    right: 4rem; /* Move left to avoid nav menu toggle */
    z-index: 998; /* Below nav menu but above game content */
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#settings-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* On very small screens, move config button below nav */
@media screen and (max-width: 480px) {
    #settings-button {
        top: 4.5rem; /* Move below the nav area */
        right: 1rem;
    }
}

/* Alternative: Move config button to left side on mobile */
@media screen and (max-width: 768px) {
    #settings-button {
        left: 1rem;
        right: auto;
        top: 1rem;
    }
}

/* Ensure nav toggle has enough space */
.mobile-menu-toggle {
    position: absolute !important;
    top: 1rem !important;
    right: 1rem !important;
    z-index: 1001 !important;
    width: 40px !important;
    height: 40px !important;
}

html, body {
    overflow-x: hidden;
    position: relative;
    width: 100%;
}