/* ============================================================
   Pokémon Box Modal — GBA PC-Box aesthetic (FireRed / Emerald)
   ============================================================ */

/* ---------- Backdrop / Overlay ---------- */
.pkmn-box-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px) saturate(130%);
  -webkit-backdrop-filter: blur(6px) saturate(130%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  overflow-y: auto;
  padding: 20px 0;
}

.pkmn-box-modal.pkmn-box-modal--open {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Card ---------- */
.pkmn-box-modal__card {
  position: relative;
  display: flex;
  flex-direction: column;
  /* Wider on large viewports; still safe on ~600px+ (narrow phones use full-bleed rule below) */
  width: min(960px, 96vw);
  max-height: min(720px, 96vh);
  border-radius: 18px;
  overflow: hidden;

  /* GBA deep blue gradient */
  background:
    linear-gradient(180deg,
      #1a1e4a 0%,
      #111437 40%,
      #0d1030 100%);
  border: 3px solid #3a4ab0;
  box-shadow:
    0 0 0 1px rgba(90, 120, 255, 0.18),
    0 0 40px rgba(60, 80, 200, 0.45),
    0 24px 64px rgba(0, 0, 0, 0.72),
    inset 0 1px 0 rgba(120, 160, 255, 0.2),
    inset 0 -1px 0 rgba(0, 0, 0, 0.4);

  transform: scale(0.88) translateY(24px);
  transition: transform 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-family: 'Inter', system-ui, sans-serif;
  color: #fff;
}

.pkmn-box-modal--open .pkmn-box-modal__card {
  transform: scale(1) translateY(0);
}

/* Scanline overlay */
.pkmn-box-modal__card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 30, 0.14) 2px,
    rgba(0, 0, 30, 0.14) 4px
  );
  pointer-events: none;
  z-index: 0;
  border-radius: inherit;
}

/* ---------- Header ---------- */
.pkmn-box-modal__header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 12px;
  background:
    linear-gradient(180deg, rgba(70, 90, 200, 0.35), rgba(40, 55, 160, 0.2));
  border-bottom: 2px solid rgba(90, 120, 255, 0.35);
}

.pkmn-box-modal__header-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  /* Pokéball icon via CSS */
  background:
    radial-gradient(circle at 50% 50%, #fff 0 28%, transparent 28%),
    linear-gradient(180deg, #e60012 0 50%, #fff 50% 52%, #1c1c1c 52%);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}

.pkmn-box-modal__title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #c8d8ff;
  text-shadow: 0 1px 3px rgba(0, 0, 80, 0.8);
  flex: 1 1 auto;
  margin: 0;
}

.pkmn-box-modal__search-wrap {
  position: relative;
  flex: 1 1 140px;
  max-width: 280px;
  min-width: 0;
  display: flex;
  align-items: center;
}

.pkmn-box-modal__search-icon {
  position: absolute;
  left: 10px;
  font-size: 0.8rem;
  opacity: 0.5;
  pointer-events: none;
}

.pkmn-box-modal__search {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 6px 12px 6px 30px;
  color: #fff;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.pkmn-box-modal__search:focus {
  border-color: rgba(140, 180, 255, 0.6);
  background: rgba(0, 0, 0, 0.45);
  box-shadow: 0 0 10px rgba(100, 150, 255, 0.2);
}

.pkmn-box-modal__search::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.pkmn-box-modal__box-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(180, 200, 255, 0.75);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.pkmn-box-modal__close {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.pkmn-box-modal__close:hover {
  background: rgba(230, 0, 18, 0.25);
  color: #fff;
  border-color: rgba(230, 0, 18, 0.5);
}

/* ---------- Body / Grid Area ---------- */
.pkmn-box-modal__body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  padding: 16px 18px 12px;
  overflow-y: auto;
  /* Custom scrollbar for GBA aesthetic */
  scrollbar-width: thin;
  scrollbar-color: rgba(90, 120, 255, 0.4) transparent;
}

.pkmn-box-modal__body::-webkit-scrollbar {
  width: 6px;
}

.pkmn-box-modal__body::-webkit-scrollbar-track {
  background: transparent;
}

.pkmn-box-modal__body::-webkit-scrollbar-thumb {
  background: rgba(90, 120, 255, 0.4);
  border-radius: 10px;
}

.pkmn-box-modal__body::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 160, 255, 0.6);
}

