:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --panel-bg: rgba(13, 11, 34, 0.78);
    --panel-border: rgba(255, 220, 238, 0.46);
    --panel-shadow: rgba(0, 0, 0, 0.34);
    --text: #fff8ff;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #07071a;
}

body {
    color: var(--text);
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", "Liberation Mono", monospace;
    overscroll-behavior: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    text-rendering: geometricPrecision;
}

#game {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #07071a;
    isolation: isolate;
    contain: layout paint size;
}

#game-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    contain: strict;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: pointer;
}

.finale-eevee {
    position: absolute;
    z-index: 7;
    pointer-events: none;
    opacity: 0;
    transform: translate3d(-50%, -100%, 0);
    transform-origin: 50% 100%;
    transition: opacity 360ms ease;
    will-change: transform, opacity;
}

.finale-eevee.show {
    opacity: 1;
}

.finale-eevee img {
    display: block;
    width: 100%;
    height: auto;
    filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.34)) drop-shadow(0 0 16px rgba(255, 168, 208, 0.28));
    transform-origin: 50% 92%;
    animation: eevee-bob 3.8s ease-in-out infinite;
}

@keyframes eevee-bob {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-6px) rotate(1deg); }
}

#hud {
    position: absolute;
    z-index: 5;
    top: calc(10px + var(--safe-top));
    right: 10px;
    left: 10px;
    contain: layout paint style;
    pointer-events: none;
}

#counter {
    display: inline-block;
    min-width: 0;
    max-width: calc(100vw - 20px);
    padding: 10px 11px;
    border: 2px solid rgba(255, 225, 242, 0.62);
    border-radius: 8px;
    background: rgba(10, 10, 26, 0.88);
    box-shadow:
        0 12px 34px var(--panel-shadow),
        0 0 0 4px rgba(255, 143, 204, 0.08);
    color: #fffafc;
    font-size: clamp(0.78rem, 3.6vw, 1rem);
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0;
    text-shadow:
        0 1px 0 rgba(0, 0, 0, 0.85),
        0 0 12px rgba(255, 179, 218, 0.62);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#countdown-panel {
    position: absolute;
    z-index: 8;
    top: 50%;
    left: 50%;
    width: min(92vw, 620px);
    padding: 18px 14px 16px;
    border: 2px solid rgba(255, 225, 242, 0.62);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(28, 16, 47, 0.96), rgba(10, 11, 30, 0.97)),
        var(--panel-bg);
    box-shadow:
        0 0 0 4px rgba(255, 143, 204, 0.12),
        0 22px 70px rgba(0, 0, 0, 0.42);
    opacity: 0;
    pointer-events: none;
    text-align: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transform: translate3d(-50%, -44%, 0) scale(0.96);
    transition: opacity 720ms ease, transform 720ms cubic-bezier(.16, 1, .3, 1);
    will-change: opacity, transform;
}

#countdown-panel.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate3d(-50%, -50%, 0) scale(1);
}

#countdown-panel h1 {
    margin: 0 0 16px;
    color: #fff8fd;
    font-size: clamp(1rem, 5.2vw, 1.9rem);
    line-height: 1.25;
    letter-spacing: 0;
    font-weight: 900;
    text-wrap: balance;
    text-shadow:
        0 1px 0 rgba(0, 0, 0, 0.88),
        0 0 12px rgba(255, 160, 214, 0.72),
        0 0 22px rgba(143, 223, 255, 0.3);
}

#countdown-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.countdown-cell {
    min-width: 0;
    padding: 12px 6px 10px;
    border: 2px solid rgba(216, 245, 255, 0.46);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.countdown-cell strong,
.countdown-cell span {
    display: block;
}

.countdown-cell strong {
    color: #ffffff;
    font-size: clamp(1.42rem, 8.8vw, 2.6rem);
    line-height: 1;
    letter-spacing: 0;
    font-variant-numeric: tabular-nums;
    text-shadow:
        0 1px 0 rgba(0, 0, 0, 0.82),
        0 0 16px rgba(255, 190, 222, 0.72);
}

.countdown-cell span {
    margin-top: 7px;
    color: #e8fcff;
    font-size: clamp(0.66rem, 3.1vw, 0.86rem);
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.75);
}

.hidden {
    display: none;
}

#perf-hud {
    position: absolute;
    z-index: 20;
    left: 8px;
    bottom: calc(8px + var(--safe-bottom));
    max-width: calc(100vw - 16px);
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, Liberation Mono, monospace;
    pointer-events: none;
    white-space: nowrap;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.85);
}

@media (min-width: 560px) {
    #hud {
        top: calc(16px + var(--safe-top));
        right: 16px;
        left: 16px;
    }

    #counter {
        padding: 11px 14px;
    }

    #countdown-panel {
        padding: 24px 24px 22px;
    }

    #countdown-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #countdown-panel {
        transition-duration: 1ms;
    }
}
