/* =========================================================================
   Pokekirk — theme + layout
   Mobile-first. Dark, neon-nature palette. Safe-area aware.
   All colors are tokens on :root so the whole game recolors from one place.
   ========================================================================= */
:root {
  /* core palette */
  --bg:            #0b1020;
  --bg-2:          #121a33;
  --panel:         #151d38;
  --panel-2:       #1c2850;
  --line:          #2a3763;
  --ink:           #eaf0ff;
  --ink-dim:       #9fb0d8;
  --ink-faint:     #6b7aa6;
  --brand:         #ffcb05;  /* signature yellow */
  --brand-2:       #3b82f6;  /* signature blue  */
  --good:          #46d17f;
  --warn:          #ffb020;
  --bad:           #ff5d6c;
  --shadow:        0 8px 28px rgba(0,0,0,.45);
  --shadow-sm:     0 3px 12px rgba(0,0,0,.35);

  /* type colors (shared with creatures.js TYPES) */
  --t-normal:  #b9b9a8;
  --t-fire:    #ff6b35;
  --t-water:   #3b9dff;
  --t-grass:   #52c45a;
  --t-electric:#ffd23f;
  --t-ice:     #7fd3ff;
  --t-rock:    #b08d57;
  --t-bug:     #9bbf2f;
  --t-spirit:  #9b7bd4;
  --t-flying:  #8fb8ff;
  --t-dark:    #6a6480;
  --t-fairy:   #ff9bd0;

  /* rarity colors (shared with creatures.js RARITY) */
  --r-common:    #9fb0d8;
  --r-uncommon:  #46d17f;
  --r-rare:      #3b9dff;
  --r-epic:      #b06bff;
  --r-legendary: #ffcb05;

  --nav-h: 64px;
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
h1, h2 { margin: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
  background: var(--bg);
}

/* ---------- scenes ---------- */
.scene { position: absolute; inset: 0 0 var(--nav-h) 0; display: none; }
.scene.active { display: block; }
.scene.panel { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(env(safe-area-inset-top) + 14px) 14px 20px; }

/* =========================================================================
   MAP SCENE
   ========================================================================= */
#map-scene { background: var(--bg); }
#world-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; padding: calc(env(safe-area-inset-top) + 10px) 12px 0;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.profile-chip {
  display: flex; align-items: center; gap: 10px;
  background: rgba(21,29,56,.82); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px 6px 6px; box-shadow: var(--shadow-sm);
}
.hud-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); display: block; overflow: hidden; flex: none; }
.hud-avatar svg { width: 100%; height: 100%; display: block; }
.hud-level-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 92px; }
.hud-level { font-size: 12px; color: var(--ink-dim); line-height: 1; }
.hud-level b { color: var(--brand); font-size: 14px; }
.xp-track { height: 5px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.xp-track.big { height: 9px; flex: 1; }
.xp-fill { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--brand), #ffe473); transition: width .4s ease; }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.hud-pill {
  background: rgba(21,29,56,.82); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; color: var(--ink-dim); box-shadow: var(--shadow-sm);
}

.nearby-tracker {
  position: absolute; right: 10px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  max-height: 46vh; overflow: hidden; pointer-events: none;
}
.nearby-chip {
  display: flex; align-items: center; gap: 7px;
  background: rgba(21,29,56,.86); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 999px 10px 10px 999px;
  padding: 4px 10px 4px 4px; box-shadow: var(--shadow-sm);
  pointer-events: auto; animation: pop .25s ease;
}
.nearby-chip .nc-art { width: 30px; height: 30px; flex: none; }
.nearby-chip .nc-dist { font-size: 11px; color: var(--ink-dim); font-family: var(--mono); }
.nearby-chip.near { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand), var(--shadow-sm); }

