/* Dungeon Master v0.4 — unified dark theme.
 *
 * Single source of truth for the application chrome. Mirrors the
 * harness palette in `static/harness/dashboard.css` so every page
 * (catalog, play, spectator, auth, landing) reads as the same app.
 *
 * Conventions:
 *   --bg     : page background (deepest)
 *   --panel  : card/topbar background
 *   --border : low-contrast separator
 *   --text   : primary copy
 *   --muted  : labels, hints, secondary copy
 *   --accent : interactive accent (links, primary buttons, active outlines)
 *   --good   : success / positive numbers
 *   --warn   : warnings / amber metrics
 *   --bad    : destructive / negative numbers
 *
 * Type stack:
 *   --font-sans    : Geist Sans  — body, UI chrome, headings
 *   --font-mono    : JetBrains Mono — IDs, dice, JSON, KPI numerals
 *   --font-display : Cormorant Garamond — entity-name <h1> only,
 *                    for sourcebook flavor on friendly catalog views.
 *
 * Responsive breakpoints (standardized):
 *   mobile  : max-width: 640px
 *   tablet  : 641px to 1023px
 *   desktop : min-width: 1024px
 */

:root {
  /* Candlelit Grimoire — warm ink-black base, ember + gold accents.
     The cold GitHub-dark slate/blue was retired for an atmospheric
     dark-fantasy key. Component classes are unchanged; only the tokens
     (and the atmosphere layer at the foot of this file) carry the theme. */
  --bg: #0c0a07;          /* deepest page — warm ink black */
  --bg-2: #120d09;        /* subtly raised */
  --panel: #17120c;       /* cards / topbar — aged vellum-dark */
  --panel-2: #1e1710;     /* nested raised panel */
  --border: #3a2e1d;      /* brass-shadow separator */
  --border-soft: #2a2115; /* faint inner separators */
  --text: #ece1cb;        /* parchment */
  --muted: #9a8a6e;       /* aged paper / secondary */
  --accent: #e0792c;      /* EMBER — primary interactive */
  --accent-rgb: 224, 121, 44;
  --gold: #c9a227;        /* BRASS/GOLD — display headings, active, highlights */
  --gold-rgb: 201, 162, 39;
  --good: #3fb950;        /* success (kept; reads fine on warm black) */
  --good-rgb: 63, 185, 80;
  --warn: #d29922;        /* amber */
  --warn-rgb: 210, 153, 34;
  /* Cross-file semantic colours (6.1 colour pass) — each was hardcoded in 3–7 stylesheets. */
  --on-accent:   #1a1206;   /* ink ON a filled accent/gold surface (buttons, pills, seg.on) */
  --bg-deep:     #0b0805;   /* deeper than --bg: stage/well backdrops */
  --bad-hover:   #f0c0b0;   /* destructive hover tint */
  --chip-bg:     #2e2613;   /* chip / tag background */
  --bad: #f85149;         /* danger */
  --bad-rgb: 248, 81, 73;
  /* alias — several screens grew up calling it --danger; keep ONE red */
  --danger: var(--bad);
  --danger-rgb: var(--bad-rgb);
  /* alias — the card family (cards.css) grew up calling success --ok; keep ONE green */
  --ok: var(--good);
  --ok-rgb: var(--good-rgb);
  /* card-family SOFT ramps — the brass/dried-blood border tints the card language is built on
     (deliberately softer than --gold-rgb/--bad-rgb; use as rgba(var(--gold-soft-rgb), .X)) */
  --gold-soft-rgb: 200, 164, 100;
  --bad-soft-rgb: 190, 70, 60;

  /* SEMANTIC TINTS — faction + terrain overlays (rgb triples, so screens control alpha via rgba()). */
  --tint-attack-rgb: 224, 88, 78;        /* hostile/target/attack red — reticle, blocked route, atk btn */
  --tint-veg-rgb: 80, 120, 60;           /* light vegetation / brush fill */
  --tint-veg-hi-rgb: 150, 200, 120;      /* light vegetation label */
  --tint-veg-dense-rgb: 50, 90, 45;      /* dense foliage fill */
  --tint-veg-dense-hi-rgb: 120, 175, 100; /* dense foliage label */

  /* ONE card-frame recipe — the family chrome (.vcard/.pcard, panels via panels.css) */
  --card-bg: linear-gradient(180deg, var(--panel-2), var(--panel));
  --card-shadow: 0 0.375rem 1.625rem -0.5rem rgba(0, 0, 0, .6);

  --glow-ember: 0 0 1.125rem -0.25rem rgba(var(--accent-rgb), 0.55);
  --glow-gold: 0 0 1rem -0.3125rem rgba(var(--gold-rgb), 0.5);

  --font-sans: "Geist Sans", "Geist", ui-sans-serif, system-ui, -apple-system,
               BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono",
               Menlo, Consolas, monospace;
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;

  /* TYPE RAMP — the ONE source for UI/body sizes (rem, so Interface-size scales them in lockstep).
     New code MUST use these; off-grid literals migrate onto the nearest step opportunistically. */
  --fs-micro:  0.5625rem;   /*  9px  — tiniest micro-caps / superscript */
  --fs-2xs:    0.625rem;    /* 10px  — micro-caps labels (.mlbl default) */
  --fs-xs:     0.6875rem;   /* 11px  — dense captions / meta */
  --fs-sm:     0.75rem;     /* 12px  — the workhorse body/control size */
  --fs-smplus: 0.78125rem;  /* 12.5px — promoted (was 72 loose uses) */
  --fs-base:   0.8125rem;   /* 13px  — comfortable body */
  --fs-md:     0.875rem;    /* 14px  — emphasis body / small heading */
  --fs-lg:     1rem;        /* 16px  — large body / inline heading */
  /* DISPLAY LADDER (Cormorant headings) — 5 steps; snap headings here, keep clamp() heroes. */
  --fs-hero:   1.875rem;
  --fs-page:   1.625rem;
  --fs-card:   1.5rem;
  --fs-modal:  1.375rem;
  --fs-sub:    1.1875rem;

  /* SPACING SPINE — the ONE source for padding/gap/margin (rem, scales with Interface size).
     Covers ~89% of authored spacing; 0.3125/0.4375/0.5625 fold onto the nearest step. */
  --sp-1:  0.125rem;    /*  2px */
  --sp-2:  0.1875rem;   /*  3px */
  --sp-3:  0.25rem;     /*  4px */
  --sp-4:  0.375rem;    /*  6px */
  --sp-5:  0.5rem;      /*  8px */
  --sp-6:  0.625rem;    /* 10px */
  --sp-7:  0.75rem;     /* 12px */
  --sp-8:  0.875rem;    /* 14px */
  --sp-9:  1rem;        /* 16px */
  --sp-10: 1.25rem;     /* 20px */
  --sp-11: 1.5rem;      /* 24px */

  /* RADIUS SCALE — one source; 0.3125/0.4375/0.5625 fold onto neighbors. */
  --r-xs:   0.1875rem;  /*  3px */
  --r-sm:   0.25rem;    /*  4px */
  --r-md:   0.375rem;   /*  6px — default control radius */
  --r-lg:   0.5rem;     /*  8px */
  --r-xl:   0.625rem;   /* 10px */
  --r-2xl:  0.75rem;    /* 12px */
  --r-pill: 62.4375rem; /* full-round for chips/pills */
  --r-round: 50%;       /* circles/avatars */

  /* SHADOWS + RINGS — keep --card-shadow/--glow-* (above); these absorb the loose drop/ring recipes. */
  --shadow-drop-sm: 0 0.5rem 1.5rem -0.625rem rgba(0, 0, 0, .6);
  --shadow-drop-md: 0 0.875rem 2.5rem -0.75rem rgba(0, 0, 0, .8);
  --shadow-card:    0 0.75rem 1.875rem -1rem rgba(0, 0, 0, .85), inset 0 0.0625rem 0 rgba(255, 255, 255, .05);
  --shadow-drop-lg: 0 1.5rem 4.375rem rgba(0, 0, 0, .6), inset 0 0.0625rem 0 rgba(255, 255, 255, .05);
  --ring-hairline: inset 0 0 0 0.0625rem var(--border-soft);
  --ring-focus: 0 0 0 0.1875rem rgba(var(--accent-rgb), .45);
  --scroll-slim: 0.375rem;   /* narrow scrollbar rail for card/panel columns */

  --ease-soft: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* KEYBOARD FOCUS — the ONE source. Every interactive element shows a crisp accent ring on keyboard
   focus (:focus-visible follows border-radius); pointer focus stays quiet (buttons never match it on
   click; text inputs do, which is correct). Replaces the ~31 scattered `outline: none` suppressors. */
:focus-visible { outline: 0.125rem solid var(--accent); outline-offset: 0.0625rem; }

/* INTERFACE SIZE (Display setting). The whole UI is sized in `rem`, so one root font-size scales
   everything — type, spacing, controls, icons, tap targets — in lockstep. Default = 16px, the
   base every rem was authored against, so Default is pixel-identical to before. */
html { font-size: 16px; }
:root[data-uiscale="small"]  { font-size: 14px; }    /* 0.875× — more on screen */
:root[data-uiscale="large"]  { font-size: 18px; }    /* 1.125× */
:root[data-uiscale="xlarge"] { font-size: 20px; }    /* 1.25×  */

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.45;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

code, .mono, .font-mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-variant-ligatures: none;
}

