/* Fonts are bundled locally (SIL Open Font License, see /fonts/OFL-LICENSE.txt). */
@font-face { font-family: 'Alegreya'; src: url('/fonts/alegreya-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Alegreya'; src: url('/fonts/alegreya-latin-400-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'Alegreya'; src: url('/fonts/alegreya-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Alegreya Sans'; src: url('/fonts/alegreya-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Alegreya Sans'; src: url('/fonts/alegreya-sans-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Alegreya Sans'; src: url('/fonts/alegreya-sans-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }

/* Walnut table, felt dice tray, bone dice, brass for good news, garnet for bad. */
:root {
  --bg: #221a15;
  --panel: #2b221c;
  --panel-2: #352a23;
  --line: #4b3e34;
  --text: #ece3d0;
  --muted: #a89e8e;
  --felt: #173430;
  --felt-2: #1e433d;
  --felt-line: #2e5a53;
  --brass: #c8a04a;
  --brass-ink: #221a15;
  --garnet: #d06470;
  --garnet-fill: #9e2f3b;
  --die: #ece3d0;
  --die-ink: #221a15;
  --focus: #e3c173;
  --serif: 'Alegreya', Georgia, 'Times New Roman', serif;
  --sans: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #e7eae4;
    --panel: #fafbf8;
    --panel-2: #f0f2ed;
    --line: #cdd3ca;
    --text: #1e2521;
    --muted: #5b655e;
    --felt: #cfe1d8;
    --felt-2: #c2d8cd;
    --felt-line: #a3c3b5;
    --brass: #87641a;
    --brass-ink: #fafbf8;
    --garnet: #9e2f3b;
    --garnet-fill: #9e2f3b;
    --die: #fffdf6;
    --die-ink: #1e2521;
    --focus: #87641a;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--sans);
  font-variant-numeric: lining-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; line-height: 1.15; }
h1 { font-size: 36px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
p { margin: 0 0 12px; }
a { color: var(--brass); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brass); border-color: var(--brass); color: var(--brass-ink); }
.btn.danger { color: var(--garnet); }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 14px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: var(--line); }
.link-btn { background: none; border: 0; padding: 0; color: var(--brass); cursor: pointer; text-decoration: underline; }

.field { display: grid; gap: 4px; margin-bottom: 14px; align-content: start; }
.field > span { font-size: 14px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 36px; padding: 6px 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
textarea.input { min-height: 120px; resize: vertical; line-height: 1.5; }
.input.invalid { border-color: var(--garnet); }
.hint { font-size: 14px; color: var(--muted); }
.error-text { color: var(--garnet); font-size: 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brass); }

.segmented { display: inline-flex; border: 1px solid var(--felt-line); border-radius: 6px; overflow: hidden; }
.segmented button {
  border: 0; background: transparent; padding: 4px 10px; min-height: 30px; font-size: 14px; cursor: pointer; color: var(--text);
}
.segmented button + button { border-left: 1px solid var(--felt-line); }
.segmented button[aria-pressed="true"] { background: var(--brass); color: var(--brass-ink); font-weight: 700; }

/* ---------- app layout ---------- */
.app {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 400px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top top" "rail sheet tray";
  height: 100vh; height: 100dvh;
}
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 21px; letter-spacing: .01em; }
.topbar .campaign-select { max-width: 260px; }
.topbar .spacer { flex: 1; }
.topbar a { text-decoration: none; font-weight: 500; }

.rail { grid-area: rail; overflow: auto; padding: 16px; border-right: 1px solid var(--line); }
.rail h2 { font-size: 18px; margin: 18px 0 8px; }
.rail h2:first-child { margin-top: 0; }
.char-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; }
.char-item {
  width: 100%; display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 8px;
  padding: 8px 10px; border: 1px solid transparent; border-radius: 6px; background: none; cursor: pointer; text-align: left;
}
.char-item:hover { background: var(--panel); }
.char-item[aria-current="true"] { background: var(--panel); border-color: var(--line); }
.char-item .name { font-family: var(--serif); font-weight: 700; font-size: 17px; }
.char-item .hp { font-size: 14px; color: var(--muted); }
.char-item .owner { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.char-item .hp.low { color: var(--garnet); }
.rail .empty { color: var(--muted); font-size: 14px; }

.sheet-pane { grid-area: sheet; overflow: auto; padding: 24px 32px 48px; }
.tray { grid-area: tray; display: flex; flex-direction: column; min-height: 0; background: var(--felt); border-left: 1px solid var(--felt-line); }
.tabbar { display: none; }

@media (max-width: 1099px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top" "main" "tabs";
  }
  .rail, .sheet-pane, .tray { grid-area: main; display: none; border: 0; }
  .app[data-tab="party"] .rail { display: block; }
  .app[data-tab="sheet"] .sheet-pane { display: block; }
  .app[data-tab="chat"] .tray { display: flex; }
  .sheet-pane { padding: 16px 16px 40px; }
  .tabbar {
    grid-area: tabs; display: grid; grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--line); background: var(--bg);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .tabbar button { border: 0; background: none; padding: 12px 0; font-weight: 500; cursor: pointer; color: var(--muted); }
  .tabbar button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 3px 0 var(--brass); }
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .topbar .campaign-select { max-width: none; flex: 1; }
}

