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

html {
    /* Fluid base: scales from 16px on desktop up, ensures rem units feel larger on mobile */
    font-size: clamp(16px, 4.5vw, 18px);
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

#particleCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

h1 {
    color: white;
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: fadeInDown 1s ease;
    text-align: center;
}

.subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.2rem;
    margin-bottom: 20px;
    text-align: center;
    animation: fadeInUp 1s ease;
}

.counter {
    color: white;
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: fadeInUp 1s ease 0.2s backwards;
}

.timer {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: fadeInUp 1s ease 0.3s backwards;
}

#timer {
    color: #4ecdc4;
}

#timer.urgent {
    color: #ff6b6b;
    animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.2); }
}

/* ═══ OVERLAYS ═══ */
.game-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.5s ease;
    padding: 20px;
}

.game-overlay.hidden {
    display: none;
}

.overlay-box {
    text-align: center;
    color: white;
    padding: 36px 48px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.15);
    max-width: 480px;
    width: 100%;
}

.overlay-icon {
    font-size: 4rem;
    margin-bottom: 8px;
}

.overlay-box h2 {
    font-size: 2.2rem;
    margin-bottom: 12px;
}

.overlay-result {
    font-size: 1.3rem;
    color: #fdcb6e;
    margin-bottom: 16px;
}

.overlay-hint {
    font-size: 0.95rem;
    color: rgba(255,255,255,0.7);
    margin-bottom: 20px;
    line-height: 1.6;
}

.overlay-btn {
    font-size: 1.1rem;
    padding: 12px 32px;
    border: none;
    border-radius: 10px;
    background: #4ecdc4;
    color: #1a1a2e;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.1s;
    margin-top: 8px;
}

.overlay-btn:hover { transform: scale(1.05); }
.overlay-btn:disabled { opacity: 0.5; cursor: default; transform: none; }

/* Fuse bar (chance overlay) */
.fuse-section {
    margin: 16px 0;
}

.fuse-label {
    font-size: 1rem;
    color: rgba(255,255,255,0.8);
    margin-bottom: 8px;
}

/* bomb + track row */
.fuse-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.fuse-bomb {
    font-size: 3rem;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px rgba(225,112,85,0.9));
    transition: transform 0.2s;
}

.fuse-bomb.exploding-bomb {
    animation: bombExplode 0.6s ease-out forwards;
}

@keyframes bombExplode {
    0%   { transform: scale(1); filter: drop-shadow(0 0 8px orange); }
    30%  { transform: scale(1.8); filter: drop-shadow(0 0 30px red); }
    60%  { transform: scale(2.5); filter: drop-shadow(0 0 60px orange); opacity: 1; }
    100% { transform: scale(4); opacity: 0; }
}

.fuse-track {
    flex: 1;
    position: relative;
    height: 32px;
    background: rgba(255,255,255,0.08);
    border-radius: 16px;
    overflow: visible;
    border: 1px solid rgba(255,255,255,0.2);
}

/* fill anchored to RIGHT (bomb side), grows leftward */
.fuse-fill {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 0%;
    border-radius: 16px;
    background: linear-gradient(270deg, #8b4513 0%, #c0722a 40%, #f9ca24 100%);
    transition: width 1.2s ease-out;
}

/* flame hidden until button clicked */
.fuse-flame {
    position: absolute;
    top: 50%;
    transform: translateY(-50%) translateX(50%);
    font-size: 1.8rem;
    right: 0%;
    transition: right 1.6s linear;
    filter: drop-shadow(0 0 10px orange);
    z-index: 2;
    pointer-events: none;
}

.fuse-flame.hidden { display: none; }

.fuse-scale {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: rgba(255,255,255,0.45);
    padding: 0 2px;
    padding-right: 52px; /* align with track, not bomb */
}

.chance-display {
    font-size: 1.6rem;
    font-weight: bold;
    color: #f9ca24;
    margin: 12px 0 8px;
}

.detonate-btn {
    background: #e17055;
    color: white;
    font-size: 1.3rem;
    padding: 14px 40px;
    animation: bombPulse 1.2s infinite;
}

.detonate-btn:hover { background: #ff6b6b; }

@keyframes bombPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(225, 112, 85, 0.6); }
    50% { box-shadow: 0 0 0 12px rgba(225, 112, 85, 0); }
}

