:root {
    --bg-color: #1a0533;
    --primary-color: #a855f7;
    --secondary-color: #f97316;
    --accent-color: #facc15;
    --text-color: #f3e8ff;
    --success-color: #4ade80;
    --error-color: #f87171;
    --card-bg: #2d1b4e;
    --card-border: #7c3aed;
    --slot-empty-color: rgba(168, 85, 247, 0.25);
    --font-main: 'Nunito', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    background-image:
        radial-gradient(ellipse at top left, rgba(168, 85, 247, 0.25) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(249, 115, 22, 0.2) 0%, transparent 50%);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ============================
   GAME CONTAINER
   ============================ */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    width: 100%;
    max-width: 700px;
    height: 100%;
    padding: 16px 20px;
    position: relative;
}

/* ============================
   BACK BUTTON
   ============================ */
.back-button {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #2F3542;
    font-size: 1.2rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    background: rgba(255, 255, 255, 0.6);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    backdrop-filter: blur(5px);
    transition: all 0.3s;
    z-index: 10;
}

.back-button:active {
    transform: scale(0.95);
}

.back-button.disabled {
    opacity: 0.8;
    background: rgba(220, 220, 220, 0.4);
    color: #747d8c;
    box-shadow: none;
}

/* ============================
   SCORE DISPLAY
   ============================ */
.score-display {
    position: absolute;
    top: 12px;
    right: 16px;
    display: flex;
    gap: 4px;
    align-items: center;
    min-height: 36px;
    flex-wrap: wrap;
    max-width: 60%;
    justify-content: flex-end;
}

.star {
    font-size: 1.6rem;
    animation: star-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
    line-height: 1;
}

.star-half {
    font-size: 1.6rem;
    animation: star-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
    line-height: 1;
    filter: grayscale(0.5);
}

