:root {
  color-scheme: dark;
  font-family: Arial, Helvetica, sans-serif;
  background: #08060b;
  color: #eee9f2;

  --ink: #eee9f2;
  --muted: #8b8194;
  --panel: #0e0b12;
  --edge: #40334857;
  --hp: #e7b652;
  --dp: #a173d8;
  --foe: #c8402f;
  --gold: #e7c477;
  --ink: #eee9f2;
}

* { box-sizing: border-box; }
html, body, #game-shell { margin: 0; width: 100%; height: 100%; overflow: hidden; }
#game-shell { display: grid; grid-template-rows: 1fr; background: #09070d; }
#viewport { position: relative; min-height: 0; background: #09070c; }
#bevy-canvas { display: block; width: 100%; height: 100%; outline: 0; }

/* The loading curtain. Opaque, and above #hud-root's z-index, so it hides the
   HUD as well as the half-built arena until web/boot.js lifts it. */
#loading {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-content: center;
  text-align: center;
  background: radial-gradient(circle, #211328, #09070d 55%);
  transition: opacity .35s;
  /* Written by boot.js, 0..1, from the bundle's bytes and then the engine's
     own report. */
  --progress: 0;
}
/* visibility trails the fade so the finished curtain stops being a hit target
   and drops out of the accessibility tree instead of lingering invisibly. */
#loading.done { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .35s, visibility 0s .35s; }
/* The curtain sits on the kit's plate, the same nine-slice the dummy panel
   wears, so the first thing on screen is already in the game's own dress. */
#loading .plate {
  --ui-scale: .34;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(420px, 86vw);
  padding: 4px 8px 8px;
}
/* Both labels sit on a busy crimson weave, so each carries a shadow to read
   off it rather than in it. Named rather than matching every span, because the
   bar's track is one too. */
#loading .step { font-size: 12px; color: var(--muted); text-shadow: 0 1px 2px #000b; }
#loading .title { line-height: 1; }

/* The track sizes the bar - it is in flow and carries the artwork's own
   height, so the fill can be laid over it. Putting the nine-slice on the
   wrapper instead would leave nothing to position against: this frame's top
   and bottom slices take up all but a pixel of its height, so its padding box,
   which is what an absolutely positioned child measures from, is flat. */
#loading .progress {
  --ui-scale: .63;
  position: relative;
  width: min(340px, 62vw);
}
#loading .progress .track {
  display: block;
  height: calc(var(--ui-h) * 1px * var(--ui-scale));
}
/* Inset to sit within the track's rail, then clipped rather than narrowed, so
   the fill keeps its drawn end caps at every percentage instead of having them
   squeezed down as the bar empties. The engine's estimate arrives in steps;
   easing the clip keeps them from reading as stutters. */
#loading .progress i {
  position: absolute;
  inset: calc(9px * var(--ui-scale));
  clip-path: inset(0 calc((1 - var(--progress)) * 100%) 0 0);
  transition: clip-path .25s ease-out;
}
/* Reserved even when empty, so the curtain does not jump the moment an asset
   turns out to be missing. */
#loading .note { min-height: 1.2em; font-size: 11px; color: var(--foe); text-shadow: 0 1px 2px #000b; }
#loading.failed .progress { display: none; }

/* The overlay itself never eats pointer events; only the action bar opts in,
   so clicks anywhere else still reach the canvas as move/cast orders. */
#hud-root {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  user-select: none;
}

/* Armed state: the slot lights up and the arena takes a crosshair. */
#viewport:has(#hud-root:not([data-armed=""])) #bevy-canvas { cursor: crosshair; }

/* ---------- bottom shade ---------- */
/* A soft black falloff across the foot of the screen. It sits behind every
   other HUD layer, so the action bar and hints read against it instead of
   against whatever the arena happens to be showing. */
.screen-shade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 46%;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(to top, #000000e0 0%, #000000a8 26%, #00000047 62%, #0000 100%);
}

/* Corner falloff over the whole viewport. Two stops rather than one: an
   ellipse that reaches past the corners for the broad darkening, and a much
   tighter overlay that only bites in the corners themselves, which is what
   keeps the middle of the arena untouched instead of hazing it over. */
