:root {
  --content-max: 1200px;
  --gap: 20px;
  --radius: 8px;

  /* Fallbacks */
  --color-text: #777;
  --color-accent: #007bff;
  --color-surface: #fff;

  /* Sticky header height (used to center hero area) */
  --header-h: 56px;

  /* Category grid sizing */
  --cat-col-pc: 180px;   /* desktop column width (5 cols) */
  --cat-col-mob: 160px;  /* mobile column width (2 cols) */
  --cat-row-h: 60px;     /* fixed tile height ≈ two lines of text */
  --cat-row-h-mobile: 50px;     /* fixed tile height ≈ two lines of text */
}

/* ===== Hero wrapper: centered both axes under sticky header ===== */
.main-wrap {
  /* max-width: var(--content-max); */
  max-width: none;
  margin: 0 auto;
  padding: var(--gap);
  text-align: center;

  display: flex;
  flex-direction: column;
  justify-content: center;                 /* vertical center */
  align-items: center;                     /* horizontal center */

  min-height: calc(100svh - var(--header-h));
}
.main-wrap > *:first-child { margin-top: 0; }

h1 {
  font-size: 3.5rem;
  margin: 0 0 20px;
  color: var(--color-accent);
  cursor: default;
}

/* Subtitle / description */
.subtitle {
  opacity: 0;
  transition: opacity 0.9s ease;
  margin: 10px 0;
  font-size: 1.5rem;
  color: #777; /* or var(--color-text) */
}

p#description.description {
  font-size: 1.2rem;
  line-height: 1.7rem;
  margin: 20px auto 0;
  max-width: 700px;
  color: #777; /* or var(--color-text) */
  opacity: 0;
  transition: opacity 0.9s ease;
}

/* Search */
.search-form {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.search-input {
  font-size: 1rem;
  padding: 8px 12px;
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.search-input:focus {
  border-color: var(--color-text);
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}

/* A11y helper */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}

/* =========================================================
   CATEGORIES — fixed equal grid, fixed row height (2 lines)
   ========================================================= */

/* Desktop (default): 5 equal columns */
.category-container {
  /* The centering power trio: */
  display: inline-grid;                          /* shrink to content width */
  margin: 0 auto;                                /* center as block */
  align-self: center;                            /* center as flex item */

  grid-template-columns: repeat(5, var(--cat-col-pc));
  grid-auto-rows: var(--cat-row-h);
  gap: 10px;

  background-color: var(--color-surface);
  padding: 0;
}

/* Tile visuals (height fixed by grid-auto-rows) with 2-line clamp */
.category-container div {
  /* text clamp to two lines with ellipsis */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  text-align: center;

  color: var(--color-text);
  background-color: var(--color-bg);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.95rem;
  line-height: 1.2;

  cursor: pointer;
  transition: background-color .2s, border-color .2s, box-shadow .2s, color .2s, transform .05s;
}

/* Hover / focus / active / selected */
.category-container div:hover {
  border-color: var(--color-text);
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
  transform: translateY(-1px);
}
.category-container div:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.category-container div:active { transform: translateY(0); }
.category-container div[aria-pressed="true"] {
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
  border-color: var(--color-accent);
  color: var(--color-accent);
  font-weight: 600;
}

/* =========================================================
   Behaviors & themes
   ========================================================= */

/* Hover behavior for description (PC only) */
@media (min-width: 768px) {
  h1:hover + .search-form + p#description.description { opacity: 1; }
}

/* Dark mode */
[data-theme="dark"] .index-body { background: #1a1a1a; }
[data-theme="dark"] p#description.description { color: #fff; }
[data-theme="dark"] .search-input {
  background: #2a2a2a; color: #fff; border-color: #e67e00;
}
[data-theme="dark"] .search-input:focus {
  border-color: #fff; box-shadow: 0 0 5px rgba(230, 126, 0, 0.3);
}

/* Modern mode */
[data-theme="modern"] .index-body { background: #182036; }
[data-theme="modern"] p#description.description { color: #fff; }
[data-theme="modern"] .search-input {
  background: #2a2a2a; color: #fff; border-color: #e67e00;
}
[data-theme="modern"] .search-input:focus {
  border-color: #fff; box-shadow: 0 0 5px rgba(230, 126, 0, 0.3);
}

/* Light mode tweak */
[data-theme="light"] .search-input:focus {
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}

/* =========================================================
   Responsive — Mobile: 2 equal columns
   ========================================================= */
@media (max-width: 768px) {
  h1 { font-size: 1.9rem; }

  p#description.description {
    font-size: 1rem;
    max-width: 90%;
    opacity: 1;
  }
  .search-input { max-width: 90%; }

  .category-container {
    grid-template-columns: repeat(2, var(--cat-col-mob));
    grid-auto-rows: var(--cat-row-h-mobile);
  }
  .category-container div {
	  padding: 4px 6px;
  }
}

/* High-res small screens */
@media (min-width: 481px) and (max-width: 767px),
       (max-width: 767px) and (min-resolution: 2dppx) {

  h1 { font-size: 1.9rem; }

  p#description.description {
    font-size: 0.9rem;
    line-height: 1rem;
    max-width: 95%;
    opacity: 0.0;
  }
  .query-display { margin-top: 5px; }

  .category-container {
    grid-template-columns: repeat(2, var(--cat-col-mob)) !important;
    grid-auto-rows: var(--cat-row-h-mobile);
  }
  .category-container div {
	  padding: 4px 6px;
  }
}
