/* ===========================================================================
   Lore terms and their tooltips.

   This is the signature element of the site. It is also the thing most likely
   to be annoying if handled carelessly, because a dense paragraph of tagged
   terms turns reading into a minefield of accidental taps.

   Two presentations, one data source:
     pointer: fine    → hover popover
     pointer: coarse  → tap opens a bottom sheet

   A sheet rather than a popover on touch because popovers clip at viewport
   edges, land under the thumb, and are fiddly to dismiss.
   ======================================================================== */

/* --- The term itself ----------------------------------------------------- */

.lore-term {
  color: inherit;
  cursor: help;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.2em;

  /* Grow the touch target vertically without disturbing line layout. The
     negative margin cancels the padding so surrounding text does not shift.
     --leading-body is set generously so adjacent lines' targets don't overlap. */
  padding-block: 0.45em;
  margin-block: -0.45em;

  /* Stops a long term breaking across lines mid-word, which would split the
     hit area into two disconnected rectangles. */
  white-space: nowrap;
}

/* A term that has an article is itself a link: hover defines it, click goes there.
   One without an article defines and nothing more, and must not look clickable —
   a pointer cursor over a word that does nothing is a promise the page breaks.
   The dotted underline and inherited colour keep both distinct from a .wiki-link,
   which is solid and accent-coloured because navigating is all it does. */
a.lore-term { cursor: pointer; }

/* A term nested inside somebody else's link. The annotator does not produce these
   — it never annotates within an <a> — but if one slips through, the link wins and
   the precedence should be visible. */
a .lore-term {
  text-decoration-color: currentColor;
  cursor: pointer;
}

.lore-term:hover,
.lore-term[aria-expanded='true'] {
  text-decoration-style: solid;
  background: var(--accent-wash);
  border-radius: var(--radius-sm);
}

.lore-term:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}

/* --- Desktop popover ----------------------------------------------------- */

.lore-popover {
  position: absolute;
  z-index: var(--z-tooltip);
  max-width: min(22rem, calc(100vw - 2rem));
  padding: var(--space-xs);
  background: var(--bg-raised);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);

  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}

.lore-popover[data-open] {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* --- Mobile bottom sheet ------------------------------------------------- */

.lore-sheet {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: var(--z-sheet);

  padding: var(--space-sm) var(--gutter);
  /* Keep clear of the home indicator on iOS */
  padding-block-end: max(var(--space-sm), env(safe-area-inset-bottom));

  background: var(--bg-raised);
  border-block-start: 1px solid var(--border);
  border-start-start-radius: var(--radius-sheet);
  border-start-end-radius: var(--radius-sheet);
  box-shadow: var(--shadow-lg);

  transform: translateY(100%);
  transition: transform var(--dur) var(--ease);
  touch-action: none;
}

.lore-sheet[data-open] { transform: translateY(0); }

/* Grab handle. Signals swipe-to-dismiss without needing a label. */
.lore-sheet__handle {
  width: 2.5rem;
  height: 4px;
  margin: 0 auto var(--space-xs);
  border-radius: 2px;
  background: var(--rule-strong);
}

.lore-sheet__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: var(--leading-tight);
  margin-block-end: var(--space-3xs);
}

.lore-sheet__category {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--accent);
  margin-block-end: var(--space-2xs);
}

.lore-sheet__body {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
  color: var(--fg-muted);
  margin-block-end: var(--space-sm);
}

.lore-sheet__link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  font-family: var(--font-ui);
  font-weight: 600;
}

