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

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, #dfe6e9 0%, #b2bec3 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;
}

/* === Card area === */
#card-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

/* === Active card (3D flip) === */
#active-card {
    width: 280px;
    height: 160px;
    perspective: 600px;
}

#card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}

#card-inner.flipped {
    transform: rotateY(180deg);
}

#card-front,
#card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

#card-front {
    background: #ffffff;
}

#card-back {
    background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
    transform: rotateY(180deg);
}

#card-word {
    font-size: 2.8rem;
    font-weight: 800;
    color: #2d3436;
    letter-spacing: 4px;
    text-align: center;
}

#card-emoji {
    font-size: 3rem;
    text-align: center;
    font-weight: 700;
}

/* Pulse hint for card word when wrong key pressed */
.pulse-hint {
    animation: pulse-hint-anim 0.6s ease;
}

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

.letter-box {
    width: 52px;
    height: 60px;
    border: 3px solid #b2bec3;
    border-radius: 12px;
    background: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 800;
    color: #2d3436;
    transition: border-color 0.2s, background 0.2s;
}

.letter-box.filled {
    background: #00b894;
    color: #ffffff;
    border-color: #00b894;
    animation: pop-in 0.2s ease;
}

/* Wrong answer: gentle fade instead of shake */
.letter-box.wrong-flash {
    color: #b2bec3;
    border-color: #dfe6e9;
    opacity: 0.4;
    transition: opacity 0.4s;
}

/* === On-screen keyboard === */
#keyboard {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 0;
}

.key-btn {
    min-width: 48px;
    min-height: 48px;
    border: 2px solid #b2bec3;
    border-radius: 10px;
    background: #ffffff;
    font-size: 1.4rem;
    font-weight: 700;
    color: #2d3436;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.key-btn:active {
    transform: scale(0.93);
}

.key-btn:focus-visible {
    outline: 3px solid #0984e3;
    outline-offset: 2px;
}

.key-btn.key-correct {
    background: #00b894;
    color: #ffffff;
    border-color: #00b894;
}

.key-btn.key-wrong {
    opacity: 0.4;
    border-color: #dfe6e9;
}

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

@keyframes pulse-hint-anim {
    0% { transform: scale(1); color: #2d3436; }
    50% { transform: scale(1.08); color: #0984e3; }
    100% { transform: scale(1); color: #2d3436; }
}

@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; }
}

/* === Card shrink-to-ribbon animation === */
#active-card.shrink-to-ribbon {
    animation: shrink-to-ribbon 0.5s ease-in forwards;
}

@keyframes shrink-to-ribbon {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.3) translateY(-80px); opacity: 0; }
}

/* === 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;
}

/* === 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;
}

/* === Hidden mobile input === */
#mobile-input {
    position: fixed;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    font-size: 16px; /* prevents iOS zoom */
}

/* === Penguin === */
#penguin {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 80px;
    height: 100px;
    z-index: 50;
}

.penguin-body {
    position: relative;
    width: 60px;
    height: 70px;
    background: #2d3436;
    border-radius: 30px 30px 20px 20px;
    margin: 0 auto;
}

.penguin-belly {
    position: absolute;
    width: 44px;
    height: 50px;
    background: #ffffff;
    border-radius: 50%;
    left: 50%;
    transform: translateX(-50%);
    top: 14px;
}

.penguin-eye {
    position: absolute;
    width: 10px;
    height: 12px;
    background: #ffffff;
    border-radius: 50%;
    top: 18px;
}

.penguin-eye.left {
    left: 16px;
}

.penguin-eye.right {
    right: 16px;
}

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

.penguin-beak {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 28px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid #e67e22;
}

.penguin-wing {
    position: absolute;
    width: 14px;
    height: 30px;
    background: #2d3436;
    border-radius: 50%;
    top: 30px;
}

.penguin-wing.left {
    left: -4px;
}

.penguin-wing.right {
    right: -4px;
}

