/* ==========================================================================
   Campaign site theme: dark red and gold.

   How the colors are organized:
   1. PALETTE: the house colors (red and gold). A future theme picker can
      swap just these few values, e.g. [data-palette="emerald"] { ... }.
   2. MODE: dark (the default) or light. Each mode turns the palette into the
      colors pages actually use (background, text, links, buttons...).
   Change values here and the whole site follows.
   ========================================================================== */

:root {
  --font-heading: "Cinzel", Georgia, serif;
  --font-body: "Alegreya Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;

  /* 1. PALETTE: red and gold */
  --house-deep: #5c0f12;        /* header band (dark mode) */
  --house-deep-light: #6e1316;  /* header band (light mode) */
  --house: #8e1a1d;             /* buttons (dark mode) */
  --house-hover: #a52226;
  --house-light: #7f1518;       /* buttons, headings, links (light mode) */
  --metal: #e8c463;             /* bright gold: text on dark */
  --metal-line: #c9a24a;        /* gold for borders and ornaments */
  --metal-dim: #7a6230;         /* quiet gold lines on dark */
  --metal-deep: #8a6516;        /* gold dark enough for text on parchment */
  --on-house: #fbecc4;          /* text on red */
}

/* 2. MODE: dark is the default */
:root, :root[data-theme="dark"] {
  --bg: #15100c;
  --bg-glow: rgba(232, 196, 99, .07);
  --surface: #211912;
  --surface-sunk: #1a140f;      /* inputs, copy boxes */
  --text: #ece2cc;
  --muted: #b3a588;
  --border: #4d3b22;
  --border-inner: #3a2c1c;
  --heading: var(--metal);
  --link: var(--metal);
  --header-bg: var(--house-deep);
  --header-text: #f3e7c9;
  --brand: var(--metal);
  --button: var(--house);
  --button-hover: var(--house-hover);
  --button-text: var(--on-house);
  --button-border: var(--metal-line);
  --secondary-text: var(--metal);
  --secondary-border: #6b5530;
  --ornament: var(--metal-line);
  --ornament-line: var(--metal-dim);
  --focus: var(--metal);
  --danger: #f08a80;
  --revealed: #8fd19e;
  --hidden: #b3a588;
  --dm-tint: #2b1614;
  --player-tint: #18221a;
  --gold: var(--metal-line);
}

