:root { color-scheme: dark; --plum: #211829; --ink: #110f1c; --gold: #f5c76a; --cream: #fff0da; --muted: #d8c9d4; --teal: #466b82; }
  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  html, body { margin: 0; height: 100%; overflow: hidden; background: var(--plum); color: var(--cream); font: 15px/1.45 system-ui, -apple-system, sans-serif; }
  button, input { font: inherit; }
  button { cursor: pointer; }
  #box { position: fixed; inset: 0; }
  #game3d { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
  #play { position: fixed; left: 50%; top: 58%; transform: translate(-50%,-50%);
    background: #211829e8; border: 1px solid #f5c76a9c; color: var(--cream);
    border-radius: 999px; padding: 12px 24px; font-weight: 650; box-shadow: 0 4px 22px #110f1c73; }
  #play:hover, #play:focus-visible { border-color: var(--gold); background: #34223c; }
  #load { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
    background: radial-gradient(ellipse at 50% 38%, #3e2b4b 0%, #211829 63%, #14111d 100%);
    text-align: center; padding: 24px; }
  .load-inside { width: min(440px, 78vw); }
  #load img { display: block; width: min(100%, 360px); max-height: 50vh; object-fit: contain; margin: 0 auto 9px; }
  #msg { font-size: 14px; color: var(--muted); }
  #bar { width: min(240px, 75%); height: 5px; margin: 14px auto 0; border-radius: 999px; overflow: hidden; background: #55435f; }
  #bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg,#72b4ba,#f5c76a); transition: width .3s; border-radius: inherit; }
  #load p { color: #c9b6be; font-size: 12px; margin: 11px 0 0; }
  @media (max-height: 450px) { #load img { max-height: 39vh; } }

#teamSelect { position:fixed; inset:0; z-index:28; display:grid; place-items:center;
    background:#110f1ce9; }
  #teamSelect[hidden] { display:none; }
  #teamSelect .teamChoices { display:flex; gap:20px; }
  #teamSelect button { width:108px; height:108px; border-radius:22px; border:2px solid #ffffff6b;
    font-size:38px; font-weight:750; color:white; background:#366ca9; }
  #teamSelect button[data-team="B"] { background:#b65b48; }
  #teamSelect button:focus-visible { outline:3px solid #f5c76a; outline-offset:4px; }
  @media (max-height:450px) { #teamSelect button { width:88px; height:78px; } }

#keys { position: fixed; right: 18px; bottom: 57px; width: min(320px, calc(100vw - 36px));
    padding: 12px 15px; z-index: 5; background: #211829ec; border: 1px solid #110f1ccc;
    border-radius: 13px; box-shadow: 0 8px 24px #110f1c44; pointer-events: none;
    color: var(--muted); font-size: 12px; }
  #keys strong { color: var(--cream); font-size: 14px; font-weight: 650; }
  #keys p { margin: 7px 0 0; line-height: 1.8; }
  kbd { display: inline-block; min-width: 20px; padding: 0 4px; border-radius: 5px;
    border: 1px solid #a68f9a66; background: #46374699; color: var(--cream);
    font: 600 11px/19px system-ui, sans-serif; text-align: center; }

#coopOverlay {position:fixed;inset:0;z-index:7;pointer-events:none;}
  .touch #coopStrip {position:absolute;top:max(8px,env(safe-area-inset-top));left:50%;transform:translateX(-50%);
    width:min(400px,calc(100% - 64px));min-height:42px;padding:4px 8px;display:flex;gap:7px;
    align-items:center;justify-content:space-between;border-radius:12px;background:#170f21e8;
    border:1px solid #9f92b75e;font:600 13px/1.1 system-ui,sans-serif;white-space:nowrap;}
  #coopRound {font-size:12px;color:#d0b8ef;}
  #coopClock {font-variant-numeric:tabular-nums;font-size:15px;}
  #coopCoins {display:flex;align-items:center;gap:4px;font-variant-numeric:tabular-nums;font-size:14px;}
  #coinA {color:#75b8fa;} #coinB {color:#ff8d71;}
  #coopCoins span {opacity:.4;}
  #coopShrines {display:flex;gap:0;}
  .shrine {display:block;width:30px;height:30px;--owner:#aaa4b5;--capture:#aaa4b5;}
  .shrine svg {width:30px;height:30px;fill:none;}
  .shrine .ring {stroke:var(--owner);stroke-width:3;opacity:.8;}
  .shrine .arc {stroke:var(--capture);stroke-width:3.5;stroke-dasharray:0 75.398;
    transform:rotate(-90deg);transform-origin:18px 18px;stroke-linecap:round;}
  .shrine path {fill:var(--owner);stroke:#ffffff4a;stroke-width:1;}
  #coopInvite {position:absolute;right:max(8px,env(safe-area-inset-right));
    top:max(8px,env(safe-area-inset-top));width:42px;height:42px;border-radius:11px;
    border:1px solid #a99ab6a0;background:#170f21e8;color:#f9e4ba;pointer-events:auto;display:grid;place-items:center;}
  #coopInvite svg {width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;}
  #captureHint {position:absolute;top:max(62px,calc(env(safe-area-inset-top) + 54px));left:50%;
    transform:translateX(-50%);border:1px solid #d4bc7e7d;border-radius:99px;
    padding:4px 14px;background:#170f21db;color:#ffe2a7;font:600 12px system-ui;}
  #coopWin {position:absolute;left:50%;top:35%;transform:translate(-50%,-20%);
    width:min(336px,calc(100vw - 24px));min-height:116px;padding:17px 14px;
    display:flex;flex-direction:column;gap:5px;align-items:center;justify-content:center;
    text-align:center;border-radius:16px;background:#170f21ef;border:1px solid #a99ab694;}
  #coopWin[hidden], #coopInvite[hidden], #captureHint[hidden], #coopOverlay[hidden] {display:none;}
  #coopWin strong {font-size:24px;} #coopWin span {font-size:18px;font-variant-numeric:tabular-nums;}
  #coopWin small {font-size:12px;color:#d8c9d4;}
  @media (max-width:500px) { .touch #coopStrip {left:max(8px,env(safe-area-inset-left));transform:none;} }

#pad { display: none; }
  .touch #pad { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 6; }
  .touch #keys, .touch .desktop-tip { display: none !important; }
  #stick { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom));
    width: clamp(92px, 24vh, 118px); height: clamp(92px, 24vh, 118px);
    border-radius: 50%; background: #211829a6; border: 1.5px solid #b2bfbd82;
    box-shadow: inset 0 0 0 10px #ffffff07, 0 4px 20px #110f1c44;
    pointer-events: auto; touch-action: none; }
  #stick i { position: absolute; left: 50%; top: 50%; width: 42px; height: 42px; margin: -21px;
    border-radius: 50%; background: #74a6acbd; border: 2px solid #d4ded69c; }
  #btns { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
    width: 230px; height: 204px; }
  #btns button { position: absolute; width: 46px; height: 46px; border-radius: 50%;
    border: 1.5px solid #e3c3847d; background: #211829e0; box-shadow: 0 3px 10px #110f1c63;
    display: grid; place-items: center; padding: 3px; color: var(--cream);
    pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent; }
  #btns button img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
  #btns button.on { border-color: #ffe0a4; background: #805c4adf; box-shadow: 0 0 0 3px #f5c76a3b; }
  /* Co-op first-minute cues target the real touch controls. No layout obstruction. */
  @keyframes first-minute-pulse {
    0%, 100% { box-shadow: 0 0 0 2px #91e8f27a, 0 0 12px #91e8f244; }
    50% { box-shadow: 0 0 0 9px #91e8f215, 0 0 30px #91e8f2bd; }
  }
  .touch body[data-tutorial-control="move"] #stick,
  .touch body[data-tutorial-control="cast"] #btns [data-k="LMB"],
  .touch body[data-tutorial-control="defend"] #btns [data-k="LMB"],
  .touch body[data-tutorial-control="build"] #btns [data-k="KeyB"] {
    animation: first-minute-pulse 1.1s ease-in-out infinite;
    border-color: #b7fbff;
  }
  #btns .big { right: 0; bottom: 0; width: 65px; height: 65px; border-color: #f5c76ab3; }
  #btns [data-k="RMB"] { right: 73px; bottom: 8px; }
  #btns [data-k="KeyQ"] { right: 124px; bottom: 33px; }
  #btns [data-k="KeyE"] { right: 124px; bottom: 88px; }
  #btns [data-k="KeyF"] { right: 71px; bottom: 104px; }
  #btns [data-k="KeyC"] { right: 14px; bottom: 119px; }
  #btns .jump { right: 183px; bottom: 88px; width: 45px; height: 45px; font-size: 11px; font-weight: 650; }
  #btns .helm { right: 183px; bottom: 145px; width: 44px; height: 44px; font-size: 11px; }
  #btns .fly { right: 185px; bottom: 35px; width: 44px; height: 44px;
    font-size: 11px; font-weight: 650; border-color: #77a9f6ad; }
  @media (max-height: 360px) { #btns { transform: scale(.86); transform-origin: bottom right; } }
  /* A 3×3 thumb cluster: every action remains >= 56 CSS px, even in landscape. */
  .touch #btns {right:max(10px,env(safe-area-inset-right));bottom:max(12px,env(safe-area-inset-bottom));
    width:180px;height:188px;transform:none;}
  .touch #btns button,.touch #btns .big,.touch #btns .jump,.touch #btns .fly,.touch #btns .helm {
    width:56px;height:56px;font-size:11px;}
  .touch #btns .big {width:60px;height:60px;}
  .touch #btns [data-k="LMB"] {right:0;bottom:0;}
  .touch #btns [data-k="RMB"] {right:62px;bottom:0;}
  .touch #btns [data-k="KeyQ"] {right:124px;bottom:0;}
  .touch #btns [data-k="KeyE"] {right:0;bottom:64px;}
  .touch #btns [data-k="KeyF"] {right:62px;bottom:64px;}
  .touch #btns [data-k="KeyC"] {right:124px;bottom:64px;}
  .touch #btns [data-k="Space"] {right:0;bottom:128px;}
  .touch #btns [data-k="KeyV"] {right:62px;bottom:128px;}
  .touch #btns [data-k="KeyR"] {right:124px;bottom:128px;}
  /* Non-game actions must never sit in the joystick's bottom-left zone. */
  .touch #live,.touch #fb {display:none!important;}
  .touch #diag {display:none;}
  .touch body[data-debug-hud="1"] #diag {display:block;}

#fresh { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top));
    transform: translateX(-50%); z-index: 12; padding: 8px 16px;
    border-radius: 999px; border: 1px solid #f5c76ab3; background: #211829f2;
    color: var(--cream); font-size: 13px; font-weight: 650; }
  #fresh:hover, #fresh:focus-visible { background: #392c40; }

#diag { position: fixed; right: 10px; bottom: 10px; padding: 6px 9px; border-radius: 8px; background: #0b0812cc; color: #e9dcc8; font: 11px/1.45 ui-monospace, Consolas, monospace; pointer-events: none; white-space: pre; z-index: 5; }
  #diag .bad { color: #ff6b5e; }
  .touch #diag { bottom: auto; top: 44px; }

#live { position: fixed; right: 18px; bottom: 14px; z-index: 5; border: 1px solid #110f1c88;
    border-radius: 999px; background: #211829d9; padding: 5px 10px;
    font-size: 12px; color: var(--cream); pointer-events: none; }
  #live::before { content: ""; display: inline-block; width: 7px; height: 7px;
    background: #8dd0a5; border-radius: 50%; margin-right: 7px; }
  #fb { position: fixed; left: 15px; bottom: 14px; z-index: 5; display: flex; gap: 6px; align-items: center; }
  #fb button, #fb input { min-height: 31px; border: 1px solid #e5c68c85; border-radius: 999px;
    background: #211829e8; color: var(--cream); padding: 5px 12px; font-size: 12px; }
  #fb input { width: min(50vw, 320px); outline: none; }
  #fb input:focus { border-color: var(--gold); }
  .touch #live { top: max(186px, calc(env(safe-area-inset-top) + 179px));
    bottom: auto; right: max(12px, env(safe-area-inset-right)); }
  .touch #fb { left: max(10px, env(safe-area-inset-left)); top: 247px; bottom: auto; }
  .touch #fb button { font-size: 11px; padding: 4px 9px; }
  .touch #fb input { width: min(55vw, 220px); }


