@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

#game-container {
    --bg-color: #080b12;
    --text-color: #ffffff;
    --ui-bg: rgba(15, 20, 30, 0.9);
    --border-color: #2a3b5c;
    --accent: #4caf50;
}

#game-container, #game-container * {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-drag: none;
}

#game-container {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at center, #111827 0%, var(--bg-color) 100%),
        linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
    background-size: 100% 100%, 64px 64px, 64px 64px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Press Start 2P', monospace;
    color: var(--text-color);
}

/* Fills its host outright -- no letterbox frame. The arena is drawn at
   a fixed 64px tile and the camera scrolls, so a larger window reveals
   more of the map rather than scaling it down. */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #111;
    overflow: hidden;
}

/* resize() matches the backing store to the display's real pixels, so
   the browser does no rescaling here and this setting is a no-op safety
   net. Texel edges stay hard because textures are magnified
   nearest-neighbour internally. */
#game-container canvas {
    display: block;
    image-rendering: auto;
}

/* The UI now lives in real CSS pixels alongside a window-sized canvas,
   so it needs no scaling of its own. */
.overlay-screen {
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* A full-width solid dark-gray beam across the top. Solid colour plus a
   sheen gradient, and a whisper of monochrome grain from a
   stitched SVG turbulence tile at ~6% alpha -- roughness you feel, not see,
   so the colour scheme stays untouched. Bottom lip is exactly 1px. */
.hud {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 12px;
    padding: 6px 16px;
    background-color: #323438;
    background-image:
        linear-gradient(115deg,
            rgba(255, 255, 255, 0.07) 0%,
            rgba(255, 255, 255, 0.02) 35%,
            rgba(0, 0, 0, 0) 60%),
        linear-gradient(180deg,
            rgba(255, 255, 255, 0.06) 0%,
            rgba(0, 0, 0, 0) 45%,
            rgba(0, 0, 0, 0.22) 100%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='64' height='64'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/><feComponentTransfer><feFuncA type='linear' slope='0.06' intercept='0'/></feComponentTransfer></filter><rect width='64' height='64' filter='url(%23n)'/></svg>");
    background-size: auto, auto, 64px 64px;
    /* Polished top edge, a hairline 1px base, soft drop onto the map. */
    box-shadow:
        0 6px 16px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.10),
        inset 0 -1px 0 rgba(0, 0, 0, 0.4);
    text-transform: uppercase;
}

.mc-head {
    width: 34px;
    height: 34px;
    flex: none;
    position: relative;
    border: 3px solid #0b0b0b;
    box-shadow: inset 2px 2px 0 rgba(255,255,255,0.22), inset -2px -3px 0 rgba(0,0,0,0.38);
}

/* Dynamic head colors applied via inline styles in JS */

/* Brow band + eyes, the two marks that read as a Minecraft face. */
.mc-head::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 8px;
    background: rgba(0, 0, 0, 0.32);
}

