/*
  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 {
  color-scheme: dark;
  /* UX cinza (lobby Brotato). Artes de armas/personagens/coin ficam nos PNGs. */
  --bg: #1a1a1a;
  --arena: #222222;
  --panel: #1f1f1f;
  --ink: #ececec;
  --muted: #9a9a9a;
  --accent: #c8c8c8;
  --accent-2: #8fbf7a;
  --danger: #e2554a;
  --coin: #d4d4d4;
  --line: #3a3a3a;
  --shadow: rgba(0, 0, 0, 0.55);
  --panel-2: #262626;
  --panel-3: #2e2e2e;
  --focus: #f0f0f0;
  /* 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);
}

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

html,
body {
  height: 100%;
  background: radial-gradient(ellipse at 50% 20%, #2f2f2f 0%, var(--bg) 70%);
  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 {
  position: absolute;
  pointer-events: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: 6px;
  padding: clamp(7px, 1.2vw, 16px);
  width: var(--stage-w);
  height: var(--stage-h);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.hud-vitals,
.hud-right {
  display: grid;
  gap: 5px;
}

.hud-vitals {
  width: min(100%, 176px);
}

.hud-right {
  justify-items: end;
}

.hud-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

#hud .stat,
.wep-chip {
  min-width: 0;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid #4a4a4a;
  box-shadow: inset 0 0 0 2px var(--bg), 0 2px 0 rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums;
}

#hud .stat {
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 700;
}

.hud-meter-header,
.hud-controls .materials,
.aim-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
}

.hud-meter-header {
  justify-content: space-between;
  margin-bottom: 4px;
  white-space: nowrap;
}

#hud .label {
  color: #cab89c;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud-meter .bar {
  height: 9px;
  border: 1px solid #0e0a07;
  background: #463627;
  overflow: hidden;
}

#hp-fill,
#xp-fill {
  height: 100%;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.21);
}

#hp-fill {
  width: 100%;
  background: #ce5447;
}

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

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

.hud-round > div {
  display: grid;
  min-width: 48px;
  padding: 5px 7px;
  font-size: 17px;
  line-height: 1.15;
}

.hud-round > div + div {
  border-left: 1px solid #4a4a4a;
}

.danger-badge {
  grid-column: 1 / -1;
  padding: 2px 5px;
  border-top: 1px solid var(--line);
  color: var(--coin);
  font-size: 0.6875rem;
  font-weight: 700;
}

#hud .materials {
  color: var(--coin);
  font-size: 15px;
}

.aim-toggle {
  pointer-events: auto;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  white-space: nowrap;
}

.aim-indicator {
  width: 17px;
  height: 10px;
  padding: 1px;
  border: 1px solid currentColor;
  color: inherit;
}

.aim-indicator::after {
  display: block;
  content: "";
  width: 5px;
  height: 6px;
  background: currentColor;
}

#hud .aim-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--coin);
}

.aim-toggle[aria-pressed="true"] .aim-indicator::after {
  margin-left: auto;
}

#weapon-strip {
  display: flex;
  gap: 4px;
}

.wep-chip {
  display: grid;
  place-items: center;
  width: 31px;
  height: 30px;
  border-top: 2px solid var(--tier-color);
}

.wep-chip .asset-img {
  width: 24px;
  height: 24px;
}

#hud #crate-notice {
  position: absolute;
  inset: auto auto 14px 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px #412a17, 0 3px 0 #100b07;
  width: max-content;
  max-width: calc(100% - 20px);
  color: var(--coin);
  text-align: center;
}

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

@media (max-width: 520px) {
  #hud .stat { font-size: 11px; padding-inline: 5px; }
  .hud-meter .bar { height: 7px; }
  .hud-round > div { min-width: 35px; padding-inline: 4px; font-size: 13px; }
  .aim-indicator { display: none; }
  .wep-chip { width: 24px; height: 22px; }
  .wep-chip .asset-img { width: 19px; height: 19px; }
}

.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: rgba(12, 12, 12, 0.78);
  backdrop-filter: blur(2px);
  z-index: 5;
}

.panel {
  width: min(92%, 520px);
  max-width: 100%;
  max-height: 100%;
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 28px 28px 24px;
  box-shadow: 0 24px 48px var(--shadow);
  overflow: auto;
}

.title-panel {
  text-align: center;
}

/* Shared lobby / icon primitives */
.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%;
}

.icon-slot {
  box-sizing: border-box;
  width: var(--slot-size);
  height: var(--slot-size);
  display: grid;
  place-items: center;
  padding: 4px;
  overflow: hidden;
}

.icon-slot img,
.icon-slot .asset-img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.stat-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 12px;
}

h1 {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(28px, 6vw, 42px);
  line-height: 1.25;
  margin-bottom: 16px;
  color: var(--ink);
}

h1 span {
  color: var(--accent);
}

h2 {
  font-family: "Press Start 2P", monospace;
  font-size: 16px;
  line-height: 1.4;
  margin-bottom: 8px;
}

.tagline {
  color: var(--muted);
  margin-bottom: 22px;
  line-height: 1.5;
}

.btn {
  appearance: none;
  border: 2px solid var(--line);
  background: #2e2e2e;
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: #3a3a3a;
  border-color: var(--accent);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: #3a3a3a;
  border-color: #5a5a5a;
  color: #f2f2f2;
}

.btn.primary:hover {
  background: #4a4a4a;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.controls {
  list-style: none;
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

kbd {
  display: inline-block;
  min-width: 52px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  background: #1a1510;
  color: var(--ink);
  font-family: inherit;
  font-size: 11px;
  margin-right: 6px;
  text-align: center;
}

.asset-img {
  display: inline-block;
  image-rendering: pixelated;
  vertical-align: middle;
  object-fit: contain;
}

.asset-img { width: 28px; height: 28px; }
.asset-img.xs { width: 18px; height: 18px; }
.asset-img.lg { width: 48px; height: 48px; }
.asset-img.xl { width: 64px; height: 64px; }
.asset-img.dim { opacity: 0.35; }

.game-panel {
  --frame-edge: #4a4a4a;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: clamp(16px, 2.4vw, 28px);
  border: 2px solid var(--frame-edge);
  background: var(--panel);
  box-shadow: inset 0 0 0 1px #111, 0 16px 40px var(--shadow);
  clip-path: none;
  scrollbar-color: #5a5a5a var(--bg);
}

.panel-heading .eyebrow {
  margin-bottom: 7px;
}

.panel-heading h2 {
  margin: 0;
  font-size: clamp(0.88rem, 2vw, 1.2rem);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #111;
}

.panel-heading .tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.game-panel button:focus-visible,
.menu-btn:focus-visible,
.aim-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.tier-1 { --tier-color: #c1b9aa; }
.tier-2 { --tier-color: #a6bd79; }
.tier-3 { --tier-color: #f0ba60; }
.tier-4 { --tier-color: #f08a75; }

.coin { color: var(--coin); }

.tier-card {
  box-shadow: inset 0 4px 0 var(--tier-color), inset 0 0 0 2px #130e09;
}
