:root {
  --bg: #0b0d12;
  --bg-elevated: #12151c;
  --bg-card: #171b24;
  --bg-hover: #1e2430;
  --border: #2a3140;
  --text: #e8ecf4;
  --text-muted: #9aa3b5;
  --accent: #6ea8ff;
  --accent-2: #8b9cff;
  --crystal: #56c7ff;
  --sidebar-w: 260px;
  --topbar-h: 56px;
  --radius: 12px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef2f8;
  --border: #d5dbe8;
  --text: #151922;
  --text-muted: #5b657a;
  --accent: #2f6fed;
  --accent-2: #4b5fd6;
  --crystal: #0a7ea4;
  --shadow: 0 8px 24px rgba(30, 40, 70, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  z-index: 20;
}
.sidebar.collapsed { display: none; }

.brand {
  padding: 1rem 1rem 0.75rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.5rem;
}
.brand-link { display: flex; gap: 0.75rem; align-items: center; color: inherit; text-decoration: none; flex: 1; min-width: 0; }
.sidebar-close { display: none; flex-shrink: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2a4a7a, #163054);
  color: #dff4ff; font-weight: 700; letter-spacing: 0.02em;
  border: 1px solid #3d6aa0;
}
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 1.05rem; }
.brand-text small { color: var(--text-muted); font-size: 0.75rem; }

.nav { padding: 0.75rem 0.65rem 2rem; }
.nav-group { margin-bottom: 1.1rem; }
.nav-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); padding: 0.25rem 0.6rem; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.65rem; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 0.92rem;
}
.nav-item:hover { background: var(--bg-hover); text-decoration: none; }
.nav-item.active { background: var(--bg-hover); color: var(--crystal); font-weight: 600; }
.nav-item.active-game { background: rgba(86, 199, 255, 0.08); color: var(--crystal); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--crystal); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 15;
}
.icon-btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.menu-btn {
  width: auto; min-width: 44px; min-height: 44px; padding: 0 0.65rem;
  gap: 0.45rem; font-weight: 600; font-size: 0.85rem; z-index: 40;
  position: relative;
}
.menu-btn-bars {
  width: 18px; height: 12px; position: relative; display: block; flex-shrink: 0;
}
.menu-btn-bars::before,
.menu-btn-bars::after {
  content: "";
  position: absolute; left: 0; right: 0; height: 2px;
  background: currentColor; border-radius: 1px;
}
.menu-btn-bars::before { top: 0; box-shadow: 0 5px 0 currentColor; }
.menu-btn-bars::after { bottom: 0; }
.menu-btn-label { line-height: 1; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 25;
  background: rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
}
.game-chip {
  font-size: 0.8rem; color: var(--text-muted); white-space: nowrap;
}
.game-chip strong { color: var(--text); }
.search-wrap { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search-wrap input {
  width: 100%; height: 36px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  padding: 0 1rem;
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); max-height: 360px; overflow: auto; z-index: 30;
}
.search-hit {
  display: flex; gap: 0.65rem; align-items: center;
  padding: 0.55rem 0.75rem; color: inherit; text-decoration: none; border-bottom: 1px solid var(--border);
}
.search-hit:hover { background: var(--bg-hover); text-decoration: none; }
.search-hit .kind { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; width: 64px; }
.search-hit img { width: 28px; height: 28px; image-rendering: pixelated; }

.content { flex: 1; padding: 1.25rem 1.5rem 3rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.loading, .empty { color: var(--text-muted); padding: 2rem 0; }

.hero {
  padding: 1.5rem 0 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.hero h1 { margin: 0 0 0.4rem; font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -0.02em; }
.hero p { margin: 0; color: var(--text-muted); max-width: 50rem; }
.hero-banner {
  height: 72px; border-radius: var(--radius); margin-bottom: 1rem;
  background:
    linear-gradient(90deg, rgba(22,48,84,0.95), rgba(40,70,120,0.4)),
    repeating-linear-gradient(90deg, #1a3048 0 12px, #16304a 12px 24px);
  border: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1.25rem;
  color: #cfe9ff; font-weight: 600;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  color: inherit; text-decoration: none;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; background: var(--bg-hover); }
.card h3 { margin: 0 0 0.35rem; font-size: 1rem; }
.card p { margin: 0; color: var(--text-muted); font-size: 0.88rem; }
.stat-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }
.stat-pill {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.35rem 0.75rem; font-size: 0.85rem;
}
.stat-pill strong { color: var(--crystal); }

.toolbar {
  display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center;
  margin-bottom: 1rem;
}
.toolbar input, .toolbar select {
  height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text); padding: 0 0.75rem;
}
.toolbar input { min-width: min(100%, 280px); flex: 1; }
.count { color: var(--text-muted); font-size: 0.85rem; margin-left: auto; }

.poke-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}
.poke-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.85rem; text-align: center;
  color: inherit; text-decoration: none;
}
.poke-card:hover { border-color: var(--accent); text-decoration: none; background: var(--bg-hover); }
.poke-card img {
  width: 72px; height: 72px; image-rendering: pixelated; object-fit: contain;
}
.poke-card .num { color: var(--text-muted); font-family: var(--mono); font-size: 0.75rem; }
.poke-card .name { font-weight: 600; margin: 0.25rem 0 0.45rem; }

