/* ─── Custom Properties ─────────────────────────────────────── */
:root {
  --bg: #0f0f14;
  --bg-card: #1a1a24;
  --bg-input: #1e1e2e;
  --border: #2a2a3a;
  --text: #e4e4ec;
  --text-muted: #8888a0;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --radius: 12px;
  --gap: 14px;
  --header-h: 64px;
  --max-w: 1320px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --error-bg: #3b1120;
  --error-text: #fca5a5;
}

[data-theme="light"] {
  --bg: #f5f5f8;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --border: #e0e0e8;
  --text: #1a1a2e;
  --text-muted: #6b6b80;
  --accent: #4f46e5;
  --accent-glow: rgba(79, 70, 229, 0.15);
  --shadow: 0 2px 16px rgba(0,0,0,0.08);
  --error-bg: #fee2e2;
  --error-text: #991b1b;
}

/* ─── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { display: block; max-width: 100%; height: auto; }

/* ─── Header ──────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.header-inner {
  display: flex; align-items: center; gap: 16px;
  max-width: var(--max-w); margin: 0 auto;
  padding: 12px 20px; height: var(--header-h);
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.1rem; color: var(--text);
  flex-shrink: 0;
}
.logo:hover { text-decoration: none; opacity: 0.85; }

/* Search bar */
.search-bar-wrapper { flex: 1; max-width: 560px; }
.search-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 28px; padding: 0 18px; height: 42px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-icon { flex-shrink: 0; color: var(--text-muted); }
.search-input {
  flex: 1; border: none; outline: none; background: transparent;
  color: var(--text); font-size: 0.95rem; min-width: 0;
}
.search-input::placeholder { color: var(--text-muted); }
.clear-btn {
  flex-shrink: 0; border: none; background: none; cursor: pointer;
  color: var(--text-muted); padding: 4px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.clear-btn:hover { color: var(--text); background: var(--border); }

/* Theme toggle */
.theme-toggle {
  flex-shrink: 0; border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text); cursor: pointer; border-radius: 50%; width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.theme-toggle:hover { border-color: var(--accent); }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="light"] .moon-icon { display: none; }

/* ─── Masonry Grid ────────────────────────────────────────── */
.masonry {
  max-width: var(--max-w);
  margin: 24px auto;
  padding: 0 20px;
  columns: 4;
  column-gap: var(--gap);
}
@media (max-width: 1024px) { .masonry { columns: 3; } }
@media (max-width: 768px)  { .masonry { columns: 2; } }
@media (max-width: 480px)  { .masonry { columns: 1; } }

/* ─── Photo Card ──────────────────────────────────────────── */
.card {
  break-inside: avoid;
  margin-bottom: var(--gap);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
.card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.card-img { width: 100%; display: block; }

.card-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  padding: 32px 12px 12px;
  opacity: 0; transition: opacity 0.25s;
  display: flex; flex-direction: column; gap: 2px;
}
.card:hover .card-overlay, .card:focus-visible .card-overlay { opacity: 1; }
@media (hover: none) { .card-overlay { opacity: 1; background: linear-gradient(transparent, rgba(0,0,0,0.55)); } }

.card-source {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: #fff;
  background: var(--accent); align-self: flex-start;
  padding: 2px 8px; border-radius: 4px;
}
.card-photographer { font-size: 0.78rem; color: rgba(255,255,255,0.85); }

/* ─── Spinner ────────────────────────────────────────────── */
.spinner-wrapper {
  display: flex; justify-content: center; padding: 24px;
}
.spinner-wrapper[hidden] { display: none; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Skeleton ────────────────────────────────────────────── */
.skeleton {
  break-inside: avoid;
  margin-bottom: var(--gap);
  border-radius: var(--radius);
  background: var(--border);
  animation: pulse 1.5s ease-in-out infinite;
}
.skeleton::before {
  content: '';
  display: block;
  /* random-ish heights via nth-child */
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ─── Error Banner ────────────────────────────────────────── */
.error-banner {
  max-width: var(--max-w); margin: 20px auto 0; padding: 12px 20px;
  background: var(--error-bg); color: var(--error-text);
  border-radius: var(--radius); font-size: 0.9rem;
  display: flex; align-items: center; gap: 10px;
}
.error-banner[hidden] { display: none; }

/* ─── Empty State ─────────────────────────────────────────── */
.empty-state {
  max-width: 400px; margin: 80px auto; text-align: center;
  color: var(--text-muted);
}
.empty-state p { margin-top: 12px; font-size: 1rem; }
.empty-state[hidden] { display: none; }

/* ─── Load Sentinel ───────────────────────────────────────── */
.load-sentinel {
  height: 1px; width: 100%;
}
.load-sentinel[hidden] { display: none; }

/* ─── Footer ──────────────────────────────────────────────── */
.footer {
  text-align: center; padding: 32px 20px;
  color: var(--text-muted); font-size: 0.8rem;
  border-top: 1px solid var(--border); margin-top: 40px;
}
.footer a { color: var(--text-muted); }
.footer a:hover { color: var(--text); }