h1, h2, h3, h4 {
  color: var(--text);
  margin: 0 0 var(--sp-5) 0;
  font-weight: 600;
  font-family: var(--font-sans);
}
h1 { font-size: var(--fs-card); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-sub); }
h3 { font-size: var(--fs-md); }

p { margin: 0 0 var(--sp-5) 0; }

hr { border: 0; border-top: 0.0625rem solid var(--border); margin: var(--sp-9) 0; }

/* ---------- Layout shell ----------------------------------------- */

.topbar {
  background: var(--panel);
  border-bottom: 0.0625rem solid var(--border);
  position: sticky;
  top: 0;
  /* Above the floating HUD panels (compact band ≤ ~44 — see views/_panels.js) so the nav/account
     dropdowns are never buried under a raised panel; below full-screen modal overlays (60+). */
  z-index: 45;
}

.topbar-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--content-gutter);
  display: flex;
  align-items: center;
  gap: var(--sp-8);
  flex-wrap: wrap;
}

.topbar-brand {
  font-weight: 600;
  font-size: var(--fs-md);
  color: var(--text);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.topbar-brand:hover { text-decoration: none; color: var(--accent); }

.topbar-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-base);
  font-family: var(--font-mono);
}

.topbar-nav a {
  color: var(--muted);
  padding: var(--sp-3) var(--sp-6);
  border-radius: var(--r-pill);
  border: 0.0625rem solid transparent;
  transition: color 160ms var(--ease-soft), border-color 160ms var(--ease-soft);
}

.topbar-nav a:hover {
  color: var(--accent);
  border-color: var(--border);
  text-decoration: none;
}

.topbar-form {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  font-size: var(--fs-base);
  flex-wrap: wrap;
}

/* Mobile drawer toggle (hamburger). Hidden on >=tablet, revealed on
   mobile via the @media block below. The drawer state is held by a
   visually-hidden checkbox so the layout works without JS; a tiny
   inline <script> in base.html mirrors :checked into aria-expanded
   and closes the drawer when a nav link is tapped. */
.topbar-toggle {
  display: none;
  margin-left: auto;
  background: var(--bg);
  color: var(--text);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-md);
  width: 2.75rem;
  height: 2.75rem;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: var(--fs-sub);
  line-height: 1;
}
.topbar-toggle:hover { border-color: var(--accent); color: var(--accent); }
.topbar-toggle[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }







:root {
  /* Site content width. Operator's law: MAXIMIZE horizontal space at every viewport — content fills
     the full width with only the side gutter; NO centered cap (a 2400px cap stranded content in the
     middle with big dead margins on wide/ultrawide monitors). Chrome (topbar/footer/strip) shares the
     same gutter so everything stays edge-aligned. */
  --content-max: none;
  --content-gutter: clamp(1rem, 2.6vw, 3.75rem);
}
main.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1.375rem var(--content-gutter);
}

footer.app-footer {
  background: var(--panel);
  border-top: 0.0625rem solid var(--border);
  color: var(--muted);
  font-size: var(--fs-sm);
  /* Pinned to the viewport bottom so the status/fleet bar is ALWAYS visible —
     long page content scrolls beneath it instead of pushing it off-screen.
     main.app-main reserves bottom space (below) so nothing hides behind it. */
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  backdrop-filter: blur(0.375rem);
}
:root { --footer-h: 3rem; }
main.app-main { padding-bottom: calc(var(--footer-h) + 1.125rem); }
/* Combat is a focused full-screen mode with its own bottom HUD/action tray —
   the global pinned footer would overlap it, so hide it there. */
body:has(.play-stage) footer.app-footer { display: none; }

/* Full-height pages (the Lab workbench) must know exactly how much vertical space the
   body actually has: constrain app-main to the gap between the topbar and the fixed
   footer and make it a flex column, so a child can fill it and scroll INTERNALLY
   instead of growing the page. (app-main already reserves --footer-h below.) */
body:has(.lab2) main.app-main {
  /* app-main is a `flex:1` child of the body flex-column, so a plain `height` only sets
     its flex-BASIS — content can still grow it. Pin it to its box so overflow:hidden
     actually clips and inner zones scroll instead of expanding the page. */
  flex: 0 0 auto;
  height: calc(100dvh - var(--topbar-h, 3.5rem));
  max-height: calc(100dvh - var(--topbar-h, 3.5rem));
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* The SPA router mounts every view into the intermediate `#app` div. On a full-height Lab
   page that div sits between the pinned app-main and `.lab2`, so it must ITSELF fill the
   column and be a flex parent — otherwise `.lab2`'s `flex:1` never resolves and the transcript
   grows past (and is clipped by) the pinned box instead of scrolling internally. */
body:has(.lab2) main.app-main > #app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

footer.app-footer .footer-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--content-gutter);
  display: flex;
  align-items: center;
  gap: var(--sp-9);
  justify-content: space-between;
  flex-wrap: wrap;
}
.footer-tag { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }
.fleet-panel .fleet-host { margin-right: var(--sp-7); }

/* ---------- Panel primitive -------------------------------------- */

.panel {
  background: var(--panel);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-8) 1.125rem;
}

.panel + .panel { margin-top: var(--sp-8); }

