@font-face {
  font-family: 'Pixelify';
  src: url('pokemon/pixelify.ttf') format('truetype');
}

/* ── Root palette: Forest After Dark ── */
:root {
  --bg:      #0e1815;
  --surface: #172620;
  --raised:  #22362e;
  --line:    #3e594b;
  --accent:  #a7c99a;
  --action:  #d1b47b;
  --text:    #f0efe3;
  --muted:   #b0bead;
  --ink:     #101722;

  /* Legacy aliases for compatibility */
  --panel:   var(--surface);
  --dim:     var(--muted);
  --yel:     var(--action);
  --grn:     #5dff8f;
  --red:     #f87171;
  --gold:    var(--action);
  --cyan:    #a7c99a;
  --org:     #d1b47b;
  --pur:     #a77bff;
  --pink:    #ff4f8b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Pixelify', "Microsoft YaHei", "Malgun Gothic", "Noto Sans CJK", sans-serif;
  font-size: 17px;
  min-height: 100vh;
  overflow-x: clip;
}

.px {
  font-family: 'Pixelify', "Microsoft YaHei", "Malgun Gothic", monospace;
}

/* ── Navigation ── */
nav {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 16px 32px;
  border-bottom: 3px solid var(--line);
  background: var(--bg);
  flex-wrap: wrap;
}

nav .logo {
  font-family: 'Pixelify', monospace;
  font-size: 20px;
  color: var(--text);
  letter-spacing: 1px;
  text-decoration: none;
  cursor: pointer;
}

nav .logo span {
  color: var(--accent);
}

