:root{padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px);box-sizing:border-box;height:100%}body{margin:0}[hidden]{display:none!important}

/* Layout: one full-bleed stage (640x360 canvas scaled to fit) with menu screens layered on top.
   Single deliberate dark look taken from the Troopers NFT palette: gunmetal, NFT teal, coin gold, blood. */
:root {
  --ink: #101314;
  --panel: #1b2123;
  --panel-2: #252d2f;
  --line: #3a4948;
  --text: #e6e3d6;
  --muted: #9ba7a3;
  --teal: #80a5a7;
  --gold: #e3aa3c;
  --blood: #b8433a;
  --hp: #cf4a3f;
  --hp-back: #3a1f1d;
  --display: "Silkscreen", "Courier New", monospace;
  --body: "VT323", "Courier New", monospace;
  color-scheme: dark;
}
html, body { height: 100%; }
body { background: var(--ink); color: var(--text); font-family: var(--body); font-size: 20px; overflow: hidden; }
#app {
  position: relative; height: 100%;
  display: grid; place-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 8px;
  box-sizing: border-box;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(128,165,167,.10), transparent 60%),
    var(--ink);
}
#stage { position: relative; width: 640px; height: 360px; box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--line), 0 18px 60px rgba(0,0,0,.6); }
#view { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; touch-action: none; }

