:root {
  --ink: #20232a;
  --paper: #faf6ee;
  --muted: #6f6a5e;
  --red: #ee1515;
  --red-dark: #b81111;
  --card: #ffffff;
  --radius: 18px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(255, 203, 5, 0.14), transparent 32%),
    radial-gradient(circle at 90% 6%, rgba(59, 76, 202, 0.10), transparent 36%),
    var(--paper);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100dvh;
}
.wrap { width: min(78rem, calc(100% - 2.2rem)); margin: 0 auto; padding: 1.6rem 0 3.2rem; }

.top .back { color: var(--muted); text-decoration: none; font-size: 0.9rem; border: 1.5px solid rgba(32,35,42,.16); border-radius: 999px; padding: .3em .95em; transition: .15s; }
.top .back:hover { color: var(--ink); border-color: var(--ink); }
.top h1 { margin-top: .7rem; font-size: clamp(1.7rem, 1.1rem + 2.4vw, 2.6rem); font-weight: 800; letter-spacing: -.02em; }
.top h1 .en { font-size: .5em; font-weight: 700; color: var(--red); vertical-align: .18em; margin-left: .35em; letter-spacing: .06em; }
.top .lede { margin-top: .45em; color: var(--muted); font-size: .95rem; }

.controls { margin-top: 1.3rem; display: flex; flex-direction: column; gap: .8rem; }
.controls input {
  width: 100%; padding: .7em 1.1em; font-size: 1rem; font-family: inherit;
  border: 2px solid rgba(32,35,42,.14); border-radius: 999px; background: #fff; color: var(--ink);
  outline: none; transition: border-color .15s;
}
.controls input:focus { border-color: var(--red); box-shadow: 0 0 0 4px rgba(238,21,21,.12); }
.type-filter { display: flex; flex-wrap: wrap; gap: .4rem; }
.region-bar { display: flex; flex-wrap: wrap; gap: .4rem; }
.rbtn {
  font-family: inherit; font-size: .8rem; font-weight: 700; cursor: pointer;
  border: 2px solid rgba(32,35,42,.14); background: #fff; color: var(--ink);
  padding: .3em .95em; border-radius: 999px; transition: .15s;
}
.rbtn:hover { border-color: rgba(238,21,21,.5); }
.rbtn.on {
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  border-color: var(--red); color: #fff;
  box-shadow: 0 4px 12px rgba(238,21,21,.35);
}
.rbtn small { opacity: .65; font-weight: 600; margin-left: .25em; }
.tbtn {
  font-size: .78rem; font-weight: 700; border: none; cursor: pointer; font-family: inherit;
  padding: .28em .85em; border-radius: 999px; color: #fff; opacity: .45; transition: .15s;
}
.tbtn:hover { opacity: .75; transform: translateY(-1px); }
.tbtn.on { opacity: 1; box-shadow: 0 4px 12px rgba(0,0,0,.25); transform: translateY(-1px); }

