/*
 * Pixel fonts under the SIL Open Font License 1.1: "Squeak Arcade" is a
 * renamed subset of Press Start 2P (The Press Start 2P Project Authors) and
 * Tiny5 is by The Tiny5 Project Authors. Licenses: fonts/OFL-*.txt.
 */
@font-face {
  font-family: "Squeak Arcade";
  src: url("./fonts/squeak-arcade.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Tiny5";
  src: url("./fonts/tiny5.woff2") format("woff2");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --black: #0e0d10;
  --shade: #1b1a1f;
  --panel: #1f261c;
  --panel-deep: #151a13;
  --edge: #3e3b44;
  --edge-light: #57535c;
  --ink: #ebe4e0;
  --muted: #9a939a;
  --warp: #95e02d;
  --warp-light: #d4ff7a;
  --warp-dark: #2f6b14;
  --gold: #f0c43e;
  --gold-dark: #b8861e;
  --blood: #dd5a3d;
  --blood-dark: #6e1a1e;
  --sky: #6fa3e0;
  --display: "Squeak Arcade", ui-monospace, monospace;
  --body: "Tiny5", ui-monospace, monospace;
  --safe-top: max(6px, var(--tg-content-safe-area-inset-top, env(safe-area-inset-top)));
  --safe-bottom: max(6px, var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom)));
  --safe-left: max(6px, var(--tg-content-safe-area-inset-left, env(safe-area-inset-left)));
  --safe-right: max(6px, var(--tg-content-safe-area-inset-right, env(safe-area-inset-right)));
  font-family: var(--body);
  background: var(--black);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--black);
  color: var(--ink);
  -webkit-font-smoothing: none;
  font-smooth: never;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Browsers keep their toolbars on screen because the page never scrolls, so
   the raid fills the small viewport; the Telegram SDK's own
   --tg-viewport-height is 100vh outside Telegram, which reaches under them. */
body {
  height: 100svh;
  height: var(--app-height, 100svh);
}

button {
  color: inherit;
  font: inherit;
}

img[data-icon] {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.underhive-shell {
  position: relative;
  width: min(100%, 560px);
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
  background: var(--black);
}

.raid-stage {
  position: absolute;
  inset: 0;
}

#underhive-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
}

#touch-controls {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* Pixel frames: a dark outer line, an edge line, and an inner highlight. */
.pixel-frame,
.hud-top > div,
.hud-row > div,
.overlay-panel,
.boss-bar,
.choice-card,
.pixel-button,
.icon-button {
  border: 2px solid var(--edge);
  box-shadow: 0 0 0 2px var(--black), inset 0 2px 0 rgba(255, 255, 255, 0.06);
}

/* HUD */
.hud {
  position: absolute;
  top: var(--safe-top);
  left: var(--safe-left);
  right: var(--safe-right);
  display: grid;
  gap: 6px;
  pointer-events: none;
}

.hud-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
}

.hud-top > div,
.hud-row > div {
  background: rgba(14, 13, 16, 0.82);
}

.hud-health {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
  padding: 4px 6px;
}

.hud-health strong {
  font-family: var(--display);
  font-size: 10px;
  min-width: 3ch;
  text-align: right;
}

.hud-health[data-low="true"] strong {
  color: var(--blood);
  animation: blink 0.6s steps(2) infinite;
}

.hud-icon {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

.meter {
  position: relative;
  display: block;
  height: 8px;
  background: var(--black);
  border: 1px solid var(--edge-light);
  overflow: hidden;
}

.meter > span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  transition: width 120ms steps(4);
}

.meter--health > span {
  background: linear-gradient(var(--blood) 0 50%, #a8302a 50% 100%);
}

.meter--xp > span {
  background: linear-gradient(var(--warp-light) 0 50%, var(--warp) 50% 100%);
}

.meter--boss > span {
  background: linear-gradient(#b07ad6 0 50%, #7a48a0 50% 100%);
}

.hud-clock {
  display: grid;
  justify-items: center;
  align-content: center;
  padding: 3px 8px;
  min-width: 108px;
}

.hud-clock strong {
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--ink);
}

.hud-clock span {
  margin-top: 2px;
  font-family: var(--body);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--muted);
}

