:root {
  --y: #F7D02C;
  --y2: #ffe566;
  --red: #E3350D;
  --br: #C48C32;
  --ink: #2a1c0e;
  --cream: #fff8e8;
  --night: #1a140c;
  --bolt: #7BE0FF;
  --good: #7CFF6B;
  --shadow: 0 12px 40px rgba(42, 28, 14, .18);
  --font: "Nunito", system-ui, sans-serif;
  --display: "Bangers", "Fredoka", system-ui, sans-serif;
  --round: 22px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--cream);
  overflow-x: hidden;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}
img { max-width: 100%; display: block; }
button, a { font-family: inherit; touch-action: manipulation; -webkit-tap-highlight-color: rgba(247,208,44,.35); }
html[lang="zh-Hant"] {
  --font: "Noto Sans TC", "PingFang TC", "Heiti TC", sans-serif;
}
html[lang="zh-Hant"] .sec-head h2,
html[lang="zh-Hant"] .nav a,
html[lang="zh-Hant"] .tl-item h3,
html[lang="zh-Hant"] .card h3,
html[lang="zh-Hant"] .media-card h3,
html[lang="zh-Hant"] .game-card h3,
html[lang="zh-Hant"] .btn,
html[lang="zh-Hant"] .kicker,
html[lang="zh-Hant"] .lead {
  font-family: "Noto Sans TC", "PingFang TC", sans-serif;
  letter-spacing: 0;
}
html[lang="zh-Hant"] .sec-head h2 { font-weight: 900; }
html[lang="zh-Hant"] .fact { height: 200px; }
.fact-back { overflow: auto; }
.skip {
  position: absolute; left: -999px; top: 0;
}
.skip:focus { left: 12px; top: 12px; background: #fff; padding: 8px 12px; z-index: 99; }

#spark-canvas {
  position: fixed; inset: 0; pointer-events: none; z-index: 40;
}