.dex-grid {
  margin-top: 1.3rem;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(9.2rem, 1fr)); gap: .8rem;
}
.card {
  background: var(--card); border: 2px solid rgba(32,35,42,.08); border-radius: var(--radius);
  padding: .85rem .8rem .75rem; cursor: pointer; position: relative; overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
  text-align: center;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(32,35,42,.14); border-color: rgba(238,21,21,.35); }
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 5.5rem;
  background: linear-gradient(160deg, var(--cc, #f0f0f0), transparent 88%);
  opacity: .55; pointer-events: none;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(32,35,42,.16); border-color: var(--ca, rgba(238,21,21,.4)); }
.card .no {
  position: absolute; top: .55rem; right: .7rem; z-index: 1;
  font-size: .72rem; font-weight: 800; color: rgba(32,35,42,.42); letter-spacing: .04em;
  background: rgba(255,255,255,.65); backdrop-filter: blur(2px);
  padding: .05em .55em; border-radius: 999px;
}
.card img { width: 88px; height: 88px; object-fit: contain; margin: .2rem auto 0; display: block; position: relative; filter: drop-shadow(0 4px 6px rgba(0,0,0,.16)); transition: transform .18s ease; }
.card:hover img { transform: scale(1.08); }
.card .nm { margin-top: .3rem; font-weight: 700; font-size: .98rem; }
.card .ts { margin-top: .4rem; display: flex; justify-content: center; gap: .3rem; }
.chip { font-size: .68rem; font-weight: 700; color: #fff; border-radius: 999px; padding: .16em .7em; text-shadow: 0 1px 2px rgba(0,0,0,.25); }

.empty { margin-top: 2.4rem; text-align: center; color: var(--muted); }

/* ===== modal ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(20, 16, 10, .55); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; width: min(30rem, 100%); max-height: min(88dvh, 46rem); overflow-y: auto;
  background: #fff; border-radius: 24px; padding: 1.5rem 1.5rem 1.2rem;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.modal-x {
  position: absolute; top: .8rem; right: .9rem; z-index: 2;
  width: 2.1rem; height: 2.1rem; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(32,35,42,.08); color: var(--ink); font-size: 1.15rem; line-height: 1;
}
.modal-x:hover { background: rgba(32,35,42,.16); }

.m-head { padding-right: 2.2rem; }
.m-head .m-no {
  display: inline-block; font-size: .78rem; font-weight: 800; letter-spacing: .08em;
  color: #fff !important; background: var(--nc, var(--red));
  padding: .12em .75em; border-radius: 999px;
}
.m-head h2 { font-size: 1.7rem; font-weight: 800; letter-spacing: -.01em; margin-top: .3em; }
.m-head .m-en { color: var(--muted); font-size: .85rem; font-weight: 600; margin-left: .4em; }
.m-head .m-genus { color: var(--muted); font-size: .85rem; margin-top: .1em; }
.m-head .m-region {
  display: inline-block; margin-right: .5em; font-size: .72rem; font-weight: 700;
  color: var(--nc, var(--red)); background: rgba(32,35,42,.06);
  padding: .1em .65em; border-radius: 999px;
}
.m-types { margin-top: .55rem; display: flex; gap: .4rem; }
.m-types .chip { font-size: .74rem; padding: .2em .9em; }

.m-art {
  margin: .6rem auto 0; width: 210px; height: 210px; border-radius: 20px;
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1.5px rgba(32,35,42,.06);
}
.m-art img { width: 190px; height: 190px; object-fit: contain; filter: drop-shadow(0 10px 14px rgba(0,0,0,.22)); }
.m-sprite-row { display: flex; justify-content: center; gap: .9rem; margin-top: .4rem; }
.m-sprite-row img { width: 62px; height: 62px; object-fit: contain; image-rendering: pixelated; opacity: .9; }

.m-meta { margin-top: .9rem; display: flex; justify-content: center; gap: 2.2rem; text-align: center; }
.m-meta b { display: block; font-size: 1.02rem; }
.m-meta span { color: var(--muted); font-size: .75rem; letter-spacing: .08em; }

.m-stats { margin-top: 1rem; display: grid; gap: .42rem; }
.srow { display: grid; grid-template-columns: 4.6em 2.6em 1fr; align-items: center; gap: .6rem; font-size: .8rem; }
.srow .sn { color: var(--muted); font-weight: 600; }
.srow .sv { font-weight: 800; text-align: right; }
.sbar { height: 8px; background: rgba(32,35,42,.08); border-radius: 999px; overflow: hidden; }
.sbar i { display: block; height: 100%; border-radius: 999px; }
.srow.total { border-top: 1.5px dashed rgba(32,35,42,.18); padding-top: .5rem; margin-top: .2rem; }

.m-flavor {
  margin-top: 1rem; background: var(--paper); border-radius: 14px; padding: .85rem 1rem;
  color: #4d483d; font-size: .9rem; border: 1.5px solid rgba(32,35,42,.07);
}
.m-flavor::before { content: "图鉴"; display: inline-block; font-size: .7rem; font-weight: 800; color: #fff; background: var(--red); border-radius: 6px; padding: .1em .6em; margin-right: .55em; vertical-align: .1em; }

.m-nav { margin-top: 1.1rem; display: flex; justify-content: space-between; gap: .6rem; }
.m-nav button {
  font-family: inherit; font-size: .88rem; font-weight: 700; cursor: pointer;
  border: 2px solid rgba(32,35,42,.14); background: #fff; color: var(--ink);
  border-radius: 999px; padding: .45em 1.1em; transition: .15s;
}
.m-nav button:hover { border-color: var(--red); color: var(--red); }

@media (max-width: 560px) {
  .dex-grid { grid-template-columns: repeat(auto-fill, minmax(7.6rem, 1fr)); gap: .6rem; }
  .card img { width: 68px; height: 68px; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }

/* Subtle Pokédex modal scrollbar, without the native grey gutter. */
.modal-card {
  scrollbar-width: thin;
  scrollbar-color: rgba(205, 86, 86, .48) transparent;
  overscroll-behavior: contain;
}
.modal-card::-webkit-scrollbar { width: 6px; }
.modal-card::-webkit-scrollbar-track { background: transparent; margin: 22px 0; }
.modal-card::-webkit-scrollbar-thumb {
  background: rgba(205, 86, 86, .48);
  border-radius: 999px;
}
.modal-card::-webkit-scrollbar-thumb:hover { background: rgba(205, 86, 86, .75); }
.modal-card::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
.modal-card::-webkit-scrollbar-corner { background: transparent; }
@media (forced-colors: active) {
  .modal-card { scrollbar-color: auto; }
}

/* Keep scrolling, remove the distracting rail completely. */
.modal-card { scrollbar-width: none; -ms-overflow-style: none; }
.modal-card::-webkit-scrollbar { display: none; width: 0; height: 0; }
.m-sprite-row { align-items: start; gap: 1.2rem; }
.m-sprite-row figure { margin: 0; min-width: 76px; text-align: center; }
.m-sprite-row img {
  width: 76px; height: 76px; image-rendering: auto; object-fit: contain;
  background: rgba(32,35,42,.025); border-radius: 14px;
}
.m-sprite-row figcaption { margin-top: .2rem; font-size: .7rem; color: var(--muted); }
.m-sprite-row .image-unavailable { display: none; font-size: .7rem; color: var(--muted); padding: 1rem .3rem; }
.m-sprite-row figure.unavailable img { display: none; }
.m-sprite-row figure.unavailable .image-unavailable { display: block; }

/* Small pixel companion beside the Pokémon name. */
.m-head .m-pixel-icon {
  display: inline-block; width: 48px; height: 48px;
  object-fit: contain; image-rendering: pixelated;
  vertical-align: middle; margin: -.2rem .35rem -.1rem -.3rem;
}

.m-sprite-row figure { position: relative; padding-right: 44px; }
.m-sprite-row figure .m-form-pixel {
  display: block; position: absolute; right: 0; top: 18px;
  width: 44px; height: 44px; background: transparent; border-radius: 0;
  image-rendering: pixelated; object-fit: contain;
}
.m-sprite-row figure.unavailable .m-form-pixel { display: block; }

.m-sprite-row figure { padding-right: 0; }
.m-head .m-name-pixels { display: inline-flex; vertical-align: middle; margin-left: .4rem; gap: 6px; flex-wrap: wrap; }
.m-head .m-name-pixels img { width: 72px; height: 72px; object-fit: contain; image-rendering: pixelated; }
