/* ==========================================================================
   INDEX.CSS - 50/50 Split Layout, Card Grid, 3D Tilt Effects
   ========================================================================== */

/* ==========================================================================
   50/50 SPLIT LAYOUT
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: clamp(28px, 5vw, 64px);
  height: calc(100vh - 70px);
  overflow: hidden;
}

/* ==========================================================================
   LEFT SIDE: Artistic Sidebar
   ========================================================================== */
.sidebar-panel {
  position: sticky;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Đẩy khối ảnh + glow lùi khỏi rãnh giữa hai cột (kèm column-gap ở .app-shell) */
  padding-right: clamp(12px, 2vw, 28px);
  box-sizing: border-box;
}

/* Minimal sidebar - just the Pokemon with glow */
.sidebar-card {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

/* Dynamic glow background based on type - STRICTLY BEHIND the image */
.sidebar-card::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    var(--type-color, rgba(255, 255, 255, 0.2)) 0%,
    transparent 70%
  );
  filter: blur(80px);
  opacity: 0.6;
  z-index: 1;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

/* Hide sidebar info on desktop (only image visible) */
.sidebar-basic,
.sidebar-detail {
  display: none;
}

/* Large artistic Pokemon image */
.sidebar-media {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.sidebar-media img {
  position: relative;
  z-index: 10;
  width: auto;
  height: 65vh;
  max-height: 75%;
  max-width: 280px;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 0 20px var(--type-color, rgba(0, 0, 0, 0.5)))
    drop-shadow(0 0 60px var(--type-color, rgba(0, 0, 0, 0.3)))
    drop-shadow(0 0 15px rgba(255, 255, 255, 0.1));
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), 
              filter 0.5s ease,
              opacity 0.15s ease;
}

/* Smooth fade transition when switching Pokemon */
.sidebar-media img.fading {
  opacity: 0;
  transform: scale(0.95);
}

.sidebar-media img:hover {
  transform: scale(1.03);
}

/* Mobile-only sidebar text */
.sidebar-basic {
  text-align: center;
}

.sidebar-name {
  margin-bottom: 8px;
}

.sidebar-detail {
  margin-top: 10px;
}

.sidebar-hint {
  font-size: 0.9rem;
}

/* ==========================================================================
   RIGHT SIDE: Scrollable Grid
   ========================================================================== */
.main-panel {
  height: 100%;
  overflow-y: auto;
  /* min-width: 0 — grid/flex item có thể co; tránh lưới thẻ bài đẩy tràn ngang trên mobile */
  min-width: 0;
  /* Chừa thêm không gian trái: neon + scale(1.05) của thẻ active không bị cắt sát mép cột */
  padding: 20px 24px 32px clamp(28px, 3.5vw, 48px);
  box-sizing: border-box;
}

.main-panel::-webkit-scrollbar {
  width: 8px;
}

.main-panel::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.main-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.main-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Page Header */
.page-header {
  padding: 12px 0 10px;
}

.page-header .muted {
  font-size: 0.88rem;
}

/* ==========================================================================
   NAVIGATION BAR - Liquid Glass (National Pokedex dropdown + Mega + G-Max)
   ========================================================================== */
.pokedex-nav {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 5px;
  margin-bottom: 14px;
  background: rgba(18, 20, 28, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 50;
  overflow: visible;
  min-width: 0;
}

/* Horizontal scroll strip: Mega / G-Max / regional forms (dropdown Gen stays outside so menu is not clipped) */
.pokedex-nav-scroll {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
  padding-bottom: 2px;
}

.pokedex-nav-scroll::-webkit-scrollbar {
  height: 6px;
}

.pokedex-nav-scroll::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 3px;
}

.pokedex-nav-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
  border-radius: 3px;
}

.pokedex-nav-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

.pokedex-nav > .nav-dropdown {
  flex-shrink: 0;
}

.pokedex-nav-scroll .nav-tab {
  flex-shrink: 0;
}

/* --- Tab Button (shared by dropdown trigger, Mega, G-Max) --- */
.nav-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  position: relative;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.9);
}

