:root {
  color-scheme: dark;
  --bg: #080b11;
  --surface: #101621;
  --line: #253144;
  --text: #f2f6fb;
  --muted: #99a8ba;
  --accent: #66d9ff;
  --danger: #ff8f70;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }

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

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(20rem, 52rem) 1fr;
  gap: 1rem;
  align-items: center;
  padding: 0.9rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.brand {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  font-size: 0.95rem;
  font-weight: 720;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 2.15rem;
  height: 2.15rem;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 800;
}

.search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(102 217 255 / 13%);
}

.search input {
  min-width: 0;
  padding: 0.78rem 0.95rem;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.94rem;
}

.search input::placeholder { color: #738297; }

.search button {
  padding: 0.7rem 1.1rem;
  border: 0;
  color: #061016;
  background: var(--accent);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.search button:hover { background: #a0e9ff; }

.syntax {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.syntax button {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  white-space: nowrap;
  cursor: pointer;
}

.syntax button:hover,
.syntax button:focus-visible {
  border-color: #54728e;
  color: var(--text);
  outline: 0;
}

main {
  width: min(100%, 112rem);
  margin: 0 auto;
  padding: 1.3rem clamp(1rem, 3vw, 2.5rem) 4rem;
}

.results-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.results-heading h1 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.results-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.8rem;
}

.card {
  position: relative;
  overflow: hidden;
  min-height: 19rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  transition: border-color 120ms ease;
}

.card:hover,
.card:focus-within {
  border-color: #4c708d;
}

.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.image-shell {
  position: relative;
  display: grid;
  aspect-ratio: 4 / 3;
  place-items: center;
  overflow: hidden;
  color: #738297;
  background: #0c111a;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.image-shell img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-shell img.failed { display: none; }

.image-shell img.full-image {
  opacity: 0;
  transition: opacity 180ms ease;
}

.image-shell img.full-image.loaded { opacity: 1; }

.rating {
  position: absolute;
  z-index: 1;
  top: 0.65rem;
  left: 0.65rem;
  min-width: 1.8rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid rgb(255 255 255 / 15%);
  border-radius: 0;
  color: white;
  background: rgb(8 11 17 / 76%);
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.card-body { padding: 0.8rem; }

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.post-id {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
}

.score { color: var(--accent); }

.tags {
  display: -webkit-box;
  min-height: 2.7rem;
  margin: 0.65rem 0 0;
  overflow: hidden;
  color: #b6c2d0;
  font-size: 0.77rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.empty {
  display: grid;
  min-height: 18rem;
  place-content: center;
  gap: 0.45rem;
  color: var(--muted);
  text-align: center;
}

.empty[hidden] { display: none; }

.empty strong {
  color: var(--text);
  font-size: 1.15rem;
}

.sentinel {
  display: grid;
  height: 6rem;
  place-items: center;
}

.loader {
  width: 1.6rem;
  height: 1.6rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0;
  animation: spin 700ms linear infinite;
}

.sentinel.loading .loader { opacity: 1; }
.error { color: var(--danger) !important; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 76rem) {
  .topbar { grid-template-columns: auto minmax(0, 1fr); }
  .syntax {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 42rem) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }
  .brand { display: none; }
  .syntax { grid-column: auto; }
  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }
  .card { min-height: 14rem; }
  .card-body { padding: 0.65rem; }
  .card-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.25rem;
  }
}

@media (max-width: 27rem) {
  .gallery { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
