:root {
  --bg: #0a0d24;
  --bg2: #11163a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef1ff;
  --muted: #9aa2cc;
  --accent: #ffe14d;
  --accent2: #6c7bff;
  --good: #44e08a;
  --bad: #ff5d73;
  --p1: #ffe14d;
  --p2: #ff7adf;
  --radius: 16px;
  --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;
}
/* hidden attribute must win over component display rules (grid/flex/etc.) */
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 120% at 50% 0%, #161b46 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
}
#app {
  position: relative;
  height: 100%;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(14px + var(--safe-top)) 16px calc(14px + var(--safe-bottom));
  animation: fade 0.25s ease;
}
.screen.active {
  display: flex;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.muted {
  color: var(--muted);
  font-size: 14px;
}
.center-col {
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
  width: 100%;
  max-width: 360px;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  transition: transform 0.08s ease, background 0.2s;
  backdrop-filter: blur(6px);
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ffb24d);
  color: #1a1500;
  border: none;
  box-shadow: 0 8px 24px rgba(255, 200, 60, 0.25);
}
.btn.big {
  padding: 18px;
  font-size: 18px;
}
.btn.small {
  font-size: 14px;
  padding: 12px;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}
.btn-emoji {
  font-size: 20px;
}
.icon-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
}

/* Loading */
.loading-box {
  margin: auto;
  text-align: center;
}
.logo-img {
  width: 104px;
  height: 104px;
  margin: 0 auto 18px;
  border-radius: 26px;
  display: block;
  box-shadow: 0 0 50px rgba(255, 200, 60, 0.3);
}
.logo-text {
  font-size: 26px;
  letter-spacing: 2px;
  margin: 0 0 16px;
}
.logo-text span {
  display: block;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: 8px;
}
.spinner {
  width: 28px;
  height: 28px;
  margin: 10px auto;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner.big {
  width: 52px;
  height: 52px;
  border-width: 5px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Top bar */
.topbar,
.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.subbar {
  margin-bottom: 8px;
}
.subbar h2 {
  margin: 0;
  font-size: 20px;
}
.profile-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--panel-strong);
  object-fit: cover;
}
.me-name {
  font-size: 14px;
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.coins-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 15px;
}
.coin-ico {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, var(--accent) 60%, #c79100);
  box-shadow: 0 0 8px rgba(255, 220, 80, 0.6);
}
.coin-mini {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 4px;
  vertical-align: -1px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, var(--accent) 60%, #c79100);
}

/* Menu */
#screen-menu::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("/assets/menu-bg.png");
  background-size: cover;
  background-position: center;
  opacity: 0.16;
  pointer-events: none;
  mask-image: linear-gradient(to bottom, #000 0%, transparent 70%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 70%);
  z-index: 0;
}
#screen-menu > * {
  position: relative;
  z-index: 1;
}
.menu-hero {
  text-align: center;
  margin: 18px 0;
}
.hero-art {
  width: 180px;
  height: 180px;
  margin: 0 auto 10px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 12px 30px rgba(108, 123, 255, 0.4));
}
.hero-title {
  font-size: 28px;
  margin: 6px 0 4px;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--accent), var(--p2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  margin: 0;
}
.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
}
.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.legal {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin: 12px 0 0;
  opacity: 0.7;
}

/* Private code */
.private-code {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  width: 100%;
}
.code-big,
.code-input {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 10px;
  text-align: center;
  color: var(--accent);
}
.code-input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--accent);
  padding: 14px;
  outline: none;
}

/* Game */
#screen-game {
  padding: calc(8px + var(--safe-top)) 8px calc(8px + var(--safe-bottom));
}
.game-toolbar {
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
  margin-bottom: 6px;
}
.keyboard-hint {
  display: none;
  margin: 0;
  padding: 6px 16px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}