:root[data-theme="light"] {
  --bg: #f3ead6;
  --bg-glow: rgba(184, 137, 44, .10);
  --surface: #fbf6ea;
  --surface-sunk: #fffdf7;
  --text: #2a1d14;
  --muted: #6b5a44;
  --border: #d6c08f;
  --border-inner: #ece0c2;
  --heading: var(--house-deep-light);
  --link: var(--house-light);
  --header-bg: var(--house-deep-light);
  --header-text: #fbefd2;
  --brand: #f0cf74;
  --button: var(--house-light);
  --button-hover: #962024;
  --button-text: var(--on-house);
  --button-border: #a87c1f;
  --secondary-text: var(--house-deep-light);
  --secondary-border: #c9a96a;
  --ornament: #a87c1f;
  --ornament-line: #c9a96a;
  --focus: var(--house-light);
  --danger: #a51d1d;
  --revealed: #2f6b3a;
  --hidden: #6b5a44;
  --dm-tint: #f3e1dc;
  --player-tint: #e4ecdc;
  --gold: #a87c1f;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(ellipse 90% 60% at 50% 0%, var(--bg-glow), transparent 70%) no-repeat, var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.55;
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--font-heading); line-height: 1.2; margin: 0 0 .5em; color: var(--heading); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; margin-top: 1.25em; }
h3 { font-size: 1.05rem; }
a { color: var(--link); text-underline-offset: 2px; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 48px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.inline { display: inline; }

/* Gold divider with a diamond under page titles */
main h1::after {
  content: "◆"; display: block; width: min(240px, 100%); margin-top: 8px;
  font-size: 9px; line-height: 1; text-align: center; color: var(--ornament);
  background:
    linear-gradient(var(--ornament-line), var(--ornament-line)) left center / calc(50% - 10px) 1px no-repeat,
    linear-gradient(var(--ornament-line), var(--ornament-line)) right center / calc(50% - 10px) 1px no-repeat;
}
.card.narrow h1::after, .login-hero h1::after { margin-left: auto; margin-right: auto; }

/* ---------- Header ---------- */
.site-header { background: var(--header-bg); border-bottom: 2px solid var(--metal-line); color: var(--header-text); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; padding-bottom: 10px; }
.brand { font-family: var(--font-heading); font-weight: 700; font-size: 1.3rem; letter-spacing: .04em; color: var(--brand); text-decoration: none; }
.header-tools { display: flex; align-items: center; gap: 8px; }
.theme-toggle, .menu-toggle {
  background: none; border: 1px solid rgba(232, 196, 99, .45); color: var(--brand);
  border-radius: 999px; height: 40px; cursor: pointer; font: inherit;
}
.theme-toggle { width: 40px; font-size: 1.1rem; }
.menu-toggle { display: none; padding: 0 14px; font-weight: 500; }
.site-nav { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: center; padding-bottom: 10px; }
.site-nav a, .link-button { color: var(--header-text); text-decoration: none; font-weight: 500; padding: 6px 0; border-bottom: 2px solid transparent; }
.site-nav a:hover, .link-button:hover { color: var(--brand); }
.site-nav a.active { color: var(--brand); border-bottom-color: var(--metal-line); }
.nav-spacer { flex: 1; }
.link-button { background: none; border-top: 0; border-left: 0; border-right: 0; font: inherit; cursor: pointer; }

/* Campaign bar: which campaign you're in and your role there */
.campaign-bar { background: rgba(0, 0, 0, .18); border-top: 1px solid rgba(232, 196, 99, .25); border-bottom: 1px solid rgba(232, 196, 99, .25); }
.campaign-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; padding-top: 6px; padding-bottom: 6px; font-size: .9rem; }
.campaign-switch { display: flex; align-items: center; gap: 8px; }
.campaign-switch label { color: var(--header-text); opacity: .85; }
.campaign-switch select { width: auto; max-width: 60vw; padding: 4px 8px; background: rgba(0, 0, 0, .25); color: var(--brand); border-color: rgba(232, 196, 99, .45); }
.campaign-name { font-family: var(--font-heading); color: var(--brand); }
.role-tag { color: var(--header-text); font-size: .8rem; border: 1px solid rgba(232, 196, 99, .45); border-radius: 999px; padding: 1px 10px; }
.campaign-extras { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.campaign-new { color: var(--header-text); font-size: .8rem; opacity: .85; }
.campaign-new:hover { color: var(--brand); opacity: 1; }

/* Manage campaign: the people list */
.member-list { list-style: none; margin: 0 0 12px; padding: 0; }
.member { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.member-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.member-name .tag { margin-left: 0; }
.member-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.member-actions form { margin: 0; }
.add-member { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 12px; }
.add-member .field { flex: 1 1 180px; }
.add-member .button { margin-bottom: 14px; }

/* Menu groups (World / Story / DM tools): a dropdown on computers, headings on phones */
.nav-group { position: relative; }
.nav-group-label { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--header-text); font: inherit; font-weight: 500; padding: 6px 0; cursor: pointer; }
.nav-group.active > .nav-group-label { color: var(--brand); border-bottom-color: var(--metal-line); }
.nav-menu a { display: block; }
.nav-search input { width: 150px; padding: 5px 10px; font-size: .9rem; background: rgba(0, 0, 0, .25); color: var(--header-text); border-color: rgba(232, 196, 99, .45); }
.nav-search input::placeholder { color: var(--header-text); opacity: .7; }
@media (min-width: 700px) {
  .nav-menu {
    display: none; position: absolute; top: 100%; left: -12px; z-index: 20; min-width: 170px; padding: 6px 0;
    background: var(--header-bg); border: 1px solid var(--metal-line); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  }
  .nav-group:hover .nav-menu, .nav-group:focus-within .nav-menu { display: block; }
  .site-nav .nav-menu a { padding: 8px 14px; border-bottom: 0; }
  .site-nav .nav-menu a:hover, .site-nav .nav-menu a.active { background: rgba(0, 0, 0, .2); }
}
@media (max-width: 699px) {
  .nav-group-label { cursor: default; padding-top: 12px; font-family: var(--font-heading); color: var(--brand); }
  .nav-group-label span { display: none; }
  .site-nav.open .nav-menu a { padding-left: 14px; }
  .nav-search input { width: 100%; }
  .site-nav.open .nav-search { padding: 10px 0; }
}

/* Phones: the links fold away behind a Menu button (only when JavaScript is on). */
@media (max-width: 699px) {
  .js .menu-toggle { display: inline-flex; align-items: center; }
  .js .site-nav { display: none; }
  .js .site-nav.open { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
  .site-nav.open a, .site-nav.open .link-button, .site-nav.open form { padding: 10px 0; border-bottom: 1px solid rgba(232, 196, 99, .2); text-align: left; width: 100%; }
  .site-nav.open form .link-button { padding: 0; border: 0; }
  .site-nav.open .nav-spacer { display: none; }
}

/* ---------- Cards, buttons, badges ---------- */
.card {
  display: block; background: var(--surface); color: inherit;
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 4px var(--border-inner); /* thin double border */
  padding: 16px; margin-bottom: 12px;
}
a.card { text-decoration: none; }
a.card:hover { border-color: var(--gold); }
.card.narrow { max-width: 440px; margin: 24px auto; }

.button {
  display: inline-block; background: var(--button); color: var(--button-text);
  border: 1px solid var(--button-border); border-radius: var(--radius);
  padding: 10px 16px; font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  min-height: 44px; /* comfortable tap target on phones */
}
.button:hover { background: var(--button-hover); }
.button.secondary { background: transparent; color: var(--secondary-text); border-color: var(--secondary-border); }
.button.secondary:hover { border-color: var(--gold); }
.button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.badge { border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 500; border: 1px solid; background: transparent; cursor: pointer; font-family: inherit; }
.badge.revealed { color: var(--revealed); }
.badge.hidden { color: var(--hidden); }
.tag { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: 999px; background: var(--surface-sunk); border: 1px solid var(--border); font-size: .75rem; color: var(--muted); }

.flash { background: var(--surface); border: 1px solid var(--gold); border-left-width: 4px; border-radius: 0; padding: 10px 14px; margin-bottom: 16px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 16px 0; }
.stat strong { display: block; font-family: var(--font-heading); font-size: 1.6rem; color: var(--heading); }
.plain-list { padding-left: 1.2em; }
.list-item h3 { margin-bottom: .2em; }
.list-item p { margin: 0; }

/* ---------- Login ---------- */
.login-hero { text-align: center; margin: 32px auto 8px; }
.login-hero .brand-big { font-family: var(--font-heading); font-weight: 700; font-size: 2.2rem; letter-spacing: .05em; color: var(--heading); margin: 0; }
.login-hero p { margin: 6px 0 0; }
.login-hero .ornament { margin: 10px auto 4px; }
.ornament {
  width: 200px; margin: 8px auto 0; font-size: 9px; line-height: 1; color: var(--ornament);
  background:
    linear-gradient(var(--ornament-line), var(--ornament-line)) left center / calc(50% - 10px) 1px no-repeat,
    linear-gradient(var(--ornament-line), var(--ornament-line)) right center / calc(50% - 10px) 1px no-repeat;
}
.card.narrow h1 { text-align: center; }
.full-width { width: 100%; }
.center { text-align: center; }

/* ---------- Forms ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.filters input, .filters select { flex: 1 1 160px; }
input[type="text"], input[type="search"], input[type="password"], input[type="email"], input[type="number"], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--surface-sunk); border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: 2px solid var(--focus); outline-offset: 0; }
input[type="checkbox"] { accent-color: var(--button); width: 18px; height: 18px; }
textarea { resize: vertical; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 500; margin-bottom: 4px; }
.field-checkbox > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.field-checkbox label { margin: 0; }
.field .helptext { display: block; color: var(--muted); font-size: .85rem; margin-top: 4px; }
.errorlist { color: var(--danger); margin: 4px 0; padding-left: 1.2em; }
fieldset { border-radius: var(--radius); border: 1px solid var(--border); margin: 0 0 16px; padding: 12px 16px; }
legend { font-family: var(--font-heading); font-weight: 700; padding: 0 6px; color: var(--heading); }

/* Visual hint of who can see what */
.player-box { background: var(--player-tint); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; }
.dm-box { background: var(--dm-tint); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0; }
.player-box h2, .dm-box h2 { margin-top: 0; font-size: 1rem; }
.dm-box h3 { margin-top: 1em; }

/* ---------- Home page ---------- */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 16px; }
.home-grid .card { margin: 0; }
.home-grid h2 { margin-top: 0; font-size: 1.1rem; }
.home-grid p { margin: 0 0 .5em; }

/* ---------- Sessions ---------- */
.session-row .npc-card-link { display: flex; align-items: center; gap: 14px; }
.session-number {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-heading); font-weight: 700; color: var(--heading); border: 2px solid var(--gold);
}

