:root {
    --paper: #fffdf7;
    --crayon: #d85a30;
    --ink: #0f766e;
    --guide: #dcd7c8;
    --start: #639922;
}

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

body {
    min-height: 100dvh;
    background:
        radial-gradient(circle at 16% 18%, rgba(250, 204, 21, 0.24), transparent 24%),
        radial-gradient(circle at 84% 82%, rgba(14, 165, 233, 0.24), transparent 30%),
        linear-gradient(150deg, #064e3b 0%, #0f766e 48%, #0891b2 100%);
    color: #fff;
    font-family: 'Fredoka One', 'Nunito', cursive;
    overflow: visible;
    user-select: none;
    -webkit-user-select: none;
}

button {
    font: inherit;
}

.score-display {
    grid-column: 3;
    justify-self: end;
    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.36s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.trace-main {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(16px, 4vh, 30px);
    padding: 92px 14px 28px;
}

.prompt-banner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 58px;
    max-width: min(92vw, 540px);
    padding: 8px 18px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.26);
    box-shadow: 0 16px 36px rgba(2, 6, 23, 0.34);
    backdrop-filter: blur(10px);
}

.prompt-text {
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: clamp(0.95rem, 3.2vw, 1.25rem);
    line-height: 1.1;
    text-align: center;
    color: #fff;
    text-shadow: 0 2px 4px rgba(2, 6, 23, 0.4);
}

.tier-pill {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 0.85rem;
    line-height: 1;
    background: #facc15;
    color: #064e3b;
    padding: 6px 12px;
    border-radius: 999px;
    white-space: nowrap;
}

.trace-card {
    position: relative;
    width: min(92vw, 460px);
    aspect-ratio: 1 / 1;
    background:
        linear-gradient(90deg, rgba(216, 90, 48, 0.04) 0 1px, transparent 1px 100%),
        linear-gradient(0deg, rgba(15, 118, 110, 0.05) 0 1px, transparent 1px 100%),
        var(--paper);
    background-size: 24px 24px;
    border-radius: 22px;
    overflow: hidden;
    border: 4px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 18px 40px rgba(2, 6, 23, 0.4), inset 0 0 0 2px rgba(15, 118, 110, 0.08);
    -webkit-tap-highlight-color: transparent;
}

#trace-svg {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.trace-msg {
    position: absolute;
    left: 50%;
    top: 14px;
    transform: translateX(-50%) scale(0.92);
    z-index: 2;
    min-width: 160px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 253, 247, 0.88);
    font-family: 'Fredoka One', cursive;
    font-size: clamp(1rem, 4.6vw, 1.45rem);
    text-align: center;
    color: #0f766e;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
}

.trace-msg.show {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

.tg-guide {
    fill: none;
    stroke: var(--guide);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 0.1 6;
}

.tg-future {
    opacity: 0.45;
}

.tg-reveal {
    fill: none;
    stroke: var(--crayon);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 2px 0 rgba(120, 53, 15, 0.18));
}

.tg-start {
    fill: var(--start);
    stroke: #fff;
    stroke-width: 1.6;
    filter: drop-shadow(0 2px 0 rgba(21, 128, 61, 0.28));
}

.tg-start.hint-pulse {
    animation: start-hint 0.7s ease-in-out 2;
}

.tg-crayon {
    fill: #fff;
    stroke: var(--crayon);
    stroke-width: 2.5;
    filter: drop-shadow(0 3px 0 rgba(120, 53, 15, 0.18));
}

.tg-arrow {
    fill: var(--start);
    stroke: #fff;
    stroke-width: 0.8;
    filter: drop-shadow(0 1px 0 rgba(21, 128, 61, 0.22));
}

@keyframes glyph-pop {
    0% { transform: scale(1); }
    45% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@keyframes start-hint {
    0%,
    100% { transform: scale(1); }
    50% { transform: scale(1.45); }
}

#trace-svg.celebrate {
    animation: glyph-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-box: fill-box;
    transform-origin: center;
}

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

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

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

@media (max-width: 420px) {
    .trace-main {
        padding-left: 10px;
        padding-right: 10px;
        gap: 16px;
    }

    .trace-card {
        width: 94vw;
        border-radius: 18px;
    }

    .prompt-banner {
        min-height: 54px;
        padding: 8px 12px;
        gap: 8px;
    }

    .tier-pill {
        font-size: 0.76rem;
        padding: 5px 9px;
    }
}