.panel h2,
.panel-title {
  margin: 0 0 var(--sp-6) 0;
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.panel-meta {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.panel-link {
  font-size: var(--fs-sm);
  color: var(--muted);
}

.panel-link:hover { color: var(--accent); }

/* ---------- KPI cards -------------------------------------------- */









.kpi .kpi-value.good { color: var(--good); }
.kpi .kpi-value.warn { color: var(--warn); }
.kpi .kpi-value.bad  { color: var(--bad); }

/* ---------- Card-family shared recipes ---------------------------- */
/* ONE slider look everywhere (zoom, tolerance, atmosphere ranges, …) */
input[type="range"] { accent-color: var(--accent); }

/* ONE micro-label recipe — small-caps mono label used across the card language
   (eyebrows, section heads, table heads, pip labels). Tune per site via the knobs;
   existing card classes attach to this in cards.css via a grouped selector. */
.mlbl,
.vc-eyebrow, .vc-source, table.vc-roll th, .vclab-var, .pclab-sandbox-l,
.pc-ds-l, .pc-slots-l, .pc-res-cad, .dmc-qwho,
.pchar-lbl, .pchar-sub, .pchar-hpk, .pchar-mode-l, .pchar-sk-h, .pchar-inv-h, .pchar-ban,
.dmc-sh, .dmc-tl, .dmc-boardh, .loot-t, .loot-foundcat,
.vc-more > summary, .pchar-inv-base-l, .pchar-hped-l, .cb-panel h3 {
  font: 600 var(--mlbl-fs, 0.625rem)/var(--mlbl-lh, 1) var(--font-mono);
  letter-spacing: var(--mlbl-ls, .1em);
  text-transform: uppercase;
  color: var(--mlbl-c, var(--muted));
}

/* ONE card-frame recipe — the family window chrome. Bound directly to its real consumers: the card
   family (.vcard/.pcard) and the docked panels (cb-hud clusters + builder rails). Padding stays
   per-site. Change the frame HERE and every card/panel updates. (.ref-pop is a deliberately tighter
   popover variant — NOT bound here.) */
.vcard,
.pcard,
.cb-hud .cb-panel,
.mb-rail .cb-panel {
  background: var(--card-bg);
  border: 0.0625rem solid var(--border);
  border-top: 0.1875rem solid var(--accent);
  border-radius: var(--r-xl);
  box-shadow: var(--card-shadow);
}

/* ---------- Status pills ----------------------------------------- */

/* ONE outlined-pill recipe — shared by .status-pill and the card family's .vc-pill (cards.css keeps
   only the .vc-pill colour variants). State variants recolor text+border instead of filling solid.
   Change the pill shape HERE and both update. */
.status-pill,
.vc-pill {
  font: 600 var(--fs-2xs)/1 var(--font-mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: var(--sp-3) 0.4375rem;
  border-radius: var(--r-pill);
  border: 0.0625rem solid var(--border);
  color: var(--muted);
  background: rgba(0, 0, 0, .18);
}
.status-pill { display: inline-block; transition: filter 160ms var(--ease-soft); }

.status-pill:hover { filter: brightness(1.05); }

/* Sub-location placement overlay (Atlas studio) */
.plate-frame { position: relative; }

.claimed-layer .claimed {
  fill: rgba(231,200,121,.16); stroke: rgba(231,200,121,.9); stroke-width: .5;
  pointer-events: none;          /* display-only; navigate via the cards below */
}
.claimed-layer .draw-poly { fill: rgba(216,178,90,.18); stroke: #d8b25a; stroke-width: .6; }
.claimed-layer .place-marker { fill: rgba(216,178,90,.5); stroke: #d8b25a; stroke-width: .4; }
.place-mode { font-size: var(--fs-sm); color: var(--muted); display: inline-flex; gap: var(--sp-6); align-items: center; }
.place-mode label { display: inline-flex; gap: var(--sp-2); align-items: center; cursor: pointer; }
.btn-mini { font-size: var(--fs-xs); padding: 0.0625rem var(--sp-5); }

.add-error { color: var(--bad); font-size: var(--fs-base); margin: var(--sp-4) 0; }
.add-hint { color: var(--muted); font-size: var(--fs-sm); margin-left: var(--sp-5); }

/* Switchboard fleet panel (global footer) */
.fleet-panel { font-size: var(--fs-xs); color: var(--muted); cursor: pointer; text-align: right; }
.fleet-panel .fleet-host { display: inline-block; }
.fleet-panel .status-pill { font-size: var(--fs-2xs); padding: 0.0625rem var(--sp-4); text-transform: none; }

.status-pill.live,
.status-pill.running { color: var(--accent); border-color: rgba(var(--accent-rgb), .5); }
.status-pill.done,
.status-pill.good    { color: var(--good); border-color: rgba(var(--good-rgb), .5); }
.status-pill.warn    { color: var(--warn); border-color: rgba(var(--warn-rgb), .5); }
.status-pill.error,
.status-pill.bad     { color: var(--bad); border-color: rgba(var(--bad-rgb), .5); }

.status-pill.canonical { color: var(--muted); }
.status-pill.override  { color: var(--accent); border-color: rgba(var(--accent-rgb), .5); }
.status-pill.hide      { color: var(--bad); border-color: rgba(var(--bad-rgb), .5); }
.status-pill.new       { color: var(--good); border-color: rgba(var(--good-rgb), .5); }
.status-pill.variant   {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent);
  border: 0.0625rem solid rgba(var(--accent-rgb), 0.45);
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* Pills that hold human-readable book titles (after the source-id →
   title rewrite) need to behave on long strings without breaking the
   header / list / search rows they sit in. Cap width with an ellipsis
   and drop the all-caps treatment that worked for short tokens like
   ``PHB`` but reads poorly for "Tasha's Cauldron of Everything".
   The id stays available on hover via the ``title`` attribute, so
   readability is preserved at no cost. */
.status-pill.variant, .status-pill.source{
  max-width: 32ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
  vertical-align: middle;
}

/* Compact source modifier — used in dense table cells (search
   results, list rows) where vertical room is at a premium. */
.status-pill.source {
  max-width: 24ch;
}

/* Tagged-id pills carry a small inline source chip showing where
   the referenced entity came from (PHB / TCoE / MPMM / …). The
   chip inherits the pill's background but adds a colored stripe
   on the right edge so multi-source lists scan visually at a
   glance. */

.tagged-pill .source-chip {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.0625rem 0.3125rem;
  border-radius: var(--r-xs);
  background: var(--bg);
  color: var(--muted);
  border: 0.0625rem solid var(--border);
  line-height: 1.4;
}
/* Source-specific tints — accent for the most common patches, muted
   for base sources. Match on the ``data-token`` attribute the
   templates stamp on the chip; the chip's ``title`` attribute now
   carries a free-text "From <book title>" string, so it can't be
   used as a selector key. Unknown tokens fall back to the default
   chip colour. */
.tagged-pill .source-chip[data-token="PHB"],
.tagged-pill .source-chip[data-token="MM"],
.tagged-pill .source-chip[data-token="DMG"] {
  color: var(--muted);
  border-color: var(--border);
}
.tagged-pill .source-chip[data-token="XGTE"],
.tagged-pill .source-chip[data-token="TCOE"],
.tagged-pill .source-chip[data-token="MPMM"],
.tagged-pill .source-chip[data-token="MTOF"],
.tagged-pill .source-chip[data-token="VRGTR"],
.tagged-pill .source-chip[data-token="SCAG"],
.tagged-pill .source-chip[data-token="JTRC"] {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.08);
}

/* ---------- Variants strip (header) + chip strip (list) --------- */









.variant-pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

/* List-view inline chips — slightly smaller, sit next to the name. */






.variant-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}








/* ---------- Chain strip (composition layers) -------------------- */







/* Numbered prefix on each chain chip — the "1", "2", "3" badges
   that make ordering scannable. */


/* Tiny role caption inside the chip — "base" / "mid" / "top" — so
   the chain orientation isn't carried only by border colour. */


/* Arrow rendered between chips. Pure visual cue for direction. */


.chain-chip.is-base {
  border-style: dashed;
  border-color: var(--border);
}

.chain-chip.is-mid {
  /* Mid layers in a 3+ chain — neutral but still clearly between
     base and top. */
  border-color: var(--border);
}

.chain-chip.is-top {
  border-color: var(--accent);
  color: var(--accent);
}

.chain-chip.is-top .chain-chip-index {
  background: var(--accent);
  color: var(--bg);
}



















/* ---------- Per-field source badge ------------------------------- */

.field-source {
  display: inline-block;
  padding: 0 0.3125rem;
  border-radius: var(--r-xs);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--border);
  color: var(--muted);
  border: 0.0625rem solid transparent;
  margin-left: var(--sp-4);
  vertical-align: middle;
  line-height: 1.6;
}

.field-source.is-modified {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.08);
}

.field-source.is-small {
  font-size: var(--fs-micro);
  padding: 0 var(--sp-3);
  margin-left: var(--sp-3);
}

/* ---------- Per-list-element layer stripe ----------------------- */

.layer-stripe {
  position: relative;
  padding-left: var(--sp-6);
  border-left: 0.1875rem solid var(--muted);
  /* Subtle inset so the stripe sits inside the panel padding without
     overlapping the panel border. */
  margin-left: 0;
}

.layer-stripe--from-base { border-left-color: var(--border); }
.layer-stripe--from-patch { border-left-color: var(--accent); }

/* When the stripe wraps a <tr>, the border-left only applies to the
   leading <td>; ::before takes over to draw a continuous bar across
   the row's vertical extent. */
tr.layer-stripe { border-left: 0; padding-left: 0; }
tr.layer-stripe > td:first-child {
  border-left: 0.1875rem solid var(--muted);
  padding-left: var(--sp-6);
}
tr.layer-stripe--from-base > td:first-child { border-left-color: var(--border); }
tr.layer-stripe--from-patch > td:first-child { border-left-color: var(--accent); }

/* ---------- Diff highlight wrappers (variant compare) ----------- */

.diff-add {
  display: inline-block;
  border-left: 0.1875rem solid var(--good);
  background: rgba(63, 185, 80, 0.08);
  padding-left: var(--sp-4);
}

.diff-rm {
  text-decoration: line-through;
  color: var(--bad);
  background: rgba(248, 81, 73, 0.08);
}

.diff-change {
  background: rgba(210, 153, 34, 0.18);
  border-radius: var(--r-xs);
  padding: 0 var(--sp-2);
}



/* ---------- Compare card grid ----------------------------------- */



.compare-summary .diff-group { margin-top: var(--sp-9); }
.compare-summary .diff-group:first-of-type { margin-top: var(--sp-5); }

.compare-summary .diff-group-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 var(--sp-5) 0;
}

.compare-summary .diff-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-6);
}

@media (min-width: 800px) {
  .compare-summary .diff-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.compare-summary .diff-card {
  background: var(--bg);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-6) var(--sp-7);
  font-size: var(--fs-base);
  border-left-width: 0.1875rem;
}

.compare-summary .diff-card-change { border-left-color: var(--warn); }
.compare-summary .diff-card-add    { border-left-color: var(--good); }
.compare-summary .diff-card-rm     { border-left-color: var(--bad); }

.compare-summary .diff-card-path {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: baseline;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.compare-summary .path-token {
  color: var(--text);
}
.compare-summary .path-sep {
  color: var(--border);
  font-weight: 700;
  opacity: 0.6;
}
.compare-summary .path-index {
  color: var(--muted);
  font-size: var(--fs-2xs);
  background: var(--panel);
  padding: 0 var(--sp-3);
  border-radius: var(--r-xs);
}

.compare-summary .diff-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.875rem;
  height: 0.875rem;
  border-radius: var(--r-xs);
  font-weight: 700;
  font-size: var(--fs-xs);
  font-family: var(--font-mono, monospace);
  line-height: 1;
}
.compare-summary .diff-card-add  .diff-glyph { background: rgba(63, 185, 80, 0.18); color: var(--good); }
.compare-summary .diff-card-rm   .diff-glyph { background: rgba(248, 81, 73, 0.18); color: var(--bad); }

.compare-summary .diff-card-bodies {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--sp-5);
  align-items: start;
}

.compare-summary .diff-card-bodies-single {
  grid-template-columns: 1fr;
}

.compare-summary .diff-card-side {
  background: var(--panel);
  border-radius: var(--r-sm);
  padding: var(--sp-4) var(--sp-5);
  font-size: var(--fs-smplus);
  word-break: break-word;
  min-width: 0;
}

.compare-summary .diff-card-label {
  display: block;
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: var(--sp-3);
}

.compare-summary .diff-card-arrow {
  color: var(--warn);
  font-weight: 700;
  align-self: center;
  font-family: var(--font-mono, monospace);
}

.compare-summary .diff-card-before .diff-value {
  text-decoration: line-through;
  color: var(--muted);
}

.compare-summary .diff-card-after .diff-value,
.compare-summary .diff-card-add .diff-value {
  color: var(--text);
}

.compare-summary .diff-card-rm .diff-value {
  color: var(--bad);
  text-decoration: line-through;
}

.compare-summary .diff-value-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 var(--sp-5);
  border-left: 0.0625rem dotted var(--border);
}
.compare-summary .diff-value-list li {
  margin: var(--sp-1) 0;
}

@media (max-width: 640px) {
  .compare-summary .diff-card-bodies {
    grid-template-columns: 1fr;
  }
  .compare-summary .diff-card-arrow {
    transform: rotate(90deg);
    align-self: flex-start;
    margin: var(--sp-1) 0;
  }
}

/* ---------- Helpers ---------------------------------------------- */

.muted { color: var(--muted); }

.right { text-align: right; }
.center { text-align: center; }

