@font-face {
  font-family: "Cinzel";
  src: url("../fonts/cinzel-400.woff2?v=20261201-credit1") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cinzel";
  src: url("../fonts/cinzel-700.woff2?v=20261201-credit1") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebgaramond-400.woff2?v=20261201-credit1") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebgaramond-400i.woff2?v=20261201-credit1") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebgaramond-600.woff2?v=20261201-credit1") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("../fonts/ebgaramond-700.woff2?v=20261201-credit1") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #2a2118;
  --ink-soft: #5c4f40;
  --parchment: #fbf6ec;
  --parchment-deep: #f3e8d4;
  --desk: #e7d8c0;
  --rule: #d7c4a4;
  --rule-strong: #8d7048;
  --oxblood: #6e2b33;
  --oxblood-deep: #521f26;
  --forest: #234237;
  --gold: #9a7436;
  --gold-soft: #e4d2ae;
  --focus: #8d3b3b;
  --serif: "EB Garamond", "Palatino Linotype", Palatino, Georgia, serif;
  --display: "Cinzel", "Palatino Linotype", Palatino, serif;
  --shadow: 0 22px 50px rgba(62, 42, 24, 0.16);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.45;
  background-color: var(--desk);
  background-image:
    radial-gradient(ellipse at 18% 0%, rgba(255, 248, 236, 0.7), transparent 42%),
    radial-gradient(ellipse at 90% 8%, rgba(154, 116, 54, 0.08), transparent 36%),
    linear-gradient(180deg, #f6ead6 0%, #e7d3b4 46%, #dcc6a4 100%);
}

.skip {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background: var(--oxblood);
  color: #f8f1e6;
  padding: 0.4rem 0.7rem;
  z-index: 5;
}
.skip:focus { top: 0.6rem; }

.site-head, main, .site-foot {
  width: min(1080px, calc(100% - 2rem));
  margin-left: auto;
  margin-right: auto;
}

.site-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.5rem 2rem;
  align-items: end;
  padding: 2.2rem 0 1.2rem;
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
}

.mark {
  width: 52px;
  height: 52px;
  flex: none;
  filter: drop-shadow(0 4px 8px rgba(80, 40, 24, 0.12));
}

.kicker, .sheet-kicker, .caption, .field-note, .section-title, .ability .abbr {
  font-family: var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.kicker {
  margin: 0 0 0.15rem;
  color: var(--gold);
  font-size: 0.62rem;
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--oxblood-deep);
}

.subtitle {
  margin: 0.2rem 0 0;
  font-family: var(--display);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.panel, .sheet {
  background: var(--parchment);
  border: 1px solid #e4d3b6;
  box-shadow: var(--shadow);
}

.panel { padding: 1.15rem 1.25rem 1.3rem; margin-bottom: 1.4rem; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  border-bottom: 1px solid var(--gold-soft);
  margin-bottom: 1rem;
}

.panel-head h2, .sheet h3, .block h3 {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--oxblood);
}

.panel-head h2 { margin: 0 0 0.45rem; font-size: 0.78rem; }

.help summary {
  cursor: pointer;
  color: var(--forest);
  font-size: 1rem;
}
.help summary:hover { color: var(--oxblood); }
.help p { margin: 0.4rem 0 0.8rem; max-width: 40rem; color: var(--ink-soft); }

.option-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
}





.sheet .identity { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.xp-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.2rem 0 1rem;
  font-size: 1.05rem;
}
.xp-table th, .xp-table td {
  border-bottom: 1px solid var(--rule);
  padding: 0.28rem 0.45rem;
  text-align: left;
}
.xp-table th {
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 400;
}

.notes {
  margin: 0.4rem 0 1rem;
  padding: 0.55rem 0.8rem;
  border-left: 3px solid var(--gold);
  background: rgba(255, 250, 242, 0.7);
  color: var(--ink-soft);
}
.notes li { margin: 0.15rem 0; }

label, legend {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

select, input[type="text"], input[type="number"] {
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--ink);
  background: #fffaf3;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  padding: 0.38rem 0.5rem;
  width: 100%;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}