.nav-tab.is-active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
  box-shadow:
    0 0 12px rgba(100, 180, 255, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Glowing underline for active tab */
.nav-tab.is-active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 20%;
  right: 20%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(100, 180, 255, 0.7), transparent);
}

.nav-tab-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-tab-icon-img {
  object-fit: contain;
}

.nav-tab.is-active .nav-tab-icon {
  opacity: 1;
}

.nav-tab-label {
  font-weight: 700;
}

.nav-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.5;
  transition: transform 0.25s ease;
}

/* --- Dropdown Container --- */
.nav-dropdown {
  position: relative;
}

.nav-dropdown.is-open .nav-chevron {
  transform: rotate(180deg);
}

/* --- Dropdown Menu (Liquid Glass, floats over content) --- */
.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 180px;
  padding: 6px;
  background: rgba(18, 20, 28, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    0 0 1px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 100;
  pointer-events: none;
}

.nav-dropdown.is-open .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

/* --- Dropdown Items --- */
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.dropdown-item.is-active {
  background: rgba(100, 180, 255, 0.12);
  color: #fff;
}

.dropdown-gen-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-color, rgba(255, 255, 255, 0.4));
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--dot-color, transparent);
}

/* ==========================================================================
   GENERATION BADGE - Small corner badge on cards
   ========================================================================== */
