/* === Reset === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    --bg-start: #e8f5e9;
    --bg-end: #c8e6c9;
    background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    position: relative;
}

.hidden {
    display: none !important;
}

/* === Header === */
header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
}

#back-btn {
    background: rgba(255, 255, 255, 0.5);
    border: none;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 1rem;
    color: #2d3436;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s;
}

#back-btn:hover {
    background: rgba(255, 255, 255, 0.8);
}

#star-area {
    font-size: 1.4rem;
}

/* === Verse display (full verse shown on top) === */
#verse-display {
    width: 100%;
    text-align: center;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #455a64;
    line-height: 1.5;
    min-height: 24px;
}

#verse-display .verse-ref {
    display: block;
    font-size: 0.85rem;
    font-style: italic;
    color: #78909c;
    margin-top: 4px;
    font-weight: 400;
}

#verse-display .verse-word {
    display: inline;
}

#verse-display .verse-word.done {
    color: #4caf50;
}

#verse-display .verse-word.current {
    color: #2d3436;
    text-decoration: underline;
    text-decoration-color: #f9a825;
    text-underline-offset: 3px;
}

#verse-display .verse-word.upcoming {
    color: #b0bec5;
}

/* === Play area === */
#play-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
}

/* === Verse ribbon === */
#verse-ribbon {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    width: 100%;
    padding: 4px 0;
}

.ribbon-word {
    background: rgba(255, 255, 255, 0.7);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: #2d3436;
    animation: float-up 0.4s ease;
}

/* === Animations === */
@keyframes pop-in {
    0% { transform: scale(0.8); }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@keyframes float-up {
    0% { transform: translateY(20px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

@keyframes bounce-in {
    0% { transform: scale(0.3); opacity: 0; }
    60% { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

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

/* === Word bloom animation === */
#dot-row.word-bloom {
    animation: word-bloom 1.0s ease forwards;
}

@keyframes word-bloom {
    0% { transform: scale(1); opacity: 1; }
    40% { transform: scale(1.15); opacity: 1; filter: brightness(1.2); }
    100% { transform: scale(0.3); opacity: 0; }
}

/* === Dot slots === */
#dot-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 70px;
}

.dot-slot {
    width: 56px;
    height: 56px;
    border: 3px dashed #c8b89a;
    border-radius: 50%;
    background: #F5E6D3;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 800;
    color: #2d3436;
    position: relative;
    transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.dot-slot .dot-indicator {
    width: 10px;
    height: 10px;
    background: #c8b89a;
    border-radius: 50%;
}

.dot-slot.guided {
    border-color: #f9a825;
    animation: guided-glow 1.5s ease-in-out infinite;
}

.dot-slot.filled {
    background: #90EE90;
    border-style: solid;
    border-color: #66bb6a;
    animation: pop-in 0.3s ease;
}

.dot-slot.filled .dot-indicator {
    display: none;
}

.dot-slot.hover-over {
    transform: scale(1.08);
    border-color: #66bb6a;
}

.dot-slot.reject-pulse {
    animation: reject-pulse 0.5s ease;
}

@keyframes guided-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(249, 168, 37, 0); }
    50% { box-shadow: 0 0 12px 4px rgba(249, 168, 37, 0.4); }
}

@keyframes reject-pulse {
    0%, 100% { background: #F5E6D3; }
    50% { background: #ffe0b2; }
}

/* === Letter tray === */
#letter-tray {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 70px;
    padding: 8px;
}

.letter-tile {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 800;
    color: #2d3436;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.letter-tile:active { cursor: grabbing; }

.letter-tile.dragging {
    transform: scale(1.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    opacity: 0.85;
    z-index: 1000;
    position: fixed;
    pointer-events: none;
}

.letter-tile.placed { display: none; }

.letter-tile.selected {
    border: 3px solid #f9a825;
    box-shadow: 0 0 12px rgba(249, 168, 37, 0.5);
    transform: scale(1.05);
}

/* === Verse complete overlay === */
#verse-complete-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    background: rgba(0, 0, 0, 0.4);
}

#verse-complete-content {
    background: #ffffff;
    border-radius: 30px;
    padding: 40px;
    text-align: center;
    max-width: 420px;
    animation: bounce-in 0.4s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

#verse-complete-text {
    font-size: 1.6rem;
    font-weight: 700;
    color: #2d3436;
    margin-bottom: 12px;
    line-height: 1.4;
}

#verse-complete-ref {
    font-size: 1.1rem;
    font-style: italic;
    color: #636e72;
}

/* === Confetti === */
#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 99;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    animation: confetti-fall 2s ease-in forwards;
}

/* === Title screen === */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #81c784, #4caf50);
    z-index: 200;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 30px;
}

#title-screen h1 {
    color: #ffffff;
    font-size: 3rem;
    font-weight: 800;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#title-pig {
    font-size: 4rem;
    animation: pig-idle-body 3s ease-in-out infinite;
}

