:root {
  --bg: #061526;
  --bg-deep: #030b14;
  --panel: #081a2c;
  --panel-light: #0d2740;
  --border-dark: #02070c;
  --border-mid: #315067;
  --border-light: #7390a0;
  --yellow: #ffc928;
  --yellow-light: #ffe26a;
  --orange: #f36b21;
  --orange-dark: #9f2d08;
  --cyan: #27c6f5;
  --cyan-dark: #087ea8;
  --white: #f4f4ee;
  --text-muted: #95a2ad;
  --disabled: #4c5862;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(39, 198, 245, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(39, 198, 245, 0.035) 1px, transparent 1px);
  background-size: 8px 8px;
  color: var(--white);
  font-family: "Pixelify Sans", "Silkscreen", "Press Start 2P", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button {
  border: 0;
  border-radius: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: minmax(280px, 46vh) minmax(0, 1fr);
  height: var(--tg-viewport-height, 100vh);
  min-height: 540px;
  padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  gap: 12px;
  background:
    radial-gradient(circle at 15% 28%, rgba(39, 198, 245, 0.08) 0 2px, transparent 3px),
    radial-gradient(circle at 86% 34%, rgba(255, 201, 40, 0.08) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 12%, rgba(243, 107, 33, 0.08) 0 2px, transparent 3px);
}

.pixel-panel,
.topline,
.item,
.modal-panel,
.dev-panel {
  border: 3px solid var(--border-mid);
  box-shadow:
    0 0 0 3px var(--border-dark),
    inset 0 0 0 2px rgba(115, 144, 160, 0.18),
    5px 5px 0 var(--border-dark);
}

.stage {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: center;
  min-height: 0;
  padding-bottom: 10px;
  border-bottom: 4px solid var(--border-dark);
}

.topline {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  min-width: 0;
  padding: 8px;
  background: var(--panel);
}

.scoreboard {
  display: grid;
  justify-items: center;
  gap: 5px;
  min-width: 0;
}

.balance {
  max-width: 100%;
  overflow: hidden;
  color: var(--yellow);
  text-overflow: ellipsis;
  text-shadow:
    0 3px 0 var(--orange-dark),
    2px 0 0 var(--border-dark),
    -2px 0 0 var(--border-dark);
  font-size: clamp(23px, 7vw, 44px);
  font-weight: 950;
  line-height: 1;
}

.income {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  text-shadow: 2px 2px 0 var(--border-dark);
}

.hud-label,
.status-chip {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: var(--panel-light);
  color: var(--yellow);
  outline: 2px solid var(--border-dark);
  box-shadow: inset 0 -4px 0 var(--bg-deep);
}

.buy:active,
.dev-panel button:active {
  transform: translateY(2px);
  box-shadow: inset 0 -1px 0 var(--bg-deep);
}

.hud-label {
  color: var(--yellow);
  font-size: 13px;
  font-weight: 950;
}

.status-chip {
  color: var(--orange);
  font-size: 13px;
  font-weight: 950;
}

.tap-target {
  position: relative;
  place-self: center;
  display: grid;
  place-items: center;
  width: min(72vw, 350px);
  aspect-ratio: 1 / 0.82;
  background: transparent;
  color: var(--yellow);
  line-height: 1;
  transform: translateZ(0) scale(1);
  transition: transform 80ms steps(2, end), color 80ms steps(2, end);
}

.tap-target span {
  display: block;
  font-size: clamp(170px, 44vw, 260px);
  font-weight: 950;
  text-shadow:
    0 5px 0 var(--orange),
    0 10px 0 var(--orange-dark),
    5px 0 0 var(--border-dark),
    -5px 0 0 var(--border-dark),
    0 -5px 0 var(--border-dark),
    5px 10px 0 var(--border-dark),
    -5px 10px 0 var(--border-dark),
    10px 15px 0 rgba(2, 7, 12, 0.55);
}

.tap-target small {
  position: absolute;
  bottom: 12px;
  left: 50%;
  padding: 5px 8px;
  background: var(--panel);
  color: var(--cyan);
  outline: 3px solid var(--border-dark);
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 950;
  white-space: nowrap;
  box-shadow: 0 4px 0 var(--border-dark);
}

.tap-target.pop {
  animation: tapPop 150ms steps(3, end);
}

.tap-target.critical {
  color: var(--yellow-light);
  animation: criticalPop 240ms steps(4, end);
}

@keyframes tapPop {
  0% { transform: scale(1); }
  38% { transform: scale(0.93); }
  72% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@keyframes criticalPop {
  0% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(-3px, 0) scale(1.08); }
  50% { transform: translate(3px, -2px) scale(0.96); }
  75% { transform: translate(-2px, 2px) scale(1.04); }
  100% { transform: translate(0, 0) scale(1); }
}

.floating-layer,
.critical-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.critical-flash {
  opacity: 0;
  background:
    linear-gradient(90deg, transparent 0 44%, rgba(255, 226, 106, 0.65) 44% 56%, transparent 56%),
    linear-gradient(transparent 0 44%, rgba(244, 244, 238, 0.5) 44% 56%, transparent 56%);
}

.critical-flash.show {
  animation: flash 190ms steps(2, end);
}

@keyframes flash {
  0%, 100% { opacity: 0; }
  35%, 70% { opacity: 1; }
}

.float-text {
  position: absolute;
  color: var(--cyan);
  font-size: 17px;
  font-weight: 950;
  animation: floatUp 640ms steps(8, end) forwards;
  text-shadow:
    2px 0 0 var(--border-dark),
    -2px 0 0 var(--border-dark),
    0 2px 0 var(--border-dark),
    2px 2px 0 var(--border-dark);
}

.float-text.tone-2 {
  color: var(--yellow);
}

.float-text.tone-3 {
  color: var(--orange);
}

.float-text.critical {
  color: var(--yellow-light);
  font-size: 22px;
}

@keyframes floatUp {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(calc(-50% + var(--drift, 8px)), -150%) scale(1.08);
  }
}

