:root {
    --bg-deep: #0f3d3e;
    --bg-mid: #1f8a70;
    --bg-light: #2ec4b6;
    --sand: #fff7e6;
    --ink: #1b2b2c;
    --accent: #e76f51;
    --accent-soft: #f4a261;
    --sun: #ffd166;
    --box: #ffd166;
    --box-edge: #f4a261;
    --shadow: rgba(15, 61, 62, 0.28);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

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

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

body {
    font-family: "Fredoka", "Trebuchet MS", sans-serif;
    color: var(--ink);
    background: linear-gradient(160deg, var(--bg-deep) 0%, var(--bg-mid) 42%, var(--bg-light) 100%);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    padding:
        calc(12px + var(--safe-top))
        calc(12px + var(--safe-right))
        calc(12px + var(--safe-bottom))
        calc(12px + var(--safe-left));
}

.bg-pattern {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(circle at 12% 18%, rgba(255, 209, 102, 0.22) 0 8%, transparent 9%),
        radial-gradient(circle at 86% 22%, rgba(231, 111, 81, 0.18) 0 10%, transparent 11%),
        radial-gradient(circle at 70% 78%, rgba(255, 247, 230, 0.12) 0 12%, transparent 13%),
        radial-gradient(circle at 20% 80%, rgba(46, 196, 182, 0.2) 0 9%, transparent 10%);
    animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
    from { transform: translate3d(0, 0, 0) scale(1); }
    to { transform: translate3d(-1.5%, 1.5%, 0) scale(1.04); }
}

.top-bar,
.game-shell {
    position: relative;
    z-index: 1;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    max-width: 960px;
    margin: 0 auto 12px;
}

.home-link,
.level-badge,
.mode-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0.45rem 0.9rem;
    border-radius: 12px;
    background: rgba(255, 247, 230, 0.92);
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 6px 16px var(--shadow);
}

.mode-badge {
    background: var(--sun);
}

.mode-badge.touch {
    background: var(--accent-soft);
    color: #3a1f12;
}

.game-shell {
    max-width: 960px;
    height: calc(100dvh - 76px - var(--safe-top) - var(--safe-bottom));
    margin: 0 auto;
    position: relative;
}

.start-screen,
.win-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.start-screen {
    text-align: center;
    animation: rise-in 0.55s ease-out both;
}

.brand {
    font-size: clamp(2.4rem, 8vw, 4.2rem);
    font-weight: 700;
    color: var(--sand);
    letter-spacing: 0.02em;
    text-shadow: 0 4px 0 rgba(15, 61, 62, 0.25);
    margin-bottom: 0.35rem;
    animation: brand-pop 1.1s ease-out both;
}

.start-screen h1,
.win-message {
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    color: var(--sand);
    margin-bottom: 0.75rem;
}

.start-copy,
.win-sub,
.hint {
    color: rgba(255, 247, 230, 0.92);
    font-size: clamp(1rem, 3.4vw, 1.25rem);
    max-width: 28ch;
    margin: 0 auto 1.4rem;
    line-height: 1.45;
}

.win-sub {
    margin-bottom: 0;
}

.primary-btn {
    appearance: none;
    border: none;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--ink);
    background: linear-gradient(180deg, var(--sun) 0%, var(--accent-soft) 100%);
    padding: 0.9rem 1.6rem;
    border-radius: 14px;
    box-shadow: 0 8px 0 #c46d3a, 0 12px 24px var(--shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn:hover {
    transform: translateY(-2px);
}

.primary-btn:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 #c46d3a, 0 8px 16px var(--shadow);
}

.play-area {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 24px;
    background: rgba(255, 247, 230, 0.12);
    border: 2px solid rgba(255, 247, 230, 0.28);
    overflow: hidden;
    touch-action: manipulation;
}

.play-area[hidden],
.start-screen[hidden],
.win-overlay[hidden] {
    display: none !important;
}

.hint {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    background: rgba(15, 61, 62, 0.45);
    white-space: nowrap;
    z-index: 2;
    pointer-events: none;
}

.target-box {
    position: absolute;
    width: var(--box-size, 160px);
    height: var(--box-size, 160px);
    border-radius: 18px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.35), transparent 40%),
        linear-gradient(180deg, var(--box) 0%, var(--accent-soft) 100%);
    border: 4px solid var(--box-edge);
    box-shadow:
        0 10px 0 rgba(196, 109, 58, 0.55),
        0 16px 28px rgba(15, 61, 62, 0.25);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    animation: box-breathe 1.8s ease-in-out infinite;
    z-index: 1;
}

.target-box:hover,
.target-box:focus-visible {
    outline: none;
    transform: scale(1.04);
}

.target-box.pulse-win {
    animation: box-win 0.45s ease-out;
}

.win-overlay {
    z-index: 5;
    background: rgba(15, 61, 62, 0.35);
    backdrop-filter: blur(2px);
}

.win-card {
    text-align: center;
    padding: 1.5rem 1.25rem;
    border-radius: 22px;
    background: rgba(15, 61, 62, 0.72);
    border: 2px solid rgba(255, 247, 230, 0.28);
    animation: rise-in 0.4s ease-out both;
    min-width: min(90vw, 320px);
}

.win-message {
    animation: celebrate-pop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

#confetti-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes brand-pop {
    0% {
        opacity: 0;
        transform: scale(0.86) translateY(12px);
    }
    60% {
        opacity: 1;
        transform: scale(1.04) translateY(0);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes box-breathe {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.03);
    }
}

@keyframes box-win {
    0% { transform: scale(1); }
    40% { transform: scale(1.18); }
    100% { transform: scale(1); }
}

@keyframes celebrate-pop {
    0% {
        opacity: 0;
        transform: scale(0.7) rotate(-4deg);
    }
    70% {
        opacity: 1;
        transform: scale(1.08) rotate(2deg);
    }
    100% {
        transform: scale(1) rotate(0);
    }
}

@media (max-width: 640px) {
    .top-bar {
        margin-bottom: 10px;
    }

    .home-link,
    .level-badge,
    .mode-badge {
        min-height: 36px;
        padding: 0.35rem 0.7rem;
        font-size: 0.92rem;
    }

    .game-shell {
        height: calc(100dvh - 68px - var(--safe-top) - var(--safe-bottom));
    }

    .hint {
        font-size: 0.95rem;
        white-space: normal;
        text-align: center;
        max-width: 90%;
    }

    .target-box {
        border-radius: 14px;
        border-width: 3px;
    }

    .primary-btn {
        width: min(100%, 280px);
    }
}

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