/* ---------- Timeline: a gold line with a dot per event ---------- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 22px; border-left: 2px solid var(--ornament-line); }
.timeline-event { position: relative; padding: 0 0 22px 18px; }
.timeline-dot { position: absolute; left: -31px; top: 4px; width: 16px; height: 16px; transform: rotate(45deg); background: var(--surface); border: 2px solid var(--gold); }
.timeline-date { margin: 0; font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; color: var(--gold); }
.timeline-event h3 { margin: 2px 0 4px; }
.timeline-event h3 a { color: inherit; text-decoration: none; }
.timeline-event.is-hidden { opacity: .7; }

/* ---------- Lists without pictures (quests) ---------- */
.stack { display: grid; gap: 10px; }
.row-card { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 0; }
.row-card .npc-card-link { flex: 1 1 200px; }
.row-card h3, .row-card p { margin: 0; }

/* ---------- NPCs ---------- */
.npc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.npc-card { text-align: center; margin: 0; }
.npc-card-link { color: inherit; text-decoration: none; display: block; }
.npc-card h3 { margin: 8px 0 2px; color: var(--text); }
.npc-card p { margin: 0 0 8px; }
.portrait {
  width: 100px; height: 100px; object-fit: cover; border-radius: 50%; display: block; margin: 0 auto;
  border: 2px solid var(--gold); box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--ornament-line); /* gold ring */
}
.portrait.large { width: 180px; height: 180px; margin-bottom: 12px; }
.portrait.placeholder { display: flex; align-items: center; justify-content: center; background: var(--surface-sunk); font-family: var(--font-heading); font-size: 2.2rem; color: var(--gold); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
.facts dt { font-weight: 500; }
.facts dd { margin: 0; }
.prose p { margin: 0 0 .8em; }

/* ---------- Tables, paging, footer ---------- */
.table-card { padding: 0; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border-inner); }
.data-table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom-color: var(--border); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.site-footer { border-top: 1px solid var(--border); padding: 16px 0 32px; }
.site-footer p { margin: 0; }

