/* ===== Mini-Game: Ambush ===== */

body.mg-body {
    background: #000;
    overflow: hidden;
    overscroll-behavior: contain;
    touch-action: none;
    -webkit-user-select: none;
            user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mg {
    position: fixed; inset: 0;
    overflow: hidden;
}

#mgCanvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    display: block;
    background: #0a0b10;
}

/* ===== HUD ===== */
.mg-hud {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 1rem 1rem 0;
    pointer-events: none;
    z-index: 10;
}
.mg-lives {
    display: inline-flex; gap: 6px;
    padding: 0.45rem 0.65rem;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    backdrop-filter: blur(6px);
}
.mg-heart {
    width: 22px; height: 20px;
    display: block;
    background: #ef4040;
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 21s-7-4.5-9.5-9a5.5 5.5 0 0 1 9.5-5 5.5 5.5 0 0 1 9.5 5C19 16.5 12 21 12 21z'/></svg>") center/contain no-repeat;
            mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 21s-7-4.5-9.5-9a5.5 5.5 0 0 1 9.5-5 5.5 5.5 0 0 1 9.5 5C19 16.5 12 21 12 21z'/></svg>") center/contain no-repeat;
    transition: opacity 0.25s, transform 0.25s, background 0.25s;
    filter: drop-shadow(0 0 6px rgba(239,64,64,0.55));
}
.mg-heart.gone {
    background: #444;
    opacity: 0.35;
    transform: scale(0.8);
    filter: none;
}
.mg-hud-right { text-align: right; }
.mg-label {
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    color: rgba(255,255,255,0.55);
    font-weight: 700;
}
.mg-score {
    font-size: 1.4rem;
    font-weight: 900;
    color: #fff;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 10px rgba(255,255,255,0.25);
    padding: 0.25rem 0.65rem;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    backdrop-filter: blur(6px);
    min-width: 70px;
}

/* ===== Crosshair (fixed center) ===== */
.mg-crosshair {
    position: absolute; top: 50%; left: 50%;
    width: 40px; height: 40px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 20;
}
.mg-crosshair-dot {
    position: absolute; top: 50%; left: 50%;
    width: 4px; height: 4px;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(255,255,255,0.6);
}
.mg-crosshair-ring {
    position: absolute; inset: 0;
    border: 1.5px solid rgba(255,255,255,0.45);
    border-radius: 50%;
    transition: transform 0.1s, border-color 0.15s;
}
.mg.fire .mg-crosshair-ring {
    animation: mg-fire-ring 0.18s ease-out;
}
@keyframes mg-fire-ring {
    0%   { transform: scale(1);   border-color: rgba(255,255,255,0.45); }
    50%  { transform: scale(1.4); border-color: rgba(255,255,120,0.9); }
    100% { transform: scale(1);   border-color: rgba(255,255,255,0.45); }
}