/* HTML HUD v1: one quiet layer over the canvas, with fixed numeric lanes. */
#htmlHud { position:fixed; inset:0; z-index:8; pointer-events:none; contain:layout style; }
#htmlHud, #htmlHud * { box-sizing:border-box; }
#htmlHud button, #coopRound, #teamSelect button { pointer-events:auto; touch-action:manipulation; }
#htmlHud button:focus-visible, #teamSelect button:focus-visible, #coopRound:focus-visible {
  outline:2px solid #f5c76a; outline-offset:2px;
}
.hud-panel, #hudSkills, #hudQuick, .hud-modal, #hudFeed, #hudToasts, #hudTutorial {
  color:#fff0da; background:rgba(27,20,36,.91); border:1px solid rgba(230,195,140,.32);
  box-shadow:0 4px 14px #110f1c38; border-radius:12px;
}
#hudVitals {
  position:absolute; left:max(12px,env(safe-area-inset-left)); top:max(12px,env(safe-area-inset-top));
  width:240px; height:109px; padding:9px 11px; font-size:12px; font-variant-numeric:tabular-nums;
}
.hud-identity { display:flex; justify-content:space-between; align-items:center; height:20px; gap:8px; }
.hud-identity strong { font-size:13px; font-weight:700; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
.hud-identity small { color:#f5c76a; white-space:nowrap; }
.hud-meter { position:relative; height:15px; margin-top:5px; overflow:hidden; border-radius:7px; background:#554456; }
.hud-meter > div { height:100%; width:100%; }
.hud-meter.hp > div { background:#dd6258; } .hud-meter.mana > div { background:#71aaf5; }
.hud-meter.xp { height:3px; margin-top:7px; } .hud-meter.xp > div { background:#f5c76a; }
.hud-meter output { position:absolute; inset:0; display:grid; place-items:center;
  font:700 10px/15px ui-monospace,monospace; text-shadow:0 1px 2px #17101c; }
#hudFlight, #hudShield { position:absolute; top:calc(100% + 5px); left:0;
  background:#1b1424e8; border-radius:6px; padding:2px 8px; border:1px solid #ffffff25; }
#hudShield { left:auto; right:0; } #hudFlight output, #hudShield output { font-variant-numeric:tabular-nums; }
#hudSkills {
  position:absolute; bottom:max(12px,env(safe-area-inset-bottom)); left:50%; transform:translateX(-50%);
  height:72px; width:max-content; max-width:calc(100vw - 32px); padding:7px;
  display:flex; align-items:center; gap:7px;
}
.hud-skill { position:relative; height:56px; width:56px; overflow:hidden;
  border:1px solid #e1b968bb; border-radius:9px; background:#392a42; }
.hud-skill img { position:absolute; inset:3px; width:calc(100% - 6px); height:calc(100% - 6px); object-fit:contain; }
.hud-cooldown { position:absolute; bottom:0; left:0; right:0; height:0%; background:#100f1bd6; }
.hud-skill .hud-left { position:absolute; inset:0; display:grid; place-items:center;
  font:700 16px ui-monospace,monospace; text-shadow:0 1px 4px #000; font-variant-numeric:tabular-nums; }
.hud-skill .hud-left[hidden] { display:none; }
.hud-skill kbd { position:absolute; right:2px; bottom:2px; background:#120f1da8; border:0;
  min-width:15px; font-size:10px; line-height:16px; color:#f5c76a; }
#hudQuick { position:absolute; left:max(12px,env(safe-area-inset-left)); top:max(129px,calc(env(safe-area-inset-top) + 117px));
  display:flex; padding:3px; gap:3px; border-color:#ffffff25; }
#hudQuick button { border:0; border-radius:6px; background:transparent; color:#d8c9d4; font:500 11px system-ui; padding:5px 6px; }
#hudQuick button:hover { background:#ffffff1a; }
#hudQuick kbd { min-width:18px; font-size:10px; line-height:16px; }
#hudFeed { position:absolute; right:max(15px,env(safe-area-inset-right));
  top:max(74px,calc(env(safe-area-inset-top) + 67px)); min-width:170px; max-width:260px;
  padding:7px 10px; text-align:right; white-space:pre-line; overflow-wrap:anywhere; font-size:12px; }
#hudToasts { position:absolute; right:max(15px,env(safe-area-inset-right)); bottom:155px;
  width:230px; padding:6px 9px; font-size:12px; text-align:right; white-space:pre-line; overflow-wrap:anywhere; }
#hudTutorial { position:absolute; top:28%; left:50%; transform:translateX(-50%); padding:6px 14px; }
#coopOverlay { z-index:9; }
body[data-html-hud="1"] #coopStrip, body[data-html-hud="1"].touch #coopStrip {
  position:absolute; top:max(10px,env(safe-area-inset-top)); left:50%; transform:translateX(-50%);
  height:43px; width:420px; padding:4px 8px; display:flex; gap:6px;
  align-items:center; justify-content:space-around; border-radius:11px;
  background:#1b1424e8; border:1px solid #c5a97166; white-space:nowrap; pointer-events:none;
  font:650 12px/1.1 system-ui,sans-serif;
}
body[data-html-hud="1"] #coopRound { border:0; color:#e0cbef; font:600 12px system-ui; background:none;
  padding:3px 5px; cursor:pointer; pointer-events:auto; white-space:nowrap; }
#coopClock { font:700 15px ui-monospace,monospace; min-width:48px; text-align:center; }
#coopCoins { display:flex; align-items:center; font-variant-numeric:tabular-nums; }
#coopCoins b { min-width:27px; text-align:center; }
#coopInvite { z-index:11; }
.hud-modal, #teamSelect.hud-modal { position:fixed; z-index:34; left:50%; top:50%;
  transform:translate(-50%,-50%); width:min(420px,calc(100vw - 24px)); max-height:calc(100dvh - 24px);
  padding:16px; overflow-y:auto; overscroll-behavior:contain; pointer-events:auto;
  background:#1d1727f6; border:1px solid #c7ad7e8a; box-shadow:0 12px 54px #000a;
}
.hud-modal.hud-wide, #teamSelect.hud-wide { width:min(650px,calc(100vw - 24px)); }
.hud-modal header, #teamSelect header { display:flex; align-items:center; justify-content:space-between;
  min-height:32px; gap:10px; border-bottom:1px solid #ffffff22; padding-bottom:9px; margin-bottom:12px; }
.hud-modal header strong, #teamSelect header strong { font-size:19px; line-height:1.25; }
.hud-modal header button, #teamSelect header button { min-width:44px; min-height:44px; color:#fff0da;
  background:#3c3048; border:1px solid #ffffff50; border-radius:8px; font-size:20px; }
.hud-modal button:disabled, #teamSelect button:disabled { opacity:.46; cursor:not-allowed; }
#hudDeath { text-align:center; }
#hudDeath p { font-size:13px; color:#d8c9d4; margin:6px 0 12px; overflow-wrap:anywhere; }
.hud-death-time { font-variant-numeric:tabular-nums; font-size:17px; padding-bottom:12px; }
#hudRespawnChoices { display:grid; grid-template-columns:repeat(2,1fr); gap:9px; }
#hudRespawnChoices button, #hudSchools button, .hud-talent, .hud-item { color:#fff0da;
  background:#352a41; border:1px solid #d2ad7080; border-radius:9px;
  min-height:45px; padding:9px 12px; }
#hudRespawnChoices .selected, #hudSchools .selected { border-color:#f5c76a; background:#574362; }
#hudSchools { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:11px; }
#hudSchools button { flex:1 0 80px; font-size:12px; min-height:42px; }
#hudTalentRows, #hudItems { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
.hud-talent { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center;
  text-align:left; gap:2px 6px; min-height:71px; }
.hud-talent-name { font-weight:650; font-size:12px; overflow-wrap:anywhere; }
.hud-talent-effect { color:#cbc0d0; font-size:11px; grid-column:1/-1; overflow-wrap:anywhere; }
.hud-talent-status { font-style:normal; font-size:10px; color:#f5c76a; }
#hudEquipped { font-size:13px; margin:7px 0 12px; }
.hud-item { text-align:left; font-size:12px; overflow-wrap:anywhere; }
#hudBoardScore { color:#f5c76a; font-size:17px; font-variant-numeric:tabular-nums; }
#hudBoardMvp { margin:6px 0; font-size:13px; }
.hud-table-wrap { max-width:100%; overflow-x:auto; }
#hudScores { border-collapse:collapse; width:100%; text-align:left; font:12px/1.3 system-ui; }
#hudScores td, #hudScores th { padding:7px 5px; border-bottom:1px solid #ffffff26; white-space:nowrap; }
#hudScores td:first-child { max-width:110px; overflow:hidden; text-overflow:ellipsis; }
#hudRoundXp { font-size:12px; color:#d8c9d4; margin-top:8px; }
#teamSelect.hud-modal { display:block; right:auto; bottom:auto; }
#teamSelect .teamChoices { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
#teamSelect .teamChoices button { width:100%; height:auto; min-height:115px; padding:12px;
  display:flex; flex-direction:column; align-items:flex-start; gap:8px;
  border:1px solid #7ca8e9; border-radius:11px; background:#26466c; color:#fff0da;
  font-size:14px; text-align:left; overflow-wrap:anywhere; }
#teamSelect .teamChoices button[data-team="B"] { background:#753e46; border-color:#e8a08f; }
#teamSelect .teamChoices button strong { font-size:17px; }
#teamSelect .teamChoices button span { font-size:12px; font-weight:400; }
body[data-hud-mode="modal"] #hudVitals, body[data-hud-mode="modal"] #hudSkills,
body[data-hud-mode="modal"] #hudQuick, body[data-hud-mode="modal"] #hudFeed,
body[data-hud-mode="modal"] #hudToasts, body[data-hud-mode="modal"] #keys,
body[data-hud-mode="modal"] #coopStrip, body[data-hud-mode="modal"] #coopInvite { visibility:hidden; }
.touch #hudSkills { display:none; }
.touch #btns button { --cool:0%; }
.touch #btns button[data-cooldown]:not([data-cooldown=""])::after { content:attr(data-cooldown);
  position:absolute; inset:0; border-radius:inherit; display:grid; place-items:center;
  background:#140e1db8; color:white; font:700 14px ui-monospace,monospace; }
.touch #hudQuick { top:max(176px,calc(env(safe-area-inset-top) + 166px)); }
.touch #pad { z-index:10; }
body[data-hud-mode="modal"] #pad { visibility:hidden; }
@media (max-width:700px) {
  #hudVitals { width:184px; height:105px; padding:7px 8px; font-size:11px; }
  .hud-identity strong { font-size:12px; }
  body[data-html-hud="1"] #coopStrip, body[data-html-hud="1"].touch #coopStrip { top:max(121px,calc(env(safe-area-inset-top) + 115px)); left:max(8px,env(safe-area-inset-left));
    transform:none; width:min(310px,calc(100% - 62px)); height:40px; gap:3px; padding:4px 5px;
    justify-content:space-between; font-size:11px; }
  #coopInvite { top:max(121px,calc(env(safe-area-inset-top) + 115px)); }
  #coopShrines .shrine { width:23px; height:25px; }
  #coopShrines .shrine svg { width:23px; height:25px; }
  #hudQuick { top:max(161px,calc(env(safe-area-inset-top) + 155px)); }
  #hudFeed { display:none !important; }
  #hudToasts { top:max(215px,calc(env(safe-area-inset-top) + 210px)); bottom:auto; right:max(10px,env(safe-area-inset-right));
    max-width:160px; width:auto; font-size:11px; }
  .hud-modal, #teamSelect.hud-modal { padding:12px; max-height:calc(100dvh - max(32px,env(safe-area-inset-top)) - max(16px,env(safe-area-inset-bottom))); }
  .hud-modal header strong, #teamSelect header strong { font-size:17px; }
  #hudTalentRows { grid-template-columns:1fr; }
  #hudItems { grid-template-columns:1fr; }
  #hudScores { font-size:11px; }
  #teamSelect .teamChoices { gap:8px; }
  #teamSelect .teamChoices button { min-height:100px; }
}
@media (min-width:1920px) {
  #hudVitals { width:260px; height:116px; }
  #hudSkills { transform:translateX(-50%) scale(1.15); transform-origin:bottom center; }
}
@media (max-height:480px) {
  #hudVitals { top:6px; }
  body[data-html-hud="1"] #coopStrip, body[data-html-hud="1"].touch #coopStrip { top:6px; }
  #hudQuick { top:121px; }
  #hudSkills { bottom:6px; }
  .hud-modal, #teamSelect.hud-modal { max-height:calc(100dvh - 12px); }
}
@media (prefers-reduced-motion:reduce) {
  #htmlHud *, #teamSelect *, #coopOverlay * { animation:none!important; transition:none!important; scroll-behavior:auto!important; }
}

body[data-html-hud="1"] .hud-skill[data-glyph]::before {
  content:attr(data-glyph); position:absolute; inset:0; display:grid; place-items:center;
  font:700 25px/1 Georgia,serif; color:#ddbbff; text-shadow:0 0 13px #f5c76a66;
}
.touch body[data-html-hud="1"] #btns button[data-glyph]::before {
  content:attr(data-glyph); position:absolute; inset:0; display:grid; place-items:center;
  font:700 27px/1 Georgia,serif; color:#e1c5ff; pointer-events:none;
}

/* Action-only tutorial and active quest use the same safe-area aware rail. */
#hudTutorial, #hudQuest { position:absolute; z-index:31; left:50%; transform:translateX(-50%);
  padding:7px 12px; border-radius:8px; max-width:min(360px,calc(100% - 16px));
  overflow-wrap:anywhere; text-align:center; line-height:1.3; font:600 12px system-ui;
  background:#241d33df; border:1px solid #bc9d6d99; color:#fff2dd; pointer-events:none; }
#hudTutorial { top:max(148px,calc(env(safe-area-inset-top) + 148px)); }
#hudQuest { top:max(194px,calc(env(safe-area-inset-top) + 194px)); font-weight:500; }
body[data-hud-mode="modal"] #hudTutorial,
body[data-hud-mode="modal"] #hudQuest { visibility:hidden; }
@media (max-width:700px) {
  #hudTutorial { top:max(257px,calc(env(safe-area-inset-top) + 251px)); }
  #hudQuest { top:max(302px,calc(env(safe-area-inset-top) + 296px)); }
}

/* Undo the old full-screen selector's grid item-centering and giant buttons. */
#teamSelect.hud-modal { justify-items:stretch; align-items:stretch; }
#teamSelect.hud-modal > header, #teamSelect.hud-modal > .teamChoices { width:100%; }
#teamSelect.hud-modal header button { width:44px; height:44px; min-width:44px; min-height:44px;
  flex:0 0 44px; border-radius:8px; font-size:20px; }