.lore-sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-sheet) - 1);
  background: rgb(0 0 0 / 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.lore-sheet-scrim[data-open] { opacity: 1; pointer-events: auto; }

/* --- Print --------------------------------------------------------------- */

@media print {
  .lore-term { text-decoration: none; padding: 0; margin: 0; }
  .lore-popover, .lore-sheet, .lore-sheet-scrim { display: none; }
}

/* --- An aspect's kind ---------------------------------------------------- */

/* /wiki/aspects writes `### Vivimancer <span class="tag">Adept</span> {#vivimancer}`: the shared .tag
   (base.css) beside the name, so the kind is real text a screen reader hears with the heading. Not
   `*Adept*{.tag}` — Markdig gives that class to the heading and drops the heading's id. A heading is bold;
   a tag is not. */
.prose h3 .tag {
  font-weight: 400;
  vertical-align: 0.2em;
}

/* --- Cross-links between pages ------------------------------------------- */

/* A [[slug]] link the author wrote. Solid and accent-coloured because navigating is
   the whole of what it does; a .lore-term is dotted and takes the surrounding colour
   because it defines a word first, and only some of them also navigate. */
.wiki-link {
  color: var(--accent-strong);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

/* A link to a page that has not been written yet. The wiki-page skill treats this
   as a legitimate state, so it is marked rather than hidden or removed — a reader
   learns the subject exists, and the build can report it. */
.wiki-link--stub {
  color: var(--fg-muted);
  text-decoration-style: dotted;
  text-decoration-color: var(--rule-strong);
}
.wiki-link--stub::after {
  content: "?";
  font-size: 0.7em;
  vertical-align: super;
  color: var(--fg-faint);
  margin-inline-start: 0.1em;
}

/* --- Writer-only notes ---------------------------------------------------- */

/* Visibly not part of the article. A writer reading the page needs to know at a
   glance which paragraphs the public can see, without having to log out. */
.writer-notes {
  margin-block-start: var(--space-xl);
  padding: var(--space-sm);
  border: 1px dashed var(--secondary);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

/* The production layer is green, not red. It used to be --danger, which said
   "something is wrong here" about material that is merely staff-only, and it
   spent the one colour reserved for destructive actions on a panel that destroys
   nothing. Purple is the world, green is the writing team. */
.writer-notes > .label { color: var(--secondary); }

.writer-notes > :first-child { margin-block-start: 0; }

/* A row a reader would not have been shown at all: a writer-only page in the index,
   or a search hit that rests on a writers fence. Without it a writer scans a list
   with no way to tell which entries are public, and a search result whose visible
   title and summary contain none of the words they typed reads as a bug rather than
   as a hit. Same colour as the panel above, so the two read as one signal. */
.gated {
  /* inline-flex and centred, so the padlock sits on the badge's middle rather than its baseline (the author, the view
     check, 2026-10-22): as inline-block this overrode base.css's flex and dropped the icon low. */
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  margin-inline-start: var(--space-2xs);
  padding-inline: 0.4em;
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
  color: var(--secondary);
  /* Keeps the row height from growing when a badge is present, so a list of mixed
     entries does not jitter. */
  line-height: 1.5;
  vertical-align: baseline;
}

/* --- Key facts ------------------------------------------------------------ */

/* Read before the prose, not after it. Someone checking whether a creature is
   dangerous should not have to find that out in paragraph three. */
.facts {
  max-width: var(--measure);
  margin: var(--space-md) auto;
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

/* A record's counts on the reading column's own edge (the UI audit, 2026-10-19, G11): .facts caps itself at --measure in
   its own smaller face, so outside a .prose it sat narrower than the prose and centred. Inside one, it fills it. */
.prose > .facts--column { max-width: none; margin-inline: 0; }

.facts__row {
  display: grid;
  gap: var(--space-3xs);
  padding-block: var(--space-2xs);
  border-block-end: 1px solid var(--border);
}
.facts__row:last-child { border-block-end: 0; }

.facts__label {
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  font-size: var(--text-xs);
  color: var(--fg-faint);
}

.facts__value { margin: 0; color: var(--fg); }

/* Two columns once there is room for the label beside its value rather than above. */
@media (min-width: 32rem) {
  .facts__row {
    grid-template-columns: 11rem minmax(0, 1fr);
    align-items: baseline;
    gap: var(--space-sm);
  }
}

/* --- Index entries -------------------------------------------------------- */

/* The summary sits under the title rather than beside it. At 390px there is no
   room for two columns, and the title is the thing being scanned. */
/* break-inside because an open subcategory goes multi-column at 48rem and above — see
   base.css's `.index__pages`. Without it a column break lands between a title and the
   summary explaining it, which is the one pairing on the row that has to stay together.
   Added here rather than as a second `.index__entry` block beside that media query: two
   rules for one element are two things somebody has to notice. */
.index__entry {
  margin-block-end: var(--space-sm);
  break-inside: avoid;
}

.index__summary {
  margin: var(--space-3xs) 0 0;
  max-width: var(--measure);
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--fg-faint);
}

/* --- Timeline ------------------------------------------------------------- */

/* One column at every width. A horizontal timeline is the classic way to force a
   phone to scroll sideways, and no viewport is allowed to do that. The rule runs
   down the inline-start edge and the markers sit on it. */
.timeline {
  max-width: var(--measure);
  margin: var(--space-lg) auto;
  padding: 0 0 0 var(--space-md);
  list-style: none;
  border-inline-start: 1px solid var(--rule-strong);
}

.timeline__entry {
  position: relative;
  padding-block: var(--space-xs);
}

/* The marker, pulled back onto the rule. Sized in em so it tracks the text if the
   reader has scaled it up. */
.timeline__entry::before {
  content: "";
  position: absolute;
  inset-inline-start: calc(-1 * var(--space-md) - 0.3em);
  inset-block-start: 1.1em;
  inline-size: 0.55em;
  block-size: 0.55em;
  border-radius: 50%;
  background: var(--accent);
}

.timeline__when {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-sm);   /* a date is a sentence, so never in capitals (Dannaway 12; FE-10) */
  font-weight: 600;
  color: var(--fg-faint);
}

.timeline__what {
  margin: var(--space-3xs) 0 0;
  color: var(--fg);
}

/* --- In-world account ----------------------------------------------------- */

/* Visibly a primary source rather than the article. The reference text above is
   what the site asserts; this is testimony, and a reader should be able to tell
   which is which without being told. */
.account {
  max-width: var(--measure);
  margin: var(--space-xl) auto 0;
  padding-block-start: var(--space-md);
  border-block-start: 1px solid var(--rule-strong);
}

.account__heading {
  font-family: var(--font-ui);
  font-size: var(--text-sm);   /* four words, so sentence case: capitals are for a label of three or fewer (FE-10) */
  font-weight: 600;
  color: var(--fg-faint);
  margin-block-start: 0;
}

.account__attribution {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--fg);
  margin-block: var(--space-3xs) var(--space-sm);
}

.account__body {
  border-inline-start: 3px solid var(--rule);
  padding-inline-start: var(--space-sm);
  color: var(--fg-muted);
  font-style: italic;
}

/* Headings inside an account are the source's own structure, not the article's, so
   they sit quieter than the article's headings. */
.account__body h2,
.account__body h3,
.account__body h4 {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-style: normal;
  font-weight: 600;
  color: var(--fg-faint);   /* the source's own words, as written: never forced into capitals (FE-10) */
}

/* A record inside the panel, for the admin block under a character sheet. .facts
   caps itself at --measure, and --measure is 66ch measured in .facts' OWN font —
   Archivo at 14px — which comes out about 100px narrower than the panel holding
   it, so it sat visibly inset as a box inside a box. A record consulted at a
   glance should fill what it is given. */
.writer-notes--record .facts { max-width: none; margin-inline: 0; }

/* Gaps are a task list, not a note, so they read as one. */
.writer-notes--gaps { border-style: dashed; border-color: var(--gold-leaf); }
.writer-notes--gaps > .label { color: var(--gold-leaf); }
.writer-notes--gaps ul { margin-block: var(--space-2xs) 0; padding-inline-start: var(--space-sm); }

/* --- The chronicle's ornament (the author's overhaul, 2026-10-12) ------------
   Brass from the art in wwwroot/art: the brass bar under a page's title and over each section (the flourishes were
   removed for now, the author 2026-11-18, FE-10),
   a smaller one over each section, the facts block's corners, a framed image and
   an opening initial. Only in the book register, so the game's screens,
   which share .prose, are left to base.css. */

[data-register="book"] .prose > h1 {
  text-align: center;
  text-wrap: balance;
}
/* The brass bar (Fantasy RPG GUI), its ends fading: under a title, and a short length over a section heading. */
[data-register="book"] .prose > h1::after,
[data-register="book"] .prose > h2::before {
  content: "";
  display: block;
  background: url("../art/title-bar.png") center / 100% 100% no-repeat;
  mask-image: linear-gradient(to right, transparent, #000 8%, #000 92%, transparent);
}
[data-register="book"] .prose > h1::after { width: min(22rem, 80%); height: 6px; margin: var(--space-xs) auto 0; }
[data-register="book"] .prose > .label { text-align: center; }
[data-register="book"] .prose > h2 {
  text-align: center;
  text-wrap: balance;
}
[data-register="book"] .prose > h2::before { width: min(9rem, 60%); height: 4px; margin: 0 auto var(--space-2xs); }
/* A section that begins straight under the title shares the title's bar rather than adding its own: the two side by
   side read as a stutter (the author, on /about, 2026-10-23). */
[data-register="book"] .prose > h1 + h2::before { display: none; }

/* An article's opening initial: the first paragraph after the facts block, which is where an article's prose
   begins. Shipped with the overhaul after the author saw it in the mock-ups (2026-10-12); the page-by-page audit
   is where a page whose opening it reads badly on is caught. */
[data-register="book"] .prose > .facts + p::first-letter,
[data-register="book"] .prose > .article-rail:has(.facts) + p::first-letter {
  float: left;
  font-family: var(--font-display);
  font-size: 3.4em;
  line-height: 0.85;
  padding: 0.06em 0.08em 0 0;
  color: var(--accent-strong);
}

[data-register="book"] .facts {
  background:
    url("../art/corner-tl.png") left top / 48px auto no-repeat,
    url("../art/corner-tr.png") right top / 48px auto no-repeat,
    url("../art/corner-bl.png") left bottom / 48px auto no-repeat,
    url("../art/corner-br.png") right bottom / 48px auto no-repeat,
    var(--parchment-grain),
    var(--paper-sunken);
  border: 0;
  padding: var(--space-md);
  box-shadow: inset 0 0 0 1px var(--rule-strong), var(--depth-plate);   /* a plate (FE-10) */
}

[data-register="book"] .prose img {
  border: 6px solid #3b2c1e;
  outline: 1px solid #a88c5c;
  outline-offset: -3px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.35);
}

/* A painted icon inside an article is a mark, not a picture: none of the framed-image treatment above, which stretched
   the writers' padlock to the column's width in a brass frame (the author, 2026-10-20). */
.prose img.icon,
[data-register="book"] .prose img.icon {
  width: auto;
  max-width: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  box-shadow: none;
}

/* A writers-only article's own mark, under its title (W04): the padlock centred, its words under it, in the
   production layer's verdigris, with no badge outline (the author, 2026-10-20). */
.article-gated {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3xs);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--secondary);
}
.article-gated__label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

