:root {
  --blue: #4aa8ff; --red: #ff5a4d; --gold: #ffcf4a; --ink: #f6f0e0; --dim: #b3aebd;
  --slate: #1b1a2b; --slate-hi: #2a2940; --slate-lo: #100f1b; --wood: #7a4f2c;
  --slot: clamp(44px, 4.3vw, 58px);
  --title: "Arial Black", "Segoe UI Black", Impact, system-ui, sans-serif;
  /* The chunky block edge shared by every HUD surface. */
  --bevel: inset 0 2px 0 rgba(255, 255, 255, .13), inset 0 -3px 0 rgba(0, 0, 0, .5), 0 3px 0 #05050a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--slate-lo); color: var(--ink); font: 600 14px/1.35 "Segoe UI", system-ui, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
canvas[data-icon], #heroes canvas { image-rendering: pixelated; }
kbd { font: 800 11px/1 ui-monospace, Consolas, monospace; }
.panel { background: linear-gradient(var(--slate-hi), var(--slate)); box-shadow: var(--bevel); }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: 0; }
#view.aiming { cursor: crosshair; }
#view.foe { cursor: pointer; }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; box-shadow: inset 0 0 120px 40px #d9231a; transition: opacity .35s; }
#flash.on { opacity: .8; transition: none; }

/* HUD: nothing touches the window edge, the outer band belongs to camera edge pan. */
#hud { position: fixed; inset: 0; pointer-events: none; user-select: none; }
#hud button, #mapbox, #shop, #tutorial, #waiting, #unit, #actions { pointer-events: auto; }

#top { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: grid; justify-items: center; gap: 6px; }
#score { display: flex; align-items: center; gap: 16px; padding: 6px 18px 8px; clip-path: polygon(0 0, 100% 0, 100% 70%, calc(100% - 12px) 100%, 12px 100%, 0 70%); }
#score div { display: grid; justify-items: center; min-width: 118px; }
#score b { font: 900 22px/1.1 var(--title); font-variant-numeric: tabular-nums; }
#score small { color: var(--dim); font-size: 12px; white-space: nowrap; }
#score span { font: 900 26px/1 var(--title); min-width: 28px; text-align: center; }
#sudden { padding: 3px 12px; font-size: 13px; color: #ffd9a8; background: rgba(120, 40, 10, .85); box-shadow: var(--bevel); white-space: nowrap; }
#sudden.burning { color: #fff; background: #d14a12; animation: throb 1s infinite alternate; }
@keyframes throb { to { filter: brightness(1.35); } }

/* Square map inside a circle wide enough to keep both bases in view at any rotation. */
#mapbox { --size: clamp(132px, 15vw, 200px); position: absolute; top: 12px; right: 12px; width: var(--size); height: var(--size); display: grid; place-items: center; overflow: hidden; border-radius: 50%; background: #0b1410; box-shadow: 0 0 0 3px var(--slate-hi), 0 0 0 5px var(--wood), 0 5px 0 5px #05050a; cursor: crosshair; }
#minimap { width: 80%; height: 80%; }
#followTag { display: none; position: absolute; bottom: 8%; padding: 0 5px; font-size: 10px; background: rgba(0, 0, 0, .7); white-space: nowrap; }
#followTag.on { display: block; }

#feed { position: absolute; top: calc(clamp(132px, 15vw, 200px) + 30px); right: 12px; width: 240px; margin: 0; padding: 0; list-style: none; font-size: 13px; text-align: right; text-shadow: 0 1px 2px #000; }
#feed li { animation: fade 7s forwards; }
#feed .ally { color: #a9d6ff; } #feed .enemy { color: #ffb5ad; }
@keyframes fade { 85% { opacity: 1; } 100% { opacity: 0; } }

#banner { position: absolute; top: 19%; width: 100%; padding: 0 16px; text-align: center; font: 900 clamp(22px, 3.2vw, 38px)/1.1 var(--title); text-shadow: 0 3px 0 #000; opacity: 0; }
#banner.on { animation: banner 2.6s; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.5); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
#toast { position: absolute; bottom: calc(var(--slot) + 104px); width: 100%; padding: 0 16px; text-align: center; font-size: 15px; color: #ffd9d4; text-shadow: 0 1px 3px #000, 0 0 2px #000; opacity: 0; transition: opacity .3s; }
#toast.on { opacity: 1; transition: none; }
#crosshair { position: absolute; top: 50%; left: 50%; width: 6px; height: 6px; margin: -3px; background: #fff; mix-blend-mode: difference; }
#respawn, #lockHint { position: absolute; top: 40%; width: 100%; padding: 0 16px; text-align: center; font: 900 clamp(20px, 2.4vw, 28px)/1.2 var(--title); text-shadow: 0 2px 0 #000; }
#lockHint { top: 56%; font: 700 16px/1.2 "Segoe UI", system-ui, sans-serif; }

