/* ===========================================================================
   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; }
}

/* --- 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 {
  display: inline-block;
  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);
}

.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-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  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-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  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;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-faint);
}

/* 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); }
