/* Grimoire du Royaume: parchment, dark wood, gilded edges and wax seals. */
:root {
  --parchment: #f1e4c3;
  --parchment-dark: #e2cfa0;
  --parchment-edge: #c9ae74;
  --ink: #2b1d10;
  --ink-soft: #5a4128;
  --ink-faint: #8a6d4a;
  --wood: #3a2414;
  --wood-dark: #24160c;
  --wood-light: #5b3a20;
  --gold: #c9a227;
  --gold-bright: #e8c766;
  --wax: #8e1f1f;
  --wax-dark: #651515;
  --moss: #4d6b2c;
  --steel: #3d5a7a;

  --rarity-common: #6b5a45;
  --rarity-rare: #2a5d8f;
  --rarity-epic: #6d3a8e;
  --rarity-legendary: #a8740f;
  --rarity-mythic: #8e1f1f;

  --el-fire: #b23a12;
  --el-ice: #2d7aa5;
  --el-nature: #4b7a26;
  --el-dark: #4a3561;
  --el-holy: #b08a16;

  --shadow: 0 6px 18px rgba(36, 22, 12, 0.35);
  --radius: 6px;
}

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

body {
  font-family: "EB Garamond", "IM Fell English", Georgia, serif;
  font-size: 17px;
  color: var(--ink);
  min-height: 100vh;
  background-color: var(--wood-dark);
  background-image:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.18) 0 2px, transparent 2px 120px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, var(--wood) 0%, var(--wood-dark) 100%);
  line-height: 1.5;
}

code { font-family: ui-monospace, monospace; font-size: 0.85em; background: rgba(0, 0, 0, 0.08); padding: 0 4px; border-radius: 3px; }

/* ---------- header: a carved wooden banner ---------- */
.wiki-header {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.35)),
    repeating-linear-gradient(90deg, var(--wood-light) 0 3px, var(--wood) 3px 26px);
  border-bottom: 4px double var(--gold);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  padding: 2rem 1rem 0;
  text-align: center;
}
.header-content { max-width: 1280px; margin: 0 auto; }
.badge-tag {
  font-family: "Cinzel", serif; font-size: 0.8rem; letter-spacing: 4px; text-transform: uppercase;
  color: var(--gold-bright);
}
.main-title {
  font-family: "Cinzel Decorative", "Cinzel", serif; font-weight: 900;
  font-size: clamp(2.2rem, 6vw, 3.8rem); letter-spacing: 2px;
  color: var(--gold-bright);
  text-shadow: 0 2px 0 #6b4d10, 0 4px 14px rgba(0, 0, 0, 0.7);
  margin: 0.2rem 0;
}
.subtitle { font-family: "IM Fell English", serif; font-style: italic; color: #e7d3a5; margin-bottom: 1.4rem; }

.nav-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.tab-btn {
  font-family: "Cinzel", serif; font-weight: 700; font-size: 0.9rem;
  display: flex; align-items: center; gap: 6px;
  padding: 0.6rem 1rem; cursor: pointer;
  color: #e7d3a5; background: rgba(0, 0, 0, 0.35);
  border: 1px solid #6b4d2a; border-bottom: none; border-radius: 8px 8px 0 0;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: rgba(201, 162, 39, 0.18); color: var(--gold-bright); }
.tab-btn.active {
  background: var(--parchment); color: var(--wax);
  border-color: var(--gold); box-shadow: 0 -2px 0 var(--gold) inset;
}
.tab-count {
  font-family: "EB Garamond", serif; font-size: 0.75rem; min-width: 1.6rem;
  padding: 0 6px; border-radius: 10px; background: var(--wax); color: #f6e7c6;
}

/* ---------- main: a parchment page ---------- */
.wiki-main {
  max-width: 1280px; margin: 0 auto 2rem; padding: 1.5rem;
  background:
    radial-gradient(ellipse at top left, rgba(255, 255, 255, 0.35), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(120, 80, 30, 0.18), transparent 55%),
    var(--parchment);
  border: 1px solid var(--parchment-edge);
  border-top: none;
  box-shadow: inset 0 0 60px rgba(120, 80, 30, 0.35), var(--shadow);
  min-height: 70vh;
}

.controls-panel { display: flex; flex-direction: column; gap: 0.8rem; margin-bottom: 1rem; }
.search-wrapper { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); opacity: 0.7; }
#search-input {
  width: 100%; padding: 0.7rem 2.4rem; font: inherit; color: var(--ink);
  background: #fbf3dc; border: 2px solid var(--parchment-edge); border-radius: var(--radius);
  box-shadow: inset 0 2px 4px rgba(90, 60, 20, 0.15);
}
#search-input:focus { outline: none; border-color: var(--gold); }
.clear-btn {
  display: none; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--ink-faint); font-size: 1rem; cursor: pointer;
}