#waiting { position: absolute; top: 30%; left: 50%; transform: translateX(-50%); display: grid; justify-items: center; gap: 8px; width: min(420px, calc(100vw - 40px)); padding: 14px 16px; text-align: center; }
#waiting b { font: 900 18px/1.2 var(--title); }
#waiting p { margin: 0; max-width: 100%; color: var(--gold); overflow-wrap: anywhere; user-select: all; }
#waiting button, #tutorial button { padding: 5px 12px; background: var(--slate-lo); box-shadow: var(--bevel); }
#waiting button:hover, #tutorial button:hover { background: var(--wood); }

#tutorial { position: absolute; top: 12px; left: 12px; width: 270px; padding: 10px 12px 12px; display: grid; gap: 3px; border-left: 4px solid var(--gold); }
#tutorial small { color: var(--dim); font-size: 11px; }
#tutorial b { font: 900 16px/1.2 var(--title); color: var(--gold); }
#tutorial p { margin: 0; font-weight: 500; }
#tutorial div { display: flex; gap: 6px; margin-top: 6px; }

#shop { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 280px; padding: 12px; display: grid; gap: 6px; }
#shop h2 { margin: 0 0 4px; font: 900 15px/1.2 var(--title); color: var(--gold); }
#shop button { display: grid; grid-template-columns: 14px 26px 1fr auto; align-items: center; gap: 8px; padding: 6px 10px; text-align: left; background: var(--slate-lo); box-shadow: var(--bevel); }
#shop button:hover:not(:disabled) { background: var(--wood); }
#shop button:disabled { opacity: .45; cursor: default; }
#shop canvas { width: 26px; height: 26px; }
#shop kbd { color: var(--dim); }
#shop small { color: var(--gold); font-size: 14px; font-weight: 800; }
#shop p { margin: 0; color: #ffd9a8; font-size: 13px; }
#shop p:empty { display: none; }

#tip { position: fixed; z-index: 1; max-width: 280px; padding: 6px 10px; font-size: 13px; font-weight: 500; background: var(--slate-lo); box-shadow: 0 0 0 1px var(--wood), 0 3px 0 #05050a; }

#deck { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: grid; grid-template-columns: minmax(250px, 310px) auto; justify-content: center; gap: 6px 8px; width: max-content; max-width: calc(100vw - 24px); }
#keys { grid-column: 1 / -1; margin: 0; font-size: 12px; font-weight: 500; color: #ddd8e6; text-align: center; text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; }
.fpOnly, .fp .isoOnly { display: none; }
.fp .fpOnly { display: inline; }

