:root {
  --bg: #1c1c1e;
  --surface: #2a2a2c;
  --surface-hover: #333335;
  --border: #3d3d40;
  --text: #e8e8ea;
  --muted: #9b9b9e;
  --accent: #4ade80;
  --accent-dim: #37a866;
  --link: #8fd6ac;
  --max-width: 760px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.32);
  --ease: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(74, 222, 128, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 48px 20px 80px;
}

.logo {
  display: block;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  margin-top: 0;
  margin-bottom: 20px;
  transition: margin-top 320ms ease;
}

.logo span {
  color: var(--accent);
}

/* Homepage: search bar centered and tabs hidden, same shape as a classic
   search-engine homepage. Pushing the logo down (everything else follows
   in normal flow) is enough to center the whole search block — reverts
   the moment a real search runs (app.js#goToResults). */
body.is-home .logo {
  margin-top: 18vh;
}

body.is-home .tabs-row {
  display: none;
}

.search-wrap {
  position: relative;
}

.search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 13px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--ease), box-shadow var(--ease);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.18);
}

.search-bar button {
  padding: 13px 22px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #10130f;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--ease), transform var(--ease), box-shadow var(--ease);
}

.search-bar button:hover {
  background: #5eeb92;
  box-shadow: var(--shadow-md);
}

.search-bar button:active {
  transform: scale(0.97);
}

.tabs-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 20px;
  border-bottom: 1px solid var(--border);
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
  /* Permanent fade at the trailing edge — a quiet hint that this bar
     scrolls for more tabs, without needing JS to detect overflow. */
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(to right, black calc(100% - 22px), transparent 100%);
}

.tabs::-webkit-scrollbar {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.region-picker {
  flex: 0 0 auto;
  padding-bottom: 6px;
}

.region-picker select {
  appearance: none;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  padding: 5px 10px;
  cursor: pointer;
  transition: color var(--ease), border-color var(--ease);
}

.region-picker select:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}

.suggestions li {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  font-size: 0.95rem;
}

.suggestions li:hover,
.suggestions li.active {
  background: var(--surface-hover);
}

.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: color var(--ease), border-color var(--ease);
}

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

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.status {
  margin-top: 24px;
  color: var(--muted);
  text-align: center;
}

.results-section {
  margin-top: 32px;
}

.results-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 12px;
}

#network-results h2 {
  color: var(--accent);
}

.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.result-item .site-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  color: #10130f;
  background: var(--accent);
  border-radius: 4px;
  padding: 1px 6px;
  margin-bottom: 4px;
}

.result-item .engine-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin-bottom: 4px;
}

.result-item .result-url {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.result-item .result-title {
  font-size: 1.05rem;
  color: var(--link);
  text-decoration: none;
}

.result-item .result-title:hover {
  text-decoration: underline;
}

.result-item .result-desc {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.4;
}

/* Shared "card" look for every grid-based tab (images/videos/marketplace) */
.result-list.grid-images .result-item,
.result-list.grid-videos .result-item,
.result-list.grid-marketplace .result-item {
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease);
}

/* Only lift on hover for devices that actually have hover (mouse/trackpad)
   — on touch, :hover can stick "on" after a tap with no way to un-hover. */
@media (hover: hover) and (pointer: fine) {
  .result-list.grid-images .result-item:hover,
  .result-list.grid-videos .result-item:hover,
  .result-list.grid-marketplace .result-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-dim);
  }
}

/* Images tab: responsive thumbnail grid instead of the default list */
.result-list.grid-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.result-list.grid-images .result-item a {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.result-list.grid-images .result-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-hover);
  display: block;
}

.result-list.grid-images .result-caption {
  padding: 8px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Videos tab: cards with a wide thumbnail */
.result-list.grid-videos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.result-list.grid-videos .result-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--surface-hover);
  display: block;
}

.result-list.grid-videos .result-item .result-title,
.result-list.grid-videos .result-item .result-url,
.result-list.grid-videos .result-item .result-desc {
  padding-left: 10px;
  padding-right: 10px;
}

.result-list.grid-videos .result-item .result-title {
  display: block;
  margin-top: 8px;
}

.result-list.grid-videos .result-item .result-desc {
  padding-bottom: 10px;
}