#hudCrosshair { position:fixed; z-index:29; top:50%; left:50%; width:14px; height:14px;
  transform:translate(-50%,-50%); pointer-events:none; opacity:.82; }
#hudCrosshair::before, #hudCrosshair::after { content:""; position:absolute; background:#fff4de;
  box-shadow:0 0 3px #16111d; border-radius:2px; }
#hudCrosshair::before { width:2px; height:12px; left:6px; top:1px; }
#hudCrosshair::after { width:12px; height:2px; top:6px; left:1px; }
#hudTarget { position:fixed; z-index:30; left:50%; top:calc(50% + 38px); transform:translateX(-50%);
  width:200px; min-height:42px; padding:6px 9px; border-radius:7px;
  background:#20182edb; border:1px solid #bd9e7470; font:600 12px system-ui;
  color:#f5e7d6; pointer-events:none; font-variant-numeric:tabular-nums; }
#hudTargetName { float:left; max-width:75%; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
#hudTargetHealth { float:right; }
.hud-target-track { clear:both; position:relative; top:3px; height:4px; border-radius:4px; background:#433247; }
#hudTargetFill { width:100%; height:100%; border-radius:inherit; background:#dd725f; }
#hudOnline { position:fixed; z-index:27; left:max(12px,env(safe-area-inset-left));
  bottom:max(10px,env(safe-area-inset-bottom)); font:11px system-ui; color:#d2c3d6;
  text-shadow:0 1px 2px #100a17; pointer-events:none; white-space:nowrap; }
body[data-hud-mode="modal"] #hudCrosshair,
body[data-hud-mode="modal"] #hudTarget,
body[data-hud-mode="modal"] #hudOnline { visibility:hidden; }
@media(max-width:700px) { #hudOnline { display:none !important; } }

#hudChips { position:fixed; z-index:30; inset:0; pointer-events:none; }
.hud-chip { position:absolute; display:block; width:64px; margin-left:-32px;
  text-align:center; text-shadow:0 1px 3px #120f18; color:#f7d595;
  font:700 17px ui-monospace,monospace; font-variant-numeric:tabular-nums;
  animation:hud-chip-out .85s ease-out both; }
#hudHitMarker { position:fixed; z-index:30; left:50%; top:50%;
  transform:translate(-50%,-50%); color:#f7dfbe; font:700 28px/1 sans-serif;
  text-shadow:0 0 7px #120b17; pointer-events:none; }
@keyframes hud-chip-out { to { transform:translateY(-22px); opacity:0; } }
body[data-hud-mode="modal"] #hudChips,
body[data-hud-mode="modal"] #hudHitMarker { visibility:hidden; }

#hudHelm { position:fixed; left:50%; bottom:max(102px,calc(env(safe-area-inset-bottom) + 102px));
  transform:translateX(-50%); z-index:31; pointer-events:none; border-radius:7px;
  padding:7px 10px; color:#fff2dd; background:#241d33d9; border:1px solid #bc9d6d77;
  white-space:normal; text-align:center; max-width:min(580px,calc(100vw - 18px));
  font:600 12px/1.35 system-ui; }
body[data-hud-mode="modal"] #hudHelm { visibility:hidden; }
@media(max-width:700px) { #hudHelm { bottom:auto; top:max(354px,calc(env(safe-area-inset-top) + 348px)); } }

.touch #hudOnline { display:none !important; }

/* RoundStart minimap: DOM/SVG only, no Bevy UI over the WebGL2 canvas. */
#hudFieldMap { position:fixed; top:119px; right:max(12px,env(safe-area-inset-right));
  z-index:24; box-sizing:border-box; width:160px; height:182px; padding:5px 7px 7px;
  background:#171f1ce8; border:1px solid #9fae8380; border-radius:9px;
  box-shadow:0 2px 9px #0006; pointer-events:none; }
#hudFieldMap[hidden] { display:none; }
#hudFieldMapName { display:block; font:600 12px/17px system-ui,sans-serif;
  letter-spacing:.02em; color:#ece8db; text-align:center; }
#hudFieldMapSvg { display:block; width:144px; height:144px; }
@media (max-width:700px) {
  #hudFieldMap { top:max(178px,calc(env(safe-area-inset-top) + 171px));
    width:118px; height:136px; padding:3px 5px 5px; }
  #hudFieldMapSvg { width:106px; height:106px; }
  #hudFieldMapName { font-size:10px; line-height:17px; }
}
body[data-hud-mode="modal"] #hudFieldMap { visibility:hidden; }
@media(max-height:480px) { #hudFieldMap { top:65px; } }

/* Live, server-fed field view. Drawn in a 160 CSS-pixel canvas (110 on phones). */
#hudMinimap { position:absolute; right:max(12px,env(safe-area-inset-right));
  top:max(12px,env(safe-area-inset-top)); width:176px; padding:7px;
  z-index:10; color:#e6d8ed; background:#1b1424ed; border:1px solid #c5a97188;
  border-radius:10px; box-shadow:0 4px 14px #110f1c38; pointer-events:none; }
#hudMapCanvas { display:block; width:160px; height:160px; border-radius:5px; }
#hudMinimap small { display:block; text-align:center; letter-spacing:.09em;
  font:650 10px/15px system-ui; }
#hudCapture { position:absolute; z-index:12; top:max(65px,calc(env(safe-area-inset-top) + 57px));
  left:50%; transform:translateX(-50%); display:flex; align-items:center; gap:7px;
  width:176px; min-height:66px; padding:4px 8px; border-radius:12px;
  background:#1b1424e8; border:1px solid #c5a97188; pointer-events:none; }
#hudCapture svg { width:58px; height:58px; flex:0 0 58px; }
#hudCapture circle { fill:none; stroke-width:6; }
#hudCapture .capture-base { stroke:#64546b; }
#hudCapture .capture-arc { transform:rotate(-90deg); transform-origin:36px 36px;
  stroke:#75b8fa; stroke-dasharray:0 175.929; stroke-linecap:round; }
#hudCapture strong, #hudCapture small { display:block; }
#hudCapture strong { font:700 12px system-ui; white-space:nowrap; }
#hudCapture small { font:500 11px/1.25 system-ui; color:#dfccd9; }
#hudFeed { top:max(211px,calc(env(safe-area-inset-top) + 199px)); }
#coopWave { font-size:11px; color:#d1c5e3; }
body[data-hud-mode="modal"] #hudMinimap,
body[data-hud-mode="modal"] #hudCapture { visibility:hidden; }
@media(max-width:700px) {
  #hudMinimap { width:122px; padding:5px; }
  #hudMapCanvas { width:110px; height:110px; }
  #hudMinimap small { font-size:9px; line-height:14px; }
  #hudCapture { top:max(202px,calc(env(safe-area-inset-top) + 196px));
    width:148px; min-height:49px; padding:2px 5px; gap:3px; }
  #hudCapture svg { width:43px; height:43px; flex-basis:43px; }
  #hudCapture strong { font-size:11px; }
  #hudCapture small { font-size:10px; }
  #coopInvite { top:max(166px,calc(env(safe-area-inset-top) + 160px)); }
  #hudToasts { top:max(404px,calc(env(safe-area-inset-top) + 398px)); }
  #coopWave { font-size:10px; }
}

