:root {
    --violet-dark: #34266f;
    --violet: #6d4bd1;
    --violet-light: #9d82ec;
    --ink: #2f2850;
    --cream: #fffaf0;
    --success: #27ae60;
    --danger: #e85d75;
}

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

html,
body {
    min-height: 100%;
}

body {
    min-height: 100dvh;
    overflow: hidden;
    color: var(--ink);
    font-family: 'Nunito', sans-serif;
    background:
        radial-gradient(circle at 14% 18%, rgba(255, 230, 109, 0.7), transparent 23%),
        radial-gradient(circle at 88% 75%, rgba(126, 214, 206, 0.48), transparent 28%),
        linear-gradient(150deg, #fff8e7 0%, #f2eaff 52%, #e4f8f5 100%);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body::before,
body::after {
    content: '';
    position: fixed;
    width: 190px;
    height: 190px;
    border-radius: 44% 56% 62% 38%;
    filter: blur(2px);
    opacity: 0.14;
    pointer-events: none;
}

body::before {
    left: -70px;
    bottom: -50px;
    background: var(--violet);
    transform: rotate(24deg);
}

body::after {
    right: -80px;
    top: 18%;
    background: #ff8fab;
    transform: rotate(-18deg);
}

button {
    color: inherit;
    font: inherit;
}

.score-display {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    min-width: 82px;
    min-height: 44px;
    font-size: clamp(1.25rem, 4vw, 1.8rem);
    line-height: 1;
}

.star {
    display: inline-block;
    animation: score-pop 0.34s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.lowercase-main {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(18px, 4.2vh, 34px);
    padding: 96px 16px 24px;
}

.instruction {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 50px;
    padding: 9px 18px;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--violet), #8f67df);
    border: 2px solid rgba(255, 255, 255, 0.78);
    box-shadow: 0 8px 0 rgba(52, 38, 111, 0.18), 0 14px 28px rgba(52, 38, 111, 0.18);
    font-family: 'Nunito', sans-serif;
    font-size: clamp(0.95rem, 3.4vw, 1.2rem);
    font-weight: 900;
    letter-spacing: 0.055em;
}

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

.letter-stage {
    width: clamp(176px, 49vw, 245px);
    height: clamp(176px, 49vw, 245px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(8px, 2.5vw, 16px);
    position: relative;
    border: 4px solid rgba(109, 75, 209, 0.3);
    border-radius: 38px;
    background:
        radial-gradient(circle at 35% 22%, rgba(255, 255, 255, 0.92), transparent 34%),
        linear-gradient(155deg, #fff, #f7f0ff);
    box-shadow: 0 12px 0 rgba(88, 60, 174, 0.18), 0 22px 42px rgba(52, 38, 111, 0.2);
    cursor: pointer;
    transition:
        width 0.55s cubic-bezier(0.175, 0.885, 0.32, 1.15),
        height 0.55s cubic-bezier(0.175, 0.885, 0.32, 1.15),
        border-radius 0.45s ease,
        border-color 0.3s ease,
        background 0.3s ease,
        box-shadow 0.3s ease,
        transform 0.12s ease;
}

.letter-stage::after {
    content: '🔊';
    position: absolute;
    right: 13px;
    bottom: 10px;
    font-size: 1rem;
    opacity: 0.38;
    transition: opacity 0.2s ease;
}

.letter-stage:active {
    transform: translateY(4px);
    box-shadow: 0 7px 0 rgba(88, 60, 174, 0.18), 0 14px 30px rgba(52, 38, 111, 0.18);
}

.letter-stage:focus-visible,
.letter-option:focus-visible {
    outline: 5px solid rgba(255, 176, 0, 0.75);
    outline-offset: 4px;
}

.uppercase-letter,
.matched-letter {
    min-width: 0;
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    line-height: 0.9;
    text-rendering: optimizeLegibility;
}

.uppercase-letter {
    color: var(--violet-dark);
    font-size: clamp(7rem, 28vw, 11.5rem);
    text-shadow: 0 6px 0 rgba(109, 75, 209, 0.12);
    transition: font-size 0.25s ease, transform 0.25s ease;
}

.letter-stage.is-wide-letter:not(.is-matched) .uppercase-letter {
    font-size: clamp(5.5rem, 24vw, 9rem);
}

.matched-letter {
    display: none;
    color: var(--success);
    font-size: clamp(5.5rem, 22vw, 9rem);
    text-shadow: 0 5px 0 rgba(39, 174, 96, 0.12);
}

.letter-stage.is-matched {
    width: min(86vw, 360px);
    height: clamp(150px, 42vw, 190px);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    overflow: visible;
    border-color: var(--success);
    border-radius: 30px;
    background:
        radial-gradient(circle at 34% 18%, rgba(255, 255, 255, 0.96), transparent 34%),
        linear-gradient(155deg, #ffffff, #edfff3);
}

.letter-stage.is-matched::after {
    opacity: 0;
}

.letter-stage.is-matched .uppercase-letter,
.letter-stage.is-matched .matched-letter {
    width: 100%;
    max-width: 100%;
    display: grid;
    place-items: center;
    font-size: clamp(4.7rem, 20vw, 8rem);
    letter-spacing: -0.04em;
}

.letter-stage.is-matched .uppercase-letter {
    animation: pair-uppercase-settle 1.1s cubic-bezier(0.175, 0.885, 0.32, 1.15) both;
}

.letter-stage.is-matched .matched-letter {
    animation: pair-letter-arrive 1.1s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

.letter-stage.is-celebrating {
    animation:
        pair-card-pop 1.1s cubic-bezier(0.175, 0.885, 0.32, 1.15) both,
        pair-card-glow 0.75s ease-in-out 1.1s infinite alternate;
}

.letter-options {
    width: min(94vw, 520px);
    min-height: clamp(92px, 25vw, 128px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(14px, 4vw, 26px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.letter-options.is-answering {
    pointer-events: none;
}

.letter-options.is-answering .letter-option:not(.is-correct) {
    opacity: 0;
    transform: translateY(8px) scale(0.84);
}

.letter-options.is-answering .letter-option.is-correct {
    opacity: 0;
    transform: translateY(-18px) scale(0.72);
}

.letter-option {
    width: clamp(92px, 25vw, 126px);
    height: clamp(92px, 25vw, 126px);
    display: grid;
    place-items: center;
    border: 3px solid rgba(109, 75, 209, 0.28);
    border-radius: 28px;
    background: #fff;
    color: var(--ink);
    font-family: 'Nunito', sans-serif;
    font-size: clamp(3.8rem, 14vw, 6rem);
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 9px 0 rgba(52, 38, 111, 0.16), 0 15px 28px rgba(52, 38, 111, 0.14);
    transition:
        opacity 0.35s ease,
        transform 0.35s ease,
        box-shadow 0.1s ease,
        border-color 0.18s ease;
}

.letter-options.two-options .letter-option {
    width: clamp(112px, 31vw, 150px);
}

.letter-option:active:not(:disabled) {
    transform: translateY(6px);
    box-shadow: 0 3px 0 rgba(52, 38, 111, 0.16), 0 8px 16px rgba(52, 38, 111, 0.12);
}

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

.letter-option.is-correct {
    color: var(--success);
    border-color: var(--success);
    background: #effff4;
    animation: option-correct 0.42s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.letter-option.is-error {
    color: var(--danger);
    border-color: var(--danger);
    animation: option-shake 0.4s ease;
}

.letter-option.hint-glow {
    border-color: var(--success);
    animation: hint-glow 1.05s ease-in-out 2;
}

.level-badge {
    min-width: 98px;
    padding: 8px 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.84);
    color: var(--violet-dark);
    border: 2px solid rgba(109, 75, 209, 0.2);
    box-shadow: 0 5px 0 rgba(52, 38, 111, 0.1);
    font-family: 'Nunito', sans-serif;
    font-size: 0.86rem;
    font-weight: 900;
    letter-spacing: 0.04em;
}

.level-badge.level-up {
    animation: level-pop 0.72s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.confetti {
    position: fixed;
    top: -12px;
    width: 10px;
    height: 14px;
    z-index: 1000;
    pointer-events: none;
    animation: confetti-fall linear forwards;
}

@keyframes pair-card-pop {
    0% { transform: scale(0.84); }
    58% { transform: scale(1.065); }
    100% { transform: scale(1); }
}

@keyframes pair-card-glow {
    0% {
        transform: scale(1);
        box-shadow:
            0 10px 0 rgba(21, 128, 61, 0.24),
            0 18px 34px rgba(52, 38, 111, 0.18),
            0 0 18px rgba(255, 230, 109, 0.5);
    }
    100% {
        transform: scale(1.035);
        box-shadow:
            0 10px 0 rgba(21, 128, 61, 0.3),
            0 20px 38px rgba(52, 38, 111, 0.2),
            0 0 42px rgba(255, 230, 109, 0.92),
            0 0 70px rgba(39, 174, 96, 0.38);
    }
}

@keyframes pair-uppercase-settle {
    0% { transform: translateX(44%) scale(1.22); }
    55% { transform: translateX(-4%) scale(0.94); }
    100% { transform: translateX(0) scale(1); }
}

@keyframes pair-letter-arrive {
    0% { transform: translateX(-42%) scale(0.2) rotate(-12deg); opacity: 0; }
    62% { transform: translateX(5%) scale(1.16) rotate(3deg); opacity: 1; }
    100% { transform: translateX(0) scale(1) rotate(0); opacity: 1; }
}

@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(52, 38, 111, 0.16), 0 0 0 rgba(39, 174, 96, 0); }
    50% { box-shadow: 0 9px 0 rgba(52, 38, 111, 0.16), 0 0 28px rgba(39, 174, 96, 0.72); }
}

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

@keyframes score-pop {
    from { transform: scale(0.35); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes confetti-fall {
    0% { transform: translateY(-10vh) translateX(0) rotate(0); opacity: 1; }
    100% { transform: translateY(110vh) translateX(var(--confetti-drift, 0)) rotate(720deg); opacity: 0; }
}

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

    .lowercase-main {
        padding: 82px 10px 16px;
        gap: clamp(14px, 3.2vh, 24px);
    }

    .letter-options {
        gap: 10px;
    }

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

@media (max-height: 690px) {
    .lowercase-main {
        padding-top: 74px;
        gap: 12px;
    }

    .instruction {
        min-height: 42px;
        padding: 6px 14px;
    }

    .letter-stage {
        width: clamp(142px, 36vh, 205px);
        height: clamp(142px, 36vh, 205px);
    }

    .letter-stage.is-matched {
        width: min(88vw, 330px);
        height: clamp(132px, 29vh, 168px);
    }

    .letter-option {
        width: clamp(78px, 20vh, 108px);
        height: clamp(78px, 20vh, 108px);
    }

    .letter-options {
        min-height: 82px;
    }
}

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