/* --- The image viewer (image-viewer.js; the UI audit, 2026-10-19, W03) -------------------------------------------
   A reading page's image is a link to itself, and opens in a full-screen <dialog> on the same tab: fitted first, its
   actual size a press away to pan around in, pinch-zoom left to the phone. Through tokens, so both themes. */
.viewer-link { display: block; cursor: zoom-in; }
.viewer-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.viewer {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--fg);
}
.viewer[open] { display: flex; flex-direction: column; }
/* Dimmed black in both themes on purpose: the dialog covers the page, and --ink turns light in dark. */
.viewer::backdrop { background: rgb(0 0 0 / 0.7); }

.viewer__bar {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border-block-end: 1px solid var(--border);
}
.viewer__button {
  min-height: var(--tap-min);
  padding: 0 var(--space-sm);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--fg);
  font: 600 var(--text-sm) var(--font-ui);
  cursor: pointer;
}
.viewer__button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.viewer__stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
/* Fitted, the image fills exactly the space between the bar and the caption and never scrolls (the author, 2026-10-20):
   absolutely placed in the stage, contained, so its size comes from the stage rather than from its own pixels. */
.viewer__stage[data-zoom="fit"] { overflow: hidden; }
.viewer__stage[data-zoom="fit"] .viewer__image {
  position: absolute;
  inset: var(--space-xs);
  width: calc(100% - 2 * var(--space-xs));
  height: calc(100% - 2 * var(--space-xs));
  object-fit: contain;
  cursor: zoom-in;
}
/* Actual size: its own pixels, panned by scrolling the stage in both directions. */
.viewer__stage[data-zoom="actual"] .viewer__image {
  display: block;
  max-width: none;
  max-height: none;
  margin: var(--space-xs);
  cursor: zoom-out;
}