#start-btn {
    background: #ffffff;
    color: #4caf50;
    border: none;
    padding: 16px 48px;
    font-size: 1.6rem;
    font-weight: 700;
    border-radius: 24px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

#start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

#start-btn:active {
    transform: scale(0.98);
}

/* === Break overlay === */
.break-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}

.break-content {
    background: #ffffff;
    border-radius: 30px;
    padding: 40px;
    text-align: center;
    max-width: 380px;
    animation: bounce-in 0.4s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.break-character {
    font-size: 4rem;
    margin-bottom: 16px;
}

.break-message {
    font-size: 1.5rem;
    font-weight: 600;
    color: #4caf50;
    margin-bottom: 24px;
    line-height: 1.3;
}

.btn-primary {
    background: #4caf50;
    color: #ffffff;
    border: none;
    padding: 14px 36px;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-primary:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* ====================== */
/* === Pig Character  === */
/* ====================== */

#pig {
    position: fixed;
    top: 80px;
    right: 20px;
    width: 110px;
    height: 130px;
    z-index: 50;
}

.pig-body {
    position: relative;
    width: 75px;
    height: 80px;
    background: #FFB6C1;
    border-radius: 50% / 45%;
    margin: 0 auto;
    margin-top: 35px;
}

.pig-head {
    position: absolute;
    width: 65px;
    height: 58px;
    background: #FFB6C1;
    border-radius: 50%;
    top: -38px;
    left: 50%;
    transform: translateX(-50%);
}

/* --- Ears --- */
.pig-ear {
    position: absolute;
    width: 18px;
    height: 20px;
    background: #FF69B4;
    border-radius: 50% 50% 0 0;
    top: -8px;
}

.pig-ear.left {
    left: 2px;
    transform: rotate(-15deg);
}

.pig-ear.right {
    right: 2px;
    transform: rotate(15deg);
}

/* --- Eyes --- */
.pig-eye {
    position: absolute;
    width: 10px;
    height: 12px;
    background: #ffffff;
    border-radius: 50%;
    top: 12px;
}

.pig-eye.left {
    left: 10px;
}

.pig-eye.right {
    right: 10px;
}

.pig-pupil {
    width: 5px;
    height: 5px;
    background: #2d3436;
    border-radius: 50%;
    margin: 3px auto 0;
}

/* --- Snout --- */
.pig-snout {
    position: absolute;
    width: 22px;
    height: 16px;
    background: #FF99AA;
    border-radius: 50%;
    left: 50%;
    transform: translateX(-50%);
    top: 22px;
}

.pig-nostril {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #c44569;
    border-radius: 50%;
    top: 6px;
}

.pig-nostril.left {
    left: 4px;
}

.pig-nostril.right {
    right: 4px;
}

/* --- Cheeks --- */
.pig-cheek {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #FF99AA;
    border-radius: 50%;
    top: 28px;
    opacity: 0.6;
}

.pig-cheek.left {
    left: 3px;
}

.pig-cheek.right {
    right: 3px;
}

/* --- Legs --- */
.pig-leg {
    position: absolute;
    width: 12px;
    height: 16px;
    background: #FFB6C1;
    border-radius: 4px 4px 6px 6px;
    bottom: -12px;
}

.pig-leg.front-left {
    left: 8px;
}

.pig-leg.front-right {
    left: 22px;
}

.pig-leg.back-left {
    right: 22px;
}

.pig-leg.back-right {
    right: 8px;
}

/* --- Tail --- */
.pig-tail {
    position: absolute;
    width: 12px;
    height: 12px;
    border: 3px solid #FF69B4;
    border-radius: 50%;
    border-bottom-color: transparent;
    border-left-color: transparent;
    right: -8px;
    top: 20px;
    transform: rotate(-30deg);
}

/* ================================ */
/* === Pig Animation States    === */
/* ================================ */

/* --- Idle --- */
#pig.idle .pig-body {
    animation: pig-idle-body 3s ease-in-out infinite;
}