.surrender-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 120, 145, 0.45);
  background: linear-gradient(135deg, rgba(255, 93, 115, 0.22), rgba(120, 30, 55, 0.35));
  color: #ffd5dc;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 70, 95, 0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.surrender-ico {
  font-size: 14px;
  line-height: 1;
}
.surrender-btn:hover {
  background: linear-gradient(135deg, rgba(255, 110, 130, 0.38), rgba(150, 35, 65, 0.45));
  border-color: rgba(255, 150, 165, 0.65);
  box-shadow: 0 6px 20px rgba(255, 70, 95, 0.28);
}
.surrender-btn:active {
  transform: scale(0.96);
}
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.hud-player {
  display: flex;
  flex-direction: column;
  min-width: 84px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.hud-player.p2 {
  text-align: right;
}
.hud-player.p1 {
  border-color: rgba(255, 225, 77, 0.5);
}
.hud-player.p2 {
  border-color: rgba(255, 122, 223, 0.5);
}
.hud-name {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 90px;
}
.hud-score {
  font-size: 24px;
  font-weight: 800;
}
.p1 .hud-score {
  color: var(--p1);
}
.p2 .hud-score {
  color: var(--p2);
}
.hud-center {
  text-align: center;
  flex: 1;
  min-width: 0;
}
.hud-timer {
  font-size: 22px;
  font-weight: 800;
}
.hud-pellets {
  font-size: 11px;
  color: var(--muted);
}
.canvas-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.game-play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  max-width: 100%;
  max-height: 100%;
}
.canvas-stage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  line-height: 0;
}
#game-canvas {
  display: block;
  background: #060818;
  border-radius: 14px;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  touch-action: none;
}
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 6, 18, 0.72);
  border-radius: 14px;
  font-size: 96px;
  font-weight: 900;
  color: var(--accent);
  pointer-events: none;
}

/* D-pad */
.touch-dpad {
  position: relative;
  width: 168px;
  height: 168px;
  margin: 10px auto 0;
}
.dpad-btn {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
.dpad-btn:active {
  background: var(--accent);
  color: #000;
}
.dpad-btn.up {
  top: 0;
  left: 56px;
}
.dpad-btn.down {
  bottom: 0;
  left: 56px;
}
.dpad-btn.left {
  left: 0;
  top: 56px;
}
.dpad-btn.right {
  right: 0;
  top: 56px;
}

/* Desktop / mouse: hide on-screen arrows — keyboard + swipe on canvas */
@media (hover: hover) and (pointer: fine) {
  #dpad {
    display: none;
  }
  .keyboard-hint {
    display: block;
  }
  .game-play-area {
    gap: 16px;
  }
}

/* Result */
.result-img {
  width: 180px;
  height: 180px;
  object-fit: contain;
  filter: drop-shadow(0 10px 30px rgba(255, 200, 60, 0.35));
}
.result-badge {
  font-size: 34px;
  font-weight: 900;
  padding: 10px 22px;
  border-radius: 999px;
}
.result-badge.win {
  background: linear-gradient(135deg, var(--good), #2bb673);
  color: #062b18;
}
.result-badge.lose {
  background: linear-gradient(135deg, var(--bad), #b6203a);
  color: #2b0610;
}
.result-badge.draw {
  background: var(--panel-strong);
}
.result-rows {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
}
.result-row.win {
  border-color: var(--good);
}
.result-reward {
  color: var(--accent);
  font-weight: 700;
}

/* Shop */
.section-title {
  margin: 14px 0 8px;
  font-size: 16px;
}
.skins-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.skin-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  position: relative;
}
.skin-card.equipped {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 225, 77, 0.3);
}
.skin-card canvas {
  width: 64px;
  height: 64px;
}
.skin-name {
  font-size: 12px;
  margin: 4px 0 2px;
}
.skin-price {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}
.skin-price.owned {
  color: var(--good);
}
.packs-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pack-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
}
.pack-img {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.pack-info {
  flex: 1;
  min-width: 0;
}
.pack-info b {
  font-size: 16px;
}
.pack-buy {
  background: linear-gradient(135deg, var(--accent2), #4a59d8);
  border: none;
  color: #fff;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
}

/* Scroll areas — content scrolls, scrollbar hidden */
#screen-shop,
#screen-leaderboard {
  overflow-y: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
#screen-shop::-webkit-scrollbar,
#screen-leaderboard::-webkit-scrollbar {
  display: none;
}

/* Leaderboard */
.lb-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.lb-tab {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}
.lb-tab.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 700;
}
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
}
.lb-row.me {
  border-color: var(--accent);
}
.lb-rank {
  font-weight: 800;
  width: 28px;
  color: var(--muted);
}
.lb-rank.top {
  color: var(--accent);
}
.lb-row .avatar {
  width: 34px;
  height: 34px;
}
.lb-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-score {
  font-weight: 800;
  color: var(--accent);
}