/* Decorative corner gems (GBA UI detail) */
.pkmn-box-modal__body::before,
.pkmn-box-modal__body::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #8af, #46f);
  box-shadow: 0 0 6px rgba(100, 160, 255, 0.7);
  z-index: 2;
  pointer-events: none;
}
.pkmn-box-modal__body::before { top: 10px; left: 10px; }
.pkmn-box-modal__body::after  { top: 10px; right: 10px; }

/* ---------- Grid (30 slots/page; column count × rows = 30) ---------- */
.pkmn-box-modal__grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  min-height: 200px; /* Prevent collapse during search */
}

@media (min-width: 760px) {
  .pkmn-box-modal__grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (min-width: 1200px) {
  .pkmn-box-modal__card {
    width: min(1120px, 94vw);
    max-height: min(680px, 96vh);
  }

  .pkmn-box-modal__grid {
    grid-template-columns: repeat(10, 1fr);
    gap: 7px;
  }

  .pkmn-box-slot__portrait-wrap {
    width: 52px;
    height: 52px;
  }
}

.pkmn-box-modal__no-results {
  grid-column: 1 / -1;
  padding: 40px 20px;
  text-align: center;
  color: rgba(255, 255, 255, 0.4);
  font-style: italic;
  font-size: 0.9rem;
}

/* ---------- Cell ---------- */
.pkmn-box-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px 5px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;

  background: linear-gradient(160deg, rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  border: 2px solid rgba(80, 110, 220, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.25),
    0 2px 4px rgba(0, 0, 0, 0.3);
  transition:
    background 0.12s ease,
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    transform 0.12s ease;
}

.pkmn-box-slot:hover {
  background: linear-gradient(160deg, rgba(100, 140, 255, 0.22), rgba(60, 90, 200, 0.15));
  border-color: rgba(130, 170, 255, 0.65);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -1px 0 rgba(0, 0, 0, 0.2),
    0 0 12px rgba(80, 130, 255, 0.35),
    0 4px 8px rgba(0, 0, 0, 0.3);
  transform: translateY(-1px);
  z-index: 2;
}

.pkmn-box-slot:active {
  transform: scale(0.94);
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.4);
}

/* Currently selected species */
.pkmn-box-slot--selected {
  background: linear-gradient(160deg, rgba(255, 200, 50, 0.22), rgba(255, 160, 0, 0.15));
  border-color: rgba(255, 210, 80, 0.75);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 200, 0.25),
    0 0 16px rgba(255, 190, 50, 0.5),
    0 0 6px rgba(255, 220, 80, 0.35),
    0 4px 8px rgba(0, 0, 0, 0.3);
}

.pkmn-box-slot--selected:hover {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 200, 0.3),
    0 0 20px rgba(255, 200, 60, 0.6),
    0 0 8px rgba(255, 230, 100, 0.4),
    0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Empty cell */
.pkmn-box-slot--empty {
  opacity: 0.12;
  cursor: default;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
  box-shadow: none;
}

.pkmn-box-slot--empty .pkmn-box-slot__portrait-wrap {
  background: rgba(0, 0, 0, 0.1);
  border-color: transparent;
}

/* Portrait wrapper */
.pkmn-box-slot__portrait-wrap {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0, 0, 30, 0.4);
  border: 1px solid rgba(80, 100, 200, 0.3);
}

.pkmn-box-slot__portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 15%;
  display: block;
  image-rendering: auto;
  transition: transform 0.15s ease;
}

.pkmn-box-slot:hover .pkmn-box-slot__portrait {
  transform: scale(1.08);
}

/* Placeholder silhouette while loading */
.pkmn-box-slot__portrait--loading {
  visibility: hidden;
}

.pkmn-box-slot__portrait-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(80,100,200,0.15), transparent 60%);
  pointer-events: none;
}

/* Missing portrait fallback icon */
.pkmn-box-slot__no-portrait {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  opacity: 0.35;
}