/* Measured separation of the map and round/utility rail at both gate sizes. */
@media (min-width:701px) {
  #coopInvite { top:max(211px,calc(env(safe-area-inset-top) + 199px)); }
  #hudFeed { top:max(265px,calc(env(safe-area-inset-top) + 253px)); }
}
@media (max-width:700px) {
  body[data-html-hud="1"] #coopStrip,
  body[data-html-hud="1"].touch #coopStrip {
    top:max(155px,calc(env(safe-area-inset-top) + 149px));
  }
  #coopInvite { top:max(155px,calc(env(safe-area-inset-top) + 149px)); }
  .touch #hudQuick, #hudQuick { top:max(202px,calc(env(safe-area-inset-top) + 196px)); }
  #hudCapture { top:max(247px,calc(env(safe-area-inset-top) + 241px)); }
  #hudTutorial { top:max(305px,calc(env(safe-area-inset-top) + 299px)); }
  #hudQuest { top:max(349px,calc(env(safe-area-inset-top) + 343px)); }
  #hudHelm { top:max(393px,calc(env(safe-area-inset-top) + 387px)); }
  #hudToasts { top:max(454px,calc(env(safe-area-inset-top) + 448px)); }
}
/* One minimap: the live one (#hudMinimap) replaces the round-start field map. */
#hudFieldMap { display:none !important; }

