/* ===========================
   Layers & Clickability
=========================== */

/* Ensure dropdowns sit above fixed sidebars */
.dropdown-panel { z-index: 1301; }

/* Mobile overlays should be above everything */
.mobile-panel { z-index: 1400 !important; }

/* Panel positioning & overflow so submenus can extend */
.category-nav .dropdown { position: relative; overflow: visible; }
.dropdown-panel {
  position: absolute;
  top: 100%;
  left: 0;
  pointer-events: auto;
  overflow: visible;
}

/* Hide panels toggled via [hidden] from JS */
.dropdown-panel[hidden] { display: none !important; }

/* ===========================
   Generic Desktop Dropdown
=========================== */
.dropdown-panel {
  background: #eaeae1;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  padding: .5rem;
  width: 420px;
  max-width: 95vw;
  border-radius: 8px;

  /* Make the whole panel scroll if content grows (e.g., Load more) */
  max-height: 85vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.dark-mode .dropdown-panel { background: #333; }

.category-nav .dropdown > a { cursor: pointer; }

/* Search row inside dropdown */
.dropdown-panel .dropdown-search { margin-bottom: .35rem; }
.dropdown-panel .dropdown-search input {
  width: 100%;
  box-sizing: border-box;
  padding: .45rem .6rem;
  font-size: .9rem;
  border: 1px solid #ccc;
  border-radius: 6px;
}

/* Grid of thumbs (desktop) */
.dropdown-panel .thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .3rem;
}

/* ===========================
   Unified Thumb Component
   (desktop dropdowns + mobile panels)
=========================== */
.dropdown-panel a.thumb,
.panel-grid a.thumb,
.mobile-panel > a.thumb {
  position: relative !important;
  display: block !important;
  overflow: hidden !important;
  border-radius: 6px !important;
  text-decoration: none !important;
}

/* Image sizing */
.dropdown-panel a.thumb img,
.panel-grid a.thumb img,
.mobile-panel > a.thumb img {
  display: block !important;
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 16 / 9 !important;
  object-fit: fill !important;
}

/* Category page thumbnail styling */
.panel-grid .category-page-thumb .thumb-title {
  background: rgba(0,0,0,.7) !important;
  font-weight: 600;
}

/* Title overlay */
.dropdown-panel a.thumb > .thumb-title,
.panel-grid a.thumb > .thumb-title,
.mobile-panel > a.thumb > .thumb-title {
  position: absolute !important;
  left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .65rem;
  line-height: 1.2;
  padding: 2px 4px;
  text-align: center;
  pointer-events: none;
}

/* Hidden thumbs (filtered out by search) */
.dropdown-panel a.thumb[hidden],
.panel-grid a.thumb[hidden],
.mobile-panel > a.thumb[hidden] {
  display: none !important;
}

/* Load-more button (if used) */
.dropdown-panel .load-more {
  width: 100%;
  margin-top: .35rem;
  padding: .45rem .6rem;
  border: 1px solid #aaa;
  background: #fafafa;
  border-radius: 6px;
  cursor: pointer;
}

/* clickable children (safety) */
.dropdown-panel .thumb,
.dropdown-panel .thumb * { pointer-events: auto; }


/* ===========================
   Mobile Panels (off-canvas)
=========================== */
.mobile-panel {
  display: none; /* Hidden by default - CRITICAL for SEO */
  position: fixed;
  inset: 0;
  background: var(--bg,#fff);
  transform: translateX(100%);
  transition: transform .3s ease;
  flex-direction: column;
  box-shadow: -2px 0 8px rgba(0,0,0,.2);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  pointer-events: none; /* Don't block clicks when closed */
}

.mobile-panel.open {
  display: flex !important; /* Show as flex when opened */
  transform: translateX(0);
  pointer-events: auto; /* Allow clicks when open */
}

/* Server-rendered thumbs before JS enhancement */
.mobile-panel > a.thumb {
  /* These are visible in source but hidden visually until wrapped */
  display: none;
}

/* After JS wraps them in .panel-grid */
.mobile-panel .panel-grid a.thumb {
  display: block;
}

.panel-header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 1rem;
  border-bottom: 1px solid #ddd;
  background: inherit;
  display: flex;
  justify-content: center;
  align-items: center;
}
.panel-header h2 {
  margin: 0;
  font-size: 1.25rem;
}
.panel-back {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: none;
  border: 0;
  font-size: .875rem;
  cursor: pointer;
}
.panel-search {
  position: sticky;
  top: 60px;
  z-index: 1;
  background: inherit;
  padding: 0 .5rem;
}
.panel-search input {
  width: 100%;
  margin: .5rem 0;
  padding: .5rem;
  font-size: .9rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.panel-grid {
  display: grid;
  grid-template-columns: repeat(5,1fr);
  gap: .2rem;
  padding: .25rem;
}

.dark-mode .mobile-panel { 
  background: #333;
  --bg: #333;
}
.dark-mode .panel-back { color: #fff; }

/* ===========================
   Mobile Tweaks (≤768px)
=========================== */
@media (max-width: 1280px) {
  /* Bigger, reliable tap targets */
  .header-icons button,
  #menu-toggle,
  #search-toggle,
  #dark-mode-toggle {
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    z-index: 1201;
  }

  .header-icons button i {
    pointer-events: none;
  }

  /* Make the logo a big tap target */
  a.site-title {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    z-index: 1201;
  }

  /* Prevent anything from overlaying taps */
  header,
  .header-row,
  .header-icons,
  .site-title {
    pointer-events: auto;
    z-index: 1200;
  }

  /* Sticky header inside mobile panels (incl. slang) */
  .mobile-panel .panel-header {
    position: sticky;
    top: 0;
    background: inherit;
    z-index: 2;
  }

  .dropdown-panel {
    width: 92vw;
    max-width: 95vw;
  }
  
  .dropdown-panel .thumb-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .2rem;
  }

  /* Make thumbs square and tighten overlay */
  .dropdown-panel a.thumb img,
  .panel-grid a.thumb img,
  .mobile-panel > a.thumb img {
    aspect-ratio: 1 / 1 !important;
  }
  
  /* Category icon should also be square on mobile */
  .panel-grid .category-page-thumb .category-page-icon {
    aspect-ratio: 1 / 1;
    font-size: 2.5rem;
  }
  
  .dropdown-panel a.thumb > .thumb-title {
    font-size: .55rem;
    padding: 2px 3px;
  }
  
  .panel-grid a.thumb > .thumb-title,
  .mobile-panel > a.thumb > .thumb-title {
    font-size: .6rem;
    padding: 3px 4px;
  }

}

/* === Writers dropdown avatar sizing === */
#writers-panel a.thumb img,
#mobile-writers-panel a.thumb img {
  aspect-ratio: 1 / 1 !important;
  border-radius: 50% !important;
  width: 80px !important;
  height: 80px !important;
  object-fit: fill !important;
  margin: 0 auto !important;
}

#writers-panel a.thumb,
#mobile-writers-panel a.thumb {
  text-align: center !important;
}

#writers-panel .thumb-title {
    width: 23%!important;
    border-radius: 25%!important;
    margin: 0 auto!important;
}



/* 🧑‍💻 Writers mobile panel grid (3 columns) */
#mobile-writers-panel .panel-grid {
  grid-template-columns: repeat(3, 1fr) !important;
  gap: .4rem !important;
  padding: .5rem !important;
}