body {
    font-family: 'Fredoka', sans-serif;
    background-color: #f0f8ff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.game-container {
    text-align: center;
    background-color: white;
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    max-width: 95%;
    /* Use more width on mobile/tablet */
    width: 650px;
    /* Slightly wider for long words */
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* --- HEADER --- */
.header-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    /* Left - Center - Right */
    align-items: center;
    margin-bottom: 0.5rem;
    position: relative;
}

/* Left Column (Settings) */
.header-left {
    justify-self: start;
    z-index: 2;
}

/* Center Column (Title) */
.title {
    grid-column: 2;
    color: #ffb7b2;
    font-size: 1.8rem;
    margin: 0;
    white-space: nowrap;
    z-index: 1;
}

/* Right Column (Toggles) */
.header-right {
    justify-self: end;
    z-index: 2;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s;
    padding: 10px;
    border-radius: 50%;
}

.icon-btn:hover {
    background-color: #f0f0f0;
    transform: scale(1.1);
}

/* --- STAGE (Emoji & Nav) --- */
.emoji-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 150px;
    /* Prevent jumpiness */
}

.emoji {
    font-size: 8rem;
    animation: bounce 2s infinite;
}

.nav-btn {
    background: none;
    border: none;
    font-size: 3rem;
    cursor: pointer;
    color: #4ecdc4;
    transition: transform 0.2s, color 0.2s;
    padding: 0 10px;
    /* Absolute positioning for clean separation */
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

#prev-btn {
    left: 0;
}

#next-word-btn {
    right: 0;
}

.nav-btn:hover {
    color: #ff6b6b;
    transform: scale(1.2);
}

.speaker-btn {
    font-size: 2rem;
    margin: -1rem auto 1rem;
    /* Pull up slightly */
    display: block;
}

/* --- GAME AREA (Slots & Tiles) --- */
.game-area-row {
    /* Removed the weird side-by-side flex layout */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 2rem;
}

.word-row-container {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.word-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    /* Allow wrapping for long words */
    max-width: 100%;
}

/* Reset Button - Positioned nicely next to the Word */
#reset-tiles-btn {
    font-size: 1.2rem;
    padding: 8px;
    background: #f0f0f0;
    border-radius: 50%;
    margin-left: 15px;
    /* Spacing from word */
    align-self: center;
    cursor: pointer;
    /* No absolute positioning! */
}

.letter-box {
    width: 60px;
    height: 80px;
    border: 3px solid #4ecdc4;
    border-radius: 12px;
    font-size: 2.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
    background-color: #f7fff7;
    transition: transform 0.2s, background-color 0.2s;
    user-select: none;
}

.letter-box.filled {
    background-color: #ffe66d;
    transform: scale(1.05);
    border-color: #ff6b6b;
}

.letter-box.active {
    border-color: #ff6b6b;
    box-shadow: 0 0 10px #ff6b6b;
}

.message {
    font-size: 2rem;
    color: #4ecdc4;
    margin-bottom: 1rem;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hidden {
    display: none !important;
}

.next-btn {
    background-color: #ff6b6b;
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.5rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    transition: transform 0.2s, background-color 0.2s;
}

.next-btn:hover {
    background-color: #ff5252;
    transform: scale(1.05);
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #aaa;
}

.close-btn:hover {
    color: #ff6b6b;
}

.setting-item {
    margin: 1rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2rem;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-20px);
    }

    60% {
        transform: translateY(-10px);
    }
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- TILE MODE --- */
.tile-pool {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    /* Important for long words! */
    min-height: 80px;
    width: 100%;
}

.tile {
    width: 60px;
    height: 80px;
    background-color: #ffd93d;
    border: 3px solid #ff6b6b;
    border-radius: 10px;
    font-size: 3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.tile:hover {
    transform: scale(1.1) translateY(-5px);
    background-color: #ffc107;
}

.tile.used {
    background-color: #e0e0e0;
    border-color: #ccc;
    color: #aaa;
    pointer-events: none;
    opacity: 0.5;
    transform: scale(0.9);
    box-shadow: none;
}

/* Update letter-box for tile mode */
.letter-box.tile-mode {
    cursor: pointer;
}

.letter-box.tile-mode:hover {
    background-color: #ffe66d;
}

.letter-box.empty-slot {
    border-style: dashed;
    background-color: #fafafa;
}

/* Toggle Switch Styling */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8f9fa;
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid #eee;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    -webkit-transition: .4s;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
}

input:checked+.slider {
    background-color: #4ecdc4;
}

input:focus+.slider {
    box-shadow: 0 0 1px #4ecdc4;
}

input:checked+.slider:before {
    -webkit-transform: translateX(22px);
    -ms-transform: translateX(22px);
    transform: translateX(22px);
}

/* Rounded sliders */
.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* --- RESPONSIVE DESIGN --- */