.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: var(--sp-6); flex-wrap: wrap; }
.row-baseline { display: flex; align-items: baseline; gap: var(--sp-6); flex-wrap: wrap; }





.crumbs .sep { color: var(--border); }


/* Display-font entity name on friendly entity-detail views. The
   _header.html partial wraps the entity <h1> in .entity-name so
   only the catalog "what is this thing?" headers get the serif
   treatment; admin/raw/edit views keep the standard sans h1. */
.entity-name {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.015em;
  font-size: var(--fs-hero);
  line-height: 1.1;
  color: var(--text);
}

/* ---------- Buttons + inputs ------------------------------------- */

/* Segmented control — the honest single-select: one joined track, exactly one segment filled. Reach for
   this instead of a row of separate buttons whenever the choice is mutually exclusive (a season, a mode).
   NOT for actions or multi-select. Wraps inside its track when space is tight, staying one control. */
.seg { display: flex; flex-wrap: wrap; gap: var(--sp-1); background: var(--panel-2, #201b12);
  border: 0.0625rem solid var(--border); border-radius: var(--r-lg); padding: var(--sp-1); }
.seg > a { text-decoration: none; }
.seg > button, .seg > a {
  flex: 1 1 auto; text-align: center; border: none; background: none; color: var(--muted); cursor: pointer; font: inherit;
  padding: var(--sp-3) var(--sp-6); border-radius: var(--r-md); font-size: var(--fs-xs); line-height: 1.4; white-space: nowrap;
  transition: background .12s, color .12s;
}
.seg > button:hover, .seg > a:hover { color: var(--text); }
.seg > button.on, .seg > a.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.seg > button:focus-visible, .seg > a:focus-visible { outline: 0.125rem solid var(--accent); outline-offset: 0.0625rem; }
/* Icon variant — compact, content-sized segments (e.g. season) that never need to stretch or wrap.
   align-self:start stops a flex-column parent from stretching it to full width. */
.seg-icons { display: inline-flex; align-self: flex-start; }
.seg-icons > button { flex: 0 0 auto; font-size: var(--fs-md); padding: var(--sp-3) 0.5625rem; }

/* Base neutral button. Kept at a single class (0,1,0) so the .btn-primary/-bad/-good/-ghost variants
   — also (0,1,0), declared after — actually WIN for background/color. (A prior `button.btn, a.btn` in
   this list raised it to 0,1,1 and silently suppressed every variant fill.) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  min-height: 2rem;               /* comfortable tap floor for the standard action button */
  background: var(--bg);
  color: var(--text);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.3125rem var(--sp-7);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
  font-family: var(--font-sans);
  transition: border-color 160ms var(--ease-soft),
              color 160ms var(--ease-soft),
              transform 80ms var(--ease-soft);
}

/* SIZE modifiers — combine with .btn (the only sanctioned size deltas per 2.1). */
.btn-sm   { min-height: 1.75rem; padding: var(--sp-3) 0.5625rem;   font-size: var(--fs-sm); gap: var(--sp-3); }
.btn-mini { min-height: 1.5rem;  padding: var(--sp-2) 0.4375rem; font-size: var(--fs-xs); gap: var(--sp-2); }

.btn:not(:disabled):not(.is-disabled):hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.btn:not(:disabled):not(.is-disabled):active { transform: translateY(0.0625rem); }

/* Disabled — ONE treatment for the whole .btn family (buttons via :disabled, links via .is-disabled).
   Hover/active are gated on :not(:disabled):not(.is-disabled) below, so a disabled button never reacts. */
.btn:disabled, .btn[disabled], .btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:not(:disabled):not(.is-disabled):hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn-good {
  background: var(--good);
  color: var(--bg);
  border-color: var(--good);
  font-weight: 600;
}
.btn-good:not(:disabled):not(.is-disabled):hover { opacity: 0.85; color: var(--bg); }

.btn-bad {
  background: var(--bad);
  color: var(--bg);
  border-color: var(--bad);
  font-weight: 600;
}
.btn-bad:not(:disabled):not(.is-disabled):hover { opacity: 0.85; color: var(--bg); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
.btn-ghost:not(:disabled):not(.is-disabled):hover { color: var(--accent); border-color: var(--border); }

/* SELECTED / active toggle that stays a button = GOLD fill (operator 2026-08-02: ember fill is reserved for
   primary ACTIONS, gold fill means "currently selected/active"). One-of-N choosers become .seg, not this. */
.btn.is-selected, .btn.on, .btn.is-on {
  background: var(--gold); border-color: var(--gold); color: var(--bg); font-weight: 600;
}
.btn.is-selected:not(:disabled):hover, .btn.on:not(:disabled):hover, .btn.is-on:not(:disabled):hover {
  background: var(--gold); border-color: var(--gold); color: var(--bg);
}

/* ── GLOBAL form-control baseline ────────────────────────────────────────────
   Every text-like input / textarea / select gets the theme by default, so a bare
   element (no .field / .wiz-* / .camp-* wrapper, or one orphaned by a refactor)
   is NEVER a tiny grey UA box. Wrapped in :where() → ZERO specificity, so EVERY
   existing class rule still wins; this only "shows through" where nothing else
   styled the control. Checkboxes/radios/ranges/buttons/etc. are excluded (they
   keep accent-color via their own rules). */
:where(
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]):not([type=submit]):not([type=button]):not([type=reset]):not([type=image]),
  textarea,
  select
) {
  background: var(--bg);
  color: var(--text);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-5) 0.6875rem;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.4;

  transition: border-color 160ms var(--ease-soft), box-shadow 160ms var(--ease-soft);
}
:where(input:focus, textarea:focus, select:focus) {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.1875rem rgba(var(--accent-rgb), 0.12);
}
:where(input, textarea)::placeholder { color: var(--muted); opacity: 0.7; }
:where(textarea) { resize: vertical; min-height: 4rem; line-height: 1.5; }
:where(select) { cursor: pointer; color-scheme: dark; }   /* dark native dropdown chrome + arrow */
:where(select) option { background: var(--panel); color: var(--text); }
:where(input):disabled, :where(textarea):disabled, :where(select):disabled { opacity: 0.5; cursor: not-allowed; }

.field,
input[type="text"].field,
input[type="search"].field,
input[type="number"].field,
input[type="password"].field,
select.field,
textarea.field {
  background: var(--bg);
  color: var(--text);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.3125rem var(--sp-6);
  font-size: var(--fs-base);
  font-family: var(--font-sans);
  width: 100%;

  transition: border-color 160ms var(--ease-soft);
}

.field:focus { border-color: var(--accent); }

textarea.field { font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.5; }

/* Instrument-control-bar family REMOVED 2026-08-07 (one-source): .ctlbar/.seg-btn/.seg-field/
   .seg-label/.seg-ico had ZERO consumers (built for the retired reader/extraction pages), yet the
   block RE-DEFINED `.seg` + `.seg > *` and silently overrode the live segmented control above
   (it was supplying bg/height/overflow while block-1 supplied gap). ONE `.seg` now: line ~1203. */

.field-label {
  display: block;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: var(--sp-3);
  font-weight: 500;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-7);
}

/* ---------- Tables ----------------------------------------------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
  background: var(--panel);
}

.table th, .table td {
  padding: var(--sp-5) var(--sp-6);
  text-align: left;
  border-bottom: 0.0625rem solid var(--border);
}

.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg);
}

.table tbody tr:hover td { background: var(--bg); }

.table-wrap {
  background: var(--panel);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* Default table behaviour on narrow viewports: wrap in horizontal
   scroll. Pages that would rather re-stack into label/value pairs
   should add the .table--stack class instead. */


.table .mono, .table code {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--accent);
  background: transparent;
}

/* ---------- Card grid (landing) --------------------------------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16.25rem, 1fr));
  gap: var(--sp-8);
}

.card-grid.cols-4 {
  grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr));
}

.card {
  display: block;
  background: var(--panel);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-9) 1.125rem;
  color: var(--text);
  text-decoration: none;
  transition: border-color 200ms var(--ease-soft),
              transform 200ms var(--ease-soft),
              box-shadow 200ms var(--ease-soft);
}

.card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-0.0625rem);
  box-shadow: 0 0 0 0.0625rem rgba(var(--accent-rgb), 0.18),
              0 0.5rem 1.125rem -0.625rem rgba(var(--accent-rgb), 0.35);
}

.card-title {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: var(--sp-4);
  color: var(--text);
}

.card-icon { font-size: var(--fs-modal); }

.card-body {
  font-size: var(--fs-base);
  color: var(--muted);
  margin-bottom: var(--sp-5);
  line-height: 1.5;
}

.card-foot {
  font-size: var(--fs-xs);
  color: var(--muted);
  font-family: var(--font-mono);
}



/* ---------- Flash + alerts --------------------------------------- */

#flash:empty { display: none; }

.alert {
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-5) var(--sp-7);
  font-size: var(--fs-base);
  background: var(--panel);
}
.alert.success { border-color: var(--good); color: var(--good); }
.alert.error   { border-color: var(--bad);  color: var(--bad); }
.alert.info    { border-color: var(--accent); color: var(--accent); }

/* ---------- Definition lists ------------------------------------- */

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--sp-3) var(--sp-8);
  margin: 0;
  font-size: var(--fs-base);
}
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; color: var(--text); }
dl.kv dd code, dl.kv dd .mono {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

/* ---------- Pre / code blocks ------------------------------------ */

pre {
  background: var(--bg);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-6) var(--sp-7);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* ---------- HP bar (spectator roster) --------------------------- */



.hpbar.warn > span { background: var(--warn); }
.hpbar.bad  > span { background: var(--bad); }


/* ---------- Battlemap helpers ------------------------------------ */

.battlemap-frame {
  background: var(--bg);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-5);
  display: block;
  width: 100%;
}