.penguin-foot {
    position: absolute;
    width: 16px;
    height: 8px;
    background: #e67e22;
    border-radius: 50%;
    bottom: -5px;
}

.penguin-foot.left {
    left: 12px;
}

.penguin-foot.right {
    right: 12px;
}

/* --- Penguin state animations --- */
#penguin.idle .penguin-body {
    animation: penguin-idle 3s ease-in-out infinite;
}

#penguin.idle .penguin-foot.right {
    animation: foot-tap 2s ease-in-out infinite;
}

#penguin.typing .penguin-body {
    animation: penguin-hop 0.3s ease;
}

#penguin.celebrate-word .penguin-body {
    animation: penguin-dance 0.8s ease;
}

#penguin.celebrate-word .penguin-wing.left,
#penguin.celebrate-verse .penguin-wing.left {
    animation: wing-flap-left 0.4s ease infinite;
}

#penguin.celebrate-word .penguin-wing.right,
#penguin.celebrate-verse .penguin-wing.right {
    animation: wing-flap-right 0.4s ease infinite;
}

#penguin.celebrate-verse .penguin-body {
    animation: penguin-big-celebrate 1.2s ease;
}

@keyframes penguin-idle {
    0%, 100% { transform: rotate(0deg) translateY(0); }
    50% { transform: rotate(2deg) translateY(-2px); }
}

@keyframes foot-tap {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.7); }
}

@keyframes penguin-hop {
    0% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
    100% { transform: translateY(0); }
}

@keyframes penguin-dance {
    0% { transform: rotate(0deg) translateY(0); }
    25% { transform: rotate(10deg) translateY(-8px); }
    50% { transform: rotate(-10deg) translateY(-4px); }
    75% { transform: rotate(5deg) translateY(-10px); }
    100% { transform: rotate(0deg) translateY(0); }
}

@keyframes penguin-big-celebrate {
    0% { transform: rotate(0deg) translateY(0) scale(1); }
    20% { transform: rotate(10deg) translateY(-15px) scale(1.15); }
    40% { transform: rotate(-10deg) translateY(-8px) scale(1.1); }
    60% { transform: rotate(8deg) translateY(-18px) scale(1.15); }
    80% { transform: rotate(-5deg) translateY(-6px) scale(1.05); }
    100% { transform: rotate(0deg) translateY(0) scale(1); }
}

@keyframes wing-flap-left {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-30deg); }
}

@keyframes wing-flap-right {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(30deg); }
}

/* === Title screen === */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    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-penguin {
    font-size: 4rem;
    animation: penguin-idle 3s ease-in-out infinite;
}

#start-btn {
    background: #ffffff;
    color: #0984e3;
    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: #0984e3;
    margin-bottom: 24px;
    line-height: 1.3;
}

.btn-primary {
    background: #0984e3;
    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);
}

/* === Responsive (small screens) === */
@media (max-width: 400px) {
    .letter-box {
        width: 40px;
        height: 48px;
        font-size: 1.5rem;
    }

    #card-word {
        font-size: 2.2rem;
    }

    #active-card {
        width: 220px;
        height: 130px;
    }

    #penguin {
        width: 60px;
        height: 75px;
    }

    .penguin-body {
        width: 45px;
        height: 53px;
    }

    .penguin-belly {
        width: 33px;
        height: 38px;
    }
}

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

    #active-card {
        width: 160px;
        height: 80px;
    }

    #card-word {
        font-size: 1.6rem;
        letter-spacing: 2px;
    }

    .letter-box {
        width: 32px;
        height: 38px;
        font-size: 1.2rem;
        border-width: 2px;
    }

    #keyboard {
        gap: 4px;
        padding: 4px 0;
    }

    .key-btn {
        min-width: 34px;
        min-height: 34px;
        font-size: 1rem;
    }

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

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

    header {
        padding: 0;
    }

    #penguin {
        display: none;
    }
}
