
:root {
  --bg-primary: #faf6f0;
  --bg-secondary: #f0e8dc;
  --bg-card: #ffffff;
  --text-primary: #2d1810;
  --text-secondary: #5a3e2b;
  --accent: #8b1a1a;
  --accent-light: #c23b22;
  --gold: #b8860b;
  --gold-light: #daa520;
  --border: #d4c5b2;
  --shadow: rgba(45, 24, 16, 0.1);
  --tag-bg: #f5ebe0;
  --tag-text: #6b4423;
}

[data-theme="dark"] {
  --bg-primary: #1a1410;
  --bg-secondary: #2a2018;
  --bg-card: #332820;
  --text-primary: #e8dcc8;
  --text-secondary: #b8a890;
  --accent: #e04040;
  --accent-light: #ff6b5a;
  --gold: #daa520;
  --gold-light: #ffd700;
  --border: #4a3a28;
  --shadow: rgba(0, 0, 0, 0.3);
  --tag-bg: #3a2a1a;
  --tag-text: #d4b896;
}

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

body {
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.8;
  min-height: 100vh;
}

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

.broken-ref { color: #999; font-style: italic; }

/* ── Header ── */
.site-header {
  background: linear-gradient(135deg, var(--accent) 0%, #4a0e0e 100%);
  color: #f5ebe0;
  padding: 1.5rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px var(--shadow);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.site-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}
.site-title a { color: #f5ebe0; }
.site-title a:hover { text-decoration: none; color: var(--gold-light); }

.header-nav {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  align-items: center;
}
.header-nav a {
  color: #e8dcc8;
  font-size: 0.95rem;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}
.header-nav a:hover {
  background: rgba(255,255,255,0.15);
  color: var(--gold-light);
  text-decoration: none;
}

.theme-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: #e8dcc8;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

/* ── Search ── */
.search-container {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 2rem;
}
.search-box {
  width: 100%;
  padding: 0.8rem 1.2rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color 0.2s;
}
.search-box:focus {
  outline: none;
  border-color: var(--gold);
}
.search-results {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
  display: none;
}
.search-results.active { display: block; }
.search-result-item {
  padding: 0.6rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-secondary); }
.search-result-type {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--tag-bg);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
}

/* ── Main Content ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-title {
  font-size: 2rem;
  color: var(--accent);
  border-bottom: 3px solid var(--gold);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

/* ── Cards Grid ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 1.5rem 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--shadow);
}

.card h3 {
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
}
.card h3 a { color: var(--text-primary); }
.card h3 a:hover { color: var(--accent); }

.card .meta { font-size: 0.85rem; color: var(--text-secondary); }

.card .desc {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Tags ── */
.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  margin-right: 0.3rem;
  margin-bottom: 0.3rem;
}
.tag.witch { background: #fde; color: #a33; }
.tag.human { background: #def; color: #358; }
.tag.demon { background: #432; color: #fa5; }
.tag.protagonist { background: var(--gold); color: #fff; }
.tag.major { background: var(--accent); color: #fff; }
.tag.alive { background: #dfd; color: #363; }
.tag.dead { background: #fdd; color: #933; }

/* ── Detail Page ── */
.detail-header {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.portrait-container {
  flex: 0 0 240px;
}
.portrait {
  width: 240px;
  height: 320px;
  border-radius: 12px;
  object-fit: cover;
  border: 3px solid var(--gold);
  background: var(--bg-secondary);
}
.portrait-placeholder {
  width: 240px;
  height: 320px;
  border-radius: 12px;
  border: 3px dashed var(--border);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.info-box {
  flex: 1;
  min-width: 300px;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
}
.info-table th {
  text-align: left;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  width: 120px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.info-table td {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.section {
  margin: 2rem 0;
}
.section h2 {
  font-size: 1.3rem;
  color: var(--accent);
  border-left: 4px solid var(--gold);
  padding-left: 0.8rem;
  margin-bottom: 1rem;
}

.ability-card {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 0.8rem;
}
.ability-name {
  font-weight: 700;
  color: var(--accent);
}
.ability-evolved {
  color: var(--gold);
  font-weight: 700;
}

.rel-list {
  list-style: none;
}
.rel-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.rel-list li:last-child { border-bottom: none; }
.rel-type {
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 0.5rem;
}

.faction-timeline {
  border-left: 3px solid var(--gold);
  padding-left: 1.5rem;
  margin-left: 0.5rem;
}
.faction-entry {
  position: relative;
  padding-bottom: 1rem;
}
.faction-entry::before {
  content: '';
  position: absolute;
  left: -1.75rem;
  top: 0.5rem;
  width: 10px;
  height: 10px;
  background: var(--gold);
  border-radius: 50%;
}

/* ── Category Filter ── */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.filter-btn {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.filter-btn:hover, .filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Timeline ── */
.timeline { position: relative; padding: 1rem 0; }
.timeline-volume {
  margin-bottom: 2rem;
}
.timeline-volume h3 {
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 1rem;
}
.timeline-event {
  display: flex;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border);
}
.timeline-chapter {
  flex: 0 0 80px;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
}

/* ── World Map ── */
.map-container {
  position: relative;
  width: 100%;
  overflow: auto;
}
.map-container img {
  max-width: 100%;
  display: block;
}
.map-marker {
  position: absolute;
  background: var(--accent);
  color: #fff;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.map-marker::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--accent);
}

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; text-align: center; }
  .container { padding: 1rem; }
  .detail-header { flex-direction: column; align-items: center; }
  .info-box { min-width: auto; }
  .card-grid { grid-template-columns: 1fr; }
  .portrait-container { flex: none; }
}

@media (max-width: 480px) {
  .site-title { font-size: 1.2rem; }
  .page-title { font-size: 1.4rem; }
  .header-nav { gap: 0.5rem; }
}