.vignette {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 108% at 50% 44%, #0000 46%, #0000005c 78%, #000000ab 100%),
    radial-gradient(76% 68% at 50% 46%, #0000 62%, #00000038 100%);
}

/* ---------- round strip ---------- */
/* The frame image and the placement of .roundstrip-inner inside its opening
   both come from web/hud/frames.js, measured off the artwork. */
.roundstrip {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 290px;
}
.panel-art {
  position: absolute;
  inset: 0;
  background: url(./hud/frame.webp) no-repeat center / 100% 100%;
  z-index: 2;
  pointer-events: none;
}
.roundstrip-inner {
  position: absolute;
  z-index: 1;
  display: grid;
  place-content: center;
  gap: 1px;
  text-align: center;
  background: #0b0810cc;
}
.roundstrip .round {
  font-size: 9px;
  letter-spacing: .2em;
  color: #9c8f7a;
}
.roundstrip .round b { color: #ece2d0; }
.roundstrip .timer {
  font: 700 20px Georgia;
  letter-spacing: .1em;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px #e7c47744;
}

/* ---------- nameplates ---------- */
.plates { position: absolute; inset: 0; }
/* Anchored by percentage of the overlay box, because the Bevy side publishes
   normalised 0..1 viewport coordinates. The transform then only carries the
   fixed centring offset. */
.nameplate {
  position: absolute;
  width: 168px;
  margin-left: -84px;
  text-align: center;
  transform: translateY(-100%);
  transition: opacity .18s;
}
/* left and top are set per plate by web/hud.js, from that warlock's own
   --w<index>-x / -y properties. */
.nameplate.off { opacity: 0; }
.nameplate.dead { opacity: .35; filter: grayscale(1); }
.nameplate .who {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  letter-spacing: .13em;
  color: #d9d1e0;
  text-shadow: 0 1px 3px #000, 0 0 8px #000;
}
.nameplate .bar {
  height: 5px;
  background: #14101a;
  border: 1px solid #00000099;
  box-shadow: 0 1px 4px #0009;
}
.nameplate .bar + .bar { height: 3px; margin-top: 2px; }
.nameplate .bar i { display: block; height: 100%; width: var(--fill, 100%); }
.nameplate.self .bar.hp i { background: var(--hp); box-shadow: 0 0 8px #e7b65288; }
.nameplate.ally .bar.hp i { background: #6fbf73; box-shadow: 0 0 8px #6fbf7388; }
.nameplate.foe .bar.hp i { background: var(--foe); box-shadow: 0 0 8px #c8402f88; }
.nameplate .bar.dp i { --fill: 0%; background: var(--dp); box-shadow: 0 0 6px #a173d888; }

/* ---------- floating combat text ---------- */
.fct-layer { position: absolute; inset: 0; overflow: hidden; }
.fct {
  position: absolute;
  font: 700 15px Georgia;
  letter-spacing: .04em;
  text-shadow: 0 2px 4px #000, 0 0 10px #000;
  animation: fct-rise 1.05s ease-out forwards;
  will-change: transform, opacity;
}
.fct.dmg { color: #ffe9a8; font-size: 18px; }
.fct.lava { color: #ff8a55; }
/* A pillar landing on you: cold stone, and the biggest number in the fight. */
.fct.crush { color: #d8dcf0; font-size: 21px; }
@keyframes fct-rise {
  0%   { transform: translate3d(-50%, 0, 0) scale(.7); opacity: 0; }
  18%  { transform: translate3d(-50%, -12px, 0) scale(1.12); opacity: 1; }
  100% { transform: translate3d(calc(-50% + var(--jitter, 0px)), -58px, 0) scale(.95); opacity: 0; }
}

/* ---------- action bar ---------- */
/* The carved frame is one image with measured openings; hud.js positions the
   slots, portrait and vital bars into those holes as percentages, so the whole
   bar scales as a unit. .bar-art paints the frame *over* its contents, letting
   the wood overlap the icons the way the artwork intends. */
.actionbar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: min(640px, 52vw);
  /* aspect-ratio comes from the frame's own dimensions, set by hud.js */
  pointer-events: none;
}
.bar-art {
  position: absolute;
  inset: 0;
  background: url(./hud/actionbar.webp) no-repeat center / 100% 100%;
  pointer-events: none;
  z-index: 2;
}
.actionbar .slot,
.actionbar .portrait,
.actionbar .vbar {
  position: absolute;
  z-index: 1;
}

.slot {
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: #0d0a12;
  cursor: pointer;
  overflow: hidden;
  pointer-events: auto;
  transition: filter .12s;
}
/* SpellIcons.png is a clean 6x5 grid, so percentage slicing lands exactly on
   cell boundaries at any rendered size. */
.slot i {
  position: absolute;
  inset: 0;
  background-image: url(./SpellIcons.webp);
  background-size: 600% 500%;
  background-position: calc(var(--col) * 20%) calc(var(--row) * 25%);
}
.slot kbd {
  position: absolute;
  right: 2px;
  bottom: 0;
  z-index: 3;
  font: 700 10px Arial;
  color: #f6f0d8;
  text-shadow: 0 1px 2px #000, 0 0 5px #000;
}
.slot .sweep {
  position: absolute;
  inset: 0;
  background: conic-gradient(from 0turn, #000000bf var(--cd, 0deg), transparent 0);
  opacity: 0;
  transition: opacity .1s;
}
.slot .cdnum {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  font: 700 15px Georgia;
  color: #fff;
  text-shadow: 0 2px 4px #000;
  opacity: 0;
}
.slot.cooling .sweep, .slot.cooling .cdnum { opacity: 1; }
.slot:hover:not(.locked) { filter: brightness(1.25); }
.slot.armed {
  box-shadow: inset 0 0 0 2px var(--gold), inset 0 0 16px #ffb03ccc;
  filter: brightness(1.3) saturate(1.15);
}
.slot.locked i { filter: grayscale(.45) brightness(.78); }
.slot.locked { cursor: default; }
.slot.locked::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #0b081059;
}
.slot.locked kbd { color: #a99bb3; }

/* ---------- portrait (the frame's centre ring) ---------- */
.portrait {
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-content: center;
  text-align: center;
  background: radial-gradient(circle at 50% 30%, #2a2029, #0d0a0d);
  box-shadow: inset 0 0 24px #000a;
}
/* Liquid fill rising from the bottom of the ring. */
.portrait::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--fill, 100%);
  background: url(./hud/bar-hp.webp) center / cover;
  opacity: .45;
  transition: none;
}
.portrait b {
  position: relative;
  font: 700 clamp(15px, 2.4vw, 27px) Georgia;
  color: #f4eefa;
  text-shadow: 0 2px 5px #000, 0 0 12px #000;
}
.portrait small {
  position: relative;
  display: block;
  font-size: clamp(7px, .8vw, 10px);
  letter-spacing: .18em;
  color: #cfc6d6;
  text-shadow: 0 1px 3px #000;
}
.portrait.critical { animation: portrait-pulse .9s ease-in-out infinite; }
@keyframes portrait-pulse {
  50% { box-shadow: inset 0 0 22px #c8402fcc; }
}

/* ---------- vital bars inside the frame's upper panel ---------- */
.vbar {
  overflow: hidden;
  border-radius: 999px;
  background: #0c0912;
  box-shadow: inset 0 1px 5px #000, inset 0 0 0 1px #00000066;
}
.vbar i {
  position: absolute;
  inset: 0;
  width: var(--fill, 100%);
}
.vbar.hp i { background: url(./hud/bar-hp.webp) left center / auto 100% repeat-x; }
.vbar.dp i { --fill: 0%; background: url(./hud/bar-dp.webp) left center / auto 100% repeat-x; }
.vbar span {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  font: 700 clamp(8px, 1.05vw, 13px) Arial;
  letter-spacing: .1em;
  color: #f2ecf6;
  text-shadow: 0 1px 3px #000, 0 0 6px #000;
}

/* ---------- control hints ---------- */
.hints {
  position: absolute;
  bottom: 12px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 10px;
  letter-spacing: .1em;
  color: #9a90a5;
  white-space: nowrap;
  text-shadow: 0 1px 3px #000;
}
.hints > span { display: flex; align-items: center; gap: 6px; }
.hints kbd {
  font: 700 9px Arial;
  color: #cec5d6;
  border: 1px solid #4b3f53;
  border-radius: 2px;
  padding: 2px 4px;
  background: #1a1420;
}


/* ---------- dummy behaviour panel ---------- */
/* The one corner of the HUD the player drives rather than reads. It is dressed
   entirely in the brass kit from web/ui: the plate, the switches and both
   corner buttons are nine-slices and sprites straight out of kit.css. Each
   piece carries its own --ui-scale rather than sharing the panel's, because
   the kit sizes everything off that one number and the plate wants a heavier
   frame than a 22px toggle does. */
.ui-word { display: inline-block; line-height: 1; white-space: nowrap; }

.dummy-panel {
  --ui-scale: .33;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  width: 280px;
  padding: 2px 2px 4px;
  pointer-events: auto;
}
.dummy-panel[hidden] { display: none; }

.dummy-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.dummy-panel .fold {
  --ui-scale: .19;
  flex: none;
  padding: 0;
  border: 0;
  cursor: pointer;
}
/* The UA's own focus ring is a blue that has no business on brass. */
.dummy-panel .fold:focus-visible,
.dummy-open:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }

.dummy-panel .switch {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 4px 3px;
  border: 0;
  border-radius: 3px;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .12s;
}
.dummy-panel .switch:hover { background: #ffffff10; }
.dummy-panel .switch:focus-visible { outline: 1px solid var(--gold); outline-offset: -1px; }
/* Both toggle states already share one box from kit.css, so flipping a switch
   cannot shift the label beside it. The scale is set here because the kit
   sizes everything off that one number. */
.dummy-panel .knob {
  --ui-scale: .26;
  flex: none;
}

.dummy-panel .what { display: grid; gap: 1px; min-width: 0; }
/* The plate is a busy crimson weave, so both label sizes carry a shadow to
   sit off it rather than in it. */
.dummy-panel .what b {
  font: 700 11px Georgia;
  letter-spacing: .05em;
  color: #b6a48f;
  text-shadow: 0 1px 2px #000a;
  transition: color .12s;
}
.dummy-panel .switch[aria-checked="true"] .what b { color: var(--gold); }
.dummy-panel .what small {
  font-size: 9px;
  line-height: 1.35;
  color: #bcae9f;
  text-shadow: 0 1px 2px #000c;
}

/* Folded away, the panel leaves a single stud behind so the corner can be
   cleared for a fight without losing the way back to the switches. */
.dummy-open {
  --ui-scale: .25;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  display: grid;
  place-content: center;
  padding: 0;
  border: 0;
  cursor: pointer;
  pointer-events: auto;
}
.dummy-open[hidden] { display: none; }


/* ---------- tooltip ---------- */
/* The frame is the kit's tooltip nine-slice, so no border or radius is set
   here - kit.css owns those and styles.css must not overwrite them.

   Width is taken from the artwork's own width (--ui-w) rather than a round
   number, which makes the horizontal middle come out at exactly its drawn
   size: nothing along the bottom edge is squeezed, and the pointer sitting in
   it keeps the width it was painted at. Only the height ever stretches, which
   is the axis the content actually varies on. It works out to ~321px, leaving
   the same ~265px of text as the old 290px box did.

   The frame is hollow, so --ui-fill backs the opening for the text to read
   against, and the shadow is a drop-shadow because a box-shadow would trace
   the border box and this frame is not a rectangle. */
.tooltip {
  --ui-scale: .63;
  --ui-fill: #0d0a12f2;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 6;
  width: calc(var(--ui-w) * 1px * var(--ui-scale));
  padding: 0;
  filter: drop-shadow(0 10px 16px #000b);
  pointer-events: none;
}
.tooltip header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tooltip b { font: 700 14px Georgia; letter-spacing: .05em; color: var(--gold); }
.tooltip kbd {
  font: 700 10px Arial;
  color: #e9e2ee;
  border: 1px solid #63576b;
  border-radius: 2px;
  padding: 2px 5px;
  background: #211a26;
}
.tooltip em {
  display: block;
  margin-top: 4px;
  font-style: normal;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #9d8fa8;
}
.tooltip p { margin: 8px 0 0; font-size: 12px; line-height: 1.45; color: #cdc4d4; }
.tooltip p.note { color: #97cf9a; font-style: italic; }
.tooltip p.locked-note { color: #d9925f; }

/* ---------- victory, defeat ---------- */
#victory,
#defeat {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  background: #07050999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s;
}
#victory.active,
#defeat.active { opacity: 1; }
#victory b,
#defeat b {
  font: 700 30px Georgia;
  letter-spacing: .22em;
  color: var(--gold);
  text-shadow: 0 0 24px #ff7b32;
}
#defeat b { color: #d8504a; text-shadow: 0 0 24px #7a1410; }
#victory span,
#defeat span,
#eliminated span { font-size: 13px; letter-spacing: .08em; color: #d7c9bd; }

/* The match is still on, so this must not hide it. */
#eliminated {
  position: absolute;
  left: 50%;
  top: 14%;
  z-index: 5;
  display: grid;
  gap: 4px;
  padding: 10px 26px;
  text-align: center;
  background: #07050999;
  border: 1px solid #5b2a27;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s;
}
#eliminated.active { opacity: 1; }
#eliminated b { font: 700 20px Georgia; letter-spacing: .2em; color: #d8504a; }

/* The behaviour panel belongs to the training dummy. */
#hud-root[data-mode="match"] .dummy-panel,
#hud-root[data-mode="match"] .dummy-open { display: none !important; }

/* ---------- rooms ---------- */
.lobby-open,
.lobby-leave {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 4;
  pointer-events: auto;
  padding: 6px 12px;
  font: 700 11px Georgia;
  letter-spacing: .18em;
  color: var(--gold);
  background: #0e0b12cc;
  border: 1px solid #5a4630;
  cursor: pointer;
}
.lobby-open:hover,
.lobby-leave:hover { background: #1b1424e6; }
.lobby-open[hidden], .lobby-leave[hidden] { display: none; }

.lobby {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 6;
  width: 270px;
  padding: 12px 14px 14px;
  pointer-events: auto;
  background: #0e0b12ee;
  border: 1px solid #5a4630;
  box-shadow: 0 6px 24px #000a;
  font-size: 12px;
  color: #d9d1e0;
}
.lobby[hidden] { display: none; }
.lobby header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.lobby header b { font: 700 12px Georgia; letter-spacing: .2em; color: var(--gold); }
.lobby .x { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.lobby section[hidden] { display: none; }
.lobby section { display: grid; gap: 8px; }
.lobby button,
.lobby input {
  font: inherit;
  padding: 7px 10px;
  color: var(--ink);
  background: #1b1424;
  border: 1px solid #4a3a52;
}
.lobby button { cursor: pointer; }
.lobby button:hover:not(:disabled) { background: #2a1f35; }
.lobby button:disabled { opacity: .45; cursor: default; }
.lobby button.primary { color: #1a1008; background: var(--gold); border-color: #a98748; font-weight: 700; }
.lobby button.primary:hover:not(:disabled) { background: #f0d28f; }
.lobby .or { text-align: center; color: var(--muted); font-size: 11px; }
.lobby .join { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.lobby input { text-transform: uppercase; letter-spacing: .25em; text-align: center; min-width: 0; }
.lobby .row { display: grid; grid-auto-flow: column; gap: 6px; }
.lobby p { margin: 0; }
.lobby .code b { font: 700 18px Georgia; letter-spacing: .3em; color: var(--gold); margin-left: 6px; }
.lobby .share a { color: #8fb4e8; font-size: 11px; word-break: break-all; }
.lobby .hint, .lobby .count { color: var(--muted); }
.lobby .status.bad { color: #e0776c; }

.net-stall {
  position: absolute;
  top: 44px;
  left: 50%;
  z-index: 5;
  transform: translateX(-50%);
  padding: 6px 16px;
  background: #07050999;
  border: 1px solid #5b2a27;
  font-size: 12px;
  letter-spacing: .08em;
  color: #e0a79f;
  pointer-events: none;
}
.net-stall[hidden] { display: none; }

@media (max-width: 720px) {
  .roundstrip { width: 190px; top: 0; }
  .roundstrip .timer { font-size: 14px; }
  .actionbar { width: 62vw; }
  .slot kbd { font-size: 8px; }
  .slot .cdnum { font-size: 12px; }
  .tooltip { width: min(calc(var(--ui-w) * 1px * var(--ui-scale)), calc(100vw - 16px)); }
  .nameplate { width: 132px; margin-left: -66px; }
  .hints { display: none; }
  /* Too little room to explain each switch; the labels have to carry it. */
  .dummy-panel { width: 200px; }
  .dummy-panel .what small { display: none; }
}
