/*
  Layout contract (Brotato Lite)
  - #app centers the stage in the viewport.
  - Stage is 16:9 via --stage-w / --stage-h.
  - Each .screen is a shell that fills 100% of the stage (no scroll, no overflow).
  - Icon slots are square: overflow hidden + object-fit contain; size via --slot-size.
  - Character lobby: name + large art + bonuses + footer; weapon: char preview + detail + icon strip.
*/

:root {
  /* Quase tela cheia, mantém 16:9 */
  --stage-w: min(98vw, calc((100vh - 16px) * 16 / 9));
  --stage-h: calc(var(--stage-w) * 9 / 16);
  /* Slot tokens — escalam com o stage */
  --slot-size: clamp(40px, calc(var(--stage-w) * 0.048), 72px);
  --weapon-slot-size: clamp(44px, calc(var(--stage-w) * 0.055), 80px);
  --slot-gap: clamp(4px, calc(var(--stage-w) * 0.005), 8px);
  --panel-radius: 4px;
  --lobby-gap: clamp(6px, calc(var(--stage-w) * 0.008), 12px);
  --lobby-pad: clamp(6px, calc(var(--stage-w) * 0.008), 12px);

  /* HUD */
  --hud-gold: #ffd384;
  --hud-edge: linear-gradient(155deg, #868380, #48484a 28%, #4b4b4d 68%, #7a7774);
  --hud-fill: linear-gradient(164deg, #282727, #141414 70%);
  --hud-label-ink: #cab89c;
  --hud-timer-track: #1c1917;
  --hud-timer-line: #101010;
  --hud-timer-fill: linear-gradient(180deg, #f9d184, #c89546);
  --hud-timer-glint: #fff1d477;
  --hud-timer-low: linear-gradient(180deg, #ffc35e, #d48023);
  --hud-timer-urgent: linear-gradient(180deg, #ff7e6a, #bf3b35);
  --hud-meter-divider: #3b3837;
  --hud-meter-line: #100d0d;
  --hud-hp-track: #402929;
  --hud-xp-track: #3c3225;
  --hud-hp-fill: linear-gradient(180deg, #ed7464, #ba4137);
  --hud-xp-fill: linear-gradient(180deg, #f4cb74, #bd853b);
  --hud-round-divider: #403c39;
  --hud-urgent-ink: #ff7667;
  --hud-danger-divider: #5b4438;
  --hud-danger-fill: #342721;
  --hud-danger-ink: #ffc08c;
  --hud-key-line: #6b6560;
  --hud-toggle-picked-edge: linear-gradient(155deg, #d89855, #755234 44%, #6b5140 72%, #b98452);
  --hud-toggle-picked-fill: linear-gradient(164deg, #3d2e21, #1c1816 76%);
  --hud-toggle-hover-edge: #c3a481;
  --hud-warning-stroke: #251913;
  --hud-crate-edge: linear-gradient(155deg, #ecc27f, #8b623c 38%, #775038 68%, #c9955b);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--page-background);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  overflow: hidden;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
}

#game {
  width: var(--stage-w);
  height: var(--stage-h);
  aspect-ratio: 16 / 9;
  background: var(--arena);
  border: 3px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 20px 60px var(--shadow);
  image-rendering: pixelated;
  display: block;
}

.hidden {
  display: none !important;
}

#hud {
  --hud-gutter: clamp(6px, calc(var(--stage-w) * 0.012), 19px);
  --hud-gap: clamp(3px, calc(var(--stage-w) * 0.006), 9px);
  --hud-label-size: clamp(8px, calc(var(--stage-w) * 0.011), 14px);
  --hud-control-size: clamp(23px, calc(var(--stage-w) * 0.035), 46px);
  --hud-weapon-size: clamp(21px, calc(var(--stage-w) * 0.035), 46px);
  --hud-timer-height: 5px;
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: var(--stage-w);
  height: var(--stage-h);
  pointer-events: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(76px, calc(var(--stage-w) * 0.155), 222px) minmax(0, 1fr);
  align-content: start;
  align-items: start;
  gap: var(--hud-gap);
  padding: calc(var(--hud-timer-height) + var(--hud-gutter)) var(--hud-gutter) var(--hud-gutter);
  font-size: clamp(10px, calc(var(--stage-w) * 0.014), 19px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

#hud .hud-frame {
  --bevel-cut: clamp(4px, calc(var(--stage-w) * 0.006), 9px);
  --bevel-stroke: 2px;
  --bevel-edge: var(--hud-edge);
  --bevel-fill: var(--hud-fill);
}

.hud-label {
  color: var(--hud-label-ink);
  font-size: var(--hud-label-size);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#wave-timer-bar {
  position: absolute;
  inset: 0 0 auto;
  height: var(--hud-timer-height);
  background: var(--hud-timer-track);
  box-shadow: 0 1px 0 var(--hud-timer-line);
  overflow: hidden;
}

#wave-timer-fill {
  height: 100%;
  transform-origin: left center;
  background: var(--hud-timer-fill);
  box-shadow: inset 0 1px var(--hud-timer-glint);
}

#wave-timer-bar.is-low #wave-timer-fill {
  background: var(--hud-timer-low);
}

#wave-timer-bar.is-urgent #wave-timer-fill {
  background: var(--hud-timer-urgent);
  animation: hud-urgent-pulse 0.55s ease-in-out infinite alternate;
}

.hud-vitals {
  display: grid;
  gap: 0.45em;
  width: min(100%, clamp(105px, calc(var(--stage-w) * 0.19), 264px));
  padding: 0.5em 0.7em 0.6em;
}

.hud-meter + .hud-meter {
  border-top: 1px solid var(--hud-meter-divider);
  padding-top: 0.32em;
}

.hud-meter-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.24em;
  margin-bottom: 0.28em;
  white-space: nowrap;
}

.hud-meter-track {
  height: clamp(6px, calc(var(--stage-w) * 0.01), 13px);
  border: 1px solid var(--hud-meter-line);
  background: var(--hud-hp-track);
  overflow: hidden;
}

#xp-bar {
  height: clamp(5px, calc(var(--stage-w) * 0.008), 10px);
  background: var(--hud-xp-track);
}

#hp-fill,
#xp-fill {
  height: 100%;
  box-shadow: inset 0 1px #ffffff40, inset 0 -1px #0003;
}

#hp-fill {
  width: 100%;
  background: var(--hud-hp-fill);
}

#xp-fill {
  width: 0;
  background: var(--hud-xp-fill);
}

.hud-round {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: var(--bevel-stroke);
  text-align: center;
}

.hud-round > div {
  display: grid;
  justify-items: center;
  gap: 0.16em;
  padding: 0.46em 0.24em;
}

.hud-round > div + div {
  border-left: 1px solid var(--hud-round-divider);
}

#wave-text,
#timer-text {
  font-size: clamp(15px, calc(var(--stage-w) * 0.024), 33px);
  line-height: 1.08;
}

