/* Adventurer's Ledger: styles. Colors are tokens so light, dark, and print stay in sync.
   Dark is the default for everyone. The theme button sets data-ledger-theme="light" on the
   root element for the light look, so the system setting never changes the default. */

:root {
  color-scheme: dark;
  --bg: #15120f;
  --bg-glow-1: #231c15;
  --bg-glow-2: #1c1611;
  --surface: #1f1a15;
  --surface-2: #27211a;
  --surface-3: #332b22;
  --ink: #efe6d8;
  --ink-2: #cbbda9;
  --ink-3: #a19079;
  --line: #3a3128;
  --line-strong: #54483a;
  --accent: #e0b25a;
  --accent-hover: #ecc476;
  --accent-ink: #1d1407;
  --accent-soft: rgba(224, 178, 90, 0.15);
  --gold: #e7bf6e;
  --gold-soft: rgba(231, 191, 110, 0.13);
  --ok: #86c993;
  --ok-soft: rgba(134, 201, 147, 0.13);
  --warn: #ecb862;
  --warn-soft: rgba(236, 184, 98, 0.12);
  --bad: #f08479;
  --bad-ink: #1d1407;
  --temp: #6cb4ee;
  --req: #f5d04c;
  --req-soft: rgba(245, 208, 76, 0.16);
  --req-ring: rgba(245, 208, 76, 0.32);
  --req-ink: #1d1407;
  --focus: #f3a15a;
  --topbar: #0e0b09;
  --topbar-ink: #efe6d8;
  --topbar-ok: #9fd8a8;
  --topbar-warn: #f5d04c;
  --brand-gold: #d9a441;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: "Cinzel", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-ledger-theme="light"] {
  color-scheme: light;
  --bg: #f4efe6;
  --bg-glow-1: #fbf7ef;
  --bg-glow-2: #ece0ca;
  --surface: #fffdf9;
  --surface-2: #f8f2e8;
  --surface-3: #ece2d1;
  --ink: #2a211a;
  --ink-2: #54473a;
  --ink-3: #75665a;
  --line: #e3d6c1;
  --line-strong: #cbb89b;
  --accent: #9b2c2c;
  --accent-hover: #7f2222;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3df;
  --gold: #946410;
  --gold-soft: #f6ead0;
  --ok: #2c6a38;
  --ok-soft: #e4f0e3;
  --warn: #8a5600;
  --warn-soft: #fbf1dc;
  --bad: #a12727;
  --bad-ink: #ffffff;
  --temp: #2b6cb0;
  --req: #b98a00;
  --req-soft: #fff3b8;
  --req-ring: rgba(214, 167, 0, 0.35);
  --req-ink: #2e2300;
  --focus: #c2410c;
  --topbar: #231b15;
  --topbar-ink: #f3e9d8;
  --shadow-sm: 0 1px 2px rgba(64, 42, 20, 0.06);
  --shadow: 0 1px 2px rgba(64, 42, 20, 0.06), 0 6px 18px rgba(64, 42, 20, 0.07);
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  font: 16px/1.5 var(--font-body);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 560px at 8% -12%, var(--bg-glow-1) 0%, transparent 62%),
    radial-gradient(900px 520px at 108% -4%, var(--bg-glow-2) 0%, transparent 58%);
  background-repeat: no-repeat;
}
h1, h2, h3, h4 { line-height: 1.2; }
h1 { font-family: var(--font-display); font-weight: 700; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--surface); color: var(--ink); padding: 8px 12px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 10px; }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------------------------------------------------------------- top bar */

/* Side gutters clear a phone's system bars; the band above the sticky bar is painted to match it. */
body::before {
  content: ""; position: fixed; inset: 0 0 auto; z-index: 21;
  height: env(safe-area-inset-top, 0px); background: var(--topbar);
}
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--topbar); color: var(--topbar-ink);
  border-bottom: 2px solid var(--brand-gold);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0;
  color: inherit; text-decoration: none;
  font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; letter-spacing: 0.04em;
}
.brand .icon { width: 30px; height: 30px; color: var(--brand-gold); stroke-width: 1.6; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.top-link { color: var(--topbar-ink); text-decoration: none; font-weight: 600; font-size: 0.92rem; padding: 6px 8px; border-radius: 6px; }
.top-link:hover { background: rgba(255, 255, 255, 0.08); }
.btn.on-dark { background: transparent; color: var(--topbar-ink); border-color: rgba(243, 233, 216, 0.35); }
.btn.on-dark:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(243, 233, 216, 0.6); }
.icon-btn.on-dark { color: var(--topbar-ink); }
.icon-btn.on-dark:hover { background: rgba(255, 255, 255, 0.1); }
/* Whether this device's changes have reached the character server (shared site only). */
.sync-pill {
  font-size: 0.78rem; font-weight: 700; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px;
  color: var(--topbar-ink); border: 1px solid rgba(243, 233, 216, 0.3);
}
.sync-pill.ok { color: var(--topbar-ok); border-color: rgba(159, 216, 168, 0.45); }
.sync-pill.warn { color: var(--topbar-warn); border-color: rgba(245, 208, 76, 0.6); }
.sync-pill[hidden] { display: none; }
@media (max-width: 520px) {
  .top-link { display: none; }
  .brand { font-size: 1rem; }
}

