:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2430;
  --muted: #5b6472;
  --border: #e2e5ea;
  --accent: #2f6fed;
  --accent-soft: #eaf1ff;
  --accent-text: #ffffff;
  --radius: 10px;

  /* Fallback letter-tile palette, cycled per card so same-letter fallbacks
     (e.g. two sites with no discoverable favicon both starting with "T")
     don't render as identical-looking tiles. */
  --tile-bg-0: var(--accent-soft);
  --tile-fg-0: var(--accent);
  --tile-bg-1: #e3f6f3;
  --tile-fg-1: #12897f;
  --tile-bg-2: #f1eaff;
  --tile-fg-2: #7c3aed;
  --tile-bg-3: #fff3dc;
  --tile-fg-3: #b7791f;
  --tile-bg-4: #ffe9ee;
  --tile-fg-4: #c2255c;
  --tile-bg-5: #e8f7e6;
  --tile-fg-5: #2f9e44;
  --tile-bg-6: #eceafd;
  --tile-fg-6: #5b4fd6;
  --tile-bg-7: #fbe9df;
  --tile-fg-7: #c05621;
  --shadow: 0 1px 2px rgba(20, 25, 35, 0.06), 0 1px 8px rgba(20, 25, 35, 0.04);
  --shadow-hover: 0 4px 14px rgba(20, 25, 35, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --surface: #1c2029;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --border: #2b313c;
    --accent: #6f9dff;
    --accent-soft: #232c40;
    --accent-text: #10131a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 8px rgba(0, 0, 0, 0.25);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.45);

    --tile-bg-0: var(--accent-soft);
    --tile-fg-0: var(--accent);
    --tile-bg-1: #163330;
    --tile-fg-1: #4fd8c4;
    --tile-bg-2: #2a2140;
    --tile-fg-2: #b794f6;
    --tile-bg-3: #3a2f14;
    --tile-fg-3: #f0b429;
    --tile-bg-4: #3a1620;
    --tile-fg-4: #f783ac;
    --tile-bg-5: #1c3320;
    --tile-fg-5: #69db7c;
    --tile-bg-6: #211f3d;
    --tile-fg-6: #9f97f0;
    --tile-bg-7: #3a2015;
    --tile-fg-7: #f6a96a;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
}

/* Keyboard focus is always visible, but the ring is not painted for mouse
   clicks (:focus-visible), so it never reads as a stuck selection. */
a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0.6rem 1rem;
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  left: 0;
}

/* ---------- Header ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.site-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
}

.site-nav a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.site-nav a.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- Search ---------- */

.search-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.search-bar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  position: relative;
}

.search-input {
  width: 100%;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.6rem 2.4rem 0.6rem 1rem;
}

.search-input::placeholder {
  color: var(--muted);
}

/* Suppress the native clear widget - .search-clear is the styled one, and
   showing both puts two crosses in the field. */
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search-clear {
  position: absolute;
  right: 1.9rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.3rem;
}

.search-clear:hover {
  color: var(--text);
}

.search-status {
  color: var(--muted);
}

/* ---------- Layout ---------- */

main,
.search-results {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

.page-heading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.25rem 0 0.25rem;
  font-size: 1.6rem;
}

.page-heading .icon {
  font-size: 1.6rem;
}

.page-intro {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

/* ---------- How-to blurb (homepage) ---------- */

.how-to {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  margin: 0 0 1.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.how-to p {
  margin: 0;
}

.how-to strong {
  color: var(--text);
}

.how-to kbd {
  font-family: inherit;
  font-size: 0.82rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  color: var(--text);
}

/* ---------- Jump nav ---------- */

.jump-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 2rem;
}

.jump-nav a {
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}

.jump-nav a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- Subject tiles (homepage) ---------- */

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.subject-tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.subject-tile:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.subject-tile .icon {
  font-size: 1.8rem;
  display: block;
  margin-bottom: 0.5rem;
}

.subject-tile .name {
  font-weight: 700;
  display: block;
}

.subject-tile .tally {
  color: var(--muted);
  font-size: 0.82rem;
}

/* ---------- Sub-areas ---------- */

.subarea {
  margin-bottom: 2.25rem;
  scroll-margin-top: 4.5rem;
}

.subarea h2 {
  font-size: 1.15rem;
  margin: 0 0 0.9rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.subarea h2 .count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}

/* ---------- Cards ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.card-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* The letter tile is hidden until the favicon actually fails: the inline
   onerror drops the <img> and adds .no-logo, which reveals the letter. That
   ordering avoids both a broken-image icon and a letter flashing behind a
   favicon that is still loading. */
.card-logo-wrap {
  position: relative;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 6px;
  background: var(--tile-bg-0);
  display: block;
}

.card-logo-wrap[data-tile="1"] { background: var(--tile-bg-1); }
.card-logo-wrap[data-tile="2"] { background: var(--tile-bg-2); }
.card-logo-wrap[data-tile="3"] { background: var(--tile-bg-3); }
.card-logo-wrap[data-tile="4"] { background: var(--tile-bg-4); }
.card-logo-wrap[data-tile="5"] { background: var(--tile-bg-5); }
.card-logo-wrap[data-tile="6"] { background: var(--tile-bg-6); }
.card-logo-wrap[data-tile="7"] { background: var(--tile-bg-7); }

.card-logo-wrap::before {
  content: attr(data-letter);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--tile-fg-0);
  opacity: 0;
}

.card-logo-wrap[data-tile="1"]::before { color: var(--tile-fg-1); }
.card-logo-wrap[data-tile="2"]::before { color: var(--tile-fg-2); }
.card-logo-wrap[data-tile="3"]::before { color: var(--tile-fg-3); }
.card-logo-wrap[data-tile="4"]::before { color: var(--tile-fg-4); }
.card-logo-wrap[data-tile="5"]::before { color: var(--tile-fg-5); }
.card-logo-wrap[data-tile="6"]::before { color: var(--tile-fg-6); }
.card-logo-wrap[data-tile="7"]::before { color: var(--tile-fg-7); }

.card-logo-wrap.no-logo::before {
  opacity: 1;
}

.card-logo {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
  background: var(--surface);
  display: block;
}

.card-title {
  font-weight: 700;
  font-size: 1rem;
}

.card-desc {
  color: var(--muted);
  font-size: 0.9rem;
  display: block;
}

.card-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.card-url {
  font-size: 0.78rem;
  color: var(--accent);
  word-break: break-word;
  margin-top: auto;
}

/* ---------- Footer ---------- */

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 2rem 1rem;
}

.site-footer p {
  margin: 0.25rem 0;
}

.footer-credit a {
  color: inherit;
  text-decoration: none;
}

.footer-credit a:hover {
  color: var(--accent);
  text-decoration: underline;
}

@media (max-width: 480px) {
  .site-header-inner {
    padding: 0.75rem 1rem;
  }

  main,
  .search-results,
  .search-bar-inner {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .card-grid,
  .subject-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
