/* Second Calamity — Official Guide design system.
   Inspired by 2000s print strategy guides; built as a screen document, not a
   facsimile of a book. No columns, no folios, no page furniture.
   All content, art, and fonts are ours (OFL: Charm / Alegreya / Signika). */

@font-face {
  font-family: "Charm";
  src: url("fonts/Charm-Regular.ttf");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Charm";
  src: url("fonts/Charm-Bold.ttf");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Alegreya";
  src: url("fonts/Alegreya-VariableFont_wght.ttf");
  font-weight: 400 900;
  font-display: swap;
}
@font-face {
  font-family: "Alegreya";
  src: url("fonts/Alegreya-Italic-VariableFont_wght.ttf");
  font-weight: 400 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Signika";
  src: url("fonts/Signika-VariableFont_GRAD,wght.ttf");
  font-weight: 300 700;
  font-display: swap;
}

/* ==========================================================================
   Tokens
   ========================================================================== */

:root {
  /* Ground. Never used as a single flat fill — see .book background layers. */
  --paper: #f0e8d4;
  --paper-lit: #fbf6e9;
  --paper-deep: #e3d9c0;
  --paper-shade: rgba(122, 98, 60, 0.13);

  --ink: #2b2620;
  --ink-soft: #574a3b;

  /* Chapter hues. One per chapter, printed-ink saturation. Everything a
     chapter colors — title, rules, sweep, drop caps, tab, TOC card — resolves
     from its entry here, so recoloring a chapter is a one-line change. */
  --ch-basics:      #6f5aa6;  /* violet */
  --ch-world:       #a35a2a;  /* sienna */
  --ch-jobs:        #d95f22;  /* orange */
  --ch-equipment:   #8a6510;  /* gold, dark enough for text (4.35:1) */
  --ch-crafting:    #5c7d3f;  /* moss */
  --ch-adventuring: #2f7d80;  /* teal */
  --ch-danger:      #a8322a;  /* crimson */
  --ch-quests:      #7d4a80;  /* plum */
  --ch-regions:     #3f7a52;  /* forest */
  --ch-appendix:    #2f6a8c;  /* steel */

  /* Active accent. Set per chapter on body; the light and deep ends are
     derived so a chapter only ever declares one colour. */
  --accent: var(--ch-jobs);
  --accent-lit: #f0955c;
  --accent-deep: #a83f10;

  --label-red: #b0301f;
  --label-rule: #7d1e12;

  --table-head: #2f5364;
  --table-head-lit: #3f6a7d;
  --table-head-deep: #1f3b48;
  --table-head-ink: #f6f1e4;

  --row-warm-a: #f7cb9c;
  --row-warm-b: #efba85;
  --row-pale-a: #f6ecd8;
  --row-pale-b: #ebdfc6;
  --row-blue-a: #c4dcea;
  --row-blue-b: #aecfe1;
  --row-blue-pale-a: #e2f0f6;
  --row-blue-pale-b: #d1e6ef;
  --cell-hair: rgba(255, 253, 246, 0.72);
  --cell-hair-h: rgba(120, 96, 60, 0.22);

  --sage: #b3bba0;
  --sage-lit: #cbd1bb;
  --olive: #55673d;
  --olive-lit: #7d8f57;

  --strip-a: #e6b481;
  --strip-b: #f3d3ae;
  --strip-c: #f9e6cf;

  --flavor-panel-a: #cfc6db;
  --flavor-panel-b: #b9aecb;
  --flavor-outline: #ddc94a;

  --chip-gold: #c8a44e;

  /* Depth */
  --lift-xs: 0 1px 1px rgba(58, 44, 28, 0.16);
  --lift-sm: 0 1px 2px rgba(58, 44, 28, 0.2), 0 2px 6px rgba(58, 44, 28, 0.08);
  --lift-md: 0 1px 2px rgba(58, 44, 28, 0.22), 0 6px 16px rgba(58, 44, 28, 0.13);
  --gloss: inset 0 1px 0 rgba(255, 255, 255, 0.42);
  --gloss-dark: inset 0 1px 0 rgba(255, 255, 255, 0.16);

  /* Grain overlay. Kept faint — it should read as stock, not as noise. */
  --grain: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="180" height="180"><filter id="g"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="3" stitchTiles="stitch"/><feColorMatrix type="saturate" values="0"/></filter><rect width="180" height="180" filter="url(%23g)" opacity="0.5"/></svg>');

  --serif: "Alegreya", Georgia, "Times New Roman", serif;
  --script: "Charm", "Segoe Script", cursive;
  --sans: "Signika", "Segoe UI", Calibri, sans-serif;

  /* Layout and type scale (12 / 13 / 14 / 18 / 22 / 30 / 44 px). */
  --book-w: 1480px;     /* the page: centred, contents sidebar + content */
  --toc-w: 240px;
  --nav-h: 44px;        /* chapter bar */
  --aside-w: 15rem;     /* side figures, floated into the prose */
  --page-pad: 32px;

  /* Flat table and UI colours (WCAG AA on paper). */
  --zebra-a: #fbf6e9;
  --zebra-b: #f1e7d2;
  --rule: #e0d3b8;
  --head: #2f5364;
  --muted: #6b5e4c;
}

* { box-sizing: border-box; }

html {
  background: #b8ab90 var(--grain);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.55;
  background: var(--paper);
}

/* ==========================================================================
   Frame: chapter bar across the top; contents sidebar | content, centred
   ========================================================================== */

html { font-size: 16px; }   /* never fluid: wider screens get more room, not bigger type */