/* ---------- Forms in grids (stat block form) ---------- */
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }
.field-grid .wide { grid-column: 1 / -1; }

/* ---------- Stat block: classic book look, always parchment, in both themes ---------- */
.statblock {
  --sb-bg: #fdf1dc; --sb-text: #1f1a14; --sb-red: #7a200d; --sb-shade: #ead9b8;
  background: var(--sb-bg); color: var(--sb-text);
  border: 1px solid #d4b98a; border-top: 4px solid #e69a28; border-bottom: 4px solid #e69a28;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  padding: 14px 16px; margin: 12px 0; font-size: .95rem; line-height: 1.45;
}
.statblock p { margin: 0 0 .45em; }
.statblock a { color: var(--sb-red); }
.sb-name { font-family: var(--font-heading); color: var(--sb-red); font-size: 1.5rem; margin: 0; letter-spacing: .02em; }
.sb-type { font-style: italic; margin: 2px 0 0; }
.sb-rule, .statblock h3 { border: 0; border-bottom: 2px solid var(--sb-red); }
.sb-rule { margin: 8px 0; }
.statblock b { color: var(--sb-red); }
.statblock h3 { font-family: var(--font-heading); color: var(--sb-red); font-size: 1.1rem; font-weight: 600; padding-bottom: 2px; margin: 14px 0 8px; }
.statblock section p { margin-bottom: .7em; }
.sb-abilities { border-collapse: collapse; margin: 8px 0; width: 100%; max-width: 420px; font-size: .9rem; text-align: center; }
.sb-abilities thead th { font-size: .65rem; text-transform: uppercase; color: #6b5a44; font-weight: 600; }
.sb-abilities tbody th { text-align: left; padding-left: 6px; }
.sb-abilities tbody th, .sb-abilities td { background: var(--sb-shade); padding: 3px 4px; border: 2px solid var(--sb-bg); }
.sb-abilities tbody td:nth-child(4) { border-right-width: 10px; }
.sb-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (min-width: 900px) {
  .sb-body { column-count: 2; column-gap: 28px; }
  .sb-body > * { break-inside: avoid-column; }
  .sb-body section p { break-inside: avoid; }
}

/* ---------- Copy for D&D Beyond ---------- */
.copy-box { border: 1px solid var(--border-inner); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 8px; background: var(--surface-sunk); }
.copy-box.empty { opacity: .55; }
.copy-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.copy-label { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.copy-value { margin-top: 4px; white-space: normal; }
.copy-value.rich p { margin: 0 0 .6em; }
.small-button { min-height: 32px; padding: 4px 12px; font-size: .85rem; }

/* ---------- Print page ---------- */
.print-page { background: #fff; max-width: 900px; margin: 0 auto; padding: 16px; }
.print-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.print-credit { font-size: .75rem; color: #555; }
@media print {
  .print-controls { display: none; }
  .print-page { padding: 0; }
  .statblock { box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (min-width: 640px) {
  .npc-detail.with-image { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: start; }
  h1 { font-size: 2rem; }
}

/* ---------- Recaps, story styles, AI usage ---------- */
.flash.error { border-color: var(--danger); }
.flash.warning { border-color: var(--metal-line); border-style: dashed; border-left-style: solid; }
.busy-message { font-weight: 500; color: var(--heading); }
.big-number { font-family: var(--font-heading); font-size: 2rem; margin: 0; color: var(--heading); }
.table-wrap { overflow-x: auto; }
.usage-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.usage-table th, .usage-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border-inner); white-space: nowrap; }
.usage-table th { color: var(--muted); font-weight: 500; }
.button:disabled, .button[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- House rules ---------- */
.rule-meta, .rule-preview { display: block; }
.rule-preview { margin-top: 2px; }
.facts + .prose { margin-top: 14px; }

/* ---------- Rulebook search ---------- */
.passage-title { margin: 0 0 2px; font-size: 1.15rem; }
.passage-text { font-size: .95rem; }

/* ---------- Chats (rules helper, story brainstorm) ---------- */
.chat-layout { display: grid; gap: 16px; }
@media (min-width: 900px) { .chat-layout { grid-template-columns: 240px 1fr; align-items: start; } }
.chat-list summary { cursor: pointer; font-family: var(--font-heading); color: var(--heading); margin-bottom: 6px; }
.chat-link { display: block; padding: 6px 0; border-bottom: 1px solid var(--border-inner); text-decoration: none; }
.chat-link.active { font-weight: 700; }
.chat-message { margin-bottom: 14px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); }
.chat-message.user { background: var(--surface-sunk); }
.chat-message.assistant { background: var(--surface); }
.chat-who { margin: 0 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.chat-form textarea { width: 100%; }
.chat-form.dropping textarea { outline: 2px dashed var(--metal-line); outline-offset: 2px; }
/* Pictures: waiting to be sent (with an × each), and inside sent messages. */
.chat-picture-tray { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; padding: 0; }
.chat-picture-tray li { position: relative; }
.chat-picture-tray img, .chat-pictures img { display: block; width: auto; height: auto; max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.chat-picture-tray img { max-height: 80px; }
.chat-picture-tray .icon-button { position: absolute; top: -8px; right: -8px; background: var(--surface); border-color: var(--border); border-radius: 50%; padding: 2px 7px; font-size: 1rem; }
.chat-pictures { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chat-pictures img { max-height: 220px; }
.chat-add-picture { cursor: pointer; }
.chat-add-picture:focus-within { outline: 2px solid var(--metal-line); outline-offset: 2px; }
/* Pictures of NPCs, places and factions a brainstorm reply mentions. */
.chat-site-pictures { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.chat-site-pictures figure { margin: 0; width: 120px; }
.chat-site-pictures img { display: block; width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }
.chat-site-pictures figcaption { font-size: .85rem; margin-top: 4px; }
.chat-message .sources a { white-space: normal; }
.passages-checked { margin-top: 8px; }
.passages-checked summary { cursor: pointer; color: var(--muted); }
.passages-checked .passage { border-top: 1px solid var(--border-inner); padding-top: 8px; margin-top: 8px; }
.text-button { background: none; border: 0; padding: 0; font: inherit; color: var(--danger); text-decoration: underline; cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.form-error { color: var(--danger); font-weight: 500; }
.chat-message.pending .prose:empty::before { content: attr(data-waiting); color: var(--muted); font-style: italic; }
.chat-message.pending .prose:empty::after { content: "…"; display: inline-block; animation: chat-dots 1.2s steps(4, end) infinite; width: 0; overflow: hidden; vertical-align: bottom; color: var(--muted); }
@keyframes chat-dots { to { width: 1.2em; } }
.chat-link-row { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border-inner); }
.chat-link-row .chat-link { flex: 1; border-bottom: 0; min-width: 0; overflow-wrap: anywhere; }
.chat-link-row form { margin: 0; }
.icon-button { background: none; border: 1px solid transparent; border-radius: var(--radius); color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 4px 8px; cursor: pointer; }
.icon-button:hover, .icon-button:focus-visible { color: var(--danger); border-color: var(--danger); }

/* ---------- Character sheets ---------- */
.sheet-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.sheet-stat, .sheet-ability { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; margin: 0; }
.sheet-stat-label { font-family: var(--font-heading); color: var(--heading); font-size: .85rem; }
.sheet-stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.sheet-abilities { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.sheet-ability { border: 1px solid var(--border-inner); border-radius: var(--radius); padding: 8px; }
.sheet-skills { list-style: none; padding: 0; margin: 0; columns: 2 220px; }
.sheet-skills li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px solid var(--border-inner); break-inside: avoid; }
.sheet-warnings { border-color: var(--metal-line); }
.sheet-source .actions { flex-wrap: wrap; }
.sheet-rolls { margin: 6px 0 0; padding-left: 20px; }
.sheet-views { display: flex; gap: 8px; margin: 0 0 14px; }
.sheet-views .button[aria-pressed="true"] { background: var(--button); color: var(--button-text); border-color: var(--button-border); }
.sheet[data-view="table"] .sheet-all-only { display: none; }
.sheet-status-list { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; }
.sheet-passives { margin-top: 10px; }
.sheet-list dt { font-weight: 700; margin-top: 8px; }
.sheet-list dd { margin: 2px 0 0 14px; }
.sheet-rolls li { margin: 4px 0; }
.sheet-feature { border-bottom: 1px solid var(--border-inner); padding: 6px 0; }
.sheet-feature summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
.sheet-feature-text { padding: 2px 0 6px 14px; }

/* The DM's party page: one card per character, side by side on wide screens. */
.party { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin: 14px 0; }
.party-card { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.party-card h2 { margin: 0; font-size: 1.3rem; }
.party-card h2 a { color: inherit; text-decoration: none; }
.party-card h2 a:hover, .party-card h2 a:focus-visible { text-decoration: underline; }
.party-card header p, .party-card p { margin: 0; }
.party-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 6px; margin: 0; }
.party-stats div { border: 1px solid var(--border-inner); border-radius: var(--radius); padding: 6px; text-align: center; }
.party-stats dt { font-family: var(--font-heading); color: var(--heading); font-size: .75rem; }
.party-stats dd { margin: 0; font-size: 1.25rem; font-weight: 700; white-space: nowrap; }
.party-stats dd .small { display: block; font-weight: 400; }
.party-saves { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.party-save.proficient { font-weight: 700; text-decoration: underline; text-decoration-color: var(--metal-line); }
.party-card .sheet-rolls { margin: 0; }
.party-footer { margin-top: auto !important; padding-top: 6px; border-top: 1px solid var(--border-inner); }
.party-add summary { cursor: pointer; }
.party-add summary h2 { display: inline; margin: 0; }
.party-add form { margin-top: 10px; }
.sheet-feature-text p { margin: 6px 0; }

/* Reward counters (Inspiration points, Bonus d6) on party cards and character sheets */
.sheet-rewards h2 { margin-top: 0; }
.rewards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.reward { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  border: 1px solid var(--border-inner); border-radius: var(--radius); padding: 8px 6px; }
.reward-name { font-family: var(--font-heading); color: var(--heading); font-size: .8rem; }
.reward-counter { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 0; }
.reward-step { min-width: 40px; min-height: 40px; padding: 0; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-sunk); color: var(--brand); font-size: 1rem; cursor: pointer; }
.reward-step:hover, .reward-step:focus-visible { border-color: var(--brand); }
.reward-count { width: 3.2em; min-height: 40px; text-align: center; font-size: 1.3rem; font-weight: 700; padding: 2px 4px;
  -moz-appearance: textfield; appearance: textfield; }
.reward-count::-webkit-inner-spin-button, .reward-count::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.reward-count-text { width: auto; min-width: 1.5em; min-height: 0; display: inline-block; }
.reward-what { line-height: 1.25; }
.reward-status:empty { display: none; }
.reward-status.error { color: var(--danger); }
