:root {
  --ink: #2e2119;
  --muted: #6d5847;
  --red: #8c1d18;
  --red-dark: #5d100d;
  --gold: #b78a3f;
  --paper: #efe0bd;
  --paper-light: #f7eccf;
  --paper-dark: #d7bf8c;
  --night: #17110e;
  --night-soft: #241a15;
  --border: rgba(78, 48, 26, .38);
  --shadow: 0 14px 35px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--night); }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Libre Baskerville", Georgia, serif;
  background:
      radial-gradient(circle at 15% 10%, rgba(140, 29, 24, .18), transparent 28rem),
      radial-gradient(circle at 80% 30%, rgba(183, 138, 63, .10), transparent 30rem),
      linear-gradient(135deg, #100c0a, #241711 48%, #110d0a);
}

a { color: inherit; }

.compendium-shell { min-height: 100vh; display: flex; flex-direction: column; }

.site-header {
  color: #f6e8c9;
  background: rgba(18, 12, 9, .94);
  border-bottom: 2px solid var(--gold);
  box-shadow: 0 8px 25px rgba(0,0,0,.4);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.header-inner {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.brand strong { display: block; font: 700 1.1rem/1.2 "Cinzel", serif; letter-spacing: .04em; }
.brand small { display: block; color: #c9b58d; margin-top: 3px; }

.brand-mark {
  width: 48px; height: 48px; display: grid; place-items: center;
  border: 2px solid var(--gold); transform: rotate(45deg);
  font: 700 .85rem "Cinzel", serif; color: var(--gold);
}
.brand-mark::first-line { transform: rotate(-45deg); }

.header-search, .hero-search, .filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-search input, .hero-search input, .filter-bar input {
  min-width: 280px;
  border: 1px solid rgba(183,138,63,.55);
  background: rgba(255,255,255,.08);
  color: #fff7e2;
  border-radius: 4px;
  padding: 12px 14px;
  font: inherit;
}

.header-search input::placeholder, .hero-search input::placeholder { color: #c7b99d; }

button, .header-search button, .hero-search button, .filter-bar button {
  border: 0;
  background: linear-gradient(#a52b23, var(--red-dark));
  color: #fff4df;
  padding: 12px 17px;
  border-radius: 4px;
  font: 700 .78rem "Cinzel", serif;
  letter-spacing: .05em;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}

.main-nav {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.main-nav a {
  text-decoration: none;
  color: #d9c7a5;
  padding: 10px 14px 12px;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  font: 600 .76rem "Cinzel", serif;
}
.main-nav a:hover { color: white; border-bottom-color: var(--red); }

.page-wrap {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 70px;
  flex: 1;
}

.parchment {
  background:
      linear-gradient(rgba(255,255,255,.1), rgba(105,69,30,.05)),
      repeating-linear-gradient(0deg, rgba(90,50,20,.018) 0, rgba(90,50,20,.018) 1px, transparent 1px, transparent 4px),
      var(--paper);
  border: 1px solid var(--paper-dark);
  box-shadow: var(--shadow), inset 0 0 30px rgba(92,57,25,.08);
}

.hero {
  min-height: 390px;
  padding: 58px;
  display: grid;
  grid-template-columns: 1fr 280px;
  align-items: center;
  position: relative;
  overflow: hidden;
  border-top: 7px solid var(--red);
}
.hero::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(92,57,25,.28);
  pointer-events: none;
}
.hero h1, .chapter-header h1, .stat-header h1 {
  font: 700 clamp(2.2rem, 5vw, 4.7rem)/1.02 "Cinzel", serif;
  margin: 8px 0 18px;
  color: #45140f;
}
.hero p { max-width: 760px; font-size: 1.1rem; line-height: 1.75; }
.hero-search { margin-top: 28px; position: relative; z-index: 2; }
.hero-search input { flex: 1; background: rgba(255,255,255,.45); color: var(--ink); min-width: 0; }
.hero-sigil {
  width: 220px; height: 220px; display: grid; place-items: center;
  border: 8px double var(--red); color: var(--red); border-radius: 50%;
  font: 700 5rem "Cinzel", serif; transform: rotate(-8deg);
  opacity: .75;
}
.hero-sigil img {
  display: block;
  width: 220px;
  max-width: 100%;
  height: auto;

  filter:
      drop-shadow(0 12px 24px rgba(0, 0, 0, .35));
}

.eyebrow {
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: .14em;
  font: 700 .72rem "Cinzel", serif;
}

.section-heading { color: #f3e4c4; text-align: center; padding: 48px 0 24px; }
.section-heading span { color: #c6a66d; text-transform: uppercase; letter-spacing: .15em; font-size: .72rem; }
.section-heading h2 { font: 600 2rem "Cinzel", serif; margin: 8px 0; }

.family-grid, .entry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.family-card, .entry-card {
  text-decoration: none;
  padding: 24px;
  color: var(--ink);
  transition: transform .16s ease, box-shadow .16s ease;
}
.family-card { display: grid; grid-template-columns: 56px 1fr auto; gap: 16px; align-items: start; }
.family-card:hover, .entry-card:hover { transform: translateY(-3px); box-shadow: 0 18px 45px rgba(0,0,0,.38); }
.family-icon { font-size: 2rem; }
.family-card h3, .entry-card h2, .entry-card h3 { font: 700 1.15rem "Cinzel", serif; margin: 0 0 8px; color: #4c160f; }
.family-card p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.family-count { color: var(--red); font: 700 1rem "Cinzel", serif; }

.chapter-header, .stat-header {
  padding: 34px 38px;
  border-top: 6px solid var(--red);
  margin-bottom: 20px;
}
.chapter-header { display: flex; justify-content: space-between; gap: 30px; align-items: center; }
.chapter-header h1, .stat-header h1 { font-size: clamp(2rem, 4vw, 3.3rem); margin-bottom: 8px; }
.chapter-header p, .stat-subtitle { color: var(--muted); line-height: 1.55; margin: 0; }
.chapter-count { white-space: nowrap; font: 700 1rem "Cinzel", serif; color: var(--red); }

.filter-bar { padding: 16px; margin-bottom: 20px; }
.filter-bar input { flex: 1; background: rgba(255,255,255,.45); color: var(--ink); min-width: 0; }
.filter-bar a { color: var(--red); font-weight: bold; }

.entry-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.entry-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.entry-card-top { display: flex; justify-content: space-between; gap: 14px; }
.version-count { color: var(--red); font-size: .72rem; white-space: nowrap; }
.entry-summary, .source-list, .tag-list { display: flex; gap: 8px; flex-wrap: wrap; }
.entry-summary span, .source-list span, .tag-list span, .tag-strip span {
  background: rgba(92,57,25,.09);
  border: 1px solid rgba(92,57,25,.18);
  padding: 5px 8px;
  font-size: .72rem;
}
.source-list { margin-top: 14px; color: var(--muted); }

.pagination {
  margin-top: 24px;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.pagination a:last-child { text-align: right; }
.pagination a { color: var(--red); font-weight: bold; text-decoration: none; }

.search-section { margin-top: 36px; }
.search-section-heading { color: #f4e7cd; display: flex; justify-content: space-between; align-items: end; margin-bottom: 14px; }
.search-section-heading h2 { font: 600 1.7rem "Cinzel", serif; margin: 4px 0; }
.search-section-heading a { color: #dfba78; }

.entry-navigation { margin-bottom: 12px; }
.entry-navigation-links {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  color: #e8d5b4; font-size: .85rem;
}
.entry-navigation-links a { text-decoration: none; }
.entry-navigation-links a:last-child { text-align: right; }
.back-link { color: #d4a95e; font-family: "Cinzel", serif; }

.source-meta, .version-switcher { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.source-meta span, .version-switcher a {
  border: 1px solid rgba(92,57,25,.25);
  background: rgba(255,255,255,.22);
  padding: 7px 10px;
  font-size: .75rem;
  text-decoration: none;
}
.version-switcher { align-items: center; }
.version-switcher > span { color: var(--muted); margin-right: 4px; }
.version-switcher a.active { background: var(--red); border-color: var(--red); color: #fff5e5; }

.stat-ribbon, .ability-table {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 18px;
  overflow: hidden;
}
.stat-ribbon.three { grid-template-columns: repeat(3, 1fr); }
.stat-ribbon > div, .ability-table > div { padding: 20px; border-right: 1px solid var(--border); }
.stat-ribbon > div:last-child, .ability-table > div:last-child { border-right: 0; }
.stat-ribbon span, .ability-table span {
  display: block; color: var(--red); font: 700 .7rem "Cinzel", serif; text-transform: uppercase; margin-bottom: 6px;
}
.stat-ribbon strong { line-height: 1.5; }
.ability-table { grid-template-columns: repeat(6, 1fr); text-align: center; }
.ability-table strong { font-size: 1.35rem; }

.two-column-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .8fr); gap: 18px; align-items: start; }
.rule-section, .sidebar-card, .tag-strip { padding: 28px; margin-bottom: 18px; }
.rule-section > h2, .sidebar-card > h2 {
  color: var(--red-dark);
  font: 700 1.35rem "Cinzel", serif;
  margin: 0 0 20px;
  padding-bottom: 10px;
  border-bottom: 3px double rgba(140,29,24,.55);
}
.rule-block { padding: 3px 0 18px; }
.rule-block + .rule-block { border-top: 1px solid rgba(92,57,25,.18); padding-top: 18px; }
.rule-block h3, .rule-block h4 { display: inline; font: 700 1rem "Libre Baskerville", serif; color: #4e1b14; }
.rules-text { line-height: 1.72; }
.rules-text p:first-child { margin-top: 0; }
.rule-caption { color: var(--muted); font-style: italic; }
.nested-rules { margin: 14px 0 0 20px; padding-left: 18px; border-left: 3px solid rgba(140,29,24,.35); }

.sidebar-card dl, .reference-list { margin: 0; }
.sidebar-card dt, .reference-list dt { color: var(--red); font: 700 .7rem "Cinzel", serif; text-transform: uppercase; margin-top: 18px; }
.sidebar-card dt:first-child, .reference-list dt:first-child { margin-top: 0; }
.sidebar-card dd, .reference-list dd { margin: 5px 0 0; line-height: 1.55; }
.reference-list { display: grid; grid-template-columns: 220px 1fr; gap: 12px 20px; }
.reference-list dt { margin: 0; }
.reference-list pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

.material-note { background: rgba(140,29,24,.07); padding: 14px; border-left: 4px solid var(--red); }
.tag-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.empty-state { padding: 50px; text-align: center; }
.empty-state h2 { font: 600 1.8rem "Cinzel", serif; color: var(--red-dark); }

.site-footer {
  color: #cbb895;
  border-top: 1px solid rgba(183,138,63,.35);
  padding: 24px 16px;
  text-align: center;
  display: flex;
  justify-content: center;
  gap: 14px;
  background: rgba(10,7,5,.7);
}
.site-footer a { color: #dfba78; }
.footer-rune { color: var(--red); }

@media (max-width: 1050px) {
  .family-grid, .entry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .entry-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-template-columns: 1fr; }
  .hero-sigil { display: none; }
  .two-column-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .header-inner { align-items: stretch; flex-direction: column; }
  .header-search input { min-width: 0; flex: 1; }
  .page-wrap { width: min(100% - 20px, 1400px); padding-top: 18px; }
  .hero, .chapter-header, .stat-header { padding: 26px 22px; }
  .hero-search, .filter-bar { align-items: stretch; flex-direction: column; }
  .family-grid, .entry-grid, .entry-grid.compact { grid-template-columns: 1fr; }
  .chapter-header { align-items: flex-start; flex-direction: column; }
  .stat-ribbon, .stat-ribbon.three { grid-template-columns: 1fr 1fr; }
  .stat-ribbon > div:nth-child(2n) { border-right: 0; }
  .ability-table { grid-template-columns: repeat(3, 1fr); }
  .ability-table > div:nth-child(3n) { border-right: 0; }
  .entry-navigation-links { grid-template-columns: 1fr; gap: 8px; }
  .entry-navigation-links a, .entry-navigation-links a:last-child { text-align: center; }
  .reference-list { grid-template-columns: 1fr; }
}


.reference-link {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--red);
  font: inherit;
  font-weight: 700;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.reference-link:hover { color: var(--red-dark); }

body.reference-modal-open { overflow: hidden; }

.reference-modal[hidden] { display: none; }

.reference-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.reference-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 7, 5, .82);
  backdrop-filter: blur(5px);
}

.reference-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(850px, 100%);
  max-height: min(82vh, 900px);
  overflow: auto;
  border-top: 6px solid var(--red);
  animation: reference-modal-in .16s ease-out;
}

.reference-modal-content { min-height: 150px; }

.reference-modal-entry { padding: 34px; }

.reference-modal-header {
  padding-bottom: 20px;
  margin-bottom: 22px;
  border-bottom: 3px double rgba(140, 29, 24, .55);
}

.reference-modal-header h2 {
  margin: 6px 44px 8px 0;
  color: #45140f;
  font: 700 clamp(1.7rem, 4vw, 2.6rem) "Cinzel", serif;
}

.reference-modal-close {
  position: sticky;
  float: right;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--red-dark);
  color: #fff5e5;
  font: 400 1.7rem/1 serif;
}

.reference-modal-loading {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-style: italic;
}

.reference-modal-rules .rule-block:last-child { padding-bottom: 0; }

.reference-modal-footer {
  margin: 26px -34px -34px;
  padding: 18px 34px;
  background: rgba(92, 57, 25, .08);
  border-top: 1px solid rgba(92, 57, 25, .18);
  text-align: right;
}

.reference-modal-footer a {
  color: var(--red);
  font-weight: 700;
}

.modal-reference-list { grid-template-columns: 180px 1fr; }

@keyframes reference-modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 760px) {
  .reference-modal { padding: 10px; }
  .reference-modal-dialog { max-height: 92vh; }
  .reference-modal-entry { padding: 24px 20px; }
  .reference-modal-footer { margin: 24px -20px -24px; padding: 16px 20px; }
  .modal-reference-list { grid-template-columns: 1fr; }
}
.dnd-dice-roll {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0.12rem;
  padding: 0.18rem 0.48rem;

  border: 1px solid rgba(140, 29, 24, 0.4);
  border-radius: 0.3rem;

  background:
      linear-gradient(
          rgba(255, 255, 255, 0.18),
          rgba(92, 57, 25, 0.08)
      ),
      var(--paper-light);

  color: var(--red-dark);
  font: inherit;
  font-weight: 700;
  line-height: 1.2;

  cursor: pointer;
  box-shadow:
      0 1px 2px rgba(0, 0, 0, 0.18),
      inset 0 0 0 1px rgba(255, 255, 255, 0.25);

  transition:
      transform 0.12s ease,
      border-color 0.12s ease,
      background-color 0.12s ease;
}

.dnd-dice-roll:hover {
  transform: translateY(-1px);
  border-color: var(--red);
  background-color: #f8e8bd;
}

.dnd-dice-roll:active {
  transform: translateY(1px);
}

.dnd-dice-roll:focus-visible {
  outline: 3px solid rgba(183, 138, 63, 0.55);
  outline-offset: 2px;
}

.dnd-dice-icon {
  display: inline-block;
  font-size: 0.95em;
}

.dnd-dice-roll.is-rolling .dnd-dice-icon {
  animation: dnd-dice-spin 0.45s ease;
}

.dnd-roll-results {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 2000;

  display: flex;
  width: min(24rem, calc(100vw - 2rem));
  flex-direction: column;
  gap: 0.65rem;

  pointer-events: none;
}

.dnd-roll-result {
  position: relative;

  padding: 1rem 2.6rem 1rem 1rem;
  overflow: hidden;

  border: 1px solid var(--paper-dark);
  border-top: 4px solid var(--red);
  border-radius: 0.25rem;

  background:
      linear-gradient(
          rgba(255, 255, 255, 0.08),
          rgba(92, 57, 25, 0.06)
      ),
      var(--paper);

  color: var(--ink);

  box-shadow:
      0 14px 36px rgba(0, 0, 0, 0.42),
      inset 0 0 24px rgba(92, 57, 25, 0.08);

  animation: dnd-roll-result-in 0.2s ease-out;
  pointer-events: auto;
}

.dnd-roll-result.is-leaving {
  animation: dnd-roll-result-out 0.18s ease-in forwards;
}

.dnd-roll-result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.dnd-roll-result-expression {
  color: var(--red-dark);
  font: 700 0.85rem "Cinzel", serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dnd-roll-result-total {
  display: grid;
  min-width: 3rem;
  min-height: 3rem;
  place-items: center;

  border: 2px solid var(--red);
  border-radius: 50%;

  color: var(--red-dark);
  font: 700 1.45rem "Cinzel", serif;
}

.dnd-roll-result-details {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.dnd-roll-result-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;

  width: 1.8rem;
  height: 1.8rem;
  padding: 0;

  border: 0;
  border-radius: 50%;

  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;

  cursor: pointer;
  box-shadow: none;
}

.dnd-roll-result-close:hover {
  color: var(--red);
  background: rgba(140, 29, 24, 0.08);
}

@keyframes dnd-dice-spin {
  0% {
      transform: rotate(0deg) scale(1);
  }

  45% {
      transform: rotate(190deg) scale(1.35);
  }

  100% {
      transform: rotate(360deg) scale(1);
  }
}

@keyframes dnd-roll-result-in {
  from {
      opacity: 0;
      transform: translateY(1rem) scale(0.97);
  }

  to {
      opacity: 1;
      transform: translateY(0) scale(1);
  }
}

@keyframes dnd-roll-result-out {
  from {
      opacity: 1;
      transform: translateX(0);
  }

  to {
      opacity: 0;
      transform: translateX(1rem);
  }
}

@media (max-width: 760px) {
  .dnd-roll-results {
      right: 0.65rem;
      bottom: 0.65rem;
      width: calc(100vw - 1.3rem);
  }
}

.footer-admin-link {
  color: inherit;
  text-decoration: none;
}

.footer-admin-link:hover,
.footer-admin-link:focus-visible {
  color: inherit;
  text-decoration: none;
}

.footer-admin-link:focus-visible {
  outline: 1px dotted currentColor;
  outline-offset: 3px;
}