/* ============================================
   WCFP Wiki - Fandom-Inspired Stylesheet
   ============================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --header-bg: #1a1a2e;
  --header-text: #f0f0f0;
  --sidebar-bg: #f8f9fa;
  --sidebar-border: #e0e0e0;
  --sidebar-width: 240px;
  --infobox-header: #2d6a4f;
  --infobox-bg: #f8f9fa;
  --infobox-border: #a2d9b1;
  --infobox-width: 320px;
  --link-color: #3366cc;
  --link-hover: #5577dd;
  --link-visited: #795cb2;
  --text-color: #202122;
  --text-muted: #72777d;
  --bg-color: #ffffff;
  --content-max: 1200px;
  --border-color: #e0e0e0;
  --toc-bg: #f8f9fa;
  --category-bg: #eef3f8;
  --category-border: #c8ccd1;
  --quote-border: #2d6a4f;
  --table-header: #eaecf0;
  --table-border: #a2a9b1;
  --spoiler-bg: #333333;
  --status-alive: #2d6a4f;
  --status-deceased: #b32424;
  --status-unknown: #72777d;
  --font-serif: "Linux Libertine", "Georgia", "Times", serif;
  --font-sans: -apple-system, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Consolas", "Monaco", "Courier New", monospace;
  --code-bg: #f4f4f4;
  --table-row-alt: #f8f9fa;
  --infobox-image-bg: #e8e8e8;
  --search-input-bg: rgba(255,255,255,0.1);
  --search-input-border: rgba(255,255,255,0.2);
  --search-input-focus-bg: rgba(255,255,255,0.2);
  --search-input-focus-border: rgba(255,255,255,0.4);
  --quote-bg: rgba(45, 106, 79, 0.05);
  --quote-text: #444;
}

/* Dark Mode */
[data-theme="dark"] {
  --header-bg: #0d0d1a;
  --header-text: #e0e0e0;
  --sidebar-bg: #1a1a2e;
  --sidebar-border: #2a2a4e;
  --infobox-header: #1f4d3a;
  --infobox-bg: #1e1e32;
  --infobox-border: #2d6a4f;
  --link-color: #6699ff;
  --link-hover: #88aaff;
  --link-visited: #b088dd;
  --text-color: #e0e0e0;
  --text-muted: #a0a0a0;
  --bg-color: #121220;
  --border-color: #2a2a4e;
  --toc-bg: #1a1a2e;
  --category-bg: #1e1e32;
  --category-border: #3a3a5e;
  --quote-border: #2d6a4f;
  --table-header: #1e1e32;
  --table-border: #3a3a5e;
  --spoiler-bg: #1a1a2e;
  --status-alive: #3d8a6f;
  --status-deceased: #cc4444;
  --status-unknown: #888888;
  --code-bg: #1e1e32;
  --table-row-alt: #1a1a2e;
  --infobox-image-bg: #2a2a4e;
  --search-input-bg: rgba(255,255,255,0.05);
  --search-input-border: rgba(255,255,255,0.15);
  --search-input-focus-bg: rgba(255,255,255,0.1);
  --search-input-focus-border: rgba(255,255,255,0.3);
  --quote-bg: rgba(45, 106, 79, 0.15);
  --quote-text: #c8c8c8;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  color: var(--text-color);
  background: var(--bg-color);
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Global Header ---------- */
.wiki-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0 24px;
  height: 55px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.wiki-header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--header-text);
}

.wiki-header-logo .logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
}

.wiki-header-title {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.wiki-header-subtitle {
  font-size: 11px;
  opacity: 0.7;
  margin-left: 8px;
}

.wiki-search {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wiki-search input {
  width: 280px;
  padding: 6px 12px;
  border: 1px solid var(--search-input-border);
  border-radius: 3px;
  background: var(--search-input-bg);
  color: white;
  font-size: 13px;
  outline: none;
  transition: all 0.2s;
}

.wiki-search input::placeholder {
  color: rgba(255,255,255,0.5);
}

.wiki-search input:focus {
  background: var(--search-input-focus-bg);
  border-color: var(--search-input-focus-border);
}

/* Dark Mode Toggle */
.theme-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--header-text);
  font-size: 16px;
  line-height: 1;
  transition: all 0.2s;
  margin-left: 12px;
}

.theme-toggle:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.3);
}

.wiki-search-results {
  position: absolute;
  top: 50px;
  right: 24px;
  width: 360px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: none;
  z-index: 1001;
}