#unit { display: flex; gap: 10px; padding: 7px 10px 9px 7px; }
#portrait { position: relative; flex: none; align-self: center; width: 62px; height: 62px; background: linear-gradient(#49506a, #23243a); box-shadow: inset 0 0 0 2px #05050a, 0 0 0 2px var(--wood); }
#face { display: block; width: 100%; height: 100%; padding: 5px; }
#stunTag { position: absolute; inset: auto 0 0; padding: 1px 0; font-style: normal; font-size: 10px; text-align: center; background: #6a43c9; }
#vitals { flex: 1; min-width: 0; display: grid; gap: 4px; align-content: center; }
#heroLine { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; }
#heroLine b { font: 900 13px/1.2 var(--title); }
#heroLine small { color: var(--dim); font-size: 11px; }
#kd { margin-left: auto; }
.bar { position: relative; height: 18px; overflow: hidden; background: #3a1512; box-shadow: inset 0 0 0 1px #05050a; }
.bar i { position: absolute; inset: 0; width: 100%; background: repeating-linear-gradient(90deg, transparent 0 13px, rgba(0, 0, 0, .28) 13px 15px), linear-gradient(#6fe07a, #2f9c47); transition: width .12s; }
.bar.low i { background: repeating-linear-gradient(90deg, transparent 0 13px, rgba(0, 0, 0, .28) 13px 15px), linear-gradient(#ff7a6b, #d9352a); }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 18px; text-shadow: 0 1px 2px #000; font-variant-numeric: tabular-nums; }
#stock { display: flex; gap: 14px; }
#stock span { position: relative; display: flex; align-items: center; gap: 5px; font-size: 15px; font-variant-numeric: tabular-nums; }
#stock canvas { width: 15px; height: 15px; }
#stock b { font-weight: 800; }
#goldStock { color: var(--gold); }
#blockStock.empty { color: var(--red); }
#blockStock.full { color: #8fe39a; }
#goldPop { position: absolute; left: 100%; top: 0; margin-left: 4px; font-style: normal; opacity: 0; }
#goldPop.on { animation: pop .9s; }
@keyframes pop { 0% { opacity: 1; transform: translateY(6px); } 100% { opacity: 0; transform: translateY(-16px); } }

#actions { display: flex; align-items: center; gap: 12px; padding: 7px 10px 9px; }
.group { display: flex; gap: 4px; }
.slot { position: relative; width: var(--slot); height: var(--slot); padding: 0; overflow: hidden; background: var(--slate-lo); box-shadow: inset 0 3px 0 rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(255, 255, 255, .1); }
.slot canvas { position: absolute; inset: 16%; width: 68%; height: 68%; }
.slot:hover { background: #2f2c49; }
.slot.on { background: #4f3a14; box-shadow: inset 0 0 0 2px var(--gold), 0 0 8px var(--gold); }
.slot.off canvas { opacity: .35; filter: grayscale(1); }
.slot kbd { position: absolute; top: 2px; left: 2px; padding: 1px 3px; color: var(--ink); background: rgba(0, 0, 0, .65); }
.slot small { position: absolute; right: 2px; bottom: 1px; color: var(--gold); font-size: 11px; font-weight: 800; text-shadow: 0 1px 1px #000; }
.slot .cd { position: absolute; inset: 0; pointer-events: none; background: conic-gradient(rgba(5, 5, 12, .8) calc(var(--cd, 0) * 360deg), transparent 0); }
.slot em { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; font: 900 18px/1 var(--title); text-shadow: 0 2px 0 #000; }
#shopButton.ready { box-shadow: inset 0 0 0 2px #8fe39a; }

/* Menu */
#menu, #result { position: fixed; inset: 0; z-index: 2; overflow-y: auto; }
#backdrop { position: fixed; inset: 0; width: 100%; height: 100%; }
#menuBody { position: relative; display: grid; gap: 10px; width: min(860px, 100%); min-height: 100%; margin: 0 auto; padding: 18px 16px; align-content: center; }
#menu header { text-align: center; }
#menu header p { margin: 2px 0 0; font-size: 16px; text-shadow: 0 2px 3px #000; }
h1 { margin: 0; font: 900 clamp(38px, 7vw, 72px)/1.05 var(--title); letter-spacing: -.01em; text-shadow: 0 5px 0 #05050a; }
h1 span { color: var(--gold); }
#menu h2 { margin: 0 0 4px; font: 900 12px/1.2 var(--title); letter-spacing: .08em; text-transform: uppercase; color: var(--gold); text-shadow: 0 2px 0 #05050a; }
#heroes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.heroCard { display: grid; align-content: start; grid-template-columns: 76px 1fr; gap: 2px 12px; padding: 10px 12px 12px; text-align: left; background: linear-gradient(var(--slate-hi), var(--slate)); box-shadow: var(--bevel); }
.heroCard:hover { filter: brightness(1.15); }
.heroCard[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--gold), 0 3px 0 #05050a; }
.heroCard canvas { grid-row: span 2; width: 76px; height: 76px; padding: 6px; background: linear-gradient(#49506a, #23243a); box-shadow: inset 0 0 0 2px #05050a; }
.heroCard b { align-self: end; font: 900 18px/1.2 var(--title); }
.heroCard p { margin: 0; font-size: 13px; font-weight: 500; color: var(--dim); }
.heroCard dl { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, auto 1fr); gap: 1px 8px; margin: 6px 0 0; font-size: 13px; }
.heroCard dt { color: var(--dim); font-weight: 500; }
.heroCard dd { margin: 0; white-space: nowrap; font-weight: 800; font-variant-numeric: tabular-nums; }
.heroCard ul { grid-column: 1 / -1; margin: 6px 0 0; padding: 0; list-style: none; font-size: 12px; font-weight: 500; }
#options { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; align-items: start; }
.seg { display: flex; gap: 4px; }
.seg button { flex: 1; display: grid; justify-items: center; align-content: center; min-height: 40px; padding: 4px 6px; background: var(--slate-lo); box-shadow: var(--bevel); }
.seg button:hover { background: var(--slate-hi); }
.seg button[aria-pressed="true"] { color: #221800; background: var(--gold); }
.seg small { font-size: 11px; font-weight: 500; line-height: 1.15; text-align: center; }
#name { width: 100%; height: 40px; padding: 0 10px; font: inherit; color: inherit; background: var(--slate-lo); border: 0; box-shadow: inset 0 3px 0 rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(255, 255, 255, .15); }
#play, #resultActions { display: flex; justify-content: center; gap: 10px; }
#play button, #result button { min-width: 230px; padding: 12px 18px; font: 900 16px/1.2 var(--title); background: var(--slate-hi); box-shadow: var(--bevel); }
#play button:hover:not(:disabled), #result button:hover { filter: brightness(1.2); }
#play button:disabled { opacity: .5; cursor: progress; }
#play button.primary, #result button.primary { color: #221800; background: var(--gold); }
#result kbd { opacity: .7; }
.invited .hostOnly { display: none; }
.invited #options { grid-template-columns: minmax(0, 320px); justify-content: center; }

/* Result */
#result { display: grid; align-content: center; justify-items: center; gap: 12px; padding: 16px; text-align: center; background: linear-gradient(rgba(10, 10, 20, .45), rgba(10, 10, 20, .88)); }
#resultText.won { color: var(--gold); } #resultText.lost { color: var(--red); }
#result p { margin: 0; font-size: 17px; }
#result p:empty { display: none; }
#resultBed { display: grid; gap: 6px; width: min(420px, 100%); padding: 10px 14px 12px; }
#resultBed .bar i { background: repeating-linear-gradient(90deg, transparent 0 13px, rgba(0, 0, 0, .28) 13px 15px), linear-gradient(#ff7a6b, #d9352a); }

/* Narrow laptops: the deck drops the key hints before it shrinks anything. */
@media (max-width: 1040px) { #keys { display: none; } }
@media (max-width: 900px) {
  #deck { grid-template-columns: 1fr; justify-items: center; }
  #unit { width: min(100%, 420px); }
  #tutorial { top: calc(clamp(132px, 15vw, 200px) + 30px); }
}
/* Phone width */
@media (max-width: 720px) {
  :root { --slot: 42px; }
  #top { left: 8px; transform: none; justify-items: start; top: 8px; }
  #score { gap: 8px; padding: 4px 10px 6px; }
  #score div { min-width: 92px; }
  #score b { font-size: 16px; } #score span { font-size: 20px; } #score small { font-size: 11px; }
  #mapbox { --size: 104px; top: 8px; right: 8px; }
  #feed { top: 122px; right: 8px; width: 170px; font-size: 12px; }
  #tutorial { top: 74px; left: 8px; width: min(190px, calc(100vw - 136px)); font-size: 12px; }
  #shop { top: auto; bottom: 186px; left: 8px; right: 8px; width: auto; transform: none; }
  #deck { bottom: 6px; width: calc(100vw - 12px); max-width: none; gap: 4px; }
  #unit { width: 100%; padding: 4px 8px 6px 4px; }
  #portrait { width: 48px; height: 48px; }
  #actions { flex-wrap: wrap; justify-content: center; gap: 4px 10px; width: 100%; padding: 4px; }
  #toast { bottom: 190px; }
  #heroes, #options { grid-template-columns: 1fr; }
  .heroCard dl { grid-template-columns: repeat(2, auto 1fr); }
  #menuBody { align-content: start; }
  #play { flex-direction: column; }
  #play button, #result button { min-width: 0; width: 100%; }
  #resultActions { flex-direction: column; width: min(320px, 100%); }
}
/* Short landscape screens */
@media (max-height: 520px) {
  :root { --slot: 38px; }
  #keys, #feed { display: none; }
  #deck { grid-template-columns: minmax(200px, 250px) auto; justify-items: stretch; }
  #unit { width: auto; padding: 3px 8px 5px 3px; }
  #portrait { width: 40px; height: 40px; }
  #actions { flex-wrap: nowrap; gap: 6px; width: auto; padding: 4px; }
  #tutorial { top: 72px; left: 8px; width: 240px; padding: 6px 10px 8px; font-size: 12px; }
  #toast { bottom: 76px; }
  #shop { top: 8px; bottom: auto; left: 8px; right: auto; width: 280px; max-height: calc(100vh - 80px); overflow-y: auto; transform: none; }
  #menuBody { align-content: start; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; transition: none !important; }
  #sudden.burning { animation: none; }
}