@keyframes star-pop {
    0% { transform: scale(0) rotate(-20deg); opacity: 0; }
    70% { transform: scale(1.3) rotate(10deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ============================
   EMOJI DISPLAY
   ============================ */
.emoji-display {
    font-size: 7rem;
    filter: drop-shadow(0 6px 12px rgba(168, 85, 247, 0.4));
    animation: float 3s ease-in-out infinite;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2rem;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ============================
   WORD DISPLAY — SYLLABLE SLOTS
   ============================ */
.word-display {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    min-height: 70px;
    align-items: center;
}

.syllable-slot {
    min-width: 70px;
    padding: 4px 10px;
    height: 68px;
    border-radius: 12px;
    border: 3px dashed rgba(168, 85, 247, 0.5);
    background: var(--slot-empty-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 900;
    color: transparent;
    text-transform: uppercase;
    transition: all 0.3s ease;
    letter-spacing: 2px;
}

.syllable-slot.filled {
    background: rgba(74, 222, 128, 0.15);
    border: 3px solid var(--success-color);
    color: var(--success-color);
    animation: slot-fill 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slot-fill {
    0% { transform: scale(0.7); opacity: 0.4; }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Merge Animation Styles --- */
.word-display {
    position: relative; /* Needed for absolute positioning of merged word */
}

.syllable-slot.slot-hide {
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s ease-in;
}

.merged-word {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    background: var(--card-bg);
    border: 4px solid var(--success-color);
    border-radius: 24px;
    padding: 10px 30px;
    font-size: 3rem;
    font-weight: 900;
    color: var(--success-color);
    box-shadow: 0 8px 0 #15803d, 0 10px 25px rgba(0,0,0,0.4);
    letter-spacing: 4px;
    text-transform: uppercase;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

.merged-word.show {
    animation: 
        merge-pop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
        glow-pulse 1s ease-in-out 0.6s infinite alternate;
}

@keyframes merge-pop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; box-shadow: 0 8px 0 #15803d, 0 10px 25px rgba(0,0,0,0.4); }
    60% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; box-shadow: 0 8px 0 #15803d, 0 10px 25px rgba(0,0,0,0.4), 0 0 45px var(--accent-color); text-shadow: 0 0 15px var(--accent-color); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; box-shadow: 0 8px 0 #15803d, 0 10px 25px rgba(0,0,0,0.4), 0 0 20px var(--accent-color); }
}

@keyframes glow-pulse {
    0% { 
        box-shadow: 0 8px 0 #15803d, 0 10px 25px rgba(0,0,0,0.4), 0 0 20px var(--accent-color);
        text-shadow: 0 0 4px var(--accent-color);
        transform: translate(-50%, -50%) scale(1);
    }
    100% { 
        box-shadow: 0 8px 0 #15803d, 0 10px 25px rgba(0,0,0,0.4), 0 0 60px var(--accent-color), 0 0 90px var(--accent-color);
        text-shadow: 0 0 15px var(--accent-color), 0 0 22px #ffffff;
        transform: translate(-50%, -50%) scale(1.06);
    }
}

/* ============================
   SYLLABLE CARDS
   ============================ */
.syllable-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    align-items: center;
    padding: 10px 0;
    width: 100%;
}

.syllable-card {
    background: var(--card-bg);
    border: 3px solid var(--card-border);
    border-radius: 18px;
    min-width: 90px;
    padding: 10px 18px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--text-color);
    cursor: pointer;
    box-shadow: 0 6px 0 #5b21b6, 0 8px 20px rgba(0,0,0,0.3);
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.2s;
    letter-spacing: 2px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

.syllable-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 60%);
    border-radius: 15px;
    pointer-events: none;
}

.syllable-card:active,
.syllable-card.pressing {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #5b21b6, 0 4px 10px rgba(0,0,0,0.3);
}

.syllable-card:hover {
    border-color: var(--primary-color);
    background: #3d2060;
}

.syllable-card.correct-flash {
    background: rgba(74, 222, 128, 0.3);
    border-color: var(--success-color);
    box-shadow: 0 6px 0 #15803d, 0 0 24px rgba(74,222,128,0.5);
    color: var(--success-color);
}

.syllable-card.used {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
    transition: all 0.3s ease;
}

.syllable-card.wrong-flash {
    animation: card-shake 0.45s ease-in-out;
    background: rgba(248, 113, 113, 0.25);
    border-color: var(--error-color);
    color: var(--error-color);
}

.syllable-card.penalty {
    border-color: var(--error-color);
    background: rgba(248, 113, 113, 0.15);
    color: transparent; /* Hide original text */
}

/* overlay the penalty seconds */
.syllable-card.penalty::after {
    content: attr(data-penalty);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 900;
    color: var(--error-color);
    text-shadow: 0 0 10px rgba(248, 113, 113, 0.5);
    animation: penalty-pulse 1s infinite;
}

@keyframes penalty-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.penalty-backdrop {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
    background: rgba(89, 33, 182, 0.15); /* Very subtle purple tint to indicate block */
}

.penalty-backdrop.hidden {
    display: none;
}

@keyframes card-shake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-8px) rotate(-2deg); }
    40% { transform: translateX(8px) rotate(2deg); }
    65% { transform: translateX(-6px) rotate(-1deg); }
    85% { transform: translateX(4px); }
}

/* ============================
   POP-IN ANIMATION (for emoji)
   ============================ */
.pop-in {
    animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes pop-in {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ============================
   CONFETTI
   ============================ */
.confetti {
    position: fixed;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    animation: fall 4s linear forwards;
    z-index: 200;
    top: -14px;
}

@keyframes fall {
    0% { transform: translateY(-14px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* ============================
   RESPONSIVE — PORTRAIT PHONE
   ============================ */
@media (max-width: 480px) {
    .emoji-display { 
        font-size: 5rem; 
        min-height: 80px; 
        margin-top: 3.5rem; 
    }

    .syllable-slot {
        min-width: 50px;
        height: 50px;
        font-size: 1.5rem;
        padding: 4px;
    }

    .syllable-card {
        min-width: 65px;
        height: 60px;
        font-size: 1.5rem;
        padding: 6px 10px;
    }

    .back-button {
        font-size: 1rem;
        padding: 0.4rem 0.8rem;
        top: 12px;
        left: 12px;
    }

    .score-display {
        top: 12px;
        right: 12px;
    }

    .star, .star-half {
        font-size: 1.2rem;
    }
}

/* ============================
   RESPONSIVE — LANDSCAPE SHORT
   ============================ */
@media (max-height: 620px) and (orientation: landscape) {
    .game-container {
        padding: 8px 16px;
        justify-content: space-around;
    }

    .emoji-display {
        font-size: 4.5rem;
        min-height: 80px;
        margin-top: 1rem;
    }

    .syllable-slot {
        height: 54px;
        font-size: 1.8rem;
    }

    .syllable-card {
        height: 62px;
        font-size: 1.8rem;
        min-width: 78px;
    }

    .score-display { top: 6px; }
    .back-button { top: 6px; }
}
