/* ==========================================================================
   Athendria Wiki — Fresh Editorial Compendium Stylesheet
   ========================================================================== */

:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-alt: #f0ebe1;
  --border: #e2dacb;
  --border-strong: #cfc3ae;
  --text: #1e242b;
  --text-muted: #5a6472;
  --heading: #151b24;
  --accent: #9b6b1f;
  --accent-hover: #7c5314;
  --accent-soft: rgba(155, 107, 31, 0.12);
  --header-bg: #18212f;
  --header-text: #f3f5f8;
  --header-muted: #b5c0d0;
  --header-border: #2a374b;
  --ikesh: #49507f;
  --kamuin: #a3393b;
  --ebrea: #3c8639;
  --shadow-sm: 0 1px 3px rgba(24, 33, 47, 0.06);
  --shadow-md: 0 6px 20px rgba(24, 33, 47, 0.08);
  --shadow-lg: 0 14px 36px rgba(24, 33, 47, 0.16);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-serif: "Cambria", "Georgia", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --header-height: 64px;
}

[data-theme="dark"] {
  --bg: #11161f;
  --surface: #18202c;
  --surface-alt: #1f2938;
  --border: #2a3649;
  --border-strong: #3b4b64;
  --text: #e2e8f0;
  --text-muted: #9aa7b8;
  --heading: #f8fafc;
  --accent: #d8a648;
  --accent-hover: #ecc16e;
  --accent-soft: rgba(216, 166, 72, 0.16);
  --header-bg: #0c1017;
  --header-text: #f1f5f9;
  --header-muted: #94a3b8;
  --header-border: #1e293b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.5);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 20px);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

h1, h2, h3, h4, h5 {
  font-family: var(--font-serif);
  color: var(--heading);
  line-height: 1.25;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

h1 { font-size: 2.1rem; margin-top: 0; }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.08rem; }
h5 { font-size: 1rem; color: var(--accent); letter-spacing: 0.01em; }

p {
  margin-top: 0;
  margin-bottom: 1em;
}

img {
  max-width: 100%;
  height: auto;
}

/* ---------- Header & Navigation ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 900;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid var(--header-border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--header-text);
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover {
  color: #f4d38a;
  text-decoration: none;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #c79335, #8f5c14);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--header-border);
  color: var(--header-text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 1.1rem;
  cursor: pointer;
  margin-left: auto;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}

.nav-link {
  color: var(--header-muted);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  text-decoration: none;
}

.nav-link.active {
  background: rgba(216, 166, 72, 0.22);
  color: #f7d996;
  font-weight: 600;
}

.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.nav-dot.ikesh { background: #747ec2; }
.nav-dot.kamuin { background: #dc5b5d; }
.nav-dot.ebrea { background: #5cc458; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* ---------- Global Search Bar ---------- */

.search-box {
  position: relative;
  width: 260px;
}

.search-form {
  display: flex;
  align-items: center;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 7px 34px 7px 32px;
  border-radius: 999px;
  border: 1px solid var(--header-border);
  background: rgba(255, 255, 255, 0.08);
  color: var(--header-text);
  font-size: 0.88rem;
  font-family: var(--font-sans);
  outline: none;
  transition: background 0.15s ease, border-color 0.15s ease, width 0.2s ease;
}

.search-input::placeholder {
  color: var(--header-muted);
}

.search-input:focus {
  background: rgba(255, 255, 255, 0.14);
  border-color: #d8a648;
}

.search-icon {
  position: absolute;
  left: 11px;
  color: var(--header-muted);
  pointer-events: none;
  font-size: 0.85rem;
}

.search-kbd {
  position: absolute;
  right: 10px;
  font-size: 0.72rem;
  color: var(--header-muted);
  border: 1px solid var(--header-border);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 1.5;
  pointer-events: none;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(440px, 92vw);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 1000;
}

.search-dropdown.open {
  display: block;
}

.search-dropdown-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}

.search-dropdown-item:hover,
.search-dropdown-item.selected {
  background: var(--surface-alt);
  text-decoration: none;
}

.search-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

.search-item-title {
  font-weight: 600;
  color: var(--heading);
  font-size: 0.93rem;
}

