* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0d1a;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  touch-action: manipulation;
}

#game-wrapper {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #1a1a3e 0%, #2d1b4e 55%, #3d1f5e 100%);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(16px, env(safe-area-inset-top)) 20px 0;
  pointer-events: none;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.6);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 26px;
  line-height: 1.1;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.7;
  font-weight: normal;
}

.hud-coins {
  color: #ffd84d;
  text-shadow: 0 0 10px rgba(255, 216, 77, 0.7);
}

.hud-best {
  color: #ff5ec7;
  text-shadow: 0 0 10px rgba(255, 94, 199, 0.7);
}

.hud-combo {
  color: #00f5a0;
  text-shadow: 0 0 12px rgba(0, 245, 160, 0.85);
  font-weight: 700;
}
/* Pulse to draw the eye — gated for photosensitivity (matches the BUG-01 a11y fix). */
@media (prefers-reduced-motion: no-preference) {
  .hud-combo:not(.hidden) {
    animation: combo-pulse 0.6s ease-in-out infinite alternate;
  }
}
@keyframes combo-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}

/* ---------- Mute button ---------- */
.icon-btn {
  position: absolute;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 50px;
  height: 50px;
  font-size: 22px;
  line-height: 1;
  border: 1px solid rgba(0, 245, 255, 0.4);
  border-radius: 50%;
  background: rgba(13, 13, 26, 0.55);
  color: #fff;
  cursor: pointer;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}

.icon-btn:active {
  transform: scale(0.9);
}

/* ND-025: music toggle sits left of the sound button. */
.icon-btn-music { right: 76px; }
.icon-btn-music.off { opacity: 0.4; text-decoration: line-through; }

.icon-btn-left {
  right: auto;
  left: 16px;
  font-size: 16px;
  letter-spacing: 1px;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* ND-020: scroll when the content is taller than the phone. The ::before /
     ::after spacers centre the content when it fits and collapse when it
     doesn't, so the top (title) is never pushed off-screen. */
  justify-content: flex-start;
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  /* Bottom padding keeps the last button scrollable clear of the sound button. */
  padding: max(24px, env(safe-area-inset-top)) 24px
    calc(max(16px, env(safe-area-inset-bottom)) + 66px);
  color: #fff;
  background: radial-gradient(circle at center, rgba(20, 10, 40, 0.55), rgba(8, 8, 20, 0.92));
  backdrop-filter: blur(2px);
  z-index: 10;
}

.overlay::before,
.overlay::after {
  content: "";
  flex: 1 0 0;
}

.overlay > * {
  flex-shrink: 0;
}

.title {
  font-size: clamp(48px, 16vw, 110px);
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 0.9;
  color: #00f5ff;
  text-shadow: 0 0 20px rgba(0, 245, 255, 0.8), 0 0 40px rgba(0, 245, 255, 0.4);
  animation: pulse 2.2s ease-in-out infinite;
}