/* Round three: reserve a stable vitals/utility rail, including flight and shield. */
#hudVitals { height:138px; }
#hudFlight, #hudShield { position:static; display:inline-block; margin-top:5px; padding:2px 6px; font-size:11px; }
#hudQuick, .touch #hudQuick { top:max(158px,calc(env(safe-area-inset-top) + 146px)); }
#hudMinimap small { letter-spacing:0; }
#hudFeed { text-align:left; border-left:3px solid #c7ad7e; }
#hudDeath .hud-death-time output { color:var(--gold); font-size:32px; font-weight:750; }
#hudBoardScore { padding:10px; background:#352a41; border-radius:8px; }
#hudScores td:first-child { max-width:none; overflow:visible; text-overflow:clip; }
#hudOnline { bottom:max(52px,calc(env(safe-area-inset-bottom) + 52px)); }
body[data-html-hud="1"] #diag { bottom:50px; }
@media(max-width:700px) {
  #hudVitals { top:64px; height:138px; width:210px; }
  #hudMinimap { top:64px; }
  body[data-html-hud="1"] #coopStrip, body[data-html-hud="1"].touch #coopStrip { top:8px; left:50%; transform:translateX(-50%); width:calc(100% - 24px); }
  #coopInvite { top:205px; }
  #hudQuick, .touch #hudQuick { top:210px; }
  #hudCapture { top:258px; }
  #hudTutorial { top:315px; }
  #hudQuest { top:355px; }
  #hudHelm { top:500px; }
  #hudFeed { display:block !important; top:545px; left:12px; right:auto; max-width:180px; min-width:0; font-size:11px; }
  #hudFeed[hidden] { display:none !important; }
  #hudToasts { top:545px; max-width:170px; }
}