.filter-groups { display: flex; flex-direction: column; gap: 0.5rem; }
.filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filter-label { font-family: "Cinzel", serif; font-weight: 700; font-size: 0.8rem; color: var(--ink-soft); margin-right: 4px; }
.pill {
  font: inherit; font-size: 0.9rem; padding: 0.2rem 0.75rem; cursor: pointer;
  color: var(--ink-soft); background: rgba(255, 255, 255, 0.35);
  border: 1px solid var(--parchment-edge); border-radius: 999px;
}
.pill:hover { border-color: var(--gold); }
.pill.active { background: var(--wax); border-color: var(--wax-dark); color: #f6e7c6; }

.results-header {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 0.5rem 0; margin-bottom: 1rem;
  border-bottom: 1px solid var(--parchment-edge);
  font-family: "IM Fell English", serif; font-style: italic; color: var(--ink-soft);
}
.sort-wrapper select {
  font: inherit; color: var(--ink); background: #fbf3dc;
  border: 1px solid var(--parchment-edge); border-radius: 4px; padding: 0.15rem 0.4rem;
}

/* ---------- cards: scrolls with gilded corners ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.wiki-card {
  position: relative; cursor: pointer;
  background: linear-gradient(180deg, #fbf3dc 0%, var(--parchment-dark) 100%);
  border: 1px solid var(--parchment-edge); border-radius: var(--radius);
  padding: 1rem 1rem 0.8rem;
  box-shadow: 0 2px 6px rgba(90, 60, 20, 0.25);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex; flex-direction: column; gap: 0.6rem;
}
.wiki-card::before, .wiki-card::after {
  content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid var(--gold);
}
.wiki-card::before { top: 4px; left: 4px; border-right: none; border-bottom: none; }
.wiki-card::after { bottom: 4px; right: 4px; border-left: none; border-top: none; }
.wiki-card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(90, 60, 20, 0.35); }
.wide-card { grid-column: 1 / -1; cursor: default; }
.wide-card:hover { transform: none; }

.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.item-name { font-family: "Cinzel", serif; font-weight: 700; font-size: 1.1rem; color: var(--ink); line-height: 1.2; }
.card-title { font-family: "Cinzel", serif; font-weight: 900; font-size: 1.35rem; color: var(--wax); }
.class-tag { font-family: "IM Fell English", serif; font-style: italic; font-size: 0.92rem; color: var(--ink-soft); }

.rarity-badge, .level-tag {
  font-family: "Cinzel", serif; font-weight: 700; font-size: 0.7rem; letter-spacing: 1px; text-transform: uppercase;
  padding: 0.15rem 0.55rem; border-radius: 3px; white-space: nowrap; color: #fbf3dc;
}
.level-tag { background: var(--wood-light); }
.rarity-common { background: var(--rarity-common); }
.rarity-rare { background: var(--rarity-rare); }
.rarity-epic { background: var(--rarity-epic); }
.rarity-legendary { background: var(--rarity-legendary); }
.rarity-mythic { background: var(--rarity-mythic); }

/* elements: small enamel seals */
.el-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: "Cinzel", serif; font-weight: 700; font-size: 0.72rem;
  padding: 0.1rem 0.5rem; border-radius: 999px; color: #fbf3dc; white-space: nowrap;
}
.el-Feu { --el: var(--el-fire); }
.el-Glace { --el: var(--el-ice); }
.el-Nature { --el: var(--el-nature); }
.el-Ombre { --el: var(--el-dark); }
.el-Sacré { --el: var(--el-holy); }
.el-badge[class*="el-"] { background: var(--el); }
.pill.el-Feu.active, .pill.el-Glace.active, .pill.el-Nature.active, .pill.el-Ombre.active, .pill.el-Sacré.active {
  background: var(--el); border-color: var(--el);
}
.element-line { font-size: 0.9rem; color: var(--ink-soft); }
.element-line strong { color: var(--ink); }