/* ---------- Pikachu 2D animation ---------- */
.pika-host { cursor: pointer; user-select: none; display: inline-block; }
.pika-svg { width: 100%; height: auto; overflow: visible; }
.pika-bob { animation: bob 1.45s ease-in-out infinite; transform-origin: 50% 90%; }
.pika-tail { animation: wag 1.7s ease-in-out infinite; transform-origin: 118px 172px; }
.pika-side .pika-tail { transform-origin: 110px 156px; }
.ear-l { animation: ear 2.3s ease-in-out infinite; transform-origin: 70px 80px; }
.ear-r { animation: ear 2.3s ease-in-out infinite .18s; transform-origin: 150px 80px; }
.pika-side .ear-r { transform-origin: 180px 70px; }
.pika-cheek { animation: cheek 1.15s ease-in-out infinite; }
.pika-eye { transform-box: fill-box; transform-origin: 50% 50%; animation: blink 4.6s infinite; }
.arm-l, .arm-r { transform-box: fill-box; transform-origin: center; animation: arms 1.45s ease-in-out infinite; }
.spark { opacity: 0; }
.pika-svg.sparking .spark,
.pika-svg[data-state="charge"] .spark,
.pika-svg[data-state="shock"] .spark { animation: spark 0.55s ease-out; }
.pika-svg[data-state="charge"] .pika-bob { animation: shake 0.18s linear infinite; }
.pika-svg[data-state="shock"] .arm-r { animation: punch 0.35s ease-out; }
.pika-host.is-zapping { filter: drop-shadow(0 0 16px #ffe566); }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes wag {
  0%, 100% { transform: rotate(-10deg); }
  50% { transform: rotate(12deg); }
}
@keyframes ear {
  0%, 70%, 100% { transform: rotate(0); }
  80% { transform: rotate(-8deg); }
  90% { transform: rotate(6deg); }
}
@keyframes cheek {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}
@keyframes blink {
  0%, 8%, 12%, 100% { transform: scaleY(1); }
  10% { transform: scaleY(0.08); }
}
@keyframes arms {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(-8deg); }
}
@keyframes spark {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes shake {
  0%, 100% { transform: translate(0, -4px); }
  25% { transform: translate(-3px, -6px); }
  75% { transform: translate(3px, -2px); }
}
@keyframes punch {
  0% { transform: translateX(0); }
  60% { transform: translateX(18px); }
  100% { transform: translateX(8px); }
}

@media (prefers-reduced-motion: reduce) {
  .pika-bob, .pika-tail, .ear-l, .ear-r, .pika-cheek, .pika-eye, .arm-l, .arm-r {
    animation: none !important;
  }
}

/* ---------- Nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 30;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 14px 8px;
  background: rgba(26, 20, 12, .92);
  color: var(--y);
  backdrop-filter: blur(10px);
  border-bottom: 3px solid var(--y);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-size: 28px; letter-spacing: 1px;
  color: var(--y); text-decoration: none;
}
.nav-pika { width: 48px; }
.nav nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav a {
  color: #ffe9a8; text-decoration: none; padding: 8px 12px; border-radius: 999px; font-weight: 800; font-size: 14px;
  min-height: 40px; display: inline-flex; align-items: center;
}
.nav a.on, .nav a:hover { background: var(--y); color: var(--ink); }
.nav-tools { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  background: transparent; border: 0; color: var(--y); font-size: 22px; cursor: pointer;
  padding: 6px; min-width: 44px; min-height: 44px;
}
.burger { display: none; }
.lang-switch {
  display: flex; border: 2px solid var(--y); border-radius: 999px; overflow: hidden;
}
.lang-switch button {
  background: transparent; color: var(--y); border: 0; padding: 6px 11px;
  font-weight: 800; cursor: pointer; min-width: 40px; min-height: 36px;
}
.lang-switch button.on { background: var(--y); color: var(--ink); }

/* ---------- Hero ---------- */
.hero {
  position: relative; min-height: 92vh;
  display: grid; place-items: center;
  color: #fff; overflow: hidden;
  background: #1b140c url("../assets/img/forest.jpg") center/cover no-repeat;
}
.hero::before {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(100deg, transparent 40%, rgba(255,255,210,.2), transparent 60%);
  animation: sheet 5s ease-in-out infinite;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(26,20,12,.25), rgba(26,20,12,.72) 70%, var(--cream));
}
@keyframes sheet {
  0%, 70%, 100% { opacity: 0; }
  74% { opacity: 1; }
  78% { opacity: .15; }
  82% { opacity: .8; }
  88% { opacity: 0; }
}
.hero-inner {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 24px;
  width: min(1120px, calc(100% - 32px));
  align-items: center; padding: 40px 0 80px;
}
.kicker {
  display: inline-block; background: var(--y); color: var(--ink);
  font-weight: 800; padding: 4px 12px; border-radius: 999px; letter-spacing: .08em;
}
.hero h1 {
  font-family: var(--display); font-size: clamp(64px, 12vw, 140px);
  margin: 8px 0 0; line-height: .9; color: var(--y);
  text-shadow: 4px 4px 0 var(--ink), 0 0 28px rgba(247,208,44,.6);
  letter-spacing: 2px;
}
.hero p.lead { font-size: 20px; max-width: 40ch; color: #fff6d4; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.hero-pika-wrap { position: relative; justify-self: center; width: min(420px, 80vw); }
.hero-pika-wrap::after {
  content: attr(data-hint);
  display: block; text-align: center; font-weight: 800; color: var(--y);
  text-shadow: 0 2px 0 #000;
}
#hero-pika { width: 100%; filter: drop-shadow(0 18px 0 rgba(0,0,0,.18)); }
.speech {
  position: absolute; right: 8%; top: 6%;
  background: #fff; color: var(--ink); padding: 10px 16px; border-radius: 18px 18px 18px 4px;
  font-weight: 800; opacity: 0; transform: scale(.6);
  box-shadow: var(--shadow);
}
.speech.pop { animation: pop 0.9s ease; }
@keyframes pop {
  0% { opacity: 0; transform: scale(.5) translateY(8px); }
  25% { opacity: 1; transform: scale(1.08); }
  70% { opacity: 1; }
  100% { opacity: 0; }
}
.dex-chip {
  display: flex; gap: 16px; margin-top: 22px; flex-wrap: wrap;
}
.dex-chip span {
  background: rgba(255,248,232,.15); border: 2px solid var(--y);
  padding: 8px 14px; border-radius: 14px; font-weight: 800;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--y); color: var(--ink); border: 3px solid var(--ink);
  padding: 12px 20px; border-radius: 999px; font-weight: 800; cursor: pointer;
  text-decoration: none; box-shadow: 0 4px 0 var(--ink); transition: transform .12s, box-shadow .12s;
  min-height: 48px;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-ghost { background: transparent; color: var(--y); border-color: var(--y); box-shadow: 0 4px 0 #8a7010; }
.btn-charge { background: var(--bolt); min-width: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.btn-shock { background: var(--red); color: #fff; min-width: 0; }
.btn-start { grid-column: 1 / -1; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn[hidden] { display: none !important; }

/* ---------- Layout ---------- */
main section { padding: 72px 0; }
#history { background: linear-gradient(180deg, var(--cream), #ffe9a8 45%, var(--cream)); }
#abilities { background: #fff3c4; }
#media { background: #1a140c; color: #fff8e8; }
#media .sec-head h2, #media .sec-head p { color: var(--y); }
#games { background: linear-gradient(180deg, #fff8e8, #fff3c4); }
#facts {
  background:
    linear-gradient(rgba(255,248,232,.9), rgba(255,248,232,.92)),
    url("../assets/img/facts.jpg") center/cover;
}
.wrap { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.sec-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.sec-head h2 {
  font-family: var(--display); font-size: clamp(36px, 6vw, 56px); margin: 0; letter-spacing: 1px;
  color: var(--ink);
}
.sec-head p { margin: 0; max-width: 46ch; color: #5c4630; }
.reveal { opacity: 0; transform: translateY(18px); transition: .6s ease; }
.reveal.in { opacity: 1; transform: none; }

.split { display: grid; grid-template-columns: 1.05fr .95fr; gap: 28px; align-items: stretch; }
.panel {
  background: #fff; border: 3px solid var(--ink); border-radius: var(--round);
  overflow: hidden; box-shadow: var(--shadow);
}
.panel img { width: 100%; height: 280px; object-fit: cover; }
.panel .pad { padding: 22px; }
.muted { color: #6b5438; }

/* ---------- Timeline ---------- */
.timeline { position: relative; display: grid; gap: 14px; }
.timeline::before {
  content: ""; position: absolute; left: 18px; top: 8px; bottom: 8px; width: 4px;
  background: linear-gradient(var(--y), var(--red)); border-radius: 4px;
}
.tl-item {
  position: relative;
  margin-left: 44px; background: #fff; border: 3px solid var(--ink); border-radius: 18px;
  padding: 14px 18px; cursor: pointer; box-shadow: 3px 4px 0 var(--ink);
}
.tl-item::before {
  content: "⚡"; position: absolute; left: -40px; top: 12px; width: 26px; text-align: center;
}
.tl-item h3 { margin: 0 0 4px; font-size: 18px; }
.tl-item .year { font-family: var(--display); color: var(--red); margin-right: 8px; }
.tl-item p { display: none; margin: 8px 0 0; color: #5c4630; }
.tl-item.open p { display: block; }
.tl-item.open { background: #fff6c8; }

/* ---------- Abilities ---------- */
.ability-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card {
  background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 18px;
  box-shadow: 3px 4px 0 var(--ink);
}
.card h3 { margin: 0 0 8px; }
.moves { display: flex; flex-wrap: wrap; gap: 8px; }
.move {
  border: 2px solid var(--ink); background: var(--y); border-radius: 999px;
  padding: 6px 12px; font-weight: 800; cursor: pointer; position: relative;
}
.move.zap { animation: shake .2s linear 2; background: var(--bolt); }
.stats { display: grid; gap: 8px; }
.stat { display: grid; grid-template-columns: 90px 36px 1fr; align-items: center; gap: 8px; font-weight: 700; opacity: 0; }
.stat.in { opacity: 1; }
.stat i {
  display: block; height: 10px; border-radius: 99px; background: #ead9b0; position: relative; overflow: hidden;
}
.stat i::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 0;
  background: linear-gradient(90deg, var(--y), var(--red));
  border-radius: inherit;
}
.stat.in i::after { width: calc(var(--v) * 1%); animation: fill .8s ease forwards; }
@keyframes fill { from { width: 0; } to { width: calc(var(--v) * 1%); } }

.evo {
  background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 18px; margin-top: 18px;
}
.evo-track { display: flex; align-items: center; gap: 8px; }
#evo-range { flex: 1; accent-color: var(--red); }
.evo-stage {
  height: 160px; display: grid; place-items: center; position: relative;
}
.evo-critter { width: 140px; height: 140px; position: relative; }
.evo-critter::before, .evo-critter::after {
  content: ""; position: absolute; inset: 18px 28px 28px; border-radius: 50% 50% 45% 45%;
  background: var(--y); border: 3px solid var(--ink);
}
.evo-critter::after {
  inset: auto 48px 18px; height: 28px; border-radius: 40%; background: var(--br);
}
#evo-stage[data-stage="0"] .evo-critter { transform: scale(.7); }
#evo-stage[data-stage="0"] .evo-critter::before { background: #ffe566; }
#evo-stage[data-stage="2"] .evo-critter::before { background: #e09030; border-radius: 46% 46% 40% 40%; }
#evo-label { color: #5c4630; }

.feature-row { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; margin-top: 18px; }
.energy-shot { border-radius: 18px; overflow: hidden; border: 3px solid var(--ink); min-height: 220px; }
.energy-shot img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Media / games ---------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs button {
  background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 8px 14px;
  font-weight: 800; cursor: pointer;
}
.tabs button.on { background: var(--y); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.media-card, .game-card {
  background: #fff; border: 3px solid var(--ink); border-radius: 18px; overflow: hidden;
  box-shadow: 3px 4px 0 var(--ink);
}
.media-card .thumb, .game-card .thumb {
  height: 140px; background: #1a140c center/cover no-repeat; position: relative;
}
.media-card .body, .game-card .body { padding: 14px; }
.tag { display: inline-block; background: var(--y); color: var(--ink); font-weight: 800; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.media-card, .game-card, .card, .panel { color: var(--ink); }
.media-card h3, .game-card h3 { margin: 8px 0; }
.media-card p, .game-card p, .card p { color: #5c4630; }
#media .tabs button { color: var(--ink); }
[data-panel] { display: none; }
[data-panel].on { display: block; }

/* ---------- Facts ---------- */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.fact {
  height: 180px; perspective: 800px; cursor: pointer;
}
.fact-inner {
  position: relative; height: 100%; transform-style: preserve-3d; transition: transform .5s;
  border: 3px solid var(--ink); border-radius: 18px;
}
.fact.flipped .fact-inner { transform: rotateY(180deg); }
.fact-front, .fact-back {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 15px;
  padding: 16px; display: grid; place-items: center; text-align: center; font-weight: 800;
}
.fact-front { background: var(--y); }
.fact-back { background: #fff; transform: rotateY(180deg); font-weight: 600; color: #5c4630; }

.quiz { background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 18px; margin-top: 22px; }
.quiz-a { display: grid; gap: 8px; }
.quiz-a button, .quiz-done + .btn {
  background: var(--cream); border: 2px solid var(--ink); border-radius: 12px; padding: 10px; font-weight: 700; cursor: pointer; text-align: left;
}
.quiz-a button.ok { background: var(--good); }
.quiz-a button.no { background: #ffb3a8; }

/* ---------- Game ---------- */
.game-sec { background: #14110e; color: #fff8e8; }
.game-sec .sec-head h2, .game-sec .sec-head p { color: var(--y); }
.game-shell { display: grid; gap: 12px; }
.game-hud {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.game-hud > div {
  background: #0e0c0a; border: 2px solid var(--y); border-radius: 12px; padding: 10px 12px;
}
.hud-label { display: block; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #c9b27a; }
.game-stage {
  position: relative; border: 3px solid var(--y); border-radius: 18px; overflow: hidden; min-height: 340px;
}
.game-bg { width: 100%; height: 380px; object-fit: cover; }
.game-pika {
  position: absolute; left: 4%; bottom: 2%; width: 210px;
  filter: drop-shadow(0 8px 0 rgba(0,0,0,.25));
}
.game-bolt { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.game-banner {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%) scale(.8);
  font-family: var(--display); font-size: 42px; letter-spacing: 2px;
  opacity: 0; pointer-events: none; text-shadow: 3px 3px 0 #000;
}
.game-banner.show { animation: pop .9s ease; }
.game-banner.good { color: var(--good); }
.game-banner.bad { color: #ff6b4a; }
.game-console {
  background: #0e0c0a; border: 3px solid var(--y); border-radius: 18px; padding: 14px;
}
.ecg-wrap { background: #08140f; border-radius: 12px; overflow: hidden; }
#g-ecg, .game-console canvas { width: 100%; display: block; }
.ecg-meta { display: flex; justify-content: space-between; padding: 6px 10px; font-weight: 800; color: var(--good); font-size: 13px; }
.charge-wrap { margin: 12px 0; }
.charge-bar {
  height: 18px; background: #2a2218; border-radius: 99px; overflow: hidden; position: relative; border: 2px solid #5a4a30;
}
.charge-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffe566, #7CFF6B); }
.charge-bar i.over { background: var(--red); }
.charge-bar .sweet {
  position: absolute; left: 72%; right: 3%; top: 0; bottom: 0;
  border-left: 2px dashed rgba(255,255,255,.5); border-right: 2px dashed rgba(255,255,255,.5);
}
.game-status { margin: 8px 0 12px; color: #f0e2c0; min-height: 44px; }
.game-btns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.game-btns .btn { width: 100%; }
.charge-bar { touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; min-height: 22px; }
.game-disclaimer { font-size: 12px; color: #b9a888; }
.film-list { margin-top: 18px; color: #c9b27a; font-size: 14px; line-height: 1.55; }
#evo-range { min-height: 44px; }

/* ---------- Footer ---------- */
footer {
  background: var(--night); color: #f3e4c0; padding: 36px 0 24px; text-align: center;
}
footer a { color: var(--y); }

.float-pika {
  position: fixed; right: 12px; bottom: 12px; width: 92px; z-index: 20;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.2));
}

.lightning-bg {
  position: absolute; inset: 0; pointer-events: none; opacity: .35;
  background-image: url("../assets/img/facts.jpg");
  background-size: cover;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .hero-inner, .split, .ability-grid, .grid-3, .facts, .feature-row {
    grid-template-columns: 1fr;
  }
  .nav {
    grid-template-columns: 1fr auto;
    position: sticky;
  }
  .nav nav {
    display: none; grid-column: 1 / -1;
    background: #1a140c; flex-direction: column; padding: 8px 0 12px;
  }
  .nav.open nav { display: flex; }
  .burger { display: grid; place-items: center; }
  .game-hud { grid-template-columns: 1fr 1fr; }
  .game-pika { width: 28vw; max-width: 140px; }
  .hero { min-height: auto; }
  .hero h1 { font-size: clamp(52px, 18vw, 96px); }
  .hero-inner { padding: 24px 0 48px; gap: 8px; }
  .hero-actions { flex-direction: column; }
  .hero-actions .btn { width: 100%; }
  .float-pika { display: none; }
  .game-bg { height: 42vw; min-height: 160px; max-height: 220px; }
  .game-stage { min-height: 0; }
  .game-banner { font-size: 28px; top: 12%; }
  main section { padding: 48px 0; }
  .wrap { width: min(1120px, calc(100% - 20px)); }
  .game-btns {
    position: sticky;
    bottom: 0;
    z-index: 16;
    background: linear-gradient(180deg, transparent, #14110e 18px);
    padding: 14px 0 calc(12px + var(--safe-b));
  }
  .btn-charge, .btn-shock, .btn-start { min-height: 56px; font-size: 17px; }
  .tabs button { min-height: 44px; }
  .quiz-a button { min-height: 48px; font-size: 16px; }
  .fact { height: 160px; }
  .tl-item { margin-left: 36px; padding: 12px; }
  .panel img { height: 200px; }
}

@media (max-width: 520px) {
  .brand { font-size: 22px; }
  .nav-pika { width: 36px; }
  .dex-chip span { font-size: 13px; }
  .game-hud > div { padding: 8px; }
  .sec-head h2 { font-size: 32px; }
}
