/* ============================================
   Main Layout & Container Styles
   ============================================ */

#board.centered-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    margin: 0 auto;
    gap: 1px;
}

.tile-row {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    margin: 0 auto 1px;
}

.tiles-container {
    display: flex;
    gap: 1px;
}

#keyboard {
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    margin-bottom: 3px;
}

/* ============================================
   Tile Styles & States
   ============================================ */

.tile {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 60px;
    height: 60px;
    margin: 1px;
    border-radius: 10px;
    font-size: 24px;
    box-sizing: border-box;
    color: #333;
    background-color: #fff;
    border: 2px solid #999;
    cursor: pointer;
}

.dark .tile {
    color: #f8fafc;
    background-color: #1e293b;
    border-color: #475569;
}

.tile.empty {
    border: 3px solid #457b9d;
    background-image: radial-gradient(#a8dadc, #f1faee);
    background-size: cover;
    color: transparent;
}

.dark .tile.empty {
    border-color: #1e3a8a;
    background-image: radial-gradient(#1e40af, #0f172a);
}

.tile.correct {
    background-color: #6aaa64;
    color: #fff;
    border-color: #6aaa64;
}

.tile.present {
    background-color: #c9b458;
    color: #fff;
    border-color: #c9b458;
}

.tile.absent {
    background-color: #787c7e;
    color: #fff;
    border-color: #787c7e;
}

.tile.selected,
.current-input {
    border-color: #6adb75 !important;
    box-shadow: 0 0 5px #6adb75;
}

/* ============================================
   Keyboard Key Styles
   ============================================ */

.key-tile,
.enter-key-tile,
.backspace-key-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    min-width: 32px;
    padding: 10px 8px;
    margin: 3px 2px;
    border-radius: 8px;
    background-color: #e5e7eb;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-sizing: border-box;
    color: #1f2937;
    touch-action: none;
    /* Disable all touch gestures to enable dragging */
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.08s ease, background-color 0.08s ease;
}

/* Touch feedback for keyboard keys */
.key-tile:active,
.enter-key-tile:active,
.backspace-key-tile:active {
    transform: scale(0.92);
    background-color: #d1d5db;
}

.dark .key-tile,
.dark .enter-key-tile,
.dark .backspace-key-tile {
    background-color: #475569;
    color: #f1f5f9;
}

.dark .key-tile:active,
.dark .enter-key-tile:active,
.dark .backspace-key-tile:active {
    background-color: #334155;
}


.key-tile.correct,
.enter-key-tile.correct,
.backspace-key-tile.correct,
.dark .key-tile.correct,
.dark .enter-key-tile.correct,
.dark .backspace-key-tile.correct {
    background-color: #6aaa64;
    color: #fff;
}

.rebours-mode .tile.correct,
.dark .rebours-mode .tile.correct {
    background-color: #e11d48;
    border-color: #e11d48;
}

.rebours-mode .key-tile.correct,
.rebours-mode .enter-key-tile.correct,
.rebours-mode .backspace-key-tile.correct,
.dark .rebours-mode .key-tile.correct,
.dark .rebours-mode .enter-key-tile.correct,
.dark .rebours-mode .backspace-key-tile.correct {
    background-color: #e11d48;
}

.key-disabled,
.dark .key-disabled {
    background-color: #bbb !important;
    color: #fff !important;
    opacity: 0.6;
    cursor: not-allowed !important;
}

.dark .key-disabled {
    background-color: #475569 !important;
    color: #94a3b8 !important;
    opacity: 0.5;
}

.key-tile.present,
.enter-key-tile.present,
.backspace-key-tile.present,
.dark .key-tile.present,
.dark .enter-key-tile.present,
.dark .backspace-key-tile.present {
    background-color: #c9b458;
    color: #fff;
}

.key-tile.absent,
.enter-key-tile.absent,
.backspace-key-tile.absent,
.dark .key-tile.absent,
.dark .enter-key-tile.absent,
.dark .backspace-key-tile.absent {
    background-color: #787c7e;
    color: #fff;
}

.floating-key {
    position: absolute;
    z-index: 1000;
    width: 35px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    pointer-events: none;
    background-color: #eee;
    border-radius: 5px;
    font-size: 14px;
    color: #333;
    touch-action: none;
}

.dark .floating-key {
    background-color: #475569;
    color: #f1f5f9;
}

/* ============================================
   Header & Navigation Styles
   ============================================ */

.logo-style {
    font-weight: bold;
    text-align: center;
    font-size: 2rem;
}

/* ============================================
   Modal & Dialog Styles
   ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    width: 100%;
    height: 100%;
    display: none;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
    position: relative;
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid #888;
    max-width: 500px;
    width: 80%;
    border-radius: 10px;
}

.dark .modal-content {
    background-color: #1e293b;
    border-color: #334155;
    color: #f8fafc;
}

.close-button {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
}

/* ============================================
   Info Button Styles
   ============================================ */

.info-button {
    visibility: hidden;
    width: 30px;
    font-size: 24px;
    text-align: center;
    color: #333;
    background: none;
    border: none;
    cursor: pointer;
}

.info-button.visible {
    visibility: visible;
}

.info-button i {
    color: #333;
}

/* ============================================
   How to Play Section Styles - Improved
   ============================================ */

.how-to-play-button {
    transition: all 0.3s ease;
    max-width: 400px;
    margin: 0 auto;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.how-to-play-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

#guidelines-body {
    max-width: 400px;
    margin: 1rem auto 0;
    overflow: hidden;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    opacity: 0;
    border-top: 2px solid #dee2e6;
    transition: max-height 0.5s ease-in-out, opacity 0.3s ease-in-out;
}

.dark #guidelines-body {
    background-color: #1e293b;
    border-top-color: #334155;
    color: #f1f5f9;
}