.gps-banner {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 66px); transform: translateX(-50%);
  background: rgba(21,29,56,.92); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 12px; color: var(--ink-dim); box-shadow: var(--shadow-sm);
  max-width: 88%; text-align: center;
}
.gps-banner.warn { border-color: var(--warn); color: #ffe0a8; }

.map-fabs { position: absolute; left: 12px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; }
.fab {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(21,29,56,.9); border: 1px solid var(--line);
  font-size: 20px; display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.fab.on { border-color: var(--brand); color: var(--brand); }

.joystick {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  width: 128px; height: 128px; border-radius: 50%;
  background: radial-gradient(circle, rgba(28,40,80,.5), rgba(11,16,32,.25));
  border: 1px solid var(--line); touch-action: none;
}
.joystick-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px;
  border-radius: 50%; background: rgba(59,130,246,.75); border: 2px solid #9fc2ff;
  box-shadow: var(--shadow-sm);
}

/* =========================================================================
   ENCOUNTER SCENE
   ========================================================================= */
.scene.encounter { inset: 0; background: #060912; z-index: 40; }
.ar-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; background: #060912; }
#encounter-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; z-index: 1; }
.enc-ar {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 62px; z-index: 3;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(10,14,26,.6); font-size: 17px; line-height: 1; color: var(--ink);
}
.enc-ar.on { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }

.enc-run {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 14px; z-index: 3;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(10,14,26,.6); font-size: 18px; color: var(--ink);
}
.enc-nameplate {
  position: absolute; top: calc(env(safe-area-inset-top) + 16px); left: 16px; z-index: 3;
  display: flex; flex-direction: column; gap: 5px; align-items: flex-start;
}
.enc-name { font-size: 22px; font-weight: 800; text-shadow: 0 2px 10px rgba(0,0,0,.6); }
.enc-cp { font-size: 13px; color: var(--brand); font-weight: 700; font-family: var(--mono); }
.enc-types { display: flex; gap: 5px; }

.enc-hint {
  position: absolute; left: 50%; bottom: 190px; transform: translateX(-50%); z-index: 3;
  font-size: 13px; color: var(--ink-dim); background: rgba(10,14,26,.5);
  padding: 5px 12px; border-radius: 999px; white-space: nowrap; transition: opacity .3s;
}

.enc-controls {
  position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 26px); z-index: 3;
  display: flex; align-items: center; justify-content: center; gap: 34px;
}
.enc-ball {
  width: 84px; height: 84px; touch-action: none; display: grid; place-items: center;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.5));
  animation: ballIdle 2.6s ease-in-out infinite;
}
@keyframes ballIdle { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-7px) rotate(4deg); } }
.enc-ball-face {
  width: 84px; height: 84px; border-radius: 50%;
  background:
    linear-gradient(#ff5d6c 0 48%, #fff 48% 52%, #f4f6ff 52% 100%);
  border: 3px solid #0b1020; position: relative;
}
.enc-ball-face::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px;
  border-radius: 50%; background: #fff; border: 3px solid #0b1020;
}
.enc-side-btn {
  width: 56px; height: 56px; border-radius: 16px; background: rgba(21,29,56,.8);
  border: 1px solid var(--line); display: grid; place-items: center; position: relative;
}
.enc-side-ico { font-size: 24px; }
.enc-side-count {
  position: absolute; right: -4px; bottom: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--brand-2); color: #fff; font-size: 11px; font-weight: 800;
  display: grid; place-items: center; border: 2px solid var(--bg);
}

.enc-result {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center;
  background: rgba(6,9,18,.82); backdrop-filter: blur(4px); padding: 24px;
}
.enc-result .card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  padding: 24px; text-align: center; max-width: 320px; width: 100%; box-shadow: var(--shadow);
  animation: pop .3s ease;
}
.enc-result h2 { font-size: 24px; margin-bottom: 4px; }
.enc-result .sub { color: var(--ink-dim); font-size: 14px; margin-bottom: 14px; }
.enc-result .art { width: 150px; height: 150px; margin: 0 auto 10px; }
.enc-result .rewards { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-size: 14px; color: var(--ink-dim); }
.enc-result .rewards b { color: var(--ink); }