.gen-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 8;
  padding: 2px 5px;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 4px;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.gen-badge.gen-1 {
  background: linear-gradient(135deg, #ff6b6b, #ee5a5a);
  color: #fff;
  box-shadow: 0 2px 6px rgba(255, 107, 107, 0.3);
}

.gen-badge.gen-2 {
  background: linear-gradient(135deg, #ffd700, #f0c000);
  color: #1a1a2e;
  box-shadow: 0 2px 6px rgba(255, 215, 0, 0.3);
}

.gen-badge.gen-3 {
  background: linear-gradient(135deg, #00bfff, #1e90ff);
  color: #fff;
  box-shadow: 0 2px 6px rgba(30, 144, 255, 0.4);
}

.gen-badge.gen-4 {
  background: linear-gradient(135deg, #9966ff, #7b52cc);
  color: #fff;
  box-shadow: 0 2px 6px rgba(153, 102, 255, 0.4);
}

.gen-badge.gen-5 {
  background: linear-gradient(135deg, #f5a623, #e0940e);
  color: #1a1a2e;
  box-shadow: 0 2px 6px rgba(245, 166, 35, 0.4);
}

.gen-badge.gen-6 {
  background: linear-gradient(135deg, #50c878, #2e8b57);
  color: #fff;
  box-shadow: 0 2px 6px rgba(80, 200, 120, 0.4);
}

.gen-badge.gen-7 {
  background: linear-gradient(135deg, #4b0082, #2d1b4e);
  color: #e6e6fa;
  box-shadow: 0 2px 6px rgba(75, 0, 130, 0.4);
}

.gen-badge.gen-8 {
  background: linear-gradient(135deg, #1e90ff, #0066b3);
  color: #fff;
  box-shadow: 0 2px 6px rgba(30, 144, 255, 0.4);
}

.gen-badge.gen-9 {
  background: linear-gradient(135deg, #228b22, #006400);
  color: #fff;
  box-shadow: 0 2px 6px rgba(34, 139, 34, 0.4);
}

.card-hitbox:hover .gen-badge {
  opacity: 1;
}

/* National dex # — góc trái trên thẻ (gen-badge ở góc phải); tách khỏi hàng tên để tên không bị chèn chỗ */
.card-grid-item > .dex--corner {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 8;
  margin: 0;
  padding: 2px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(5, 10, 22, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.card-hitbox:hover .card-grid-item > .dex--corner {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(8, 14, 28, 0.88);
}

/* ==========================================================================
   SEARCH BAR
   ========================================================================== */
.search-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  margin-bottom: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-container:focus-within {
  border-color: rgba(100, 180, 255, 0.6);
  box-shadow: 0 0 12px rgba(100, 180, 255, 0.25);
}

.search-icon {
  font-size: 1rem;
  opacity: 0.6;
  pointer-events: none;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.search-input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

/* ==========================================================================
   CARD GRID
   ========================================================================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr));
  gap: 12px;
  padding: 10px 0 0 clamp(4px, 1vw, 12px);
  min-width: 0;
}

/* ==========================================================================
   CARD HITBOX - Static Wrapper for 3D Tilt
   Now an <a> tag for navigation to detail page.
   ========================================================================== */
.card-hitbox {
  display: block;
  text-decoration: none;
  color: inherit;
  perspective: 1000px;
  height: 100%;
  position: relative;
  min-width: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent; /* Tắt hiệu ứng nháy đen mặc định của trình duyệt trên mobile khi chạm vào thẻ <a> */
}

.card-hitbox:hover,
.card-hitbox:focus,
.card-hitbox:active {
  text-decoration: none;
  color: inherit;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* ==========================================================================
   CARD - Base Visual Styling
   ========================================================================== */
.card {
  display: block;
  position: relative;
  background: linear-gradient(180deg, var(--panel), rgba(255, 255, 255, 0.03));
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  transition: box-shadow 160ms ease, border-color 160ms ease;
}

/* Hover for NON-grid cards only */
.card:not(.card-grid-item):hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: var(--shadow);
}

/* Grid cards: hover border glow */
.card-hitbox:hover .card-grid-item {
  border-color: rgba(255, 255, 255, 0.25);
}

/* ==========================================================================
   CARD-GRID-ITEM - 3D Tilting Card
   JS sets: --rotate-x, --rotate-y, --lift, --shadow-dx, --shadow-dy, --mouse-x, --mouse-y
   ========================================================================== */
.card-grid-item {
  cursor: pointer;
  position: relative;
  text-align: left;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-width: 0;
  aspect-ratio: 3 / 4.2;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  transform-style: preserve-3d;
  transform-origin: center center !important;
  transform:
    translateZ(var(--lift, 0px))
    rotateX(var(--rotate-x, 0deg))
    rotateY(var(--rotate-y, 0deg));
  box-shadow:
    calc(var(--shadow-dx, 0px) + 4px)
    calc(var(--shadow-dy, 0px) + 8px)
    20px rgba(0, 0, 0, 0.35);
  transition:
    transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 0.5s ease,
    border-color 0.2s ease;
  will-change: transform;
}

/* Holographic foil effect */
.card-hitbox:hover .card-grid-item::after {
  opacity: 0.7;
}

.card-grid-item::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 5;
  background: radial-gradient(
    800px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
    rgba(255, 255, 255, 0.4) 0%,
    rgba(180, 220, 255, 0.16) 25%,
    rgba(255, 200, 220, 0.1) 50%,
    transparent 60%
  );
  mix-blend-mode: color-dodge;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* ==========================================================================
   ACTIVE STATE - Clean Selection without Blur Overlay
   ========================================================================== */

/* Active state: 2px border + scale + glow (spread vừa đủ — tránh cắt sát đường chia cột) */
.card-grid-item.active {
  border: 2px solid var(--type-color, rgba(255, 255, 255, 0.8));
  transform: scale(1.05);
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.38),
    0 0 18px var(--type-color, rgba(0, 0, 0, 0.55)),
    0 0 34px var(--type-color, rgba(0, 0, 0, 0.32));
  z-index: 5;
}

/* Disable the holographic overlay on active card - keep image clear */
.card-grid-item.active::after {
  display: none;
}

/* Glow sau ảnh khi active — nhỏ hơn một chút so với trước để mép trái ít tràn */
.card-grid-item.active .card-glow {
  transform: translate(-50%, -50%) scale(4.25);
  opacity: 0.75;
  filter: blur(34px);
}

.card-grid-item .card-title {
  display: block;
  min-width: 0;
}

/* Tên dùng cả chiều ngang thẻ; tối đa 2 dòng — tránh một hàng dex+tên cắt ellipsis */
.card-grid-item .name {
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.25;
  word-break: break-word;
  flex: none;
  text-overflow: clip;
}

.card-grid-item .card-media,
.card-grid-item .card-body {
  transform-style: preserve-3d;
}

/* ==========================================================================
   CARD GLOW EFFECT - Strictly behind image (z-index: 1)
   ========================================================================== */
.card-glow {
  position: absolute;
  top: 45%;
  left: 50%;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(1);
  filter: blur(50px);
  opacity: 0.15;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), 
              opacity 0.4s ease,
              filter 0.4s ease;
  z-index: 1;
  background: var(--glow-color, #ffffff);
  pointer-events: none;
}

.card:hover .card-glow {
  transform: translate(-50%, -50%) scale(4);
  opacity: 0.6;
}

/* ==========================================================================
   CARD MEDIA - Avatar-style image
   ========================================================================== */
.card-media {
  aspect-ratio: 1 / 1;
  position: relative;
  z-index: 2;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-radius: 10px 10px 0 0;
}

.card-media img {
  position: relative;
  z-index: 5;
  width: 75%;
  height: 75%;
  object-fit: contain;
  object-position: center;
  transform: translateY(-8px);
  image-rendering: auto;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
  opacity: 0;
  animation: fadeInImage 0.3s ease-out forwards;
  animation-play-state: paused;
  transition: transform 0.3s ease, opacity 0.18s ease;
}

.card-media img.loaded {
  animation-play-state: running;
}

/* Smooth cross-fade when switching form images */
.card-media img.form-swapping {
  opacity: 0 !important;
  transform: translateY(-8px) scale(0.95);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

/* Zoom on hover */
.card-hitbox:hover .card-media img.loaded {
  transform: translateY(-8px) scale(1.08);
}

/* ==========================================================================
   CARD BODY
   ========================================================================== */
.card-body {
  position: relative;
  z-index: 2;
  padding: 10px 10px 10px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.card-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 0;
  min-width: 0;
}

.dex {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.name {
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1 1 0;
}

/* Type badges container */
.types {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
  margin-top: auto;
}

/* ==========================================================================
   RESPONSIVE: Mobile Layout (<768px)
   ========================================================================== */
@media (max-width: 768px) {
  /* Stack layout vertically */
  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
    min-width: 0;
  }

  /* Sidebar on top — chỉ ảnh: không giới hạn 50vh để sprite không bị chèn ép như khi còn khối chữ */
  .sidebar-panel {
    position: relative;
    height: auto;
    min-height: 240px;
    max-height: none;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
  }

  .sidebar-card {
    padding: 16px 20px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
  }

  /* Giống desktop: chỉ hiện sprite + neon, không hiện tên / hệ / stats / preview */
  .sidebar-basic,
  .sidebar-detail {
    display: none;
  }

  /* Kích thước ảnh + neon hơi gọn hơn desktop (chỉ mobile) */
  .sidebar-card::before {
    width: 140%;
    height: 140%;
    background: radial-gradient(circle closest-side, var(--glow-color, rgba(255,255,255,0.5)) 0%, transparent 75%);
    filter: none; /* Thay blur bằng radial-gradient để GPU không bị lag khi đổi màu */
    opacity: 0.45;
    transition: none; /* Đổi màu ngay lập tức, không cần chuyển cảnh */
  }

  .sidebar-media img {
    height: min(52vh, 340px);
    max-height: 85%;
    max-width: min(300px, 88vw);
    filter: none; /* Bỏ drop-shadow trên mobile để tránh lỗi viền đen của iOS Safari khi đổi ảnh và tăng tốc độ render */
  }

  /* Main panel below */
  .main-panel {
    height: auto;
    overflow: visible;
    padding: 16px;
  }

  /* Smaller grid on mobile — minmax(0,1fr) trong auto-fill để cột luôn co vừa khung */
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(110px, 100%), 1fr));
    gap: 10px;
  }

  /* Compact cards on mobile */
  .card-body {
    padding: 8px;
  }

  .card-grid-item > .dex--corner {
    top: 5px;
    left: 5px;
    padding: 2px 5px;
    font-size: 0.65rem;
    border-radius: 4px;
  }

  .name {
    font-size: 0.8rem;
  }

  .card-grid-item .name {
    font-size: 0.78rem;
    -webkit-line-clamp: 2;
  }

  /* Chỉ thẻ trong lưới Pokédex: badge hệ nhỏ gọn — 2 hệ xếp chồng ít ăn chỗ, tên ít bị “kẹt” sát ảnh */
  .card-grid .types {
    gap: 2px 3px;
    row-gap: 2px;
  }

  .card-grid .type-badge {
    padding: 1px 5px;
    font-size: 0.52rem;
    font-weight: 600;
    letter-spacing: 0.08px;
    border-radius: 4px;
    line-height: 1.15;
  }

  /* Compact nav on mobile */
  .pokedex-nav {
    gap: 4px;
    padding: 4px;
  }

  .nav-tab {
    padding: 8px 12px;
    font-size: 0.75rem;
    gap: 5px;
  }

  .nav-tab-icon {
    width: 14px;
    height: 14px;
  }

  .nav-dropdown-menu {
    min-width: 160px;
  }

  /* Smaller gen badge on mobile */
  .gen-badge {
    font-size: 0.5rem;
    padding: 2px 4px;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .main-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  .card-grid {
    /* minmax(0,1fr) bắt buộc: repeat(3,1fr) mặc định là minmax(auto,1fr) → cột không co → tràn màn hình */
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding-left: 0;
    padding-right: 0;
  }

  .card-grid-item {
    /* Gọn hơn trên điện thoại; aspect-ratio hơi thấp hơn giúp thẻ không quá cao */
    aspect-ratio: 3 / 4;
  }

  .card-grid-item.active {
    transform: scale(1.02);
    box-shadow:
      0 6px 16px rgba(0, 0, 0, 0.35),
      0 0 12px var(--type-color, rgba(0, 0, 0, 0.5)),
      0 0 22px var(--type-color, rgba(0, 0, 0, 0.28));
  }

  .card-body {
    padding: 6px 6px 8px;
    gap: 4px;
  }

  .card-grid-item > .dex--corner {
    top: 4px;
    left: 4px;
    padding: 1px 4px;
    font-size: 0.58rem;
    border-radius: 3px;
  }

  .card-grid-item .name {
    font-size: 0.72rem;
    line-height: 1.2;
  }

  .card-grid .types {
    gap: 1px 2px;
    row-gap: 1px;
    justify-content: center;
  }

  .card-grid .type-badge {
    padding: 1px 3px;
    font-size: 0.5rem;
    font-weight: 600;
    letter-spacing: 0;
    border-radius: 3px;
    line-height: 1.1;
  }

  .card-media {
    aspect-ratio: 1 / 1;
  }

  .card-media img {
    width: 72%;
    height: 72%;
  }

  .sidebar-media img {
    height: 30vh;
    max-height: 200px;
  }

  /* Even more compact nav */
  .nav-tab {
    padding: 6px 10px;
    gap: 4px;
  }

  .nav-tab-label {
    font-size: 0.7rem;
  }
}

@media (hover: none), (pointer: coarse) {
  .card-hitbox {
    perspective: none;
  }

  .card-grid-item {
    transform: none;
    transition: none; /* Tắt hoàn toàn transition để viền active sáng lên ngay lập tức */
    will-change: auto;
  }

  .card-grid-item::after {
    display: none;
  }

  .card-hitbox:hover .card-grid-item {
    border-color: var(--border);
  }

  .card:hover .card-glow {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.15;
  }

  .card-glow {
    transition: opacity 0.22s ease, filter 0.22s ease;
  }

  .card-media img {
    transition: opacity 0.18s ease;
  }

  .sidebar-media img {
    transition: none;
  }

  .card-hitbox:hover .card-media img.loaded {
    transform: translateY(-8px);
  }

  .card-grid-item.active {
    transform: none;
    box-shadow: 0 0 0 2px var(--type-color, rgba(255, 255, 255, 0.8));
    border-color: transparent;
  }

  .card-grid-item.active .card-glow {
    display: none;
  }
}