.battlemap-svg {
  display: block;
  /* Fill the wrapper in BOTH dimensions; preserveAspectRatio="xMidYMid
     meet" on the <svg> handles fitting the actual graphics so wide-
     aspect maps don't crop and tall-aspect maps don't either. */
  width: 100%;
  height: 100%;
  background: var(--bg);
}

/* Pan/zoom viewport. Clips the SVG when zoomed past 100% so it
   doesn't blow out the page. Inner stage holds the transform state +
   lives OUTSIDE the HTMX swap target (#battlemap-region), which
   means user zoom + pan survive the periodic /battlemap refresh. */
.battlemap-viewport {
  position: relative;
  overflow: hidden;
  height: 78vh;
  max-height: 78vh;
  border-radius: var(--r-md);
  background: var(--bg);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

/* Pan/zoom stage + nested HTMX-swapped containers all need to fill
   the viewport so the SVG inside has a finite height to size against.
   Without this, SVG height auto-collapses to its viewBox-derived
   intrinsic height and overflows the viewport at non-4:3 aspects. */
.battlemap-pan-zoom {
  width: 100%;
  height: 100%;
  will-change: transform;
}
.battlemap-viewport #battlemap-region,
.battlemap-viewport .battlemap-frame {
  width: 100%;
  height: 100%;
}
.battlemap-viewport .battlemap-frame {
  /* Drop the inner padding so we don't shave 16 px off both axes —
     viewport already has the rounded background. */
  padding: 0;
  border: 0;
}

.battlemap-toolbar {
  align-items: center;
  flex-wrap: wrap;
}
.battlemap-toolbar .btn-ghost {
  padding: var(--sp-1) var(--sp-5);
  font-size: var(--fs-sm);
  line-height: 1.4;
}

.battlemap-cell { cursor: pointer; }
.battlemap-cell:hover { stroke: var(--accent); stroke-width: 2; }

.battlemap-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-7);
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-top: var(--sp-5);
}

.battlemap-legend .swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border: 0.0625rem solid var(--border);
  vertical-align: middle;
  margin-right: var(--sp-3);
}

/* ---------- Narration log ---------------------------------------- */







/* ---------- Audit timeline -------------------------------------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 0 0 var(--sp-9);
  border-left: 0.0625rem solid var(--border);
}

.timeline > li {
  position: relative;
  padding: var(--sp-4) 0 var(--sp-8) var(--sp-7);
  font-size: var(--fs-base);
}

.timeline > li::before {
  content: "";
  position: absolute;
  left: -1.3125rem;
  top: 0.75rem;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: var(--r-pill);
  background: var(--accent);
  border: 0.125rem solid var(--bg);
}

.timeline > li.create::before { background: var(--good); }
.timeline > li.delete::before { background: var(--bad); }

.timeline pre {
  margin-top: var(--sp-4);
  font-size: var(--fs-xs);
  max-height: 12.5rem;
}

/* ---------- Layout grids reused by many pages -------------------- */

.split-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-8);
}
@media (min-width: 900px) {
  .split-2 { grid-template-columns: 1fr 1fr; }
}

.split-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-8);
}
@media (min-width: 1100px) {
  .split-3 { grid-template-columns: 2fr 1fr; }
}

/* ---------- Misc utility classes used in templates -------------- */

.tabs {
  display: flex;
  gap: var(--sp-4);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-7);
}

.tabs .status-pill { cursor: default; }

/* Prevent forms inside flex layouts from collapsing inputs */
form.inline { display: inline-flex; align-items: center; gap: var(--sp-4); margin: 0; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-7);
  margin-bottom: var(--sp-7);
  flex-wrap: wrap;
}

.section-head h1 { margin: 0; }
.section-head .sub { color: var(--muted); font-size: var(--fs-base); }

/* ---------- Play screen — tactical-tool overlay layout ----------
   The /play/{cid} screen now puts the battlemap in a full-viewport
   stage; UI elements (party roster, action tray, narration drawer,
   view controls, generate-map controls) sit on TOP of the map as
   semi-transparent overlay panels at the corners + edges. Pure CSS
   positioning — only the narration drawer + generate-map popover
   ship a tiny bit of inline JS for toggling.
*/

:root {
  --topbar-h: 3.5rem;
  --crumbs-h: 2.25rem;
}

.play-stage {
  position: relative;
  height: calc(100dvh - var(--topbar-h, 3.5rem) - var(--crumbs-h, 2.25rem));
  /* Fallback for browsers without dynamic-viewport units. */
  min-height: calc(100vh - var(--topbar-h, 3.5rem) - var(--crumbs-h, 2.25rem));
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%,
      rgba(var(--accent-rgb), 0.04) 0%,
      transparent 65%),
    var(--bg-deep);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-lg);
}

/* Override main padding so the stage fills edge-to-edge. The play
   screen breaks out of the standard 1200px content column. */
body:has(.play-stage) main.app-main {
  max-width: none;
  padding: var(--sp-7) var(--sp-7) var(--sp-7);
}

.play-stage .battlemap-viewport {
  position: absolute;
  inset: 0;
  height: auto;
  max-height: none;
  border-radius: 0;
  border: 0;
}

/* ---------- Overlay panel primitive ------------------------------ */
.overlay-panel {
  position: absolute;
  z-index: 5;
  background: rgba(22, 27, 34, 0.92);
  -webkit-backdrop-filter: blur(0.5rem);
  backdrop-filter: blur(0.5rem);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 0.5rem 1.5rem -0.625rem rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  color: var(--text);
  font-size: var(--fs-sm);
}

.overlay-panel .panel-title {
  margin: 0 0 var(--sp-4) 0;
  font-size: var(--fs-xs);
}

.overlay-top-left    { top: 0.75rem;    left: 0.75rem;   max-width: 17.5rem; }
.overlay-top-right   { top: 0.75rem;    right: 0.75rem;  max-width: 22.5rem; }
.overlay-bottom {
  left: 50%;
  transform: translateX(-50%);
  bottom: 0.75rem;
  max-width: calc(100% - 22.5rem);
  min-width: min(26.25rem, 80%);
}
.overlay-bottom-left { bottom: 0.75rem; left: 0.75rem;   }

.overlay-right-drawer {
  top: 0.75rem;
  bottom: 0.75rem;
  right: 0.75rem;
  width: 20rem;
  max-width: 38vw;
  display: flex;
  flex-direction: column;
}

/* ---------- Party roster overlay -------------------------------- */
.party-overlay {
  padding: var(--sp-6) var(--sp-7);
  max-height: calc(100% - 1.5rem);
  overflow-y: auto;
}

.party-overlay h2 {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 var(--sp-5) 0;
  font-weight: 600;
}

.party-overlay-row {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  padding: var(--sp-4) var(--sp-3);
  border-top: 0.0625rem solid rgba(255, 255, 255, 0.04);
}
.party-overlay-row:first-of-type { border-top: none; }

.party-overlay-row.is-active {
  background: linear-gradient(90deg,
    rgba(var(--accent-rgb), 0.10) 0%,
    transparent 100%);
  margin: 0 -0.25rem;
  padding-left: var(--sp-5);
  padding-right: var(--sp-5);
  border-radius: var(--r-sm);
}

.party-overlay-row .swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: var(--r-pill);
  flex-shrink: 0;
  border: 0.09375rem solid var(--border);
}
.party-overlay-row.is-active .swatch { border-color: var(--accent); }