/* Business tab */
.result-item .result-address {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Video duration pill over the thumbnail */
.thumb-wrap {
  position: relative;
  display: block;
}

.thumb-duration {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 0.72rem;
  padding: 1px 5px;
  border-radius: 3px;
}

/* Music tab: compact rows, not a grid */
.result-list.list-music {
  gap: 4px;
}

.result-list.list-music .result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.result-list.list-music .result-item:hover {
  border-color: var(--accent-dim);
  box-shadow: var(--shadow-sm);
}

.music-row {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}

.music-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface-hover);
  flex: 0 0 auto;
}

.music-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.music-artist {
  font-size: 0.8rem;
  color: var(--muted);
}

.music-length {
  font-size: 0.8rem;
  color: var(--muted);
  flex: 0 0 auto;
}

/* Marketplace tab: image grid with a price badge in the caption */
.result-list.grid-marketplace {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.result-list.grid-marketplace .result-item a {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.result-list.grid-marketplace .result-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-hover);
  display: block;
}

.result-list.grid-marketplace .result-caption {
  display: block;
  padding: 8px 10px;
}

.result-title-inline {
  display: block;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.price-badge {
  display: inline-block;
  margin-top: 4px;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------ */
/* Mobile                                                              */
/* ------------------------------------------------------------------ */
@media (max-width: 640px) {
  .page {
    padding: 28px 14px 56px;
  }

  .logo {
    flex: 1 0 100%;
    font-size: 1.35rem;
    margin-bottom: 12px;
  }

  .search-bar input,
  .search-bar button {
    padding: 11px 16px;
    font-size: 0.95rem;
  }

  /* Region picker drops to its own line so tabs get the full row width —
     sharing the row left too little room to show more than 3-4 tabs
     before the scrollable overflow, with no clear affordance they existed. */
  .tabs-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .tabs {
    flex: 1 1 100%;
  }

  .region-picker {
    flex: 1 1 100%;
    padding-bottom: 10px;
  }

  .region-picker select {
    width: 100%;
    font-size: 0.8rem;
    padding: 7px 10px;
  }

  .tab {
    padding: 9px 10px;
    font-size: 0.85rem;
  }

  .result-list.grid-images {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
  }

  .result-list.grid-videos {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }

  .result-list.grid-marketplace {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  .result-item .result-title {
    font-size: 1rem;
  }
}

/* Network switcher — Google-apps-style grid launcher, fixed top-right
   regardless of homepage/results state. Every network site shares the
   same branding, so tiles are text-only rather than per-site icons. */
.network-switcher-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color var(--ease);
}

.network-switcher-btn:hover,
.network-switcher-btn[aria-expanded="true"] {
  background: var(--surface-hover);
}

/* Nine dots via a single element's box-shadow, rather than nine real
   elements — same visual result, no extra markup. */
.grid-dots {
  position: relative;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow:
    -8px -8px 0 var(--muted), 0 -8px 0 var(--muted), 8px -8px 0 var(--muted),
    -8px 0 0 var(--muted), 8px 0 0 var(--muted),
    -8px 8px 0 var(--muted), 0 8px 0 var(--muted), 8px 8px 0 var(--muted);
}

.network-switcher-btn:hover .grid-dots,
.network-switcher-btn[aria-expanded="true"] .grid-dots {
  background: var(--text);
  box-shadow:
    -8px -8px 0 var(--text), 0 -8px 0 var(--text), 8px -8px 0 var(--text),
    -8px 0 0 var(--text), 8px 0 0 var(--text),
    -8px 8px 0 var(--text), 0 8px 0 var(--text), 8px 8px 0 var(--text);
}

.network-switcher-menu {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, 84px);
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.network-switcher-menu[hidden] {
  display: none;
}

.network-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  aspect-ratio: 1;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  transition: background-color var(--ease), color var(--ease);
}

.network-tile:hover {
  background: var(--accent);
  color: #10130f;
}

.network-tile.current {
  color: var(--accent);
  border: 1px solid var(--accent-dim);
}

@media (max-width: 640px) {
  .network-switcher-menu {
    grid-template-columns: repeat(3, 1fr);
    left: 16px;
    right: 16px;
  }
}