.hud-clock span[data-tone="open"] {
  color: var(--warp-light);
  animation: blink 0.8s steps(2) infinite;
}

.hud-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
}

.icon-button {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: rgba(27, 26, 31, 0.9);
  cursor: pointer;
}

.icon-button img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.icon-button:active {
  transform: translateY(1px);
}

.hud-xp {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.hud-xp .meter {
  height: 6px;
}

.hud-xp strong {
  font-family: var(--display);
  font-size: 9px;
  color: var(--warp-light);
  text-shadow: 1px 1px 0 var(--black);
}

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
}

.hud-loadout {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 70%;
  padding: 3px;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

.hud-loadout:empty {
  display: none;
}

.loadout-slot {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  background: rgba(14, 13, 16, 0.8);
  border: 1px solid var(--edge);
}

.loadout-slot--perk {
  border-color: #4d2a66;
}

.loadout-slot__icon {
  width: 22px;
  height: 22px;
}

.loadout-slot__pips {
  position: absolute;
  right: -2px;
  bottom: -3px;
  font-family: var(--display);
  font-size: 6px;
  color: var(--gold);
  text-shadow: 1px 1px 0 var(--black), -1px 0 0 var(--black);
}

.hud-loot {
  display: grid;
  gap: 2px;
  padding: 4px 6px;
  min-width: 78px;
}

.hud-loot span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.hud-loot strong {
  font-family: var(--display);
  font-size: 9px;
}

/* Event banner */
.event-banner {
  position: absolute;
  top: calc(var(--safe-top) + 108px);
  left: 50%;
  margin: 0;
  padding: 7px 12px;
  transform: translateX(-50%);
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: 1px;
  white-space: nowrap;
  color: var(--ink);
  background: rgba(14, 13, 16, 0.9);
  border: 2px solid var(--edge-light);
  box-shadow: 0 0 0 2px var(--black);
  pointer-events: none;
  opacity: 0;
}

.event-banner[data-tone="good"] {
  color: var(--warp-light);
  border-color: var(--warp-dark);
}

.event-banner[data-tone="warn"] {
  color: var(--gold);
  border-color: var(--gold-dark);
}

.event-banner[data-tone="boss"] {
  color: #ffd8cf;
  background: rgba(58, 13, 18, 0.94);
  border-color: var(--blood);
}

.event-banner--show {
  animation: banner 2.4s steps(24) forwards;
}

@keyframes banner {
  0% {
    opacity: 0;
    transform: translate(-50%, -8px) scale(1.2);
  }
  8% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -6px);
  }
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* Boss bar */
.boss-bar {
  position: absolute;
  left: calc(var(--safe-left) + 10px);
  right: calc(var(--safe-right) + 10px);
  bottom: calc(var(--safe-bottom) + 12px);
  display: grid;
  gap: 4px;
  padding: 6px 8px;
  background: rgba(42, 24, 56, 0.9);
  border-color: #7a48a0;
  pointer-events: none;
}

.boss-bar strong {
  font-family: var(--display);
  font-size: 9px;
  color: #e4c8ff;
  text-align: center;
}

.boss-bar .meter {
  height: 8px;
}

/* Floating stick */
.floating-stick,
.floating-stick__knob {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.floating-stick {
  width: 108px;
  height: 108px;
  border: 2px dashed rgba(212, 255, 122, 0.35);
  border-radius: 50%;
  background: rgba(14, 13, 16, 0.2);
}

.floating-stick__knob {
  width: 40px;
  height: 40px;
  border: 2px solid var(--warp-light);
  border-radius: 50%;
  background: rgba(149, 224, 45, 0.35);
  box-shadow: 0 0 0 2px var(--black);
}

/* Overlays */
.overlay-panel {
  position: absolute;
  z-index: 5;
  left: calc(var(--safe-left) + 6px);
  right: calc(var(--safe-right) + 6px);
  top: 50%;
  transform: translateY(-50%);
  max-height: calc(100% - var(--safe-top) - var(--safe-bottom) - 12px);
  overflow-y: auto;
  padding: 14px 12px 12px;
  background: rgba(21, 26, 19, 0.97);
  text-align: center;
  outline: none;
}

.overlay-panel h2 {
  margin: 6px 0 10px;
  font-family: var(--display);
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink);
}

