*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a1f;
  --bg-card: #24242b;
  --bg-card-hover: #2e2e38;
  --text: #e0e0e0;
  --text-muted: #999;
  --accent: #c9a96e;
  --border: #3a3a44;
  --radius: 8px;
  --max-width: 1400px;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ─────────────────────────────── */

.page-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
  text-align: center;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.page-header .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Navigation ──────────────────────────── */

.nav-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background 0.15s, border-color 0.15s;
}

.nav-back:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.nav-back svg {
  width: 16px;
  height: 16px;
}

/* ── Alphabet Filter ─────────────────────── */

.alpha-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  justify-content: center;
}

.alpha-filter a,
.alpha-filter span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.alpha-filter a:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.alpha-filter a.active {
  background: var(--accent);
  color: #1a1a1f;
  font-weight: 600;
}

.alpha-filter span.empty {
  opacity: 0.3;
  cursor: default;
}

/* ── Character Grid ──────────────────────── */

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

.char-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  border: 1px solid var(--border);
}

.char-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.char-card-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--bg);
}

.char-card-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 2.5rem;
}

.char-card-name {
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-card-count {
  padding: 0 0.75rem 0.6rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Character Page ──────────────────────── */

.char-profile {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.char-portrait {
  width: 250px;
  height: 250px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.char-info {
  flex: 1;
  min-width: 280px;
}

.char-info h2 {
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.char-info .meta-row {
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
}

.char-info .meta-row strong {
  color: var(--text);
  font-weight: 500;
}

/* ── Family Section ──────────────────────── */

.family-section {
  margin-bottom: 2rem;
}

.family-section h3 {
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.family-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.family-link {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}

.family-link:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

/* ── Gallery Grid (character page) ───────── */

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

.gallery-item {
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s;
}

.gallery-item:hover {
  transform: scale(1.02);
  border-color: var(--accent);
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

/* ── Lightbox ────────────────────────────── */

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.lightbox.active {
  display: flex;
}

.lightbox img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
}

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

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.5rem;
  color: #fff;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  padding: 0.5rem 1rem;
  line-height: 1;
  border-radius: 4px;
  transition: background 0.15s;
}

.lightbox-nav:hover {
  background: rgba(0, 0, 0, 0.8);
}

.lightbox-prev {
  left: 1rem;
}

.lightbox-next {
  right: 1rem;
}

.lightbox-counter {
  color: var(--text-muted);
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

/* ── Loading / Error ─────────────────────── */

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.error-msg {
  text-align: center;
  padding: 2rem;
  color: #e05555;
}

/* ── Responsive ──────────────────────────── */

@media (max-width: 768px) {
  .char-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.6rem;
  }

  .char-card-name {
    font-size: 0.78rem;
    padding: 0.45rem 0.5rem;
  }

  .page-header h1 {
    font-size: 1.4rem;
  }

  .container {
    padding: 1rem;
  }

  .char-profile {
    gap: 1rem;
    justify-content: center;
  }

  .char-portrait {
    width: 180px;
    height: 180px;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
  }
}