/* Homepage layout — compact hero, sticky search, category-grouped tool grid */

/* --- Hero ---------------------------------------------------------------- */
.home-hero {
  padding: 36px 0 20px;
  text-align: center;
}
.home-hero h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  line-height: 1.2;
}
.home-hero p {
  font-size: 12px;
  line-height: 1.65;
  max-width: 520px;
  margin: 0 auto;
  color: #444;
}

/* --- Sticky search ------------------------------------------------------- */
.home-search {
  position: sticky;
  top: 50px; /* below sticky nav */
  background: #fff;
  z-index: 5;
  padding: 12px 0;
  margin-bottom: 4px;
  border-bottom: 1px solid #eee;
  transition: box-shadow 0.18s ease, padding 0.18s ease;
}
/* Stuck state — when scrolled past initial position, get a subtle shadow */
.home-search.is-stuck {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border-bottom-color: #ddd;
}
@media (max-width: 700px) {
  .home-search {
    top: 0; /* on mobile, sticky to viewport top — nav is not sticky on phone */
    padding: 10px 0 8px;
    margin: 0 -16px 4px; /* edge-to-edge */
    padding-left: 16px;
    padding-right: 16px;
  }
  .home-search.is-stuck {
    padding-top: 8px;
    padding-bottom: 6px;
  }
  .home-search.is-stuck .search-count { display: none; } /* save vertical space */
}
.search-wrap {
  position: relative;
  display: block;
}
.search-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 400;
  padding: 12px 44px 12px 16px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  outline: none;
  width: 100%;
}
.search-input::placeholder { color: #999; }
.search-input:focus { box-shadow: 0 0 0 2px rgba(0,0,0,0.06); }
.search-kbd {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: #fff;
  border: 1px solid #aaa;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  color: #666;
  pointer-events: none;
  user-select: none;
}
.search-input:focus ~ .search-kbd { display: none; }
@media (max-width: 700px) {
  .search-kbd { display: none; }
}
.search-count {
  font-size: 10px;
  margin-top: 6px;
  color: #666;
}

/* --- Category quick-nav (chips) ----------------------------------------- */
.cat-quicknav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 16px 0 24px;
}
.cat-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  padding: 6px 10px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cat-chip:hover { background: #f5f5f5; }
.cat-chip.is-active { background: #000; color: #fff; }
.cat-chip-n {
  font-size: 9px;
  font-weight: 400;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.08);
}
.cat-chip.is-active .cat-chip-n {
  background: rgba(255, 255, 255, 0.18);
}

/* --- Category sections -------------------------------------------------- */
.cat-sections {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cat-section {
  border-top: 1px solid #000;
  /* Lazy-render: skip rendering off-screen sections; reserve ~600px so scrollbar is stable */
  content-visibility: auto;
  contain-intrinsic-size: 0 600px;
}
/* Don't lazy-render the first 3 sections — they're always above the fold */
.cat-sections > .cat-section:nth-of-type(-n+3) {
  content-visibility: visible;
  contain-intrinsic-size: auto;
}
.cat-section:last-of-type {
  border-bottom: 1px solid #000;
}
.cat-section > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  user-select: none;
}
.cat-section > summary::-webkit-details-marker { display: none; }
.cat-section > summary::before {
  content: '+';
  font-size: 18px;
  font-weight: 400;
  margin-right: 12px;
  display: inline-block;
  width: 12px;
  text-align: center;
  transition: transform 0.15s;
  line-height: 1;
}
.cat-section[open] > summary::before {
  content: '−';
}
.cat-section-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.cat-section-count {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cat-section[open] .cat-section-name { color: #000; }

/* --- Tool grid (within each section) ------------------------------------ */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 4px 0 20px;
}
.tool-card {
  padding: 14px;
  border: 1px solid #000;
  text-decoration: none;
  color: #000;
  display: flex;
  flex-direction: column;
  min-height: 110px;
}
.tool-card:hover { background: #000; color: #fff; }
.tool-card:hover .tool-desc { color: #ccc; }
.tool-card.hidden { display: none; }
.tool-name {
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
  line-height: 1.3;
}
.tool-desc {
  font-size: 10px;
  line-height: 1.4;
  margin-top: auto;
  color: var(--text-secondary);
}

/* --- No results --------------------------------------------------------- */
.no-results {
  padding: 40px 0;
  text-align: center;
  font-size: 13px;
  color: #888;
}

/* --- Collapsed SEO ------------------------------------------------------ */
.home-seo {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid #000;
}
.home-seo > summary {
  cursor: pointer;
  list-style: none;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 8px 0;
}
.home-seo > summary::-webkit-details-marker { display: none; }
.home-seo > summary::after {
  content: ' →';
  display: inline-block;
  transition: transform 0.15s;
}
.home-seo[open] > summary::after {
  transform: rotate(90deg);
}
.home-seo p {
  font-size: 12px;
  line-height: 1.85;
  margin-top: 12px;
  color: #333;
}

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 700px) {
  .home-hero { padding: 28px 0 16px; }
  .home-hero h1 { font-size: 22px; }
  .cat-grid { grid-template-columns: 1fr; gap: 6px; padding-bottom: 16px; }
  .tool-card { min-height: auto; padding: 12px 14px; }
  .home-search { top: 48px; padding: 10px 0; }
  .cat-quicknav { gap: 4px; margin-bottom: 16px; }
  .cat-chip { font-size: 9px; padding: 5px 8px; }
}
@media (max-width: 480px) {
  .home-hero h1 { font-size: 20px; }
  .home-hero p  { font-size: 11px; }
}
@media (min-width: 701px) and (max-width: 920px) {
  .cat-grid { grid-template-columns: 1fr 1fr; }
}

/* --- Filtered/search results layout ------------------------------------ */
/* When user filters by category chip or types in search, hide section
   summary headers and let each section's native cat-grid handle the
   3-col responsive layout. Avoids display:contents conflicts with
   <details> element semantics. */
.cat-sections.is-searching .cat-section {
  border: none;
  /* Always render — override the lazy-render content-visibility */
  content-visibility: visible;
  contain-intrinsic-size: auto;
  margin-bottom: 12px;
}
.cat-sections.is-searching > summary,
.cat-sections.is-searching .cat-section > summary {
  display: none;
}
.cat-sections.is-searching .cat-grid {
  padding-top: 0;
  padding-bottom: 8px;
}

/* --- Recently used rail (homepage) -------------------------------------- */
.recent-rail-wrap {
  margin: 12px 0 4px;
  padding: 10px 12px;
  border: 1px solid #000;
  background: #fff;
}
.recent-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.recent-rail-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #555;
}
.recent-rail-clear {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: transparent;
  border: 1px solid transparent;
  color: #999;
  cursor: pointer;
  padding: 2px 6px;
}
.recent-rail-clear:hover { color: #000; border-color: #000; }
.recent-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.recent-pill {
  display: inline-flex;
  align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  padding: 6px 10px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  text-decoration: none;
  white-space: nowrap;
  max-width: 100%;
}
.recent-pill:hover { background: #000; color: #fff; }
.recent-pill-name { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) {
  .recent-rail { gap: 4px; }
  .recent-pill { font-size: 10px; padding: 5px 8px; }
}

/* --- Popular calculators rail (above category sections) ---------------- */
.popular-rail {
  margin: 16px 0 24px;
}
.popular-rail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #000;
}
.popular-rail-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.popular-rail-hint {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #888;
}
.popular-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.popular-card {
  padding: 10px 12px;
  border: 1px solid #000;
  text-decoration: none;
  color: #000;
  display: flex;
  flex-direction: column;
  min-height: 78px;
  background: #fff;
}
.popular-card:hover { background: #000; color: #fff; }
.popular-name {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 3px;
}
.popular-desc {
  font-size: 9px;
  line-height: 1.45;
  color: #444;
  margin-top: auto;
}
.popular-card:hover .popular-desc { color: #ccc; }
@media (max-width: 920px) {
  .popular-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  .popular-grid { grid-template-columns: 1fr 1fr; }
  .popular-rail-hint { display: none; }
}
/* Hide popular rail while user is actively searching */
.cat-sections.is-searching ~ .popular-rail,
body.searching .popular-rail { display: none; }