nav a {
  font-family: 'Pixelify', monospace;
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

nav a.on {
  background: var(--raised);
  color: var(--accent);
  box-shadow: inset 0 -3px 0 var(--accent);
  padding: 6px 10px;
}

nav a:hover {
  color: var(--text);
}

.nav-wallet {
  margin-left: auto;
  font-family: 'Pixelify', monospace;
  font-size: 10px;
  background: var(--raised);
  border: 2px solid var(--line);
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.nav-wallet .rank {
  color: var(--action);
}

.nav-wallet .pts {
  color: var(--action);
}

/* ── Shared components ── */
.panel {
  background: var(--surface);
  border: 3px solid var(--line);
  box-shadow: 4px 4px 0 #0004;
  padding: 20px;
}

.h {
  font-family: 'Pixelify', monospace;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 14px;
}

.btn {
  display: inline-block;
  font-family: 'Pixelify', monospace;
  font-size: 13px;
  background: var(--action);
  color: var(--ink);
  padding: 16px 22px;
  border: none;
  box-shadow: 3px 3px 0 #0004;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:disabled,
.btn.disabled {
  filter: grayscale(.6) brightness(.75);
  cursor: not-allowed;
  pointer-events: none;
}

.bar {
  height: 12px;
  background: var(--bg);
  border: 2px solid var(--line);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  transition: width .4s ease;
}

.tag {
  display: inline-block;
  font-family: 'Pixelify', monospace;
  font-size: 9px;
  padding: 5px 8px;
  border: 2px solid currentColor;
  margin-right: 6px;
}

/* ── Frame / window components ── */
.frame {
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: 4px 4px 0 #0004;
}

.windowbar {
  background: var(--raised);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 12px;
}

/* ── Sprite rendering ── */
canvas.sprite {
  image-rendering: pixelated;
}

.poke-sprite {
  image-rendering: pixelated;
  display: block;
}

.poke-sprite.card-sprite {
  width: 96px;
  height: 96px;
  margin: 0 auto 8px;
  object-fit: contain;
}

@media (prefers-reduced-motion: reduce) {
  img.poke-sprite[src$=".gif"] {
    content: attr(data-static) url("");
  }
}

/* ── Type colors — 18 Pokemon types + legacy ── */
.fire     { color: #f08030 }
.water    { color: #6890f0 }
.grass    { color: #78c850 }
.electric { color: #f8d030 }
.ice      { color: #98d8d8 }
.fighting { color: #c03028 }
.poison   { color: #a040a0 }
.ground   { color: #e0c068 }
.flying   { color: #a890f0 }
.psychic  { color: #f85888 }
.bug      { color: #a8b820 }
.rock     { color: #b8a038 }
.ghost    { color: #705898 }
.dragon   { color: #7038f8 }
.dark     { color: #705848 }
.steel    { color: #b8b8d0 }
.fairy    { color: #ee99ac }
.normal   { color: #a8a878 }

/* Legacy type aliases */
.volt   { color: var(--action) }
.shadow { color: var(--pur) }
.stone  { color: #a8a29e }

/* ── Type badge backgrounds ── */
.type-badge {
  display: inline-block;
  font-family: 'Pixelify', monospace;
  font-size: 8px;
  padding: 4px 7px;
  border-radius: 3px;
  color: #fff;
  margin-right: 4px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .4);
}

.type-badge.fire     { background: #f08030 }
.type-badge.water    { background: #6890f0 }
.type-badge.grass    { background: #78c850 }
.type-badge.electric { background: #f8d030; color: #333 }
.type-badge.ice      { background: #98d8d8; color: #333 }
.type-badge.fighting { background: #c03028 }
.type-badge.poison   { background: #a040a0 }
.type-badge.ground   { background: #e0c068; color: #333 }
.type-badge.flying   { background: #a890f0 }
.type-badge.psychic  { background: #f85888 }
.type-badge.bug      { background: #a8b820; color: #333 }
.type-badge.rock     { background: #b8a038 }
.type-badge.ghost    { background: #705898 }
.type-badge.dragon   { background: #7038f8 }
.type-badge.dark     { background: #705848 }
.type-badge.steel    { background: #b8b8d0; color: #333 }
.type-badge.fairy    { background: #ee99ac; color: #333 }
.type-badge.normal   { background: #a8a878; color: #333 }

/* ── Animations ── */
@keyframes hitFlash {
  0%, 100% { filter: none }
  50%       { filter: brightness(3) saturate(0) }
}

@keyframes shake {
  0%, 100% { transform: translateX(0) }
  20%      { transform: translateX(-8px) }
  40%      { transform: translateX(8px) }
  60%      { transform: translateX(-6px) }
  80%      { transform: translateX(4px) }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(20px) }
}

@keyframes cardFlip {
  0%   { transform: rotateY(180deg) scale(.8) }
  100% { transform: rotateY(0) scale(1) }
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 10px var(--glow) }
  50%       { box-shadow: 0 0 30px var(--glow), 0 0 60px var(--glow) }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px) }
  to   { opacity: 1; transform: none }
}

@keyframes packTear {
  0%   { clip-path: inset(0) }
  50%  { clip-path: inset(0 0 50% 0) }
  100% { clip-path: inset(0 0 100% 0) }
}

@keyframes shineSwipe {
  0%   { left: -100% }
  100% { left: 200% }
}

.hit-flash { animation: hitFlash .15s ease }
.shake     { animation: shake .3s ease }
.faint     { animation: fadeOut .6s ease forwards }
.slide-up  { animation: slideUp .4s ease both }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 3px solid var(--accent);
  box-shadow: 0 0 40px rgba(167, 201, 154, .2);
  padding: 32px;
  max-width: 500px;
  width: 90%;
  text-align: center;
}

.modal .modal-title {
  font-family: 'Pixelify', monospace;
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 16px;
}

/* ── Practice banner ── */
.practice-banner {
  position: sticky;
  top: 0;
  z-index: 2000;
  width: 100%;
  background: var(--raised);
  border-bottom: 3px solid var(--action);
  padding: 10px 16px;
  text-align: center;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  overflow-wrap: anywhere;
}
.practice-banner strong { color: var(--action); }

/* ── Pearl button (packs) ── */
.pearl-btn {
  height: 76px;
  border-radius: 40px;
  border: 3px solid var(--line);
  background: linear-gradient(
    90deg,
    var(--raised) 0%,
    #2e4a3a 30%,
    var(--surface) 55%,
    #1e3028 78%,
    var(--raised) 100%
  );
  box-shadow: inset 0 6px 10px rgba(167, 201, 154, .08),
              inset 0 -6px 12px #0002,
              0 0 20px rgba(167, 201, 154, .06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 28px;
  font-weight: 900;
  cursor: pointer;
  width: 100%;
}

.pearl-btn:hover {
  filter: brightness(1.1);
}

.pearl-btn.lock {
  filter: grayscale(.6) brightness(.75);
  cursor: not-allowed;
}

/* ── Footer ── */
.foot {
  text-align: right;
  padding: 10px 24px;
  font-size: 16px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ── Sub-tabs (packs / real / collection) ── */
.sub-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.sub-tabs a {
  font-weight: 700;
  font-size: 18px;
  padding: 10px 18px;
  border-radius: 22px;
  color: var(--muted);
  border: 1px solid var(--line);
  text-decoration: none;
  cursor: pointer;
}

.sub-tabs a.on {
  color: var(--ink);
  background: var(--action);
  border-color: var(--action);
}

/* ── Card collection styles ── */
.face {
  background: var(--raised);
  border-color: var(--line);
  box-shadow: 4px 4px 0 #0006;
}

.card.holo .front {
  background: linear-gradient(
    135deg,
    var(--raised),
    var(--line),
    var(--raised)
  );
}

.cardname,
.carddata {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.back {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
}

.back .sigil {
  background: var(--action);
  color: var(--ink);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  nav {
    padding: 12px 16px;
    gap: 12px;
  }

  nav .logo {
    font-size: 14px;
  }

  nav a {
    font-size: 8px;
  }

  .nav-wallet {
    font-size: 8px;
    padding: 8px 10px;
  }

  .panel {
    padding: 14px;
  }

  body {
    font-size: 17px;
  }

  .sub-tabs {
    padding: 8px 16px;
  }

  .sub-tabs a {
    font-size: 14px;
    padding: 8px 12px;
  }
}

@media (max-width: 480px) {
  nav {
    padding: 10px 12px;
    gap: 6px;
  }

  nav a {
    font-size: 7px;
    padding-bottom: 3px;
  }

  nav a.on {
    padding-bottom: 3px;
  }

  .nav-wallet {
    margin-left: 0;
    width: 100%;
    text-align: center;
    font-size: 7px;
  }

  .h {
    font-size: 10px;
  }

  .btn {
    font-size: 10px;
    padding: 12px 14px;
  }

  .pearl-btn {
    height: 56px;
    font-size: 20px;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