.guidelines-content {
    font-size: 16px;
    line-height: 1.5;
}

.guidelines-content h3 {
    margin-top: 12px;
    margin-bottom: 8px;
    font-weight: 600;
}

.guidelines-content ul {
    margin-bottom: 12px;
}

.guidelines-content li {
    margin-bottom: 4px;
}

#guidelines-body:not(.hidden) {
    max-height: 2000px;
    opacity: 1;
}

.rotate-180 {
    transform: rotate(180deg);
}

.tile.example {
    width: 40px;
    height: 40px;
    font-size: 20px;
    margin-right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Animation Styles
   ============================================ */

.invalid-word {
    animation: shake 0.6s;
    border-color: #ff4d4d;
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }

    100% {
        transform: translateX(0);
    }
}

/* ============================================
   Responsive Design
   ============================================ */

/* Tablet and smaller screens */
@media (max-width: 600px) {

    .game-container {
        padding: 10px;
        width: 100%;
        margin: 0 auto;
    }

    #board.centered-board {
        max-width: 90%;
    }

    .tile {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    .key-tile {
        width: 28px;
        padding: 6px;
        font-size: 12px;
    }

    .enter-key-tile,
    .backspace-key-tile {
        width: 45px;
        padding: 6px;
        font-size: 12px;
    }

    .keyboard-row {
        margin-bottom: 2px;
    }

    .logo-style {
        font-size: 1.5rem;
    }

    .btn-how-to-play {
        font-size: 14px;
        padding: 10px 15px;
    }

    #how-to-play-container {
        max-width: 100%;
    }

    .how-to-play-button {
        max-width: 100%;
        font-size: 14px;
    }

    #guidelines-body {
        max-width: 100%;
    }

    .guidelines-content {
        font-size: 14px;
    }

    .guidelines-content h3 {
        font-size: 16px;
    }

    .tile.example {
        width: 35px;
        height: 35px;
        font-size: 18px;
        min-width: 35px;
    }
}

/* Mobile screens - LARGER touch targets for better usability */
@media (max-width: 600px) {

    /* Remove side margins on mobile */
    .game-bg {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .game-bg>.max-w-xl {
        max-width: 100%;
        padding: 0 !important;
    }

    #gameContainer {
        padding-left: 2px !important;
        padding-right: 2px !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-bottom: none !important;
        box-shadow: none !important;
    }

    #board.centered-board {
        max-width: 100%;
        padding: 0 4px;
    }

    .tile-row {
        max-width: 100%;
    }

    #keyboard {
        width: 100vw !important;
        max-width: 100vw !important;
        margin-left: -2px;
        /* Compensate for container padding if any */
        padding: 0 1px;
    }

    .keyboard-row {
        margin-bottom: 2px;
        width: 100%;
        gap: 2px;
        /* Use gap instead of margins */
    }

    .key-tile {
        height: 54px;
        min-width: 0;
        /* Allow shrinking */
        flex: 1;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        font-weight: 600;
        margin: 0;
        /* Remove margins, use gap */
        border-radius: 4px;
    }

    .enter-key-tile,
    .backspace-key-tile {
        height: 54px;
        min-width: 0;
        flex: 1.5;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px;
        font-weight: 700;
        margin: 0;
        /* Remove margins, use gap */
        border-radius: 4px;
    }

    /* Even stronger touch feedback on mobile */
    .key-tile:active,
    .enter-key-tile:active,
    .backspace-key-tile:active {
        transform: scale(0.88);
        background-color: #9ca3af;
    }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 400px) {
    .tile {
        width: 48px;
        height: 48px;
        font-size: 18px;
        margin: 1px;
    }

    .key-tile {
        height: 50px;
        min-width: 24px;
        font-size: 16px;
        margin: 1px;
    }

    .enter-key-tile,
    .backspace-key-tile {
        height: 50px;
        min-width: 44px;
        font-size: 12px;
        margin: 1px;
    }

    .logo-style {
        font-size: 1.2rem;
    }

    .guidelines-content {
        font-size: 13px;
    }

    .guidelines-content h3 {
        font-size: 15px;
    }

    .tile.example {
        width: 30px;
        height: 30px;
        font-size: 16px;
        min-width: 30px;
    }

    #guidelines-body .p-4 {
        padding: 12px 10px;
    }

    .guidelines-content ul {
        padding-left: 16px;
    }

    .guidelines-content .space-y-2 {
        margin-top: 8px;
    }
}