:root {
  --hero-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
  --bg: #f6f5fb;
  --surface: #ffffff;
  --border: #e4e2ef;
  --text: #211f36;
  --text-soft: #6b6884;
  --primary: #7c5cf5;
  --primary-dark: #6344e0;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(40, 30, 80, 0.06);
  --shadow-lg: 0 12px 32px rgba(40, 30, 80, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Mitr", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; display: block; }

.loading-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 36px; height: 36px;
  border: 4px solid #e4e2ef;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Top nav ---------------- */
.topnav {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  gap: 20px;
  padding: 12px 28px;
}
.topnav-logo {
  font-weight: 700; font-size: 20px; color: var(--primary-dark);
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
.topnav-logo .badge {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--hero-grad);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.topnav-tabs { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.topnav-tab {
  padding: 8px 16px; border-radius: 999px; border: 1px solid transparent;
  color: var(--text-soft); font-size: 14px; cursor: pointer; white-space: nowrap;
  background: transparent;
}
.topnav-tab:hover { background: var(--bg); }
.topnav-tab.active { background: var(--primary); color: #fff; }
.topnav-mainlink {
  font-size: 13px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-soft);
  white-space: nowrap;
}
.topnav-mainlink:hover { border-color: var(--primary); color: var(--primary); }

/* ---------------- Hero ---------------- */
.hero {
  background: var(--hero-grad);
  color: #fff;
  padding: 40px 28px 56px;
  text-align: center;
}
.hero h1 { margin: 0 0 8px; font-size: 30px; font-weight: 700; }
.hero p { margin: 0; opacity: 0.9; font-size: 14px; }

/* ---------------- Filter bar ---------------- */
.filters {
  max-width: 1200px; margin: -32px auto 0; padding: 0 20px;
}
.filters-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 14px;
}
.search-row { display: flex; gap: 10px; }
.search-input {
  flex: 1; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  font-size: 14px;
}
.search-input:focus { outline: none; border-color: var(--primary); }

.tag-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
  padding: 5px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
  border: 1.5px solid transparent; background: #f0eef9; color: var(--text-soft);
}
.tag-chip.active { color: #fff; }

.char-filter-label { font-size: 13px; color: var(--text-soft); margin-bottom: 6px; }
.char-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px; max-height: 160px; overflow-y: auto;
}
.char-chip {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 2px; border-radius: 10px; cursor: pointer; border: 2px solid transparent;
  font-size: 10px; text-align: center; color: var(--text-soft);
}
.char-chip img {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: #eee;
}
.char-chip.active { border-color: var(--primary); background: #f0eef9; color: var(--primary-dark); }
.char-filter-row { display: flex; align-items: center; justify-content: space-between; }
.char-filter-clear {
  font-size: 12px; color: var(--primary); cursor: pointer; background: none; border: none;
}
.char-dropdown { display: none; }

/* ---------------- Grid ---------------- */
.content { max-width: 1200px; margin: 0 auto; padding: 26px 20px 60px; }
.result-count { font-size: 13px; color: var(--text-soft); margin-bottom: 14px; }
.card-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px;
}
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease;
  border: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card-thumb {
  aspect-ratio: 1 / 1; background: #eee; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; }
.card-tag-dot { font-size: 10px; padding: 2px 7px; border-radius: 999px; color: #fff; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-soft); }

/* ---------------- Detail modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 15, 45, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 200;
}
.modal-panel {
  background: var(--surface); border-radius: 16px; max-width: 760px; width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text-soft); }
.modal-body { padding: 20px 22px 26px; display: flex; flex-direction: column; gap: 18px; }
.modal-media-tabs { display: flex; gap: 8px; }
.modal-media-tab {
  padding: 6px 14px; border-radius: 999px; font-size: 13px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; color: var(--text-soft);
}
.modal-media-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.modal-media-preview {
  width: 100%; max-width: 420px; margin: 0 auto; border-radius: 12px; overflow: hidden;
  background: #f2f1f8; aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center;
}
.modal-media-preview img { width: 100%; height: 100%; object-fit: contain; }
.modal-section-label { font-size: 12px; color: var(--text-soft); margin-bottom: 4px; }
.modal-section-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.modal-char-grid {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.modal-char-item { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 56px; }
.modal-char-item img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #eee; }
.modal-char-item span { font-size: 10px; color: var(--text-soft); text-align: center; }

/* ---------------- Footer ---------------- */
.site-footer {
  background: #1c1a2e; color: #cfcbe6; padding: 32px 20px; margin-top: 40px;
}
.footer-inner {
  max-width: 1200px; margin: 0 auto; display: flex; flex-wrap: wrap;
  align-items: center; justify-content: space-between; gap: 16px;
}
.footer-links { display: flex; flex-wrap: wrap; gap: 18px; font-size: 13px; }
.footer-links a { color: #cfcbe6; }
.footer-links a:hover { color: #fff; }
.footer-copy { font-size: 12px; color: #8a86ac; margin-top: 14px; text-align: center; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
  .char-grid {
    display: flex; overflow-x: auto; max-height: none; padding-bottom: 4px;
  }
  .char-chip { min-width: 56px; }
}

@media (max-width: 620px) {
  .topnav { padding: 10px 14px; gap: 10px; }
  .topnav-mainlink { display: none; }
  .hero { padding: 28px 16px 44px; }
  .hero h1 { font-size: 22px; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .filters-card { padding: 14px; }
  .char-grid { display: none; }
  .char-dropdown {
    display: block; width: 100%; padding: 10px 12px; border-radius: 10px;
    border: 1px solid var(--border); font-size: 14px; background: #fff;
  }
}