select:hover, input[type="text"]:hover, input[type="number"]:hover { border-color: var(--oxblood); }
select:focus, input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--oxblood);
  box-shadow: 0 0 0 3px rgba(110, 43, 51, 0.16);
}
select:disabled, input:disabled {
  color: #9a8b78;
  background: #f6f0e6;
  border-color: var(--rule);
}

fieldset {
  border: 1px dashed var(--rule);
  margin: 0.95rem 0 0;
  padding: 0.7rem 0.8rem 0.85rem;
  background: rgba(255, 252, 247, 0.45);
  transition: border-color 0.18s ease, background-color 0.18s ease;
}
fieldset.is-active, .name-entry.is-active input {
  border-color: var(--gold);
}
fieldset.is-active { background: #fffaf3; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.55rem;
}
.stat-grid input { text-align: center; font-size: 1.35rem; }

.name-entry { margin-top: 0.85rem; max-width: 22rem; }

.field-note {
  margin: 0.45rem 0 0;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  text-transform: none;
  font-family: var(--serif);
  color: var(--ink-soft);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

.btn {
  font-family: var(--display);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 2px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.65; cursor: progress; transform: none; }

.btn-primary {
  background: var(--oxblood);
  color: #f8f1e6;
  border: 1px solid var(--oxblood-deep);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset;
}
.btn-primary:hover { background: var(--oxblood-deep); }

.btn-ghost {
  background: transparent;
  color: var(--oxblood-deep);
  border: 1px solid var(--rule-strong);
}
.btn-ghost:hover { background: #fffaf3; border-color: var(--oxblood); }

.sheet {
  position: relative;
  padding: 1.85rem 1.7rem 1.9rem;
  margin-bottom: 2rem;
  background-color: var(--parchment);
  background-image:
    linear-gradient(180deg, rgba(255, 252, 246, 0.65), transparent 7rem),
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(141, 112, 72, 0.035) 4px);
}
.sheet::before,
.sheet::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.sheet::before {
  inset: 0.55rem;
  border: 1px solid rgba(154, 116, 54, 0.55);
  box-shadow: inset 0 0 0 4px rgba(251, 246, 236, 0.4), inset 0 0 0 5px rgba(154, 116, 54, 0.28);
}
.sheet::after {
  inset: 0.38rem;
  background:
    linear-gradient(var(--gold), var(--gold)) left top / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left top / 1px 16px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right top / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right top / 1px 16px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left bottom / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) left bottom / 1px 16px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right bottom / 16px 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) right bottom / 1px 16px no-repeat;
}
.sheet:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sheet-banner {
  text-align: center;
  padding-bottom: 0.8rem;
  margin-bottom: 0.9rem;
  border-bottom: 3px double var(--gold);
}
.sheet-kicker {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.68rem;
}
.char-name {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  font-weight: 700;
  line-height: 1.05;
  color: var(--ink);
}
.char-title {
  margin: 0.15rem 0 0;
  font-style: italic;
  font-size: 1.35rem;
  color: var(--ink-soft);
}
.clamp {
  margin: 0 0 0.8rem;
  padding: 0.45rem 0.7rem;
  background: #f8ead0;
  border-left: 3px solid var(--gold);
}

.identity {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0 0 1rem;
}
.identity div, .vital, .ability, .coin {
  background: rgba(255, 252, 247, 0.72);
  border: 1px solid var(--rule);
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}
.identity div { padding: 0.4rem 0.5rem 0.5rem; text-align: center; }
.identity dt {
  font-family: var(--display);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--oxblood);
}
.identity dd { margin: 0.1rem 0 0; font-size: 1.2rem; font-weight: 600; }

.vitals {
  display: grid;
  grid-template-columns: 0.7fr 1.1fr 1.2fr;
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}
.vital {
  padding: 0.55rem 0.75rem 0.65rem;
  text-align: center;
}
.vital span, .coin span, .coin small {
  display: block;
  font-family: var(--display);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--oxblood);
}
.vital strong {
  display: grid;
  place-items: center;
  margin: 0.2rem auto 0.15rem;
  font-family: var(--display);
  font-size: 2.15rem;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: lining-nums tabular-nums;
}
.vital-round strong {
  width: 4.4rem;
  height: 4.4rem;
  border: 1.5px solid var(--rule-strong);
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%, #fffdf8, #f4e7cf 72%);
  box-shadow: inset 0 0 0 3px rgba(251, 246, 236, 0.8), inset 0 0 0 4px rgba(141, 112, 72, 0.28);
}
.vital small { display: block; color: var(--ink-soft); font-size: 0.95rem; }