.party-overlay-row .name {
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.party-overlay-row .hpbar {
  width: 3.5rem;
  height: 0.3125rem;
  flex-shrink: 0;
}

.party-overlay-row .hp-text {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.party-overlay-row .ac-badge {
  font-size: var(--fs-2xs);
  color: var(--muted);
  font-family: var(--font-mono);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 var(--sp-3);
  flex-shrink: 0;
}

.party-overlay-row .active-dot {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: var(--r-pill);
  background: var(--accent);
  box-shadow: 0 0 0.375rem var(--accent);
  flex-shrink: 0;
}

/* ---------- Generate-map overlay (popover) ---------------------- */
.gen-map-overlay {
  padding: var(--sp-4);
}

.gen-map-overlay-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: transparent;
  border: 0;
  color: var(--text);
  cursor: pointer;
  font-size: var(--fs-sub);
  border-radius: var(--r-md);
}
.gen-map-overlay-toggle:hover { color: var(--accent); background: rgba(var(--accent-rgb),0.08); }

.gen-map-overlay-body {
  display: none;
  padding: var(--sp-6) var(--sp-7) var(--sp-7);
  width: 20rem;
  max-width: 90vw;
}
.gen-map-overlay.is-open .gen-map-overlay-toggle { display: none; }
.gen-map-overlay.is-open .gen-map-overlay-body   { display: block; }
.gen-map-overlay.is-open                         { padding: var(--sp-3) var(--sp-4) var(--sp-4); }

.gen-map-overlay-body .field-label {
  margin-top: var(--sp-4);
}

.gen-map-overlay-body form { display: flex; flex-direction: column; gap: var(--sp-4); }
.gen-map-overlay-body .row { gap: var(--sp-4); }
.gen-map-overlay-body .field { font-size: var(--fs-sm); padding: var(--sp-3) var(--sp-5); }

/* ---------- Narration drawer ------------------------------------ */

.narration-drawer .drawer-body {
  padding: var(--sp-7) var(--sp-8);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}



/* The drawer slides off-screen to the right when closed. The toggle
   tab stays anchored to the screen edge. */
.narration-drawer.is-closed {
  transform: translateX(calc(100% + 0.75rem));
}




/* When the drawer is closed the toggle becomes a stand-alone tab
   pinned to the right edge of the play stage. */
.narration-drawer.is-closed .narration-drawer-toggle {
  left: auto;
  right: 0;
  border-right: 0.0625rem solid var(--border);
  border-radius: var(--r-lg) 0 0 var(--r-lg);
}


/* ---------- View controls overlay ------------------------------- */



.viewctl-overlay .btn-ghost {
  padding: var(--sp-1) var(--sp-4);
  font-size: var(--fs-xs);
  min-height: 0;
  line-height: 1.2;
}

/* ---------- Phase 4: mode badge --------------------------------- */





/* ---------- Phase 4: scene strip / arc timeline ----------------- */
.scene-strip {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  flex-wrap: wrap;
  margin: 0 0 var(--sp-5) 0;
  padding: var(--sp-4) var(--sp-5);
  background: rgba(22, 27, 34, 0.6);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-lg);
}
.scene-strip-rail {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.scene-chip-form { display: contents; }
.scene-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.0625rem;
  padding: var(--sp-2) var(--sp-6);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: var(--fs-sm);
  line-height: 1.2;
}
.scene-chip:hover { border-color: var(--accent); }
.scene-chip.is-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.0625rem var(--accent) inset;
}
.scene-chip .scene-chip-kind {
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.scene-chip.kind-explore .scene-chip-kind { color: var(--accent); }
.scene-chip.kind-social  .scene-chip-kind { color: var(--good); }
.scene-chip.kind-combat  .scene-chip-kind { color: var(--bad); }
.scene-chip .scene-chip-title { font-weight: 600; }
.scene-arrow { color: var(--muted); font-size: var(--fs-sm); }
.scene-empty { font-size: var(--fs-sm); }
.scene-new { margin-left: auto; }
.scene-new > summary { list-style: none; cursor: pointer; }
.scene-new > summary::-webkit-details-marker { display: none; }

/* ---------- Phase 4: narrative stage (explore / social) --------- */
.play-stage.narrative-mode {
  display: block;
  overflow: visible;
  height: auto;
  min-height: 0;
  padding: 0;
  background:
    radial-gradient(circle at 50% 0%,
      rgba(var(--accent-rgb), 0.04) 0%, transparent 60%),
    var(--bg-deep);
}
.play-stage.narrative-mode.mode-social {
  background:
    radial-gradient(circle at 50% 0%,
      rgba(63, 185, 80, 0.05) 0%, transparent 60%),
    var(--bg-deep);
}

.play-stage.narrative-mode .party-overlay {
  position: static;
  max-width: none;
  grid-column: 2;
  grid-row: 1;
  align-self: start;
}









/* Suggested actions (envelope ACTIONS as clickable intents). */
.suggested-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.suggested-actions .suggested-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.suggested-action-form { display: contents; }
.suggested-action {
  padding: var(--sp-3) var(--sp-6);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-pill);
  background: rgba(22, 27, 34, 0.7);
  color: var(--text);
  cursor: pointer;
  font-size: var(--fs-sm);
}
.suggested-action:hover { border-color: var(--accent); color: var(--accent); }

/* Free-text intent box. */




/* ---------- Phase 4: combat HUD --------------------------------- */

/* Sit the combat HUD to the LEFT of the narration drawer when both
   are open (the narration drawer is 320px wide on the right edge). */
.combat-mode .narration-drawer { right: 0.75rem; }
.combat-mode .combat-hud { right: 21.5rem; }



.enemy-list{
  list-style: none;
  margin: 0;
  padding: 0;
}

.initiative-row.is-active {
  background: linear-gradient(90deg, rgba(var(--accent-rgb),0.12), transparent);
}

.initiative-row .init-name { flex: 1; font-weight: 600; }
.initiative-row.kind-monster .init-name { color: var(--bad); }
.initiative-row .init-hp { font-family: ui-monospace, monospace; font-size: var(--fs-xs); color: var(--muted); }
.initiative-row .init-hp.is-down { color: var(--bad); }
.enemy-row {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  flex-wrap: wrap;
}
.enemy-row.is-dead { opacity: 0.45; text-decoration: line-through; }
.enemy-row .enemy-name { flex: 1; font-weight: 600; }
.enemy-conditions { display: flex; gap: var(--sp-2); flex-wrap: wrap; flex-basis: 100%; }







@media (max-width: 900px) {
  .narrative-region { grid-template-columns: 1fr; }
  .play-stage.narrative-mode .party-overlay { grid-column: 1; grid-row: 2; }
  .narrative-stage { grid-column: 1; }
}

/* ---------- Mobile collapse ------------------------------------- */
@media (max-width: 640px) {
  :root {
    --topbar-h: 3.25rem;
    --crumbs-h: 1.875rem;
  }

  body:has(.play-stage) main.app-main { padding: var(--sp-4); }

  /* Footer un-pins on mobile: its fleet/status bar wraps to several rows on narrow
     screens, and a fixed bar that tall covers page content (the reserved --footer-h
     space assumes one row). Let it flow after the content instead. */
  footer.app-footer { position: static; backdrop-filter: none; }
  main.app-main { padding-bottom: var(--sp-11); }

  /* Party roster collapses to a 40px icon button. Tap to expand. */
  .party-overlay {
    max-width: 2.5rem;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
  }
  .party-overlay::before {
    content: "P";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
    font-size: var(--fs-md);
  }
  .party-overlay > * { display: none; }
  .party-overlay.is-open {
    width: auto;
    height: auto;
    max-width: 17.5rem;
    max-height: 60dvh;
    padding: var(--sp-6) var(--sp-7);
    overflow-y: auto;
  }
  .party-overlay.is-open::before { display: none; }
  .party-overlay.is-open > * { display: block; }
  .party-overlay.is-open .party-overlay-row { display: flex; }

  /* Narration drawer takes the full-edge tab pattern; default
     closed on phones since the map is the focus. */
  .overlay-right-drawer { width: 84vw; max-width: 84vw; }

  /* Bottom action tray spans full width edge-to-edge. */
  .overlay-bottom {
    left: 0.375rem;
    right: 0.375rem;
    transform: none;
    max-width: none;
    min-width: 0;
  }

  .overlay-bottom-left { bottom: 3.75rem; }
}

/* ---------- Page-load motion ------------------------------------- */