.bomb-pulse {
    animation: bombIconPulse 1s infinite alternate;
    display: inline-block;
}

@keyframes bombIconPulse {
    from { transform: scale(1); }
    to { transform: scale(1.15); }
}

/* Win box */
.win-box {
    border-color: #f9ca24;
    background: rgba(249, 202, 36, 0.08);
}

.coordinates {
    font-family: 'Courier New', monospace;
    font-size: 1.3rem;
    background: rgba(0,0,0,0.4);
    border-radius: 10px;
    padding: 14px 20px;
    margin: 16px 0;
    border: 1px solid rgba(249, 202, 36, 0.4);
    color: #f9ca24;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    user-select: none;
}

.coordinates:hover {
    background: rgba(249, 202, 36, 0.12);
    border-color: rgba(249, 202, 36, 0.8);
}

.coordinates.copied {
    background: rgba(0, 184, 148, 0.2);
    border-color: #00b894;
    color: #00b894;
}

.coordinates p { margin: 4px 0; }

.copy-hint {
    font-size: 0.75rem;
    color: rgba(249, 202, 36, 0.5);
    margin-top: 8px;
    font-family: sans-serif;
    letter-spacing: normal;
}

.coordinates.copied .copy-hint {
    color: #00b894;
}

.version {
    position: fixed;
    bottom: 8px;
    right: 12px;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.3);
    letter-spacing: 0.05em;
    pointer-events: none;
    z-index: 999;
}

#score {
    color: #fdcb6e;
    display: inline-block;
    min-width: 50px;
    text-align: center;
    transition: transform 0.2s ease;
}

.elements-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
    max-width: 600px;
}

.boom-element {
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: fadeIn 1s ease backwards;
    will-change: transform;
}

.boom-element:nth-child(1) { animation-delay: 0.1s; }
.boom-element:nth-child(2) { animation-delay: 0.2s; }
.boom-element:nth-child(3) { animation-delay: 0.3s; }
.boom-element:nth-child(4) { animation-delay: 0.4s; }
.boom-element:nth-child(5) { animation-delay: 0.5s; }
.boom-element:nth-child(6) { animation-delay: 0.6s; }
.boom-element:nth-child(7) { animation-delay: 0.7s; }
.boom-element:nth-child(8) { animation-delay: 0.8s; }
.boom-element:nth-child(9) { animation-delay: 0.9s; }

.boom-element:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
}

.boom-element:active {
    transform: scale(0.95);
}

.boom-element.exploding {
    animation: explode 0.5s ease forwards;
}


.floating-skull {
    position: fixed;
    font-size: 4rem;
    z-index: 2000;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    will-change: transform, opacity;
    transition: transform 0.7s ease-out, opacity 0.7s ease-out;
}

.floating-skull.skull-zoom-active {
    transform: translate(-50%, -50%) scale(12);
    opacity: 0;
}

.boom-element.fading {
    animation: fadeOutIn 1s ease forwards;
}

.boom-element span {
    display: block;
    line-height: 1;
}

.boom-element.ghosting span {
    animation: ghostMorph 0.5s ease forwards;
}

@keyframes explode {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.5);
        opacity: 0.5;
    }
    100% {
        transform: scale(0);
        opacity: 0;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOutIn {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}


@keyframes ghostMorph {
    0% {
        filter: blur(0px) brightness(1);
        transform: scale(1);
    }
    50% {
        filter: blur(5px) brightness(1.5);
        transform: scale(1.2);
        opacity: 0.7;
    }
    100% {
        filter: blur(0px) brightness(1);
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 2.2rem;
    }

    .subtitle {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }
    
    .counter {
        font-size: 1.8rem;
        margin-bottom: 10px;
    }
    
    .timer {
        font-size: 1.4rem;
        margin-bottom: 20px;
    }
    
    .elements-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
        max-width: 100%;
    }
    
    .boom-element {
        width: 90px;
        height: 90px;
        font-size: 3rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1.1rem;
    }
    
    .counter {
        font-size: 1.6rem;
    }
    
    .timer {
        font-size: 1.3rem;
    }
    
    .elements-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        max-width: 100%;
    }
    
    .boom-element {
        width: 80px;
        height: 80px;
        font-size: 2.8rem;
    }
    
    .overlay-box {
        padding: 24px 20px;
    }
}