.ball-picker {
  position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 7;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 10px; display: flex; gap: 10px; box-shadow: var(--shadow);
}
.ball-picker button {
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 64px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px; font-size: 12px;
}
.ball-picker button[disabled] { opacity: .4; }

/* =========================================================================
   PANELS (dex / bag / profile)
   ========================================================================= */
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.panel-head h1 { font-size: 26px; letter-spacing: -.5px; }
.panel-sub { color: var(--ink-dim); font-size: 13px; }

.dex-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.dex-tab { flex: 1; padding: 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); color: var(--ink-dim); font-weight: 600; }
.dex-tab.active { background: var(--panel-2); color: var(--ink); border-color: var(--brand-2); }

.dex-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dex-cell {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 8px 8px; text-align: center; position: relative; aspect-ratio: 1 / 1.12;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.dex-cell .num { position: absolute; top: 6px; left: 8px; font-size: 10px; color: var(--ink-faint); font-family: var(--mono); }
.dex-cell .art { width: 64px; height: 64px; }
.dex-cell .cname { font-size: 12px; font-weight: 700; }
.dex-cell.unseen .art { filter: brightness(0) saturate(0); opacity: .35; }
.dex-cell.unseen .cname { color: var(--ink-faint); }
.dex-cell.caught::after { content: "✓"; position: absolute; top: 6px; right: 8px; color: var(--good); font-weight: 900; font-size: 12px; }
.dex-cell .rarity-dot { position: absolute; bottom: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; }

.dex-detail { position: absolute; inset: 0; background: var(--bg); overflow-y: auto; padding: calc(env(safe-area-inset-top) + 14px) 16px 24px; z-index: 5; }
.dex-detail .back { background: none; border: none; color: var(--brand-2); font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.dex-detail .hero-art { width: 160px; height: 160px; margin: 0 auto; }
.dex-detail h2 { text-align: center; font-size: 24px; }
.dex-detail .flavor { color: var(--ink-dim); font-size: 14px; line-height: 1.5; text-align: center; margin: 10px 0 16px; }
.stat-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.stat-row .label { width: 64px; color: var(--ink-dim); }
.stat-bar { flex: 1; height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.stat-bar i { display: block; height: 100%; background: var(--brand-2); }

/* collection cards */
.col-card {
  display: flex; align-items: center; gap: 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px;
}
.col-card .art { width: 54px; height: 54px; flex: none; }
.col-card .meta { flex: 1; min-width: 0; }
.col-card .meta .nm { font-weight: 700; }
.col-card .meta .cp { color: var(--brand); font-family: var(--mono); font-size: 13px; }
.col-card .shiny-tag { color: var(--brand); font-size: 11px; font-weight: 800; }

/* =========================================================================
   BAG
   ========================================================================= */
.bag-list { display: flex; flex-direction: column; gap: 10px; }
.bag-item {
  display: flex; align-items: center; gap: 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.bag-item .ico { font-size: 28px; width: 40px; text-align: center; }
.bag-item .info { flex: 1; }
.bag-item .info .nm { font-weight: 700; }
.bag-item .info .desc { font-size: 12px; color: var(--ink-dim); }
.bag-item .qty { font-family: var(--mono); font-weight: 800; color: var(--brand); font-size: 18px; }
.bag-note { margin-top: 16px; font-size: 13px; color: var(--ink-dim); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; line-height: 1.5; }

/* =========================================================================
   PROFILE
   ========================================================================= */
.profile-hero { text-align: center; margin: 10px 0 20px; }
.profile-avatar { width: 110px; height: 110px; margin: 0 auto 10px; border-radius: 50%; background: var(--panel-2); overflow: hidden; border: 3px solid var(--line); }
.profile-avatar svg { width: 100%; height: 100%; }
.profile-name { background: transparent; border: none; border-bottom: 1px dashed var(--line); color: var(--ink); font-size: 22px; font-weight: 800; text-align: center; width: 70%; padding: 4px; }
.profile-level { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 12px; font-size: 14px; }
.profile-level b { color: var(--brand); }

.profile-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 20px; }
.stat-tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat-tile .v { font-size: 26px; font-weight: 800; color: var(--brand); font-family: var(--mono); }
.stat-tile .k { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }

.profile-settings { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }
.profile-settings h2 { font-size: 15px; color: var(--ink-dim); margin: 8px 0; }
.profile-settings .row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.profile-settings .row:last-of-type { border-bottom: none; }
.profile-settings input[type=checkbox] { width: 44px; height: 26px; appearance: none; background: var(--panel-2); border-radius: 99px; position: relative; border: 1px solid var(--line); }
.profile-settings input[type=checkbox]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink-dim); transition: .2s; }
.profile-settings input[type=checkbox]:checked { background: var(--brand-2); }
.profile-settings input[type=checkbox]:checked::after { left: 20px; background: #fff; }
.btn-ghost { width: 100%; margin-top: 12px; padding: 13px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--brand-2); color: var(--ink); font-weight: 700; }
.btn-danger { width: 100%; margin-top: 10px; padding: 13px; border-radius: 12px; background: transparent; border: 1px solid var(--bad); color: var(--bad); font-weight: 700; }
.profile-foot { text-align: center; color: var(--ink-faint); font-size: 12px; margin-top: 18px; }

/* =========================================================================
   BEACON PANEL
   ========================================================================= */
.beacon-panel { position: absolute; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(6,9,18,.8); backdrop-filter: blur(5px); padding: 20px; }
/* these overlays set their own display, so they must still honor the hidden attribute */
.beacon-panel[hidden], .enc-result[hidden], .ball-picker[hidden] { display: none !important; }
.beacon-panel .card { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 22px; max-width: 320px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.beacon-panel .spin-disc { width: 120px; height: 120px; margin: 0 auto 14px; border-radius: 50%; background: radial-gradient(circle, var(--brand-2), #1a2a55); display: grid; place-items: center; font-size: 48px; }
.beacon-panel .loot { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.beacon-panel .loot .li { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; }

/* =========================================================================
   BOTTOM NAV
   ========================================================================= */
.bottom-nav {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--nav-h);
  display: flex; background: rgba(13,19,38,.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 30;
}
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: none; color: var(--ink-faint); }
.nav-btn .nav-ico { font-size: 22px; filter: grayscale(.6); transition: .15s; }
.nav-btn .nav-label { font-size: 11px; }
.nav-btn.active { color: var(--brand); }
.nav-btn.active .nav-ico { filter: none; transform: translateY(-1px); }

/* =========================================================================
   TOASTS + SPLASH + shared
   ========================================================================= */
.toast-container { position: absolute; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: 90%; }
.toast { background: rgba(21,29,56,.96); border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; font-size: 14px; box-shadow: var(--shadow); animation: toastIn .25s ease; }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }

.splash { position: absolute; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; transition: opacity .5s; }
.splash.hide { opacity: 0; pointer-events: none; }
.splash-logo { font-size: 42px; font-weight: 800; letter-spacing: -1px; color: var(--ink); }
.splash-logo b { color: var(--brand); }
.splash-spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--panel-2); border-top-color: var(--brand); animation: spin 1s linear infinite; }
.splash-tip { color: var(--ink-dim); font-size: 14px; }

/* type + rarity chips shared */
.type-chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; color: #0b1020; text-transform: capitalize; }
.rarity-chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; text-transform: capitalize; border: 1px solid currentColor; }

/* ---------- animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes shake { 10%,90% { transform: translateX(-2px); } 20%,80% { transform: translateX(3px); } 30%,50%,70% { transform: translateX(-5px); } 40%,60% { transform: translateX(5px); } }

body.reduce-motion * { animation-duration: .001ms !important; transition-duration: .001ms !important; }

@media (min-width: 560px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