.panel-kicker {
  margin: 0;
  font-family: var(--display);
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--warp);
}

.easter-egg-caption {
  margin: -4px 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.choice-cards {
  display: grid;
  gap: 8px;
}

.choice-card {
  pointer-events: auto;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  background: var(--shade);
  cursor: pointer;
}

.choice-card:hover,
.choice-card:focus-visible {
  border-color: var(--warp);
  outline: none;
  background: #22301c;
}

.choice-card:active {
  transform: translateY(2px);
}

.choice-card--perk {
  border-color: #4d2a66;
}

.choice-card--fallback {
  border-color: var(--gold-dark);
}

.choice-card__art {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: var(--black);
  border: 1px solid var(--edge);
  padding: 7px;
}

.choice-card__text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.choice-card__type {
  font-family: var(--display);
  font-size: 7px;
  letter-spacing: 1px;
  color: var(--gold);
}

.choice-card--perk .choice-card__type {
  color: #b07ad6;
}

.choice-card strong {
  font-family: var(--display);
  font-size: 10px;
  line-height: 1.3;
  color: var(--ink);
}

.choice-card__detail {
  font-size: 13px;
  line-height: 1.1;
  color: var(--warp-light);
}

.choice-card__key {
  align-self: start;
  font-family: var(--display);
  font-size: 8px;
  color: var(--edge-light);
}

.pixel-button {
  pointer-events: auto;
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px 10px;
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--black);
  background: var(--warp);
  border-color: var(--warp-light);
  cursor: pointer;
}

.pixel-button:active {
  transform: translateY(2px);
}

.pixel-button--secondary {
  color: var(--ink);
  background: var(--shade);
  border-color: var(--edge-light);
}

.volume-controls {
  display: grid;
  gap: 6px;
  margin: 10px 0 2px;
}

.volume-slider {
  display: grid;
  grid-template-columns: 9ch minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  font-family: var(--display);
  font-size: 8px;
  letter-spacing: 1px;
  text-align: left;
  color: var(--muted);
}

.volume-slider input {
  width: 100%;
  margin: 0;
  accent-color: var(--warp);
}

.pause-build {
  display: grid;
  gap: 4px;
  margin: 0 0 6px;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 14px;
}

.pause-build li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pause-build__icon {
  width: 24px;
  height: 24px;
}

/* Result */
.result-panel[data-outcome="extracted"] {
  border-color: var(--warp);
}

.result-panel[data-outcome="death"] {
  border-color: var(--blood);
}

.result-score {
  display: grid;
  gap: 4px;
  margin: 4px 0 6px;
}

.result-score span {
  font-family: var(--display);
  font-size: 8px;
  color: var(--muted);
}

.result-score strong {
  font-family: var(--display);
  font-size: 26px;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--black);
}

.result-loot {
  margin: 0 0 4px;
  font-family: var(--display);
  font-size: 9px;
  color: var(--gold);
}

.result-receipt {
  margin: 0 0 8px;
  font-size: 13px;
}

.result-receipt[data-tone="success"] {
  color: var(--warp-light);
}

.result-receipt__lost {
  color: #d48b7c;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 0 0 8px;
}

.result-stats > div {
  display: grid;
  gap: 3px;
  padding: 5px 2px;
  background: var(--shade);
  border: 1px solid var(--edge);
}

.result-stats > div span {
  font-family: var(--display);
  font-size: 6px;
  color: var(--muted);
}

.result-stats > div strong {
  font-family: var(--display);
  font-size: 10px;
}

.result-weapons {
  grid-column: 1 / -1;
  display: grid;
  gap: 3px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
}

.result-weapons li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 6ch;
  gap: 6px;
  align-items: center;
}

.result-weapons__icon {
  width: 20px;
  height: 20px;
}

.result-weapons__bar {
  height: 6px;
  background: var(--black);
  border: 1px solid var(--edge);
}

.result-weapons__bar > span {
  display: block;
  height: 100%;
  background: var(--warp);
}