/* Tablet & Smaller Laptops */
@media (max-width: 900px) {
    .game-container {
        width: 95%;
        padding: 1.5rem;
    }

    .emoji {
        font-size: 6rem;
    }

    .letter-box,
    .tile {
        width: 50px;
        height: 70px;
        font-size: 2.5rem;
    }
}

/* Mobile Devices - App Layout */
@media (max-width: 600px) {
    body {
        overscroll-behavior-y: none;
        height: 100vh;
        width: 100vw;
        position: fixed;
        overflow: hidden;
        /* Prevent body scroll */
        background-color: #ffffff;
        /* Cleaner background */
    }

    .game-container {
        padding: 5px 10px;
        width: 100%;
        height: 100%;
        max-width: 100%;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        /* Spread content out */
    }

    /* 1. Header: Minimalist Top Bar */
    .header-controls {
        flex: 0 0 auto;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 5px 0;
        border-bottom: 0px solid transparent;
        margin-bottom: 5px;
        opacity: 0.8;
        z-index: 10;
        position: relative;
        /* For absolute title */
    }

    .title {
        font-size: 1.4rem;
        margin: 0;
        position: absolute;
        left: 0;
        right: 0;
        text-align: center;
        pointer-events: none;
        /* Don't block clicks */
        z-index: 1;
    }

    .toggle-container {
        order: 1;
        /* Left */
        transform: scale(0.8);
        margin: 0;
        z-index: 2;
        position: relative;
    }

    #settings-btn {
        order: 2;
        /* Right */
        position: relative;
        font-size: 1.4rem;
        padding: 5px;
        z-index: 2;
    }

    /* 2. Stage: Emoji & Navigation */
    .emoji-container {
        flex: 1 1 auto;
        /* Grow to fill space */
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
        /* For absolute arrows */
        margin: 0;
        width: 100%;
    }

    .emoji {
        font-size: 8rem;
        /* Big Emoji */
        max-height: 40vh;
        /* Don't get TOO big */
        object-fit: contain;
    }

    .nav-btn {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        font-size: 3rem;
        padding: 20px;
        z-index: 20;
        opacity: 0.3;
        /* Subtle arrows */
    }

    #prev-btn {
        left: 0;
    }

    #next-btn {
        right: 0;
    }

    .nav-btn:hover {
        opacity: 1;
    }

    /* 3. Game Area: Slots & Tools */
    .game-area-row {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        /* Stack word and tools */
        gap: 10px;
        margin-bottom: 15px;
        position: relative;
    }

    .word-container {
        display: flex;
        justify-content: center;
        gap: 5px;
    }

    .letter-box,
    .tile {
        width: 50px;
        height: 65px;
        font-size: 2.2rem;
        border-radius: 12px;
        border-width: 2px;
    }

    /* Reset Button Floating near slots */
    #reset-tiles-btn {
        position: absolute;
        right: 0px;
        top: 50%;
        transform: translateY(-50%);
        background: #fff;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        z-index: 5;
    }

    /* 4. Footer: Tile Pool */
    .tile-pool {
        flex: 0 0 auto;
        /* Fixed height for tiles */
        min-height: 90px;
        background: #f4f4f4;
        border-radius: 20px;
        padding: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 8px;
        margin-bottom: 20px;
        /* Safe area padding */
        width: 100%;
        box-sizing: border-box;
    }

    .celebration-creature {
        font-size: 8rem;
    }
}

/* Landscape Mode (Short screens) */
@media (max-height: 500px) and (orientation: landscape) {
    .game-container {
        padding: 0.5rem;
    }

    .header-controls {
        margin-bottom: 0.2rem;
        display: none;
        /* Hide header in super short landscape, or make very compact */
    }

    .emoji {
        display: none;
        /* Hide emoji to save space? Or make tiny side-by-side */
    }

    .word-container {
        margin: 0.5rem 0;
    }
}

/* --- MAGIC EFFECTS --- */
.magic-sparkle {
    position: fixed;
    font-size: 2rem;
    pointer-events: none;
    z-index: 9999;
    animation: sparklePop 1s ease-out forwards;
}

@keyframes sparklePop {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.5);
        opacity: 0;
    }
}

/* --- CELEBRATION ANIMATIONS --- */
.celebration-creature {
    position: fixed;
    font-size: 15rem;
    z-index: 2000;
    pointer-events: none;
    animation: flyAcross 4s linear forwards;
    bottom: -20vh;
    left: -20vw;
}

@media (max-width: 600px) {
    .celebration-creature {
        font-size: 8rem;
    }
}

@keyframes flyAcross {
    0% {
        transform: translate(0, 0) rotate(0deg);
        left: -10vw;
        bottom: -10vh;
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    100% {
        transform: translate(120vw, -120vh) rotate(20deg);
        left: 0;
        bottom: 0;
        opacity: 1;
    }
}