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

:root {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface2: #252840;
  --border: #2e3250;
  --accent: #6c63ff;
  --accent-hover: #857dff;
  --text: #e8eaf6;
  --text-muted: #7986cb;
  --card-radius: 8px;
  --transition: 0.15s ease;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.875rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.site-title:hover { color: var(--accent-hover); }

nav { display: flex; gap: 0.25rem; margin-left: auto; }

.nav-link {
  padding: 0.375rem 0.875rem;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover, .nav-link.active {
  background: var(--surface2);
  color: var(--text);
}

/* ── Main ── */
main {
  flex: 1;
  padding: 2rem 1.5rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ── Search page ── */
.search-hero {
  text-align: center;
  padding: 3rem 0 2rem;
}
.search-hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}
.search-hero p {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.search-wrap {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
}

.search-input {
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2);
}
.search-input::placeholder { color: var(--text-muted); }

.autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.autocomplete.hidden { display: none; }

.ac-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1.25rem;
  cursor: pointer;
  transition: background var(--transition);
}
.ac-item:hover, .ac-item.selected {
  background: var(--surface2);
}
.ac-name { font-weight: 500; }
.ac-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.ac-item:hover .ac-count, .ac-item.selected .ac-count {
  background: var(--border);
}

/* ── Gallery page ── */
.gallery-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.gallery-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.gallery-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.card-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.card-tile:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(108, 99, 255, 0.2);
}

.card-tile img {
  width: 100%;
  aspect-ratio: 2.5 / 3.5;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}

.card-meta {
  padding: 0.5rem 0.625rem 0.625rem;
}
.card-meta-name {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta-set {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  display: flex;
  gap: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  max-width: 600px;
  width: 100%;
  z-index: 1;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

@media (max-width: 480px) {
  .modal-content { flex-direction: column; }
}

.modal-content img {
  width: 220px;
  flex-shrink: 0;
  border-radius: 6px;
  align-self: flex-start;
}
@media (max-width: 480px) {
  .modal-content img { width: 100%; }
}

.modal-info { display: flex; flex-direction: column; gap: 0.5rem; padding-top: 0.25rem; }
.modal-info h2 { font-size: 1.25rem; font-weight: 700; }
.modal-info p { color: var(--text-muted); font-size: 0.9rem; }
.modal-info p span { color: var(--text); }

.modal-close {
  position: absolute;
  top: 0.75rem; right: 0.875rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }

/* ── States ── */
.loading, .empty, .error {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}
.error { color: #ef5350; }

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