/* === Fonts === */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

/* === Custom Properties === */
:root {
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --radius: 0.5rem;
  --cols: 3;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
}

html.dark {
  --bg: #09090b;
  --surface: #18181b;
  --border: #27272a;
  --text: #fafafa;
  --text-muted: #71717a;
}

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

html {
  -webkit-font-smoothing: antialiased;
  scrollbar-color: var(--text-muted) transparent;
}
* { scrollbar-width: thin; }
::selection { background: var(--accent); color: #fff; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  transition: background-color 0.2s, color 0.2s;
}

/* === Skip Link === */
.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 200;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-mono);
  background: var(--accent);
  color: #fff;
}
.skip-link:focus { position: fixed; top: 0.5rem; left: 0.5rem; }

/* === App Shell === */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* === Header === */
.site-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.header-brand { display: flex; align-items: center; gap: 0.625rem; }
.header-icon { font-size: 1.125rem; }
.header-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  font-family: var(--font-mono);
}
.header-nav { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }

/* === Buttons === */
.btn-icon {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  font-family: var(--font-mono);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--text-muted); }

/* === Filter Bar === */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s;
}
.filter-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* View tabs */
.view-tabs {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.view-tab {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  border-radius: calc(var(--radius) - 2px);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.view-tab[aria-selected="true"] {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
html.dark .view-tab[aria-selected="true"] { background: var(--border); }
.view-tab:hover:not([aria-selected="true"]) { color: var(--text); }
.view-tab-count { margin-left: 0.25rem; font-size: 0.625rem; opacity: 0.6; }

/* Search box */
.search-box {
  flex: 1;
  min-width: 120px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-icon { color: var(--text-muted); flex-shrink: 0; }
.search-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.875rem;
  color: var(--text);
  font-family: var(--font-mono);
}
.search-input::placeholder { color: var(--text-muted); }
.search-clear {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  transition: color 0.15s;
}
.search-clear:hover { color: var(--text); }

/* Filter actions */
.filter-actions { display: flex; align-items: center; gap: 0.5rem; }
.btn-sm {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm:hover { color: var(--text); border-color: var(--text-muted); }
.zip-btn { display: inline-flex; align-items: center; gap: 0.25rem; }
.zip-btn:disabled { opacity: 0.5; cursor: wait; }
.count-display {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Tag row */
.tag-row { display: flex; align-items: flex-start; gap: 0.5rem; margin-top: 0.75rem; }
.tag-toggle { flex-shrink: 0; margin-top: 0.125rem; }
.tag-toggle.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tag-toggle.is-active:hover {
  color: #fff;
  border-color: var(--accent);
}

/* Size filter row */
.size-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.size-pill {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.size-pill:hover { border-color: var(--text-muted); color: var(--text); }
.size-pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Tag pills */
.tag-list { display: none; flex-wrap: wrap; gap: 0.375rem; }
.tag-list.is-open { display: flex; }
.tag-pill {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.tag-pill:hover { border-color: var(--text-muted); color: var(--text); }
.tag-pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* === Wallpaper Grid === */
.wallpaper-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 1rem;
  padding: 1.25rem;
}
@media (max-width: 1024px) { .wallpaper-grid { --cols: 2; } }
@media (max-width: 640px) { .wallpaper-grid { --cols: 1; } }

/* === Wallpaper Card === */
wallpaper-card { display: block; }
.card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.2s;
}
.card:hover, .card:focus-visible {
  border-color: var(--text-muted);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.card:focus-visible { border-color: var(--accent); }
.card-media-wrap {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  aspect-ratio: 16/10;
}
.card img.card-media,
.card video.card-media {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.card img.card-media.is-loaded,
.card video.card-media { opacity: 1; }

/* Badges */
.card-badges {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  display: flex;
  gap: 0.25rem;
  z-index: 2;
}
.card-badge {
  padding: 0.125rem 0.5rem;
  font-size: 0.625rem;
  font-weight: 600;
  font-family: var(--font-mono);
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.card-badge-theme {
  background: rgba(0,0,0,0.6);
  color: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
}
.card-badge-size {
  background: var(--accent);
  color: #fff;
}

/* Favorite star (idle) */
.card-fav-idle {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  color: var(--accent);
  font-size: 0.875rem;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
  z-index: 2;
}

/* Card overlay */
.card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.75rem;
  background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0.3) 50%, transparent);
  opacity: 0;
  transition: opacity 0.2s;
}
.card:hover .card-overlay,
.card:focus-within .card-overlay { opacity: 1; }
.card-overlay-fav { position: absolute; top: 0.5rem; right: 0.5rem; }
.card-overlay-fav button {
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: color 0.15s;
  background: rgba(0,0,0,0.3);
  color: rgba(255,255,255,0.6);
}
.card-overlay-fav button:hover { color: var(--accent); }
.card-overlay-fav button.is-fav { color: var(--accent); background: rgba(0,0,0,0.4); }
.card-title {
  font-size: 0.75rem;
  font-weight: 500;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 0.5rem;
  font-family: var(--font-mono);
}
.card-actions { display: flex; gap: 0.375rem; }
.card-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  border-radius: calc(var(--radius) - 2px);
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}
.card-btn-primary { background: var(--accent); color: #fff; }
.card-btn-primary:hover { background: var(--accent-hover); }
.card-btn-secondary { background: rgba(255,255,255,0.15); color: #fff; backdrop-filter: blur(4px); }
.card-btn-secondary:hover { background: rgba(255,255,255,0.25); }

/* === Lightbox === */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.92);
  backdrop-filter: blur(8px);
  animation: fade-in 0.2s ease-out;
}
.lightbox {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  width: 100%;
  margin: 0 1rem;
  outline: none;
  display: flex;
  flex-direction: column;
}
.lightbox-hints {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.lightbox-hint-text {
  font-size: 0.625rem;
  font-family: var(--font-mono);
  color: rgba(255,255,255,0.4);
}
.lightbox-counter {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: rgba(255,255,255,0.4);
  font-variant-numeric: tabular-nums;
}
.lightbox-close {
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font-mono);
  padding: 0.125rem 0.25rem;
  border-radius: var(--radius);
  transition: color 0.15s;
}
.lightbox-close:hover { color: #fff; }
.lightbox-content {
  border-radius: 0.75rem;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.lightbox-nav:hover { background: rgba(0,0,0,0.7); color: #fff; }
.lightbox-nav-prev { left: 0.75rem; }
.lightbox-nav-next { right: 0.75rem; }
.lightbox-media {
  width: 100%;
  height: auto;
  display: block;
  max-height: 75vh;
  object-fit: contain;
  background: #000;
}
.lightbox-info {
  padding: 1rem;
  border-top: 1px solid var(--border);
}
.lightbox-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.lightbox-title {
  font-size: 0.875rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}
.lightbox-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}
.lightbox-tag { font-size: 0.75rem; color: var(--text-muted); }
.lightbox-dim {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.lightbox-size-badge {
  font-size: 0.625rem;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 0.125rem 0.375rem;
  border-radius: 9999px;
  background: var(--accent);
  color: #fff;
  text-transform: uppercase;
}
.lightbox-filesize {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}
.lightbox-fav-btn {
  font-size: 1.125rem;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: color 0.15s;
  padding: 0.125rem 0.25rem;
  border-radius: var(--radius);
}
.lightbox-fav-btn.is-fav { color: var(--accent); }
.lightbox-fav-btn:not(.is-fav) { color: var(--border); }
.lightbox-fav-btn:not(.is-fav):hover { color: var(--accent); }
.lightbox-action-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.lightbox-copy-btn {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
html.dark .lightbox-copy-btn { background: var(--border); }
.lightbox-copy-btn:hover { background: var(--border); color: var(--text); }
.lightbox-download-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-mono);
  border-radius: calc(var(--radius) - 2px);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}
.lightbox-download-btn:hover { background: var(--accent-hover); }

/* === Info Overlay (lightbox) === */
.lightbox-info-toggle {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 10;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font-mono);
  transition: background 0.15s;
}
.lightbox-info-toggle:hover { background: rgba(0,0,0,0.7); }

/* === Toast === */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 0.625rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--border);
  color: #10b981;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  animation: toast-in 0.3s ease-out;
}

/* === States === */
.state-container { display: flex; align-items: center; justify-content: center; padding: 8rem 0; }
.state-empty { text-align: center; }
.state-empty-icon { font-size: 1.875rem; margin-bottom: 0.75rem; opacity: 0.3; }
.state-text { font-size: 0.875rem; font-family: var(--font-mono); }

/* === Animations === */
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === Utility === */
.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;
}