main {
  flex: 1; width: 100%; max-width: 1200px; margin: 0 auto;
  padding-block: 24px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
main:focus { outline: none; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 14px;
  font-weight: 600; font-size: 0.95rem; line-height: 1.2; text-decoration: none;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  cursor: pointer; transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn.sm { min-height: 34px; padding: 5px 11px; font-size: 0.875rem; }
.btn.lg { min-height: 48px; padding: 11px 20px; font-size: 1rem; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: var(--bad-ink); }
.btn.danger:hover { background: var(--bad); border-color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; padding: 0;
  color: var(--ink-2); background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 700; font-size: 1.1rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.icon-btn.danger:hover { color: var(--bad); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.link {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-weight: 700; color: var(--accent); text-decoration: underline; text-underline-offset: 3px;
}

/* ---------------------------------------------------------------- type + misc */

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title { font-size: clamp(1.5rem, 3vw, 2rem); margin: 0; overflow-wrap: anywhere; }
.head-actions { display: flex; gap: 8px; }
.eyebrow { margin: 0 0 4px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
.lede { color: var(--ink-2); margin: 4px 0 16px; max-width: 68ch; }
.hint { color: var(--ink-3); font-size: 0.875rem; font-weight: 400; }
.muted { color: var(--ink-3); }
.ok { color: var(--ok); font-weight: 700; font-size: 0.85rem; }
.need { color: var(--warn); font-weight: 700; font-size: 0.85rem; }
.warn-text { color: var(--warn); font-weight: 600; font-size: 0.85rem; }
.tag {
  display: inline-block; vertical-align: middle;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; font-family: var(--font-body);
  background: var(--surface-3); color: var(--ink-2);
}
.tag.sub { background: var(--gold-soft); color: var(--gold); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card.empty { max-width: 560px; margin: 40px auto; text-align: center; }
.card-title { font-family: var(--font-display); font-size: 1.05rem; letter-spacing: 0.03em; margin: 0 0 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head .card-title { margin: 0; }
.sub-title { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); margin: 16px 0 6px; }
.card-title + .sub-title { margin-top: 0; }

.callout {
  margin: 16px 0; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}
.callout.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--ink); }
/* A problem note at the top of the page, closed with its X. */
.callout.notice { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-top: 0; }
.callout.notice p { margin: 0; padding-top: 7px; }
.callout ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------------------------------------------------------------- forms */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin: 8px 0 16px; }
.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.label { font-size: 0.85rem; font-weight: 700; color: var(--ink-2); }
input[type="text"], input[type="number"], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: 0.8; }
.num { width: 92px; text-align: center; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; margin: 6px 0; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.check.tight { margin: 0; }
.text-choice { max-width: 520px; }
/* Coin purse: platinum, gold, silver, copper, each with a dot in its metal's color. */
.coins { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; min-width: 0; margin: 0; padding: 0; border: 0; }
.coins legend { padding: 0; margin-bottom: 6px; }
.coin { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.coin .num { width: 100%; }
.coin-name { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 700; color: var(--ink-2); }
.coin-name::before { content: ""; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--metal); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3); }
.coin-pp { --metal: #cfd8e0; }
.coin-gp { --metal: #e2b23e; }
.coin-sp { --metal: #a9afb5; }
.coin-cp { --metal: #b8703a; }
@media (max-width: 640px) { .coins { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; margin: 4px 0 8px;
  background: var(--surface-3); border-radius: 10px; max-width: 100%;
}
.seg {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border: 0; border-radius: 7px; background: transparent;
  font-weight: 600; font-size: 0.9rem; color: var(--ink-2); cursor: pointer;
}
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg:hover { color: var(--ink); }
.seg.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.segmented.big .seg { padding: 9px 14px; }

/* ---------------------------------------------------------------- roster */

.hero {
  display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 28px; align-items: center;
  padding: 28px; margin-bottom: 24px;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); margin: 0 0 8px; }
.hero-art .icon { width: 100%; height: auto; color: var(--accent); stroke-width: 1.1; }
.hero.compact { grid-template-columns: 64px minmax(0, 1fr); padding: 20px 24px; gap: 20px; }
.hero.compact h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); }
.hero .lede { margin-bottom: 0; }
.store-line { margin: 8px 0 0; max-width: 68ch; font-size: 0.875rem; color: var(--ink-3); }
.store-line.is-loading::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%;
  background: var(--gold); vertical-align: 0.05em; animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.hero-points { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 6px; color: var(--ink-2); }
.hero-points li { padding-left: 20px; position: relative; }
.hero-points li::before { content: "\25C6"; position: absolute; left: 0; color: var(--gold); font-size: 0.75em; top: 0.3em; }
@media (max-width: 640px) {
  .hero, .hero.compact { grid-template-columns: 1fr; padding: 20px; gap: 12px; }
  .hero-art { width: 64px; }
}

.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 14px; }
.char-card {
  display: flex; align-items: stretch; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.char-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.char-open {
  flex: 1; min-width: 0; display: flex; gap: 14px; align-items: center; padding: 14px;
  background: none; border: 0; color: inherit; text-align: left; cursor: pointer;
}
.char-level {
  flex: none; width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem;
  background: var(--accent); color: var(--accent-ink);
}
.is-draft .char-level { background: var(--surface-3); color: var(--ink-3); }
.char-text { display: flex; flex-direction: column; min-width: 0; }
.char-name { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.char-line, .char-stats { font-size: 0.9rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char-stats { color: var(--ink-3); font-size: 0.85rem; }
.char-actions { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 6px; border-left: 1px solid var(--line); }
.char-player { font-size: 0.82rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.char-card.is-theirs .char-level { background: var(--surface-3); color: var(--ink); }
.roster-title { display: flex; align-items: baseline; gap: 4px; font-family: var(--font-display); font-size: 1.15rem; letter-spacing: 0.03em; margin: 26px 0 12px; }
.roster > .muted { margin: 0; }

/* The player code panel under the shared roster. */
.code-panel { margin-top: 28px; padding: 0; }
.code-panel summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 14px 20px; cursor: pointer; list-style: none; }
.code-panel summary::-webkit-details-marker { display: none; }
.code-panel summary::before { content: "\25B8"; display: inline-block; width: 10px; color: var(--gold); transition: transform 0.15s; }
.code-panel[open] summary::before { transform: rotate(90deg); }
.code-title { font-weight: 700; }
.code-panel > :not(summary) { margin-left: 20px; margin-right: 20px; max-width: 68ch; }
.code-panel > p { margin-top: 0; color: var(--ink-2); }
.code-panel > :last-child { margin-bottom: 18px; }
.code-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.player-code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; font-size: 1.05rem; letter-spacing: 0.06em;
  padding: 6px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line);
  overflow-wrap: anywhere; user-select: all;
}

/* ---------------------------------------------------------------- builder */

.steps { display: flex; gap: 6px; overflow-x: auto; padding: 4px; margin: 0 -4px 16px; scrollbar-width: thin; }
.step {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
  font-weight: 600; font-size: 0.9rem; cursor: pointer;
}
.step:hover { border-color: var(--line-strong); color: var(--ink); }
.step-num {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-3); font-size: 0.8rem; font-weight: 700;
}
.step.done .step-num { background: var(--ok); color: var(--surface); }
.step.active { border-color: var(--accent); color: var(--ink); box-shadow: 0 0 0 2px var(--accent-soft); }
.step.active .step-num { background: var(--accent); color: var(--accent-ink); }

.builder-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.builder-main h2 { font-family: var(--font-display); font-size: 1.5rem; margin: 0; }
.builder-main h2:focus { outline: none; }
.builder-main h3 { font-family: var(--font-display); font-size: 1.15rem; margin: 22px 0 8px; }
.builder-side { position: sticky; top: calc(76px + env(safe-area-inset-top, 0px)); }
@media (max-width: 960px) {
  .builder-body { grid-template-columns: minmax(0, 1fr); }
  .builder-side { position: static; }
}
@media (max-width: 520px) {
  .builder-main.card { padding: 16px; }
  .step-label { display: none; }
  .step.active .step-label { display: inline; }
  .step { padding-right: 6px; }
  .step.active { padding-right: 12px; }
}
.step-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }

h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); margin: 22px 0 8px; }

