/* ==========================================================
   BOMB SURVIVAL - STABLE FULLSCREEN EDITION
   - 100% fullscreen arena
   - Fast sprite transforms
   - Separate boss attack GIF layer for clean one-shot playback
   - Pause, loading and game-over overlays
   ========================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #000000;
    --panel: rgba(0, 0, 0, 0.54);
    --panel-strong: rgba(0, 0, 0, 0.82);
    --gold: #daa520;
    --gold-2: #ffd36a;
    --text: #f1e7c8;
    --muted: #a8945e;
    --danger: #8b0000;
    --line: rgba(218, 165, 32, 0.20);
    --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);
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
}

body {
    position: fixed;
    inset: 0;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#gameWrapper,
#gameContainer,
#canvasWrapper {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
    background: #000;
}

#canvasWrapper {
    z-index: 0;
    touch-action: none;
    isolation: isolate;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

#arenaBackground,
#arenaFrame,
#canvas,
#spriteLayer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#arenaBackground,
#arenaFrame {
    object-fit: cover;
    object-position: center center;
    pointer-events: none;
    image-rendering: auto;
}

#arenaBackground {
    z-index: 0;
}

#canvas {
    z-index: 1;
    display: block;
    background: transparent;
    touch-action: none;
}

#spriteLayer {
    z-index: 3;
    overflow: hidden;
    pointer-events: none;
    contain: layout paint style;
}

#arenaFrame {
    z-index: 6;
}

#header {
    position: fixed;
    z-index: 42;
    top: calc(var(--safe-top) + 6px);
    left: calc(var(--safe-left) + 74px);
    right: calc(var(--safe-right) + 206px);
    height: clamp(34px, 5.8vh, 48px);
    display: grid;
    grid-template-columns: 0.92fr 0.92fr 0.58fr 1.15fr;
    gap: clamp(4px, 0.65vw, 8px);
    align-items: stretch;
    pointer-events: none;
}

.stat-card {
    min-width: 0;
    min-height: 0;
    padding: clamp(4px, 0.7vw, 7px) clamp(6px, 1vw, 10px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: none;
    backdrop-filter: blur(3px);
}

.stat-label {
    color: var(--muted);
    font-size: clamp(7px, 0.85vw, 9px);
    line-height: 1;
    font-weight: 900;
    letter-spacing: 1.3px;
    text-transform: uppercase;
    white-space: nowrap;
}

.stat-value {
    display: inline-block;
    margin-top: 3px;
    color: var(--gold-2);
    font-size: clamp(14px, 2vw, 23px);
    font-weight: 950;
    line-height: 1;
    white-space: nowrap;
    transition: transform 90ms ease, color 90ms ease;
}

.stat-value.pulse {
    transform: scale(1.08);
    color: #fff2a7;
}

.hp-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

#hpText {
    color: var(--gold-2);
    font-size: clamp(9px, 1vw, 12px);
    font-weight: 900;
    white-space: nowrap;
}

#hpBarOuter {
    width: 100%;
    height: clamp(5px, 1.1vh, 8px);
    margin-top: 5px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.72);
    border: 1px solid rgba(58, 43, 14, 0.78);
    border-radius: 999px;
}

#hpBarInner {
    width: 100%;
    height: 100%;
    background: var(--gold);
    transition: width 180ms ease, background 180ms ease;
}

#homeButton,
#musicButton,
#pauseButton {
    position: fixed;
    z-index: 50;
    top: calc(var(--safe-top) + 6px);
    height: clamp(34px, 5.8vh, 48px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: none;
    color: var(--gold-2);
    border-radius: 8px;
    text-decoration: none;
    font-size: clamp(10px, 1.15vw, 13px);
    font-weight: 900;
    transition: background 120ms ease, color 120ms ease, transform 120ms ease;
    backdrop-filter: blur(3px);
}

#homeButton {
    left: calc(var(--safe-left) + 6px);
    width: 62px;
    gap: 5px;
}

#homeButton svg {
    width: 17px;
    height: 17px;
}

#pauseButton {
    right: calc(var(--safe-right) + 6px);
    min-width: 86px;
    padding: 0 9px;
}

#musicButton {
    right: calc(var(--safe-right) + 100px);
    min-width: 96px;
    padding: 0 9px;
}

#homeButton:hover,
#musicButton:hover,
#pauseButton:hover,
#restartButton:hover {
    background: rgba(27, 27, 27, 0.76);
    color: #fff2a7;
    transform: translateY(-1px);
}

.sprite {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    object-fit: contain;
    will-change: transform;
    image-rendering: auto;
    pointer-events: none;
    transform: translate3d(-9999px, -9999px, 0);
}

.player-sprite {
    z-index: 5;
    transform-origin: center bottom;
}

.boss-sprite,
.boss-attack-sprite {
    z-index: 5;
    transform-origin: center center;
}

.boss-attack-sprite {
    z-index: 6;
    display: none;
}

.bomb-sprite {
    z-index: 4;
    transform-origin: center center;
}

.heal-sprite {
    z-index: 4;
    transform-origin: center center;
}

.rare-enemy-sprite {
    z-index: 5;
    transform-origin: center bottom;
}

.effect-sprite {
    z-index: 8;
    animation: effectFade 620ms ease forwards;
}

.float-text {
    position: absolute;
    z-index: 9;
    color: var(--gold-2);
    font-weight: 950;
    font-size: clamp(17px, 2.4vw, 22px);
    -webkit-text-stroke: 2px #000;
    pointer-events: none;
    animation: floatUp 780ms ease-out forwards;
}

.is-paused .effect-sprite,
.is-paused .float-text {
    animation-play-state: paused;
}

@keyframes floatUp {
    from { opacity: 1; transform: translate(-50%, 0) scale(1); }
    to { opacity: 0; transform: translate(-50%, -46px) scale(0.96); }
}

@keyframes effectFade {
    from { opacity: 1; transform: translate(-50%, -50%) scale(0.9); }
    to { opacity: 0; transform: translate(-50%, -50%) scale(1.18); }
}

#startHint {
    position: fixed;
    left: 50%;
    bottom: calc(var(--safe-bottom) + 14px);
    z-index: 38;
    max-width: min(92vw, 820px);
    padding: 7px 12px;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.66);
    border: 0;
    border-radius: 999px;
    color: var(--text);
    font-size: clamp(10px, 1.8vw, 13px);
    font-weight: 800;
    text-align: center;
    opacity: 0.9;
    pointer-events: none;
    transition: opacity 220ms ease, transform 220ms ease;
}

#startHint.hidden-hint {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 44;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.72);
    padding: 20px;
}

.overlay.active {
    display: flex;
}

.loading-overlay {
    z-index: 70;
    background: rgba(0, 0, 0, 0.88);
}

.pause-overlay {
    z-index: 43;
    background: rgba(0, 0, 0, 0.38);
}

.panel,
.gameover-panel,
.pause-panel,
.loading-panel {
    background: var(--panel-strong);
    border: 1px solid rgba(218, 165, 32, 0.15);
    box-shadow: none;
    backdrop-filter: blur(4px);
}

.gameover-panel,
.pause-panel,
.loading-panel {
    width: min(380px, 92vw);
    padding: 26px;
    border-radius: 14px;
    text-align: center;
    animation: modalIn 180ms ease-out;
}

.pause-panel h2,
.gameover-panel h2,
.loading-panel h2 {
    margin-bottom: 14px;
    color: var(--gold-2);
    font-size: clamp(28px, 6vw, 38px);
    letter-spacing: 3px;
}

.pause-panel p,
.loading-panel p {
    color: var(--muted);
    font-weight: 800;
}

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

.final-line {
    font-size: 18px;
    color: var(--text);
}

.best-line {
    margin-top: 6px;
    color: var(--muted);
}

#finalTime,
#finalBestTime {
    color: var(--gold-2);
    font-size: 26px;
    font-weight: 950;
}

#newBestMessage {
    margin-top: 12px;
    color: var(--gold-2);
    font-weight: 950;
    letter-spacing: 2px;
}

.hidden {
    display: none !important;
}

#restartButton {
    width: 100%;
    margin-top: 18px;
    padding: 12px 18px;
    background: rgba(0, 0, 0, 0.82);
    color: var(--gold-2);
    border: 1px solid rgba(218, 165, 32, 0.18);
    border-radius: 8px;
    font-weight: 950;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}

.restart-hint {
    margin-top: 12px;
    color: #888;
    font-size: 12px;
}

#damageOverlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    opacity: 0;
    pointer-events: none;
    background: rgba(139, 0, 0, 0.28);
    transition: opacity 80ms ease;
}

#damageOverlay.active {
    opacity: 1;
}

.screen-shake {
    animation: shake 220ms linear;
}

@keyframes shake {
    0%, 100% { transform: translate3d(0, 0, 0); }
    25% { transform: translate3d(-5px, 0, 0); }
    50% { transform: translate3d(5px, 0, 0); }
    75% { transform: translate3d(-3px, 0, 0); }
}

@media (max-width: 820px) {
    #header {
        top: calc(var(--safe-top) + 48px);
        left: calc(var(--safe-left) + 6px);
        right: calc(var(--safe-right) + 6px);
        height: auto;
        grid-template-columns: 1fr 1fr 0.72fr 1.35fr;
        gap: 4px;
    }

    .stat-card {
        min-height: 32px;
        padding: 4px 6px;
        border-radius: 7px;
    }

    .stat-label {
        font-size: 7px;
        letter-spacing: 1px;
    }

    .stat-value {
        margin-top: 2px;
        font-size: clamp(13px, 4.4vw, 18px);
    }

    #hpText {
        font-size: 9px;
    }

    #hpBarOuter {
        height: 5px;
        margin-top: 3px;
    }

    #homeButton,
    #musicButton,
    #pauseButton {
        height: 36px;
        top: calc(var(--safe-top) + 6px);
    }

    #homeButton {
        width: 38px;
        font-size: 0;
    }

    #musicButton {
        right: calc(var(--safe-right) + 86px);
        min-width: 78px;
        font-size: 10px;
    }

    #pauseButton {
        min-width: 74px;
        font-size: 10px;
    }

    #startHint {
        max-width: 92vw;
        border-radius: 10px;
        bottom: calc(var(--safe-bottom) + 10px);
    }
}

@media (max-width: 470px) {
    #header {
        grid-template-columns: 1fr 1fr 0.62fr;
    }

    #hpContainer {
        grid-column: span 3;
    }
}

@media (max-height: 560px) and (orientation: landscape) {
    #header {
        top: calc(var(--safe-top) + 6px);
        left: calc(var(--safe-left) + 54px);
        right: calc(var(--safe-right) + 162px);
        height: 34px;
        grid-template-columns: 0.95fr 0.95fr 0.6fr 1.25fr;
    }

    .stat-card {
        padding: 4px 7px;
    }

    .stat-label {
        font-size: 7px;
        letter-spacing: 1px;
    }

    .stat-value {
        font-size: 15px;
    }

    #homeButton {
        width: 40px;
        font-size: 0;
    }

    #musicButton {
        right: calc(var(--safe-right) + 82px);
        min-width: 76px;
        font-size: 10px;
    }

    #pauseButton {
        min-width: 72px;
        font-size: 10px;
    }
}