#timer-text {
  color: var(--hud-gold);
}

#timer-text.is-urgent {
  color: var(--hud-urgent-ink);
  transform: scale(1.18);
  animation: hud-urgent-pulse 0.55s ease-in-out infinite alternate;
}

.danger-badge {
  grid-column: 1 / -1;
  padding: 0.32em 0.4em;
  border-top: 1px solid var(--hud-danger-divider);
  background: var(--hud-danger-fill);
  color: var(--hud-danger-ink);
  font-size: var(--hud-label-size);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-left {
  display: grid;
  justify-items: start;
  gap: var(--hud-gap);
  min-width: 0;
}

.hud-right {
  display: grid;
  justify-items: end;
  gap: var(--hud-gap);
  min-width: 0;
}

.hud-economy {
  display: grid;
  gap: 0.28em;
  width: fit-content;
  justify-items: start;
}

.hud-materials,
.hud-poupanca,
.aim-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  min-height: var(--hud-control-size);
  padding-inline: 0.58em;
}

.hud-materials {
  width: fit-content;
  color: var(--hud-gold);
}

.hud-poupanca {
  width: fit-content;
  color: var(--ink);
  min-height: calc(var(--hud-control-size) * 0.88);
  font-size: 0.92em;
  transform-origin: left center;
}