.stats-list { display: flex; flex-direction: column; gap: 2px; }
.stat-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 0.15rem 0;
  border-bottom: 1px dotted rgba(138, 109, 74, 0.45);
}
.stat-name { color: var(--ink-soft); }
.stat-val { font-weight: 700; }
.stat-val.hp { color: var(--wax); }
.stat-val.str { color: #8a4b12; }
.stat-val.def { color: var(--steel); }
.stat-val.mana { color: #2a5d8f; }
.stat-val.dodge { color: var(--moss); }
.gold-val { color: #8a6410; font-weight: 700; }

.monster-lore { font-family: "IM Fell English", serif; font-style: italic; color: var(--ink-soft); font-size: 0.95rem; }
.monster-weakness {
  padding: 0.6rem 0.8rem; border-left: 4px solid var(--wax);
  background: rgba(142, 31, 31, 0.07); border-radius: 0 4px 4px 0;
}

.drops-preview, .craft-ingredients { display: flex; flex-wrap: wrap; gap: 4px; }
.craft-ingredients { flex-direction: column; }
.drops-title {
  width: 100%; font-family: "Cinzel", serif; font-weight: 700; font-size: 0.75rem;
  letter-spacing: 1px; text-transform: uppercase; color: var(--ink-faint);
}
.drop-tag {
  font-size: 0.82rem; padding: 0.05rem 0.5rem; border-radius: 3px;
  background: rgba(255, 255, 255, 0.45); border: 1px solid var(--parchment-edge);
}
.drop-tag.signature { border-color: var(--gold); background: rgba(201, 162, 39, 0.18); font-weight: 700; }
.ingredient-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 0.3rem 0.5rem;
  background: rgba(255, 255, 255, 0.4); border: 1px solid rgba(201, 174, 116, 0.6); border-radius: 4px;
}
.ingredient-qty { font-weight: 700; color: var(--wax); }

.card-bottom {
  margin-top: auto; display: flex; justify-content: space-between; gap: 8px;
  padding-top: 0.5rem; border-top: 1px solid rgba(138, 109, 74, 0.4);
  font-size: 0.85rem; color: var(--ink-faint);
}

/* ---------- guide (laws of the kingdom) ---------- */
.law {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, #fbf3dc, var(--parchment-dark));
  border: 1px solid var(--parchment-edge); border-radius: var(--radius);
  padding: 1.2rem 1.4rem; box-shadow: 0 2px 6px rgba(90, 60, 20, 0.25);
}
.law h2 {
  font-family: "Cinzel", serif; font-weight: 900; font-size: 1.4rem; color: var(--wax);
  border-bottom: 2px solid var(--gold); padding-bottom: 0.3rem; margin-bottom: 0.7rem;
}
.law p { margin-bottom: 0.6rem; }
.law p:first-of-type::first-letter {
  font-family: "Cinzel Decorative", serif; font-size: 2.6rem; float: left; line-height: 0.9;
  margin: 0.15rem 0.4rem 0 0; color: var(--wax);
}
.toc { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.toc a {
  font-family: "Cinzel", serif; font-weight: 700; font-size: 0.85rem; text-decoration: none;
  color: var(--ink); padding: 0.25rem 0.7rem; border: 1px solid var(--gold); border-radius: 4px;
  background: rgba(201, 162, 39, 0.12);
}
.toc a:hover { background: var(--wax); color: #f6e7c6; }

.scroll-table { overflow-x: auto; margin: 0.6rem 0; }
table.ledger { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
table.ledger th {
  font-family: "Cinzel", serif; font-size: 0.78rem; letter-spacing: 1px; text-align: left;
  background: var(--wood); color: var(--gold-bright); padding: 0.4rem 0.6rem;
}
table.ledger td { padding: 0.3rem 0.6rem; border-bottom: 1px dotted var(--parchment-edge); }
table.ledger tr:nth-child(even) td { background: rgba(255, 255, 255, 0.3); }

/* classes / skills */
.skill-list { display: flex; flex-direction: column; gap: 6px; }
.skill {
  padding: 0.45rem 0.6rem; border: 1px solid rgba(201, 174, 116, 0.8); border-radius: 4px;
  background: rgba(255, 255, 255, 0.4);
}
.skill .skill-name { font-family: "Cinzel", serif; font-weight: 700; }
.skill .skill-meta { font-size: 0.8rem; color: var(--ink-faint); }
.skill.basic { border-color: var(--gold); background: rgba(201, 162, 39, 0.12); }

/* ---------- modal: an unrolled scroll ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  background: rgba(20, 12, 6, 0.72); padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-card {
  position: relative; width: min(680px, 100%); max-height: 88vh; overflow-y: auto;
  background: linear-gradient(180deg, #fbf3dc, var(--parchment));
  border: 3px double var(--gold); border-radius: var(--radius);
  padding: 1.6rem; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.modal-close {
  position: absolute; top: 8px; right: 10px; width: 32px; height: 32px; cursor: pointer;
  border-radius: 50%; border: none; background: var(--wax); color: #f6e7c6; font-size: 1rem;
}
.modal-body h2 { font-family: "Cinzel", serif; font-weight: 900; color: var(--wax); }
.modal-section {
  margin-top: 1rem; padding: 0.8rem; border: 1px solid var(--parchment-edge); border-radius: 4px;
  background: rgba(255, 255, 255, 0.35);
}
.modal-section h3 {
  font-family: "Cinzel", serif; font-size: 0.85rem; letter-spacing: 1px; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 0.5rem;
}

/* ---------- misc ---------- */
.loader-box, .empty-box { grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; color: var(--ink-soft); font-style: italic; }
.spinner {
  width: 40px; height: 40px; margin: 0 auto 1rem; border-radius: 50%;
  border: 4px solid var(--parchment-edge); border-top-color: var(--wax); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.wiki-footer {
  text-align: center; padding: 1.2rem; font-family: "IM Fell English", serif; font-style: italic;
  color: #d9c08a; border-top: 4px double var(--gold);
}
.wiki-footer code { background: rgba(255, 255, 255, 0.08); color: var(--gold-bright); }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .wiki-header { padding: 1.2rem 0.5rem 0; }
  .tab-btn { padding: 0.45rem 0.6rem; font-size: 0.78rem; }
  .tab-label { display: none; }
  .tab-btn.active .tab-label { display: inline; }
  .wiki-main { padding: 1rem; }
  .cards-grid { grid-template-columns: 1fr; }
  .law { padding: 1rem; }
}