.section-title {
  margin: 1.15rem 0 0.45rem;
  font-size: 0.72rem;
  border-bottom: 1px solid var(--gold-soft);
  padding-bottom: 0.25rem;
}

.abilities {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.5rem;
}
.ability { padding: 0.55rem 0.6rem 0.5rem; }
.ability:hover, .identity div:hover, .vital:hover, .coin:hover {
  transform: translateY(-2px);
  border-color: var(--rule-strong);
  box-shadow: 0 8px 16px rgba(80, 52, 24, 0.08);
}
.ability header {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "score abbr"
    "score name";
  align-items: center;
  column-gap: 0.55rem;
}
.ability .abbr { grid-area: abbr; color: var(--oxblood); font-size: 0.8rem; }
.ability-name { grid-area: name; color: var(--ink-soft); font-size: 0.95rem; }
.ability .score {
  grid-area: score;
  display: grid;
  place-items: center;
  width: 3.4rem;
  height: 3.4rem;
  border: 1.5px solid var(--rule-strong);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #fffdf8, #f3e6cc 70%);
  box-shadow: inset 0 0 0 2px rgba(251, 246, 236, 0.9), inset 0 0 0 3px rgba(141, 112, 72, 0.25);
  font-family: var(--display);
  font-size: 1.25rem;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
}
.mods { margin-top: 0.35rem; }
.mods div, .traits div {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  border-top: 1px dotted var(--rule);
  padding: 0.12rem 0;
  font-size: 0.98rem;
}
.mods b, .traits b { font-weight: 600; }
.prof { margin: 0.35rem 0 0; color: var(--ink-soft); font-size: 0.95rem; font-style: italic; }

.caption { margin: 0 0 0.4rem; font-size: 0.95rem; letter-spacing: 0.01em; text-transform: none; font-family: var(--serif); color: var(--ink-soft); }