.hud-poupanca[hidden] {
  display: none !important;
}

.hud-poupanca.is-reveal {
  animation: poupanca-reveal 0.38s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.hud-poupanca.is-catch {
  animation: poupanca-catch 0.14s ease-out;
}

@keyframes poupanca-reveal {
  from {
    opacity: 0;
    transform: translateY(-0.35em) scale(0.72);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes poupanca-catch {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

#hud-coin,
#hud-bag {
  width: 1.35em;
  height: 1.35em;
}

#hud-bag {
  width: 1.2em;
  height: 1.2em;
}

.aim-toggle {
  pointer-events: auto;
  cursor: pointer;
  border: 0;
  color: var(--hud-label-ink);
  font: inherit;
  font-size: var(--hud-label-size);
  white-space: nowrap;
}

.aim-toggle strong {
  display: inline-block;
  min-width: 4.5ch;
  color: var(--ink);
}

.aim-key {
  min-width: 1.35em;
  padding: 0.12em 0.22em;
  border: 1px solid var(--hud-key-line);
  border-radius: 2px;
  font: inherit;
  text-align: center;
  box-shadow: 0 1px var(--ink-shadow);
}

#hud .aim-toggle[aria-pressed="true"] {
  --bevel-edge: var(--hud-toggle-picked-edge);
  --bevel-fill: var(--hud-toggle-picked-fill);
}

.aim-toggle[aria-pressed="true"] strong,
.aim-toggle[aria-pressed="true"] .aim-key {
  color: var(--hud-gold);
}

#hud .aim-toggle:hover {
  --bevel-edge: var(--hud-toggle-hover-edge);
}

#weapon-strip {
  display: grid;
  justify-items: start;
  gap: var(--hud-gap);
  list-style: none;
}

#hud .wep-entry {
  --bevel-edge: var(--tier-hud-edge);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  width: fit-content;
  min-height: var(--hud-control-size);
  padding-inline: 0.58em;
}

.wep-entry .wep-art {
  width: 1.35em;
  height: 1.35em;
}

.wep-dmg {
  color: var(--hud-gold);
  font-size: inherit;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.weapon-overflow {
  color: var(--hud-label-ink);
  font-size: var(--hud-label-size);
  padding-inline: 0.16em;
}

#hud #crate-notice {
  --bevel-edge: var(--hud-crate-edge);
  position: absolute;
  inset: auto auto var(--hud-gutter) 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2 * var(--hud-gutter));
  padding: 0.55em 1em;
  color: var(--hud-gold);
  text-align: center;
}

#crate-notice:empty {
  opacity: 0;
}

@keyframes hud-urgent-pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.32); }
}

#hud[inert] #wave-timer-fill,
#hud[inert] #timer-text {
  animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
  #wave-timer-bar.is-urgent #wave-timer-fill,
  #timer-text.is-urgent {
    animation: none;
  }
}

.screen {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: var(--stage-w);
  height: var(--stage-h);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--screen-shade);
  backdrop-filter: blur(2px);
  z-index: 5;
}

/* Layout das grades do lobby */
.lobby-shell {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--lobby-gap);
  padding: var(--lobby-pad);
}

.icon-grid {
  flex: 0 0 auto;
  display: grid;
  gap: var(--slot-gap);
  padding: 0;
  border: 0;
  background: transparent;
  justify-content: center;
  margin-inline: auto;
  max-width: 100%;
}