/* Dex number */
.pkmn-box-slot__dex {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.55rem;
  font-weight: 700;
  color: rgba(160, 185, 255, 0.7);
  letter-spacing: 0.04em;
  line-height: 1.2;
  height: 1.2em;
}

/* Species name */
.pkmn-box-slot__name {
  font-size: 0.54rem;
  font-weight: 700;
  color: rgba(220, 230, 255, 0.9);
  text-align: center;
  line-height: 1.2;
  height: 1.2em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

/* Type badges on hover */
.pkmn-box-slot__types {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 14px;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.pkmn-box-slot:hover .pkmn-box-slot__types,
.pkmn-box-slot--selected .pkmn-box-slot__types {
  opacity: 1;
  transform: translateY(0);
}

.pkmn-box-slot__type-badge {
  font-size: 0.44rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 1px 4px;
  border-radius: 3px;
  line-height: 1.3;
  border: 1px solid rgba(255,255,255,0.15);
}

/* ---------- Footer / Pagination ---------- */
.pkmn-box-modal__footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px 14px;
  border-top: 2px solid rgba(90, 120, 255, 0.25);
  background: linear-gradient(0deg, rgba(20, 25, 80, 0.45), transparent);
}

.pkmn-box-modal__page-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid rgba(80, 110, 220, 0.45);
  background: linear-gradient(160deg, rgba(60, 80, 200, 0.3), rgba(30, 40, 140, 0.25));
  color: rgba(200, 215, 255, 0.9);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.12s ease;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 2px 4px rgba(0,0,0,0.3);
}

.pkmn-box-modal__page-btn:hover:not(:disabled) {
  background: linear-gradient(160deg, rgba(90, 120, 255, 0.45), rgba(50, 70, 200, 0.35));
  border-color: rgba(120, 160, 255, 0.7);
  box-shadow: 0 0 14px rgba(80, 130, 255, 0.4), inset 0 1px 0 rgba(255,255,255,0.15), 0 2px 6px rgba(0,0,0,0.4);
  transform: translateY(-1px);
}

.pkmn-box-modal__page-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.pkmn-box-modal__page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pkmn-box-modal__page-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.pkmn-box-modal__page-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
}

.pkmn-box-modal__page-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(200, 220, 255, 0.9);
  letter-spacing: 0.04em;
}

/* Page dots indicator */
.pkmn-box-modal__page-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.pkmn-box-modal__page-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(100, 130, 220, 0.35);
  border: 1px solid rgba(80, 110, 200, 0.4);
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.pkmn-box-modal__page-dot--active {
  background: rgba(140, 190, 255, 0.95);
  border-color: rgba(180, 220, 255, 0.7);
  box-shadow: 0 0 6px rgba(130, 180, 255, 0.7);
  transform: scale(1.4);
}