/* VIP badge */
.vip-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #2a2000;
  background: linear-gradient(135deg, #ffe14d, #ffb24d);
  box-shadow: 0 0 10px rgba(255, 200, 60, 0.5);
}

/* Daily reward banner */
.daily-banner {
  appearance: none;
  border: 1px solid rgba(68, 224, 138, 0.5);
  background: linear-gradient(135deg, rgba(68, 224, 138, 0.18), rgba(108, 123, 255, 0.18));
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  animation: pulseGlow 2s ease-in-out infinite;
}
@keyframes pulseGlow {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(68, 224, 138, 0);
  }
  50% {
    box-shadow: 0 0 22px rgba(68, 224, 138, 0.35);
  }
}

/* Booster bar (menu) */
.booster-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 8px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.booster-bar::-webkit-scrollbar {
  display: none;
}
.booster-label {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}
.booster-chip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.booster-chip .b-ico {
  font-size: 16px;
}
.booster-chip .b-count {
  color: var(--muted);
  font-size: 12px;
}
.booster-chip.selected {
  border-color: var(--accent);
  background: rgba(255, 225, 77, 0.15);
  box-shadow: 0 0 0 1px rgba(255, 225, 77, 0.3);
}
.booster-chip.empty {
  opacity: 0.45;
}

/* Shop: hints + free coins */
.section-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px;
}
.free-coins {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.free-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.free-card .fc-info b {
  font-size: 15px;
}
.free-card .fc-info .muted {
  display: block;
}
.free-card .fc-btn {
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  color: #062b18;
  background: linear-gradient(135deg, var(--good), #2bb673);
}
.free-card .fc-btn.ad {
  color: #fff;
  background: linear-gradient(135deg, var(--accent2), #4a59d8);
}
.free-card .fc-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Boosters grid (shop) */
.boosters-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.booster-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.booster-card .bc-ico {
  font-size: 30px;
}
.booster-card .bc-title {
  font-size: 13px;
  font-weight: 700;
}
.booster-card .bc-desc {
  font-size: 10px;
  color: var(--muted);
  min-height: 26px;
}
.booster-card .bc-own {
  font-size: 11px;
  color: var(--good);
}
.booster-card .bc-buy {
  margin-top: 4px;
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 8px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  color: #1a1500;
  background: linear-gradient(135deg, var(--accent), #ffb24d);
}

/* Upgrades / case cards */
.upgrades-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.upgrade-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(255, 225, 77, 0.1), rgba(108, 123, 255, 0.1));
  border: 1px solid rgba(255, 225, 77, 0.35);
  border-radius: 14px;
  padding: 14px;
}
.upgrade-card .uc-ico {
  font-size: 34px;
}
.upgrade-card .uc-body {
  flex: 1;
}
.upgrade-card .uc-title {
  font-weight: 800;
  font-size: 15px;
}
.upgrade-card .uc-desc {
  font-size: 11px;
  color: var(--muted);
}
.upgrade-card .uc-buy {
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--accent2), #4a59d8);
}
.upgrade-card .uc-owned {
  flex-shrink: 0;
  color: var(--good);
  font-weight: 700;
  font-size: 14px;
}

/* "Best value" tag on coin packs */
.pack-card {
  position: relative;
}
.pack-card.best {
  border-color: var(--accent);
}
.pack-tag {
  position: absolute;
  top: -9px;
  left: 14px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #1a1500;
  background: linear-gradient(135deg, var(--accent), #ffb24d);
}
.pack-bonus {
  font-size: 11px;
  color: var(--good);
  font-weight: 700;
}

/* Skin card locked (vip-only) */
.skin-card.locked {
  opacity: 0.85;
}
.skin-card .skin-lock {
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(20, 24, 56, 0.95);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 50;
  max-width: 90%;
  text-align: center;
  animation: fade 0.2s ease;
}
