:root {
  --ink: #0c0c0c;
  --paper: #ffffff;
  --pink: #d72d6b;
  --pink-deep: #a81f50;
  --muted: #a7a7ad;
  --ui: 'Chakra Petch', system-ui, sans-serif;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --bevel: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); font-family: var(--ui); overflow: hidden; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* ---------- full screens (start / no card / error) ---------- */
.screen {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
  text-align: center;
  background:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px) 0 0 / 16px 16px,
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px) 0 0 / 16px 16px,
    radial-gradient(120% 70% at 50% 0%, #2a0f1b 0%, var(--ink) 60%);
}
.logo { width: 112px; height: auto; margin-bottom: 18px; filter: drop-shadow(0 6px 0 rgba(215,45,107,0.35)); }
.eyebrow { margin: 0 0 10px; font-weight: 700; letter-spacing: 0.24em; text-transform: uppercase; font-size: 13px; color: var(--pink); }
h1 { margin: 0 0 22px; font-family: var(--pixel); font-weight: 400; font-size: clamp(17px, 5.6vw, 30px); line-height: 1.45; text-wrap: balance; }
.body { max-width: 30ch; margin: 0 0 26px; font-size: 17px; line-height: 1.5; color: #d9d9de; }
.steps { list-style: none; counter-reset: s; margin: 0 0 30px; padding: 0; display: grid; gap: 10px; text-align: left; font-size: 17px; }
.steps li { counter-increment: s; display: flex; align-items: center; gap: 12px; }
.steps li::before {
  content: counter(s); flex: none; display: grid; place-items: center; width: 28px; height: 28px;
  font-family: var(--pixel); font-size: 11px; background: var(--paper); color: var(--ink);
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.steps b { color: var(--pink); font-weight: 700; }
.fine { margin: 18px 0 0; font-size: 13px; color: var(--muted); }

.btn {
  appearance: none; border: 0; cursor: pointer;
  min-width: 220px; min-height: 56px; padding: 0 28px;
  font-family: var(--pixel); font-size: 15px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--paper); background: var(--pink);
  clip-path: var(--bevel);
  box-shadow: inset 0 -6px 0 var(--pink-deep);
  transition: transform 120ms ease-out, filter 120ms ease-out;
}
.btn:active { transform: translateY(2px) scale(0.98); filter: brightness(0.92); }
.btn:focus-visible { outline: 3px solid var(--paper); outline-offset: 4px; }
.btn-ghost { margin-top: 12px; background: transparent; box-shadow: inset 0 0 0 2px #4a4a52; font-size: 11px; min-height: 48px; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(rgba(12,12,12,0.75), transparent);
  font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; font-size: 12px;
}
.topbar img { width: 30px; height: auto; }
.topbar span { flex: 1; }
.icon-btn {
  pointer-events: auto; appearance: none; border: 0; cursor: pointer;
  width: 44px; height: 44px; font-size: 18px; color: var(--paper); background: rgba(12,12,12,0.6);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.icon-btn.off { color: #6b6b72; text-decoration: line-through; }

.testbar {
  position: absolute; left: 0; right: 0; top: calc(68px + env(safe-area-inset-top));
  padding: 10px 16px; display: flex; gap: 10px; align-items: center;
  background: #ffd23a; color: #181818; border-bottom: 3px solid #181818; font-size: 14px; font-weight: 700;
}
.testbar b { font-family: var(--pixel); font-size: 10px; font-weight: 400; }
.taken-portrait { width: 140px; height: 140px; margin: 0 0 18px; display: grid; place-items: center; border-radius: 50%; background: #17171b; border: 3px solid #2c2c33; }
.taken-portrait canvas { width: 96px; height: 96px; image-rendering: pixelated; }

.status {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 12px 18px; font-family: var(--pixel); font-size: 11px; background: rgba(12,12,12,0.8);
}

.scan { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
.scan p {
  margin: 0; padding: 10px 14px; text-align: center; font-size: 16px; font-weight: 700; line-height: 1.35;
  background: rgba(12,12,12,0.72);
}
.frame { position: relative; width: min(62vw, 280px); aspect-ratio: 1; animation: breathe 1.6s ease-in-out infinite; }
.frame i { position: absolute; width: 34px; height: 34px; border: 5px solid var(--paper); }
.frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-color: var(--pink); }
.frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-color: var(--pink); }
.frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }
@keyframes breathe { 50% { transform: scale(0.94); } }

/* Game Boy-style text box */
.dialog {
  pointer-events: auto;
  position: absolute; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; min-height: 96px;
  padding: 18px 20px 20px;
  font-family: var(--pixel); font-size: 13px; line-height: 1.9; color: #181818;
  background: #f8f8f0;
  border: 4px solid #181818;
  box-shadow: inset 0 0 0 4px #f8f8f0, inset 0 0 0 7px #181818, 0 6px 0 rgba(0,0,0,0.35);
}
.dialog p { margin: 0; min-height: 2lh; }
.dialog .more { position: absolute; right: 12px; bottom: 6px; display: block; line-height: 0; color: var(--pink); animation: nudge 0.7s steps(2) infinite; }
@keyframes nudge { 50% { transform: translateY(3px); } }

/* ---------- Pokédex ---------- */
.dex-btn {
  pointer-events: auto; appearance: none; border: 0; cursor: pointer;
  position: absolute; left: 16px; bottom: calc(128px + env(safe-area-inset-bottom));
  text-decoration: none;
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 12px 0 10px;
  font-family: var(--pixel); font-size: 10px; color: #fff; background: #d8102e;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  box-shadow: inset 0 -5px 0 #8f0a1f;
  animation: dex-in 320ms cubic-bezier(.2, .9, .3, 1.3) both;
}
.dex-btn:active { transform: translateY(2px); }
.mydex-btn { left: auto; right: 16px; color: #fff; }
.mydex-btn:hover { color: #fff; }
@keyframes dex-in { from { transform: translateY(14px) scale(0.9); opacity: 0; } }
.dex-lens { flex: none; width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; background: radial-gradient(circle at 35% 35%, #bfe9ff, #2b8fd8 60%, #155a92); }
.dex-lens.big { width: 30px; height: 30px; border-width: 4px; }

.dex {
  pointer-events: auto; position: absolute; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; padding: 12px 14px 16px;
  background: #d8102e; border: 4px solid #181818; border-radius: 14px 14px 14px 36px;
  box-shadow: inset 0 -6px 0 #9a0b22, 0 8px 0 rgba(0,0,0,0.35);
  animation: dex-open 300ms cubic-bezier(.2, .9, .3, 1.15) both;
}
@keyframes dex-open { from { transform: translateY(40px); opacity: 0; } }
.dex-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.led { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #181818; }
.led.r { background: #ff5a5a; } .led.y { background: #ffd23a; } .led.g { background: #5fd35f; }
.dex-close {
  margin-left: auto; appearance: none; border: 0; cursor: pointer; width: 40px; height: 40px;
  font-size: 18px; color: #fff; background: #8f0a1f; border-radius: 50%;
}
.dex-screen {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 8px;
  background: #dfe9d3; border: 3px solid #181818; box-shadow: inset 0 0 0 3px #b9c9a8;
}
.dex-portrait { flex: none; width: 80px; height: 80px; display: grid; place-items: center; background: #f4f8ee; border: 2px solid #181818; border-radius: 6px; }
.dex-portrait canvas { width: 80px; height: 80px; image-rendering: pixelated; }
.dex-meta { min-width: 0; color: #1d2a16; }
.dex-meta p { margin: 0; }
.dex-no { font-family: var(--pixel); font-size: 10px; color: #4b5d3c; }
.dex-name { font-family: var(--pixel); font-size: 14px; margin: 6px 0 !important; }
.dex-species { font-size: 14px; font-weight: 700; }
.dex-types { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 4px !important; }
.dex-types span { padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; color: #fff; background: var(--t, #777); }
.dex-hw { font-size: 13px; color: #3d4d30; }
.dex-text {
  margin: 10px 0 0; min-height: 4.8em; padding: 9px 11px; border-radius: 6px;
  font-family: var(--pixel); font-size: 10px; line-height: 1.75; color: #fff; background: #1b1b1f; border: 3px solid #181818;
}

/* ---------- no-camera preview ---------- */
.stage {
  position: fixed; inset: 0; z-index: 10;
  background:
    radial-gradient(60% 40% at 50% 62%, #3a1626 0%, transparent 70%),
    linear-gradient(#141418, #0c0c0c);
}
.stage-floor {
  position: absolute; left: 50%; top: 66%; width: min(70vw, 340px); aspect-ratio: 2 / 1; transform: translate(-50%, -50%);
  border-radius: 50%; background: radial-gradient(closest-side, rgba(0,0,0,0.6), transparent);
}
.stage-sprite { position: absolute; left: 50%; top: 66%; width: min(82vw, 420px); aspect-ratio: 1; transform: translate(-50%, -88%); }
.stage-sprite canvas { width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
/* while the Pokédex is open, lift the preview Pokémon above it */
.stage-sprite, .stage-floor { transition: top 300ms ease-out; }
.dex-open .stage-sprite, .dex-open .stage-floor { top: 40%; }
.stage-hint { position: absolute; left: 0; right: 0; top: calc(64px + env(safe-area-inset-top)); margin: 0; text-align: center; font-size: 13px; color: var(--muted); }

/* MindAR puts the camera <video> (z-index -2) and the 3D canvas inside #ar-root, sized from #ar-root.
   It has to fill the screen and be its own layer, or the video ends up 0px tall / under the page background. */
#ar-root { position: fixed; inset: 0; z-index: 0; overflow: hidden; }
#ar-root a-scene, #ar-root .a-canvas { z-index: 1 !important; }
/* A-Frame's own "Enter VR / AR" buttons: not used here */
.a-enter-vr, .a-enter-ar, .a-enter-vr-button, .a-enter-ar-button, .a-orientation-modal { display: none !important; }
html.ar-on, html.ar-on body { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  .frame, .dialog .more { animation: none; }
}

/* ---------- My Pokédex page ---------- */
html:has(body.page-scroll), body.page-scroll { overflow: auto; height: auto; min-height: 100%; }
.pdx { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.pdx-head {
  padding: calc(18px + env(safe-area-inset-top)) 18px 16px; display: flex; flex-direction: column; gap: 10px;
  background: #d8102e; border-bottom: 4px solid #181818; box-shadow: inset 0 -6px 0 #9a0b22;
}
.pdx-top { display: flex; align-items: center; gap: 10px; }
.pdx-top h1 { margin: 0 0 0 auto; font-size: 14px; line-height: 1.4; }
.pdx-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 15px; font-weight: 700; }
.pdx-count { font-family: var(--pixel); font-size: 12px; }
.pdx-bar { height: 10px; background: #8f0a1f; border: 2px solid #181818; }
.pdx-bar div { height: 100%; width: 0; background: #ffd23a; transition: width 400ms ease-out; }
.pdx-rare { font-size: 13px; font-weight: 700; color: #ffe3e8; }
.pdx-empty { margin: 18px 16px 0; font-size: 16px; line-height: 1.5; color: #d9d9de; text-align: center; }
.pdx-grid { padding: 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pdx-slot {
  position: relative; min-height: 128px; box-sizing: border-box; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: #18181c; border: 3px solid #2c2c33; color: #6b6b74; font-family: var(--ui);
}
.pdx-slot.caught { background: #eef4e6; border-color: #181818; color: #1d2a16; cursor: pointer; }
.pdx-slot.rare { border-color: #e9b640; }
.pdx-slot.rare:not(.caught) { background: #1b1810; }
.pdx-slot canvas { width: 72px; height: 72px; image-rendering: pixelated; }
.pdx-q { width: 72px; height: 72px; display: grid; place-items: center; font-family: var(--pixel); font-size: 30px; color: #3a3a42; }
.pdx-slot.rare .pdx-q, .pdx-slot.rare:not(.caught) .pdx-name { color: #e9b640; }
.pdx-no { font-family: var(--pixel); font-size: 8px; color: #8d8d95; }
.pdx-slot.caught .pdx-no { color: #4b5d3c; }
.pdx-name { font-size: 12px; font-weight: 700; }
.pdx-badge { position: absolute; right: -6px; top: -8px; padding: 3px 6px; background: #ffd23a; color: #181818; border: 2px solid #181818; font-family: var(--pixel); font-size: 8px; }
.pdx-install {
  margin: 0 16px 12px; padding: 12px 10px 12px 14px; display: flex; align-items: center; gap: 10px;
  background: #121215; border: 2px solid #d72d6b;
}
.pdx-install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 14px; color: #d9d9de; }
.pdx-install-text b { color: #fff; font-size: 15px; }
.pdx-install-btn { min-height: 44px; padding: 0 16px; border: 0; background: #d72d6b; color: #fff; font-family: var(--pixel); font-size: 10px; cursor: pointer; }
.pdx-x { width: 44px; height: 44px; border: 0; background: transparent; color: #a7a7ad; font-size: 16px; cursor: pointer; }
.pdx-foot { margin-top: auto; padding: 14px 16px calc(22px + env(safe-area-inset-bottom)); border-top: 1px solid #2c2c33; display: flex; justify-content: center; }
.pdx-foot .btn { width: 100%; }
.pdx-sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; padding: 12px 12px calc(14px + env(safe-area-inset-bottom)); background: rgba(0, 0, 0, 0.6); }
.pdx-sheet .dex { position: relative; left: auto; right: auto; bottom: auto; width: 100%; }
.pdx-copies { margin-left: 8px; font-size: 13px; font-weight: 700; color: #ffe3e8; }
.pdx-help { width: 100%; max-width: 520px; box-sizing: border-box; padding: 24px 22px; background: #121215; border-top: 4px solid #d72d6b; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.pdx-help h2 { margin: 0; font-family: var(--pixel); font-weight: 400; font-size: 15px; }
.pdx-help .steps { margin: 0; }
