:root {
    --ink: #34266f;
    --teal: #0f9f91;
    --teal-dark: #08766e;
    --teal-soft: #c9f6ee;
    --vowel: #f08b36;
    --vowel-dark: #bd5d18;
    --vowel-soft: #fff0d7;
    --cream: #fffaf0;
    --yellow: #ffe66d;
    --correct: #27ae60;
    --error: #e74c3c;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
}

body {
    font-family: 'Nunito', sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 16% 15%, rgba(255, 230, 109, 0.4) 0 8%, transparent 9%),
        radial-gradient(circle at 88% 84%, rgba(15, 159, 145, 0.16) 0 12%, transparent 13%),
        linear-gradient(145deg, #fffaf0, #f8f2ff);
    user-select: none;
    -webkit-user-select: none;
}

button {
    font: inherit;
}

.start-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
        radial-gradient(circle at 18% 18%, rgba(255, 230, 109, 0.52) 0 9%, transparent 10%),
        radial-gradient(circle at 84% 82%, rgba(15, 159, 145, 0.23) 0 14%, transparent 15%),
        linear-gradient(145deg, #fffaf0, #f8f2ff);
}

.start-overlay.is-hidden {
    display: none;
}

.start-card {
    width: min(92vw, 470px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(12px, 2.4vh, 22px);
    padding: clamp(28px, 6vh, 54px) clamp(20px, 6vw, 42px);
    border: 5px solid #fff;
    border-radius: 38px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 14px 0 rgba(8, 118, 110, 0.18), 0 28px 60px rgba(52, 38, 111, 0.18);
    text-align: center;
}

.start-icon {
    width: clamp(96px, 25vw, 138px);
    height: clamp(96px, 25vw, 138px);
    display: grid;
    place-items: center;
    border: 5px solid #fff;
    border-radius: 32px;
    color: #fff;
    background: linear-gradient(145deg, #20bfae, var(--teal-dark));
    box-shadow: 0 9px 0 rgba(8, 118, 110, 0.25), 0 16px 28px rgba(52, 38, 111, 0.14);
    font-size: clamp(3.4rem, 14vw, 5.8rem);
}

.start-card h1 {
    margin: 0;
    color: var(--ink);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(2rem, 8vw, 3.5rem);
    line-height: 1.05;
}

.start-card p {
    margin: 0;
    color: var(--teal-dark);
    font-size: clamp(1.05rem, 4.2vw, 1.4rem);
    font-weight: 900;
}

.start-button {
    min-width: min(78vw, 300px);
    min-height: 76px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 15px 28px;
    border: 5px solid #fff;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--teal), var(--teal-dark));
    box-shadow: 0 9px 0 rgba(8, 118, 110, 0.34), 0 16px 28px rgba(52, 38, 111, 0.16);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(1.35rem, 5.5vw, 1.8rem);
    letter-spacing: 0.035em;
    cursor: pointer;
    touch-action: manipulation;
}

.start-button:active {
    transform: translateY(5px);
    box-shadow: 0 4px 0 rgba(8, 118, 110, 0.34), 0 10px 20px rgba(52, 38, 111, 0.14);
}

.start-button:focus-visible {
    outline: 6px solid var(--yellow);
    outline-offset: 5px;
}

.start-button:disabled {
    opacity: 0.72;
}

.syllable-main {
    width: min(100%, 760px);
    height: 100dvh;
    min-height: 100%;
    margin: 0 auto;
    padding: clamp(82px, 11vh, 104px) 16px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: clamp(10px, 2vh, 22px);
}

.instruction {
    min-height: 50px;
    max-width: min(92vw, 520px);
    padding: 9px 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 3px solid rgba(15, 159, 145, 0.24);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.86);
    box-shadow: 0 8px 22px rgba(52, 38, 111, 0.1);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(1rem, 4vw, 1.42rem);
    letter-spacing: 0.025em;
    text-align: center;
}

.instruction-spark {
    font-size: 1.2em;
}

.blend-stage {
    position: relative;
    width: min(94vw, 560px);
    height: clamp(190px, 31vh, 285px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(12px, 4vw, 28px);
    border-radius: 36px;
    border: 3px solid rgba(15, 159, 145, 0.18);
    background: rgba(255, 255, 255, 0.66);
    box-shadow: inset 0 0 34px rgba(15, 159, 145, 0.08), 0 18px 44px rgba(52, 38, 111, 0.12);
}

.blend-card {
    width: clamp(92px, 25vw, 142px);
    height: clamp(112px, 17vh, 158px);
    display: grid;
    place-items: center;
    border-radius: 28px;
    border: 5px solid #fff;
    box-shadow: 0 10px 0 rgba(52, 38, 111, 0.16), 0 18px 30px rgba(52, 38, 111, 0.12);
    font-family: 'Fredoka One', cursive;
}

.consonant-card {
    color: #fff;
    background: linear-gradient(145deg, #20bfae, var(--teal-dark));
    font-size: clamp(4.5rem, 20vw, 8rem);
    line-height: 1;
    cursor: pointer;
}

.vowel-slot {
    color: var(--vowel-dark);
    background: repeating-linear-gradient(135deg, rgba(240, 139, 54, 0.08) 0 12px, rgba(255, 255, 255, 0.75) 12px 24px);
    border-color: rgba(240, 139, 54, 0.46);
    box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.68), 0 10px 0 rgba(52, 38, 111, 0.1);
}

.blend-plus {
    font-family: 'Fredoka One', cursive;
    font-size: clamp(2.5rem, 10vw, 4.4rem);
    color: var(--vowel);
    transition: opacity 260ms ease, transform 260ms ease;
}

.listen-card {
    display: none;
    color: #fff;
    background: linear-gradient(145deg, #20bfae, var(--teal-dark));
    font-size: clamp(3.4rem, 15vw, 6rem);
    cursor: pointer;
}

.mode-listen .consonant-card,
.mode-listen .blend-plus,
.mode-listen .vowel-slot {
    display: none;
}

.mode-listen .listen-card {
    display: grid;
}

.merged-syllable {
    position: absolute;
    inset: 50% auto auto 50%;
    width: clamp(190px, 58vw, 330px);
    height: clamp(125px, 19vh, 174px);
    display: grid;
    place-items: center;
    border: 5px solid #fff;
    border-radius: 32px;
    color: var(--ink);
    background: linear-gradient(105deg, var(--teal-soft) 0 49%, var(--vowel-soft) 51% 100%);
    box-shadow: 0 10px 0 rgba(8, 118, 110, 0.25), 0 20px 40px rgba(52, 38, 111, 0.18);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(5rem, 24vw, 9rem);
    line-height: 0.9;
    letter-spacing: 0.01em;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.55);
}

.blend-stage.is-merging .blend-plus {
    opacity: 0;
    transform: scale(0.3);
}

.blend-stage.is-merging .consonant-card,
.blend-stage.is-merging .vowel-slot,
.blend-stage.is-merging .listen-card {
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 280ms ease 560ms, transform 420ms ease 440ms;
}

.blend-stage.is-merged .merged-syllable {
    opacity: 1;
    animation: syllable-merge-pop 1100ms cubic-bezier(0.2, 0.9, 0.2, 1) both,
        syllable-glow 950ms ease-in-out 1100ms infinite alternate;
}

.flying-option {
    position: fixed;
    z-index: 40;
    margin: 0;
    pointer-events: none;
    transition: transform 760ms cubic-bezier(0.2, 0.9, 0.28, 1), opacity 200ms ease 720ms;
}

.syllable-options {
    width: min(94vw, 620px);
    min-height: clamp(96px, 16vh, 136px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(10px, 3.2vw, 24px);
}

.syllable-options.two-options {
    justify-content: space-around;
    gap: clamp(24px, 10vw, 80px);
}

.syllable-option {
    position: relative;
    width: clamp(82px, 24vw, 136px);
    min-width: 72px;
    height: clamp(88px, 14vh, 126px);
    min-height: 72px;
    display: grid;
    place-items: center;
    border: 5px solid #fff;
    border-radius: 26px;
    color: var(--vowel-dark);
    background: linear-gradient(145deg, #fff7e7, #ffd38f);
    box-shadow: 0 9px 0 rgba(189, 93, 24, 0.27), 0 15px 26px rgba(52, 38, 111, 0.13);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(3rem, 13vw, 5.5rem);
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.mode-listen + .syllable-options .syllable-option,
.syllable-options.listen-options .syllable-option {
    color: var(--ink);
    background: linear-gradient(105deg, var(--teal-soft) 0 49%, var(--vowel-soft) 51% 100%);
    box-shadow: 0 9px 0 rgba(8, 118, 110, 0.24), 0 15px 26px rgba(52, 38, 111, 0.13);
    font-size: clamp(2.8rem, 12vw, 5rem);
}

.syllable-option:focus-visible,
.blend-card:focus-visible {
    outline: 5px solid var(--yellow);
    outline-offset: 4px;
}

.syllable-option.is-correct {
    border-color: #b8f3c8;
    animation: option-correct 650ms ease both;
}

.syllable-option.is-correct::after {
    content: '✓';
    position: absolute;
    transform: translate(31px, -37px);
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--correct);
    font: 800 1.25rem/1 'Nunito', sans-serif;
}

.syllable-option.is-error {
    border-color: #ffc1bb;
    animation: option-shake 420ms ease both;
}

.syllable-option.is-error::after {
    content: '×';
    position: absolute;
    transform: translate(31px, -37px);
    color: var(--error);
    font: 900 2rem/1 'Nunito', sans-serif;
}

.syllable-option.hint-glow {
    animation: hint-glow 1.25s ease-in-out both;
}

.syllable-option:disabled {
    cursor: default;
}

.syllable-options.is-answering .syllable-option:not(.is-correct) {
    opacity: 0.28;
    transform: scale(0.9);
    transition: opacity 260ms ease, transform 260ms ease;
}

.level-badge {
    min-height: 40px;
    padding: 8px 22px;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--teal), var(--teal-dark));
    box-shadow: 0 7px 0 rgba(8, 118, 110, 0.24), 0 12px 22px rgba(52, 38, 111, 0.12);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(0.95rem, 3.7vw, 1.22rem);
    letter-spacing: 0.04em;
}

.level-badge.level-up {
    animation: level-pop 720ms ease both;
}

.reward-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(18px, 4vh, 34px);
    padding: 24px;
    color: var(--ink);
    background:
        radial-gradient(circle at center, rgba(255, 255, 255, 0.95), rgba(201, 246, 238, 0.96)),
        var(--cream);
    opacity: 1;
}

.reward-overlay.is-hidden {
    display: none;
}

.reward-emoji {
    font-size: clamp(7rem, 38vw, 14rem);
    line-height: 1;
    animation: reward-pop 760ms cubic-bezier(0.2, 1.15, 0.3, 1) both;
}

.reward-word {
    max-width: 94vw;
    padding: 14px 24px;
    border: 5px solid #fff;
    border-radius: 30px;
    background: linear-gradient(105deg, var(--teal-soft), var(--vowel-soft));
    box-shadow: 0 10px 0 rgba(8, 118, 110, 0.22), 0 18px 38px rgba(52, 38, 111, 0.16);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(2.6rem, 13vw, 6rem);
    line-height: 1.12;
    text-align: center;
    overflow-wrap: anywhere;
}

.app-version {
    position: fixed;
    right: 8px;
    bottom: 6px;
    z-index: 5;
    color: rgba(52, 38, 111, 0.44);
    font: 800 0.68rem/1 'Nunito', sans-serif;
}

@keyframes syllable-merge-pop {
    0% { transform: translate(-50%, -50%) scale(0.55); opacity: 0; }
    58% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes syllable-glow {
    from { box-shadow: 0 10px 0 rgba(8, 118, 110, 0.25), 0 18px 30px rgba(52, 38, 111, 0.16), 0 0 14px rgba(255, 230, 109, 0.42); }
    to { box-shadow: 0 10px 0 rgba(8, 118, 110, 0.3), 0 22px 42px rgba(52, 38, 111, 0.2), 0 0 42px rgba(255, 230, 109, 0.92); }
}

@keyframes option-correct {
    0%, 100% { transform: scale(1); }
    55% { transform: scale(1.12) translateY(-5px); }
}

@keyframes option-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

@keyframes hint-glow {
    0%, 100% { box-shadow: 0 9px 0 rgba(189, 93, 24, 0.27), 0 0 0 rgba(255, 230, 109, 0); }
    50% { transform: scale(1.08); box-shadow: 0 9px 0 rgba(189, 93, 24, 0.27), 0 0 36px rgba(255, 230, 109, 1), 0 0 0 7px rgba(15, 159, 145, 0.2); }
}

@keyframes level-pop {
    0% { transform: scale(0.7); opacity: 0.4; }
    60% { transform: scale(1.22); opacity: 1; }
    100% { transform: scale(1); }
}

@keyframes reward-pop {
    0% { transform: scale(0.3) rotate(-10deg); opacity: 0; }
    65% { transform: scale(1.12) rotate(3deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

@media (max-width: 430px) {
    .game-header {
        top: 10px;
        left: 10px;
        right: 10px;
        gap: 7px;
    }

    .syllable-main {
        padding: 78px 10px 14px;
    }

    .blend-stage {
        width: 100%;
        border-radius: 28px;
    }

    .syllable-option {
        border-radius: 22px;
    }
}

@media (max-height: 690px) {
    .start-card {
        gap: 9px;
        padding-top: 20px;
        padding-bottom: 24px;
    }

    .start-icon {
        width: 84px;
        height: 84px;
        font-size: 3rem;
    }

    .start-button {
        min-height: 66px;
    }

    .syllable-main {
        padding-top: 72px;
        gap: 8px;
    }

    .instruction {
        min-height: 40px;
        padding: 5px 14px;
    }

    .blend-stage {
        height: clamp(168px, 29vh, 206px);
    }

    .blend-card {
        height: clamp(94px, 17vh, 120px);
    }

    .syllable-options {
        min-height: 78px;
    }

    .syllable-option {
        height: clamp(74px, 13vh, 94px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }

    .flying-option {
        display: none !important;
    }
}