.result-weapons strong {
  font-family: var(--display);
  font-size: 7px;
  text-align: right;
}

.result-save {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 7px;
  line-height: 1.5;
  color: var(--muted);
}

.result-save[data-save-state="saved"] {
  color: var(--warp);
}

.result-diagnostics {
  margin-top: 10px;
  text-align: left;
}

.result-diagnostics textarea {
  width: 100%;
  min-height: 90px;
  font: 10px ui-monospace, monospace;
  color: var(--ink);
  background: var(--black);
  border: 1px solid var(--edge);
}

/* Start screen & leaderboard */
/* The start button is pinned to the bottom; the content above it scrolls. */
.leaderboard-panel {
  --start-space: calc(var(--safe-bottom) + 76px);
  position: absolute;
  z-index: 6;
  inset: 0;
  pointer-events: none;
}

.leaderboard-panel[open] {
  pointer-events: auto;
  background:
    radial-gradient(circle at 50% 18%, rgba(87, 168, 34, 0.18), transparent
    55%),
    rgba(14, 13, 16, 0.96);
}

.leaderboard-panel > summary {
  position: absolute;
  left: calc(var(--safe-left) + 12px);
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  list-style: none;
  pointer-events: auto;
  margin: 0;
  padding: 14px 10px;
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 1px;
  text-align: center;
  color: var(--black);
  background: var(--warp);
  border: 2px solid var(--warp-light);
  box-shadow: 0 0 0 2px var(--black), 0 4px 0 var(--warp-dark);
  cursor: pointer;
  animation: pulse 1.4s steps(2) infinite;
}

.leaderboard-panel > summary::-webkit-details-marker {
  display: none;
}

.leaderboard-panel:not([open]) > summary {
  display: none;
}

.leaderboard-panel [data-leaderboard-open-label] {
  display: none;
}

.leaderboard-panel__body {
  position: absolute;
  inset: 0 0 var(--start-space);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(var(--safe-top) + 14px) calc(var(--safe-right) + 12px) 12px
    calc(var(--safe-left) + 12px);
  text-align: center;
}

.title-card {
  margin-bottom: 16px;
}

.game-title {
  margin: 10px 0 12px;
  font-family: var(--display);
  font-size: 22px;
  line-height: 1.4;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--black), 0 0 12px rgba(240, 196, 62, 0.25);
}

.game-title span {
  font-size: 16px;
  color: var(--warp-light);
}

.title-cast {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  margin: 8px 0 12px;
}

.title-cast img {
  height: 54px;
  width: auto;
  animation: bob 0.9s steps(2) infinite;
}

.title-cast img:nth-child(2) {
  animation-delay: 0.2s;
  height: 44px;
}
.title-cast img:nth-child(3) {
  animation-delay: 0.4s;
  height: 46px;
}
.title-cast img:nth-child(4) {
  animation-delay: 0.1s;
  height: 30px;
}

.title-hint {
  max-width: 320px;
  margin: 0 auto;
  font-size: 14px;
  line-height: 1.15;
  color: var(--muted);
}

.skin-switch {
  display: inline-block;
  width: auto;
  margin: 12px auto 0;
  padding: 8px 14px;
  font-size: 9px;
}

.statistics-state {
  font-size: 13px;
  color: var(--muted);
}

.run-statistics {
  display: grid;
  gap: 12px;
  margin-top: 10px;
  text-align: left;
}

.run-statistics h3 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 9px;
  color: var(--warp-light);
}

.run-statistics ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 3px;
}

.run-statistics li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 5px 6px;
  font-size: 14px;
  background: var(--shade);
  border: 1px solid var(--edge);
}

.run-statistics li.current-user {
  border-color: var(--warp);
  background: #1f2a17;
}

.leader__name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.leader__score {
  font-family: var(--display);
  font-size: 9px;
  color: var(--gold);
}

.leader__weapons {
  display: flex;
  gap: 2px;
}

.leaderboard-weapon__art {
  width: 16px;
  height: 16px;
}

.run-statistics p {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 7px;
  color: var(--muted);
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.15);
  }
}

[hidden] {
  display: none !important;
}