.type {
  display: inline-block; min-width: 4.2rem; text-align: center;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; border-radius: 999px; padding: 0.18rem 0.5rem;
  color: #fff; margin: 0 0.12rem;
}
.type.Normal { background: #a8a878; } .type.Fire { background: #f08030; }
.type.Water { background: #6890f0; } .type.Electric { background: #f8d030; color: #333; }
.type.Grass { background: #78c850; } .type.Ice { background: #98d8d8; color: #333; }
.type.Fighting { background: #c03028; } .type.Poison { background: #a040a0; }
.type.Ground { background: #e0c068; color: #333; } .type.Flying { background: #a890f0; }
.type.Psychic { background: #f85888; } .type.Bug { background: #a8b820; }
.type.Rock { background: #b8a038; } .type.Ghost { background: #705898; }
.type.Dragon { background: #7038f8; } .type.Dark { background: #705848; }
.type.Steel { background: #b8b8d0; color: #333; } .type.Fairy { background: #ee99ac; color: #333; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.data {
  width: 100%; border-collapse: collapse; font-size: 0.9rem; background: var(--bg-card);
}
table.data th, table.data td {
  padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); text-align: left;
}
table.data th { background: var(--bg-elevated); color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; position: sticky; top: 0; }
table.data tr:hover td { background: var(--bg-hover); }
table.data a { color: inherit; font-weight: 600; }

.detail-header {
  display: grid; grid-template-columns: 120px 1fr; gap: 1.25rem; align-items: start;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem; margin-bottom: 1rem;
}
.detail-header img { width: 112px; height: 112px; image-rendering: pixelated; }
.detail-sprite {
  display: flex; flex-direction: column; align-items: center; gap: 0.65rem;
}
.detail-header h1 { margin: 0 0 0.35rem; }

.shiny-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  height: 36px; padding: 0 0.85rem;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text);
  font: inherit; font-size: 0.82rem; font-weight: 700;
  letter-spacing: 0.03em; cursor: pointer;
  white-space: nowrap;
}
.shiny-btn:hover { border-color: var(--accent); }
.shiny-btn-star { color: #c9a227; font-size: 0.95rem; line-height: 1; }
.shiny-btn.is-on {
  border-color: #c9a227;
  background: linear-gradient(135deg, rgba(201,162,39,0.25), rgba(126,200,227,0.2));
  box-shadow: 0 0 0 1px rgba(201,162,39,0.35);
}
.shiny-btn.is-on .shiny-btn-star { color: #ffe08a; }
.bars { display: grid; gap: 0.4rem; margin-top: 0.75rem; }
.bar-row { display: grid; grid-template-columns: 72px 36px 1fr; gap: 0.5rem; align-items: center; font-size: 0.85rem; }
.bar {
  height: 8px; border-radius: 999px; background: var(--border); overflow: hidden;
}
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--crystal)); }

.type-chart { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.type-chart table { border-collapse: collapse; font-size: 0.72rem; }
.type-chart th, .type-chart td {
  width: 34px; height: 34px; text-align: center; border: 1px solid var(--border);
}
.type-chart .m2 { background: #2f6b3a; color: #fff; font-weight: 700; }
.type-chart .m05 { background: #6b3a2f; color: #fff; }
.type-chart .m0 { background: #333; color: #aaa; }
.type-chart .m1 { color: var(--text-muted); }

.section { margin: 1.5rem 0; }
.section h2 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.section h3 {
  margin: 1.15rem 0 0.4rem; font-size: 0.95rem;
  color: var(--crystal); font-weight: 600;
}
.section p { margin: 0 0 0.75rem; max-width: 46rem; }
.section p:last-child { margin-bottom: 0; }
.section ul, .section ol {
  margin: 0 0 0.85rem; padding-left: 1.2rem; max-width: 46rem;
  color: var(--text);
}
.section li { margin: 0.35rem 0; }
.section li::marker { color: var(--text-muted); }
.about-lead {
  font-size: 1.05rem; color: var(--text); max-width: 40rem; line-height: 1.55;
}
.about-meta {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem;
}
.about-meta span {
  font-size: 0.78rem; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 0.28rem 0.7rem; background: var(--bg-elevated);
}
.feature-list {
  display: grid; gap: 0.65rem; margin: 0.85rem 0 0;
}
.feature-list article {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.85rem 1rem;
}
.feature-list h3 { margin: 0 0 0.3rem; font-size: 0.95rem; color: var(--text); }
.feature-list p { margin: 0; color: var(--text-muted); font-size: 0.9rem; max-width: none; }
.feature-list a { font-weight: 600; }
.steps {
  counter-reset: step; list-style: none; padding-left: 0; max-width: 40rem;
}
.steps li {
  counter-increment: step; position: relative;
  padding: 0.55rem 0 0.55rem 2.4rem;
  border-bottom: 1px solid var(--border);
}
.steps li:last-child { border-bottom: none; }
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0.55rem;
  width: 1.6rem; height: 1.6rem; border-radius: 8px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--crystal); font-size: 0.75rem; font-weight: 700;
  display: grid; place-items: center; font-family: var(--mono);
}
.muted { color: var(--text-muted); }
.footer {
  border-top: 1px solid var(--border); padding: 1rem 1.5rem; color: var(--text-muted); font-size: 0.82rem;
}
.footer a { color: var(--accent); }

.guide-figure {
  margin: 1rem 0 1.25rem;
  max-width: 46rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.guide-figure img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
  background: #0a0c10;
}
.guide-figure figcaption {
  padding: 0.55rem 0.85rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.toc-list {
  display: grid;
  gap: 0.35rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  max-width: 40rem;
}
.toc-list a {
  display: block;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: inherit;
  text-decoration: none;
  font-size: 0.92rem;
}
.toc-list a:hover { border-color: var(--accent); background: var(--bg-hover); text-decoration: none; }
.badge-row {
  display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0.85rem;
}
.badge-pill {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; border-radius: 999px;
  padding: 0.22rem 0.65rem; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--crystal);
}
.chapter {
  margin: 1.75rem 0;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}
.chapter:first-of-type { border-top: none; padding-top: 0; }
.chapter > h2 { scroll-margin-top: 4.5rem; }
.note-box {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-left: 3px solid var(--crystal); border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.85rem 1rem; margin: 0.85rem 0; max-width: 46rem;
  font-size: 0.9rem; color: var(--text-muted);
}
.note-box strong { color: var(--text); }
.code-block {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.85rem 1rem; overflow: auto;
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.5;
  color: var(--text-muted); max-width: 46rem;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    z-index: 60;
    /* Solid panel — PWA/WebKit was showing content through the drawer */
    background: #12151c;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.45);
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    pointer-events: auto;
  }
  [data-theme="light"] .sidebar {
    background: #ffffff;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .sidebar-backdrop {
    display: block;
    z-index: 55;
    background: rgba(0, 0, 0, 0.55);
  }
  .sidebar-backdrop[hidden] { display: none !important; }
  /* Do NOT raise main-wrap above the drawer — that made the menu untouchable */
  .main-wrap {
    position: relative;
    z-index: 1;
  }
  .topbar {
    z-index: 40;
    padding-top: max(0.35rem, env(safe-area-inset-top, 0));
    height: auto;
    min-height: var(--topbar-h);
    position: sticky;
    background: var(--bg-elevated);
    backdrop-filter: none;
  }
  .menu-btn {
    background: var(--crystal);
    color: #061018;
    border-color: transparent;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  }
  body.drawer-open .menu-btn {
    /* Keep Menu tappable above the open drawer */
    position: relative;
    z-index: 70;
  }
  .game-chip { display: none; }
  body.drawer-open {
    overflow: hidden;
  }
  body.drawer-open .main-wrap {
    pointer-events: none;
  }
  body.drawer-open .menu-btn {
    pointer-events: auto;
  }
  .detail-header { grid-template-columns: 1fr; text-align: center; }
}

@media (max-width: 420px) {
  .menu-btn-label { display: none; }
  .menu-btn { min-width: 44px; padding: 0; width: 44px; }
}

/* Installed PWA (iOS/Android home screen) */
@media (display-mode: standalone), (display-mode: fullscreen) {
  .topbar {
    padding-top: max(0.5rem, env(safe-area-inset-top, 0));
  }
  .sidebar {
    padding-top: max(0.75rem, env(safe-area-inset-top, 0));
  }
}
