@font-face {
  font-family: "Cinzel";
  src: url("../fonts/cinzel-400.woff2?v=20261201-dungeon4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cinzel";
  src: url("../fonts/cinzel-700.woff2?v=20261201-dungeon4") 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-dungeon4") 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-dungeon4") 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-dungeon4") 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-dungeon4") 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 {
  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 {
  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); }

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 { border-color: var(--oxblood); }
select:focus, input[type="text"]: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; }

.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;
}
.treasure-title {
  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);
}
.treasure-types {
  margin: 0.15rem 0 0;
  font-style: italic;
  font-size: 1.35rem;
  color: var(--ink-soft);
}

.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; }

/* Treasure controls and ledger. */
main { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 1.4rem; align-items: start; }
.controls { position: static; }
.panel { padding: 1.15rem; }
.panel-head { margin-bottom: .65rem; }
.help { margin-bottom: 1rem; }
.help p { font-size: 1rem; }
.option-switches { margin: 0 0 1rem; border: 1px solid var(--rule); background: #fffaf3; }
.ua-switch { display: grid; grid-template-columns: 1.2rem 1fr; gap: .6rem; align-items: center; cursor: pointer; font-size: .72rem; letter-spacing: .05em; }
.ua-switch input { accent-color: var(--oxblood); width: 1.15rem; height: 1.15rem; margin: 0; }
.hoard-count { max-width: 12rem; margin-top: 1rem; }
.type-picker { margin: 0; padding: .65rem .7rem .85rem; }
.picker-heading { font-family: var(--display); font-size: .65rem; font-weight: 400; letter-spacing: .12em; text-transform: uppercase; margin: .8rem 0 .4rem; color: var(--ink-soft); }
.filters { display: flex; border: 1px solid var(--rule); border-radius: 2px; overflow: hidden; }
.filters button { flex: 1; border: 0; border-right: 1px solid var(--rule); color: var(--ink-soft); padding: .4rem .2rem; background: transparent; cursor: pointer; font-family: var(--serif); font-size: 1rem; }
.filters button:last-child { border-right: 0; }
.filters button[aria-pressed="true"] { background: var(--gold-soft); color: var(--ink); font-weight: 600; }
.mode-choice { margin-bottom: 1rem; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mode-choice button { border-bottom: 1px solid var(--rule); min-height: 44px; padding: .4rem .1rem; font-size: .95rem; line-height: 1.15; }
.mode-choice button:nth-child(4n) { border-right: 0; }
.mode-choice button:nth-last-child(-n+4) { border-bottom: 0; }
.category-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.category { min-height: 44px; padding: .45rem .3rem; font-family: var(--serif); font-size: 1rem; line-height: 1.2; overflow-wrap: normal; }
.category[data-table="rods-staves-wands"] { grid-column: 1 / -1; white-space: nowrap; }
.letter-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .3rem; }
.letter { display: grid; place-items: center; min-height: 34px; padding: .25rem 0; font-family: var(--display); font-size: .88rem; color: var(--ink); background: #fffaf3; border: 1px solid var(--rule); border-radius: 2px; cursor: pointer; transition: background .15s, border-color .15s; }
.letter:hover { border-color: var(--oxblood); background: var(--parchment-deep); }
.letter.deemphasized:not([aria-pressed="true"]) { color: #8c7c69; background: transparent; border-style: dashed; }
.letter[aria-pressed="true"] { background: var(--oxblood); color: #fffaf3; border-color: var(--oxblood-deep); box-shadow: inset 0 0 0 2px rgba(255,255,255,.15); }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.actions { gap: .5rem; }
.actions .btn { flex: 1 1 40%; padding: .7rem .4rem; font-size: .65rem; letter-spacing: .06em; }
.actions #generate, .actions #print { flex-basis: 100%; }
.status { min-height: 2.8em; border-top: 1px solid var(--gold-soft); padding-top: .65rem; color: var(--forest); }
.sheet { min-width: 0; padding: 1.7rem 1.5rem; }
.treasure-title { font-size: clamp(1.6rem, 3vw, 2.2rem); }
.treasure-types { font-size: 1.2rem; }
.record-meta { margin: .35rem 0 0; color: var(--ink-soft); font-size: .98rem; }
.totals-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; margin: 0 0 1.4rem; }
.totals-strip > div { padding: .55rem .65rem; background: rgba(255,252,247,.75); border: 1px solid var(--rule); text-align: center; break-inside: avoid; }
.totals-strip dt { font-family: var(--display); font-size: .56rem; letter-spacing: .06em; color: var(--ink-soft); }
.totals-strip dd { margin: .18rem 0 0; font-size: 1.45rem; font-weight: 600; line-height: 1.2; font-variant-numeric: lining-nums tabular-nums; }
.totals-strip small { font-family: var(--display); font-size: .6rem; color: var(--gold); }
.totals-strip .grand-total { border-color: var(--rule-strong); background: var(--parchment-deep); }
.totals-strip .grand-total dt, .totals-strip .grand-total dd { color: var(--oxblood-deep); }
.treasure-table { width: 100%; border-collapse: collapse; margin: 0 0 1.35rem; font-size: 1.06rem; font-variant-numeric: lining-nums tabular-nums; }
.treasure-table caption, .maps-card h3 { text-align: left; font-family: var(--display); font-weight: 700; font-size: .72rem; letter-spacing: .1em; color: var(--oxblood); padding: .25rem 0 .4rem; }
.treasure-table th, .treasure-table td { text-align: left; border-bottom: 1px solid var(--rule); padding: .4rem .3rem; vertical-align: top; }
.treasure-table thead th { color: var(--ink-soft); font-family: var(--display); font-size: .58rem; letter-spacing: .06em; font-weight: 400; background: var(--parchment-deep); }
.treasure-table thead th:not(:first-child), .treasure-table .numeric { text-align: right; }
.treasure-table .numeric { white-space: nowrap; }
.treasure-table td:first-child { overflow-wrap: anywhere; }
.treasure-table:has(th:nth-child(4)) td:nth-child(2) { white-space: normal; font-size: .88rem; color: var(--ink-soft); min-width: 5rem; }
.treasure-table tbody tr:nth-child(even) { background: rgba(243,232,212,.3); }
.treasure-table tfoot th, .treasure-table tfoot td { border-bottom: 3px double var(--gold-soft); font-weight: 600; }
.record-note { font-size: .9rem; color: var(--ink-soft); margin: .6rem 0 0; }
.empty-hoard { border-left: 3px solid var(--gold); background: var(--parchment-deep); padding: .85rem 1rem; font-style: italic; }
.maps-card { border: 1px solid var(--rule); padding: .6rem .8rem; margin: .8rem 0 1.1rem; break-inside: avoid; }
.maps-card h3, .maps-card p { margin: 0; }
.copy-buffer { position: fixed; top: 0; left: -10000px; }
dialog { background: var(--parchment); color: var(--ink); border: 1px solid var(--rule-strong); padding: 1.2rem; max-width: min(90vw, 44rem); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(42,33,24,.5); }
.manual-copy { width: 100%; height: 50vh; font-family: var(--serif); font-size: 1rem; display: block; margin-bottom: 1rem; }
@media (min-width: 1200px) {
  .site-head, main, .site-foot { width: min(1200px, calc(100% - 3rem)); }
  main { grid-template-columns: 350px minmax(0, 1fr); }
  .totals-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .totals-strip .grand-total { grid-column: auto; }
}
@media (max-width: 860px) {
  main { display: block; }
  .controls { position: static; }
  .letter-grid { grid-template-columns: repeat(11, minmax(0, 1fr)); }
  .totals-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .totals-strip .grand-total { grid-column: auto; }
}
@media (max-width: 580px) {
  body { font-size: 1.05rem; }
  .site-head, main, .site-foot { width: calc(100% - 1.2rem); }
  .site-head { padding-top: 1.5rem; }
  h1 { font-size: 1.65rem; line-height: 1.1; }
  .brand { gap: .65rem; }
  .mark { width: 42px; height: 42px; }
  .subtitle { font-size: .66rem; letter-spacing: .12em; }
  .letter-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .sheet { padding: 1.15rem .85rem; }
  .sheet::before { inset: .35rem; }
  .totals-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .totals-strip .grand-total { grid-column: auto; }
  .treasure-table { font-size: .97rem; }
  .treasure-table td, .treasure-table th { padding: .35rem .2rem; }
  .treasure-table:has(th:nth-child(4)) td:nth-child(2) { min-width: 0; font-size: .78rem; }
}
/* Narrow screens keep the full item description above its category and values. */
@media screen and (max-width: 580px) {
  .totals-strip dd { font-size: 1.2rem; overflow-wrap: anywhere; }
  .magic-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .magic-table tbody { display: block; }
  .magic-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; column-gap: .7rem; border-bottom: 1px solid var(--rule); padding: .3rem .2rem; }
  .magic-table td { display: block; border: 0; padding: .15rem 0; }
  .magic-table td:first-child { grid-column: 1 / -1; }
  .treasure-table.magic-table td:nth-child(2) { text-align: left; }
  .magic-table td:nth-child(3)::after { content: " XP"; }
  .magic-table td:nth-child(4)::after { content: " GP"; }
  .magic-table td:nth-child(3), .magic-table td:nth-child(4) { font-size: .85rem; color: var(--ink-soft); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
  .btn:hover { transform: none; }
}
[hidden] { display: none !important; }

.map-entry { margin: .4rem 0 .8rem; }
.map-entry h4 { font-family: var(--display); font-size: .78rem; letter-spacing: .04em; margin: 0 0 .25rem; color: var(--oxblood); }
.map-entry ul { margin: .25rem 0 0 1.1rem; padding: 0; }
.map-entry li { margin: .15rem 0; }
/* Encounter controls and field sheets use the treasure site's house style. */
[hidden] { display: none !important; }
.level-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35rem; }
.level-grid .letter { min-height: 43px; }
#wilderness-picker fieldset + fieldset { margin-top: .85rem; }
.matrix-preview { font-size: .88rem; line-height: 1.5; margin-top: .7rem; }
.check-hint { font-size: .88rem; border-top: 1px solid var(--gold-soft); padding-top: .8rem; }
.hoard-count { max-width: 100%; }
#count { width: 5.2rem; min-height: 44px; margin-top: .3rem; }
.results { min-width: 0; }
.sheet-tools { display: flex; gap: .55rem; justify-content: flex-end; }
.sheet-tools .btn { padding: .55rem .7rem; letter-spacing: .05em; font-size: .63rem; min-height: 40px; }
.print-help { margin: .35rem 0 .75rem; text-align: right; font-size: .82rem; }
.totals-strip dd { font-size: 1.35rem; }
.encounter-card { border: 1px solid var(--rule); background: rgba(255,252,247,.65); margin-bottom: 1.1rem; break-inside: avoid; page-break-inside: avoid; }
.encounter-head { display: flex; align-items: center; gap: .65rem; background: var(--parchment-deep); padding: .7rem .8rem; border-bottom: 1px solid var(--rule); }
.encounter-index { display: grid; place-items: center; font-family: var(--display); font-size: .75rem; color: var(--oxblood); border: 1px solid var(--gold); width: 2rem; height: 2rem; flex-shrink: 0; }
.sheet .encounter-head h3 { font-size: 1rem; letter-spacing: .035em; text-transform: none; margin: 0; }
.encounter-head p { margin: .15rem 0 0; font-size: .83rem; color: var(--ink-soft); }
.encounter-xp { margin-left: auto; white-space: nowrap; font-size: 1.05rem; color: var(--oxblood-deep); font-variant-numeric: tabular-nums; }
.encounter-xp small { font-family: var(--display); font-size: .55rem; }
.creature-group { margin: .7rem .8rem; }
.creature-group + .creature-group { border-top: 1px solid var(--rule-strong); padding-top: .65rem; }
.creature-group h4 { margin: 0; color: var(--oxblood); font-size: 1.1rem; }
.creature-source, .number-roll, .airborne-note { color: var(--ink-soft); font-size: .85rem; margin: .35rem 0 .55rem; }
.number-roll, .airborne-note { margin: .55rem .8rem; }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem .8rem; margin: .6rem 0; }
.stat-grid > div { min-width: 0; border-bottom: 1px solid var(--gold-soft); padding-bottom: .35rem; }
.stat-grid .wide { grid-column: 1 / -1; }
.stat-grid dt { color: var(--ink-soft); font-family: var(--display); font-size: .55rem; letter-spacing: .06em; }
.stat-grid dd { margin: .1rem 0 0; font-size: 1rem; overflow-wrap: anywhere; }
.hp-list { font-variant-numeric: tabular-nums; font-size: 1rem; overflow-wrap: anywhere; margin: .6rem 0; }
.hp-list strong { margin-right: .3rem; color: var(--oxblood); }
.treasure-line, .group-detail { font-size: .95rem; margin: .55rem 0; }
.treasure-link { display: inline-block; color: var(--forest); margin-left: .3rem; white-space: nowrap; text-underline-offset: .15em; }
.xp-details, .hp-details, .party-magic { font-size: .9rem; margin: .65rem 0; }
.xp-details summary, .hp-details summary, .party-magic summary { color: var(--forest); cursor: pointer; }
.xp-details p, .party-magic p { margin: .3rem 0; overflow-wrap: anywhere; }
.xp-details summary span { font-size: .85rem; color: var(--ink-soft); }
.monster-notes, .encounter-notes { font-size: .87rem; color: var(--ink-soft); padding-left: 1.1rem; margin: .65rem 0; }
.encounter-notes { margin: .65rem .8rem .65rem 1.9rem; }
.monster-notes li + li, .encounter-notes li + li { margin-top: .3rem; }
.meeting { padding: .6rem .8rem; border-top: 1px solid var(--gold-soft); background: rgba(243,232,212,.35); }
.meeting p, .reaction { margin: .25rem 0; font-size: .9rem; }
.meeting span { color: var(--ink-soft); }
.reaction { margin: .65rem .8rem; color: var(--ink-soft); }
.roll-trail { margin: 0; padding: .65rem .8rem; font-size: .8rem; color: var(--ink-soft); border-top: 1px dashed var(--rule); line-height: 1.5; }
.adjudication { font-size: .9rem; color: var(--oxblood-deep); background: var(--parchment-deep); border-left: 2px solid var(--gold); padding: .55rem .65rem; margin: .65rem .8rem; }
.creature-group .adjudication, .sheet-adjudication { margin-left: 0; margin-right: 0; }

.npc-block { margin: .7rem .8rem; border-top: 1px solid var(--rule-strong); padding-top: .6rem; break-inside: avoid; }
.npc-block h4 { margin: 0; color: var(--oxblood); font-size: 1.05rem; }
.npc-block .npc-index { color: var(--ink-soft); margin-right: .2rem; }
.npc-block .stat-grid dd { font-size: .92rem; }
.npc-block.soldiers p { margin: .45rem 0; font-size: .92rem; overflow-wrap: anywhere; }
.party-table { border-collapse: collapse; width: calc(100% - 1.6rem); margin: .7rem .8rem; font-size: .95rem; }
.party-table th, .party-table td { text-align: left; padding: .35rem .25rem; border-bottom: 1px solid var(--rule); }
.party-table th { font-family: var(--display); font-size: .55rem; color: var(--ink-soft); }
.party-table caption { text-align: left; font-size: .88rem; color: var(--ink-soft); }
.party-table small { display: block; font-size: .8rem; color: var(--ink-soft); }
.party-table th:last-child, .party-table td:last-child { text-align: right; }
.party-magic { margin: .8rem; }
.encounter-card > p:not([class]) { margin: .65rem .8rem; }
.fortress-type { margin: .8rem; color: var(--oxblood); font-size: 1.15rem; }
@media (max-width: 580px) {
  .level-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sheet-tools { justify-content: stretch; }
  .sheet-tools .btn { flex: 1; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem .65rem; }
  .encounter-head { padding: .6rem; gap: .45rem; flex-wrap: wrap; }
  .sheet .encounter-head h3 { font-size: .95rem; }
  .encounter-xp { font-size: .95rem; }
  .print-help { text-align: left; }
}

/* ------------------------------------------------------------------ Dungeon generator */
.mode-choice.filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mode-choice button:nth-last-child(-n+4) { border-bottom: 0; }
.mode-choice button:nth-child(4n) { border-right: 1px solid var(--rule); }
.mode-choice button:last-child { border-right: 0; }
.category-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.type-picker + .type-picker, .type-picker + .option-switches, .option-switches + div { margin-top: .85rem; }
.inline-count { margin-top: .7rem; }
#rooms, #stack { width: 5.2rem; min-height: 44px; margin-top: .3rem; }
#wander { min-height: 44px; margin-top: .3rem; }
.option-switches { margin: .85rem 0 0; padding: .55rem .7rem; display: grid; gap: .55rem; }
.ua-switch { flex-direction: row; text-transform: none; font-family: var(--serif); font-size: 1rem; letter-spacing: 0; color: var(--ink); }
.ua-switch.is-disabled { opacity: .55; }
.resume-card { border: 1px solid var(--gold); background: #fffaf3; padding: .7rem .8rem .8rem; margin: 0 0 1rem; }
.resume-card h3 { margin: 0; font-family: var(--display); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--oxblood); }
.resume-card p { margin: .3rem 0 .6rem; font-size: 1rem; }
.resume-actions { display: flex; gap: .45rem; flex-wrap: wrap; }
.resume-actions .btn { flex: 1 1 40%; padding: .6rem .4rem; font-size: .62rem; letter-spacing: .06em; min-height: 44px; }
.confirm { margin-top: .7rem; border-top: 1px dashed var(--rule-strong); padding-top: .55rem; }
.confirm p { margin-top: 0; color: var(--oxblood-deep); }

/* Map frame, pan and zoom. */
.level-sheet + .level-sheet { margin-top: 2.2rem; padding-top: 1.4rem; border-top: 3px double var(--gold); }
.map-frame { position: relative; margin: 0 0 1.2rem; border: 1px solid var(--rule-strong); background: #efe6d4; }
.map-tools { position: absolute; top: .45rem; right: .45rem; display: flex; gap: .3rem; z-index: 2; }
.map-tools button { min-width: 40px; min-height: 40px; font-family: var(--display); font-size: 1rem; color: var(--oxblood-deep); background: rgba(255, 250, 243, .92); border: 1px solid var(--rule-strong); border-radius: 2px; cursor: pointer; }
.map-tools button.wide { font-size: .6rem; letter-spacing: .08em; text-transform: uppercase; padding: 0 .5rem; }
.map-tools button:hover { border-color: var(--oxblood); }
.map-view { height: min(72vh, 760px); min-height: 340px; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.map-view.dragging { cursor: grabbing; }
.map-view svg { display: block; width: 100%; height: 100%; }
.map-legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin: .35rem .2rem 0; font-size: .85rem; color: var(--ink-soft); }
.map-legend span::before { content: ""; display: inline-block; width: .7rem; height: .7rem; margin-right: .3rem; vertical-align: -.05rem; border: 1px solid var(--ink); background: #fff; }
.map-legend .lg-secret::before { content: "S"; font-size: .6rem; line-height: .7rem; text-align: center; color: var(--oxblood); }
.map-legend .lg-lead::before { background: #b8313d; border-color: #b8313d; clip-path: polygon(0 0, 100% 50%, 0 100%); }
.map-legend .lg-door::before { border-radius: 50%; border: 2px solid #b8313d; background: transparent; }
.map-legend .lg-trap::before { content: "T"; font-size: .55rem; line-height: .7rem; text-align: center; color: var(--oxblood); border-radius: 50%; }
.map-legend .lg-wander::before { background: var(--forest); border-radius: 50%; }
.map-legend .lg-water::before { background: #9cc8e8; border-color: #3b78a8; }

.dungeon-map .rock-fill { fill: #efe6d4; }
.dungeon-map .rock-grid { stroke: #e3d7c0; }
.dungeon-map.solo .rock-fill { fill: #3a3129; }
.dungeon-map.solo .rock-grid { stroke: #443a31; }
.dungeon-map .sheet-edge { fill: none; stroke: #b9a585; stroke-width: 1; }
.dungeon-map .walls polygon { fill: #2a2118; stroke: #2a2118; stroke-width: 3; stroke-linejoin: round; }
.dungeon-map.solo .walls polygon { stroke: #120d09; fill: #120d09; }
.dungeon-map .floor { stroke: none; cursor: default; }
.dungeon-map .floor.area { cursor: pointer; }
.dungeon-map .floor.hl { stroke: #c79a3b; stroke-width: 2.2; }
.dungeon-map .door rect { fill: #fffdf8; stroke: #2a2118; stroke-width: .8; }
.dungeon-map .door.false-door rect { fill: #d9cdb8; stroke-dasharray: 1 .8; }
.dungeon-map .wall-line { stroke: #2a2118; stroke-width: 3; }
.dungeon-map .hidden-door .wall-line { stroke: #b8313d; stroke-dasharray: 1.5 1; }
.dungeon-map .secret-s { font: 700 5px var(--serif); text-anchor: middle; fill: #6e2b33; paint-order: stroke; stroke: #fffdf8; stroke-width: 1.2; }
.dungeon-map .oneway { fill: none; stroke: #6e2b33; stroke-width: .9; }
.dungeon-map .room-label { cursor: pointer; }
.dungeon-map .room-label rect { fill: #fffdf8; stroke: #6e2b33; stroke-width: .6; }
.dungeon-map .room-label text { font: 700 5.5px var(--serif); text-anchor: middle; fill: #6e2b33; }
.dungeon-map .room-label.hl rect { fill: #6e2b33; }
.dungeon-map .room-label.hl text { fill: #fffaf3; }
.dungeon-map .water { fill: #9cc8e8; stroke: #3b78a8; stroke-width: .6; }
.dungeon-map .chasm { fill: #2c241d; stroke: #120d09; stroke-width: .6; }
.dungeon-map .ripple { fill: none; stroke: #3b78a8; stroke-width: .4; }
.dungeon-map .bridge { stroke: #8a5a2b; stroke-width: 1.2; }
.dungeon-map .boat { fill: #8a5a2b; }
.dungeon-map .jump { stroke: #fffdf8; stroke-width: .6; stroke-dasharray: 1.5 1.5; }
.dungeon-map .column { fill: #2a2118; }
.dungeon-map .gallery { stroke: #5c4f40; stroke-width: .6; stroke-dasharray: 2 1.5; }
.dungeon-map .stair-tread, .dungeon-map .stairs line { stroke: #2a2118; stroke-width: .6; }
.dungeon-map .mark-tag { font: 600 4.2px var(--serif); fill: #2a2118; paint-order: stroke; stroke: #fffdf8; stroke-width: 1; }
.dungeon-map .trap-mark circle, .dungeon-map .trap-mark rect { fill: #fffdf8; stroke: #6e2b33; stroke-width: .6; }
.dungeon-map .trap-mark path { fill: none; stroke: #6e2b33; stroke-width: .6; }
.dungeon-map .trap-mark .slide { stroke-width: 1.4; stroke-dasharray: 1.4 .8; }
.dungeon-map .trap-mark text { font: 700 4px var(--serif); text-anchor: middle; fill: #6e2b33; }
.dungeon-map .gas { fill: #8fa36b; opacity: .35; pointer-events: none; }
.dungeon-map .well, .dungeon-map .shaft { fill: #fffdf8; stroke: #2a2118; stroke-width: .6; }
.dungeon-map .well-in { fill: #3b78a8; }
.dungeon-map .shaft-x { stroke: #2a2118; stroke-width: .5; }
.dungeon-map .wander-mark circle { fill: #234237; }
.dungeon-map .wander-mark text { font: 700 3.6px var(--serif); fill: #fffaf3; text-anchor: middle; }
.dungeon-map .dressing-mark { fill: #8d7048; }
.dungeon-map .noise-mark { fill: none; stroke: #8d7048; stroke-width: .5; }
.dungeon-map .lead { fill: #b8313d; stroke: #fffdf8; stroke-width: .6; cursor: pointer; }
.dungeon-map .door-lead { fill: rgba(184, 49, 61, .08); stroke: #b8313d; stroke-width: 1.2; }
.dungeon-map .hidden-lead { stroke-dasharray: 1.5 1; opacity: .7; cursor: default; }
.dungeon-map .lead.selected { stroke: #c79a3b; stroke-width: 1.8; }
.dungeon-map.solo .lead:not(.hidden-lead) { animation: lead-pulse 1.8s ease-in-out infinite; }
@keyframes lead-pulse { 50% { opacity: .55; } }
.dungeon-map .party circle { fill: #c79a3b; stroke: #fffaf3; stroke-width: 1; }
.dungeon-map .scale path, .dungeon-map .north path { stroke: #2a2118; fill: #2a2118; stroke-width: .6; }
.dungeon-map .scale text, .dungeon-map .north text { font: 4.5px var(--serif); fill: #2a2118; }
.dungeon-map .north text { text-anchor: middle; }
.dungeon-map.solo .scale path, .dungeon-map.solo .north path { stroke: #e4d2ae; fill: #e4d2ae; }
.dungeon-map.solo .scale text, .dungeon-map.solo .north text { fill: #e4d2ae; }

/* Key. */
.atmosphere, .upper, .room-key, .feature-key, .open-key { margin: 0 0 1.2rem; }
.sheet h3 { font-size: .78rem; margin: 1.2rem 0 .55rem; }
.atmosphere p, .upper p { margin: .3rem 0; }
.muted { color: var(--ink-soft); }
.wander-table { margin: .45rem 0; font-size: .98rem; }
.wander-table summary, .roll-log summary, .stat-card summary { color: var(--forest); cursor: pointer; }
.wander-table ol { margin: .3rem 0 0 1.3rem; padding: 0; }
.key-entry { border: 1px solid var(--rule); background: rgba(255, 252, 247, .65); margin: 0 0 .8rem; padding: 0 .8rem .55rem; scroll-margin-top: 1rem; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.key-entry:hover { border-color: var(--rule-strong); }
.key-entry.hl { border-color: var(--oxblood); box-shadow: 0 0 0 2px rgba(110, 43, 51, .18); }
.key-entry header { display: flex; gap: .65rem; align-items: center; margin: 0 -.8rem .4rem; padding: .5rem .8rem; background: var(--parchment-deep); border-bottom: 1px solid var(--rule); }
.key-num { display: grid; place-items: center; flex: none; width: 2rem; height: 2rem; font-family: var(--display); font-size: .8rem; color: var(--oxblood); border: 1px solid var(--gold); background: #fffaf3; }
.key-entry h4 { margin: 0; font-family: var(--display); font-size: .82rem; letter-spacing: .06em; color: var(--oxblood); }
.key-entry h4 .use { font-family: var(--serif); font-size: 1rem; letter-spacing: 0; color: var(--ink); font-weight: 400; }
.key-entry header p { margin: .1rem 0 0; font-size: .9rem; }
.key-entry > p, .key-monster p { margin: .3rem 0; font-size: 1rem; }
.key-entry .dressing { font-size: .93rem; color: var(--ink-soft); }
.key-monster { border-left: 2px solid var(--gold); padding-left: .55rem; margin: .4rem 0; }
.stat-card { margin: .3rem 0 .45rem; font-size: .95rem; }
.stat-card .encounter-card { margin: .5rem 0 0; cursor: auto; }
.feature-key .party-table { width: 100%; margin: 0; }
.feature-key .party-table th { width: 9.5rem; vertical-align: top; font-size: .58rem; padding-top: .55rem; }
.feature-key .party-table td, .feature-key .party-table th:last-child { text-align: left; }
.feature-key tr[data-mark] { cursor: pointer; }
.roll-log { font-size: .85rem; color: var(--ink-soft); margin-top: 1rem; }
.roll-log ol { margin: .3rem 0 0 1.3rem; padding: 0; max-height: 28rem; overflow: auto; }
.roll-log li { margin: .15rem 0; }

/* Solo panel. */
.solo-panel { margin-bottom: 1rem; }
.solo-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; border-bottom: 1px solid var(--gold-soft); margin-bottom: .6rem; }
.solo-head h2 { margin: 0 0 .4rem; font-family: var(--display); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--oxblood); }
.solo-clock { margin: 0; font-variant-numeric: tabular-nums; color: var(--forest); font-size: 1rem; text-align: right; }
.solo-here { margin: 0 0 .6rem; }
.solo-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .4rem; }
.solo-actions button { text-align: left; min-height: 44px; padding: .45rem .6rem; font-family: var(--serif); font-size: 1rem; color: var(--ink); background: #fffaf3; border: 1px solid var(--rule-strong); border-radius: 2px; cursor: pointer; }
.solo-actions button:hover { border-color: var(--oxblood); background: var(--parchment-deep); }
.solo-actions button.primary { border-color: var(--oxblood); box-shadow: inset 3px 0 0 var(--oxblood); }
.solo-actions button.selected { background: var(--gold-soft); }
.solo-actions .none { color: var(--ink-soft); font-style: italic; margin: 0; }
.solo-tools { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; justify-content: space-between; margin: .8rem 0 0; padding-top: .6rem; border-top: 1px dashed var(--rule); }
.solo-tools .btn { padding: .5rem .7rem; font-size: .6rem; letter-spacing: .06em; min-height: 40px; }
.solo-log { margin-top: .7rem; font-size: .95rem; }
.solo-log summary { color: var(--forest); cursor: pointer; }
.solo-log ol { margin: .4rem 0 0; padding-left: 1.6rem; max-height: 15rem; overflow: auto; }
.solo-log li { margin: .2rem 0; }
.solo-log li .when { color: var(--ink-soft); font-size: .85rem; font-variant-numeric: tabular-nums; margin-right: .35rem; }
.solo-log li.monster { color: var(--oxblood-deep); font-weight: 600; }
.solo-log li.head, .solo-log li.travel { color: var(--forest); font-weight: 600; }
.solo-log li.warn { color: var(--oxblood); }
.solo-log li.find { color: var(--forest); }
.solo-log li.check { color: var(--ink-soft); }

@media (max-width: 860px) {
  .map-view { height: 62vh; }
}
@media (max-width: 580px) {
  .category-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .map-view { height: 58vh; min-height: 300px; }
  .solo-actions { grid-template-columns: 1fr; }
  .feature-key .party-table th { width: 6.5rem; }
  .key-entry { padding: 0 .6rem .5rem; }
  .key-entry header { margin: 0 -.6rem .4rem; padding: .45rem .6rem; }
}
@media (prefers-reduced-motion: reduce) {
  .dungeon-map.solo .lead { animation: none !important; }
}
.sheet .solo-panel { margin: 0 0 1.4rem; box-shadow: none; border-color: var(--rule-strong); background: #fffaf3; }
.other-level > summary { font-family: var(--display); font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--forest); cursor: pointer; }
