/* ==========================================================================
   Tool grid — the homepage's primary way of presenting 126 tools.
   Replaces the six list-style group blocks with one searchable field of
   icon tiles. Each tile carries the family hue, so colour does the first
   pass of navigation and the label confirms it.
   ========================================================================== */

.tg { display: grid; gap: 14px; }

/* ---------- search + filters --------------------------------------------- */
.tg__bar {
  display: grid;
  gap: 10px;
  position: sticky;
  top: var(--hdr-h, 64px);
  z-index: 30;
  padding: 12px 0;
  background: linear-gradient(var(--ink-900) 70%, transparent);
  backdrop-filter: blur(6px);
}

.tg__field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 48px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--ink-800);
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.tg__field:focus-within {
  border-color: var(--phosphor);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--phosphor) 22%, transparent);
}
.tg__field > svg {
  width: 18px; height: 18px; flex: none;
  stroke: var(--text-300); fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.tg__field input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  background: none;
  color: var(--text-100);
  font-family: var(--font-text);
  font-size: 0.9375rem;
}
.tg__field input::placeholder { color: var(--text-400); }
.tg__field input:focus { outline: none; }
.tg__field input::-webkit-search-cancel-button { display: none; }

.tg__clear {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 50%;
  background: var(--ink-700);
  color: var(--text-200);
  cursor: pointer;
  transition: background-color 140ms, color 140ms;
}
.tg__clear:hover { background: var(--ink-600, #2a2f36); color: var(--text-100); }
.tg__clear svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.tg__clear[hidden] { display: none; }

.tg__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tg__chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--ink-800);
  color: var(--text-200);
  font-family: var(--font-text);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 140ms, color 140ms, background-color 140ms;
}
.tg__chip:hover { border-color: var(--text-300); color: var(--text-100); }
.tg__chip[aria-pressed="true"] {
  border-color: var(--chip-hue, var(--phosphor));
  color: var(--text-100);
  background: color-mix(in srgb, var(--chip-hue, var(--phosphor)) 14%, var(--ink-800));
}
.tg__chip-dot {
  width: 7px; height: 7px; flex: none;
  border-radius: 50%;
  background: var(--chip-hue, var(--text-300));
}
.tg__chip-n { font-family: var(--font-mono); font-size: 0.6875rem; color: var(--text-400); }
.tg__chip[aria-pressed="true"] .tg__chip-n { color: var(--text-200); }

.tg__count {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-400);
}
.tg__count b { color: var(--text-200); font-weight: 600; }

/* ---------- the grid ------------------------------------------------------ */
.tg__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
  gap: 8px;
}

.tg__tile {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line-1);
  border-radius: var(--radius-sm);
  background: var(--ink-800);
  color: var(--text-100);
  text-decoration: none;
  transition: border-color 150ms var(--ease-out), background-color 150ms var(--ease-out),
              transform 150ms var(--ease-out);
}
.tg__tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--tile-hue, var(--phosphor));
  opacity: 0;
  transition: opacity 150ms var(--ease-out);
}
.tg__tile:hover,
.tg__tile:focus-visible {
  border-color: color-mix(in srgb, var(--tile-hue, var(--phosphor)) 55%, var(--line-2));
  background: var(--ink-750, #191d22);
  transform: translateY(-1px);
}
.tg__tile:hover::before,
.tg__tile:focus-visible::before { opacity: 1; }
.tg__tile:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tg__tile[hidden] { display: none; }

.tg__ic {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex: none;
  border-radius: var(--radius-xs);
  background: color-mix(in srgb, var(--tile-hue, var(--phosphor)) 12%, var(--ink-700));
  color: var(--tile-hue, var(--phosphor));
}
/* Phosphor at 12% is a fill, not a text surface; the stroke needs the
   text-safe token to stay above 3:1 on its own tinted chip. */
[data-theme="dark"] .tg__ic { color: var(--tile-hue-text, var(--phosphor-text)); }
.tg__ic svg {
  width: 21px; height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tg__txt { display: grid; gap: 2px; min-width: 0; }
.tg__name {
  font-family: var(--font-text);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.005em;
  color: var(--text-100);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.tg__fam {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-400);
}

/* ---------- mobile fold ---------------------------------------------------- */
.tg__tile[data-tg-cut] { display: none; }
.tg__fold {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  margin-top: 4px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--ink-800);
  color: var(--text-100);
  font-family: var(--font-text);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 150ms, background-color 150ms;
}
.tg__fold:hover { border-color: var(--text-300); background: var(--ink-750, #191d22); }
.tg__fold[hidden] { display: none; }
.tg__fold svg {
  width: 15px; height: 15px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- empty state ---------------------------------------------------- */
.tg__empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 56px 20px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
  text-align: center;
}
.tg__empty[hidden] { display: none; }
.tg__empty svg { width: 30px; height: 30px; stroke: var(--text-400); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tg__empty-t { font-family: var(--font-display); font-size: 1.0625rem; font-weight: 700; color: var(--text-100); }
.tg__empty-d { font-size: 0.875rem; color: var(--text-300); max-width: 38ch; line-height: 1.6; }
.tg__empty-b {
  margin-top: 4px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--ink-800);
  color: var(--text-100);
  font-family: var(--font-text);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.tg__empty-b:hover { border-color: var(--text-300); }

/* ---------- mobile ---------------------------------------------------------- */
@media (max-width: 640px) {
  /* One column, not two: a 2-up grid turns 126 tools into a 63-row wall
     ~14,000px tall. A single column of wide rows is faster to scan and
     each row is a full-width target. */
  .tg__grid { grid-template-columns: minmax(0, 1fr); gap: 5px; }
  .tg__tile { min-height: 56px; padding: 8px 12px; gap: 11px; }
  .tg__ic { width: 34px; height: 34px; }
  .tg__ic svg { width: 19px; height: 19px; }
  .tg__name { font-size: 0.8125rem; }
  /* Family label is redundant on a one-column list where every row shows
     the same family while a chip is active; keep it but shrink the gap. */
  .tg__txt { gap: 1px; }

  /* 37px chips are under the 44px touch minimum once the row wraps. */
  .tg__chip { min-height: 44px; padding: 0 14px; }
  .tg__chips { gap: 6px; }
  .tg__field { height: 52px; }

  /* The sticky bar would cover a third of the screen once chips wrap to
     three rows on a phone; static keeps the grid usable. */
  .tg__bar { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  .tg__tile, .tg__tile::before { transition: none; }
  .tg__tile:hover, .tg__tile:focus-visible { transform: none; }
}