.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: 10px; margin: 8px 0 20px; }
.pick-grid.compact { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); margin-bottom: 8px; }
.pick-grid.two { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.pick {
  display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; text-align: left;
  color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.pick:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-2); }
.pick.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.pick:disabled { opacity: 0.45; cursor: not-allowed; }
.pick-title { font-family: var(--font-display); font-weight: 700; font-size: 1.02rem; }
.pick-meta { font-size: 0.78rem; font-weight: 700; color: var(--gold); }
.pick-blurb { font-size: 0.85rem; color: var(--ink-2); line-height: 1.4; }

.detail { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 8px; }
.detail > h3:first-child { font-size: 1.35rem; margin: 0 0 12px; }
.detail > .field { margin-bottom: 14px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 8px; margin: 0 0 12px; }
.facts div { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.facts dt { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.facts dd { margin: 2px 0 0; font-weight: 600; font-size: 0.92rem; }
.trait-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; color: var(--ink-2); }
.trait-list strong { color: var(--ink); }

.asi-list { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.asi-list li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.asi-list select { width: auto; min-height: 34px; padding: 4px 8px; }
.asi-amt { font-weight: 800; color: var(--accent); }

.choice {
  margin: 10px 0; padding: 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--line-strong); border-radius: var(--radius-sm);
}
.choice.needed { border-left-color: var(--warn); background: var(--warn-soft); }
.choice.complete { border-left-color: var(--ok); }
.choice-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; margin-bottom: 8px; }
.choice-title { font-weight: 700; }
.count { margin-left: 4px; font-weight: 600; font-size: 0.85rem; color: var(--ink-3); }
.asi-fields { display: grid; gap: 8px; margin-top: 8px; max-width: 560px; }
.asi-fields select optgroup { font-style: normal; font-weight: 700; }
/* A chosen feat: its book and prerequisite, what it does, and its own choices. */
.feat-detail { display: grid; gap: 8px; }
.feat-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin: 2px 0 0; }
.feat-prereq { font-size: 0.85rem; color: var(--ink-2); }
.feat-detail > .option-desc { font-size: 0.88rem; }
.feat-pick { padding: 8px 10px; border-left: 3px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.feat-pick.needed { border-left-color: var(--warn); background: var(--warn-soft); }
.feat-pick.complete { border-left-color: var(--ok); }
.feat-pick .choice-head { margin-bottom: 6px; }
.feat-pick .text-choice { width: 100%; }
.feat-pick .hint { display: block; margin-top: 4px; }

.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 8px; }
.options.compact { grid-template-columns: repeat(auto-fill, minmax(min(100%, 165px), 1fr)); }
.option {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.options.compact .option { padding: 8px 10px; }
.option:hover { border-color: var(--line-strong); }
.option.checked { border-color: var(--accent); background: var(--accent-soft); }
.option.disabled { opacity: 0.5; cursor: not-allowed; }
.option input { width: 16px; height: 16px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }
.option-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.option-name { font-weight: 600; font-size: 0.92rem; }
.option-desc { font-size: 0.82rem; color: var(--ink-2); line-height: 1.38; margin: 0; }
.option-reason { font-size: 0.75rem; color: var(--ink-3); font-style: italic; }

.feature-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.feature { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.feature.is-sub { border-left: 3px solid var(--gold); }
.feature-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.feature-name { font-weight: 700; }
.feature-text { margin: 4px 0 0; color: var(--ink-2); font-size: 0.92rem; }
.feature .choice { margin-bottom: 0; }

.ability-table { width: 100%; border-collapse: collapse; }
.ability-table th, .ability-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.ability-table thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.ability-table tr.primary th { color: var(--accent); }
.ability-table select { width: auto; min-width: 116px; }
@media (max-width: 520px) {
  .ability-table th, .ability-table td { padding: 7px 4px; }
  .ability-table tbody th { font-size: 0.9rem; }
  .ability-table select { min-width: 0; width: 74px; padding: 6px 2px 6px 6px; }
  .ability-table .stepper { gap: 2px; }
  .ability-table .stepper .icon-btn { width: 28px; height: 28px; }
  .ability-table .num { width: 64px; }
}
.num-cell { text-align: center !important; font-variant-numeric: tabular-nums; }
.total { font-weight: 700; font-size: 1.1rem; }
.mod { font-weight: 800; color: var(--accent); }
.star { color: var(--gold); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper .icon-btn { border-color: var(--line-strong); background: var(--surface); }
.stepper-val { min-width: 2ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.points { margin: 4px 0 10px; }
.points strong { font-size: 1.35rem; color: var(--accent); }
.points.over strong { color: var(--bad); }
.rolls { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.roll {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 78px; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.roll-total { font-family: var(--font-display); font-weight: 700; font-size: 1.45rem; line-height: 1.1; }
.roll-dice { display: flex; gap: 3px; }
.die {
  width: 20px; height: 20px; display: grid; place-items: center;
  font-size: 0.75rem; font-weight: 700; border-radius: 4px;
  background: var(--surface); border: 1px solid var(--line-strong);
}
.die.dropped { opacity: 0.4; text-decoration: line-through; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

.ac-preview { display: flex; align-items: center; gap: 14px; padding: 12px 14px; margin: 0 0 8px; border-radius: var(--radius-sm); background: var(--surface-2); }
.ac-badge {
  flex: none; width: 54px; height: 60px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; color: var(--accent);
  background: var(--surface); border: 2px solid var(--accent); border-radius: 12px 12px 26px 26px;
}
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 12px; }
.inline-form select, .inline-form input { flex: 1 1 200px; width: auto; }
.inline-form .btn { flex: none; }
.gear-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.gear-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-radius: var(--radius-sm); background: var(--surface-2); }

.review-list { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.review-list > li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; padding: 10px 14px;
  border-radius: var(--radius-sm); background: var(--surface-2); border-left: 4px solid var(--ok);
}
.review-list > li.todo { border-left-color: var(--warn); background: var(--warn-soft); }
.review-list ul { flex-basis: 100%; margin: 0; padding-left: 18px; font-size: 0.92rem; color: var(--ink-2); }
.finish { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 18px; }

.summary { padding: 16px; }
.summary .eyebrow { margin-bottom: 2px; }
.summary-name { font-family: var(--font-display); font-size: 1.25rem; margin: 0; overflow-wrap: anywhere; }
.summary .muted { margin: 2px 0 0; font-size: 0.9rem; }
.mini-abilities { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 12px 0; }
.mini-ab { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; border-radius: var(--radius-sm); background: var(--surface-2); }
.mini-label { font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em; color: var(--ink-3); }
.mini-mod { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; line-height: 1.2; }
.mini-score { font-size: 0.75rem; color: var(--ink-3); }
.mini-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0 0 12px; }
.mini-stats div { display: flex; justify-content: space-between; gap: 6px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.86rem; }
.mini-stats dt { color: var(--ink-3); }
.mini-stats dd { margin: 0; font-weight: 700; }
.mini-skills { margin: 0; font-size: 0.86rem; color: var(--ink-2); }

/* ---------------------------------------------------------------- sheet */

.sheet-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; }
.sheet-id { display: flex; align-items: center; gap: 16px; min-width: 0; }
.level-badge {
  flex: none; width: 76px; height: 76px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 4px var(--accent-soft);
}
.level-badge span { font-size: 0.6rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.level-badge strong { font-family: var(--font-display); font-size: 1.95rem; line-height: 1; }
.level-badge.pop { animation: pop 0.8s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.2); box-shadow: 0 0 0 12px var(--accent-soft); }
  100% { transform: scale(1); }
}
.sheet-titles { min-width: 0; }
.sheet-name { font-size: clamp(1.5rem, 3.5vw, 2.2rem); margin: 0; overflow-wrap: anywhere; }
.sheet-line { margin: 2px 0 0; font-weight: 600; color: var(--ink-2); }
.sheet-meta { margin: 2px 0 0; font-size: 0.9rem; color: var(--ink-3); }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
@media (max-width: 760px) {
  .sheet-head { grid-template-columns: minmax(0, 1fr); }
  .sheet-actions { justify-content: flex-start; }
  .level-badge { width: 62px; height: 62px; }
  .level-badge strong { font-size: 1.6rem; }
}

.tabs { display: flex; gap: 2px; margin: 18px 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs [role="tab"] {
  flex: none; padding: 10px 14px; margin-bottom: -1px; white-space: nowrap;
  font-weight: 700; font-size: 0.95rem; color: var(--ink-3);
  background: none; border: 0; border-bottom: 3px solid transparent; cursor: pointer;
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.stat-strip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px;
  padding: 10px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 0.66rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.stat-value { font-family: var(--font-display); font-weight: 700; font-size: 1.55rem; line-height: 1.2; }
.stat-note {
  font-size: 0.72rem; line-height: 1.3; color: var(--ink-3);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
@media (max-width: 900px) { .stat-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 400px) { .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.sheet-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.sheet-grid .col { display: grid; gap: 16px; min-width: 0; }
.panel > * + * { margin-top: 16px; }
.panel > .callout:first-child { margin-top: 0; }
@media (max-width: 860px) { .sheet-grid { grid-template-columns: minmax(0, 1fr); } }

.hp-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hp-cur { font-family: var(--font-display); font-size: 2.4rem; font-weight: 700; line-height: 1; }
.hp-max { margin-left: 6px; font-size: 1.1rem; font-weight: 700; color: var(--ink-3); }
.hp-temp { margin-left: 10px; font-weight: 700; color: var(--temp); }
/* Green for hit points, then blue for temporary hit points right after it. */
.hp-bar { display: flex; height: 10px; margin: 10px 0 12px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.hp-bar > div { flex: none; height: 100%; transition: width 0.3s; }
.hp-bar > div:last-child { border-radius: 0 999px 999px 0; }
.hp-fill { background: var(--ok); }
.hp-bar.mid .hp-fill { background: var(--warn); }
.hp-bar.low .hp-fill { background: var(--bad); }
.hp-temp-fill { background: var(--temp); }
.hp-controls, .rest-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hp-controls .num { width: 100px; min-height: 34px; padding: 4px 8px; }
.rest-controls { margin: 8px 0 6px; }
.hp-card .hint { margin: 0; }

.ability-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.ability {
  display: flex; flex-direction: column; align-items: center; padding: 10px 6px 8px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
}
.ab-name { font-size: 0.66rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.ab-mod { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; line-height: 1.15; }
.ab-score { margin-top: 2px; padding: 0 10px; font-size: 0.85rem; font-weight: 700; border-radius: 999px; background: var(--surface); border: 1px solid var(--line-strong); }
.ab-save { margin-top: 8px; display: inline-flex; align-items: center; gap: 5px; font-size: 0.8rem; color: var(--ink-2); }
.ab-save.prof { color: var(--ink); font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink-3); display: inline-block; }
.ab-save.prof .dot { background: var(--accent); border-color: var(--accent); }
@media (max-width: 400px) { .ability-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.skill-list { list-style: none; padding: 0; margin: 0; columns: 2; column-gap: 20px; }
.skill { display: flex; align-items: center; gap: 8px; padding: 5px 2px; border-bottom: 1px dashed var(--line); break-inside: avoid; font-size: 0.92rem; }
.skill-name { flex: 1; min-width: 0; }
.skill-ab { font-size: 0.68rem; font-weight: 700; color: var(--ink-3); }
.skill-bonus { min-width: 2.6ch; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.skill.lvl-none .skill-name { color: var(--ink-2); }
.skill.lvl-proficient, .skill.lvl-expertise { font-weight: 600; }
.pip { width: 10px; height: 10px; flex: none; display: inline-block; border-radius: 50%; border: 1.5px solid var(--ink-3); }
.pip.lvl-proficient, .lvl-proficient > .pip { background: var(--accent); border-color: var(--accent); }
.pip.lvl-expertise, .lvl-expertise > .pip { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-soft); }
.pip.lvl-half, .lvl-half > .pip { background: linear-gradient(90deg, var(--ink-3) 50%, transparent 50%); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 0; font-size: 0.8rem; color: var(--ink-3); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 400px) { .skill-list { columns: 1; } }

.attack-table, .prog-table { width: 100%; border-collapse: collapse; }
.attack-table { font-size: 0.92rem; }
.attack-table th { padding: 6px 8px; text-align: left; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.attack-table td { padding: 8px; vertical-align: top; border-bottom: 1px solid var(--line); }
.attack-notes { margin-top: 2px; font-size: 0.78rem; color: var(--ink-3); }

.res-list, .prof-list { margin: 0; display: grid; gap: 6px; }
.res-list div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.9rem; }
.res-list dt { color: var(--ink-2); }
.res-list dd { margin: 0; font-weight: 700; text-align: right; }
.prof-list { gap: 0; margin-bottom: 12px; }
.prof-list div { padding: 7px 0; border-bottom: 1px solid var(--line); }
.prof-list dt { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.prof-list dd { margin: 2px 0 0; font-size: 0.92rem; }

.cast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.cast-grid:empty { display: none; }
.cast-card {
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.cast-card h3 { margin: 0 0 8px; font-family: var(--font-display); font-size: 1.05rem; }
.cast-stats { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; }
.cast-stats dt { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.cast-stats dd { margin: 0; font-weight: 700; font-size: 1.05rem; }
.slot-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.slot-level { width: 110px; font-weight: 700; font-size: 0.92rem; }
.pips { display: flex; flex-wrap: wrap; gap: 6px; }
.pip-btn { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid var(--accent); background: var(--accent); cursor: pointer; }
.pip-btn.used { background: transparent; border-color: var(--line-strong); }
.slot-left { margin-left: auto; font-size: 0.85rem; color: var(--ink-3); }
.spell-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.spell-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.spell-list.mine li { flex-wrap: nowrap; }
.spell-name { flex: 1; min-width: 110px; font-weight: 600; overflow-wrap: anywhere; }
.count-pill { padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--surface-3); color: var(--ink-2); }

.feature-group .feat { padding: 10px 0; border-top: 1px solid var(--line); }
.feature-group .card-title + .feat { border-top: 0; padding-top: 0; }
.feat summary { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; cursor: pointer; list-style: none; font-weight: 700; }
.feat summary::-webkit-details-marker { display: none; }
.feat summary::before { content: "\25B8"; display: inline-block; width: 10px; color: var(--ink-3); transition: transform 0.15s; }
.feat[open] summary::before { transform: rotate(90deg); }
.feat p { margin: 6px 0 0 18px; font-size: 0.93rem; color: var(--ink-2); }
.feat-choices { margin: 6px 0 0 18px; padding-left: 18px; font-size: 0.9rem; color: var(--ink-2); }

.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; max-height: 620px; overflow-y: auto; }
.hist-item { display: flex; gap: 12px; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.hist-level {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; color: var(--accent); background: var(--surface); border: 2px solid var(--accent);
}
.hist-body { min-width: 0; }
.hist-feats { margin-top: 2px; font-size: 0.88rem; color: var(--ink-2); }
.hist-picks { margin-top: 2px; font-size: 0.82rem; color: var(--ink-3); }
.prog-table { font-size: 0.85rem; min-width: 600px; }
.prog-table th { padding: 6px; text-align: center; white-space: nowrap; font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); border-bottom: 2px solid var(--line-strong); }
.prog-table th.feat-col { text-align: left; }
.prog-table td { padding: 6px; border-bottom: 1px solid var(--line); }
.prog-table tr.future td { color: var(--ink-3); }
.prog-table tr.current td { background: var(--accent-soft); font-weight: 700; }
.prog-table tr.current td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.feat-cell { min-width: 230px; }
.feat-cell .sub { color: var(--gold); }

/* ---------------------------------------------------------------- level-up dialog */

dialog.modal {
  width: min(780px, calc(100vw - 24px)); max-width: none; max-height: calc(100vh - 32px);
  padding: 0; border: 0; border-radius: 16px; overflow: hidden;
  color: var(--ink); background: var(--surface); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
dialog.modal::backdrop { background: rgba(20, 14, 8, 0.58); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 1.55rem; }
.modal-body { flex: 1; padding: 16px 20px 20px; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 12px; padding: 12px 20px; background: var(--surface-2); border-top: 1px solid var(--line); }
.lu-status { font-size: 0.9rem; flex: 1 1 220px; }
.lu-buttons { display: flex; gap: 8px; margin-left: auto; }
.lu-section { font-family: var(--font-display); font-size: 1.1rem; margin: 22px 0 10px; }
.lu-hp { margin: 14px 0 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.lu-hp legend { padding: 0 6px; font-weight: 700; }
/* The hit die roll is required to level up, so its box is yellow until a valid roll is in it. */
.roll-input.needs-roll, .roll-input.needs-roll:focus {
  background: var(--req-soft); border: 2px solid var(--req); color: var(--ink);
  box-shadow: 0 0 0 3px var(--req-ring);
}
.req-tag {
  display: inline-block; margin-left: 4px; padding: 1px 8px; border-radius: 999px;
  background: var(--req); color: var(--req-ink); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.03em; vertical-align: 0.1em;
}
.req-tag[hidden] { display: none; }
.hp-gain { margin: 8px 0 0; }
.diff { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.diff li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding: 7px 10px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.92rem; }
.diff li.big { background: var(--ok-soft); }
.diff-label { font-weight: 600; }
.diff-vals { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.from { color: var(--ink-3); }
.diff li.new .from { font-style: italic; }
.to { font-weight: 800; color: var(--ok); }
.arrow { color: var(--ink-3); }
@media (max-width: 640px) {
  dialog.modal { width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .modal-inner { height: 100%; max-height: none; }
  .modal-body { padding: 14px 16px 18px; }
  .modal-head, .modal-foot {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .modal-head { padding-top: calc(16px + env(safe-area-inset-top, 0px)); }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
}

/* Confirmation dialog: a small centered box at every width. */
dialog.modal.confirm { width: min(440px, calc(100vw - 32px)); height: fit-content; max-height: calc(100vh - 32px); margin: auto; border-radius: 16px; }
dialog.modal.confirm .modal-inner { height: auto; }
dialog.modal.confirm .modal-head { padding: 16px 20px 12px; }
dialog.modal.confirm .modal-head h2 { font-size: 1.25rem; overflow-wrap: anywhere; }
dialog.modal.confirm .modal-body p { margin: 0; color: var(--ink-2); }
dialog.modal.confirm .modal-foot { padding: 12px 20px; }

/* Death saving throws: a centered box that opens at 0 hit points. */
dialog.modal.death { width: min(480px, calc(100vw - 32px)); height: fit-content; max-height: calc(100vh - 32px); margin: auto; border-radius: 16px; }
dialog.modal.death .modal-inner { height: auto; }
dialog.modal.death .modal-head { padding: 16px 20px 12px; }
dialog.modal.death .modal-body { padding: 16px 20px 20px; }
.death-rules { margin: 0 0 16px; font-size: 0.92rem; color: var(--ink-2); }
.death-track { display: grid; gap: 10px; margin: 0 0 16px; }
.death-row { display: grid; grid-template-columns: 92px auto 1fr; align-items: center; gap: 12px; }
.death-label { font-weight: 700; }
.death-count { justify-self: end; font-size: 0.85rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.save-pips { display: flex; gap: 8px; }
.save-pip { width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 2px solid var(--line-strong); background: transparent; cursor: pointer; }
.save-pip:hover { border-color: var(--ink-3); }
.save-pip.s.on { background: var(--ok); border-color: var(--ok); }
.save-pip.f.on { background: var(--bad); border-color: var(--bad); }
.death-status { margin: 0 0 16px; padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 600; background: var(--surface-2); border-left: 4px solid var(--ok); }
.death-status.dead { border-left-color: var(--bad); }
.death-heal { padding-top: 14px; border-top: 1px solid var(--line); }
.death-heal .inline-form { margin: 6px 0 0; }
.death-heal .inline-form input { flex: 0 1 120px; min-width: 0; }
.dying-row {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px;
  margin: 0 0 12px; padding: 8px 10px; border-radius: var(--radius-sm); font-size: 0.9rem;
  background: var(--surface-2); border-left: 4px solid var(--bad);
}

/* ---------------------------------------------------------------- footer */

.site-footer {
  border-top: 1px solid var(--line); font-size: 0.8rem; color: var(--ink-3);
  padding-block: 20px 28px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.site-footer .inner { max-width: 1200px; margin: 0 auto; }
.site-footer p { margin: 0 0 6px; }
.site-footer a { color: var(--ink-2); }


@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- print */

@media print {
  :root:not(#print-override) {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #fff; --surface-3: #eee;
    --ink: #000; --ink-2: #222; --ink-3: #555; --line: #bbb; --line-strong: #888;
    --accent: #000; --accent-ink: #fff; --accent-soft: #eee; --gold: #333; --gold-soft: #eee;
    --ok: #000; --ok-soft: #fff; --warn: #000; --warn-soft: #fff;
    --shadow: none; --shadow-sm: none;
  }
  body { background: #fff; font-size: 11pt; }
  .topbar, .site-footer, .tabs, .sheet-actions, .hp-controls, .rest-controls, .btn, .icon-btn,
  .notice, .dying-row, dialog, .inline-form, .skip-link, .readonly-note, .code-panel { display: none !important; }
  main { max-width: none; padding: 0; }
  .panel[hidden] { display: block !important; }
  .panel::before {
    content: attr(data-print-title); display: block; margin: 14pt 0 6pt; padding-bottom: 2pt;
    font-family: var(--font-display); font-size: 13pt; font-weight: 700; border-bottom: 1px solid #000;
  }
  .card, .stat, .ability, .hist-item, .feat { break-inside: avoid; box-shadow: none; }
  .history { max-height: none; overflow: visible; }
  textarea { border: 0; padding: 0; min-height: 0; resize: none; }
  input[type="number"] { border: 0; }
  .feat summary::before { content: ""; }
}

/* ---------------------------------------------------------------- another player's sheet */

/* Everything shows; the buttons and fields that would change the character are gone or locked. */
fieldset.ro-panel { border: 0; padding: 0; margin: 0; min-width: 0; }
.ro-panel .hp-controls, .ro-panel .rest-controls, .ro-panel .inline-form, .ro-panel [data-action="remove-spell"],
.ro-panel [data-action="undo-level"], .ro-panel [data-action="death-open"] { display: none; }
.ro-panel textarea:disabled, .ro-panel input:disabled {
  opacity: 1; cursor: default; color: var(--ink); -webkit-text-fill-color: var(--ink); background: var(--surface-2);
}
.ro-panel .pip-btn:disabled, .ro-panel input[type="checkbox"]:disabled { cursor: default; opacity: 1; }
.readonly-note { margin: 0 0 12px; }