.wiki-search-results.active {
  display: block;
}

.wiki-search-results a {
  display: block;
  padding: 10px 14px;
  color: var(--text-color);
  text-decoration: none;
  border-bottom: 1px solid var(--border-color);
}

.wiki-search-results a:hover {
  background: var(--sidebar-bg);
}

.wiki-search-results a:last-child {
  border-bottom: none;
}

.search-result-title {
  font-weight: 600;
  color: var(--link-color);
}

.search-result-type {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Layout ---------- */
.wiki-layout {
  display: flex;
  flex: 1;
}

/* ---------- Sidebar ---------- */
.wiki-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 16px 0;
  overflow-y: auto;
  height: calc(100vh - 55px);
  position: sticky;
  top: 55px;
  font-size: 13px;
}

/* Sidebar AO3 Link */
.sidebar-ao3 {
  padding: 12px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 8px;
}

.sidebar-ao3 a {
  display: block;
  padding: 8px 12px;
  background: var(--infobox-header);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  transition: background 0.2s;
}

.sidebar-ao3 a:hover {
  background: #245a42;
  text-decoration: none;
}

.sidebar-section {
  margin-bottom: 4px;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.sidebar-section-header:hover {
  color: var(--text-color);
}

.sidebar-section-header .chevron {
  transition: transform 0.2s;
  font-size: 10px;
}

.sidebar-section-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-links {
  list-style: none;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-links.collapsed {
  max-height: 0 !important;
}

/* Sidebar Subsections (for Episodes by Season) */
.sidebar-subsections {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-subsections.collapsed {
  max-height: 0 !important;
}

.sidebar-subsection {
  margin-left: 8px;
}

.sidebar-subsection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 6px 20px;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.sidebar-subsection-header:hover {
  color: var(--text-color);
}

.sidebar-subsection-header .chevron {
  transition: transform 0.2s;
  font-size: 9px;
}

.sidebar-subsection-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-subsection .sidebar-links {
  margin-left: 8px;
}

.sidebar-subsection .sidebar-links a {
  padding-left: 32px;
  font-size: 12px;
}

.sidebar-links a {
  display: block;
  padding: 5px 16px 5px 28px;
  color: var(--link-color);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.5;
  transition: background 0.15s;
}

.sidebar-links a:hover {
  background: rgba(0,0,0,0.04);
  text-decoration: underline;
}

.sidebar-links a.active {
  background: rgba(0,0,0,0.06);
  font-weight: 600;
  color: var(--text-color);
}

/* ---------- Content ---------- */
.wiki-content {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
  padding: 20px 28px 40px;
}

/* Page Title */
.page-title {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 400;
  line-height: 1.2;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
  margin-bottom: 16px;
}

/* ---------- Infobox ---------- */
.infobox {
  float: right;
  width: var(--infobox-width);
  margin: 0 0 16px 20px;
  border: 1px solid var(--infobox-border);
  border-radius: 2px;
  background: var(--infobox-bg);
  font-size: 13px;
  clear: right;
}

.infobox-header {
  background: var(--infobox-header);
  color: white;
  padding: 10px 14px;
  font-size: 17px;
  font-family: var(--font-serif);
  font-weight: 600;
  text-align: center;
}

.infobox-image {
  text-align: center;
  padding: 8px;
  background: var(--infobox-image-bg);
}

.infobox-image img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.infobox-image-caption {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 4px;
}

.infobox-section-header {
  background: var(--infobox-header);
  color: white;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.infobox-row {
  display: flex;
  border-top: 1px solid var(--infobox-border);
}

.infobox-label {
  width: 110px;
  min-width: 110px;
  padding: 6px 10px;
  font-weight: 600;
  background: rgba(0,0,0,0.02);
  vertical-align: top;
  color: var(--text-color);
}

.infobox-value {
  flex: 1;
  padding: 6px 10px;
}

.infobox-value a {
  color: var(--link-color);
  text-decoration: none;
}

.infobox-value a:hover {
  text-decoration: underline;
}

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

.status-alive { background: var(--status-alive); }
.status-deceased { background: var(--status-deceased); }
.status-unknown { background: var(--status-unknown); }
.status-escaped { background: #b8860b; }
.status-imprisoned { background: #8b4513; }

/* ---------- Table of Contents ---------- */
.toc {
  background: var(--toc-bg);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  margin-bottom: 20px;
  display: inline-block;
  min-width: 200px;
  max-width: 400px;
  font-size: 13px;
}

.toc-title {
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
  font-size: 14px;
}

.toc ol {
  margin: 0 !important;
  padding-left: 24px;
}

.toc li {
  margin: 3px 0;
}

.toc a {
  color: var(--link-color);
  text-decoration: none;
}

.toc a:hover {
  text-decoration: underline;
}

.toc ol ol {
  padding-left: 20px;
}

/* ---------- Content Styling ---------- */
.wiki-content h2 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 400;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
  margin-top: 28px;
  margin-bottom: 12px;
  clear: both;
}

.wiki-content h3 {
  font-size: 17px;
  font-weight: 600;
  margin-top: 22px;
  margin-bottom: 8px;
}

.wiki-content h4 {
  font-size: 15px;
  font-weight: 600;
  margin-top: 18px;
  margin-bottom: 6px;
}

.wiki-content p {
  margin-bottom: 12px;
}

.wiki-content a {
  color: var(--link-color);
  text-decoration: none;
}

.wiki-content a:hover {
  text-decoration: underline;
}

.wiki-content a:visited {
  color: var(--link-visited);
}

.wiki-content a.redlink {
  color: #cc3333;
}

.wiki-content strong {
  font-weight: 700;
}

.wiki-content em {
  font-style: italic;
}

.wiki-content ul, .wiki-content ol {
  margin: 0 0 12px 24px;
}

.wiki-content li {
  margin-bottom: 4px;
}

.wiki-content blockquote {
  border-left: 4px solid var(--quote-border);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--quote-bg);
  font-style: italic;
  color: var(--quote-text);
}

.wiki-content blockquote p {
  margin-bottom: 4px;
}

.wiki-content blockquote cite,
.wiki-content blockquote .quote-source {
  display: block;
  font-style: normal;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.wiki-content hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 24px 0;
}

.wiki-content img {
  max-width: 100%;
  height: auto;
}

.wiki-content code {
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.wiki-content pre {
  background: var(--code-bg);
  padding: 12px 16px;
  border-radius: 3px;
  overflow-x: auto;
  margin: 12px 0;
}

.wiki-content pre code {
  background: none;
  padding: 0;
}

/* Tables */
.wiki-content table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
}

.wiki-content table th {
  background: var(--table-header);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  border: 1px solid var(--table-border);
}

.wiki-content table td {
  padding: 6px 12px;
  border: 1px solid var(--table-border);
  vertical-align: top;
}

.wiki-content table tr:nth-child(even) {
  background: var(--table-row-alt);
}

/* ---------- Appearances Grid ---------- */
.appearances-grid {
  display: grid;
  grid-template-columns: auto repeat(24, 1fr);
  gap: 1px;
  background: var(--table-border);
  border: 1px solid var(--table-border);
  margin: 12px 0;
  font-size: 12px;
}

.appearances-grid .grid-header {
  background: var(--table-header);
  padding: 4px 6px;
  font-weight: 600;
  text-align: center;
}

.appearances-grid .grid-season {
  background: var(--table-header);
  padding: 4px 8px;
  font-weight: 600;
}

.appearances-grid .grid-cell {
  padding: 4px;
  text-align: center;
  background: white;
}

.grid-cell.appeared {
  background: #2d6a4f;
  color: white;
}

.grid-cell.absent {
  background: #d0d0d0;
}

.grid-cell.mentioned {
  background: #b8860b;
  color: white;
}

/* ---------- Categories ---------- */
.categories {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.categories-label {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.category-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.category-tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--category-bg);
  border: 1px solid var(--category-border);
  border-radius: 2px;
  font-size: 12px;
  color: var(--link-color);
  text-decoration: none;
  transition: background 0.15s;
}

.category-tag:hover {
  background: #dde3eb;
  text-decoration: none;
}

/* ---------- Episode Infobox Variant ---------- */
.infobox.episode-infobox {
  width: 300px;
}

.infobox.episode-infobox .infobox-header {
  font-size: 15px;
}

/* ---------- Hatnote ---------- */
.hatnote {
  font-style: italic;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-left: 20px;
  font-size: 13px;
}

/* ---------- Notice Boxes ---------- */
.notice-box {
  border: 1px solid;
  border-radius: 3px;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 13px;
}

.notice-box.spoiler {
  border-color: #c33;
  background: #fff5f5;
}

.notice-box.info {
  border-color: #3366cc;
  background: #f0f5ff;
}

.notice-box.warning {
  border-color: #cc9900;
  background: #fffcf0;
}

/* ---------- Quote Block (Epigraph) ---------- */
.epigraph {
  margin: 0 0 20px 0;
  padding: 12px 20px;
  border-left: 4px solid var(--infobox-header);
  background: rgba(45, 106, 79, 0.04);
  font-style: italic;
  font-size: 15px;
}

.epigraph .quote-source {
  font-style: normal;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Season Navigation (Episode Pages) ---------- */
.episode-nav {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.episode-nav a {
  color: var(--link-color);
  text-decoration: none;
  font-size: 13px;
}

.episode-nav a:hover {
  text-decoration: underline;
}

/* ---------- Footer ---------- */
.wiki-footer {
  background: var(--header-bg);
  color: rgba(255,255,255,0.6);
  text-align: center;
  padding: 16px;
  font-size: 12px;
  margin-top: auto;
}

.wiki-footer a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
}

.wiki-footer a:hover {
  text-decoration: underline;
}

/* ---------- Main Page Specific ---------- */
.main-page-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 20px 0;
}

.main-page-section {
  background: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 16px;
}

.main-page-section h3 {
  margin-top: 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--infobox-header);
  color: var(--infobox-header);
}

.main-page-section ul {
  margin: 8px 0 0 20px;
}

.main-page-section li {
  margin-bottom: 3px;
}

.main-page-hero {
  background: linear-gradient(135deg, #1a1a2e 0%, #2d6a4f 100%);
  color: white;
  padding: 32px;
  border-radius: 4px;
  margin-bottom: 24px;
  text-align: center;
}

.main-page-hero h2 {
  font-family: var(--font-serif);
  font-size: 32px;
  border: none;
  color: white;
  margin: 0 0 8px 0;
}

.main-page-hero p {
  font-size: 15px;
  opacity: 0.9;
  margin: 0;
}

.main-page-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 16px;
}

.stat-item {
  text-align: center;
}

.stat-number {
  font-size: 28px;
  font-weight: 700;
}

.stat-label {
  font-size: 12px;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .infobox {
    width: 280px;
  }
}

@media (max-width: 900px) {
  .wiki-sidebar {
    display: none;
  }

  .infobox {
    float: none;
    width: 100%;
    margin: 0 0 16px 0;
  }

  .main-page-grid {
    grid-template-columns: 1fr;
  }

  .wiki-search input {
    width: 200px;
  }
}

@media (max-width: 600px) {
  .wiki-content {
    padding: 12px 16px 32px;
  }

  .wiki-header {
    padding: 0 12px;
  }

  .wiki-header-subtitle {
    display: none;
  }

  .wiki-search input {
    width: 140px;
  }
}

/* ---------- Spoiler Warning Overlay ---------- */
.spoiler-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.spoiler-overlay.hidden {
  display: none;
}

.spoiler-dialog {
  background: var(--bg-color);
  border-radius: 8px;
  max-width: 520px;
  width: 100%;
  padding: 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.spoiler-dialog h2 {
  font-family: var(--font-serif);
  font-size: 28px;
  color: #cc3333;
  margin: 0 0 16px 0;
  border: none;
}

.spoiler-dialog .warning-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.spoiler-dialog p {
  color: var(--text-color);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.spoiler-dialog .note {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 24px;
}

.spoiler-dialog .rating-note {
  font-size: 13px;
  color: var(--text-color);
  background: rgba(204, 51, 51, 0.1);
  border-left: 3px solid #cc3333;
  padding: 8px 12px;
  margin-bottom: 24px;
  border-radius: 0 4px 4px 0;
}

.spoiler-dialog .ao3-link {
  display: inline-block;
  margin-bottom: 24px;
  padding: 10px 20px;
  background: var(--infobox-header);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 600;
  transition: background 0.2s;
}

.spoiler-dialog .ao3-link:hover {
  background: #245a42;
  text-decoration: none;
}

.spoiler-dialog .continue-btn {
  display: block;
  width: 100%;
  padding: 14px 24px;
  background: #cc3333;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.spoiler-dialog .continue-btn:hover {
  background: #aa2222;
}

.spoiler-dialog .continue-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 12px;
}

/* ---------- Print ---------- */
@media print {
  .wiki-header,
  .wiki-sidebar,
  .wiki-footer,
  .toc,
  .wiki-search {
    display: none !important;
  }

  .wiki-content {
    max-width: 100%;
    padding: 0;
  }

  .infobox {
    float: none;
    width: 100%;
    margin: 0 0 16px 0;
    break-inside: avoid;
  }
}
