:root {
  --primary: #8FE3CF; --tertiary: #FFC857; --error: #FF7A6B;
  --surface: #101418; --elevated: #1A2028; --raised: #232b35;
  --text: #E9EEF3; --muted: #8A96A3; --grid: rgba(255,255,255,.07); --line: rgba(255,255,255,.09);
  --font: "Avenir Next", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { background: var(--surface); color-scheme: dark; -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 var(--font); color: var(--text); background: var(--surface);
  padding-bottom: max(24px, env(safe-area-inset-bottom)); }
a { color: var(--primary); }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; letter-spacing: .01em; }
h3 { margin: 0 0 8px; font-size: 17px; }
.muted { color: var(--muted); }
.error { color: var(--error); }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
[hidden] { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  background: rgba(16,20,24,.86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .02em; }
.actions { display: flex; gap: 6px; }

/* buttons */
.btn { white-space: nowrap; font: inherit; font-size: 14px; font-weight: 600; min-height: 40px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--raised); color: var(--text); cursor: pointer; touch-action: manipulation; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--primary); color: #06201a; border-color: transparent; }
.btn.danger { color: var(--error); }
.btn.ghost { background: transparent; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; font-weight: 600; min-height: 32px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; touch-action: manipulation; }
.chip[aria-selected="true"] { background: var(--raised); color: var(--text); border-color: transparent; }

main { max-width: 720px; margin: 0 auto; padding: 12px max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); display: grid; gap: 12px; }
.card { background: var(--elevated); border-radius: var(--radius); padding: 14px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.sec-head h2 { margin: 0; }

/* hero */
.hero { position: relative; padding: 0; overflow: hidden;
  background: radial-gradient(90% 70% at 50% 25%, #26313c 0%, #1A2028 60%, #141a20 100%); }
#stage { display: block; width: 100%; height: 320px; touch-action: pan-y; cursor: grab; }
@media (min-width: 560px) { #stage { height: 380px; } }
#stage:active { cursor: grabbing; }
.hero-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px 12px; }
.hero-name { font-size: 18px; } .hero-name span { color: var(--muted); font-size: 13px; margin-right: 4px; }
.hero-sub { color: var(--muted); font-size: 13px; }
.hero-hint { position: absolute; top: 10px; right: 14px; margin: 0; font-size: 12px; color: var(--muted); pointer-events: none; }
.hero.no3d #stage { height: 120px; background: url('/icon.svg') center / 80px no-repeat; }

/* connect bar */
.connect-row { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.connect-text { flex: 1; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--primary); animation: spin .9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.empty p { margin: 0 0 12px; color: var(--muted); }
.empty b { color: var(--text); }

/* stats grid */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat { background: var(--elevated); border-radius: var(--radius); padding: 12px 14px; min-height: 92px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; min-height: 16px; }
.stat-sub.up { color: var(--error); } .stat-sub.down { color: var(--primary); }

/* insights */
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.insights li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.insights .ico { font-size: 18px; line-height: 1.3; text-align: center; }
.insights .t { font-weight: 600; } .insights .s { color: var(--muted); font-size: 13px; }

/* charts */
.chart { display: block; width: 100%; height: 200px; touch-action: pan-y; }
#ch-hour, #ch-weekday { height: 180px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; background: var(--c, var(--primary)); }
.legend span.dash::before { background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px); }

/* hero partner */
.partner { display: flex; align-items: center; gap: 10px; }
.partner img { width: 64px; height: 64px; image-rendering: auto; filter: drop-shadow(0 4px 8px rgba(0,0,0,.5)); }
.egg { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--raised); color: var(--muted); font-weight: 700; margin: 8px; }

/* Pokédex */
.encounter { display: flex; align-items: center; gap: 12px; background: var(--raised); border-radius: 12px; padding: 10px 12px; }
.encounter img { width: 72px; height: 72px; flex: none; }
.encounter.fled img, .encounter.unknown img { filter: brightness(0) opacity(.35); }
.enc-title { font-weight: 700; }
.enc-sub { color: var(--muted); font-size: 13px; }
.enc-title .ok { color: var(--primary); } .enc-title .bad { color: var(--error); }
.recent { display: flex; gap: 6px; margin: 10px 0 4px; overflow-x: auto; padding-bottom: 2px; }
.recent .r { flex: none; width: 46px; text-align: center; font-size: 10px; color: var(--muted); }
.recent .r img { width: 40px; height: 40px; display: block; margin: 0 auto; }
.recent .r.fled img { filter: brightness(0) opacity(.3); }
.recent .r.today img { outline: 2px dashed var(--line); border-radius: 8px; }
.recent .r .m { font-weight: 600; }
.recent .r.caught .m { color: var(--primary); } .recent .r.fled .m { color: var(--error); }
.poke-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 4px; margin-top: 8px; }
.poke { position: relative; aspect-ratio: 1; border-radius: 10px; border: 2px solid transparent; background: var(--raised); padding: 2px; cursor: pointer; display: grid; place-items: center; font: inherit; color: var(--muted); }
.poke img { width: 100%; height: 100%; object-fit: contain; display: block; }
.poke.uncaught img { filter: brightness(0) opacity(.28); }
.poke .id { position: absolute; left: 4px; top: 2px; font-size: 9px; color: var(--muted); }
.poke[aria-pressed="true"] { border-color: var(--primary); }
.poke.legendary.uncaught { background: #241d2a; }
#poke-detail img { width: 40px; height: 40px; vertical-align: middle; margin-right: 6px; }
.type { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; padding: 1px 6px; border-radius: 999px; background: var(--surface); color: var(--text); margin-right: 4px; }
.rar { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.rar.rare { color: var(--tertiary); } .rar.legendary { color: var(--error); }

/* leaderboard */
.board-controls { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.board li { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--raised); }
.board li.me { outline: 2px solid var(--primary); }
.board .rank { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.board .rank.top { color: var(--tertiary); }
.board .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.board .who .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid rgba(255,255,255,.2); background: var(--muted); }
.board .who .sp { width: 28px; height: 28px; flex: none; margin: -6px 0; }
.board .who .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .who .tag { color: var(--muted); font-size: 12px; }
.board .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.board-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 0 12px; }

/* snackbar */
.snackbar { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: #f1f4f7; color: #101418; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; max-width: min(92vw, 520px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: transform .2s, opacity .2s; pointer-events: none; z-index: 20; }
.snackbar.show { transform: translate(-50%, 0); opacity: 1; }
.snackbar.err { background: var(--error); color: #2a0a06; }

/* dialogs */
.dlg { border: 1px solid var(--line); border-radius: 16px; background: var(--elevated); color: var(--text); padding: 18px; max-width: min(92vw, 420px); }
.dlg::backdrop { background: rgba(0,0,0,.55); }
.dlg label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
.dlg input { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
