* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: #1b2a4a;
  color: #283040;
  font-family: 'Press Start 2P', monospace;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#pano { position: absolute; inset: 0; }
.overlay3d { position: absolute; inset: 0; pointer-events: none; z-index: 2; }

.dialog {
  background: #f8f8f8;
  border: 4px solid #303848;
  border-radius: 8px;
  box-shadow: inset 0 0 0 3px #a8b8c8, 0 4px 0 rgba(0, 0, 0, .35);
  padding: 14px 16px;
  font-size: 11px;
  line-height: 1.8;
}
.muted { color: #687890; font-size: 9px; }

.btn {
  font: inherit;
  font-size: 11px;
  background: #f8f8f8;
  color: #283040;
  border: 3px solid #303848;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 #303848;
  text-decoration: none;
  text-align: center;
}
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn.primary { background: #e03c28; color: #fff; }
.btn.gold { background: #f8c830; }
.btn.small { font-size: 9px; padding: 6px 8px; }

.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}

/* Title */
#title { background: transparent; overflow: hidden; }
#title::after {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(rgba(10, 16, 32, .35), rgba(10, 16, 32, .15) 30%, rgba(10, 16, 32, .25) 65%, rgba(10, 16, 32, .75)),
    radial-gradient(ellipse 36% 70% at 50% 55%, rgba(10, 16, 32, .5), transparent);
}
#stage { transition: opacity .6s ease; background: #1b2a4a; }
#stage.fading #pano, #stage.fading .overlay3d { opacity: 0; transition: opacity .6s ease; }
#stage #pano, #stage .overlay3d { transition: opacity .7s ease; }
.hero-tag {
  position: absolute; left: 16px; bottom: 28px; z-index: 1; display: flex; flex-direction: column; gap: 6px;
  background: rgba(16, 24, 48, .82); border: 3px solid #f8f8f8; border-radius: 6px; padding: 10px 12px;
  color: #f8f8f8; font-size: 9px; line-height: 1.4; text-align: left;
}
.hero-live { color: #ff6050; display: flex; align-items: center; gap: 6px; }
.hero-live::before { content: ""; width: 8px; height: 8px; background: #ff3b30; border-radius: 50%; animation: pulse 1s infinite; }
#heroCount { color: #f8c830; }
@media (max-width: 760px) { .hero-tag { left: 50%; transform: translateX(-50%); bottom: 12px; white-space: nowrap; } }
.title-wrap { position: relative; z-index: 1; width: 100%; max-width: 380px; text-align: center; }
.title-pack { height: 150px; margin-bottom: -10px; }
.title-pack canvas { width: 100% !important; height: 100% !important; }
.big-logo {
  font-size: 44px; line-height: 1.15; color: #f8c830; letter-spacing: 2px;
  text-shadow: 4px 0 #2850a8, -4px 0 #2850a8, 0 4px #2850a8, 0 -4px #2850a8, 6px 8px 0 #101828;
}
.tag {
  color: #f8f8f8; font-size: 9px; line-height: 1.9; margin: 18px 0 20px; padding: 10px 12px;
  background: rgba(16, 24, 48, .78); border: 3px solid #303848; border-radius: 6px;
}
.menu { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.menu .muted { text-align: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 .btn { font-size: 9px; padding: 10px 6px; }
.wallet-btn { background: #ab9ff2; color: #1c1440; font-size: 9px; }
.wallet-btn.connected { background: #d8f0d0; color: #22502a; }

.list-box { width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; gap: 12px; }
#challengeList { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; padding: 2px; }
.challenge {
  font: inherit; text-align: left; cursor: pointer; background: #fff; color: #283040;
  border: 3px solid #303848; border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 3px 0 #303848;
}
.challenge:active { transform: translateY(3px); box-shadow: none; }
.challenge .c-name { font-size: 11px; color: #e03c28; }
.challenge .c-place { font-size: 8px; color: #485068; }
.challenge .c-blurb { font-size: 8px; line-height: 1.7; color: #687890; }
.challenge .c-foot { display: flex; justify-content: space-between; align-items: center; font-size: 8px; color: #b8860b; }
.challenge .c-stars { font-family: Arial, sans-serif; font-size: 16px; letter-spacing: 2px; }
.rewards { background: #fff6d8; border: 3px solid #f8c830; border-radius: 6px; padding: 10px; font-size: 8px; line-height: 1.8; display: flex; flex-direction: column; gap: 6px; }
.rewards-title { color: #b8860b; font-size: 10px; }
#boardList { overflow-y: auto; padding-left: 26px; font-size: 9px; line-height: 2.2; }
#boardList li.me { color: #e03c28; }
.intro {
  position: fixed; inset: 0; margin: auto; height: fit-content; z-index: 15;
  width: min(380px, calc(100% - 32px)); text-align: center; display: flex; flex-direction: column; gap: 10px;
  font-size: 9px; animation: dropIn .4s ease-out both;
}
.intro-label { color: #b8860b; font-size: 9px; }
.intro h2 { font-size: 16px; color: #e03c28; }
.intro-place { font-size: 9px; color: #485068; }
.intro-stars { font-family: Arial, sans-serif; font-size: 20px; color: #f8a800; letter-spacing: 3px; }
.radar-chip {
  position: fixed; top: 54px; right: 10px; z-index: 10; pointer-events: none;
  background: rgba(16, 24, 48, .88); color: #f8f8f8; border: 3px solid #a8b8c8; border-radius: 6px;
  padding: 7px 9px; font-size: 9px; line-height: 1.5; text-align: right;
}
.radar-chip .r-label { color: #a8b8c8; font-size: 7px; display: block; }
.radar-chip.warmer { border-color: #ff6050; }
.radar-chip.warmer b { color: #ff6050; }
.radar-chip.colder { border-color: #60a8ff; }
.radar-chip.colder b { color: #60a8ff; }
.radar-chip.bump { animation: radarBump .5s ease-out; }
@keyframes radarBump { 0% { transform: scale(1.15); } 100% { transform: none; } }
#radar { top: 104px; }
#hudTime.urgent { color: #ff6050; animation: pulse .6s ease-in-out infinite; }
.disclaimer { color: #7888a8; font-size: 7px; line-height: 1.8; margin-top: 18px; }

/* Picker */
#picker { padding: 0; align-items: flex-end; }
#pickmap { position: absolute; inset: 0; }
.picker-bar { position: relative; margin: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; width: calc(100% - 32px); max-width: 560px; font-size: 9px; }
.pick-row { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.pick-search {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 1;
  width: calc(100% - 32px); max-width: 560px; padding: 10px;
}
.pick-search .pick-row { width: 100%; }
#pickQuery { flex: 1; min-width: 0; font: inherit; font-size: 10px; padding: 10px; border: 3px solid #303848; border-radius: 6px; }
#pickResults { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow-y: auto; }
#pickResults button {
  width: 100%; text-align: left; font: inherit; font-size: 8px; line-height: 1.6; padding: 8px;
  background: #fff; border: 2px solid #a8b8c8; border-radius: 4px; cursor: pointer; color: #283040;
}
#pickResults button:hover { border-color: #303848; background: #f0f4fa; }
@media (max-width: 560px) { .picker-bar { flex-direction: column; align-items: stretch; } .picker-bar .pick-row { justify-content: space-between; } }

#loading { background: rgba(16, 24, 40, .88); }
.loading-box { display: flex; align-items: center; gap: 14px; }
.spinner { width: 18px; height: 18px; background: #e03c28; border: 3px solid #303848; animation: spin .8s steps(4) infinite; }

/* HUD */
#hud {
  position: fixed; top: 10px; left: 10px; right: 10px; z-index: 10;
  display: flex; gap: 10px; align-items: center;
  background: #303848; color: #f8f8f8; border-radius: 8px; padding: 8px 10px;
  font-size: 10px; box-shadow: 0 4px 0 rgba(0, 0, 0, .35);
}
#hud .logo { color: #f8c830; margin-right: auto; }
#hudPacks::before { content: "PACKS "; color: #a8b8c8; }
#hudScore::before { content: "PTS "; color: #a8b8c8; }
.icon-btn { font: inherit; font-size: 9px; background: #485068; color: #f8f8f8; border: 2px solid #a8b8c8; border-radius: 4px; padding: 5px 6px; cursor: pointer; }
.icon-btn.off { opacity: .45; text-decoration: line-through; }
#radar {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: #f8c830; color: #283040; border: 3px solid #303848; border-radius: 6px;
  padding: 8px 10px; font-size: 9px; white-space: nowrap; animation: pulse 1s ease-in-out infinite;
  pointer-events: none;
}

/* Hints */
#hintbox {
  position: fixed; left: 10px; bottom: 26px; z-index: 10;
  width: min(360px, calc(100% - 20px)); max-height: 44vh; overflow-y: auto;
  font-size: 9px;
}
.hint-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; cursor: pointer; color: #b8860b; }
#hintbox.collapsed #hintList { display: none; }
#hintList { margin-top: 8px; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
#hintList li.new { animation: flashIn .8s ease-out; }
#hintList img { width: 100%; border: 3px solid #303848; border-radius: 4px; cursor: zoom-in; display: block; margin-top: 4px; }
#hintList img.zoom { position: fixed; inset: 12% 6%; width: 88%; height: auto; z-index: 30; cursor: zoom-out; }
.warm { color: #e03c28; }
.cold { color: #2850a8; }

/* Encounter */
#encounter { flex-direction: column; justify-content: flex-end; padding: 0; background: #f8f8f8; z-index: 25; }
.field {
  position: relative; flex: 1; width: 100%; overflow: hidden;
  background: linear-gradient(#90c8f0 0 58%, #78b860 58% 100%);
}
#encounter.gold .field { background: linear-gradient(#281848 0 58%, #4a3478 58% 100%); }
.platform {
  position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  width: min(70%, 340px); height: 64px; border-radius: 50%; background: #5e9c48; border: 4px solid #3e7030;
}
#encounter.gold .platform { background: #6a4c20; border-color: #f8c830; }
#encStage { position: absolute; inset: 0; cursor: pointer; }
#encStage canvas { display: block; }
.enc-dialog { width: calc(100% - 20px); max-width: 640px; margin: 10px; min-height: 118px; font-size: 11px; }
.enc-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

#flash { position: absolute; inset: 0; z-index: 5; pointer-events: none; background: #fff; opacity: 0; }
#flash.go { animation: flash .6s steps(1) forwards; }
#flash.white { animation: whiteout .5s ease-out forwards; }

/* Card reveal: the real card over a photo of where it was found */
#reveal { z-index: 30; padding: 0; overflow: hidden; background: #101828; }
.reveal-bg {
  position: absolute; inset: -24px; background: #101828 center / cover no-repeat;
  filter: blur(3px) brightness(.5) saturate(1.2); transform: scale(1.05);
}
#reveal::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(8, 12, 24, .75) 100%);
}
.reveal-wrap {
  position: relative; z-index: 1; height: 100%; width: 100%; max-width: 640px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  gap: 14px; padding: 16px 12px 12px;
}
.found-tag {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  background: rgba(16, 24, 40, .78); border: 3px solid #f8f8f8; border-radius: 8px;
  color: #f8f8f8; padding: 10px 14px; font-size: 10px; line-height: 1.6; max-width: 100%;
  animation: dropIn .5s ease-out both;
}
.found-label { color: #f8c830; font-size: 9px; }
.found-meta { color: #a8b8c8; font-size: 8px; }

.pcard {
  --rx: 0deg; --ry: 0deg; --mx: 50%; --my: 50%; --px: 50%; --py: 50%;
  position: relative; isolation: isolate;
  width: min(300px, 64vw, 42vh); aspect-ratio: 63 / 88; perspective: 1000px;
  flex-shrink: 0; touch-action: none;
}
.pcard-inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transform: rotateY(540deg) scale(.4);
  transition: transform 1.1s cubic-bezier(.2, 1.3, .35, 1);
}
.pcard.flipped .pcard-inner { transform: rotateX(var(--rx)) rotateY(var(--ry)); }
.pcard.live .pcard-inner { transition: transform .15s ease-out; }
.pcard-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 4.6% / 3.3%; overflow: hidden; box-shadow: 0 18px 40px rgba(0, 0, 0, .55);
}
.pcard-front { background: #222; }
.pcard-front img { width: 100%; height: 100%; display: block; user-select: none; }
.pcard-back { transform: rotateY(180deg); background: #2850a8 center / cover; }

.glare {
  position: absolute; inset: 0; pointer-events: none; mix-blend-mode: overlay;
  background: radial-gradient(farthest-corner circle at var(--mx) var(--my),
    rgba(255, 255, 255, .55) 0%, rgba(255, 255, 255, .12) 25%, rgba(0, 0, 0, .2) 90%);
  opacity: .35;
}
.shine, .sparkle { position: absolute; inset: 0; pointer-events: none; display: none; }
.pcard.foil .shine {
  display: block; mix-blend-mode: color-dodge; opacity: .22;
  background-image:
    var(--glitter),
    repeating-linear-gradient(115deg, #ff7a7a 0%, #ffe86a 5%, #9dff7a 10%, #7af2ff 15%, #7a9dff 20%, #e47aff 25%, #ff7a7a 30%),
    repeating-linear-gradient(45deg, rgba(0, 0, 0, .45) 0 1px, transparent 1px 5px);
  background-size: 160px 160px, 400% 400%, 100% 100%;
  background-position: center, var(--px) var(--py), center;
  background-blend-mode: soft-light, normal, overlay;
  filter: brightness(.6) contrast(1.4) saturate(1.2);
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0,0,0,.45) 55%, rgba(0,0,0,.25) 100%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, rgba(0,0,0,.45) 55%, rgba(0,0,0,.25) 100%);
}
.pcard.golden .shine {
  background-image:
    var(--glitter),
    repeating-linear-gradient(115deg, #fff2a8 0%, #ffc83a 6%, #ff9f2e 12%, #fff6c8 18%, #ffd85a 24%, #fff2a8 30%),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, .4) 0 1px, transparent 1px 4px);
  opacity: .26;
}
.pcard.foil .sparkle {
  display: block; mix-blend-mode: color-dodge; opacity: .5;
  background-image: var(--glitter); background-size: 90px 90px;
  background-position: calc(var(--px) * -1) var(--py);
  -webkit-mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, transparent 30%);
  mask-image: radial-gradient(circle at var(--mx) var(--my), #000 0%, transparent 30%);
}
.pcard.golden::before, .pcard.holo::before {
  content: ""; position: absolute; inset: -14%; z-index: -1; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, rgba(255, 210, 60, .85), transparent 25%,
    rgba(255, 240, 160, .8), transparent 50%, rgba(255, 190, 40, .85), transparent 75%);
  filter: blur(22px); animation: spin 5s linear infinite; opacity: 0; transition: opacity 1s .8s;
}
.pcard.holo::before {
  background: conic-gradient(from 0deg, transparent, rgba(120, 180, 255, .7), transparent 30%,
    rgba(230, 130, 255, .6), transparent 60%, rgba(120, 255, 220, .6), transparent 90%);
}
.pcard.flipped.golden::before, .pcard.flipped.holo::before { opacity: 1; }

#reveal { overflow-y: auto; align-items: flex-start; }
.reveal-wrap { height: auto; min-height: 100%; }
.pcard.live { cursor: zoom-in; }
.zoom-hint { color: #a8b8c8; font-size: 8px; text-align: center; margin-top: -6px; }

/* Card inspector: zoom and scroll around the full-size card */
#inspect { z-index: 35; flex-direction: column; padding: 0; background: rgba(8, 12, 24, .96); }
.inspect-scroll {
  flex: 1; width: 100%; overflow: auto; touch-action: pan-x pan-y; overscroll-behavior: contain;
  display: flex; padding: 24px; cursor: grab;
}
.inspect-scroll.dragging { cursor: grabbing; }
#inspectImg {
  width: var(--w, 360px); max-width: none; height: auto; border-radius: 3.5% / 2.5%;
  margin: auto; flex-shrink: 0; /* auto margins centre it without clipping when zoomed */
  box-shadow: 0 20px 50px rgba(0, 0, 0, .6); user-select: none; -webkit-user-drag: none;
}
.inspect-bar {
  display: flex; align-items: center; gap: 10px; padding: 12px; color: #f8f8f8; font-size: 10px;
}
.inspect-bar .btn { min-width: 40px; }
#zoomLabel { min-width: 52px; text-align: center; }
.inspect-tip { color: #7888a8; font-size: 7px; padding-bottom: 12px; text-align: center; }

.reveal-info { width: 100%; min-height: 96px; font-size: 10px; animation: dropIn .4s ease-out both; }
.rarity-pill { display: inline-block; padding: 2px 6px; border-radius: 4px; color: #fff; font-size: 8px; margin-right: 6px; }

/* Results + bag */
#results, #bag { background: rgba(16, 24, 40, .92); }
.results { max-width: 380px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 16px; }
.results h2 { font-size: 16px; color: #b8860b; }
.best { color: #e03c28; }
.bag-box { width: 100%; max-width: 720px; max-height: 90vh; display: flex; flex-direction: column; gap: 12px; }
.bag-head { display: flex; justify-content: space-between; align-items: center; }
.bag-head h2 { font-size: 14px; }
#bagGrid { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; padding: 4px; }
#bagGrid canvas { width: 100%; height: auto; border-radius: 4px; image-rendering: pixelated; }
.bag-card {
  font: inherit; font-size: 7px; line-height: 1.5; color: #687890; background: none; border: 0; padding: 0;
  cursor: pointer; display: flex; flex-direction: column; gap: 4px; text-align: left;
}
.bag-card .thumb { position: relative; border-radius: 5px; overflow: hidden; aspect-ratio: 63 / 88; background: #d8dde6; }
.bag-card img { width: 100%; height: 100%; display: block; }
.bag-card.foil .thumb::after {
  content: ""; position: absolute; inset: 0; mix-blend-mode: color-dodge; opacity: .45;
  background: linear-gradient(115deg, transparent 20%, #ff9a9a 35%, #fff07a 42%, #8affd0 50%, #8ab4ff 58%, transparent 72%);
  background-size: 250% 250%; animation: foilSweep 3.5s linear infinite;
}
#bagGrid p { grid-column: 1 / -1; }

#toast {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 40;
  background: #303848; color: #f8f8f8; padding: 10px 14px; border-radius: 6px; font-size: 9px;
  max-width: calc(100% - 32px); line-height: 1.7; text-align: center;
}

@media (max-width: 560px) {
  #hud .logo { display: none; }
  #hud { gap: 6px; font-size: 8px; padding: 8px; }
  #hud > span { white-space: nowrap; }
  #hudPacks { margin-right: auto; }
  #hudPacks::before { content: "PK "; }
  #hudScore::before { content: "PT "; }
  .icon-btn { font-size: 8px; padding: 4px 5px; white-space: nowrap; }
  .radar-chip { top: 50px; }
  .big-logo { font-size: 36px; }
}

@keyframes pulse { 50% { opacity: .65; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes flash { 0%, 30%, 60% { opacity: 1; } 15%, 45%, 100% { opacity: 0; } }
@keyframes whiteout { 0% { opacity: .95; } 100% { opacity: 0; } }
@keyframes dropIn { from { opacity: 0; transform: translateY(-12px); } }
@keyframes foilSweep { from { background-position: 100% 0; } to { background-position: -150% 0; } }
@keyframes flashIn { 0% { background: #f8c830; } 100% { background: transparent; } }