@keyframes panelRise {
  from { opacity: 0; transform: translateY(0.5rem); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: no-preference) {
  .rise {
    animation: panelRise 240ms var(--ease-soft) both;
    animation-delay: calc(var(--i, 0) * 30ms);
  }
}

/* ===================================================================
   RESPONSIVE LAYER
   =================================================================== */

/* ---------- Mobile: <= 640px ------------------------------------- */
@media (max-width: 640px) {
  body { font-size: var(--fs-md); line-height: 1.5; }

  main.app-main { padding: var(--sp-8) var(--sp-7); }

  h1 { font-size: var(--fs-modal); }
  h2 { font-size: var(--fs-lg); }

  .entity-name { font-size: var(--fs-page); }

  /* Top row = brand + hamburger ONLY. Both the nav links AND the account actions (Log in/Sign up or
     the user chip) live in the drawer the hamburger opens — so the bar never overflows or wraps,
     regardless of login state. */
  .topbar-inner { padding: var(--sp-5) var(--sp-7); gap: var(--sp-5) var(--sp-6); }
  .topbar-brand { font-size: var(--fs-md); }
  .topbar-toggle { display: inline-flex; order: 1; margin-left: auto; width: 2.625rem; height: 2.625rem; }

  /* account slot → bottom of the drawer (hidden until the drawer opens). NB: `.topbar` prefix is
     REQUIRED — auth.css loads after theme.css and its plain `#auth-slot{display:inline-flex}` would
     otherwise win (media queries add no specificity), keeping the chip on a stray 2nd row. */
  .topbar #auth-slot { display: none; order: 3; width: 100%; margin-left: 0; }
  .topbar.nav-open #auth-slot,
  body[data-nav-open="true"] .topbar #auth-slot { display: flex; }
  #auth-slot .topbar-auth {
    width: 100%; border-left: 0; padding-left: 0; gap: var(--sp-8);
    border-top: 0.0625rem solid var(--border); margin-top: var(--sp-3); padding-top: var(--sp-7);
  }
  #auth-slot .topbar-auth-link, #auth-slot .topbar-auth-cta { padding: var(--sp-6) var(--sp-7); min-height: 2.75rem;
    display: inline-flex; align-items: center; }

  .topbar-nav,
  .topbar-form {
    display: none;
    order: 2;
    width: 100%;
    margin-left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-4);
  }

  /* Drawer open: toggled by JS via the body[data-nav-open] attribute or the .nav-open class. */
  body[data-nav-open="true"] .topbar-nav,
  body[data-nav-open="true"] .topbar-form,
  .topbar.nav-open .topbar-nav,
  .topbar.nav-open .topbar-form {
    display: flex;
  }

  .topbar-nav a {
    padding: var(--sp-7) var(--sp-8);
    border-radius: var(--r-md);
    border-color: var(--border);
    min-height: 2.75rem;
    display: flex;
    align-items: center;
  }

  .topbar-form .field,
  .topbar-form select.field,
  .topbar-form input.field {
    width: 100% !important;
    min-height: 2.75rem;
  }

  .topbar-form .btn { width: 100%; min-height: 2.75rem; }

  .campaign-strip-inner { padding: var(--sp-4) var(--sp-7); font-size: var(--fs-sm); }

  .panel { padding: var(--sp-7); border-radius: var(--r-lg); }

  .crumbs { font-size: var(--fs-base); gap: var(--sp-4); }
  .crumbs h1 { font-size: var(--fs-sub); flex-basis: 100%; }
  .crumbs .btn { margin-left: 0 !important; }

  .section-head { flex-direction: column; align-items: stretch; }

  /* KPI row: 2 columns on mobile. */
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
  .kpi { padding: var(--sp-5) var(--sp-4); }
  .kpi span, .kpi .kpi-value { font-size: var(--fs-sub); }

  /* Card grid: 1 column. */
  .card-grid,
  .card-grid.cols-4 { grid-template-columns: 1fr; gap: var(--sp-6); }
  .card { padding: var(--sp-8) var(--sp-8); }

  /* Buttons + fields touch-friendly. */
  .btn, button.btn, a.btn {
    min-height: 2.75rem;
    padding: var(--sp-6) var(--sp-8);
    font-size: var(--fs-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .field, input.field, select.field, textarea.field {
    min-height: 2.75rem;
    font-size: var(--fs-lg); /* prevents iOS zoom on focus */
    padding: var(--sp-6) var(--sp-7);
  }
  textarea.field { min-height: 12rem; }

  /* Inline forms collapse to vertical on mobile. */
  form.inline { display: flex; flex-direction: column; align-items: stretch; gap: var(--sp-5); }

  /* Field-row stacks. */
  .field-row { grid-template-columns: 1fr; gap: var(--sp-6); }

  /* Tables — default scroll wrap. */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { font-size: var(--fs-sm); }
  .table th, .table td { padding: var(--sp-4) var(--sp-5); white-space: nowrap; }

  /* The .table--stack opt-in re-flows table rows as label/value
     pairs on mobile; entity_list uses this since its narrow many-
     column layout is unreadable when scrolled. */
  .table--stack thead { display: none; }
  .table--stack,
  .table--stack tbody,
  .table--stack tr,
  .table--stack td { display: block; width: 100%; }
  .table--stack tr {
    border-bottom: 0.0625rem solid var(--border);
    padding: var(--sp-6) var(--sp-7);
  }
  .table--stack tr:last-child { border-bottom: none; }
  .table--stack td {
    padding: var(--sp-3) 0;
    border: none;
    white-space: normal;
  }
  .table--stack td::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 7rem;
    color: var(--muted);
    font-size: var(--fs-2xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: var(--sp-5);
    font-weight: 600;
  }

  /* Crumb action buttons full-width. */
  .crumbs .btn,
  .section-head .btn { width: 100%; }

  /* Definition lists: stack so the column doesn't squish. */
  dl.kv { grid-template-columns: 1fr; gap: var(--sp-1) 0; }
  dl.kv dt { margin-top: var(--sp-4); }

  /* Battlemap: legacy non-stage embed (e.g. spectator view) keeps a
     shorter viewport on phones. The new .play-stage wrapper inside
     /play/{cid} overrides this rule with absolute positioning. */
  .battlemap-viewport { height: 60vh; max-height: 60vh; }

  /* Chain strip wraps; per-field source badges hide so they don't
     crowd the labels in narrow KPI grids. */
  .chain-strip { gap: var(--sp-3); }
  .field-source { display: none; }
}

/* ---------- Tablet: 641px to 1023px ------------------------------ */
@media (min-width: 641px) and (max-width: 1023px) {
  main.app-main { padding: 1.125rem var(--sp-9); }

  /* Topbar: brand + nav row 1, jump form row 2. */
  .topbar-inner { gap: var(--sp-6) var(--sp-8); }
  .topbar-nav { order: 2; }
  .topbar-form {
    order: 3;
    margin-left: 0;
    width: 100%;
    border-top: 0.0625rem dashed var(--border);
    padding-top: var(--sp-5);
  }

  /* KPI row: 4 across. */
  .kpi-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  /* Card grid: 2 across. */
  .card-grid,
  .card-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .field-row { grid-template-columns: 1fr 1fr; }
}

/* ---------- Desktop: >= 1024px ----------------------------------- */
@media (min-width: 1024px) {
  /* Restore single-row topbar — topbar-form auto-pushes to right. */
  .topbar-form { margin-left: auto; }
}

/* ===================================================================
   CANDLELIT GRIMOIRE — atmosphere + display typography (Phase A)
   Appended last so it layers over the component base above. Only
   tokens + this block carry the dark-fantasy theme; component classes
   are untouched.
   =================================================================== */

/* Warm candlelight wash + vignette behind all content. Fixed, inert,
   sits beneath everything (negative z). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(125% 90% at 50% -8%,
      rgba(var(--accent-rgb), 0.07) 0%, transparent 52%),
    radial-gradient(110% 80% at 50% 116%,
      rgba(var(--gold-rgb), 0.045) 0%, transparent 55%),
    radial-gradient(140% 120% at 50% 50%,
      transparent 60%, rgba(0, 0, 0, 0.45) 100%),
    var(--bg);
}

/* Fine paper grain for texture — static SVG fractal noise, very low
   opacity. Above the wash, below content. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 10rem 10rem;
}

/* ---- Display typography — illuminated serif headings -------------- */
h1, .page-title, .section-head h1, .card-title, .hero-title{
  font-family: var(--font-display);
}
h1,
.page-title {
  font-size: var(--fs-page);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.12;
}
.card-title { font-size: var(--fs-sub); font-weight: 600; }

/* Small uppercase "label" titles stay sans-shaped but go brass. */
.panel-title,
.panel h2 { color: var(--gold); }

/* Hero — large illuminated, glowing display title (home/landing). */
.hero-title {
  font-size: clamp(2.125rem, 6vw, 3.5rem);
  font-weight: 700;
  line-height: 1.04;
  letter-spacing: 0.005em;
  color: var(--text);
  text-shadow: 0 0 1.875rem rgba(var(--accent-rgb), 0.22);
}
.hero-title .ember { color: var(--accent); }
.hero-title .gilt { color: var(--gold); text-shadow: var(--glow-gold); }

/* Illuminated drop-cap helper for hero/lead paragraphs. */
.dropcap::first-letter {
  font-family: var(--font-display);
  float: left;
  font-size: 3.1em;
  line-height: 0.82;
  padding: var(--sp-3) var(--sp-6) 0 0;
  color: var(--gold);
  text-shadow: var(--glow-gold);
}

/* ---- Accent glow + interaction polish ---------------------------- */
a { transition: color 140ms var(--ease-soft); }
a:hover { color: var(--gold); }

::selection { background: rgba(var(--accent-rgb), 0.32); color: var(--text); }

.brand-mark { color: var(--gold); }

.topbar-brand {
  font-family: var(--font-display);
  font-size: var(--fs-sub);
  letter-spacing: 0.03em;
  color: var(--gold);
}
.topbar-brand:hover { color: var(--accent); text-decoration: none; }

/* Primary buttons ignite — ember fill with a soft glow, gilding on hover. */
.btn-primary { box-shadow: var(--glow-ember); }
.btn-primary:not(:disabled):not(.is-disabled):hover {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--on-accent);
  box-shadow: var(--glow-gold);
}

/* Reusable glow / accent-color utilities. */
.glow { box-shadow: var(--glow-ember); }



/* Active turn / live indicators pulse with ember warmth. */
.party-overlay-row.is-active .active-dot,
.status-pill.live { box-shadow: var(--glow-ember); }

/* ---- Decorative divider — ✦ flourish ----------------------------- */
hr {
  border: 0;
  height: 0.0625rem;
  position: relative;
  overflow: visible;
  margin: var(--sp-11) 0;
  background: linear-gradient(90deg,
    transparent, var(--border) 18%, var(--border) 82%, transparent);
}
hr::after {
  content: "\2726";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -55%);
  color: var(--gold);
  background: var(--bg);
  padding: 0 var(--sp-7);
  font-size: var(--fs-sm);
}

/* ---- Themed scrollbars ------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 0.625rem; height: 0.625rem; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--r-pill);
  border: 0.125rem solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* SLIM SCROLLBAR — ONE source for the narrow card/panel rails (was duplicated 5× in cards/tower,
   each of which had DROPPED the accent-on-hover feedback; restored here). */