.title span {
  display: block;
  color: #ff5ec7;
  text-shadow: 0 0 20px rgba(255, 94, 199, 0.8), 0 0 40px rgba(255, 94, 199, 0.4);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.tagline {
  margin: 22px 0 30px;
  font-size: clamp(14px, 4.2vw, 19px);
  line-height: 1.6;
  opacity: 0.85;
}

.btn {
  font-family: inherit;
  font-size: clamp(20px, 6vw, 28px);
  font-weight: bold;
  letter-spacing: 3px;
  color: #0d0d1a;
  background: linear-gradient(135deg, #00f5ff, #00b3ff);
  border: none;
  border-radius: 50px;
  padding: 16px 52px;
  cursor: pointer;
  box-shadow: 0 0 24px rgba(0, 245, 255, 0.6);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.btn:active {
  transform: scale(0.94);
  box-shadow: 0 0 12px rgba(0, 245, 255, 0.5);
}

.hint {
  margin-top: 22px;
  font-size: 15px;
  opacity: 0.6;
  letter-spacing: 1px;
}

.btn-ghost {
  margin-top: 16px;
  background: transparent;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: none;
}

.btn-reward {
  background: linear-gradient(135deg, #ffd84d, #ff9d2e);
  color: #2a1a00;
  box-shadow: 0 0 24px rgba(255, 216, 77, 0.6);
  margin-bottom: 12px;
  /* ND-023: compact, single-line, so PLAY AGAIN stays near the fold with Boost added. */
  font-size: clamp(15px, 4.4vw, 19px);
  letter-spacing: 1.5px;
  padding: 12px 26px;
  white-space: nowrap;
}

.btn-reward:disabled {
  opacity: 0.5;
  filter: grayscale(0.4);
  box-shadow: none;
}

/* ---------- Shop ---------- */
#shop {
  margin-top: 26px;
  width: min(360px, 86vw);
}

.shop-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  letter-spacing: 3px;
  opacity: 0.8;
  margin-bottom: 10px;
}

.shop-head .bank {
  color: #ffd84d;
  font-weight: bold;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 216, 77, 0.6);
}

#skin-row,
#shoe-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}

#skin-row::-webkit-scrollbar,
#shoe-row::-webkit-scrollbar { display: none; }
.shop-head.shop-sub { margin-top: 12px; }
.shoe-hint {
  flex-basis: 100%;
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.4;
  color: #9fb0d0;
  opacity: 0.85;
}

.skin-chip {
  flex: 0 0 auto;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.2s ease;
}

.skin-chip:active { transform: scale(0.93); }

.skin-chip.selected {
  border-color: #00f5ff;
  box-shadow: 0 0 14px rgba(0, 245, 255, 0.5);
}

.skin-chip.locked .swatch { opacity: 0.45; }

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.skin-price {
  font-size: 11px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.skin-price.owned { color: #00ffb4; }
.skin-price.afford { color: #ffd84d; }
.skin-price.cant { color: #ff6b8a; }

/* ---------- Boost (ND-023) ---------- */
.boost-panel {
  margin-top: 18px;
  width: min(340px, 86vw);
  padding: 12px 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 216, 77, 0.35);
  background: rgba(255, 216, 77, 0.06);
  box-shadow: 0 0 18px rgba(255, 216, 77, 0.12) inset;
}
#boost-over { margin-top: 4px; margin-bottom: 16px; }
.boost-head {
  font-size: 12px;
  letter-spacing: 3px;
  opacity: 0.85;
  margin-bottom: 10px;
  color: #ffd84d;
}
.boost-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.boost-chip {
  --c: 0, 255, 180;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 2px solid rgba(var(--c), 0.25);
  background: rgba(var(--c), 0.06);
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.boost-chip:active { transform: scale(0.93); }
.boost-chip.selected {
  border-color: rgb(var(--c));
  background: rgba(var(--c), 0.16);
  box-shadow: 0 0 14px rgba(var(--c), 0.55);
}
.boost-shield { --c: 0, 255, 180; }
.boost-magnet { --c: 255, 216, 77; }
.boost-slowmo { --c: 120, 180, 255; }
.boost-icon { font-size: 22px; line-height: 1; }
.boost-name { font-size: 12px; letter-spacing: 0.5px; }
.boost-pay {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}
.boost-btn {
  flex: 1 1 0;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.5px;
  padding: 10px 8px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}
.boost-btn:active { transform: scale(0.95); }
.boost-btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.boost-ad {
  color: #2a1a00;
  background: linear-gradient(135deg, #ffd84d, #ff9d2e);
  box-shadow: 0 0 14px rgba(255, 216, 77, 0.5);
}
.boost-gems {
  color: #ffd84d;
  background: transparent;
  border: 2px solid rgba(255, 216, 77, 0.6);
}
.boost-ready {
  padding: 10px;
  border-radius: 12px;
  font-weight: bold;
  letter-spacing: 1px;
  color: rgb(var(--c));
  border: 2px solid rgb(var(--c));
  background: rgba(var(--c), 0.12);
  box-shadow: 0 0 16px rgba(var(--c), 0.45);
}

/* ---------- Gem packs (native IAP) ---------- */
#gem-shop { margin-top: 14px; }
#gem-shop.hidden { display: none; }

#gem-pack-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}

#gem-pack-row::-webkit-scrollbar { display: none; }

.gem-pack {
  position: relative;
  flex: 0 0 auto;
  min-width: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 10px;
  border-radius: 12px;
  border: 2px solid rgba(255, 216, 77, 0.35);
  background: rgba(255, 216, 77, 0.06);
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.2s ease;
}

.gem-pack:active { transform: scale(0.94); }
.gem-pack:disabled { opacity: 0.5; cursor: default; }

.gem-amt { font-size: 15px; font-weight: 700; color: #ffd84d; white-space: nowrap; }

.gem-price {
  font-size: 12px;
  letter-spacing: 0.3px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #00c46a;
  color: #04170d;
  font-weight: 700;
  white-space: nowrap;
}

.gem-badge {
  position: absolute;
  top: -8px;
  right: -6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #ff5ec7;
  color: #1a0410;
  white-space: nowrap;
}

/* ---------- QR ---------- */
#qr-box {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#qr {
  background: #fff;
  padding: 8px;
  border-radius: 10px;
  line-height: 0;
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.35);
}

#qr svg, #qr img, #qr canvas, #qr table {
  display: block;
  width: 116px;
  height: 116px;
}

.qr-cap {
  font-size: 12px;
  letter-spacing: 1px;
  opacity: 0.6;
}

.gameover-title {
  font-size: clamp(34px, 11vw, 64px);
  font-weight: 900;
  letter-spacing: 3px;
  color: #ff4d6d;
  text-shadow: 0 0 20px rgba(255, 77, 109, 0.7);
}

.results {
  margin: 28px 0;
  width: min(320px, 80vw);
}

.result-row {
  display: flex;
  justify-content: space-between;
  font-size: clamp(18px, 5vw, 24px);
  padding: 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.result-row span:first-child {
  opacity: 0.65;
  letter-spacing: 1px;
}

.result-row span:last-child {
  font-weight: bold;
}

.best-row span:last-child {
  color: #ff5ec7;
}

.new-record {
  color: #ffd84d;
  font-size: clamp(18px, 5vw, 24px);
  font-weight: bold;
  letter-spacing: 2px;
  margin-bottom: 24px;
  text-shadow: 0 0 14px rgba(255, 216, 77, 0.8);
  animation: pulse 1s ease-in-out infinite;
}

.hidden {
  display: none !important;
}

/* ---------- Reward toast ---------- */
.toast {
  position: absolute;
  top: max(70px, calc(env(safe-area-inset-top) + 60px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  max-width: 86vw;
  padding: 12px 20px;
  border-radius: 14px;
  background: rgba(13, 13, 26, 0.92);
  border: 1px solid rgba(255, 216, 77, 0.6);
  color: #ffe9a8;
  font-size: 15px;
  font-weight: bold;
  text-align: center;
  letter-spacing: 0.5px;
  box-shadow: 0 0 20px rgba(255, 216, 77, 0.35);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  white-space: pre-line;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(6px);
}

/* ---------- Progress panel (streak / daily / missions) ---------- */
#progress-panel {
  margin-top: 22px;
  width: min(360px, 86vw);
  text-align: left;
}

.streak-badge {
  font-size: 15px;
  font-weight: bold;
  color: #ffb347;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  text-shadow: 0 0 10px rgba(255, 179, 71, 0.5);
}

.prog-row {
  font-size: 12.5px;
  letter-spacing: 0.3px;
  margin: 6px 0;
  opacity: 0.92;
}

.prog-row.done { color: #00ffb4; }

.prog-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.prog-head .reward { color: #ffd84d; }

.prog-bar {
  position: relative;
  height: 5px;
  margin-top: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.prog-bar > span {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, #00f5ff, #00ffb4);
  border-radius: 3px;
}

#missions {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 8px;
}

#missions .prog-label { font-size: 11px; letter-spacing: 2px; opacity: 0.55; }

/* ---------- Reduced motion (BUG-01 / ND-A11Y-01) ---------- */
@media (prefers-reduced-motion: reduce) {
  .title,
  .new-record {
    animation: none;
  }
}
