* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --green: #3dd68c;
    --green-deep: #1b7a4a;
    --pink: #ff4d8d;
    --gold: #ffc857;
    --cyan: #00e5c0;
    --bg: #06100c;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #06100c;
    overflow: hidden;
}

canvas {
    display: block;
    cursor: crosshair;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.4) 100%);
    z-index: 2;
}

#frenzy-flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    background: radial-gradient(circle at 50% 70%, rgba(0,229,192,0.2), transparent 65%);
    animation: frenzyPulse 0.55s ease-in-out infinite alternate;
}

@keyframes frenzyPulse {
    from { opacity: 0.45; }
    to { opacity: 1; }
}

#ui-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    z-index: 5;
}

#top-bar {
    display: grid;
    grid-template-columns: 1fr 1.1fr 1fr;
    align-items: start;
    gap: 10px;
    width: 100%;
}

.label {
    font-family: 'Fredoka', sans-serif;
    font-size: 11px;
    letter-spacing: 0.14em;
    color: rgba(255,255,255,0.6);
    margin-bottom: 2px;
}

#score-block {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
}

#score {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(32px, 6vw, 48px);
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 18px rgba(61,214,140,0.55), 2px 3px 0 #000;
    line-height: 1;
}

.combo-badge {
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--gold);
    background: rgba(0,0,0,0.45);
    border: 2px solid rgba(255,200,87,0.45);
    padding: 4px 12px;
    border-radius: 999px;
    text-shadow: 0 0 8px rgba(255,200,87,0.5);
    transition: transform 0.12s ease, color 0.12s, box-shadow 0.12s;
}

.combo-badge.pop {
    transform: scale(1.5);
    color: #fff;
    box-shadow: 0 0 28px rgba(255,200,87,0.85);
}

#center-hud {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    min-height: 48px;
}

#combo-banner {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: clamp(22px, 5vw, 36px);
    letter-spacing: 0.04em;
    color: #fff;
    text-shadow: 0 0 18px var(--pink), 0 0 36px var(--gold), 2px 3px 0 #000;
    animation: bannerIn 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
    white-space: nowrap;
}

#hint-toast {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(16px, 3.5vw, 22px);
    font-weight: 600;
    color: #fff;
    background: rgba(0,0,0,0.45);
    border: 2px solid rgba(61,214,140,0.45);
    padding: 8px 18px;
    border-radius: 999px;
    text-shadow: 1px 1px 0 #000;
    animation: toastBob 1.2s ease-in-out infinite;
}

@keyframes toastBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes bannerIn {
    from { opacity: 0; transform: scale(0.35) translateY(18px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

#right-hud {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

#high-score-block { text-align: right; }

#high-score {
    font-family: 'Fredoka', sans-serif;
    font-size: 20px;
    font-weight: 700;
    color: rgba(255,255,255,0.9);
}

#energy-container { width: min(280px, 42vw); }
.energy-label { text-align: right; }

#energy-bar-bg {
    width: 100%;
    height: 22px;
    border-radius: 999px;
    background: rgba(0,0,0,0.55);
    border: 3px solid rgba(255,255,255,0.3);
    overflow: hidden;
    position: relative;
    box-shadow: 0 0 16px rgba(0,0,0,0.4), inset 0 0 8px rgba(0,0,0,0.5);
}

#energy-bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #ff4d6d 0%, #ffc857 40%, #3dd68c 100%);
    transition: width 0.12s linear, filter 0.2s;
    box-shadow: 0 0 14px rgba(61,214,140,0.45);
}

#energy-bar-shine {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.4) 0%, transparent 55%);
    pointer-events: none;
    border-radius: 999px;
}

#level-hud {
    margin-top: 12px;
    max-width: 420px;
    width: min(420px, 92vw);
    align-self: center;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(61, 214, 140, 0.28);
    border-radius: 16px;
    padding: 10px 14px 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

#level-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

#level-badge {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.06em;
    color: #06100c;
    background: linear-gradient(180deg, #6ff5b0, #3dd68c);
    padding: 6px 10px;
    border-radius: 10px;
    flex-shrink: 0;
    box-shadow: 0 3px 0 #0f5c36;
}

#level-meta {
    flex: 1;
    min-width: 0;
}

#level-name {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: #fff;
    line-height: 1.1;
}

#level-goal-text {
    font-size: 12px;
    font-weight: 700;
    color: rgba(255,255,255,0.55);
}

#stars-earned {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    color: var(--gold);
    font-size: 16px;
    text-shadow: 0 0 10px rgba(255,200,87,0.5);
    flex-shrink: 0;
}

#level-bar-bg {
    width: 100%;
    height: 14px;
    border-radius: 999px;
    background: rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.2);
    overflow: hidden;
}

#level-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #00e5c0, #3dd68c 50%, #ffc857);
    border-radius: 999px;
    transition: width 0.2s ease-out;
    box-shadow: 0 0 12px rgba(61,214,140,0.45);
}

#level-progress-label {
    text-align: right;
    font-family: 'Fredoka', sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: rgba(255,255,255,0.55);
    margin-top: 4px;
}

.level-clear-card {
    border-color: rgba(255, 200, 87, 0.45);
}

.level-clear-kicker {
    font-family: 'Fredoka', sans-serif;
    letter-spacing: 0.2em;
    font-size: 13px;
    color: var(--gold);
    margin-bottom: 6px;
}

.level-clear-title {
    font-size: clamp(32px, 8vw, 48px) !important;
    color: #fff !important;
    text-shadow: 0 0 24px rgba(61,214,140,0.5), 3px 4px 0 #0a1f14 !important;
    margin-bottom: 12px !important;
}