#pig.idle .pig-tail {
    animation: pig-idle-tail 2.5s ease-in-out infinite;
}

@keyframes pig-idle-body {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes pig-idle-tail {
    0%, 100% { transform: rotate(-30deg); }
    50% { transform: rotate(-15deg); }
}

/* --- Correct --- */
#pig.correct .pig-body {
    animation: pig-correct-body 0.4s ease;
}

#pig.correct .pig-ear {
    animation: pig-correct-ear 0.4s ease;
}

@keyframes pig-correct-body {
    0% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
    100% { transform: translateY(0); }
}

@keyframes pig-correct-ear {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(-10deg); }
    100% { transform: rotate(0deg); }
}

/* --- Wrong --- */
#pig.wrong .pig-head {
    animation: pig-wrong-head 0.5s ease;
}

@keyframes pig-wrong-head {
    0% { transform: translateX(-50%) rotate(0deg); }
    30% { transform: translateX(-50%) rotate(12deg); }
    70% { transform: translateX(-50%) rotate(-5deg); }
    100% { transform: translateX(-50%) rotate(0deg); }
}

/* --- Celebrate word --- */
#pig.celebrate-word .pig-body {
    animation: pig-celebrate-word-body 0.8s ease;
}

#pig.celebrate-word .pig-ear {
    animation: pig-celebrate-word-ear 0.3s ease infinite;
}

@keyframes pig-celebrate-word-body {
    0% { transform: rotate(0deg) translateY(0); }
    25% { transform: rotate(8deg) translateY(-10px); }
    50% { transform: rotate(-8deg) translateY(-5px); }
    75% { transform: rotate(4deg) translateY(-12px); }
    100% { transform: rotate(0deg) translateY(0); }
}

@keyframes pig-celebrate-word-ear {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-15deg); }
}

/* --- Celebrate verse --- */
#pig.celebrate-verse .pig-body {
    animation: pig-celebrate-verse-body 1.2s ease;
}

#pig.celebrate-verse .pig-tail {
    animation: pig-celebrate-verse-tail 0.2s ease-in-out infinite;
}

@keyframes pig-celebrate-verse-body {
    0% { transform: rotate(0deg) translateY(0) scale(1); }
    20% { transform: rotate(15deg) translateY(-20px) scale(1.15); }
    40% { transform: rotate(-15deg) translateY(-10px) scale(1.1); }
    60% { transform: rotate(10deg) translateY(-25px) scale(1.15); }
    80% { transform: rotate(-8deg) translateY(-8px) scale(1.05); }
    100% { transform: rotate(0deg) translateY(0) scale(1); }
}

@keyframes pig-celebrate-verse-tail {
    0%, 100% { transform: rotate(-30deg); }
    50% { transform: rotate(10deg); }
}

/* === Responsive (small screens) === */
@media (max-width: 400px) {
    #pig {
        width: 80px;
        height: 100px;
    }

    .pig-body {
        width: 55px;
        height: 60px;
    }

    .pig-head {
        width: 50px;
        height: 45px;
        top: -30px;
    }

    #verse-display { font-size: 0.95rem; padding: 6px 10px; }
    .dot-slot { width: 44px; height: 44px; font-size: 1.5rem; }
    .letter-tile { width: 44px; height: 44px; font-size: 1.5rem; }
}

/* === Compact layout for short viewports (landscape phones) === */
@media (max-height: 500px) {
    #game-container {
        gap: 4px;
        padding: 6px;
    }

    #verse-display { font-size: 0.85rem; padding: 4px 8px; }

    #verse-ribbon {
        min-height: 24px;
    }

    .ribbon-word {
        font-size: 0.8rem;
        padding: 2px 6px;
    }

    header {
        padding: 0;
    }

    #pig {
        display: none;
    }

    .dot-slot { width: 36px; height: 36px; font-size: 1.2rem; }
    .letter-tile { width: 36px; height: 36px; font-size: 1.2rem; }
}