.viewer__caption {
  margin: 0;
  padding: var(--space-xs) var(--space-sm);
  border-block-start: 1px solid var(--border);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  max-height: 25dvh;
  overflow: auto;
}

/* --- A path: an aspect's or a trade's ranks, folded ------------------------ */

/* /wiki/aspect-paths and /wiki/trades write each aspect or trade as a fold (the author, 2026-11-14): a <details> whose
   summary is the heading, so the index lists names a reader opens one at a time and a link to the heading lands on
   it; open-target.js opens the fold a link lands inside. Within it a rail holds the ranks together: a node for each
   rung, and each rung's Masters or holders branching off a thinner line of their own. Written as HTML around the
   Markdown, so every heading keeps the id a [[slug#heading]] lands on. */
.prose .path {
  margin-block-start: var(--space-2xs);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

/* A field or a family heads its folds with a rule, and stands well clear of the last fold above, so what belongs
   together reads as one group. */
.prose h2:has(+ .path) {
  margin-block-start: var(--space-xl);
  padding-block-end: var(--space-3xs);
  border-block-end: 1px solid var(--rule-strong);
}
.prose h2 + .path { margin-block-start: var(--space-sm); }

.path__name {
  display: flex;
  align-items: center;
  gap: var(--space-2xs);
  min-height: var(--tap-min);
  padding: var(--space-2xs) var(--space-sm);
  cursor: pointer;
  list-style: none;
}
.path__name::-webkit-details-marker { display: none; }
.path__name::after {
  content: "\25BE";
  margin-inline-start: auto;
  color: var(--fg-faint);
  font-size: var(--text-sm);
}
.path[open] > .path__name::after { content: "\25B4"; }
.path[open] > .path__name { border-block-end: 1px solid var(--rule); }
.path__name > h3 {
  margin: 0;
  font-size: var(--text-lg);
}
.path__name:hover > h3 { color: var(--accent-strong); }

.path__about {
  margin: var(--space-sm) var(--space-sm) 0;
  color: var(--fg-muted);
}
.path__about > p { margin: 0; }

/* The rail. Its children sit a step in from it; each rung's node is centred on the 2px line. */
.path__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin: var(--space-sm) var(--space-sm) var(--space-md) calc(var(--space-sm) + 5px);
  padding-inline-start: var(--space-md);
  border-inline-start: 2px solid var(--rule-strong);
}
.path__rung { position: relative; }
.path__rung > * { margin: 0; }
.path__rung > * + * { margin-block-start: var(--space-2xs); }
.path__rung::before {
  content: "";
  position: absolute;
  inset-inline-start: calc(-1 * var(--space-md) - 7px);
  inset-block-start: 0.3em;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--bg-raised);
}
/* A Master reached by more than one road sits where the roads meet: a diamond rather than a ring. */
.path__rung--shared::before { border-radius: 2px; transform: rotate(45deg); }
/* The top of a Tempered aspect, the name the town gives any of them: the node filled. */
.path__rung--top::before { background: var(--accent); }
.path__rung--top > p { font-style: italic; color: var(--fg-muted); }

.path__rung > h4 { font-size: var(--text-base); }

.path__level {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-faint);
}

/* A rung's Masters, or a trade rank's holders, branch off a line of their own. */
.path__rung > ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  list-style: none;
  padding-inline-start: var(--space-sm);
  border-inline-start: 1px solid var(--rule-strong);
}
.path__rung > ul > li { position: relative; }
.path__rung > ul > li::before {
  content: "";
  position: absolute;
  inset-inline-start: calc(-1 * var(--space-sm));
  inset-block-start: 0.8em;
  width: calc(var(--space-sm) - 4px);
  border-block-start: 1px solid var(--rule-strong);
}