.level-stars {
    font-size: clamp(36px, 9vw, 52px);
    color: var(--gold);
    letter-spacing: 0.12em;
    text-shadow: 0 0 20px rgba(255,200,87,0.6);
    margin-bottom: 10px;
    animation: pulse 0.5s infinite alternate;
}

.level-bonus {
    font-family: 'Fredoka', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: #3dd68c;
    margin-bottom: 8px;
}

.level-next-hint {
    color: rgba(255,255,255,0.5);
    font-weight: 700;
    font-size: 14px;
}

.best-level-line {
    font-size: 14px;
    color: rgba(255,255,255,0.55);
    margin-bottom: 18px;
    font-weight: 700;
}

.best-level-line strong {
    color: var(--gold);
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
}

#frenzy-indicator {
    color: var(--cyan);
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(24px, 5.5vw, 42px);
    font-weight: 700;
    text-align: center;
    margin-top: 16px;
    text-shadow: 0 0 14px var(--cyan), 0 0 28px var(--cyan), 0 2px 0 #000;
    animation: pulse 0.45s infinite alternate;
    letter-spacing: 0.06em;
}

@keyframes pulse {
    from { opacity: 0.8; transform: scale(1); }
    to { opacity: 1; transform: scale(1.07); }
}

.hidden { display: none !important; }

.screen {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 28%, rgba(27,122,74,0.4), rgba(6,16,12,0.93) 70%);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    padding: 20px;
}

.screen-card {
    position: relative;
    max-width: 500px;
    width: 100%;
    text-align: center;
    color: #fff;
    background: rgba(10, 24, 18, 0.78);
    border: 3px solid rgba(61,214,140,0.35);
    border-radius: 28px;
    padding: 32px 24px 28px;
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.05) inset,
        0 28px 70px rgba(0,0,0,0.55),
        0 0 50px rgba(61,214,140,0.15);
    overflow: hidden;
}

.title-glow {
    position: absolute;
    top: -40%;
    left: 50%;
    width: 280px;
    height: 280px;
    transform: translateX(-50%);
    background: radial-gradient(circle, rgba(61,214,140,0.4), transparent 70%);
    pointer-events: none;
}

h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(40px, 10vw, 60px);
    font-weight: 700;
    line-height: 0.95;
    letter-spacing: 0.02em;
    margin-bottom: 10px;
    text-shadow: 0 0 28px rgba(61,214,140,0.55), 3px 4px 0 #0a1f14;
    position: relative;
}

h1 .accent {
    color: var(--pink);
    text-shadow: 0 0 22px rgba(255,77,141,0.55), 3px 4px 0 #2a0a14;
}

.tagline {
    font-size: 18px;
    color: rgba(255,255,255,0.78);
    margin-bottom: 14px;
    font-weight: 700;
}

.howto {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 auto 18px;
    max-width: 340px;
    text-align: left;
}

.howto-step {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 17px;
    font-weight: 800;
    color: #fff;
    background: rgba(61,214,140,0.12);
    border: 2px solid rgba(61,214,140,0.3);
    border-radius: 14px;
    padding: 10px 14px;
}

.howto-step span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #3dd68c;
    color: #06100c;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    flex-shrink: 0;
}

.bug-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    text-align: left;
    margin: 0 auto 18px;
    max-width: 380px;
    font-size: 15px;
    font-weight: 700;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255,255,255,0.9);
}

.legend-item em {
    margin-left: auto;
    font-style: normal;
    color: rgba(255,255,255,0.5);
    font-size: 13px;
}

.dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 10px currentColor;
}

.dot.fly { background: #3dd68c; color: #3dd68c; }
.dot.caterpillar { background: #7dff7d; color: #7dff7d; }
.dot.butterfly { background: #c77dff; color: #c77dff; }
.dot.wasp { background: #ffc857; color: #ffc857; }
.dot.firefly { background: #00e5c0; color: #00e5c0; }

.hint {
    font-size: 14px;
    color: rgba(255,255,255,0.5);
    margin-bottom: 22px;
    font-weight: 700;
}

button {
    font-family: 'Fredoka', sans-serif;
    padding: 16px 44px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #06100c;
    background: linear-gradient(180deg, #6ff5b0 0%, #3dd68c 55%, #1b9e5c 100%);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    box-shadow:
        0 7px 0 #0f5c36,
        0 14px 28px rgba(61,214,140,0.35);
    transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
    pointer-events: auto;
}

button:hover { filter: brightness(1.08); }

button:active {
    transform: translateY(6px);
    box-shadow: 0 1px 0 #0f5c36, 0 4px 12px rgba(61,214,140,0.25);
}

.go-title {
    color: var(--pink);
    font-size: clamp(28px, 7vw, 42px);
    text-shadow: 0 0 28px rgba(255,77,141,0.5), 3px 4px 0 #2a0a14;
}

.final-line {
    margin-top: 8px;
    color: rgba(255,255,255,0.55);
    font-size: 14px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-family: 'Fredoka', sans-serif;
}

#final-score {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(52px, 13vw, 84px);
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 28px rgba(61,214,140,0.5);
    margin: 4px 0 12px;
    line-height: 1;
}

#new-best {
    color: var(--gold);
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    letter-spacing: 0.1em;
    margin-bottom: 10px;
    animation: pulse 0.6s infinite alternate;
}

.go-stats {
    color: rgba(255,255,255,0.55);
    font-size: 15px;
    margin-bottom: 26px;
    font-weight: 700;
}

@media (max-width: 600px) {
    #top-bar { grid-template-columns: 1fr 1fr; }
    #center-hud { grid-column: 1 / -1; order: 3; }
    .bug-legend { grid-template-columns: 1fr; }
}