.book {
  display: grid;
  grid-template-columns: var(--toc-w) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  column-gap: 40px;
  max-width: var(--book-w);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 var(--page-pad);
  position: relative;
  overflow-x: clip;   /* the banner sweep's overhang; clip keeps the sticky bar working */
  background-color: var(--paper);
  background-image:
    var(--grain),
    radial-gradient(120% 55% at 50% 0%, rgba(255, 252, 243, 0.9), rgba(255, 252, 243, 0) 62%);
  box-shadow: 0 0 3rem rgba(38, 30, 20, 0.45);
}

/* Anchors land below the sticky chapter bar. */
:where(h2, h3, [id]) { scroll-margin-top: calc(var(--nav-h) + 16px); }

/* ---------- Chapter bar ---------- */

nav.tabs {
  grid-column: 1 / -1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: var(--nav-h);
  margin: 0 calc(var(--page-pad) * -1);
  padding: 0 var(--page-pad);
  overflow-x: auto;
  scrollbar-width: none;
  background: #e6dcc4;
  border-bottom: 3px solid var(--accent);
}
nav.tabs::-webkit-scrollbar { display: none; }

nav.tabs > a {
  display: flex;
  align-items: center;
  padding: 0 clamp(8px, 0.8vw, 14px);
  font: 600 13px var(--sans);
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-decoration: none;
  color: #3b3125;
  box-shadow: inset 0 -4px 0 var(--tab, transparent);
}
nav.tabs > a:hover { color: #1d1710; background: rgba(255, 255, 255, 0.35); }
nav.tabs > a:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: -2px; }
nav.tabs > a.current { color: #fff; background: color-mix(in srgb, var(--accent) 82%, #000); box-shadow: none; }
/* Home: the guide's title, first in the bar, set apart from the chapter tabs. */
nav.tabs > a.home { font: 400 20px var(--script); letter-spacing: 0; color: #1d1710; margin-right: 10px; border-right: 1px solid var(--rule); }
nav.tabs > a.home.current { color: #fff; background: #3c4043; }

/* ---------- Contents sidebar (guide.js) ----------
   Every section; the entries under the one you are reading open beneath it. */

.toc {
  grid-column: 1;
  grid-row: 2;
  position: sticky;
  top: calc(var(--nav-h) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--nav-h) - 24px);
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 24px 0 48px;
  font: 14px/1.35 var(--sans);
}
.toc b { display: block; margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.toc a { display: block; padding: 5px 10px; border-left: 2px solid var(--rule); color: #4a3f31; text-decoration: none; }
.toc a.sub { display: none; padding: 3px 10px 3px 22px; font-size: 13px; }
.toc a.sub.open { display: block; }
.toc a:hover { color: #1d1710; border-left-color: var(--accent); }
.toc a.on { color: #1d1710; font-weight: 600; border-left-color: var(--accent); }

/* ---------- Chapter accents ---------- */

/* .ch-* on <body> colours the page; .tab-* colours a rail tab or TOC card.
   Both resolve the same hue, so a tab always matches the chapter it opens. */
.ch-basics,      .tab-basics      { --accent: var(--ch-basics); }
.ch-world,       .tab-world       { --accent: var(--ch-world); }
.ch-jobs,        .tab-jobs        { --accent: var(--ch-jobs); }
.ch-equipment,   .tab-equipment   { --accent: var(--ch-equipment); }
.ch-crafting,    .tab-crafting    { --accent: var(--ch-crafting); }
.ch-adventuring, .tab-adventuring { --accent: var(--ch-adventuring); }
.ch-danger,      .tab-danger      { --accent: var(--ch-danger); }
.ch-quests,      .tab-quests      { --accent: var(--ch-quests); }
.ch-regions,     .tab-regions     { --accent: var(--ch-regions); }
.ch-appendix,    .tab-appendix    { --accent: var(--ch-appendix); }

/* Derived ends, resolved wherever an accent is declared. */
body, nav.tabs a, .toc-chapters li {
  --accent-lit: color-mix(in srgb, var(--accent) 58%, #fff5e6);
  --accent-deep: color-mix(in srgb, var(--accent) 76%, #2b1608);
  --tab: color-mix(in srgb, var(--accent) 24%, #f4ecda);
}

/* ---------- Page body ---------- */

/* The content area. Layout inside it keys off its own width (container
   queries), so the notes drawer narrowing it reflows the page correctly. */
main.page {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  position: relative;
  padding: 0 0 96px;
  container: page / inline-size;
}
main.page > * { max-width: 100%; }

p { margin: 0 0 0.75em; text-align: left; hyphens: manual; }

/* Ruled and banded heads sit beside a float rather than sliding under it —
   without this their border/background runs behind a floated figure. */
h2, h2.sub, h3, .label, .jobname,
p.todo, div.todo, aside.callout, blockquote.flavor, details.spoiler { display: flow-root; }
ul, ol { margin: 0 0 0.75em; padding-left: 1.3rem; }
li { margin: 0.25rem 0; }

/* ==========================================================================
   Chapter head
   ========================================================================== */

header.chapter-head {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  position: relative;
  margin: 0 0 24px;
  text-align: right;
}

/* Banner strip. Real art goes in --banner; it dissolves into the page at the
   bottom edge rather than ending on a rule. */
header.chapter-head::before {
  content: "";
  display: block;
  align-self: stretch;
  height: 6.2rem;
  margin: 0 calc(var(--page-pad) * -1) 0.7rem;
  background-color: var(--paper-deep);
  background-image: var(--banner, linear-gradient(100deg, #35422f, #55673d 26%, #8a7a4e 52%, #2f5364 78%, #22303a));
  background-size: cover;
  background-position: center 40%;
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 58%, rgba(0, 0, 0, 0.35) 84%, rgba(0, 0, 0, 0) 100%);
  mask-image: linear-gradient(180deg, #000 0%, #000 58%, rgba(0, 0, 0, 0.35) 84%, rgba(0, 0, 0, 0) 100%);
}

/* Curved accent sweep across the banner, in place of a straight rule. */
header.chapter-head::after {
  content: "";
  position: absolute;
  left: calc(var(--page-pad) * -1);
  right: calc(var(--page-pad) * -1);
  top: 0;
  height: 5.6rem;
  border-bottom: 2px solid var(--accent);
  border-radius: 0 0 50% 50% / 0 0 1.1rem 1.1rem;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(58, 44, 28, 0.35));
}

h1 {
  font-family: var(--script);
  font-weight: 400;
  font-size: 44px;
  line-height: 1;
  margin: 0;
  padding-bottom: 0.05rem;
  border-bottom: 2px solid var(--ink);
  align-self: stretch;
  color: var(--accent);
}

header.chapter-head .kicker {
  order: 2;
  font-family: var(--serif);
  font-variant: small-caps;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: #4a3f31;
  margin-top: 8px;
}

/* ==========================================================================
   Headings
   ========================================================================== */

h2 {
  font-family: var(--script);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.1;
  color: var(--accent);
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.05rem;
  margin: 48px 0 8px;   /* bound to what follows */
  /* A new section never starts beside the last section's figure. */
  clear: both;
}

h2.sub {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  border-bottom: 2px solid var(--label-rule);
  padding-bottom: 0.1rem;
  margin: 40px 0 8px;
}

h3 {
  font-family: var(--script);
  font-weight: 400;
  font-size: 22px;
  color: #f6f1e2;
  padding: 0.1rem 0.9rem 0;
  margin: 32px 0 8px;
  border-radius: 2px 9px 9px 2px;
  /* Earthy band, shifted toward the chapter accent so entity names belong to
     the chapter they sit in. */
  background: color-mix(in srgb, var(--accent) 38%, #334023);
  box-shadow: var(--gloss-dark), var(--lift-sm);
}

/* ---------- Job name bar ---------- */

.jobname {
  display: flex;
  align-items: baseline;
  margin: 2rem 0 0.7rem;
  padding-left: 0.4rem;
  border-bottom: 2px solid var(--ink);
  border-radius: 3px 10px 0 0;
  background: #98a186;
  box-shadow: var(--gloss), var(--lift-sm);
}

.jobname .cap {
  /* A darker shade of the chapter colour: >= 3:1 on the sage band. */
  color: color-mix(in srgb, var(--accent) 55%, #000) !important;
  font-family: var(--script);
  font-size: 44px;
  line-height: 0.55;
  color: var(--accent);
  padding-right: 0.05em;
  position: relative;
  z-index: 1;
}

.jobname .rest {
  flex: 1;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 30px;
  padding: 0.05rem 0.8rem 0.05rem 0.1rem;
}

/* ---------- Sub-heads: two tiers, and only two ----------
   .striphead is the workhorse — a filled strip carrying the label, tinted by
   the chapter accent. .label is the rule head, for table captions and the odd
   standalone tag. Nothing else sits between a section head and body copy. */

.striphead {
  display: flow-root;
  margin: 24px 0 8px;
  padding: 4px 10px;
  border-radius: 2px;
  font: 600 13px var(--sans);
  letter-spacing: 0.04em;
  color: #3b2e1d;
  background: color-mix(in srgb, var(--accent) 16%, #f6ecd8);
}

.label, table.stats caption {
  font: 600 13px var(--sans);
  letter-spacing: 0.02em;
  color: #7a2b20;
  border-bottom: 2px solid var(--label-rule);
  padding-bottom: 2px;
  margin: 24px 0 6px;
}

/* ---------- Drop cap ---------- */

.dropcap::first-letter {
  font-family: var(--script);
  initial-letter: 3;
  padding-right: 0.12em;
  color: var(--accent);
}

/* ==========================================================================
   Data tables — flat, and as wide as the content area, like the text around
   them. Where the content area is too narrow for a table (phones, or the notes
   drawer open) it scrolls inside itself rather than pushing or hiding under
   anything.
   ========================================================================== */

table.stats {
  width: 100%;
  border-collapse: collapse;
  font: 400 14px/1.4 var(--sans);
  margin: 0 0 24px;
}

table.stats caption {
  caption-side: top;
  text-align: left;
  display: table-caption;
}

table.stats th {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  color: #fff;
  background: var(--head);
}

table.stats td {
  padding: 6px 10px;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
}
table.stats tbody tr:last-child td { border-bottom: 0; }
table.stats tbody tr:nth-child(odd) td  { background: var(--zebra-a); }
table.stats tbody tr:nth-child(even) td { background: var(--zebra-b); }
table.stats td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* A header sits over its column: right-aligned where the column holds numbers. */
table.stats:has(> tbody > tr:first-child > td:nth-child(1).num) > thead > tr > th:nth-child(1),
table.stats:has(> tbody > tr:first-child > td:nth-child(2).num) > thead > tr > th:nth-child(2),
table.stats:has(> tbody > tr:first-child > td:nth-child(3).num) > thead > tr > th:nth-child(3),
table.stats:has(> tbody > tr:first-child > td:nth-child(4).num) > thead > tr > th:nth-child(4),
table.stats:has(> tbody > tr:first-child > td:nth-child(5).num) > thead > tr > th:nth-child(5),
table.stats:has(> tbody > tr:first-child > td:nth-child(6).num) > thead > tr > th:nth-child(6),
table.stats:has(> tbody > tr:first-child > td:nth-child(7).num) > thead > tr > th:nth-child(7),
table.stats:has(> tbody > tr:first-child > td:nth-child(8).num) > thead > tr > th:nth-child(8),
table.stats:has(> tbody > tr:first-child > td:nth-child(9).num) > thead > tr > th:nth-child(9),
table.stats:has(> tbody > tr:first-child > td:nth-child(10).num) > thead > tr > th:nth-child(10),
table.stats:has(> tbody > tr:first-child > td:nth-child(11).num) > thead > tr > th:nth-child(11),
table.stats:has(> tbody > tr:first-child > td:nth-child(12).num) > thead > tr > th:nth-child(12) { text-align: right; }
table.stats td:last-child:not(.num) { min-width: 18rem; }
@container page (max-width: 760px) {
  main.page table.stats { display: block; overflow-x: auto; }
}
/* Base tables (tools/gen-equipment.py): fixed columns, so each kind's tables
   line up down the page; the unclassed last column takes the rest. Phones
   keep auto layout and scroll. */
@container page (min-width: 761px) {
  table.stats.bases { table-layout: fixed; }
  table.stats.bases th.c-name { width: 11rem; }
  table.stats.bases th.c-lv   { width: 3rem; }
  table.stats.bases th.c-num  { width: 5rem; }
  table.stats.bases th.c-blk  { width: 6.5rem; }
  table.stats.bases th.c-req  { width: 7rem; }
  table.stats.bases th.c-text { width: 21rem; }
  table.stats.bases td { overflow-wrap: break-word; }
}


/* Column tints — a wash laid over the row gradient, for tables that group
   columns (job columns, element columns). Apply per-cell. */
table.stats td.tint-a { box-shadow: inset 0 0 0 99px rgba(63, 106, 125, 0.15); }
table.stats td.tint-b { box-shadow: inset 0 0 0 99px rgba(160, 58, 38, 0.13); }
table.stats td.tint-c { box-shadow: inset 0 0 0 99px rgba(85, 103, 61, 0.15); }
table.stats td.tint-d { box-shadow: inset 0 0 0 99px rgba(119, 98, 142, 0.15); }

/* ==========================================================================
   Callouts
   ========================================================================== */

aside.callout {
  --strip: var(--strip-a);
  --strip-hi: var(--strip-b);
  margin: 1.15rem 0;
  padding: 0 0 0.55rem;
  border: 1px solid rgba(122, 98, 60, 0.4);
  border-radius: 5px;
  background: rgba(255, 253, 245, 0.85);
  box-shadow: var(--lift-sm);
  break-inside: avoid;
}

aside.callout > h4 {
  position: relative;
  margin: 0 0 0.5rem;
  padding: 0.3rem 0.7rem 0.3rem 2.7rem;
  border-radius: 4px 4px 0 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--strip);
  box-shadow: var(--gloss), 0 1px 2px rgba(58, 44, 28, 0.18);
}

/* Icon disc overlapping the strip's left end. Set --icon to real art. */
aside.callout > h4::before {
  content: "";
  position: absolute;
  left: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background-image: var(--icon, radial-gradient(120% 120% at 32% 24%, #fff6e2, var(--strip) 48%, var(--accent-deep)));
  background-size: cover;
  box-shadow: 0 1px 2px rgba(58, 44, 28, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

aside.callout > p,
aside.callout > ol,
aside.callout > ul { margin: 0.45rem 0.8rem; }

aside.callout.warn   { --strip: #dd9a7c; --strip-hi: #eebda6; }
aside.callout.aether { --strip: #a3c1c9; --strip-hi: #c6dbe0; }

/* ==========================================================================
   Flavor box
   ========================================================================== */

blockquote.flavor {
  border: 1.5px solid var(--ink-soft);
  border-radius: 12px;
  margin: 1.35rem 0;
  padding: 0.6rem 0.85rem 0.8rem;
  background: rgba(255, 253, 245, 0.7);
  box-shadow: var(--lift-sm);
  break-inside: avoid;
}

blockquote.flavor > h4 {
  margin: 0 0 0.5rem;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink);
}

blockquote.flavor > .panel {
  border: 2px solid var(--flavor-outline);
  border-radius: 10px;
  padding: 0.75rem 0.95rem;
  font-family: var(--sans);
  font-weight: 350;
  font-size: 14px;
  line-height: 1.45;
  color: #29222f;
  background: var(--flavor-panel-a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -6px 14px rgba(60, 46, 78, 0.16);
}

blockquote.flavor footer {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 0.45rem;
  text-align: right;
  color: var(--ink-soft);
}

/* ==========================================================================
   Quest card
   --------------------------------------------------------------------------
   Shaped title bar, a facts panel, then the walkthrough in plain prose below
   the panel — the facts are scannable, the prose is readable, and neither is
   forced into a table.
   ========================================================================== */

article.quest {
  margin: 1.25rem 0;
  border: 1px solid rgba(122, 98, 60, 0.42);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255, 253, 245, 0.9);
  box-shadow: var(--lift-sm);
  break-inside: avoid;
}

article.quest > h4 {
  margin: 0;
  padding: 0.3rem 2.4rem 0.32rem 0.85rem;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #3b2e1d;
  clip-path: polygon(0 0, 100% 0, calc(100% - 1.5rem) 100%, 0 100%);
  background: color-mix(in srgb, var(--chip-gold) 62%, #f2dcaa);
  box-shadow: var(--gloss);
}

.quest-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.12rem 1.2rem;
  margin: 0;
  padding: 0.5rem 0.85rem 0.55rem;
  border-bottom: 1px solid rgba(122, 98, 60, 0.28);
  font-family: var(--sans);
  font-size: 13px;
  background: rgba(246, 236, 214, 0.9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.quest-facts > div { display: flex; gap: 0.4rem; align-items: baseline; }

.quest-facts dt {
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--label-red);
  white-space: nowrap;
}

.quest-facts dd { margin: 0; min-width: 0; }

article.quest > p { margin: 0.5rem 0.85rem; }
article.quest > p:last-child { margin-bottom: 0.7rem; }

@media (max-width: 40rem) {
  .quest-facts { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   Figures
   ========================================================================== */

figure.shot { margin: 1.2rem 0; break-inside: avoid; }

figure.shot img,
figure.portrait img {
  width: 100%;
  display: block;
  border: 1px solid rgba(43, 38, 32, 0.55);
  border-radius: 2px;
  box-shadow: var(--lift-md), inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

figure.shot figcaption {
  font-family: var(--sans);
  font-weight: 350;
  font-size: 12px;
  color: var(--ink-soft);
  padding-top: 0.28rem;
}

figure.shot.left  { float: left;  width: 46%; margin: 0.3rem 1.2rem 0.7rem 0; }
figure.shot.right { float: right; width: 46%; margin: 0.3rem 0 0.7rem 1.2rem; }

figure.portrait { float: left; width: 38%; margin: 0 1.3rem 0.5rem 0; }

/* Side figures float into the prose; the text wraps around them. */
figure.shot.side {
  float: right;
  clear: right;
  width: var(--aside-w);
  max-width: var(--aside-w);
  margin: 0.35rem 0 0.9rem 1.4rem;
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-block;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 1px 7px;
  border-radius: 10px;
  color: #fff;
  margin-right: 3px;
  background: var(--chip-c, #574a3b);
}

.badge.aggro   { --chip-c: #8a2e1d; }
.badge.passive { --chip-c: #455c39; }
.badge.links   { --chip-c: #7d5a1c; }
.badge.sight   { --chip-c: #3a5470; }
.badge.sound   { --chip-c: #5a4970; }
.badge.aether  { --chip-c: #1f555c; }

/* ==========================================================================
   Helpers
   ========================================================================== */

.clear { clear: both; }

hr {
  border: 0;
  height: 2px;
  margin: 1.6rem 0;
  background: rgba(122, 98, 60, 0.5);
}

a { color: #1a5f66; }

/* ==========================================================================
   TOC / cover
   ========================================================================== */

.toc-chapters {
  display: grid;
  /* Clears any floated devnote above it — a grid is a formatting context, so
     it would otherwise narrow beside the float instead of running full width. */
  clear: both;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 1rem;
  padding: 0;
  margin: 1.6rem 0;
  list-style: none;
}

.toc-chapters li {
  border-top: 0.35rem solid var(--tab, #ddd5c2);
  border-radius: 0 0 4px 4px;
  padding: 0.85rem 1rem;
  background: rgba(255, 253, 245, 0.95);
  box-shadow: var(--lift-sm);
}

.toc-chapters li a {
  font-family: var(--script);
  font-size: 22px;
  color: color-mix(in srgb, var(--accent) 60%, #000);   /* >= 4.5:1 on the card */
  text-decoration: none;
}

.toc-chapters li p {
  font-family: var(--sans);
  font-weight: 350;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0.35rem 0 0;
  text-align: left;
}

/* ==========================================================================
   Job quick-selector
   ========================================================================== */


.jobdex {
  margin: 1.2rem 0 1.6rem;
  padding: 0.75rem 1rem 0.85rem;
  border: 1px solid rgba(122, 98, 60, 0.35);
  border-left: 4px solid var(--olive);
  border-radius: 0 5px 5px 0;
  background: rgba(255, 253, 245, 0.9);
  box-shadow: var(--lift-sm);
}

.jobdex-group {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.6rem;
  margin: 0.3rem 0;
}

.jobdex-group a {
  font-family: var(--sans);
  font-size: 13px;
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.05rem 0.45rem;
  border: 1px solid transparent;
  border-radius: 3px;
  white-space: nowrap;
}

.jobdex-group a:hover {
  color: var(--ink);
  border-color: rgba(122, 98, 60, 0.45);
  background: rgba(255, 255, 250, 0.95);
  box-shadow: var(--lift-xs);
}

.jobdex-group a.jobdex-role {
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--label-red);
  min-width: 8.5rem;
  padding-left: 0;
}
.jobdex-group a.jobdex-role:hover { background-image: none; border-color: transparent; box-shadow: none; }

/* ==========================================================================
   Removable layer — design-build only
   --------------------------------------------------------------------------
   Everything below is stripped for the retail build. The invariant: any text
   that will not ship lives inside .devnote, .todo, or details.spoiler. Prose
   outside those containers is final guide copy.
   ========================================================================== */

details.spoiler {
  margin: 1.2rem 0;
  border: 1px solid #9c3623;
  border-radius: 4px;
  background: rgba(252, 240, 232, 0.95);
  box-shadow: var(--lift-sm);
}

details.spoiler > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.45rem 0.85rem;
  border-radius: 3px 3px 0 0;
  color: #f8f2e6;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: #b8452f;
  box-shadow: var(--gloss-dark);
}

details.spoiler > summary::-webkit-details-marker { display: none; }
details.spoiler > summary::before { content: "\25B8\00a0\00a0"; display: inline-block; }
details.spoiler[open] > summary::before { content: "\25BE\00a0\00a0"; }
details.spoiler > summary:hover { background: #c9553e; }
details.spoiler > .spoiler-body { padding: 0.35rem 1rem 0.9rem; }
details.spoiler .spoiler-body > h3 { margin-top: 1rem; }

.devnote {
  margin: 1rem 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid rgba(47, 83, 100, 0.35);
  border-left: 4px solid var(--table-head);
  border-radius: 0 4px 4px 0;
  font-family: var(--sans);
  font-size: 13px;
  color: #2f3d47;
  background: #eef3f6;
}

.devnote p { text-align: left; margin: 0.35rem 0; }
.devnote p:first-child { margin-top: 0; }
.devnote p:last-child { margin-bottom: 0; }

.devnote-tag {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--table-head);
}

/* Design notes (guide.js). Without the script they stay boxes in the flow.
   With it they leave the text: at 1840px and wider they are Docs-style cards beside the page,
   level with their passage; narrower, a drawer that pushes the page aside.
   The toggle sits in the chapter bar. */
nav.tabs .notes-toggle {
  flex: none;
  position: relative;
  align-self: center;
  height: 32px;
  margin: 0 0 0 auto;
  padding: 0 14px;
  border: 0;
  border-radius: 16px;
  font: 600 13px var(--sans);
  color: #fff;
  background: #3c4043;
  cursor: pointer;
}
.notes-panel {
  position: fixed;
  top: var(--nav-h);
  right: 0;
  bottom: 0;
  z-index: 35;
  width: 360px;
  overflow-y: auto;
  padding: 16px;
  background: #f1f3f4;
  border-left: 1px solid #dadce0;
  transform: translateX(100%);
  transition: transform 0.15s ease;
}
.notes-open .notes-panel { transform: none; }
.notes-panel h4 { margin: 0 0 12px; font: 600 15px var(--sans); color: #202124; }
.notes-panel .devnote {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  font: 13px/1.45 var(--sans);
  color: #3c4043;
  background: #fff;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
  cursor: pointer;
}

.notes-panel .devnote-tag { color: #202124; letter-spacing: 0; }
@media (min-width: 1101px) {
  html.notes-open:not(.notes-rail-mode) .book { margin-right: 360px; }
}
/* Card mode (>= 1840px): cards in the band right of the page, which shifts left
   so the page and its notes centre together. */
html.notes-rail-mode .notes-panel {
  position: absolute; top: 0; bottom: auto; right: auto; transform: none;
  width: 300px; padding: 0; background: transparent; border: 0; overflow: visible;
}
html.notes-rail-mode .notes-panel > h4 { display: none; }
html.notes-rail-mode .notes-panel .devnote { position: absolute; left: 0; right: 0; margin: 0; }
html.notes-rail-mode.notes-hidden .notes-panel { display: none; }
html.notes-rail-mode:not(.notes-hidden) .book {
  margin-left: max(16px, calc((100vw - var(--book-w) - 340px) / 2));
  margin-right: auto;
}

/* Unwritten content. Marked so the retail build can strip it and the build
   check can fail on anything left behind. */
.todo {
  font-family: var(--sans);
  font-size: 13px;
  font-style: normal;
  color: #6d4a12;
  background-image: repeating-linear-gradient(
    135deg,
    rgba(214, 160, 46, 0.16) 0 6px,
    rgba(214, 160, 46, 0.07) 6px 12px
  );
  box-shadow: inset 0 0 0 1px rgba(176, 128, 30, 0.4);
  border-radius: 3px;
}

p.todo, div.todo { padding: 0.4rem 0.7rem; margin: 0.7rem 0; text-align: left; }
span.todo { padding: 0 0.3rem; }
td.todo { color: #6d4a12; box-shadow: none; background-image: none; }

/* ---------- Retail preview: <html data-build="retail"> ---------- */

html[data-build="retail"] .devnote,
html[data-build="retail"] .todo { display: none !important; }

html[data-build="retail"] td.todo { display: table-cell !important; color: transparent; }

html[data-build="retail"] details.spoiler {
  border: 0;
  background: none;
  box-shadow: none;
  margin: 0;
}
html[data-build="retail"] details.spoiler > summary { display: none; }
html[data-build="retail"] details.spoiler > .spoiler-body { padding: 0; }

/* ==========================================================================
   Narrow screens
   ========================================================================== */

.nav-menu { display: none; }   /* the phone chapter menu (guide.js) */

@media (max-width: 1100px) {
  :root { --page-pad: 16px; }
  .book { grid-template-columns: minmax(0, 1fr); column-gap: 0; }
  .toc { display: none; }
  main.page { grid-column: 1; }
    figure.shot.left, figure.shot.right, figure.shot.side, figure.portrait {
    float: none; width: 100%; max-width: none; margin: 1.2rem 0;
  }
}

/* Below 1200px the eleven tabs no longer fit one bar: they fold into one
   chapter menu (guide.js), so the bar never scrolls or hides a tab. */
@media (max-width: 1200px) {
  nav.tabs { overflow: visible; }
  nav.tabs > a { display: none; }
  .nav-menu { display: block; position: relative; align-self: center; }
  .nav-menu > summary {
    list-style: none; display: flex; align-items: center; min-height: 44px; padding: 0 12px;
    font: 600 14px var(--sans); color: #1d1710; cursor: pointer;
  }
  .nav-menu > summary::-webkit-details-marker { display: none; }
  .nav-menu[open] > div {
    position: absolute; top: 44px; left: calc(var(--page-pad) * -1); z-index: 50; width: min(100vw, 360px);
    background: #f6efdd; border-bottom: 3px solid var(--accent); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
  }
  .nav-menu[open] > div a {
    display: flex; align-items: center; min-height: 44px; padding: 0 16px;
    font: 600 15px var(--sans); color: #1d1710; text-decoration: none; border-top: 1px solid var(--rule);
  }
  .nav-menu[open] > div a.current { color: #fff; background: color-mix(in srgb, var(--accent) 82%, #000); }
}

@media (max-width: 640px) {
  body { font-size: 17px; }
  h1 { font-size: 32px; }
  h2 { font-size: 26px; margin: 24px 0 6px; }
  header.chapter-head { margin-bottom: 12px; }
  header.chapter-head + h2 { margin-top: 8px; }
  header.chapter-head::before { height: 48px; margin-bottom: 6px; }
  header.chapter-head::after { height: 44px; }
  header.chapter-head .kicker { display: none; }
  .jobname .cap { font-size: 32px; }
  .jobname .rest { font-size: 22px; }
  table.stats td { white-space: normal; }
  table.stats.wide { font-size: 14px; }
  /* The 18rem text-column floor is for desktop; on a phone it forces every table to scroll. */
  main.page table.stats td:last-child:not(.num) { min-width: 12rem; }
  main.page .fam-card table.stats td:last-child:not(.num) { min-width: 16rem; }
  /* Ability tables: the fixed name/target widths give way so the description keeps ~14rem. */
  table.stats.abilities td:first-child, table.stats.abilities td:nth-child(3) { width: auto; }
  main.page table.stats.abilities td:last-child:not(.num) { min-width: 14rem; }
  .notes-panel { width: 100%; }
  nav.tabs .notes-toggle { padding: 0 12px; }
  nav.tabs .notes-toggle::after { content: ""; position: absolute; inset: -6px 0; }   /* 44px hit area */
  .jobdex-group a, .toc-chapters li a, details.spoiler > summary { display: inline-flex; align-items: center; min-height: 44px; }
  details.spoiler > summary { display: flex; }
  }

@media print {
  nav.tabs, .toc, .notes-toggle { display: none !important; }
  .book { display: block; box-shadow: none; }
}

/* ---- equipment: modifier view ---- */

/* A base type's prefixes and suffixes (tools/gen-equipment.py, modview.js),
   laid out after craftofexile: one 28px row per modifier family —
   Modifier · Affix · Tiers · iLvl · Weight · Chance — opening onto its tiers.
   Collapsed behind a summary line until asked for. Prefixes and suffixes sit
   side by side when the content area has room for both (container query). */

main.page > table.stats.wide,
main.page > .modview { clear: both; }

.modview { display: flex; flex-direction: column; margin: 8px 0 32px; font-family: var(--sans); }
.mv-note { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.modview.js .mv-note { display: none; }

.mv-collapse { order: -1; display: flex; align-items: center; gap: 12px; margin: 0 0 12px; }
.mv-toggle { font: 600 14px var(--sans); color: #fff; background: var(--head); border: 0; border-radius: 3px; padding: 6px 12px; cursor: pointer; }
.mv-summary { font-size: 13px; color: #4a3f31; }
.modview.collapsed .mv-bar,
.modview.collapsed .mv-sides { display: none; }

/* Prefixes left, suffixes right, each half the content area; stacked only
   when a half would fall under the table's 30rem floor. */
.mv-sides { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; align-items: start; }
@container page (min-width: 984px) {
  .mv-sides { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.mv-side { overflow-x: auto; }

.mv-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 12px; border-bottom: 2px solid #7a2b20; margin-bottom: 4px; }
.mv-head h4 { margin: 0; font: 700 14px var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: #7a2b20; }
.mv-count { font-size: 13px; color: var(--muted); }
.mv-none { font-size: 13px; font-style: italic; color: var(--muted); }

/* Fixed columns, so the prefix and suffix tables line up with each other and
   every base type's tables share one grid. Modifier takes what's left. */
.mv-table { width: 100%; min-width: 30rem; table-layout: fixed; border-collapse: collapse; font: 400 14px/1.3 var(--sans); }
.mv-table th {
  text-align: left; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap;
  color: #fff; background: var(--head); padding: 6px 6px;
}
.mv-table th:first-child { padding-left: 8px; }
.mv-table th:nth-child(2) { width: 6.5rem; }
.mv-table th:nth-child(3) { width: 2.5rem; }
.mv-table th:nth-child(4) { width: 2.25rem; }
.mv-table th:nth-child(5) { width: 3.25rem; }
.mv-table th:nth-child(6) { width: 3.5rem; }
.mv-table th:nth-child(n+3), .mv-table td.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; padding: 5px 6px; }
.mv-table td { padding: 5px 8px; height: 28px; vertical-align: middle; border-bottom: 1px solid var(--rule); overflow-wrap: break-word; }
.mv-table td.mv-affix { font: italic 13px var(--serif); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv-table tbody.mv-fam:nth-of-type(odd) .mv-row td  { background: var(--zebra-a); }
.mv-table tbody.mv-fam:nth-of-type(even) .mv-row td { background: var(--zebra-b); }
.mv-tier td { background: #fffdf7; font-size: 13px; }
.mv-tier td:first-child { padding-left: 24px; }
.mv-tier b { color: var(--accent-deep); }
.mv-tier.off td { color: var(--muted); }
.mv-excl-text { display: block; font-size: 12px; font-style: italic; color: var(--muted); }
button.mv-excl-mark { border: 0; background: none; padding: 0 2px; margin-left: 4px; font: inherit; color: var(--muted); cursor: pointer; }

/* Tags, from the backend's mod_definition_tags (a mod can carry several): filled chips on rows, outlined filters until chosen. */
.tag-attack { --tag: #8a3f15; }   .tag-caster { --tag: #2f4f8a; }   .tag-attribute { --tag: #4f5a14; }
.tag-mana { --tag: #1f5a78; }     .tag-life { --tag: #8f2222; }
.tag-resist { --tag: #6a2f7a; }   .tag-defense { --tag: #3e474e; }  .tag-block { --tag: #4b4153; }
.tag-utility { --tag: #4a5637; }  .tag-support { --tag: #5c4c22; }
.mv-chip, .mv-tag { font: 600 12px var(--sans); letter-spacing: 0.02em; border-radius: 3px; }
.mv-chip { margin-left: 6px; padding: 1px 6px; white-space: nowrap; color: #fff; background: var(--tag); vertical-align: 1px; }
.mv-tag { padding: 1px 8px; color: var(--tag); background: var(--zebra-a); border: 1px solid var(--tag); cursor: pointer; }
.mv-tag.on { color: #fff; background: var(--tag); }

/* ---------- Script layer: modview.js adds .js, the summary line and the controls ---------- */

.mv-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px 12px; margin-bottom: 12px;
  border: 1px solid var(--rule); border-radius: 4px; background: #f6efdd;
}
.mv-il-box { font: 700 13px var(--sans); color: var(--ink); }
.mv-il-box input {
  width: 4.6rem; margin-left: 6px; font: 700 16px var(--sans); text-align: center;
  padding: 2px 4px; border: 1px solid var(--head); border-radius: 3px; background: #fffdf6;
}
.mv-hint { font-size: 13px; color: var(--muted); }
.mv-search, .mv-all {
  font: 13px var(--sans); color: var(--ink); padding: 3px 8px;
  border: 1px solid var(--rule); border-radius: 3px; background: #fffdf6;
}
.mv-search { margin-left: auto; min-width: 14rem; }
.mv-all { font-weight: 600; cursor: pointer; }
.mv-tags { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; }

.modview.js .mv-fam:not(.open) .mv-tier { display: none; }
.modview.js .mv-excl-text:not(.show) { display: none; }
.modview.js .mv-row { cursor: pointer; }
.modview.js .mv-row td:first-child::before { content: "\25B8"; display: inline-block; width: 1rem; color: var(--accent-deep); }
.modview.js .mv-fam.open .mv-row td:first-child::before { content: "\25BE"; }
.modview.js .mv-row:hover td { background: #fffbef; }
.modview.js .mv-row:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: -2px; }
.modview.js .mv-fam.locked .mv-row td { color: var(--muted); }

@media (max-width: 640px) {
  .mv-toggle, .mv-all, .mv-search, .mv-il-box input { min-height: 44px; }
  .mv-search { margin-left: 0; min-width: 0; flex: 1 1 10rem; }
  .mv-tags { gap: 8px; }
  .mv-tag { min-height: 32px; padding: 4px 10px; }
  .mv-table td { height: 44px; }
  button.mv-excl-mark { display: inline-grid; place-items: center; min-width: 32px; min-height: 32px; }
}

@media print {
  .mv-bar, .mv-collapse { display: none; }
  .modview.collapsed .mv-sides { display: grid; }
  .modview.js .mv-note { display: block; }
  .modview.js .mv-fam:not(.open) .mv-tier { display: table-row; }
  .mv-table tbody { break-inside: avoid; }
}


/* ---- jobs ---- */
/* Generated ability tables (tools/gen-jobs.py). How an ability is pressed
   (GCD, cost, cast, recast) rides as a quiet second line under its name. */
table.stats.abilities td:first-child { width: 9.5rem; }
table.stats.abilities td:nth-child(3) { width: 6.5rem; }
table.stats.abilities .use {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

/* ---- bestiary ---- */

/* Families sit two to a row, like a print bestiary: a screenshot slot, the
   family head, how it behaves, then its members and abilities. */
.fam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34rem, 1fr));
  gap: 8px 40px;
  align-items: start;
  margin: 0 0 24px;
  clear: both;
}
main.page > div.todo:has(.fam-grid) { max-width: none; }
.fam-card { min-width: 0; }
.fam-card > h3 { margin-top: 16px; }
main.page .fam-card > table.stats { display: table; width: 100%; margin-bottom: 12px; }
.fam-card td:nth-child(3) { white-space: nowrap; }
.fam-card td:last-child:not(.num) { min-width: 12rem; }
div.fam-shot { min-height: 0; padding: 4px 10px; margin: 0 0 8px; font-size: 12px; }
@media (max-width: 640px) {
  .fam-grid { grid-template-columns: minmax(0, 1fr); }
  main.page .fam-card > table.stats { display: block; overflow-x: auto; }
  .fam-card td:last-child:not(.num) { min-width: 16rem; }
  .fam-card td:nth-child(2), .fam-card td:nth-child(3) { white-space: nowrap; }
}

/* ---- art (tools/images.py: assets/<kind>/<name>.webp) ---- */
figure.fam-shot { display: block; min-height: 0; margin: 0 0 0.6rem; }
figure.fam-shot img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: var(--lift-sm);
}
.item-icon {
  width: 1.7em;
  height: 1.7em;
  margin: -0.2em 0.45em -0.2em 0;
  vertical-align: middle;
  object-fit: contain;
}