.matrix-wrap { overflow-x: auto; margin-bottom: 0.35rem; }
table.matrix {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  min-width: 36rem;
}
table.matrix th, table.matrix td {
  border: 1px solid var(--rule);
  text-align: center;
  padding: 0.32rem 0.2rem;
}
table.matrix th {
  background: #f4e7d2;
  color: var(--oxblood);
  font-family: var(--display);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
table.matrix td {
  background: rgba(255, 252, 247, 0.8);
  font-variant-numeric: lining-nums tabular-nums;
}
table.matrix.ledger td {
  font-family: var(--display);
  font-size: 1.2rem;
  padding: 0.48rem 0.25rem;
}
table.matrix tbody tr:hover td { background: #fff6e8; }

.prose { margin: 0.2rem 0 0.55rem; }
.block h3 { margin: 0.8rem 0 0.35rem; font-size: 0.72rem; }
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.block ul, .spell-list { margin: 0.2rem 0 0.4rem; padding-left: 1.15rem; }
.block li, .spell-list li { padding: 0.08rem 0; }
.spell-list { list-style: none; padding-left: 0; }
.spell-list span {
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--oxblood);
  margin-right: 0.35rem;
}
.empty { margin: 0.2rem 0; color: var(--ink-soft); font-style: italic; }

.coins {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
}
.coin { text-align: center; padding: 0.45rem 0.3rem 0.5rem; }
.coin b { display: block; font-family: var(--display); font-size: 1.25rem; font-weight: 700; }

.traits {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.2rem;
}
.background {
  margin: 0.9rem 0 0.2rem;
  padding: 0.7rem 0.9rem;
  border-left: 3px solid var(--oxblood);
  background: rgba(255, 250, 242, 0.7);
  font-style: italic;
  font-size: 1.18rem;
}

.colophon {
  margin: 1rem 0 0;
  text-align: center;
  color: var(--ink-soft);
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.site-foot {
  padding: 0 0 2.4rem;
  color: var(--ink-soft);
  font-size: 1rem;
}
.site-foot p { margin: 0.2rem 0; }
.site-foot a { color: var(--oxblood-deep); }
.site-foot a:hover { background: rgba(110, 43, 51, 0.08); }

.noscript {
  width: min(1080px, calc(100% - 2rem));
  margin: 1rem auto;
  padding: 0.8rem 1rem;
  background: #fff4e4;
  border: 1px solid var(--gold);
}

.sheet-placeholder { text-align: center; color: var(--ink-soft); font-style: italic; }

@media (max-width: 980px) {
  .site-head { grid-template-columns: 1fr; gap: 0.6rem; }
  .option-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .identity { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .vitals { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  body { font-size: 1.05rem; }
  .site-head, main, .site-foot { width: min(100% - 1.2rem, 1080px); }
  .option-grid, .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .abilities, .identity, .coins, .traits, .split { grid-template-columns: 1fr 1fr; }
  .actions .btn { flex: 1 1 auto; }
  .sheet { padding: 1.15rem 0.85rem 1.3rem; }
  .sheet::before { inset: 0.35rem; }
  table.matrix { min-width: 32rem; }
}

@media (max-width: 460px) {
  .abilities, .identity, .coins, .traits, .split { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .btn:hover, .ability:hover, .identity div:hover, .vital:hover, .coin:hover { transform: none; }
}

[hidden] { display: none !important; }
.option-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.block li { overflow-wrap: anywhere; }
.ability .score { width: 3.4rem; height: 3.4rem; font-size: 1.05rem; padding: 0; white-space: nowrap; letter-spacing: -0.02em; }
@media (max-width: 760px) { .option-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .option-grid { grid-template-columns: 1fr; } }

/* Rules options panel (refs #20): fixed cells, so toggling Psionics or changing race never moves anything. */
.option-switches {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem 1.5rem; align-items: start;
  margin: 0 0 1.1rem; padding: .8rem 1rem .9rem; border: 1px solid var(--rule); border-radius: 3px; background: #fffaf3;
}
.switches-title { padding: 0 .4rem; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.ua-switch { display: grid; grid-template-columns: 1.4rem 1fr; column-gap: .6rem; align-items: start; margin: 0; cursor: pointer; font-size: 1.08rem; }
.ua-switch input { accent-color: var(--oxblood); width: 1.4rem; height: 1.4rem; margin: .1rem 0 0; }
.switch-text { display: flex; flex-direction: column; }
.switch-name { line-height: 1.6rem; }
.ua-switch .field-note { margin: .1rem 0 0; }
.psionic-group { display: flex; flex-direction: column; gap: .45rem; }
.ua-sub { margin-left: 1rem; padding-left: .9rem; border-left: 2px solid var(--rule); font-size: .98rem; transition: opacity .15s ease; }
.ua-sub.is-off { visibility: hidden; opacity: 0; }
.ua-sub:has(input:disabled) { cursor: default; }
.mc-levels { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: end; }
.mc-levels[hidden] { display: none; }
.mc-levels .field-note { flex-basis: 100%; }
select option:disabled { color: #b5a68f; background: #f3ece1; font-style: italic; }
@media (max-width: 760px) { .option-switches { grid-template-columns: 1fr; } }

/* Line up every control in the options grid (refs #23): labels stay on one line and the
   select/input sits at the bottom of its cell, so a row's controls share the same baseline. */
.option-grid { align-items: end; }
.option-grid > label, .mc-levels > label { justify-content: flex-end; white-space: nowrap; min-width: 0; }
.mc-levels { grid-column: 1 / -1; display: grid; grid-template-columns: inherit; gap: inherit; }
.mc-levels[hidden] { display: none; }
.mc-levels .field-note, .mc-levels #mc-max { grid-column: 1 / -1; justify-self: start; white-space: normal; }
.option-grid .lbl { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option-grid select, .option-grid input[type="text"] { height: 2.5rem; box-sizing: border-box; }
/* Content-sized leading columns keep the primary switches aligned at desktop width. */
@media (min-width: 1100px) {
  .option-switches { grid-template-columns: max-content max-content minmax(0, 1fr); column-gap: 1.75rem; }
  .option-switches .switch-name { white-space: nowrap; letter-spacing: 0.06em; }
  .option-switches .ua-sub .switch-name { white-space: normal; overflow-wrap: anywhere; }
  .option-switches .ua-switch { font-size: 1rem; }
  .option-switches .ua-sub { font-size: 0.92rem; margin-left: 0.6rem; padding-left: 0.7rem; }
}

/* Boxed character record: keep the game tables distinct from conditional notes. */
.sheet .block {
  min-width: 0;
  margin: 0.8rem 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--rule);
  background: rgba(255, 252, 247, 0.72);
  overflow-wrap: anywhere;
}
.sheet .block > h3 {
  margin: -0.7rem -0.8rem 0.6rem;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--rule);
  background: #f4e7d2;
  color: var(--oxblood-deep);
}
.sheet .identity { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.sheet .identity div:nth-child(2) { grid-column: span 2; }
.sheet .identity dd { font-size: 1.05rem; overflow-wrap: anywhere; }
.sheet .vitals { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 0.8rem; }
.sheet .vital strong { font-size: clamp(1.45rem, 3vw, 2.15rem); overflow-wrap: anywhere; }
.sheet .abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 1rem 0; }
.sheet .ability { min-width: 0; padding: 0.65rem 0.75rem; }
.sheet .ability-com { grid-column: 2; }
.sheet .ability header { grid-template-columns: 3.4rem 1fr; }
.sheet .ability .score { font-size: 1.1rem; }
.sheet .mods { margin-bottom: 0; }
.sheet .mods div { align-items: baseline; }
.sheet .mods dt { min-width: 0; }
.sheet .mods dd { margin: 0; text-align: right; font-weight: 600; }
.sheet .save-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.sheet table.matrix { min-width: 0; table-layout: fixed; }
.sheet table.matrix caption { text-align: left; color: var(--ink-soft); margin: 0.25rem 0; font-size: 0.95rem; }
.sheet table.matrix td { font-weight: 600; }
.sheet table.saves { table-layout: auto; }
.sheet table.saves th { text-align: left; font-family: var(--serif); font-size: 1rem; letter-spacing: 0; text-transform: none; }
.sheet table.saves td { font-size: 1.3rem; padding: 0.35rem 0.7rem; }
.sheet table.turn-undead th {
  font-family: var(--serif); font-size: 1rem; letter-spacing: 0; text-align: left;
}
.sheet table.turn-undead th:last-child { width: 38%; text-align: center; }
.sheet table.turn-undead td { font-size: 1.15rem; }
.sheet table.turn-undead th, .sheet table.turn-undead td { padding: 0.25rem 0.6rem; }
.sheet table.attack th, .sheet table.attack td { padding: 0.4rem 0.05rem; font-size: 0.9rem; font-family: var(--serif); letter-spacing: 0; }
.sheet table.attack th:first-child { width: 3rem; }
.sheet table.spell-slots th { font-family: var(--serif); letter-spacing: 0; font-size: 0.95rem; }
.sheet table.spell-slots th:first-child { width: 5.5rem; }
.sheet .split { gap: 1rem; }
.sheet .coins { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.sheet .record-space { min-height: 2.5rem; margin-top: 0.6rem; border-bottom: 1px dotted var(--rule); }
.sheet .hp-breakdown ul { list-style: none; padding-left: 0; margin: 0; }
.sheet .hp-breakdown li { font-size: 0.95rem; line-height: 1.45; padding: 0.3rem 0; }
.sheet .hp-breakdown li + li { border-top: 1px dotted var(--rule); }
.attack-narrow { display: none; }
@media (max-width: 800px) {
  .sheet .abilities { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet .ability-com { grid-column: 1 / -1; justify-self: center; width: calc((100% - 0.5rem) / 2); }
  .sheet .save-layout, .sheet .split { grid-template-columns: 1fr; gap: 0; }
  .sheet .identity { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet .identity div:nth-child(2) { grid-column: auto; }
  .sheet .vitals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attack-wide { display: none; }
  .attack-narrow { display: block; }
}
@media (max-width: 460px) {
  .sheet .abilities { grid-template-columns: 1fr; }
  .sheet .ability-com { width: 100%; }
  .sheet .block { padding: 0.6rem; }
  .sheet .block > h3 { margin: -0.6rem -0.6rem 0.5rem; padding: 0.5rem 0.6rem; }
  .sheet table.attack th, .sheet table.attack td { font-size: 0.8rem; }
  .sheet table.attack th:first-child { width: 2.5rem; }
  .sheet table.spell-slots th, .sheet table.spell-slots td { font-size: 0.8rem; padding: 0.3rem 0.05rem; }
  .sheet table.spell-slots th:first-child { width: 4.4rem; }
}
@media (max-width: 460px) {
  .sheet .coin b { font-size: 0.95rem; white-space: nowrap; }
}

/* Painted library and local uploads share one oval canvas, including its ring. */
.portrait-heading { display: flex; align-items: center; gap: 1.5rem; margin-bottom: 0.75rem; }
.portrait-heading .sheet-banner { flex: 1; min-width: 0; margin: 0; }
.portrait-heading .char-title { overflow-wrap: anywhere; }
.portrait-block { flex: 0 0 112px; margin: 0; }
.portrait-image { display: block; width: 112px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; overflow: hidden; }
.portrait-image canvas { display: block; width: 100%; height: auto; aspect-ratio: 320 / 404; }
.portrait-image:focus-visible { outline: 2px solid var(--oxblood); outline-offset: 4px; }
.portrait-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; margin: 0 0 1rem; font-size: 0.9rem; }
.portrait-controls button { border: 1px solid var(--rule); background: #fffaf3; color: var(--ink); padding: 0.3rem 0.6rem; cursor: pointer; font: inherit; }
.portrait-controls input { max-width: 100%; min-width: 0; font: inherit; }
.portrait-controls small { flex-basis: 100%; color: var(--ink-soft); }
.portrait-option { display: flex; flex-direction: row; align-items: center; gap: 0.5rem; margin: 0.75rem 0; font-family: var(--serif); font-size: 1rem; letter-spacing: 0; text-transform: none; }
.portrait-option input { accent-color: var(--oxblood); }
@media (max-width: 460px) {
  .portrait-heading { gap: 0.75rem; }
  .portrait-block { flex-basis: 88px; }
  .portrait-image { width: 88px; }
  .portrait-heading .char-name { font-size: 1.65rem; overflow-wrap: anywhere; }
}

/* Appendix P party mode */
.party-option-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; align-items: end; }
.party-option-grid > label { min-width: 0; }
.party-option-grid input, .party-option-grid select { height: 2.5rem; min-width: 0; box-sizing: border-box; }
@media (max-width: 760px) { .party-option-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .party-option-grid { grid-template-columns: 1fr; } }
#party-options { margin-top: 1rem; }
#party-summary { min-width: 0; }
#party-summary h2, #party-summary h3 { margin: 1rem 0 .6rem; }
#party-summary p, #party-summary li { overflow-wrap: anywhere; }
.party-table-wrap { overflow-x: auto; max-width: 100%; }
.party-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.party-table th, .party-table td { text-align: left; vertical-align: top; padding: .5rem; border-bottom: 1px solid var(--line, #bbb); }
.party-table th { font-weight: 700; }
.party-table td:nth-child(9), .party-table td:nth-child(10) { min-width: 10rem; }
@media print { #party-options, #generation-mode { display: none !important; } }

.party-settings { margin-bottom: 1rem; }
.party-settings > summary { cursor: pointer; font-weight: 600; margin-bottom: .75rem; }
.party-filter { margin: 1rem 0; min-width: 0; }
.party-filter .actions { margin: 0 0 .5rem; }
.party-filter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .25rem .75rem; }
.party-filter-grid .portrait-option { margin: .25rem 0; }
.party-slot { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: .75rem 0; min-width: 0; }
.party-slot legend { grid-column: 1 / -1; }
.party-slot select { width: 100%; }
@media (max-width: 760px) { .party-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) {
  .party-slot, .party-filter-grid { grid-template-columns: 1fr; }
}
