/* The HUD's design tokens. Declared on :root because three of the buttons they
   paint (the settings gear, the pause toggle, the dock-side arrow) are fixed
   and live OUTSIDE #game-container, where the lobby is still in the document. */
        :root {
            --gold: #f3d98b;
            --gold-hi: #fff0b8;
            --gold-lo: #d9a441;
            --ink: #f7efe0;
            --mut: #b9a9d8;
            --line: rgba(243, 217, 139, 0.34);
            --panel-a: rgba(28, 19, 64, 0.93);
            --panel-b: rgba(15, 10, 36, 0.93);
            --hud-display: "Cinzel", Georgia, serif;
            --hud-ui: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
            --hud-radius: 14px;
            --hud-shadow: 0 6px 24px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.08);
        }

        #entity-overlay {
            /* one 2D canvas for all enemy health bars (below the player
               nametags at z-index 10, above the WebGL canvas); it must
               never intercept the pointer */
            position: absolute;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            z-index: 5;
            pointer-events: none;
        }

        /* ------------------------------------------------------------- HUD */
        /* bottom-LEFT column (unit frame under, loadout above): the
           bottom-center belongs to the ability dock and the bottom-right to
           the minimap. column-reverse keeps the markup in reading order while
           the frame - the panel a pilot reads most - owns the screen corner. */
        #hud {
            position: absolute;
            bottom: calc(16px + env(safe-area-inset-bottom, 0px));
            left: calc(16px + env(safe-area-inset-left, 0px));
            display: none;
            flex-direction: column-reverse;
            align-items: flex-start;
            gap: 10px;
            z-index: 50;
            font-family: var(--hud-ui);
            user-select: none;
            -webkit-user-select: none;
        }

        .hud-panel {
            background-image: linear-gradient(160deg, var(--panel-a), var(--panel-b));
            border: 1px solid var(--line);
            border-radius: var(--hud-radius);
            padding: 12px 14px;
            box-shadow: var(--hud-shadow);
            color: var(--ink);
            font-family: var(--hud-ui);
        }

        .hud-panel-title {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            font-family: var(--hud-display);
            font-size: 11px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.12em;
            color: var(--gold);
            margin-bottom: 8px;
        }

        /* ------------------------------------------------ unit frame */
        #hud-status {
            display: flex;
            flex-direction: column;
            gap: 6px;
            /* FIXED width: the buff chips are capped to this width, so the panel
               (and the centered HUD) can never grow/shrink or re-center while
               playing, no matter how many buffs are stacked */
            width: 320px;
        }

        .uf {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .uf-portrait {
            position: relative;
            flex: none;
            width: 64px;
            height: 64px;
            border-radius: 50%;
            padding: 3px;
            /* the XP ring: --xp is this run's progress to the next level, written
               by hud.js beside the XP bar; the badge below prints the level */
            background: conic-gradient(var(--gold) calc(var(--xp, 0) * 360deg), rgba(255, 255, 255, 0.14) 0);
        }

        .uf-portrait > img {
            display: none;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            border: 2px solid #0f0a24;
            background-color: #2a1546;
            object-fit: cover;
        }

        .uf-mono {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            border: 2px solid #0f0a24;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: var(--hud-display);
            font-size: 22px;
            font-weight: 800;
            color: var(--gold);
            background-image: linear-gradient(135deg, #7a5cff, #2a1546);
        }

        .uf-portrait.has-art > img { display: block; }

        .uf-portrait.has-art > .uf-mono { display: none; }

        #hud-level {
            position: absolute;
            right: -8px;
            bottom: -4px;
            min-width: 28px;
            padding: 0 6px;
            height: 22px;
            border-radius: 11px;
            background-image: linear-gradient(180deg, var(--gold-hi), var(--gold-lo));
            color: #2a1546;
            border: 2px solid #0f0a24;
            font-family: var(--hud-display);
            font-size: 12px;
            font-weight: 800;
            line-height: 18px;
            text-align: center;
        }

        .uf-body {
            flex: 1 1 auto;
            min-width: 0;
            display: grid;
            gap: 5px;
        }

        #hud-topline {
            display: flex;
            align-items: baseline;
            gap: 8px;
            font-family: var(--hud-display);
            letter-spacing: 0.04em;
        }

        #hud-name {
            font-size: 14px;
            font-weight: 700;
            color: var(--ink);
            text-shadow: 0 1px 2px #000;
            flex-grow: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            max-width: 150px;
        }

        #hud-gold {
            font-size: 13px;
            font-weight: 700;
            color: var(--gold);
            text-shadow: 0 1px 2px #000;
            white-space: nowrap;
        }

        .bar {
            position: relative; /* the label renders INSIDE the bar */
            width: 100%;
            height: 18px;
            background-color: rgba(0, 0, 0, 0.55);
            border: 1px solid rgba(255, 255, 255, 0.14);
            border-radius: 99px;
            overflow: hidden;
            box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
        }

        .bar-inner {
            height: 100%;
            width: 100%;
            border-radius: 99px;
            transition: width 0.15s;
        }

        #hp-bar-inner { background-image: linear-gradient(180deg, #5dffa8, #16a864); }

        .bar.xp { height: 12px; }

        #xp-bar-inner { width: 0%; background-image: linear-gradient(90deg, #8f6fd8, var(--gold)); }

        #mana-bar-inner { background-image: linear-gradient(180deg, #8cc4ff, #3a6cff); }

        /* the pool the next hit can end: the fill's own colour is owned by
           combat_text.js (the shield band), so the warning is drawn on the
           track, not on the fill */
        .bar.hp.low {
            border-color: rgba(255, 106, 106, 0.8);
            box-shadow: 0 0 10px rgba(208, 42, 74, 0.55), inset 0 1px 3px rgba(0, 0, 0, 0.6);
        }

        .bar.hp.low .bar-label { color: #ffc4c4; }

        .bar-label {
            position: absolute;
            left: 0;
            right: 0;
            top: 50%;
            transform: translateY(-50%);
            text-align: center;
            font-size: 11px;
            font-weight: 700;
            color: #fff;
            line-height: 1;
            white-space: nowrap;
            pointer-events: none;
            text-shadow: 0 1px 2px #000, 0 0 4px rgba(0, 0, 0, 0.7);
        }

        .bar.xp .bar-label { font-size: 9px; }

        #buff-row {
            display: flex;
            flex-wrap: wrap;
            gap: 4px;
            /* FIXED height (no min/max pair): the row must never grow or shrink
               with the buff count. With min-height it was 18px for <=1 line and
               40px once chips wrapped, which popped the whole panel (and the
               centered HUD) by ~22px every time the second line appeared.
               40px fits 2 lines (~2 * 18px + 4px gap); 3+ lines scroll inside. */
            height: 40px;
            align-content: center; /* <=2 lines: vertically centered; a 3rd+ line has no free space, so it top-aligns and scrolls */
            overflow-x: hidden;
            overflow-y: auto;
            scrollbar-width: none; /* Firefox: hide but keep scrollable */
        }

        #buff-row::-webkit-scrollbar { display: none; }

        .buff-chip {
            font-size: 11px;
            font-weight: 700;
            background-color: rgba(0, 0, 0, 0.45);
            border: 1px solid rgba(185, 169, 216, 0.4);
            border-radius: 99px;
            padding: 1px 8px;
            color: var(--ink);
            /* long labels truncate instead of forcing the row/panel wider */
            min-width: 0;
            max-width: 100%;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        /* match-long chest buffs (last until the match ends) */
        .buff-chip.match {
            background-color: rgba(74, 55, 8, 0.7);
            border-color: var(--gold);
            color: var(--gold-hi);
        }

        .buff-chip.trait {
            background-color: rgba(74, 22, 8, 0.7);
            border-color: #d98a4a;
            color: #ffcf9a;
        }

        .buff-chip.tower {
            background-color: rgba(10, 40, 44, 0.7);
            border-color: #4ad0d9;
            color: #b6f0ff;
        }

        .buff-chip.terrain {
            background-color: rgba(20, 34, 20, 0.7);
            border-color: #6cc98a;
            color: #d8ffe4;
        }

        /* weapons panel ---------------------------------------------------
           An ICON GRID, not a list of rows: a fighter carries up to
           MAX_WEAPONS (20 = game_logic/data/weapons.py MAX_EXTRA_WEAPONS + 1)
           and twenty labelled rows would own the whole bottom edge of the
           screen. A slot IS the item: its card art (data/weapons.py "icon"),
           its level pip, its rarity ring, its signature / evolved marks. The
           name, the one-line rule, the cooldown and the scaling are the slot's
           tooltip (public/hud.js weaponTooltip). */
        #hud-weapons { width: 320px; }

        #weapon-count { white-space: nowrap; }

        #weapon-list {
            display: grid;
            /* 8 slots a row: twenty weapons land in two rows, and the panel
               never grows past its own width */
            grid-template-columns: repeat(8, 32px);
            gap: 4px;
        }

        .weapon-slot {
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            background-color: rgba(0, 0, 0, 0.45);
            border: 1px solid rgba(255, 255, 255, 0.16);
            border-radius: 8px;
            cursor: default;
        }

        /* item card art (public/assets/images/items): the 40px icon drawn at
           the slot's own size - pixelated so it stays crisp instead of being
           resampled by half a pixel */
        .weapon-icon {
            width: 28px;
            height: 28px;
            border-radius: 5px;
            image-rendering: pixelated;
        }

        /* a weapon row with no art (no "icon" in data/weapons.py) still holds
           its cell and shows its initial instead of an empty box */
        .weapon-icon-empty {
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 13px;
            font-weight: bold;
            color: #9a94b8;
            background-color: rgba(255, 255, 255, 0.06);
        }

        /* the level pip sits in the slot's corner; an EVOLVED weapon shows a
           star there instead (it is maxed, so the number says nothing) */
        .weapon-level {
            position: absolute;
            right: 2px;
            bottom: -1px;
            font-size: 10px;
            font-weight: bold;
            color: var(--gold);
            pointer-events: none;
            text-shadow: 0 1px 2px #000, 0 0 3px #000;
        }

        /* rarity ring: the SAME tier hues the level-up cards use
           (windows.css .lu-rarity) - an offer and the slot it became should
           read alike. Declared before the signature / evolved rules on
           purpose: those outrank a rarity colour. */
        .weapon-slot.rarity-common    { border-color: #9aa7b8; }
        .weapon-slot.rarity-uncommon  { border-color: #7dffa8; }
        .weapon-slot.rarity-rare      { border-color: #6db3ff; }
        .weapon-slot.rarity-epic      { border-color: #c58aff; }
        .weapon-slot.rarity-legendary { border-color: #ffb347; }
        .weapon-slot.rarity-mythic    { border-color: #ff6d8a; }

        .weapon-slot.weapon-signature {
            border-color: var(--gold-lo);
        }

        .weapon-slot.weapon-evolved {
            border-color: var(--gold);
            box-shadow: 0 0 8px rgba(243, 217, 139, 0.4);
        }

        /* weapons panel: collapsible via its title (collapsed only when the
           player left it that way - see lobby.js initWeaponsCollapse) */
        #hud-weapons .hud-panel-title {
            cursor: pointer;
            user-select: none;
            touch-action: manipulation;
        }

        #hud-weapons .hud-panel-title::after { content: " \25BE"; color: var(--gold); }

        #hud-weapons.collapsed .hud-panel-title::after { content: " \25B8"; }

        #hud-weapons.collapsed #weapon-list { display: none; }

        /* --------------------------------------------------------- minimap */
        #minimap {
            position: absolute;
            bottom: calc(16px + env(safe-area-inset-bottom, 0px));
            right: calc(16px + env(safe-area-inset-right, 0px));
            width: 200px;
            height: 200px;
            background-color: rgba(10, 6, 24, 0.82);
            border: 2px solid rgba(243, 217, 139, 0.55);
            border-radius: var(--hud-radius);
            box-shadow: var(--hud-shadow);
            z-index: 50;
            display: none;
            cursor: crosshair;  /* click / right-click = walk to point */
        }

        /* --------------------------------------------------------- chat */
        /* raised above the bottom-left status/weapon HUD */
        #chat-container {
            position: absolute;
            bottom: 268px;
            left: 0px;
            width: 12em;
            height: 5em;
            background-color: rgba(10, 6, 24, 0.6);
            border: 1px solid var(--line);
            border-radius: 0 10px 10px 0;
            z-index: 50;
            display: flex;
            flex-direction: column;
        }

        #chat-messages {
            flex-grow: 1;
            overflow-y: auto;
            padding: 5px;
            font-size: 0.7em;
            color: var(--ink);
        }

        #chat-input {
            width: 100%;
            background-color: rgba(10, 6, 24, 0.85);
            border: none;
            color: var(--ink);
            padding: 5px;
            box-sizing: border-box;
            display: none;
        }

        /* ------------------------------------------------------ debug info */
        #debug-info {
            position: absolute;
            top: 64px; /* below the ability-side toggle */
            right: 10px;
            z-index: 50;
            font-size: 12px;
            background-color: rgba(10, 6, 24, 0.55);
            border: 1px solid var(--line);
            border-radius: 8px;
            padding: 5px 8px;
        }

        /* ------------------------------------------------------ wave banner */
        #wave-banner {
            position: absolute;
            top: 12px;
            left: 50%;
            transform: translateX(-50%);
            text-align: center;
            z-index: 50;
            background-image: linear-gradient(160deg, var(--panel-a), var(--panel-b));
            border: 1px solid var(--line);
            border-radius: 99px;
            padding: 5px 20px;
            display: none;
        }

        #wave-text {
            font-family: var(--hud-display);
            font-size: 17px;
            font-weight: 700;
            letter-spacing: 0.08em;
            color: var(--gold);
            text-shadow: 0 1px 3px #000;
        }

        #wave-enemies { font-size: 12px; color: var(--mut); }

        /* --------------------------------------------------------- nametags */
        /* game UI text is never selected by accident (mobile long-press /
           swipe; the lobby - outside #game-container - keeps selection) */
        #game-container div {
            user-select: none;
            -webkit-user-select: none;
        }

        .nametag {
            position: absolute;
            background-color: rgba(10, 6, 24, 0.82);
            border: 1px solid var(--line);
            color: var(--ink);
            padding: 3px 8px;
            border-radius: 8px;
            font-size: 14px;
            font-weight: bold;
            white-space: nowrap;
            transform: translate(-50%, -50%);
            z-index: 10;
            text-shadow: 0 1px 2px #000;
            pointer-events: none; /* touch through to the canvas (joystick) */
        }

        .nametag.dead { color: #ff9090; }

        /* Twilight Shroud (Akali's W, game_logic/kits/akali_kit.py). The cloud itself is
           drawn on the floor (client_zone.js kind "shroud"), and her body is not
           hidden from the party - the rig's materials are SHARED with every other
           clone of it (model_loader.js pools), so a per-instance opacity write would
           fade everyone wearing the model. The dimmed tag is the honest half: the
           server cannot pick her out either (game_logic/systems/navigation.py), so
           the tag that points at her position dims with the targeting. */
        .nametag.stealthed,
        .healthbar.stealthed {
            opacity: 0.32;
        }

        .healthbar {
            position: absolute;
            width: 46px;
            height: 5px;
            background-color: rgba(0, 0, 0, 0.6);
            border: 1px solid #00000080;
            border-radius: 3px;
            transform: translate(-50%, -50%);
            z-index: 10;
            pointer-events: none;
        }

        /* room-pause banner: rendered from the `paused` broadcast only */
        #paused-banner {
            position: absolute;
            top: 12px;
            left: 50%;
            transform: translateX(-50%);
            z-index: 62;
            background-color: rgba(42, 21, 70, 0.9);
            border: 1px solid var(--gold-lo);
            border-radius: 99px;
            padding: 6px 18px;
            font-family: var(--hud-display);
            letter-spacing: 0.08em;
            font-size: 13px;
            font-weight: 700;
            color: var(--gold-hi);
            display: none;
            white-space: nowrap;
        }

        /* targeting chip (status panel, under the bars) */
        #target-row {
            margin-top: 6px;
            font-size: 11px;
            line-height: 1.2;
            color: var(--mut);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        #target-row .target-label { color: #8a86a8; }

        #target-chip { color: #c3bcda; }

        /* the Z-cycled target rule (game_logic/systems/targeting.py) */
        #target-mode-chip { color: #9ad0ff; }

        #target-chip.has-target { color: #ff8fa3; font-weight: 700; }