.search-page-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.search-item-snippet {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-dropdown-footer {
  display: block;
  padding: 10px 14px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--accent);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.search-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

mark {
  background: rgba(232, 181, 67, 0.35);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

.theme-toggle {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--header-border);
  color: var(--header-text);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* ---------- Page Layout ---------- */

.page-shell {
  max-width: 1360px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 64px;
  flex: 1;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.page-shell.no-sidebar {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1040px;
}

/* ---------- Sidebar Table of Contents ---------- */

.toc-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 20px);
  max-height: calc(100vh - var(--header-height) - 40px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.toc-title {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list li {
  margin: 2px 0;
}

.toc-list a {
  display: block;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.35;
  text-decoration: none;
  border-left: 2px solid transparent;
}

.toc-list a:hover {
  background: var(--surface-alt);
  color: var(--heading);
}

.toc-list a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.toc-list .toc-sub {
  padding-left: 18px;
  font-size: 0.8rem;
}

/* ---------- Main Content ---------- */

.main-content {
  min-width: 0;
}

.page-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 28px 30px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.page-hero.theme-ikesh { border-top-color: var(--ikesh); }
.page-hero.theme-kamuin { border-top-color: var(--kamuin); }
.page-hero.theme-ebrea { border-top-color: var(--ebrea); }

.page-kicker {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
  margin-bottom: 6px;
}

.page-hero.theme-ikesh .page-kicker { color: #5b65a6; }
.page-hero.theme-kamuin .page-kicker { color: #b84244; }
.page-hero.theme-ebrea .page-kicker { color: #3c8639; }

.page-subtitle {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Home Continent Cards ---------- */

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin: 20px 0 28px;
}

.quick-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.quick-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

.quick-card.ikesh { border-top-color: var(--ikesh); }
.quick-card.kamuin { border-top-color: var(--kamuin); }
.quick-card.ebrea { border-top-color: var(--ebrea); }

.quick-card h3 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.quick-card p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* ---------- Interactive Continent Map ---------- */

.map-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.map-status {
  font-weight: 600;
  color: var(--accent);
  min-height: 1.2em;
}

.map-stage {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #141923;
}

.map-stage img {
  display: block;
  width: 100%;
  height: auto;
}

.map-stage svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-stage svg path {
  cursor: pointer;
  transition: fill 0.2s ease, opacity 0.2s ease;
}

.map-stage svg path:hover {
  fill: rgba(220, 62, 62, 0.72) !important;
  stroke: #ffffff !important;
  stroke-width: 1.5;
}

.map-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 1200;
  background: rgba(18, 25, 38, 0.94);
  color: #f8fafc;
  border: 1px solid rgba(216, 166, 72, 0.55);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: none;
  white-space: nowrap;
}

/* ---------- Controls Bar (Filter + Sort) ---------- */

.list-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0 18px;
}

.filter-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  outline: none;
}

.filter-input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--heading);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: var(--surface-alt);
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* ---------- Lore Entry Cards ---------- */

.entry-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.entry-card > h2:first-child,
.entry-card > h3:first-child {
  margin-top: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.entry-card img,
.content-card img {
  display: block;
  max-width: 100%;
  width: auto !important;
  max-height: 460px;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 14px 0;
  border: 1px solid var(--border);
  cursor: zoom-in;
  box-shadow: var(--shadow-sm);
}

.entry-card ul,
.content-card ul {
  padding-left: 22px;
  margin-bottom: 1em;
}

.entry-card li,
.content-card li {
  margin-bottom: 0.4em;
}

.section-heading-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 28px 0 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.section-heading-bar h2 {
  margin: 0;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.94rem;
}

th, td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  background: var(--surface-alt);
  color: var(--heading);
  font-weight: 700;
}

tr:last-child td {
  border-bottom: none;
}

/* ---------- Search Results Page ---------- */

.search-hero-form {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.search-hero-input {
  flex: 1;
  padding: 11px 16px;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.search-hero-input:focus {
  border-color: var(--accent);
}

.search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0;
}

.filter-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.search-result-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 12px;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.search-result-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}

.search-result-card h3 {
  margin: 0 0 6px;
  font-size: 1.12rem;
}

.search-result-card p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* ---------- Highlight Pulse ---------- */

@keyframes targetPulse {
  0% { box-shadow: 0 0 0 0 rgba(216, 166, 72, 0.7); border-color: var(--accent); }
  50% { box-shadow: 0 0 0 8px rgba(216, 166, 72, 0.18); border-color: var(--accent); }
  100% { box-shadow: var(--shadow-sm); }
}

.search-target-highlight {
  animation: targetPulse 1.8s ease-out;
}

/* ---------- Image Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(10, 14, 22, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}

.lightbox.open {
  display: flex;
}

.lightbox-inner {
  max-width: 92vw;
  max-height: 90vh;
  text-align: center;
}

.lightbox-inner img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.lightbox-caption {
  color: #e2e8f0;
  margin-top: 10px;
  font-size: 0.95rem;
}

/* ---------- Back to Top & Footer ---------- */

.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 800;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--heading);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  font-size: 1.1rem;
  display: none;
  align-items: center;
  justify-content: center;
}

.back-to-top.visible {
  display: inline-flex;
}

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .page-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .toc-sidebar {
    position: static;
    max-height: 260px;
  }
}

@media (max-width: 920px) {
  .nav-toggle {
    display: inline-flex;
  }
  .site-nav {
    display: none;
    width: 100%;
    padding: 10px 0 14px;
    border-top: 1px solid var(--header-border);
    flex-direction: column;
    align-items: stretch;
  }
  .site-nav.open {
    display: flex;
  }
  .header-actions {
    width: 100%;
    margin-left: 0;
    padding-bottom: 10px;
  }
  .search-box {
    flex: 1;
    width: auto;
  }
}