/* ===== Damage flash ===== */
.mg-damage {
    position: absolute; inset: 0;
    pointer-events: none;
    z-index: 15;
    background: radial-gradient(ellipse at center, transparent 35%, rgba(239,64,64,0.55) 100%);
    opacity: 0;
    transition: opacity 0.15s;
}
.mg-damage.active { animation: mg-damage-flash 0.7s ease-out; }
@keyframes mg-damage-flash {
    0%   { opacity: 0; }
    15%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ===== Player-death black fade ===== */
.mg-deathfade {
    position: absolute; inset: 0;
    z-index: 28;
    background: #000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1s ease-in;
}
.mg-deathfade.show { opacity: 1; pointer-events: auto; }

/* ===== Back button ===== */
.mg-back {
    position: absolute; top: 1rem; left: 50%;
    transform: translateX(-50%);
    width: 44px; height: 44px;
    display: grid; place-items: center;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    backdrop-filter: blur(6px);
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: 700;
    z-index: 10;
}
.mg-back:hover { background: rgba(0,0,0,0.75); }

/* ===== Joystick ===== */
.mg-joystick {
    position: absolute;
    bottom: 1.5rem; left: 1.5rem;
    width: 140px; height: 140px;
    z-index: 25;
    touch-action: none;
}
.mg-joystick-ring {
    position: absolute; inset: 0;
    border: 2px solid rgba(255,255,255,0.18);
    border-radius: 50%;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
}
.mg-joystick-inner {
    position: absolute; top: 50%; left: 50%;
    width: 56px; height: 56px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle at 30% 30%, #fff, #999 60%, #555 100%);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
    transition: background 0.15s;
    will-change: transform;
}
.mg-joystick.active .mg-joystick-inner {
    background: radial-gradient(circle at 30% 30%, #ffe280, #d4a017 60%, #8a6a24 100%);
}

/* ===== Shoot button ===== */
.mg-shoot {
    position: absolute;
    bottom: 1.5rem; right: 1.5rem;
    width: 110px; height: 110px;
    display: grid; place-items: center;
    background: radial-gradient(circle at 30% 30%, #ff7070, #c01f1f 70%, #6a0e0e 100%);
    border: 3px solid rgba(255,255,255,0.25);
    border-radius: 50%;
    color: #fff;
    font-weight: 900;
    font-size: 1.05rem;
    letter-spacing: 0.1em;
    box-shadow: 0 8px 20px rgba(192,31,31,0.5), inset 0 -6px 12px rgba(0,0,0,0.3);
    cursor: pointer;
    z-index: 25;
    touch-action: manipulation;
    transition: transform 0.08s;
}
.mg-shoot:active,
.mg-shoot.pressed {
    transform: scale(0.92);
    background: radial-gradient(circle at 30% 30%, #ffaaaa, #d43535 70%, #7a1515 100%);
    box-shadow: 0 4px 12px rgba(192,31,31,0.5), inset 0 -2px 8px rgba(0,0,0,0.3);
}
.mg-shoot-label { pointer-events: none; }

/* ===== Start overlay ===== */
.mg-start {
    position: absolute; inset: 0; z-index: 30;
    display: grid; place-items: center;
    background: rgba(0,0,0,0.82);
    backdrop-filter: blur(8px);
    padding: 1rem;
}
.mg-start[hidden] { display: none; }
.mg-start-inner {
    max-width: 440px; text-align: center;
    padding: 2rem 1.75rem;
    background: linear-gradient(180deg, rgba(127,90,240,0.12), rgba(0,0,0,0.4));
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px;
}
.mg-start-title {
    font-size: clamp(2.25rem, 8vw, 3.25rem);
    font-weight: 900;
    letter-spacing: 0.12em;
    background: linear-gradient(135deg, #fff, #d4a017);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
    font-family: 'Impact', 'Arial Black', sans-serif;
}
.mg-start-sub {
    color: rgba(255,255,255,0.75);
    margin-bottom: 1rem;
    font-size: 0.95rem;
}
.mg-start-controls {
    list-style: none; padding: 0; margin: 0 0 1.5rem;
    text-align: left;
    display: flex; flex-direction: column; gap: 0.4rem;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
}
.mg-start-controls strong { color: #fff; }

/* ===== Game over overlay ===== */
.mg-over {
    position: absolute; inset: 0; z-index: 30;
    display: grid; place-items: center;
    background: rgba(0,0,0,0.88);
    backdrop-filter: blur(10px);
    padding: 1rem;
}
.mg-over[hidden] { display: none; }
.mg-over-inner {
    max-width: 420px; text-align: center;
    padding: 2.5rem 2rem;
    background: linear-gradient(180deg, rgba(239,64,64,0.15), rgba(0,0,0,0.4));
    border: 1px solid rgba(239,64,64,0.3);
    border-radius: 16px;
    animation: mg-over-in 0.4s ease;
}
@keyframes mg-over-in {
    from { opacity: 0; transform: scale(0.9); }
    to   { opacity: 1; transform: scale(1); }
}
.mg-over-title {
    font-size: clamp(1.75rem, 6vw, 2.5rem);
    font-weight: 900;
    letter-spacing: 0.1em;
    color: #ef4040;
    text-shadow: 0 0 20px rgba(239,64,64,0.5);
    margin-bottom: 1rem;
    font-family: 'Impact', 'Arial Black', sans-serif;
}
.mg-over-score {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: rgba(255,255,255,0.8);
}
.mg-over-score span {
    font-weight: 900; color: #fff;
    font-variant-numeric: tabular-nums;
    font-size: 1.5rem;
    margin-left: 0.5rem;
}
.mg-over-actions {
    display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap;
}

/* ===== Screen shake on damage ===== */
.mg.shake #mgCanvas { animation: mg-shake 0.4s; }
@keyframes mg-shake {
    0%, 100% { transform: translate(0, 0); }
    15% { transform: translate(-8px, 4px); }
    30% { transform: translate(6px, -4px); }
    45% { transform: translate(-4px, -2px); }
    60% { transform: translate(4px, 3px); }
    75% { transform: translate(-2px, -1px); }
}

/* ===== Mobile portrait tweaks ===== */
@media (max-width: 520px) {
    .mg-joystick { width: 110px; height: 110px; bottom: 1rem; left: 1rem; }
    .mg-joystick-inner { width: 46px; height: 46px; }
    .mg-shoot { width: 90px; height: 90px; bottom: 1rem; right: 1rem; font-size: 0.95rem; }
    .mg-hud { padding: 0.75rem 0.75rem 0; }
    .mg-back { width: 38px; height: 38px; top: 0.75rem; }
}