/* ---------- HUD (inside the stage, scales with it) */
#hud { position: absolute; inset: 0; pointer-events: none; font-family: var(--display); }
/* HUD sizes are in em: the stage font-size is 8px per 1x of zoom, so the HUD scales with the pixels */
.hud-top { position: absolute; left: 1.5em; top: 1.2em; display: flex; flex-direction: column; gap: .6em; }
.hpbar { width: 15em; height: 1.5em; background: var(--hp-back); box-shadow: 0 0 0 2px #000, inset 0 -3px 0 rgba(0,0,0,.35); position: relative; }
.hpbar > i { position: absolute; inset: 0 auto 0 0; background: var(--hp); box-shadow: inset 0 3px 0 rgba(255,255,255,.18), inset 0 -3px 0 rgba(0,0,0,.25); transition: width .15s steps(4); }
.hpbar.armor { height: 1.1em; background: #1d2a36; }
.needs { display: flex; gap: .5em; width: 15em; }
.hpbar.need { width: auto; flex: 1; height: 1.1em; background: #33281a; }
.hpbar.need > i { background: #d39a3c; }
.hpbar.need.water { background: #1a2a36; }
.hpbar.need.water > i { background: #4f9bd6; }
.hpbar.need.low { animation: needblink 1s steps(2) infinite; }
@keyframes needblink { 50% { box-shadow: 0 0 0 2px #b8433a; } }
.hpbar.armor > i { background: #6f9fcf; }
.hpbar > span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .75em; color: var(--text); text-shadow: 1px 1px 0 #000; letter-spacing: .06em; }
.stats .clock { color: #c9d4e8; }
.stats { display: flex; gap: 1.4em; font-size: 1em; text-shadow: 1px 1px 0 #000; font-variant-numeric: tabular-nums; }
.stats b { color: var(--gold); font-weight: 400; }
.stats .k b { color: var(--teal); }
.hud-btn { position: absolute; right: 1.5em; top: 1.2em; pointer-events: auto; font-size: .9em; padding: .5em .8em; }
#mute-btn { right: 68px; top: 6px; width: 48px; height: 48px; padding: 0; font-size: 0; image-rendering: pixelated; }
#mute-btn, #mute-btn:hover, #mute-btn:active { border: 0; box-shadow: none; transform: none; background: url(assets/ui_sound.png) 0 0 / 288px 48px no-repeat transparent; }
#mute-btn:hover { background-position: -48px 0; }
#mute-btn:active { background-position: -96px 0; }
#mute-btn[aria-pressed="true"] { background-position: -144px 0; }
#mute-btn[aria-pressed="true"]:hover { background-position: -192px 0; }
#mute-btn[aria-pressed="true"]:active { background-position: -240px 0; }
#toast { position: absolute; left: 50%; top: 16%; transform: translateX(-50%); font-family: var(--display); font-size: 1.4em; color: var(--gold); text-shadow: 2px 2px 0 #000; white-space: nowrap; opacity: 0; transition: opacity .25s; }
#toast.on { opacity: 1; }

/* ---------- touch controls */
#touch { position: absolute; inset: 0; pointer-events: none; }
#stick { position: absolute; left: 4%; bottom: 8%; width: 26%; aspect-ratio: 1; max-width: 140px; border-radius: 50%; background: rgba(16,19,20,.35); box-shadow: 0 0 0 2px rgba(128,165,167,.5); pointer-events: auto; touch-action: none; }
#stick i { position: absolute; left: 50%; top: 50%; width: 42%; aspect-ratio: 1; margin: -21% 0 0 -21%; border-radius: 50%; background: rgba(128,165,167,.55); }
.tbtn { position: absolute; pointer-events: auto; touch-action: none; border: 0; border-radius: 50%; font-family: var(--display); color: var(--text); background: rgba(27,33,35,.7); box-shadow: 0 0 0 2px var(--line); }
#t-attack { right: 5%; bottom: 10%; width: 17%; max-width: 92px; aspect-ratio: 1; font-size: 12px; box-shadow: 0 0 0 2px var(--blood); }
#t-use { right: 24%; bottom: 8%; width: 11%; max-width: 60px; aspect-ratio: 1; font-size: 12px; }
#t-reload { right: 19%; bottom: 36%; width: 9%; max-width: 50px; aspect-ratio: 1; font-size: 11px; }
#t-swap { right: 6%; bottom: 42%; width: 11%; max-width: 60px; aspect-ratio: 1; font-size: 10px; }


/* ---------- full screens (menus) */
.screen { position: absolute; inset: 0; z-index: 5; overflow-y: auto; display: grid; place-items: center;
  padding-block: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: rgba(10,12,13,.82); backdrop-filter: blur(2px); box-sizing: border-box; }
.card { width: min(100%, 760px); background: var(--panel); box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--line), 0 24px 80px rgba(0,0,0,.6); padding: 22px; box-sizing: border-box; display: grid; gap: 16px; }
.card.narrow { width: min(100%, 460px); }
.card.shop-card { width: min(100%, 760px); }
h1, h2 { font-family: var(--display); font-weight: 700; margin: 0; text-wrap: balance; letter-spacing: .04em; }
h1 { font-size: clamp(30px, 6vw, 46px); line-height: 1; color: var(--text); text-shadow: 3px 3px 0 #000, 0 0 0 var(--blood); }
h1 span { color: var(--blood); }
h2 { font-size: 18px; }
.tag { font-family: var(--display); font-size: 11px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; margin-top: 6px; }
.select-grid { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 620px) { .select-grid { grid-template-columns: minmax(0, 1fr); } .trait { grid-template-columns: 76px 36px minmax(0, 1fr) 36px; } .trait output { font-size: 18px; padding-inline: 6px; } }
.touch-only { display: none; }
.is-touch .touch-only { display: block; }
.is-touch .keys-only { display: none; }
.preview { display: grid; gap: 8px; justify-items: center; }
.preview .plate { width: 100%; max-width: 220px; aspect-ratio: 1; background: var(--teal); box-shadow: inset 0 0 0 2px #000; display: grid; place-items: end center; position: relative; overflow: hidden; }
.preview canvas { width: 100%; aspect-ratio: 1; image-rendering: pixelated; }
.preview .who { font-family: var(--display); font-size: 12px; color: var(--gold); letter-spacing: .06em; }
.traits { display: grid; gap: 8px; }
.trait { display: grid; grid-template-columns: 92px 36px minmax(0, 1fr) 36px; gap: 8px; align-items: center; }
.trait label { font-family: var(--display); font-size: 11px; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }
.trait output { background: var(--panel-2); box-shadow: inset 0 0 0 2px #000; padding: 4px 10px; font-size: 20px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.idbox { display: flex; gap: 8px; align-items: center; }
.idbox label { font-family: var(--display); font-size: 11px; color: var(--muted); letter-spacing: .1em; }
input[type=number] { width: 84px; font: inherit; font-size: 20px; background: var(--panel-2); color: var(--text); border: 0; box-shadow: inset 0 0 0 2px #000; padding: 4px 8px; }
.btn { font-family: var(--display); font-size: 12px; letter-spacing: .08em; color: var(--text); background: var(--panel-2); border: 0; padding: 9px 14px; cursor: pointer;
  box-shadow: 0 0 0 2px #000, inset 0 -3px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.06); }
.btn:hover { background: #2f3a3c; }
.btn:active { transform: translateY(1px); box-shadow: 0 0 0 2px #000, inset 0 2px 0 rgba(0,0,0,.35); }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.go { background: var(--blood); color: #fff; font-size: 15px; padding: 12px 22px; }
.btn.go:hover { background: #cc4c42; }
.btn.small { padding: 6px 0; width: 36px; font-size: 14px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.help { font-size: 18px; color: var(--muted); line-height: 1.1; }
.help kbd { font-family: var(--display); font-size: 10px; color: var(--text); background: var(--panel-2); box-shadow: 0 0 0 1px #000; padding: 2px 5px; }
.shop-head { display: grid; grid-template-columns: 72px minmax(0,1fr); gap: 14px; align-items: center; }
.shop-head canvas { width: 72px; height: 72px; image-rendering: pixelated; background: var(--panel-2); box-shadow: inset 0 0 0 2px #000; }
.shop-head p { margin: 0; font-size: 20px; line-height: 1.05; }
.shop-head b { font-family: var(--display); font-weight: 400; font-size: 11px; color: var(--teal); display: block; margin-bottom: 4px; letter-spacing: .08em; }
.wallet { font-family: var(--display); font-size: 13px; color: var(--gold); }
.offers { display: grid; gap: 10px; }
.pack-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.card:has(.pack-grid) { width: min(100%, 980px); }
@media (max-width: 900px) { .pack-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .pack-grid { grid-template-columns: minmax(0, 1fr); } }
.pack-list { display: grid; gap: 6px; margin-top: 8px; }
.pack-item { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; background: var(--panel-2); box-shadow: inset 0 0 0 2px #000; padding: 4px 8px; font-size: 19px; }
.pack-item canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.pack-item b { font-family: var(--display); font-weight: 400; font-size: 11px; color: var(--gold); font-variant-numeric: tabular-nums; }
.small-help { font-size: 16px; margin-top: 8px; }
.stash-list { max-height: min(52vh, 460px); overflow-y: auto; padding-right: 4px; }
.pack-item.stash-row, .stash-head { grid-template-columns: 24px minmax(0, 1fr) 64px 64px 112px; }
@media (max-width: 520px) { .pack-item.stash-row, .stash-head { grid-template-columns: 20px minmax(0, 1fr) 40px 40px 100px; } }
.stash-head { display: grid; gap: 8px; padding: 0 8px; font-family: var(--display); font-size: 9px; color: var(--muted); letter-spacing: .1em; }
.stash-head b { font-weight: 400; text-align: right; }
.stash-row b { text-align: right; }
.stash-row b.stored { color: var(--teal); }
.btn.tiny { padding: 5px 8px; font-size: 9px; }
.offer-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.shop-sec { font-family: var(--display); font-size: 11px; color: var(--teal); letter-spacing: .14em; margin-top: 6px; }
.offers { max-height: min(56vh, 520px); overflow-y: auto; padding-right: 4px; }
.offer { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: center; background: var(--panel-2); box-shadow: inset 0 0 0 2px #000; padding: 10px 12px; }
.offer.with-icon { grid-template-columns: 72px minmax(0, 1fr) auto; }
.offer-icon { width: 72px; height: 72px; image-rendering: pixelated; background: #12171a; box-shadow: inset 0 0 0 2px #000; object-fit: contain; padding: 4px; box-sizing: border-box; }
.stats-bars { display: grid; gap: 3px; margin-top: 6px; max-width: 260px; }
.stat { display: grid; grid-template-columns: 68px minmax(0, 1fr) 76px; gap: 6px; align-items: center; }
.stat em { white-space: nowrap; }
.stat span { font-family: var(--display); font-size: 8px; color: var(--muted); letter-spacing: .08em; }
.stat i { height: 6px; background: #12171a; box-shadow: 0 0 0 1px #000; display: block; }
.stat i b { display: block; height: 100%; background: var(--gold); }
.stat em { font-style: normal; font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .offer.with-icon { grid-template-columns: 52px minmax(0, 1fr); } .offer-icon { width: 52px; height: 52px; } .offer-btns { grid-column: 1 / -1; } }
.offer h3 { margin: 0; font-family: var(--display); font-size: 12px; font-weight: 400; letter-spacing: .06em; }
.offer p { margin: 2px 0 0; font-size: 18px; color: var(--muted); line-height: 1; }
.offer .btn b { color: var(--gold); font-weight: 400; }
.big-msg { font-family: var(--display); font-size: clamp(24px, 5vw, 36px); color: var(--blood); text-shadow: 3px 3px 0 #000; margin: 0; }
#rotate { position: absolute; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom, 0px)); text-align: center; font-family: var(--display); font-size: 11px; color: var(--muted); letter-spacing: .1em; display: none; }
@media (orientation: portrait) and (max-width: 700px) { #rotate { display: block; } }
#loading { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--display); font-size: 14px; color: var(--muted); letter-spacing: .1em; background: var(--ink); z-index: 9; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