.shop {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

.shop-list {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 8px 18px;
  scrollbar-width: none;
}

body.local-debug .shop-list {
  padding-bottom: 70px;
}

.shop-list::-webkit-scrollbar {
  display: none;
}

.item {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 12px;
  min-height: 0;
  padding: 14px;
  background: var(--panel);
}

.item.locked {
  background: var(--bg-deep);
  color: var(--text-muted);
}

.item-main {
  display: grid;
  align-items: center;
  min-width: 0;
  padding: 2px 2px 0;
}

.item-title {
  min-width: 0;
  margin: 0 0 9px;
  overflow: hidden;
  color: var(--yellow);
  text-overflow: ellipsis;
  font-size: 14px;
  font-weight: 950;
  line-height: 1.25;
  text-transform: uppercase;
  white-space: nowrap;
}

.item-meta {
  display: grid;
  gap: 3px;
  min-width: 0;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.item-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.buy {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 7px 8px 9px;
  background: var(--yellow);
  color: var(--border-dark);
  outline: 3px solid var(--border-dark);
  box-shadow:
    inset 0 -6px 0 var(--orange),
    4px 4px 0 var(--border-dark);
  font-size: 13px;
  font-weight: 950;
}

.buy small {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--border-dark);
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  font-weight: 950;
}

.buy:disabled {
  background: var(--disabled);
  color: var(--text-muted);
  box-shadow:
    inset 0 -6px 0 var(--bg-deep),
    4px 4px 0 var(--border-dark);
  cursor: default;
}

.buy:disabled small {
  color: var(--text-muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 11, 20, 0.82);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(330px, 100%);
  padding: 22px;
  background: var(--panel);
  text-align: center;
}

.modal-panel h2 {
  margin: 0 0 10px;
  color: var(--yellow);
  font-size: 18px;
}

.modal-panel p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 800;
}

.modal-panel button {
  width: 100%;
  min-height: 44px;
  background: var(--yellow);
  color: var(--border-dark);
  outline: 3px solid var(--border-dark);
  box-shadow: inset 0 -5px 0 var(--orange);
  font-weight: 950;
}

.dev-panel {
  position: fixed;
  right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 10;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--panel);
}

.dev-panel.hidden {
  display: none;
}

.dev-panel button {
  min-height: 34px;
  padding: 0 10px;
  background: var(--cyan);
  color: var(--border-dark);
  outline: 2px solid var(--border-dark);
  box-shadow: inset 0 -4px 0 var(--cyan-dark);
  font-size: 11px;
  font-weight: 950;
}

@media (min-width: 760px) {
  .app-shell {
    width: min(520px, 100vw);
    margin: 0 auto;
    border-inline: 4px solid var(--border-dark);
  }
}

@media (min-width: 520px) {
  .item {
    grid-template-columns: minmax(0, 1fr) minmax(104px, auto);
    align-items: center;
  }

  .buy {
    width: auto;
    min-width: 104px;
  }
}

@media (max-height: 620px) {
  .app-shell {
    grid-template-rows: minmax(210px, 40vh) minmax(0, 1fr);
    gap: 8px;
  }

  .tap-target {
    width: min(54vw, 230px);
  }

  .tap-target span {
    font-size: clamp(128px, 34vw, 190px);
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 9px;
  }
}
