:root {
  color-scheme: light dark;
  --bg: #fff;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --accent: #2563eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #eaeaea;
    --muted: #9aa0a6;
    --border: #2c2f36;
    --accent: #6ea8fe;
  }
}

* {
  box-sizing: border-box;
}

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

header {
  padding: 2rem 1.5rem 1rem;
  max-width: 60rem;
  margin: 0 auto;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 2rem;
}

.tagline {
  margin: 0 0 0.5rem;
  color: var(--muted);
}

.source-note {
  font-size: 0.85rem;
  color: var(--muted);
}

.source-note a {
  color: var(--accent);
}

#filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  padding: 0 1.5rem 1rem;
  max-width: 60rem;
  margin: 0 auto;
}

#filters label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--muted);
  gap: 0.25rem;
}

#filters select,
#filters input {
  font-size: 0.95rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

#result-count {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: auto;
  align-self: center;
}

#sort-note {
  max-width: 60rem;
  margin: -0.5rem auto 1rem;
  padding: 0 1.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-style: italic;
}

#sort-note.hidden {
  display: none;
}

main#gallery {
  /* CSS grid with a fine-grained row unit, not multi-column -- columns
     read top-to-bottom-then-across, which reorders photos out of scrape/
     rank order. Each card's grid-row-end span is set in JS (app.js) from
     its actual rendered height, so cards keep left-to-right/top-to-bottom
     order while a tall portrait card doesn't force its row-neighbors to
     match its height. */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  grid-auto-rows: 10px;
  gap: 1rem;
  padding: 0 1.5rem 2rem;
  max-width: 90rem;
  margin: 0 auto;
  /* Critical: without this, grid's default "stretch" clamps every card to
     a single 10px auto-row before app.js gets a chance to measure its
     real height and set grid-row-end -- the measurement itself would be
     reading the clamped box, not the card's intended content height. */
  align-items: start;
}

.card {
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--border);
  position: relative;
}

.card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9; /* overridden inline per-card for portrait originals */
  object-fit: cover;
}

.card .card-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem 0.6rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
  color: #fff;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.card:hover .card-meta {
  opacity: 1;
}

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 1.5rem;
}

#lightbox.hidden {
  display: none;
}

#lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#lightbox-img {
  max-width: 90vw;
  max-height: 75vh;
  border-radius: 6px;
}

#lightbox-info {
  color: #fff;
  font-size: 0.85rem;
  margin-top: 0.75rem;
  text-align: center;
  max-width: 40rem;
}

#lightbox-info a {
  color: #9ecbff;
}

#lightbox-close {
  position: absolute;
  top: -2.5rem;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

footer {
  padding: 2rem 1.5rem 3rem;
  max-width: 60rem;
  margin: 0 auto;
  color: var(--muted);
  font-size: 0.8rem;
}

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