/* ---------- sheet ---------- */
.sheet { max-width: 760px; }
.sheet-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.sheet-head h1 { flex: 1; min-width: 200px; overflow-wrap: anywhere; }
.sheet-head .meta { width: 100%; color: var(--muted); font-size: 14px; margin-top: -12px; }
.save-state { font-size: 14px; color: var(--muted); min-width: 90px; text-align: right; }
.save-state.error { color: var(--garnet); }
.notice { padding: 10px 12px; border-left: 3px solid var(--brass); background: var(--panel); margin-bottom: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.vitals { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; margin-bottom: 28px; }
.vital { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.vital .caption { font-size: 14px; color: var(--muted); }
.vital .big { font-family: var(--serif); font-weight: 700; font-size: 36px; line-height: 1.1; }
.vital .big .of { font-size: 21px; color: var(--muted); font-weight: 400; }
.vital .temp { font-size: 14px; color: var(--brass); }
.hp-bar { height: 6px; border-radius: 3px; background: var(--panel-2); margin: 10px 0 12px; overflow: hidden; }
.hp-bar > i { display: block; height: 100%; width: var(--pct, 100%); background: var(--brass); }
.hp-bar.low > i { background: var(--garnet-fill); }
.hp-adjust { display: flex; gap: 8px; flex-wrap: wrap; }
.hp-adjust .input { width: 84px; }

.section { margin-bottom: 28px; }
.section > h2 { margin-bottom: 10px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.stat .label { font-size: 14px; color: var(--muted); }
.stat .value { font-family: var(--serif); font-weight: 700; font-size: 21px; overflow-wrap: anywhere; }

.roll-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.roll-btn {
  display: grid; text-align: left; gap: 0;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer;
}
.roll-btn:hover:not(:disabled) { border-color: var(--brass); }
.roll-btn .label { font-weight: 700; }
.roll-btn .expr { font-size: 14px; color: var(--muted); }
.roll-btn:disabled { cursor: default; opacity: .7; }

.inventory { width: 100%; border-collapse: collapse; }
.inventory th { text-align: left; font-weight: 500; font-size: 14px; color: var(--muted); padding: 4px 8px; border-bottom: 1px solid var(--line); }
.inventory td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.inventory td.qty { width: 64px; text-align: right; }
.notes-view { white-space: pre-wrap; overflow-wrap: anywhere; }

.edit-row { display: grid; gap: 8px; align-items: start; margin-bottom: 8px; }
.edit-row.stat-row { grid-template-columns: 1fr 1fr auto; }
.edit-row.item-row { grid-template-columns: 2fr 72px 3fr auto; }
.edit-row.roll-row { grid-template-columns: 1fr; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.roll-row .exprs { display: grid; gap: 6px; }
.roll-row .expr-line { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; }
.roll-row .row-actions { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.vitals-edit { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
@media (max-width: 600px) {
  .vitals { grid-template-columns: 1fr; }
  .vitals-edit { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .edit-row.item-row { grid-template-columns: 1fr 72px auto; }
  .edit-row.item-row .item-notes { grid-column: 1 / -1; grid-row: 2; }
}

.empty-state { max-width: 520px; padding-top: 12vh; }
.empty-state h1 { margin-bottom: 12px; }
.empty-state p { color: var(--muted); }
.empty-state .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* ---------- dice tray ---------- */
.tray-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--felt-line); }
.tray-head h2 { font-size: 18px; }
.log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.log .day { align-self: center; font-size: 13px; color: var(--muted); }
.msg { overflow-wrap: anywhere; }
.msg .who { font-family: var(--serif); font-weight: 700; }
.who .player { font-family: var(--sans); font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 6px; }
.msg time, .card-head time { font-size: 12px; color: var(--muted); margin-left: 8px; white-space: nowrap; }
.msg.emote { font-style: italic; font-family: var(--serif); }
.msg.whisper { border-left: 2px solid var(--brass); padding-left: 10px; }
.msg.whisper .tag, .card .tag { font-size: 13px; color: var(--brass); }
.msg.system { color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.msg.system.error { color: var(--garnet); }

.card { background: var(--felt-2); border: 1px solid var(--felt-line); border-radius: 10px; padding: 10px 12px; }
.card.private { border-style: dashed; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.card-head .title { font-family: var(--serif); font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.card-head .by { text-align: right; font-size: 15px; }
.result { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; padding: 6px 0; }
.result + .result { border-top: 1px solid var(--felt-line); }
.result .formula { grid-column: 1; font-size: 13px; color: var(--muted); }
.result .dice { grid-column: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.result .const { font-weight: 700; color: var(--muted); }
.result .total {
  grid-column: 2; grid-row: 1 / span 3;
  font-family: var(--serif); font-weight: 700; font-size: 34px; line-height: 1; min-width: 48px; text-align: right;
}
.result .sub { grid-column: 1; font-size: 13px; }
.result.crit .total, .result.crit .sub { color: var(--brass); }
.result.fumble .total, .result.fumble .sub { color: var(--garnet); }

/* The dice: each type keeps its silhouette. */
.die {
  --size: 34px;
  display: inline-grid; place-items: center;
  width: var(--size); height: var(--size);
  background: var(--die); color: var(--die-ink);
  font-weight: 700; font-size: 15px; line-height: 1;
  clip-path: circle(50%);
}
.die.d4 { clip-path: polygon(50% 2%, 98% 94%, 2% 94%); padding-top: 10px; font-size: 13px; }
.die.d6 { clip-path: inset(3% round 22%); }
.die.d8 { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); font-size: 14px; }
.die.d10, .die.d100 { clip-path: polygon(50% 0, 100% 44%, 50% 100%, 0 44%); font-size: 13px; padding-bottom: 3px; }
.die.d100 { --size: 38px; }
.die.d12 { clip-path: polygon(50% 0, 98% 36%, 80% 97%, 20% 97%, 2% 36%); padding-top: 3px; }
.die.d20 { clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); }
.die.dropped { background: color-mix(in srgb, var(--die) 22%, transparent); color: var(--text); text-decoration: line-through; opacity: .7; }
.die.nat-max:not(.dropped) { background: var(--brass); color: var(--brass-ink); }
.die.nat-one:not(.dropped) { background: var(--garnet-fill); color: #f6ece0; }
.die.adjusted { box-shadow: inset 0 0 0 2px var(--brass); }

@media (prefers-reduced-motion: no-preference) {
  .card.fresh .die { animation: settle .32s cubic-bezier(.2, .9, .3, 1.2) both; }
  .card.fresh .die:nth-child(2) { animation-delay: .04s; }
  .card.fresh .die:nth-child(3) { animation-delay: .08s; }
  .card.fresh .die:nth-child(n+4) { animation-delay: .12s; }
  @keyframes settle {
    from { transform: rotate(-70deg) scale(.6); opacity: 0; }
    to { transform: none; opacity: 1; }
  }
}

.tray-controls { border-top: 1px solid var(--felt-line); padding: 10px 14px 12px; display: grid; gap: 8px; }
.quick-dice { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.quick-dice .die-btn {
  border: 0; padding: 0; background: none; cursor: pointer; display: inline-grid; place-items: center;
}
.quick-dice .die-btn .die { --size: 36px; font-size: 12px; }
.quick-dice .die-btn:hover .die { background: var(--brass); color: var(--brass-ink); }
.quick-dice .die-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.tray-options { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 14px; }
.tray-options select { min-height: 30px; padding: 2px 8px; font-size: 14px; background: var(--felt-2); border-color: var(--felt-line); }
.compose { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.tray .compose .input { background: var(--felt-2); border-color: var(--felt-line); }

/* ---------- dialogs ---------- */
dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  padding: 24px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .55); }
dialog h2 { margin-bottom: 16px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
dialog .actions .left { margin-right: auto; }
.member-list { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 6px; }
.member-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel-2); border-radius: 6px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* ---------- sign-in ---------- */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(380px, 100%); }
.login-box h1 { font-size: 48px; margin-bottom: 4px; }
.login-box .lede { color: var(--muted); margin-bottom: 28px; }

/* ---------- fairness page ---------- */
.stats-page { max-width: 1100px; margin: 0 auto; padding: 24px 24px 64px; }
.stats-page header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.stats-page .intro { max-width: 68ch; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 20px 0 24px; }
.filters .field { margin: 0; min-width: 200px; }
.die-panels { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.die-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.die-panel.wide { grid-column: 1 / -1; }
.die-panel .top { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.die-panel .top .die { --size: 40px; }
.die-panel .count { color: var(--muted); font-size: 14px; }
.verdict { font-size: 14px; margin: 8px 0 0; }
.verdict.unusual { color: var(--garnet); font-weight: 700; }
.verdict.borderline { color: var(--brass); }
.verdict.waiting { color: var(--muted); }
.figures { font-size: 13px; color: var(--muted); margin-top: 4px; }
.bars { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 4px; border-bottom: 1px solid var(--line); }
.bars .bar { flex: 1; min-width: 1px; height: var(--h, 0%); background: var(--brass); opacity: .85; border-radius: 2px 2px 0 0; }
.bars .expected { position: absolute; left: 0; right: 0; bottom: var(--h, 0%); border-top: 1px dashed var(--text); opacity: .6; }
.bar-labels { display: flex; gap: 2px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bar-labels span { flex: 1; text-align: center; min-width: 1px; }
.selftest { margin-top: 36px; }

/* Roll result toast on phones, when the chat tab isn't showing. */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 10px;
  background: var(--felt-2); border: 1px solid var(--felt-line); color: var(--text);
  font-family: var(--serif); font-weight: 700; font-size: 18px;
  cursor: pointer; z-index: 20;
}
.login-box .btn.primary { width: 100%; min-height: 44px; font-size: 17px; }
.login-foot { margin-top: 20px; }

/* ---------- 5e sheet ---------- */
.sheet-dnd5e { max-width: 860px; }
.notice.soft { font-size: 15px; }
.common-fields { display: grid; grid-template-columns: 2fr 1fr; gap: 0 16px; }

.vitals5 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.5fr); gap: 12px; margin-bottom: 20px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.vital.tile { padding: 10px 12px; display: grid; align-content: start; text-align: left; font: inherit; color: inherit; }
.vital.tile .big { font-size: 28px; }
.roll-tile { cursor: pointer; }
.roll-tile:hover:not(:disabled) { border-color: var(--brass); }
.tile.inspiration { cursor: pointer; }
.tile.inspiration[aria-pressed="true"] { border-color: var(--brass); }
.tile.inspiration[aria-pressed="true"] .big { color: var(--brass); }
.tile:disabled { cursor: default; }
.hp-card .hit-dice { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 14px; }
.hp-card .hd { display: inline-flex; align-items: center; gap: 8px; }
.hp-card .rests { display: flex; gap: 8px; margin-top: 10px; }
.death-saves { display: grid; gap: 6px; margin-top: 12px; padding: 10px; border-radius: 8px; background: var(--panel-2); }
.death-saves .btn { justify-self: start; }

.pips { display: inline-flex; flex-wrap: wrap; gap: 5px; vertical-align: middle; }
.pip {
  width: 18px; height: 18px; padding: 0; border-radius: 50%;
  border: 2px solid var(--brass); background: var(--brass); cursor: pointer;
}
.pip.used { background: transparent; border-color: var(--line); }
.pip:disabled { cursor: default; }

.status-row { display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: center; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.exhaustion { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.exhaustion .caption, .death-saves .caption { font-size: 14px; color: var(--muted); }
.ex-level { font-family: var(--serif); font-size: 21px; min-width: 14px; text-align: center; }
.ex-effects { font-size: 14px; color: var(--garnet); }
.conditions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--garnet); font-size: 14px; }
.chip-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; }
.add-condition { width: auto; min-height: 30px; padding: 2px 8px; font-size: 14px; }

.abilities { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.ability { display: grid; gap: 4px; }
.ability-check {
  display: grid; justify-items: center; gap: 0; padding: 8px 4px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; color: inherit;
}
.ability-check:hover:not(:disabled), .save-btn:hover:not(:disabled), .skill:hover:not(:disabled), .attack-btn:hover:not(:disabled) { border-color: var(--brass); }
.ability-check .abbr { font-size: 13px; color: var(--muted); }
.ability-check .mod { font-family: var(--serif); font-weight: 700; font-size: 30px; line-height: 1.1; }
.ability-check .score { font-size: 14px; padding: 0 8px; border-radius: 999px; background: var(--panel-2); }
.save-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 4px 6px;
  background: none; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; cursor: pointer; color: inherit;
}
.prof-mark { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--muted); flex: none; }
.prof-mark.on { background: var(--brass); border-color: var(--brass); }
.prof-mark.expert { background: var(--brass); border-color: var(--brass); box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px var(--brass); }
.ability-check:disabled, .save-btn:disabled, .skill:disabled, .attack-btn:disabled { cursor: default; }

.skills { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; }
.skill {
  display: grid; grid-template-columns: auto 1fr auto 44px; align-items: center; gap: 8px;
  padding: 6px 10px; background: none; border: 1px solid transparent; border-bottom-color: var(--line); border-radius: 6px 6px 0 0;
  text-align: left; cursor: pointer; color: inherit;
}
.skill .abil { font-size: 13px; color: var(--muted); }
.skill .bonus { font-weight: 700; text-align: right; }

.attack-list { display: grid; gap: 8px; }
.attack-btn {
  width: 100%; display: grid; grid-template-columns: 1fr auto minmax(120px, auto); gap: 12px; align-items: baseline;
  padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; text-align: left; cursor: pointer; color: inherit;
}
.attack-btn .name { font-family: var(--serif); font-weight: 700; font-size: 18px; }
.attack-btn .hit { font-weight: 700; }
.attack-btn .dmg { color: var(--muted); text-align: right; }
.attack .mastery, .attack > .hint { font-size: 14px; padding: 4px 14px 0; }
.attack .mastery { color: var(--muted); }
.attack .mastery strong { color: var(--text); }
.grapple { margin-top: 10px; }

.spell-stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 12px; }
.spell-stat { display: inline-flex; align-items: center; gap: 12px; }
.slots { display: grid; gap: 6px; margin-bottom: 14px; }
.slot-row { display: flex; align-items: center; gap: 12px; }
.slot-label { min-width: 150px; font-size: 14px; color: var(--muted); }
.spell-level h3 { margin: 14px 0 6px; }
.spell-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.spell { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.spell.unprepared .name { color: var(--muted); }
.spell-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spell-main .name { font-weight: 700; }
.spell-main .cast { margin-left: auto; }

.resources { display: grid; gap: 8px; }
.resource { display: grid; grid-template-columns: minmax(120px, 1fr) auto minmax(110px, auto); align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.resource .name { font-weight: 700; }
.resource .hint { text-align: right; }
.counter { display: inline-flex; align-items: center; gap: 8px; }

.details-list { display: grid; gap: 6px; }
.detail { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.detail summary { cursor: pointer; font-weight: 700; }
.detail .notes-view { margin-top: 6px; }
.effects { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.prof-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; }
.prof-list dt { color: var(--muted); }
.prof-list dd { margin: 0; }
.currency { font-weight: 700; }

/* 5e edit form */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.edit-row.class-row { grid-template-columns: 2fr 2fr 90px auto; align-items: start; }
.edit-row.class-row > .btn { margin-top: 28px; }
.edit-row .full { grid-column: 1 / -1; margin: 0; }
.edit-row .field { margin-bottom: 8px; }
.hp-settings { margin-top: 16px; }
.hp-rolls { display: grid; gap: 8px; }
.roll-inputs { display: flex; flex-wrap: wrap; gap: 6px; }
.small-num { width: 64px; }
.ability-table { border-collapse: collapse; width: 100%; max-width: 560px; }
.ability-table th, .ability-table td { padding: 4px 8px; text-align: left; }
.ability-table thead th { font-weight: 500; font-size: 14px; color: var(--muted); }
.ability-table .input { width: 90px; }
.ability-table .total { font-family: var(--serif); font-size: 21px; }
.section h3 { margin: 14px 0 8px; }
.check-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 16px; }
.skill-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; margin-bottom: 14px; }
.skill-edit { display: grid; grid-template-columns: 1fr 150px; align-items: center; gap: 8px; font-size: 15px; }
.skill-edit .input { min-height: 30px; padding: 2px 6px; font-size: 14px; }
.edit-row.attack-edit, .edit-row.spell-edit, .edit-row.text-block-edit { grid-template-columns: 1fr; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.edit-row .row-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.edit-row.resource-edit { grid-template-columns: 1.5fr 1fr 1.2fr auto; align-items: end; }
.edit-row.effect-edit { grid-template-columns: 1.5fr 1.5fr 90px auto auto; align-items: end; }
.edit-row.effect-edit .check { margin-bottom: 16px; }
.currency-edit { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0 10px; max-width: 520px; }

@media (max-width: 760px) {
  .vitals5 { grid-template-columns: 1fr; }
  .abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .skills { grid-template-columns: 1fr; }
  .grid-3, .grid-2, .common-fields { grid-template-columns: 1fr; }
  .edit-row.class-row, .edit-row.resource-edit, .edit-row.effect-edit { grid-template-columns: 1fr 1fr; }
  .skill-grid, .check-grid { grid-template-columns: 1fr; }
  .attack-btn { grid-template-columns: 1fr auto; }
  .attack-btn .dmg { grid-column: 1 / -1; text-align: left; }
  .resource { grid-template-columns: 1fr auto; }
  .resource .hint { grid-column: 1 / -1; text-align: left; }
  .currency-edit { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .tiles { gap: 8px; }
  .vital.tile { padding: 8px 10px; }
  .vital.tile .caption { font-size: 13px; line-height: 1.25; }
  .vital.tile .big { font-size: 22px; }
}

/* Crit damage on roll cards */
.result.crit-damage .total { color: var(--brass); }

/* ---------- compendium ---------- */
.sheet-pane.cmp-mode { padding: 0; overflow: hidden; }
#compendium-host { height: 100%; }
.compendium { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); height: 100%; }
.cmp-list-pane { overflow-y: auto; padding: 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.cmp-detail-pane { overflow-y: auto; padding: 24px 32px 48px; }
.cmp-search { min-height: 40px; font-size: 17px; }
.cmp-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
.cmp-filters .field { margin-bottom: 6px; }
.cmp-filters .field span { font-size: 13px; }
.cmp-filters .input { min-height: 32px; padding: 3px 8px; font-size: 14px; }
.cmp-list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cmp-count { margin: 0; }
.cmp-results { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.cmp-result {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 0 8px; align-items: baseline;
  padding: 7px 10px; border: 1px solid transparent; border-radius: 6px; background: none; text-align: left; cursor: pointer; color: inherit;
}
.cmp-result:hover { background: var(--panel); }
.cmp-result[aria-current="true"] { background: var(--panel); border-color: var(--line); }
.cmp-result .name { font-weight: 700; }
.cmp-result .sub { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.badge { font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ed-2024 { color: var(--brass); border-color: var(--brass); }
.badge.ed-hb { color: var(--garnet); border-color: var(--garnet); }
.cmp-back { display: none; margin-bottom: 8px; }
.cmp-entry { max-width: 760px; }
.cmp-entry-head h2 { font-size: 36px; }
.cmp-entry-head .subtitle { font-family: var(--serif); font-style: italic; font-size: 18px; color: var(--muted); margin: 4px 0 6px; }
.badges { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cmp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 20px; }
.cmp-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 16px; }
.cmp-facts dt { color: var(--muted); }
.cmp-facts dd { margin: 0; }
.rules-text { max-width: 70ch; font-family: var(--serif); font-size: 17px; line-height: 1.55; }
.rules-text p { margin: 0 0 10px; }
.rules-text ul { margin: 0 0 10px; padding-left: 22px; }
.table-wrap { overflow-x: auto; margin: 0 0 12px; }
.rules-table { border-collapse: collapse; font-family: var(--sans); font-size: 15px; }
.rules-table th, .rules-table td { padding: 4px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.cmp-empty { max-width: 560px; padding-top: 8vh; }
.cmp-empty h2 { font-size: 36px; margin-bottom: 12px; }
.attribution { margin-top: 32px; font-size: 13px; }
.cmp-editor { max-width: 760px; }
.cmp-editor h2 { margin-bottom: 6px; }

/* stat blocks */
.statblock { display: grid; gap: 14px; }
.sb-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.sb-top .cmp-facts { margin: 0; }
.sb-quick, .sb-rolls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sb-abilities { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; max-width: 620px; }
.sb-ability { display: grid; gap: 4px; }
.sb-check {
  display: grid; justify-items: center; padding: 6px 2px; cursor: pointer; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.sb-check .abbr { font-size: 12px; color: var(--muted); }
.sb-check .score { font-family: var(--serif); font-weight: 700; font-size: 21px; line-height: 1.1; }
.sb-check .mod { font-size: 13px; }
.sb-save { font-size: 13px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; color: inherit; }
.sb-check:hover, .sb-save:hover { border-color: var(--brass); }
.sb-section h3 { font-size: 21px; border-bottom: 1px solid var(--brass); padding-bottom: 4px; margin-bottom: 10px; }
.sb-action { margin-bottom: 12px; }
.sb-action .rules-text p:last-child { margin-bottom: 4px; }
.roll-inline { font-size: 13px; }

/* compendium cards in chat */
.entry-card .entry-sub { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 15px; margin-top: -4px; }
.entry-card .entry-stats { font-size: 14px; margin: 6px 0; }
.entry-card .rules-text { font-size: 15px; }
.entry-card details summary { cursor: pointer; font-size: 14px; color: var(--brass); margin: 4px 0; }
.entry-card .open-entry { font-size: 13px; margin-top: 4px; }

@media (max-width: 1099px) {
  .compendium { grid-template-columns: 1fr; }
  .compendium[data-mode="list"] .cmp-detail-pane { display: none; }
  .compendium[data-mode="detail"] .cmp-list-pane { display: none; }
  .cmp-list-pane { border-right: 0; }
  .cmp-detail-pane { padding: 16px 16px 40px; }
  .cmp-back { display: inline-flex; }
  #compendium-btn { display: none; }
  .sb-abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cmp-entry-head h2 { font-size: 30px; }
}

/* ---------- roll visibility and reveal ---------- */
.reveal-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.reveal { font-size: 13px; }
.tag.revealed { color: var(--muted); font-size: 13px; }

/* ---------- encounter ---------- */
#encounter-host { max-width: 900px; }
.enc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px 20px; flex-wrap: wrap; margin-bottom: 12px; }
.enc-top h2 { font-size: 36px; }
.enc-visibility { max-width: 320px; }
.enc-add { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; }
.enc-add > .input { flex: 1; min-width: 220px; min-height: 40px; }
.count-field { margin: 0; width: 90px; }
.enc-add .check { min-height: 36px; }
.enc-results { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; max-width: 560px; }
.enc-result {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: 6px 10px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; color: inherit;
}
.enc-result:hover { border-color: var(--brass); }
.enc-result .name { font-weight: 700; }
.enc-result .sub { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.enc-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.enc-list { display: grid; gap: 10px; }
.enc-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.enc-card.down { opacity: .55; }
.enc-card.down:focus-within { opacity: 1; }
.enc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.enc-init { display: inline-flex; align-items: center; gap: 2px; }
.enc-init .input { width: 64px; text-align: center; font-family: var(--serif); font-weight: 700; font-size: 20px; }
.enc-name { flex: 1; min-width: 140px; font-family: var(--serif); font-weight: 700; font-size: 20px; background: transparent; border-color: transparent; }
.enc-name:hover, .enc-name:focus { border-color: var(--line); background: var(--bg); }
.enc-ac { display: inline-grid; justify-items: center; padding: 0 8px; }
.enc-ac .caption { font-size: 12px; color: var(--muted); line-height: 1; }
.enc-ac strong { font-family: var(--serif); font-size: 20px; line-height: 1.1; }
.enc-hp { display: grid; grid-template-columns: auto minmax(80px, 1fr) auto; align-items: center; gap: 12px; }
.enc-hp .hp-bar { margin: 0; }
.enc-hp-text .big { font-family: var(--serif); font-size: 24px; }
.enc-hp-text .of { color: var(--muted); }
.enc-hp-text .temp { color: var(--brass); font-size: 14px; }
.enc-hp-text .state { font-size: 14px; color: var(--garnet); font-weight: 700; }
.enc-hp .amount { width: 76px; }
.enc-notes { flex: 1; min-width: 160px; min-height: 30px; padding: 2px 8px; font-size: 14px; }
.enc-card .statblock { border-top: 1px solid var(--line); padding-top: 10px; }
.encounter-add { display: inline-flex; align-items: center; gap: 6px; }
.encounter-add .count { width: 64px; min-height: 30px; padding: 2px 6px; }
.small-check { font-size: 14px; }
.ability-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0 8px; }
.ability-row .field span { text-align: center; }
@media (max-width: 760px) {
  .enc-hp { grid-template-columns: auto 1fr; }
  .enc-hp .hp-adjust { grid-column: 1 / -1; }
  .ability-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.conditions select.add-condition { width: auto; flex: none; }
.account-links { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 4px 0 16px; }
@media (max-width: 1099px) {
  #new-campaign, .topbar a[href="/stats.html"] { display: none; }
  .brand { font-size: 19px; }
}
@media (max-width: 1099px) {
  .topbar .campaign-select { flex: 1 1 180px; min-width: 180px; }
}

/* ---------- character builder ---------- */
#builder-host { max-width: 900px; }
.b-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.b-head h1 { margin-bottom: 4px; }
.b-steps { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.b-steps button {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border: 0; background: none; cursor: pointer; color: var(--muted);
  border-bottom: 3px solid transparent; font-weight: 500;
}
.b-steps button[aria-current="step"] { color: var(--text); border-bottom-color: var(--brass); }
.b-steps .num { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1px solid currentColor; font-size: 12px; }
.b-steps .todo { color: var(--garnet); }
.b-body h2 { margin-bottom: 12px; }
.b-body h3 { margin: 16px 0 8px; }
.b-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.b-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-bottom: 18px; }
.b-card {
  display: grid; gap: 2px; text-align: left; padding: 10px 12px; cursor: pointer; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.b-card:hover { border-color: var(--muted); }
.b-card[aria-pressed="true"] { border-color: var(--brass); box-shadow: inset 0 0 0 1px var(--brass); }
.b-card .name { font-family: var(--serif); font-weight: 700; font-size: 18px; }
.b-card .sub { font-size: 13px; color: var(--muted); }
.b-options { display: grid; gap: 6px; }
.b-option { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.b-option input { margin-top: 5px; accent-color: var(--brass); }
.b-option .rules-text { font-size: 15px; }
.b-row { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-bottom: 10px; }
.b-trait { border-bottom: 1px solid var(--line); padding: 8px 0; }
.rules-text.compact { font-size: 15px; }
.rules-text.compact p { margin-bottom: 6px; }
.b-equip { margin-bottom: 14px; }
.b-picks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.b-picks .input { width: auto; min-width: 200px; }
.b-spells { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 16px; }
.b-spell { display: grid; grid-template-columns: auto 1fr; gap: 0 8px; align-items: baseline; }
.b-spell .hint { grid-column: 2; font-size: 12px; }
.b-methods { margin-bottom: 12px; }
.b-methods button { color: var(--text); }
.b-abilities .pb { display: inline-flex; align-items: center; gap: 8px; }
.b-abilities .pb strong { min-width: 22px; text-align: center; font-size: 18px; }
.b-abilities select.input { width: 90px; }
.b-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.notice ul { margin: 6px 0; padding-left: 20px; }
.sheet-tools { display: flex; justify-content: flex-end; gap: 8px; margin: -8px 0 12px; }

/* ---------- level up ---------- */
dialog:has(.levelup) { width: min(720px, calc(100vw - 32px)); }
.levelup .section { margin-bottom: 18px; }
.levelup-spells { max-height: 260px; overflow-y: auto; padding: 4px; border: 1px solid var(--line); border-radius: 8px; }
@media (max-width: 600px) {
  .b-cards { grid-template-columns: 1fr 1fr; }
  .b-steps button { padding: 6px 6px; font-size: 14px; }
}

/* ---------- D&D 3.5 sheet ---------- */
.sheet-dnd35 { max-width: 880px; }
.sheet-dnd35 .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.hp-state { font-weight: 700; color: var(--garnet); margin-top: 2px; }
.temp.nonlethal { color: var(--muted); }
.saves35 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.save35 {
  display: grid; justify-items: start; gap: 0; padding: 8px 12px; text-align: left; cursor: pointer; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.save35 .name { font-size: 14px; color: var(--muted); }
.save35 .big { font-family: var(--serif); font-weight: 700; font-size: 26px; line-height: 1.1; }
.save35:hover:not(:disabled) { border-color: var(--brass); }
.attack35 { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: grid; gap: 6px; }
.attack35-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; }
.attack35-main .name { font-family: var(--serif); font-weight: 700; font-size: 18px; }
.attack35-main .hit { font-weight: 700; }
.attack35-main .dmg { color: var(--muted); }
.attack35-buttons { display: flex; gap: 8px; }
.skills35 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 16px; }
.skill35 { grid-template-columns: auto 1fr auto 44px 44px; }
.skill35 .ranks { font-size: 12px; color: var(--muted); text-align: right; }
.skill35 .flag { color: var(--muted); margin-left: 2px; }
.caster35 { margin-bottom: 16px; }
.caster35 h3 { margin: 6px 0 2px; }
.skill-budget { font-weight: 500; }
.skill-table td, .skill-table th { padding: 4px 8px; }
.skill-table .small-num { width: 70px; }
.empty-state.inline { padding-top: 12px; max-width: 560px; }
.empty-state.inline .btn { margin: 8px 0; }
.result.confirm .total { color: var(--text); }
.levelup-gains { margin: 0; padding-left: 20px; }
@media (max-width: 760px) {
  .sheet-dnd35 .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .skills35 { grid-template-columns: 1fr; }
  .saves35 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.tile .big.word { font-size: 20px; line-height: 1.4; }

/* ---------- manuals ---------- */
#manuals-host { max-width: 960px; }
.man-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 16px; }
.man-head h1 { margin-bottom: 4px; }
.man-head h1 .badge { font-size: 14px; vertical-align: middle; }
.man-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.man-card {
  display: grid; gap: 4px; text-align: left; padding: 14px 16px; cursor: pointer; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.man-card:hover { border-color: var(--brass); }
.man-title { display: flex; align-items: center; gap: 8px; }
.man-title .name { font-family: var(--serif); font-weight: 700; font-size: 20px; }
.man-card .sub { font-size: 14px; color: var(--muted); }
.man-form { max-width: 640px; }
.man-edition { border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px 4px; margin: 0 0 14px; display: grid; gap: 4px; }
.man-edition legend { padding: 0 4px; font-weight: 600; }
.man-crumbs { margin-bottom: 8px; }
.man-sections { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.man-sections button {
  padding: 8px 10px; border: 0; background: none; cursor: pointer; color: var(--muted); font-weight: 500;
  border-bottom: 3px solid transparent; display: inline-flex; align-items: center; gap: 6px;
}
.man-sections button[aria-current="page"] { color: var(--text); border-bottom-color: var(--brass); }
.man-sections .count { font-size: 12px; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--line); color: var(--text); text-align: center; }
.man-section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.man-entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.man-entries li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.man-entries .name { font-weight: 700; margin-right: 8px; }
.man-entries .sub { font-size: 14px; color: var(--muted); }
.man-row-actions { display: inline-flex; gap: 6px; flex: none; }
.custom-class { border-left: 3px solid var(--line); padding-left: 10px; margin-top: 4px; }
.b-card .badge { margin-left: 6px; font-size: 11px; vertical-align: middle; }
.cmp-editor .text-block-edit textarea { min-height: 64px; }

/* ---------- automation ---------- */
.auto-editor { border-top: 1px solid var(--line); padding-top: 12px; }
.auto-block { margin: 14px 0 18px; }
.auto-block h4 { margin: 0 0 2px; font-size: 17px; }
.auto-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; display: grid; gap: 4px; }
.auto-line { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 10px; }
.auto-row { margin: 4px 0; }
.auto-lead { font-size: 13px; color: var(--muted); min-width: 64px; padding-bottom: 8px; }
.auto-nested { margin-left: 28px; padding-left: 10px; border-left: 2px solid var(--line); }
.auto-actions, .auto-conds { display: grid; gap: 4px; }
label.mini { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
label.mini .input { min-height: 32px; padding: 3px 8px; font-size: 15px; color: var(--text); }
.auto-describe { margin: 4px 0 0; padding-left: 20px; }
.auto-describe li { margin: 2px 0; }
.automation .combat-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.combat-bar .sep { flex: 1; }
.auto-notes { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.auto-notes li { padding: 6px 12px; border-left: 3px solid var(--brass); background: var(--panel); border-radius: 0 8px 8px 0; }
.auto-cards { display: grid; gap: 8px; margin-top: 10px; }
.auto-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.auto-states, .auto-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.state-chip { cursor: pointer; }
.state-chip.on { border-color: var(--brass); color: var(--brass); font-weight: 700; }
.counter-chip strong { margin: 0 4px; }
.auto-summary ul { padding-left: 20px; }
.auto-edit-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- 5e sheet layout (Roll20-style arrangement) ---------- */
.sheet-dnd5e { max-width: 1320px; container-type: inline-size; }
/* The character card shows the name, so the frame's own title and meta line step aside in this view. */
.sheet-dnd5e:has(> .s5) > .sheet-head h1,
.sheet-dnd5e:has(> .s5) > .sheet-head .meta { display: none; }
.sheet-dnd5e:has(> .s5) > .sheet-head { justify-content: flex-end; margin-bottom: 8px; }
.s5 { display: grid; gap: 12px; }
.s5-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.s5-title { font-family: var(--sans); font-size: 15px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brass); margin: 0 0 10px; }
.s5-top, .s5-mid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.s5-body { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "left" "right"; align-items: start; }
.s5-left { grid-area: left; display: grid; gap: 12px; }
.s5-main { grid-area: main; }
.s5-right { grid-area: right; display: grid; gap: 12px; }
@container (min-width: 700px) {
  .s5-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .s5-mid { grid-template-columns: minmax(0, 1fr) 200px; }
  .s5-body { grid-template-columns: 240px minmax(0, 1fr); grid-template-areas: "left main" "right main"; }
}
@container (min-width: 1100px) {
  .s5-body { grid-template-columns: 240px minmax(0, 1fr) 220px; grid-template-areas: "left main right"; }
}

/* character card */
.s5-identity { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 10px 14px; align-content: start; }
.s5-badge { width: 54px; height: 54px; margin: 10px; background: var(--garnet-fill); border: 2px solid var(--garnet); transform: rotate(45deg); display: grid; place-items: center; border-radius: 6px; }
.s5-badge span { transform: rotate(-45deg); color: #fff; font-family: var(--serif); font-weight: 700; font-size: 24px; }
.s5-name { font-size: 26px; line-height: 1.1; margin: 0 0 4px; color: var(--brass); }
.s5-line { font-size: 15px; line-height: 1.45; }
.s5-line.dim { color: var(--muted); font-size: 14px; }
.s5-owner { font-size: 13px; }
.s5-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.s5-initiative { margin-left: auto; font-size: 16px; padding: 8px 18px; }
.s5-inspiration[aria-pressed="true"] { border-color: var(--brass); color: var(--brass); font-weight: 700; }
.s5-due { grid-column: 1 / -1; margin: 0; }
.s5-tag { display: inline-block; font-size: 11px; font-weight: 700; line-height: 1.5; padding: 0 5px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }

/* hit points */
.s5-hp-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: stretch; }
.s5-hp-box { border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px 4px; min-width: 160px; background: var(--bg); }
.s5-hp-nums { display: flex; align-items: baseline; justify-content: space-around; gap: 10px; font-family: var(--serif); }
.s5-hp-cur, .s5-hp-max { font-size: 30px; font-weight: 700; }
.s5-hp-sep { color: var(--muted); font-size: 22px; }
.s5-hp-box .hp-bar { margin: 2px 0 4px; }
.s5-hp-labels { display: flex; justify-content: space-around; font-size: 12px; color: var(--muted); }
.s5-temp { display: grid; justify-items: center; align-content: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; background: var(--bg); }
.s5-temp-val { font-family: var(--serif); font-size: 24px; font-weight: 700; }
.s5-hp-adjust { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.s5-amount { width: 64px; text-align: center; }
.s5-dmg { border-color: var(--garnet); }
.s5-heal { border-color: #4f8f5b; }
.s5-rests { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; align-items: center; }
@container (min-width: 700px) { .s5-rests { flex-direction: column; align-items: stretch; } }
.s5-hitdice { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.s5-hd { display: inline-flex; align-items: center; gap: 6px; }

/* abilities and AC */
.s5-ability-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.s5-ability { display: grid; justify-items: center; gap: 5px; padding: 0 4px; border-right: 1px solid var(--line); }
.s5-ability:last-child { border-right: 0; }
.s5-ability-head { display: flex; align-items: center; gap: 6px; font-size: 15px; }
.s5-score { border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; font-size: 13px; background: var(--bg); }
.s5-ability-rolls { display: flex; gap: 6px; }
.s5-mod, .s5-save {
  min-width: 42px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-weight: 700; font-size: 16px; cursor: pointer; font-family: var(--sans);
}
.s5-save.on { border-color: var(--garnet); background: color-mix(in srgb, var(--garnet-fill) 45%, var(--bg)); }
.s5-mod:hover:not(:disabled), .s5-save:hover:not(:disabled) { border-color: var(--brass); }
.s5-ability-labels { display: flex; gap: 6px; font-size: 11px; color: var(--muted); }
.s5-ability-labels span { min-width: 42px; text-align: center; }
/* Six abilities with two buttons each need about 100px apiece; below that, two rows of three. */
@container (max-width: 880px) {
  .s5-ability-row { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 14px; }
  .s5-ability:nth-child(3) { border-right: 0; }
}
.s5-ac-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0; font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: .03em; }
.s5-shield {
  display: grid; place-items: center; width: 46px; height: 50px; font-size: 21px; font-weight: 700; font-family: var(--serif);
  border: 2px solid var(--muted); border-radius: 8px 8px 24px 24px; background: var(--bg);
}
.s5-box { display: inline-grid; place-items: center; min-width: 40px; height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; font-weight: 700; background: var(--bg); }
.s5-box.wide { min-width: 76px; }

/* left column */
.s5-skill-list { display: grid; }
.s5-skill {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 38px 14px; align-items: center; gap: 6px; padding: 6px 4px;
  background: none; border: 0; border-bottom: 1px solid var(--line); color: inherit; text-align: left; cursor: pointer; font: inherit; font-size: 14px;
}
.s5-skill:last-child { border-bottom: 0; }
.s5-skill:hover:not(:disabled) { background: var(--bg); }
.s5-skill .name { font-weight: 600; }
.s5-bonus { text-align: center; font-weight: 700; border-radius: 5px; padding: 2px 0; background: var(--bg); }
.s5-bonus.on { background: color-mix(in srgb, var(--garnet-fill) 55%, var(--bg)); }
.s5-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--muted); }
.s5-dot.on { background: var(--garnet); border-color: var(--garnet); }
.s5-dot.expert { background: var(--brass); border-color: var(--brass); box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--brass); }
.s5-plain { list-style: none; margin: 0; padding: 0; }
.s5-plain li { padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; font-weight: 600; }
.s5-plain li:last-child { border-bottom: 0; }
.s5-chip-group { margin-bottom: 8px; }
.s5-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; min-height: 30px; align-items: center; }
.s5-chip { font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); }

/* right column */
.s5-resource { margin-bottom: 10px; }
.s5-stepper { display: inline-flex; align-items: center; gap: 4px; margin-top: 3px; }
.s5-right .add-condition { width: 100%; margin-top: 6px; }
.s5-exhaustion { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.s5-ex { margin: 6px 0 0; }
.s5-sense { display: grid; grid-template-columns: minmax(0, 1fr) auto 30px; gap: 6px; align-items: center; padding: 4px 0; font-size: 14px; }
.s5-sense strong { text-align: right; }

/* middle: tabs and tables */
.s5-tabs { display: flex; flex-wrap: wrap; gap: 2px 16px; border-bottom: 1px solid var(--line); margin: -4px 0 12px; }
.s5-tabs button {
  background: none; border: 0; padding: 8px 2px 6px; font-family: var(--sans); font-weight: 700; font-size: 14px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer;
}
.s5-tabs button[aria-selected="true"] { color: var(--brass); border-bottom-color: var(--brass); }
.s5-panel { display: grid; gap: 16px; }
.s5-panel[hidden] { display: none; }
.s5-table { display: grid; }
.s5-thead, .s5-row { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1.1fr); gap: 8px; align-items: center; }
.s5-thead { padding: 6px 8px; background: var(--bg); border-radius: 6px; font-size: 13px; color: var(--muted); }
.s5-thead > span:first-child { color: var(--brass); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.s5-row { padding: 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.s5-row.dim { opacity: .6; }
.s5-thead.two, .s5-row.two, details.s5-row.two > summary { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); }
.s5-row-extra { grid-column: 1 / -1; display: grid; gap: 2px; }
.s5-sub { font-size: 12px; color: var(--muted); }
.s5-hit, .s5-dmg-btn {
  background: none; border: 1px solid transparent; border-radius: 6px; padding: 3px 6px; font: inherit; font-weight: 700; cursor: pointer; color: var(--text); text-align: left;
}
.s5-dmg-btn { color: var(--garnet); }
.s5-hit:hover:not(:disabled), .s5-dmg-btn:hover:not(:disabled) { border-color: var(--line); background: var(--bg); }
.s5-dc { font-weight: 700; }
details.s5-row { display: block; padding: 0; }
details.s5-row > summary { display: grid; gap: 8px; padding: 8px; cursor: pointer; list-style: none; align-items: start; }
details.s5-row > summary::-webkit-details-marker { display: none; }
.s5-full { padding: 0 8px 10px; }
.s5-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 13px; color: var(--muted); white-space: pre-line; }
details[open] .s5-clamp { display: none; }
.s5-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.s5-toggle input { accent-color: var(--garnet); width: 16px; height: 16px; }
.s5-spell-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.s5-spell-stat { font-weight: 600; font-size: 14px; }
.s5-level-head .pips { justify-self: start; }
.s5-coins { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.s5-coin { display: grid; gap: 2px; }
.s5-coin .input { width: 100%; min-width: 0; }
.s5-items .s5-thead, .s5-items .s5-row { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.4fr) auto 0; }
.s5-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 16px; }
.s5-fact { font-weight: 600; }
@container (max-width: 560px) {
  .s5-thead, .s5-row { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr); }
  .s5-thead > span:nth-child(2), .s5-row > .s5-cell:nth-child(2) { display: none; }
  .s5-items .s5-thead, .s5-items .s5-row { grid-template-columns: minmax(0, 1fr) auto; }
  .s5-coins { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