/* ---------- Pokémon type colour tokens (reuse style.css tokens via inline approach) ---------- */
/* We duplicate a minimal set here so this file is self-contained */
.pkmn-box-slot__type-badge.type-normal   { background: #a8a878; color: #fff; }
.pkmn-box-slot__type-badge.type-fire     { background: #f08030; color: #fff; }
.pkmn-box-slot__type-badge.type-water    { background: #6890f0; color: #fff; }
.pkmn-box-slot__type-badge.type-electric { background: #f8d030; color: #333; }
.pkmn-box-slot__type-badge.type-grass    { background: #78c850; color: #fff; }
.pkmn-box-slot__type-badge.type-ice      { background: #98d8d8; color: #333; }
.pkmn-box-slot__type-badge.type-fighting { background: #c03028; color: #fff; }
.pkmn-box-slot__type-badge.type-poison   { background: #a040a0; color: #fff; }
.pkmn-box-slot__type-badge.type-ground   { background: #e0c068; color: #333; }
.pkmn-box-slot__type-badge.type-flying   { background: #a890f0; color: #fff; }
.pkmn-box-slot__type-badge.type-psychic  { background: #f85888; color: #fff; }
.pkmn-box-slot__type-badge.type-bug      { background: #a8b820; color: #fff; }
.pkmn-box-slot__type-badge.type-rock     { background: #b8a038; color: #fff; }
.pkmn-box-slot__type-badge.type-ghost    { background: #705898; color: #fff; }
.pkmn-box-slot__type-badge.type-dragon   { background: #7038f8; color: #fff; }
.pkmn-box-slot__type-badge.type-dark     { background: #705848; color: #fff; }
.pkmn-box-slot__type-badge.type-steel    { background: #b8b8d0; color: #333; }
.pkmn-box-slot__type-badge.type-fairy    { background: #ee99ac; color: #fff; }

/* ---------- Species detail (sprite preview + stats + Play) ---------- */
.pkmn-box-detail {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(4, 6, 20, 0.72);
  backdrop-filter: blur(4px);
}

.pkmn-box-detail.pkmn-box-detail--open {
  display: flex;
}

.pkmn-box-detail__panel {
  width: min(340px, 100%);
  /* Viewport-limited (detail layer is outside `__card`, so not tied to box max-height) */
  max-height: min(92vh, 680px);
  max-height: min(92dvh, 680px);
  overflow: auto;
  border-radius: 14px;
  padding: 14px 16px 16px;
  background: linear-gradient(180deg, #1f2458 0%, #14183d 55%, #0f1230 100%);
  border: 2px solid rgba(90, 120, 220, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(140, 180, 255, 0.18),
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 16px 48px rgba(0, 0, 0, 0.65);
}

.pkmn-box-detail__header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(100, 140, 255, 0.25);
}

.pkmn-box-detail__back {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(220, 230, 255, 0.92);
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.pkmn-box-detail__back:hover {
  background: rgba(100, 140, 255, 0.22);
  border-color: rgba(160, 200, 255, 0.45);
}

.pkmn-box-detail__headtext {
  flex: 1;
  min-width: 0;
}

.pkmn-box-detail__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #e8eeff;
  text-shadow: 0 1px 3px rgba(0, 0, 40, 0.8);
}

.pkmn-box-detail__dex {
  display: block;
  margin-top: 2px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(160, 185, 255, 0.85);
}

.pkmn-box-detail__stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 70%, rgba(40, 60, 140, 0.55), rgba(8, 10, 28, 0.92) 72%);
  border: 1px solid rgba(80, 110, 200, 0.35);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.45);
}

#pkmn-box-detail-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.pkmn-box-detail__types {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
  min-height: 22px;
}

.pkmn-box-detail__stats {
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: minmax(0, 38%) 1fr;
  gap: 6px 10px;
  font-size: 0.72rem;
  line-height: 1.35;
}

.pkmn-box-detail__stats dt {
  margin: 0;
  font-weight: 700;
  color: rgba(170, 195, 255, 0.75);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.58rem;
}

.pkmn-box-detail__stats dd {
  margin: 0;
  font-weight: 600;
  color: rgba(240, 245, 255, 0.95);
}

.pkmn-box-detail__footer {
  display: flex;
  justify-content: center;
}

.pkmn-box-detail__play {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 2px solid rgba(100, 220, 140, 0.55);
  background: linear-gradient(180deg, rgba(50, 160, 90, 0.95), rgba(30, 110, 65, 0.98));
  color: #fff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: filter 0.15s ease, transform 0.12s ease;
}

.pkmn-box-detail__play:hover {
  filter: brightness(1.08);
}

.pkmn-box-detail__play:active {
  transform: scale(0.98);
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .pkmn-box-modal__card {
    width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  .pkmn-box-modal__grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .pkmn-box-slot__portrait-wrap {
    width: 46px;
    height: 46px;
  }

  .pkmn-box-modal__page-btn {
    padding: 7px 10px;
    font-size: 0.65rem;
  }
}

@media (max-width: 380px) {
  .pkmn-box-modal__grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .pkmn-box-modal,
  .pkmn-box-modal__card,
  .pkmn-box-slot,
  .pkmn-box-modal__page-btn,
  .pkmn-box-detail__panel,
  .pkmn-box-detail__play,
  .pkmn-box-detail__back {
    transition: none;
  }
}