.vc-body::-webkit-scrollbar, .vc-col::-webkit-scrollbar, .sb-col::-webkit-scrollbar,
.sb-body::-webkit-scrollbar, .mb-rail::-webkit-scrollbar { width: var(--scroll-slim); height: var(--scroll-slim); }
.vc-body::-webkit-scrollbar-thumb, .vc-col::-webkit-scrollbar-thumb, .sb-col::-webkit-scrollbar-thumb,
.sb-body::-webkit-scrollbar-thumb, .mb-rail::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--r-xs); }
.vc-body::-webkit-scrollbar-thumb:hover, .vc-col::-webkit-scrollbar-thumb:hover, .sb-col::-webkit-scrollbar-thumb:hover,
.sb-body::-webkit-scrollbar-thumb:hover, .mb-rail::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ---- Accessibility — visible focus + skip link ------------------- */
:focus-visible {
  outline: 0.125rem solid var(--accent);
  outline-offset: 0.125rem;
  border-radius: var(--r-xs);
}
.skip-link {
  position: absolute;
  left: -624.9375rem;
  top: 0;
  z-index: 100;
  background: var(--panel);
  color: var(--gold);
  border: 0.0625rem solid var(--gold);
  padding: var(--sp-5) var(--sp-8);
  border-radius: 0 0 var(--r-md) 0;
}
.skip-link:focus { left: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ===================================================================
   SHARED UI PRIMITIVES (Phase B) — toasts, modals, command palette,
   smart-table controls, empty states, page headers, kbd.
   Behaviour lives in /static/ui.js.
   =================================================================== */

/* ---- Toasts ------------------------------------------------------ */
#toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  max-width: min(23.75rem, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-6);
  background: var(--panel-2);
  border: 0.0625rem solid var(--border);
  border-left: 0.1875rem solid var(--accent);
  border-radius: var(--r-lg);
  padding: var(--sp-6) var(--sp-7);
  font-size: var(--fs-base);
  color: var(--text);
  box-shadow: 0 0.75rem 1.875rem -0.75rem rgba(0, 0, 0, 0.7);
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 200ms var(--ease-soft), transform 200ms var(--ease-soft);
}
.toast.is-in { opacity: 1; transform: none; }
.toast-success { border-left-color: var(--good); }
.toast-error   { border-left-color: var(--bad); }
.toast-warn    { border-left-color: var(--warn); }
.toast-icon { color: var(--accent); font-size: var(--fs-base); line-height: 1.5; }
.toast-success .toast-icon { color: var(--good); }
.toast-error .toast-icon   { color: var(--bad); }
.toast-warn .toast-icon    { color: var(--warn); }
.toast-msg { flex: 1; min-width: 0; }
.toast-close {
  background: none; border: 0; color: var(--muted);
  cursor: pointer; font-size: var(--fs-lg); line-height: 1; padding: 0 var(--sp-1);
}
.toast-close:hover { color: var(--text); }

/* ---- Modal / confirm + cheatsheet -------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-10);
  background: rgba(4, 3, 1, 0.66);
  -webkit-backdrop-filter: blur(0.1875rem);
  backdrop-filter: blur(0.1875rem);
}
.modal-backdrop.is-in { display: flex; }
.modal {
  width: 100%;
  max-width: 26.25rem;
  background: var(--panel);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-2xl);
  padding: var(--sp-10) 1.375rem;
  box-shadow: 0 1.5rem 3.75rem -1.25rem rgba(0, 0, 0, 0.8), var(--glow-gold);
}
.modal-title { font-family: var(--font-display); font-size: var(--fs-modal); color: var(--gold); margin: 0 0 var(--sp-5); }
.modal-body { color: var(--muted); margin: 0 0 1.125rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-6); }





kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  background: var(--bg);
  border: 0.0625rem solid var(--border);
  border-bottom-width: 0.125rem;
  border-radius: var(--r-sm);
  padding: 0.0625rem var(--sp-4);
  color: var(--text);
}

/* ---- Command palette --------------------------------------------- */

.cmdk-backdrop.is-in { display: flex; }





.cmdk-item.is-active { background: rgba(var(--accent-rgb), 0.14); }





/* ---- Smart-table controls ---------------------------------------- */









.table.is-compact th, .table.is-compact td { padding: var(--sp-2) var(--sp-5); font-size: var(--fs-sm); }

/* ---- Empty states ------------------------------------------------ */
.empty-state {
  text-align: center;
  padding: 3rem var(--sp-11);
  border: 0.0625rem dashed var(--border);
  border-radius: var(--r-2xl);
  background:
    radial-gradient(60% 80% at 50% 0%, rgba(var(--accent-rgb), 0.05), transparent 70%),
    var(--panel);
}
.empty-state .empty-icon { font-size: 2.5rem; color: var(--gold); opacity: 0.8; }
.empty-state .empty-title { font-family: var(--font-display); font-size: var(--fs-card); margin: var(--sp-6) 0 var(--sp-3); }
.empty-state .empty-text { color: var(--muted); max-width: 46ch; margin: 0 auto 1.125rem; }

/* ---- Page header + breadcrumb ------------------------------------ */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-9);
  flex-wrap: wrap;
  margin-bottom: 1.125rem;
  padding-bottom: var(--sp-8);
  border-bottom: 0.0625rem solid var(--border);
}
.page-header .ph-title { margin: 0; }
.page-header .ph-sub { color: var(--muted); font-size: var(--fs-base); margin-top: var(--sp-1); }
.page-header .ph-actions { display: flex; gap: var(--sp-5); flex-wrap: wrap; }

/* ---- HTMX loading indicator -------------------------------------- */


.spinner {
  display: inline-block; width: 0.875rem; height: 0.875rem;
  border: 0.125rem solid var(--border); border-top-color: var(--accent);
  border-radius: var(--r-pill); animation: spin 0.7s linear infinite; vertical-align: -0.125rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Codex (corpus) thumbnails ----------------------------------- */


/* ---- Home hero --------------------------------------------------- */
.home-hero {
  position: relative;
  text-align: center;
  padding: 3.625rem var(--sp-9) 2.5rem;
  margin-bottom: var(--sp-6);
}
.home-hero::before {
  content: "";
  position: absolute;
  inset: -12% 0 0 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(58% 70% at 50% 0%,
    rgba(var(--accent-rgb), 0.12), transparent 70%);
}

.home-hero .hero-title { margin: 0 auto; }


.hero-actions .btn { padding: var(--sp-5) 1.125rem; font-size: var(--fs-md); }

/* ---- Narrative reading — storybook prose ------------------------- */








.narrative-stage .suggested-action {
  background: var(--bg);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text);
  padding: var(--sp-3) var(--sp-7);
  font-size: var(--fs-base);
  cursor: pointer;
}
.narrative-stage .suggested-action:hover { border-color: var(--accent); color: var(--gold); }
.narrative-stage .suggested-action-form { display: inline; }
.narrative-stage .suggested-actions { display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: center; margin: var(--sp-7) 0; }
.narrative-stage .suggested-label { color: var(--muted); font-size: var(--fs-sm); margin-right: var(--sp-3); }

/* ---- Codex item gallery ------------------------------------------ */





/* ---- Topbar account menu ----------------------------------------- */
.topbar-account { display: flex; align-items: center; }
.account-menu { position: relative; }
.account-menu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-6);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-pill);
  font-size: var(--fs-base);
  color: var(--text);
  font-family: var(--font-mono);
}
.account-menu > summary::-webkit-details-marker { display: none; }
.account-menu > summary:hover { border-color: var(--accent); color: var(--gold); }
.account-ava { color: var(--gold); }
.account-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 0.375rem);
  z-index: 20;
  background: var(--panel);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  min-width: 10.5rem;
  box-shadow: 0 0.875rem 2.125rem -0.875rem rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.account-pop a,
.account-pop button {
  text-align: left;
  background: none;
  border: 0;
  color: var(--muted);
  padding: var(--sp-4) var(--sp-6);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  cursor: pointer;
  font-family: var(--font-sans);
  width: 100%;
}
.account-pop a:hover,
.account-pop button:hover { background: var(--bg); color: var(--gold); text-decoration: none; }
.account-pop form { margin: 0; }

/* ---- #3 click-to-roll tokens in prose ---------------------------- */
.rollable {
  background: rgba(var(--accent-rgb), 0.1);
  border: 0;
  border-bottom: 0.0625rem dashed var(--accent);
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0 var(--sp-1);
  border-radius: var(--r-xs);
}
.rollable:hover { background: rgba(var(--accent-rgb), 0.22); color: var(--gold); }

/* #4 roll skill/save from sheet */
.rollable-check {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  background: rgba(var(--accent-rgb), 0.1);
  border: 0.0625rem solid var(--border);
  border-radius: var(--r-sm);
  color: var(--accent);
  cursor: pointer;
  padding: 0.0625rem var(--sp-5);
}
.rollable-check:hover {
  border-color: var(--accent);
  color: var(--gold);
  background: rgba(var(--accent-rgb), 0.2);
}


/* ---- #7 your-turn cue -------------------------------------------- */
.your-turn-banner {
  display: none;
  align-items: center;
  gap: var(--sp-5);
  margin: 0 0 var(--sp-6);
  padding: var(--sp-5) var(--sp-8);
  border: 0.0625rem solid var(--accent);
  border-radius: var(--r-lg);
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--gold);
  font-weight: 600;
  box-shadow: var(--glow-ember);
  animation: yourTurnPulse 1.8s var(--ease-soft) infinite;
}
body[data-your-turn="1"] .your-turn-banner { display: flex; }
@keyframes yourTurnPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.0); }
  50% { box-shadow: 0 0 1.125rem -0.125rem rgba(var(--accent-rgb), 0.55); }
}

/* ---- #6 Intent slash-menu ---------------------------------------- */





/* ---- #17 roll feed + #8 recap ------------------------------------ */
.roll-feed-list { list-style: none; margin: var(--sp-5) 0 0; padding: 0; font-size: var(--fs-base); }
.roll-feed-list li { padding: var(--sp-2) 0; border-bottom: 0.0625rem solid var(--border-soft); color: var(--muted); }
.roll-feed-list li:last-child { border-bottom: 0; }
.recap { margin-bottom: var(--sp-6); }
.recap .recap-prose {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  line-height: 1.6;
  color: var(--text);
  margin: 0;
}