.mc-head::after {
    content: '';
    position: absolute;
    top: 12px; left: 5px;
    width: 6px; height: 6px;
    background: var(--head-eye-color, #14141c);
    box-shadow: 12px 0 0 var(--head-eye-color, #14141c);
}

/* Hero Selection UI */
.hero-options { display: flex; gap: 20px; justify-content: flex-start; margin: 20px 0; overflow-x: auto; max-width: 90vw; padding-bottom: 15px; }
.hero-options::-webkit-scrollbar { height: 10px; }
.hero-options::-webkit-scrollbar-thumb { background: #666; border-radius: 5px; }
.hero-options::-webkit-scrollbar-track { background: rgba(0,0,0,0.3); border-radius: 5px; }
.hero-card { background: rgba(0,0,0,0.5); border: 2px solid #555; padding: 20px; cursor: pointer; transition: all 0.2s; display: flex; flex-direction: column; align-items: center; min-width: 80px; flex-shrink: 0; }
.hero-card:hover { border-color: #fff; background: rgba(255,255,255,0.1); }
.hero-card.selected { border-color: #4caf50; background: rgba(76,175,80,0.2); box-shadow: 0 0 15px rgba(76,175,80,0.5); }
.hero-card .mc-head { transform: scale(1.5); margin-bottom: 15px; }

.hud-name {
    font-size: 11px;
    letter-spacing: 1px;
    color: #ece9e4;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 7px;
}

/* Each fighter's slot in the top line: name over a small lives bar. */
.hud-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 0;
    flex: 1 1 0;
}

/* Hero face sits above the name; a touch smaller than the selection-card
   head so the top bar stays compact. */
.hud-slot .mc-head {
    width: 26px;
    height: 26px;
}

.hud-slot.dead .mc-head { filter: grayscale(1) brightness(0.5); }

.hud-slot .hud-name {
    font-size: 10px;
    margin: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hud-slot.dead .hud-name { color: #8a7a6a; text-decoration: line-through; }

/* Lives as a compact segmented HP bar; --hp is the fill fraction 0..1
   and --hp-color its colour, both set from updateUI. Segment ticks are a
   repeating gradient so any max-lives count divides cleanly. */
.hpbar {
    width: 74px;
    max-width: 100%;
    height: 9px;
    background: #2b211a;
    border: 2px solid #17110a;
    box-shadow: inset 1px 1px 0 rgba(0,0,0,0.5);
    position: relative;
    image-rendering: pixelated;
}

.hpbar::before {
    content: '';
    position: absolute;
    inset: 0;
    width: calc(var(--hp, 1) * 100%);
    background: var(--hp-color, #5fbf3a);
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.3);
}

.hpbar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent 0,
        transparent calc(100% / var(--hp-segs, 3) - 1px),
        rgba(0,0,0,0.55) calc(100% / var(--hp-segs, 3) - 1px),
        rgba(0,0,0,0.55) calc(100% / var(--hp-segs, 3))
    );
}

/* Centre-screen timer: crisp and fully opaque while shown; JS drives the
   opacity (0.8s fades) per match phase. pointer-events none so it never
   blocks the game. .doom paints the final countdown and banner red. */
.hud-center-timer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.timer-label {
    font-size: 14px;
    color: #ffd83d;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 8px;
}

.timer-clock {
    font-size: 52px;
    color: #fff;
    letter-spacing: 4px;
    text-shadow: 4px 4px 0 #000, 0 0 24px rgba(255, 255, 255, 0.25);
}

.hud-center-timer.doom .timer-label { color: #ff5030; }
.hud-center-timer.doom .timer-clock {
    color: #ff5030;
    text-shadow: 4px 4px 0 #000, 0 0 32px rgba(255, 60, 30, 0.55);
    /* Final-10 heartbeat: one thump per second, in step with the ticks. */
    animation: doomPulse 1s ease-in-out infinite;
}

@keyframes doomPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.1); }
}

@media (max-width: 640px) {
    .timer-label { font-size: 10px; }
    .timer-clock { font-size: 36px; }
}

/* Overlay Screens */
.overlay-screen {
    position: absolute;
    top: 0; left: 0;
    background: rgba(12, 16, 23, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.5s ease;
    pointer-events: auto;
}

.hidden { opacity: 0; pointer-events: none; }

.progress-bar {
    width: 400px;
    height: 24px;
    border: 4px solid #fff;
    margin-top: 30px;
    padding: 2px;
    background: #000;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.2);
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.1s;
    box-shadow: inset 0 -5px 0 rgba(0,0,0,0.2);
}

h1.title {
    font-size: 48px;
    text-shadow: 6px 6px 0 #000, 0 0 30px rgba(255,255,255,0.2);
    margin-bottom: 20px;
    text-align: center;
    line-height: 1.5;
}

.btn {
    margin-top: 40px;
    padding: 20px 40px;
    background: var(--accent);
    border: 4px solid #fff;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 20px;
    cursor: pointer;
    box-shadow: inset 0 -6px 0 rgba(0,0,0,0.3), 0 10px 0 #000;
    text-transform: uppercase;
    transition: all 0.1s;
}

.btn:hover { background: #66bb6a; transform: translateY(2px); box-shadow: inset 0 -4px 0 rgba(0,0,0,0.3), 0 8px 0 #000; }
.btn:active { transform: translateY(10px); box-shadow: inset 0 0 0 rgba(0,0,0,0.3), 0 0 0 #000; }

/* ==========================================================================
   Touch controls: fixed joystick (bottom-left) + TNT button (bottom-right).
   Hidden on desktops -- shown only on coarse pointers, or when JS detected a
   touchscreen (body.touch). pointer-events is set on these two elements only,
   so the rest of the (pointer-events: none) UI layer never blocks the canvas.
   ========================================================================== */
#game-container canvas { touch-action: none; }

#joystick, #btn-bomb { display: none; }

@media (pointer: coarse) {
    #joystick, #btn-bomb { display: block; }
}
body.touch #joystick, body.touch #btn-bomb { display: block; }

#joystick {
    position: absolute;
    left: 24px;
    bottom: 24px;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    border: 3px solid rgba(255, 255, 255, 0.25);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    touch-action: none;
    -webkit-touch-callout: none;
    z-index: 20;
}

/* Centred via negative margins, so the JS transform is a pure offset from
   the middle -- (0,0) means "knob at rest in the centre". */
#joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 56px;
    height: 56px;
    margin-left: -28px;
    margin-top: -28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    border: 3px solid rgba(255, 255, 255, 0.45);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), inset 0 3px 0 rgba(255, 255, 255, 0.25);
}

/* Round TNT drop button; the icon is the engine's own baked TNT top face
   (--tex-tnt), so it matches the blocks on the field. */
#btn-bomb {
    position: absolute;
    right: 28px;
    bottom: 36px;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background-color: rgba(178, 34, 34, 0.55);
    background-image: var(--tex-tnt, none);
    background-size: 56px 56px;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: pixelated;
    border: 4px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    touch-action: none;
    -webkit-touch-callout: none;
    z-index: 20;
}

#btn-bomb:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
