:root {
  --ink: #2b2118; --accent: #6b1d1d; --shade: #efe6d6; --paper: #faf6ee;
  --line: #d6c9b5; --muted: #8a7a66; --pos: #2f6b2f; --neg: #9b2020;
  --surface: #fff; color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--paper); }
h1 { margin: 0; color: var(--accent); letter-spacing: .04em; }
h2 { margin: 0 0 .6rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
h3 { font-size: .9rem; margin: 1rem 0 .4rem; }
main { max-width: 1000px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; }
.top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem;
       padding: 1rem max(1rem, calc((100% - 1000px) / 2 + 1rem)); border-bottom: 3px solid var(--accent); background: var(--shade); }
.top p { margin: 0; }
.top-actions { display: flex; gap: .5rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.stat .big { font-size: 1.6rem; font-weight: 700; margin: 0 0 .4rem; }
.bar { height: 8px; background: var(--shade); border-radius: 4px; overflow: hidden; margin-bottom: .6rem; }
.bar span { display: block; height: 100%; background: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
label { display: grid; gap: .2rem; font-size: .8rem; font-weight: 600; color: var(--muted); flex: 1; }
label[hidden] { display: none; }
input, select { font: inherit; color: var(--ink); padding: .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.entry { display: grid; gap: .6rem; }
.row { display: flex; gap: .6rem; }
button, .button { font: inherit; font-weight: 600; padding: .5rem 1rem; border-radius: 6px; border: 1px solid var(--accent);
                  background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; display: inline-block; }
button:disabled { opacity: .4; cursor: default; }
.ghost { background: transparent; color: var(--accent); }
.small { padding: .2rem .6rem; font-size: .8rem; }
.flash { margin: 0; padding: .6rem .9rem; border-radius: 6px; background: #e5f0e1; color: var(--pos); }
.flash.error { background: #f6e0e0; color: var(--neg); }
.inventory { list-style: none; margin: 0; padding: 0; }
.inventory li { display: flex; justify-content: space-between; padding: .3rem 0; border-bottom: 1px solid var(--shade); }
.ledger-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; }
.tabs a { color: var(--muted); text-decoration: none; padding: .2rem .5rem; border-radius: 4px; font-size: .85rem; }
.tabs a.on { background: var(--accent); color: #fff; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; color: var(--muted); font-weight: 600; }
td, th { padding: .4rem .5rem; border-bottom: 1px solid var(--shade); vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }
tr.undone td { text-decoration: line-through; color: var(--muted); }
tr.undone td:last-child { text-decoration: none; }
.compact td, .compact th { padding: .25rem .4rem; }
.sheet summary { cursor: pointer; list-style: none; }
.sheet summary h2 { display: inline; }
.sheet summary::after { content: " ▸"; color: var(--accent); }
.sheet[open] summary::after { content: " ▾"; }
.features { padding-left: 1.1rem; margin: 0; }
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login form { display: grid; gap: .8rem; text-align: left; margin-top: 1rem; }
.flash.warn { background: #fbf0d9; color: #7a5410; }
.flash.warn a { color: inherit; font-weight: 600; }
textarea { font: inherit; color: var(--ink); padding: .5rem; border: 1px solid var(--line); border-radius: 6px; width: 100%; resize: vertical; }
.settings { display: grid; gap: 1rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem; }
.fields.wide { grid-template-columns: 1fr; }
.hint { font-weight: 400; font-size: .75rem; }
.small-text { font-size: .85rem; margin: 0 0 .6rem; }
label.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; color: var(--ink); font-size: .9rem; margin-top: .6rem; }
label.check input { width: auto; }
.skills-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 1rem; }
.skills-grid label.check { margin-top: .3rem; }
.abilities input[type=number] { width: 4.5rem; }
.abilities .dice { font-size: .85rem; letter-spacing: .1em; }
.save-bar { position: sticky; bottom: 0; padding: .75rem 0; background: linear-gradient(transparent, var(--paper) 30%); }
.notes { white-space: pre-wrap; margin: 0; }
.item-pick { all: unset; box-sizing: border-box; display: flex; justify-content: space-between; width: 100%; padding: .3rem .25rem; border-radius: 4px; cursor: pointer; }
.item-pick:hover, .item-pick:focus-visible { background: var(--shade); }
.inventory li { padding: 0; }
.requests { list-style: none; margin: 0; padding: 0; }
.request { padding: .7rem 0; border-bottom: 1px solid var(--shade); }
.request:last-child { border-bottom: 0; }
.request-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.request-head form { margin-left: auto; }
.request-details { margin: .35rem 0 0; white-space: pre-wrap; }
.request-note { margin: .35rem 0 0; font-size: .9rem; }
.badge { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .15rem .5rem; border-radius: 999px; background: var(--shade); color: var(--muted); }
.badge.open { background: #fbf0d9; color: #7a5410; }
.badge.in_progress { background: #e3ecf7; color: #234d7a; }
.badge.done { background: #e5f0e1; color: var(--pos); }
.badge.rejected { background: #f6e0e0; color: var(--neg); }
.quick-hp { display: grid; grid-template-columns: 4.5rem 1fr; gap: .4rem; margin-bottom: .5rem; }
.quick-hp input { padding: .35rem .5rem; font-size: .9rem; }
.quick-hp-buttons { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.quick-hp-buttons button { padding: .35rem .5rem; }
.temp-hp { display: flex; align-items: center; gap: .4rem; margin-bottom: .5rem; font-size: .85rem; }
.temp-hp label { flex: 1; color: var(--muted); }
.temp-hp input { width: 4.5rem; padding: .3rem .45rem; font-size: .9rem; }
.temp-hp button, .temp-hp button.ghost { padding: .3rem .6rem; color: #2a7fb8; border-color: #2a7fb8; background: transparent; }
.vital-temp { color: #2a7fb8; font-weight: 700; }
.temp-badge { display: inline-block; vertical-align: middle; font-size: .8rem; font-weight: 700; color: #fff;
  background: #2a7fb8; border-radius: 999px; padding: .1rem .55rem; }
.long-rest { text-align: right; }

/* ---------- Color: one accent per kind of information ---------- */
:root {
  --c-hp: #b3261e;    --c-hp-bg: #fbe9e7;
  --c-gold: #a8730a;  --c-gold-bg: #fdf3dc;
  --c-stat: #2f5d8a;  --c-stat-bg: #e6eef7;
  --c-item: #3f7d3a;  --c-item-bg: #e7f2e4;
  --c-entry: #8a3b12; --c-entry-bg: #fbeee4;
  --c-req: #6b4fa0;   --c-req-bg: #efe9f8;
  --c-ledger: #5b4636; --c-ledger-bg: #f1ebe3;
}
body { background: linear-gradient(180deg, #f6eee0 0, var(--paper) 320px); }
.top { background: linear-gradient(100deg, #efe1c8 0%, #f3e3d6 45%, #e9dff0 100%); }
.top h1 { text-shadow: 0 1px 0 #fff8; }

.card { border-top: 4px solid var(--tone, var(--line)); }
.card h2 { color: var(--tone, var(--accent)); }
.tone-hp     { --tone: var(--c-hp);     --tone-bg: var(--c-hp-bg); }
.tone-gold   { --tone: var(--c-gold);   --tone-bg: var(--c-gold-bg); }
.tone-stat   { --tone: var(--c-stat);   --tone-bg: var(--c-stat-bg); }
.tone-item   { --tone: var(--c-item);   --tone-bg: var(--c-item-bg); }
.tone-entry  { --tone: var(--c-entry);  --tone-bg: var(--c-entry-bg); }
.tone-req    { --tone: var(--c-req);    --tone-bg: var(--c-req-bg); }
.tone-ledger { --tone: var(--c-ledger); --tone-bg: var(--c-ledger-bg); }
.card.stat { background: linear-gradient(160deg, var(--tone-bg) 0%, var(--surface) 70%); }
.stat .big { color: var(--tone); }
.stat .big .muted { color: var(--muted); }

/* HP bar shifts from green to amber to red as health drops */
.bar.hp-high span { background: linear-gradient(90deg, #3f7d3a, #5c9e4f); }
.bar.hp-mid span  { background: linear-gradient(90deg, #c27c0e, #e0a12a); }
.bar.hp-low span  { background: linear-gradient(90deg, #9b1c1c, #d23a2a); }
.bar { background: #00000010; }
.quick-hp-buttons button[value=remove] { background: var(--c-hp); border-color: var(--c-hp); }
.quick-hp-buttons button[value=add] { color: var(--c-item); border-color: var(--c-item); }

/* Inventory and ledger */
.tone-item .item-pick:hover, .tone-item .item-pick:focus-visible { background: var(--c-item-bg); }
.tone-item .item-pick b { color: var(--c-item); }
.kind { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
        padding: .1rem .45rem; border-radius: 999px; margin-right: .2rem; }
.kind-hp   { background: var(--c-hp-bg);   color: var(--c-hp); }
.kind-gold { background: var(--c-gold-bg); color: var(--c-gold); }
.kind-item { background: var(--c-item-bg); color: var(--c-item); }
.tabs a.tab-hp:hover   { color: var(--c-hp); }
.tabs a.tab-gold:hover { color: var(--c-gold); }
.tabs a.tab-item:hover { color: var(--c-item); }
.tabs a.on.tab-hp   { background: var(--c-hp); color: #fff; }
.tabs a.on.tab-gold { background: var(--c-gold); color: #fff; }
.tabs a.on.tab-item { background: var(--c-item); color: #fff; }
.ledger tbody tr:hover td { background: #faf6ee; }

/* Buttons and fields pick up the section color */
.card button:not(.ghost):not(.item-pick) { background: var(--tone, var(--accent)); border-color: var(--tone, var(--accent)); }
.card .ghost { color: var(--tone, var(--accent)); border-color: var(--tone, var(--accent)); }
.card input:focus, .card select:focus, .card textarea:focus { outline-color: var(--tone, var(--accent)); }
.abilities .total b { color: var(--c-gold); }
.compact td b { color: var(--c-stat); }

/* ---------- Phones: never wider than the screen ---------- */
main > *, .grid > *, .stats > *, .settings > * { min-width: 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.grid { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.fields { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.skills-grid { grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); }

@media (max-width: 640px) {
  body { font-size: 15px; }
  .top { padding: .8rem 1rem; }
  .top h1 { font-size: 1.6rem; }
  .top p { font-size: .85rem; }
  .top-actions { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: .4rem; }
  .top-actions form { display: contents; }
  .top-actions .button, .top-actions button { padding: .45rem .3rem; font-size: .82rem; text-align: center; white-space: nowrap; }
  main { padding: .75rem; gap: .75rem; }
  .card { padding: .85rem; }
  .row { flex-wrap: wrap; }
  .row > label { min-width: 8rem; }

  /* Ledger rows become compact cards: what + change, then why, then # / time / undo */
  .ledger thead { display: none; }
  .ledger, .ledger tbody { display: block; }
  .ledger tr { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .5rem; padding: .55rem 0; border-bottom: 1px solid var(--shade); }
  .ledger td { display: block; padding: 0; border: 0; }
  .ledger .l-what { order: 1; flex: 1; min-width: 0; }
  .ledger .l-change { order: 2; font-size: 1.05rem; }
  .ledger .l-why { order: 3; flex-basis: 100%; }
  .ledger .l-id { order: 4; font-size: .8rem; }
  .ledger .l-when { order: 5; flex: 1; font-size: .8rem; }
  .ledger .l-undo { order: 6; }
  .ledger tr:hover td { background: none; }
  .ledger-head { flex-direction: column; align-items: flex-start; }
}
html, body { min-height: 100%; }
body { background-attachment: fixed; }

/* ---------- D&D Beyond-style header blocks ---------- */
/* Abilities: the modifier is what you roll with, so it's big; the score sits in an oval below. */
.abilities-strip { display: grid; grid-template-columns: repeat(6, 1fr); gap: .6rem; }
.ability { position: relative; display: flex; flex-direction: column; align-items: center; background: var(--surface);
           border: 1.5px solid var(--c-stat); border-radius: 10px; padding: .45rem .3rem 1.35rem; margin-bottom: .8rem; }
.ability-name { font-size: .62rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-stat); }
.ability-mod { font-size: 1.9rem; font-weight: 700; line-height: 1.15; color: var(--ink); font-variant-numeric: tabular-nums; }
.ability-score { position: absolute; bottom: -.8rem; min-width: 2.6rem; text-align: center; background: var(--surface);
                 border: 1.5px solid var(--c-stat); border-radius: 999px; padding: .05rem .5rem; font-weight: 600; font-size: .95rem; }

/* Combat basics row: label on top, value large; Armor Class in a shield. */
.combat-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: .6rem; }
.combat-box { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: .2rem;
              background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px; padding: .55rem .3rem; text-align: center; }
.combat-label { font-size: .62rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); line-height: 1.2; }
.combat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.combat-value small { font-size: .85rem; font-weight: 600; color: var(--muted); }
.combat-box.armor { border: 0; background: none; position: relative; padding: .5rem .3rem .9rem; }
.combat-box.armor::before { content: ""; position: absolute; inset: 0; z-index: 0; background: var(--c-stat);
  clip-path: polygon(50% 0, 100% 12%, 100% 55%, 50% 100%, 0 55%, 0 12%); }
.combat-box.armor::after { content: ""; position: absolute; inset: 2px; z-index: 0; background: var(--c-stat-bg);
  clip-path: polygon(50% 0, 100% 12%, 100% 55%, 50% 100%, 0 55%, 0 12%); }
.combat-box.armor > * { position: relative; z-index: 1; }
.combat-box.armor .combat-label, .combat-box.armor .combat-value { color: var(--c-stat); }

@media (max-width: 640px) {
  .abilities-strip { grid-template-columns: repeat(3, 1fr); row-gap: 1.1rem; }
  .combat-strip { grid-template-columns: repeat(3, 1fr); }
  .ability-mod { font-size: 1.6rem; }
  .combat-value { font-size: 1.35rem; }
}

/* ---------- D&D Beyond-style panels: saves / skills / actions ---------- */
.panels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1.35fr); gap: 1rem; align-items: start; }
.panel-col { display: grid; gap: 1rem; min-width: 0; }
.panels .card h2 { margin-bottom: .7rem; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; border: 1.5px solid var(--muted); vertical-align: middle; }
.is-prof .dot { background: var(--c-stat); border-color: var(--c-stat); }
.bonus-box { display: inline-block; min-width: 2.3rem; padding: .1rem .35rem; border: 1.5px solid var(--line); border-radius: 6px;
             text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--surface); }
.is-prof .bonus-box { border-color: var(--c-stat); }
.saves { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.save { display: flex; align-items: center; gap: .45rem; padding: .3rem .45rem; border: 1px solid var(--shade); border-radius: 8px; }
.save-name { flex: 1; font-weight: 700; font-size: .85rem; letter-spacing: .04em; }
.panel-note { margin: .6rem 0 0; font-size: .82rem; color: var(--muted); }
.kv { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.kv li { display: flex; align-items: center; gap: .55rem; font-size: .9rem; }
.training { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .3rem .8rem; font-size: .9rem; }
.training dt { font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding-top: .15rem; }
.training dd { margin: 0; }
.skills th, .actions th { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; }
.skills td { padding: .22rem .35rem; }
.skills .small-caps { font-size: .72rem; font-weight: 700; letter-spacing: .04em; }
.skills tr.is-prof td:nth-child(3) { font-weight: 600; }
.actions td { padding: .45rem .35rem; vertical-align: top; }
.actions .sub { display: block; font-size: .78rem; color: var(--muted); font-weight: 400; }
.tone-hp .bonus-box { border-color: var(--c-hp-bg); }
@media (max-width: 960px) {
  .panels { grid-template-columns: 1fr 1fr; }
  .panels > .panel-col:last-child { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .panels { grid-template-columns: 1fr; }
}

/* ---------- Settings: D&D Beyond-style ability editors and skill toggles ---------- */
.ability-editors { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: .7rem; margin-bottom: .4rem; }
.ability-editor { display: grid; gap: .45rem; border: 1.5px solid var(--c-stat); border-radius: 10px; padding: .6rem; background: var(--surface); }
.ae-head { text-align: center; font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-stat); }
.ae-result { display: flex; flex-direction: column; align-items: center; }
.ae-mod { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.ae-total { min-width: 2.6rem; text-align: center; border: 1.5px solid var(--c-stat); border-radius: 999px; padding: 0 .5rem; font-weight: 600; }
.ae-row { font-size: .7rem; }
.ae-base { display: flex; gap: .3rem; }
.ae-base input { flex: 1; min-width: 0; }
.ability-editor input[type=number] { width: 100%; padding: .35rem .4rem; }
.ability-editor .dice { min-height: 1em; font-size: .8rem; text-align: center; letter-spacing: .1em; }
.ae-save { margin-top: 0; font-size: .8rem; }
.skill-toggle { display: flex; align-items: center; gap: .45rem; padding: .35rem .5rem; border: 1px solid var(--shade); border-radius: 8px;
                font-weight: 400; color: var(--ink); font-size: .9rem; cursor: pointer; }
.skill-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.skill-toggle .skill-name { flex: 1; }
.skill-toggle:has(input:checked) .dot { background: var(--c-stat); border-color: var(--c-stat); }
.skill-toggle:has(input:checked) { border-color: var(--c-stat-bg); background: var(--c-stat-bg); font-weight: 600; }
.skill-toggle:has(input:focus-visible) { outline: 2px solid var(--c-stat); }
.skills-grid { gap: .4rem .6rem; }
.small-caps { font-size: .72rem; font-weight: 700; letter-spacing: .04em; }
.skill-toggle { position: relative; }
.skill-toggle input { width: 1px; height: 1px; margin: 0; left: 0; top: 0; }
.ability-editors { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 900px) { .ability-editors { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px) { .ability-editors { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Click-to-roll ---------- */
.rollable { cursor: pointer; transition: background .15s, box-shadow .15s; }
.rollable:hover, .rollable:focus-visible { box-shadow: 0 0 0 2px var(--c-stat-bg), 0 0 0 3.5px var(--c-stat); outline: none; }
tr.rollable:hover td, tr.rollable:focus-visible td { background: var(--c-stat-bg); }
tr.rollable:hover, tr.rollable:focus-visible { box-shadow: none; }
.dmg-roll { border-bottom: 1.5px dashed var(--c-hp); padding: 0 .1rem; border-radius: 3px; }
.rollable.just-rolled { animation: rolled .6s ease-out; }
@keyframes rolled { from { background: #fff3c4; } to { background: transparent; } }
.roller { position: fixed; right: 1rem; bottom: 1rem; z-index: 20; width: 15rem; background: var(--surface); border: 1.5px solid var(--c-stat);
          border-radius: 12px; box-shadow: 0 6px 24px #0002; padding: .6rem; font-size: .85rem; }
.roller-mode { display: grid; grid-template-columns: repeat(3, 1fr); gap: .25rem; margin-bottom: .5rem; }
.roller-mode button { padding: .2rem; font-size: .75rem; background: transparent; color: var(--c-stat); border: 1px solid var(--c-stat-bg); }
.roller-mode button.on { background: var(--c-stat); color: #fff; border-color: var(--c-stat); }
.roller-last { text-align: center; color: var(--muted); }
.roll-label { font-weight: 700; color: var(--ink); }
.roll-total { font-size: 2.2rem; font-weight: 800; line-height: 1.1; color: var(--c-stat); font-variant-numeric: tabular-nums; }
.roll-detail { font-size: .75rem; }
.roller-last.crit .roll-total, .roller-history .crit { color: var(--c-item); }
.roller-last.fumble .roll-total, .roller-history .fumble { color: var(--c-hp); }
.roller-history { list-style: none; margin: .4rem 0 0; padding: .35rem 0 0; border-top: 1px solid var(--shade); color: var(--muted); font-size: .75rem; }
.roller-history:empty { display: none; }
main { padding-bottom: 7rem; }
@media (max-width: 640px) {
  .roller { left: .5rem; right: .5rem; bottom: .5rem; width: auto; display: grid; grid-template-columns: auto 1fr; gap: .5rem; align-items: center; padding: .45rem; }
  .roller-mode { grid-template-columns: 1fr; margin: 0; }
  .roll-total { font-size: 1.6rem; }
  .roller-history { display: none; }
}
.roller-toggle { position: absolute; top: -.9rem; right: .6rem; padding: .1rem .55rem; font-size: .78rem; border-radius: 999px;
                 background: var(--c-stat); border-color: var(--c-stat); color: #fff; }
.roller.collapsed { width: auto; padding: 0; border: 0; box-shadow: none; background: none; }
.roller.collapsed > :not(.roller-toggle) { display: none; }
.roller.collapsed .roller-toggle { position: static; padding: .4rem .8rem; font-size: .9rem; box-shadow: 0 4px 14px #0003; }
@media (max-width: 640px) {
  .roller.collapsed { left: auto; display: block; }
  .roller-toggle-text { display: none; }
  .roller.collapsed .roller-toggle-text { display: inline; }
}

/* ---------- Trackers: spell slots, Sneak Attack, Hit Dice, Inspiration, death saves ---------- */
.trackers { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.tracker-head { font-size: .9rem; }
.tracker-head .muted { font-size: .8rem; }
.tracker-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: .3rem; }
.tracker-row form, .rest-buttons form { margin: 0; }
.pips { display: inline-flex; gap: .25rem; margin-right: .3rem; }
.pip { width: .95rem; height: .95rem; border-radius: 3px; border: 1.5px solid var(--c-hp); background: var(--c-hp); }
.pip.used { background: var(--surface); border-color: var(--line); }
.pip.ok { border-color: var(--c-item); background: var(--surface); }
.pip.ok.used { background: var(--c-item); border-color: var(--c-item); }
.pip.bad { border-color: var(--c-hp); background: var(--surface); }
.pip.bad.used { background: var(--c-hp); }
.rest-buttons { display: flex; gap: .4rem; justify-content: flex-end; margin-top: .8rem; padding-top: .6rem; border-top: 1px solid var(--shade); }
.combat-strip { grid-template-columns: repeat(6, 1fr); }
.combat-box.inspiration { padding: 0; }
.combat-box.inspiration button { all: unset; box-sizing: border-box; width: 100%; height: 100%; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: space-between; gap: .2rem; padding: .55rem .3rem; border-radius: 10px; text-align: center; }
.combat-box.inspiration button:focus-visible { outline: 2px solid var(--c-gold); }
.combat-box.inspiration .combat-value { color: var(--line); }
.combat-box.inspiration.on { border-color: var(--c-gold); background: var(--c-gold-bg); }
.combat-box.inspiration.on .combat-value, .combat-box.inspiration.on .combat-label { color: var(--c-gold); }
.death-saves { margin: .2rem 0 .6rem; padding: .6rem; border: 1.5px dashed var(--c-hp); border-radius: 8px; display: grid; gap: .3rem; font-size: .9rem; }
.ds-group { display: flex; align-items: center; justify-content: space-between; }
@media (max-width: 640px) { .combat-strip { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Conditions ---------- */
.stats { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.condition-chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; }
.condition-chips form { margin: 0; }
.card .chip { border-radius: 999px; padding: .15rem .55rem; font-size: .75rem; font-weight: 600; }
.card .chip.ghost { background: var(--surface); border-color: var(--c-req-bg); }
.card .chip.ghost:hover { border-color: var(--c-req); }
.active-conditions { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; font-size: .85rem; }
.active-conditions li { background: var(--c-req-bg); border-radius: 6px; padding: .3rem .5rem; }
.exhaustion { margin-top: .6rem; font-size: .85rem; }
.exhaustion button { min-width: 2rem; }

/* ---------- Journal ---------- */
.journal { list-style: none; margin: 0; padding: 0; }
.journal-entry { padding: .9rem 0; border-bottom: 1px solid var(--shade); }
.journal-entry:last-child { border-bottom: 0; }
.journal-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.journal-head h3 { margin: 0; color: var(--c-req); font-size: 1.05rem; }
.journal-body { white-space: pre-wrap; margin: .4rem 0 .3rem; }
.journal-edit summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.journal-edit[open] summary { margin-bottom: .5rem; }
.journal-edit > form + form { margin-top: .5rem; }
.journal-search { display: flex; align-items: center; gap: .5rem; }
.journal-search input { width: 14rem; padding: .3rem .5rem; }
@media (max-width: 640px) { .journal-search, .journal-search input { width: 100%; } }

/* ---------- Rogue: expertise, weapons, Sneak Attack, spellcasting ---------- */
.is-exp .dot, .dot.legend-exp { background: var(--c-gold); border-color: var(--c-gold); box-shadow: 0 0 0 2px var(--c-gold-bg); }
.dot.legend-prof { background: var(--c-stat); border-color: var(--c-stat); }
.is-exp .bonus-box { border-color: var(--c-gold); }
.exp-badge { display: inline-block; background: var(--c-gold-bg); color: var(--c-gold); font-size: .62rem; font-weight: 700; text-transform: uppercase;
             letter-spacing: .04em; border-radius: 999px; padding: 0 .4rem; vertical-align: middle; }
.tools-check { display: flex; align-items: center; gap: .45rem; margin-top: .7rem; padding: .3rem .45rem; border: 1px solid var(--shade);
               border-radius: 8px; font-size: .9rem; font-weight: 600; }
.tools-check .bonus-box { margin-left: auto; }
.attacks-tag { display: inline-block; background: var(--c-hp); color: #fff; font-size: .68rem; font-weight: 700; border-radius: 999px;
               padding: 0 .45rem; margin-left: .2rem; white-space: nowrap; }
.sneak-note { margin-top: .6rem; padding-top: .5rem; border-top: 1px solid var(--shade); }
.sneak-note .panel-note { margin-top: 0; }
.sneak-note.is-used .panel-note { opacity: .65; }
.sneak-used { color: var(--c-hp); }
.spell-stats { display: flex; align-items: center; gap: .4rem 1rem; flex-wrap: wrap; margin-bottom: .7rem; }
.spell-stats > div { display: flex; align-items: center; gap: .4rem; }
.slot-pips .pip { border-radius: 50%; border-color: var(--c-gold); background: var(--c-gold); }
.slot-pips .pip.used { background: var(--surface); border-color: var(--line); }
.spell-group { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--c-gold); margin: .8rem 0 .3rem; }
.spells li { font-size: .85rem; }
.vital-slots { background: var(--c-gold-bg); color: var(--c-gold); }
.skill-item { display: grid; gap: .1rem; }
.skills-grid label.check.exp-toggle { margin: 0 0 .2rem .5rem; font-size: .78rem; color: var(--muted); }
.extra-dice { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.dice-chip { font-size: .74rem; padding: .05rem .45rem; border-radius: 999px; background: var(--c-gold-bg); color: var(--c-gold); border: 1px solid #ecd9ae; }
.roller-mode button { font-size: .68rem; }
.saves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dot { flex-shrink: 0; }

/* ---------- Full ability names instead of abbreviations ---------- */
.skill-ability { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; line-height: 1.1; }
.skill-toggle .skill-ability { display: inline; margin-left: .25rem; }
.save-name { font-size: .8rem; letter-spacing: 0; min-width: 0; overflow-wrap: anywhere; }
.save { padding: .3rem .4rem; gap: .35rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.saves { grid-template-columns: 1fr; gap: .3rem; }
.save-name { font-size: .9rem; font-weight: 600; overflow-wrap: normal; }

/* ---------- Money: coins, currencies, and a card that gets fancier with wealth ---------- */
.money .ledger-head { margin-bottom: .2rem; }
.money-tier-name { font-size: .75rem; font-weight: 700; color: var(--c-gold); letter-spacing: .04em; }
.coins { list-style: none; margin: 0 0 .6rem; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .9rem; }
.coin-row { display: flex; align-items: center; gap: .3rem; }
.coin { display: inline-grid; place-items: center; width: 1rem; height: 1rem; border-radius: 50%; font-size: .55rem; color: #fff;
        box-shadow: inset 0 -2px 0 #0002, inset 0 1px 0 #fff8; }
.coin-pp { background: radial-gradient(circle at 35% 30%, #fafcff, #b8c3cf 60%, #8996a4); }
.coin-gp { background: radial-gradient(circle at 35% 30%, #fff3b0, #e3b23c 60%, #b07d12); }
.coin-ep { background: radial-gradient(circle at 35% 30%, #f6f1d4, #c9bf86 60%, #9a8f55); }
.coin-sp { background: radial-gradient(circle at 35% 30%, #ffffff, #c7ccd1 60%, #8f979e); }
.coin-cp { background: radial-gradient(circle at 35% 30%, #f6c49b, #c27a45 60%, #8b4f25); }
.coin-other { background: radial-gradient(circle at 35% 30%, #e4d7ff, #8d6bd1 60%, #5b3f9a); }
.quick-money { display: grid; grid-template-columns: 5rem 1fr; gap: .4rem; }
.quick-money input, .quick-money select { padding: .35rem .5rem; font-size: .9rem; }
.quick-money .currency-name, .quick-money input[name=description] { grid-column: 1 / -1; }
.quick-money .quick-hp-buttons button[value=add] { background: var(--c-gold); border-color: var(--c-gold); }
.quick-money .quick-hp-buttons button[value=remove] { color: var(--c-gold); border-color: var(--c-gold); background: transparent; }
label .currency-name { margin-top: .3rem; }

/* Tiers: 0 empty, 1 a few coins, 2 comfortable, 3 well off, 4 wealthy, 5 dragon's hoard */
.money-tier-0 { filter: grayscale(.7); }
.money-tier-0 .money-total { color: var(--muted); }
.money-tier-3 { background: linear-gradient(160deg, #fdf0c8 0%, var(--surface) 75%); }
.money-tier-3 .money-total, .money-tier-4 .money-total, .money-tier-5 .money-total {
  background: linear-gradient(90deg, #8a5a00, #e3b23c, #fff1a8, #e3b23c, #8a5a00); background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.money-tier-4, .money-tier-5 { border-color: #e3b23c; box-shadow: 0 0 0 1px #f3dc93, 0 6px 22px #e3b23c33; }
.money-tier-4 { background: linear-gradient(160deg, #fbe39a 0%, #fff8e1 60%, var(--surface) 100%); }
.money-tier-4 .money-total, .money-tier-5 .money-total { animation: shimmer 3s linear infinite; }
.money-tier-5 { background: radial-gradient(circle at 20% 10%, #fff6c9, transparent 40%),
                            radial-gradient(circle at 85% 30%, #fff1a8, transparent 35%),
                            linear-gradient(160deg, #f7cf5a 0%, #fde9a5 55%, #fff4cf 100%); position: relative; overflow: hidden; }
.money-tier-5::after { content: "✦ ✧ ✦"; position: absolute; right: .8rem; top: 2.4rem; color: #fff; letter-spacing: .4rem;
                       text-shadow: 0 0 6px #e3b23c; animation: twinkle 2.4s ease-in-out infinite; pointer-events: none; }
.money-tier-5 .money-tier-name::before { content: "👑 "; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: 0 0; } }
@keyframes twinkle { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .money-total, .money-tier-5::after { animation: none !important; } }
.quick-money .quick-hp-buttons button[value=add] { color: #fff; }
.quick-hp { grid-template-columns: 6rem 1fr; }
.quick-money { grid-template-columns: 6rem 1fr; }

/* ---------- Sticky vitals + section tabs ---------- */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
[id] { scroll-margin-top: 4.5rem; }
.sheet-nav { position: sticky; top: 0; z-index: 15; background: #fffdf8ee; backdrop-filter: blur(6px);
             border-bottom: 1px solid var(--line); box-shadow: 0 2px 10px #0000000d; }
.sheet-nav-inner { max-width: 1000px; margin: 0 auto; padding: .4rem 1rem; display: flex; align-items: center; gap: 1rem; }
.vitals { display: flex; gap: .4rem; flex-shrink: 0; }
.vital { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .55rem; border-radius: 999px; font-size: .85rem;
         background: var(--shade); color: var(--ink); text-decoration: none; white-space: nowrap; }
.vital-hp.hp-high { background: #e7f2e4; color: #2f6b2f; }
.vital-hp.hp-mid { background: #fdf0d5; color: #8a5a00; }
.vital-hp.hp-low { background: #fbe2df; color: var(--c-hp); animation: pulse 1.6s ease-in-out infinite; }
.vital-cond { background: var(--c-req-bg); color: var(--c-req); font-weight: 700; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px #b3261e22; } }
.tabs-nav { display: flex; gap: .2rem; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.tabs-nav::-webkit-scrollbar { display: none; }
.tabs-nav a { padding: .35rem .7rem; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .85rem; white-space: nowrap; }
.tabs-nav a:hover { color: var(--accent); background: var(--shade); }
.tabs-nav a.on { background: var(--accent); color: #fff; }
.tabs-nav a.edited::after { content: ' ●'; color: var(--c-gold); font-size: .7em; vertical-align: middle; }
.tabs-nav a.on.edited::after { color: #fff; }

/* ---------- Toast messages: always visible, go away by themselves ---------- */
.flash.toast { position: fixed; top: 3.6rem; left: 50%; transform: translateX(-50%); z-index: 30; width: min(560px, calc(100% - 1.5rem));
               box-shadow: 0 8px 28px #0003; display: flex; align-items: flex-start; gap: .6rem; transition: opacity .3s, transform .3s;
               animation: toast-in .25s ease-out; }
.flash.toast.hide { opacity: 0; transform: translate(-50%, -1rem); pointer-events: none; }
.toast-close { all: unset; cursor: pointer; margin-left: auto; font-size: 1.2rem; line-height: 1; padding: 0 .2rem; opacity: .6; }
.toast-close:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -.6rem); } }
body:not(:has(.sheet-nav)) .flash.toast { top: 1rem; }

@media (max-width: 640px) {
  .sheet-nav-inner { flex-wrap: wrap; gap: .35rem; padding: .35rem .6rem; }
  .tabs-nav { margin-left: 0; width: 100%; }
  .tabs-nav a { padding: .3rem .55rem; font-size: .8rem; }
  .vital { font-size: .8rem; }
  [id] { scroll-margin-top: 6rem; }
  .flash.toast { top: auto; bottom: 4.5rem; }
  .flash.toast.hide { transform: translate(-50%, 1rem); }
}
@media (max-width: 640px) {
  .flash.toast { top: 4.9rem; bottom: auto; }
  .flash.toast.hide { transform: translate(-50%, -1rem); }
}

/* ---------- Inventory card with its own item form ---------- */
.inventory-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.inventory { columns: 2 14rem; column-gap: 1rem; }
.inventory li { break-inside: avoid; }
.item-pick.on { background: var(--c-item-bg); outline: 1.5px solid var(--c-item); }
.inventory-filter { margin-bottom: .5rem; padding: .35rem .6rem; }
.item-form { display: grid; gap: .45rem; padding: .7rem; border-radius: 10px; background: var(--c-item-bg); position: sticky; top: 4.5rem; }
.item-form .small-text { margin: 0; }
.item-form-row { display: grid; grid-template-columns: 4.5rem 1fr; gap: .4rem; }
.item-form input { padding: .35rem .5rem; font-size: .9rem; }
@media (max-width: 760px) { .inventory-layout { grid-template-columns: 1fr; } .item-form { position: static; } }

/* ---------- Ledger: manual entry, day groups, paging ---------- */
.manual-entry { margin: .2rem 0 .8rem; border: 1px dashed var(--line); border-radius: 8px; padding: .4rem .7rem; }
.manual-entry summary { cursor: pointer; font-weight: 600; color: var(--c-ledger); font-size: .9rem; }
.manual-entry[open] summary { margin-bottom: .6rem; }
.ledger tr.day-row td { padding: .8rem .5rem .3rem; border-bottom: 2px solid var(--shade); font-size: .75rem; font-weight: 700;
                        text-transform: uppercase; letter-spacing: .06em; color: var(--c-ledger); background: none; }
.ledger tr.day-row:hover td { background: none; }
.ledger-more { text-align: center; margin: .8rem 0 0; }
.ledger-more a { color: var(--c-ledger); font-weight: 600; }
@media (max-width: 640px) { .ledger tr.day-row { display: block; } .ledger tr.day-row td { display: block; } }
.item-form .quick-hp-buttons button[value=add] { background: var(--c-item); border-color: var(--c-item); color: #fff; }
.item-form .quick-hp-buttons button[value=remove] { background: var(--surface); border-color: var(--c-item); color: var(--c-item); }

/* ---------- Page navigation, settings bar, save hints ---------- */
.top-actions { flex-wrap: wrap; }
.top-actions .button.current { background: var(--accent); color: #fff; }
.unsaved-badge { font-size: .8rem; font-weight: 700; color: #8a5a00; background: #fdf0d5; padding: .2rem .6rem; border-radius: 999px; }
form.is-dirty .save-bar button { box-shadow: 0 0 0 3px #e3b23c66; }
.save-bar { display: flex; align-items: center; gap: .8rem; }
.save-hint { font-size: .8rem; }
.row .save-hint { align-self: center; }
@media (max-width: 640px) {
  .save-hint { display: none; }
  .top-actions { display: grid; grid-template-columns: repeat(3, 1fr); }
}

/* ---------- State backdrops: a drawing per active state, faint, behind the sheet ---------- */
.state-backdrop { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; transition: background .6s; }
.state-art { position: absolute; width: clamp(150px, 28vw, 340px); opacity: .2; filter: drop-shadow(0 0 1px #fff); }
.slot-1 { right: 2vw; bottom: 2vh; transform: rotate(-6deg); }
.slot-2 { left: 2vw; bottom: 4vh; transform: rotate(5deg); }
.slot-3 { right: 3vw; top: 18vh; transform: rotate(8deg); }
.slot-4 { left: 3vw; top: 20vh; transform: rotate(-7deg); }
.slot-5 { right: 30vw; bottom: 30vh; transform: rotate(3deg); }
.slot-6 { left: 30vw; top: 40vh; transform: rotate(-4deg); }
main.has-states .card:not(.stat):not(.money) { background-color: #ffffffe6; }
main.has-states { position: relative; }

/* Tints follow the first (most important) state */
.tint-dying { background: radial-gradient(ellipse at center, transparent 30%, #4a0a0a55 100%); }
.tint-poisoned { background: radial-gradient(ellipse at 70% 80%, #3f7d3a33, transparent 60%), linear-gradient(#e7f2e455, #e7f2e455); }
.tint-blinded { background: radial-gradient(ellipse at center, transparent 25%, #000000aa 100%); }
.tint-frightened { background: linear-gradient(#4b556322, #4b556333); }
.tint-charmed { background: radial-gradient(circle at 30% 30%, #f9c5dd66, transparent 60%), radial-gradient(circle at 80% 70%, #f9c5dd55, transparent 55%); }
.tint-deafened { background: linear-gradient(#efe9f866, #efe9f866); }
.tint-grappled, .tint-restrained { background: linear-gradient(90deg, #5b463622, transparent 30%, transparent 70%, #5b463622); }
.tint-incapacitated, .tint-stunned { background: radial-gradient(circle at 50% 30%, #fdf0d566, transparent 70%); }
.tint-invisible { background: repeating-linear-gradient(45deg, #6b4fa00d 0 12px, transparent 12px 24px); }
.tint-paralyzed { background: linear-gradient(#e3ecf777, #e3ecf777); }
.tint-petrified { background: linear-gradient(#78716c33, #a8a29e33); }
.tint-prone { background: linear-gradient(0deg, #7a541033, transparent 35%); }
.tint-unconscious { background: radial-gradient(ellipse at center, transparent 35%, #1e3a5f66 100%); }
.tint-exhaustion { background: linear-gradient(#fdf0d566, #f6e7c866); }

/* Gentle motion that fits each state */
.art-poisoned, .art-charmed { animation: bob 4s ease-in-out infinite; }
.art-frightened { animation: shiver .25s linear infinite; }
.art-stunned, .art-incapacitated { animation: spin-slow 12s linear infinite; }
.art-invisible { animation: fade 3s ease-in-out infinite; }
.art-unconscious, .art-dying { animation: breathe 5s ease-in-out infinite; }
@keyframes bob { 50% { translate: 0 -10px; } }
@keyframes shiver { 25% { translate: 1px 0; } 75% { translate: -1px 0; } }
@keyframes spin-slow { to { rotate: 360deg; } }
@keyframes fade { 50% { opacity: .05; } }
@keyframes breathe { 50% { scale: 1.04; opacity: .12; } }
@media (prefers-reduced-motion: reduce) { .state-art { animation: none !important; } }
@media (max-width: 640px) { .state-art { width: 46vw; opacity: .16; } .slot-5, .slot-6 { display: none; } }

/* Live updates: a form that's being saved dims briefly */
form.is-busy { opacity: .6; pointer-events: none; transition: opacity .15s; }

/* ---------- Real tabs: one panel at a time ---------- */
main [data-panel][hidden] { display: none !important; }
.tab-panel { display: grid; gap: 1rem; }
.tabs-nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Undo from the notice ---------- */
.toast-detail { font-weight: 400; opacity: .85; }
.toast-undo { margin: 0 0 0 auto; }
.toast-undo + .toast-close { margin-left: .2rem; }
.flash .toast-undo button { background: var(--pos); border-color: var(--pos); color: #fff; padding: .15rem .7rem; }
.flash.toast { align-items: center; }
div.flash { margin: 0; }


/* ---------- Dark theme (follows the device, or the toggle in the page navigation) ---------- */
html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ece3d4; --accent: #c75a4e; --shade: #2e2620; --paper: #17130f; --surface: #221c17;
  --line: #3d332b; --muted: #a39482; --pos: #8fd18a; --neg: #f08a80;
  --c-hp: #e0645a;    --c-hp-bg: #3a1f1c;
  --c-gold: #e3b23c;  --c-gold-bg: #3a3018;
  --c-stat: #82abd8;  --c-stat-bg: #1d2a3a;
  --c-item: #84c77f;  --c-item-bg: #1f3020;
  --c-entry: #d8915f; --c-entry-bg: #3a281c;
  --c-req: #ad97e0;   --c-req-bg: #2a2340;
  --c-ledger: #c4ac95; --c-ledger-bg: #2e2620;
}
html[data-theme="dark"] body { background: linear-gradient(180deg, #1f1913 0, var(--paper) 320px); }
html[data-theme="dark"] .top { background: linear-gradient(100deg, #2a2018 0%, #2a1f22 45%, #241f2e 100%); border-bottom-color: var(--accent); }
html[data-theme="dark"] .top h1 { text-shadow: none; }
html[data-theme="dark"] .sheet-nav { background: #1c1712ee; box-shadow: 0 2px 10px #0006; }
html[data-theme="dark"] .flash { background: #1f3020; color: #a6d9a1; }
html[data-theme="dark"] .flash.error { background: #3a1f1c; color: #f3a59c; }
html[data-theme="dark"] .flash.warn { background: #3a3018; color: #e8c97a; }
html[data-theme="dark"] .vital-hp.hp-high { background: #1f3020; color: #a6d9a1; }
html[data-theme="dark"] .vital-hp.hp-mid { background: #3a3018; color: #e8c97a; }
html[data-theme="dark"] .vital-hp.hp-low { background: #3a1f1c; color: #f3a59c; }
html[data-theme="dark"] .unsaved-badge { background: #3a3018; color: #e8c97a; }
html[data-theme="dark"] .ledger tbody tr:hover td { background: #241e18; }
html[data-theme="dark"] .dice-chip { border-color: #5a4a22; }
html[data-theme="dark"] .bar { background: #ffffff14; }
html[data-theme="dark"] main.has-states .card:not(.stat):not(.money) { background-color: #221c17e6; }
html[data-theme="dark"] .state-art { opacity: .14; filter: invert(.15); }
html[data-theme="dark"] .money-tier-3 { background: linear-gradient(160deg, #3d3214 0%, var(--surface) 75%); }
html[data-theme="dark"] .money-tier-4 { background: linear-gradient(160deg, #4d3c12 0%, #2c2416 60%, var(--surface) 100%); box-shadow: 0 0 0 1px #6b5418, 0 6px 22px #e3b23c22; }
html[data-theme="dark"] .money-tier-5 { background: radial-gradient(circle at 20% 10%, #6b541888, transparent 40%),
                                                  linear-gradient(160deg, #5a4614 0%, #3a2f15 55%, var(--surface) 100%); }
html[data-theme="dark"] .ae-total, html[data-theme="dark"] .ability-score { color: var(--ink); }
.theme-toggle { min-width: 2.6rem; }

/* ---------- Compact header: page buttons on one row; notices out of the way ---------- */
.top { padding-top: .7rem; padding-bottom: .7rem; }
.top h1 { font-size: 1.7rem; }
.top-actions { gap: .3rem; align-items: center; }
.top-actions .button, .top-actions button { padding: .35rem .7rem; font-size: .88rem; }
.top-actions .theme-toggle { padding: .35rem .55rem; }
.top-actions form { margin: 0; }
@media (min-width: 641px) {
  /* Notices sit at the bottom centre on larger screens, clear of the header buttons and the dice panel. */
  .flash.toast { top: auto; bottom: 1.2rem; }
  .flash.toast.hide { transform: translate(-50%, 1rem); }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, .6rem); } }
}
@media (min-width: 641px) and (max-width: 1180px) {
  .flash.toast { left: calc(50% - 7rem); width: min(520px, calc(100% - 18rem)); }
}
@media (max-width: 640px) {
  .top-actions { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%; padding-bottom: 2px; }
  .top-actions::-webkit-scrollbar { display: none; }
  .top-actions .button, .top-actions button { flex: 0 0 auto; }
  .top h1 { font-size: 1.4rem; }
}

/* ---------- Dice panel: quick dice and free-form rolls ---------- */
.quick-dice { display: grid; grid-template-columns: repeat(7, 1fr); gap: .2rem; margin-bottom: .4rem; }
.die-btn { all: unset; box-sizing: border-box; text-align: center; cursor: pointer; font-size: .72rem; font-weight: 700;
           padding: .2rem 0; border-radius: 5px; border: 1px solid var(--c-stat-bg); color: var(--c-stat); }
.die-btn:hover, .die-btn:focus-visible { background: var(--c-stat-bg); }
.die-btn.rollable:hover { box-shadow: none; }
.roller-custom { display: grid; grid-template-columns: 1fr auto; gap: .3rem; margin-bottom: .5rem; }
.roller-custom input { padding: .25rem .45rem; font-size: .85rem; }
.roller-custom input.invalid { outline: 2px solid var(--neg); }
.roller .roller-custom button { background: var(--c-stat); border-color: var(--c-stat); color: #fff; padding: .2rem .6rem; }
@media (max-width: 640px) {
  .quick-dice, .roller-custom { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .roller:not(.collapsed) { display: grid; grid-template-columns: 1fr; gap: .35rem; }
  .roller-mode { grid-template-columns: repeat(3, 1fr); }
  .roller .roller-last { display: flex; align-items: baseline; gap: .5rem; text-align: left; flex-wrap: wrap; }
  .roller .roll-total { font-size: 1.4rem; }
  .quick-dice, .roller-custom { margin-bottom: 0; }
}

/* Settings tabs: a hidden panel stays hidden even when it is a grid/flex form. */
[data-spanel][hidden], .save-bar[hidden] { display: none !important; }

/* Experience: level progress, awarding XP and leveling up. */
.xp-bar { margin: .8rem 0; padding: .6rem .9rem; border-radius: 10px; border: 1.5px solid #c9a227; background: var(--surface); }
.xp-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .8rem; }
.xp-head b { color: #9a7a12; }
.bar.xp { margin: .45rem 0; }
.bar.xp span { background: linear-gradient(90deg, #e3b23c, #c9a227); }
.xp-award { display: grid; grid-template-columns: 6rem 1fr auto; gap: .4rem; }
.xp-award input { padding: .35rem .5rem; font-size: .9rem; }
.xp-award button { background: #c9a227; border-color: #c9a227; color: #fff; }
.level-up { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin: .2rem 0 .5rem;
  padding: .45rem .7rem; border-radius: 8px; background: #fbf1cf; font-weight: 700; color: #7a5c00; }
.level-up button { white-space: nowrap; background: #c9a227; border-color: #c9a227; color: #fff; }
.xp-log { list-style: none; margin: .5rem 0 0; padding: 0; font-size: .82rem; display: grid; gap: .15rem; }
.xp-log b { color: #9a7a12; }
.xp-log li { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .35rem; }
.xp-undo { margin: 0 0 0 auto; }
.xp-undo button { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px;
  padding: 0 .4rem; font-size: .8rem; line-height: 1.4; }
.xp-undo button:hover { color: var(--accent); border-color: var(--accent); }
html[data-theme="dark"] .level-up { background: #3a3014; color: #f0d27a; }
html[data-theme="dark"] .xp-head b, html[data-theme="dark"] .xp-log b { color: #e3b23c; }

/* ---------- Playing the rogue: turn tracker, hiding, crossbow volley, concentration, rogue checks ---------- */
.turn-card .ledger-head { margin-bottom: .5rem; }
.turn-card .ledger-head h2 { margin: 0; }
.turn-card form { margin: 0; }
.turn-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.turn-slot { display: grid; align-content: start; gap: .3rem; }
.turn-chip { display: flex; align-items: center; gap: .45rem; width: 100%; padding: .45rem .6rem; border-radius: 999px; font-size: .9rem;
             background: var(--c-hp); border-color: var(--c-hp); color: #fff; }
.turn-chip.used { background: var(--surface); color: var(--muted); border-color: var(--line); text-decoration: line-through; }
.turn-box { display: inline-grid; place-items: center; width: 1.05rem; height: 1.05rem; border-radius: 4px; border: 1.5px solid currentColor;
            font-size: .75rem; line-height: 1; flex-shrink: 0; }
.turn-opts { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.35; }
.turn-opts b { color: var(--ink); font-weight: 600; }
.turn-opts a { color: var(--c-hp); font-weight: 600; }
.turn-slot.is-used .turn-opts { opacity: .55; }
.turn-roll { display: inline-flex; gap: .3rem; align-items: baseline; margin: .1rem .3rem 0 0; white-space: nowrap; color: var(--ink); font-weight: 600; }
.turn-roll [data-roll]:not(.dmg-roll) { border-bottom: 1.5px dashed var(--c-stat); padding: 0 .1rem; border-radius: 3px; }
.turn-new { white-space: nowrap; }
.hidden-box, .conc-box { margin-top: .7rem; padding: .5rem .65rem; border-radius: 8px; border: 1px dashed var(--line); font-size: .88rem; }
.hidden-box .panel-note, .conc-box .panel-note { margin-top: .3rem; }
.hidden-box.is-hidden { border: 1.5px solid var(--c-req); background: var(--c-req-bg); }
.hidden-box.is-hidden b { color: var(--c-req); }
.conc-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.conc-head form, .conc-head .tracker-row { margin: 0; }
.conc-box { border: 1.5px solid var(--c-gold); background: var(--c-gold-bg); margin: 0 0 .7rem; }
.conc-box b { color: var(--c-gold); }
.conc-box.needs-save { border-color: var(--c-hp); background: var(--c-hp-bg); }
.conc-save p { margin: .35rem 0 0; }
.conc-save b { color: var(--c-hp); }
.stat .conc-box { margin: .2rem 0 .6rem; }
.conc-badge { display: inline-block; background: var(--c-gold-bg); color: var(--c-gold); font-size: .62rem; font-weight: 700; text-transform: uppercase;
              letter-spacing: .04em; border-radius: 999px; padding: 0 .4rem; vertical-align: middle; }
.spell-head { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; margin-bottom: .1rem; }
.spell-head form { margin: 0 0 0 auto; }
.spell-head form + form { margin-left: 0; }
.spells .cast { background: var(--c-gold); border-color: var(--c-gold); color: #fff; padding: .15rem .6rem; }
.spells li.is-concentrating { list-style: "◎ "; }
.vital-hidden { background: var(--c-req-bg); color: var(--c-req); }
.vital-conc { background: var(--c-gold-bg); color: var(--c-gold); max-width: 11rem; overflow: hidden; text-overflow: ellipsis; }
.vital-conc.needs-save { background: var(--c-hp-bg); color: var(--c-hp); }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem; }
.check-tile-form { margin: 0; display: contents; }
.check-tile { display: flex; align-items: center; gap: .4rem; padding: .35rem .45rem; border: 1px solid var(--shade); border-radius: 8px;
              font-size: .85rem; font-weight: 600; color: var(--ink); background: var(--surface); text-align: left; width: 100%; min-width: 0; }
button.check-tile { font: inherit; font-size: .85rem; font-weight: 600; border-color: var(--c-req-bg); }
button.check-tile:hover { border-color: var(--c-req); }
.check-tile .bonus-box { margin-left: auto; }
.check-name { min-width: 0; }
.check-skill { display: block; font-size: .7rem; font-weight: 400; color: var(--muted); line-height: 1.2; }
.actions tr.volley-row td { padding-top: 0; }
.actions tr:has(+ .volley-row) td { border-bottom: 0; }
.volley { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.volley-form { display: flex; gap: .35rem; margin: 0; }
.volley-form button[value="fire:2"] { background: var(--c-hp); border-color: var(--c-hp); padding: .3rem .75rem; }
.volley-form button.ghost { color: var(--c-hp); border-color: var(--c-hp); padding: .3rem .75rem; }
.volley form { margin: 0; }
.bolts { font-size: .85rem; padding: .1rem .5rem; border-radius: 999px; background: var(--shade); white-space: nowrap; }
.bolts.low { background: var(--c-gold-bg); color: var(--c-gold); }
.bolts.out { background: var(--c-hp-bg); color: var(--c-hp); font-weight: 700; }
.bolts-warn { color: var(--c-hp); font-weight: 600; }
.volley-row .panel-note { margin-top: .3rem; }
.sneak-line { margin-top: .5rem; }
.sneak-line a { color: var(--c-hp); font-weight: 700; }
.sneak-line.is-used { opacity: .65; }
/* Volley result in the dice panel */
.roller .roller-last.is-volley { display: grid; gap: .3rem; text-align: left; }
.shot { border-top: 1px solid var(--shade); padding-top: .25rem; }
.shot-hit { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
.shot-name { font-weight: 700; color: var(--ink); font-size: .78rem; }
.shot-total { font-size: 1.35rem; color: var(--c-stat); font-variant-numeric: tabular-nums; line-height: 1.1; }
.shot-d20 { font-size: .72rem; }
.shot-flag { font-size: .7rem; font-weight: 700; border-radius: 999px; padding: 0 .4rem; }
.shot.crit .shot-total { color: var(--c-item); }
.shot.crit .shot-flag { background: var(--c-item-bg); color: var(--c-item); }
.shot.fumble .shot-total { color: var(--c-hp); }
.shot.fumble .shot-flag { background: var(--c-hp-bg); color: var(--c-hp); }
.shot-dmg { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; font-size: .8rem; color: var(--ink); }
.sneak-chip { font: inherit; font-size: .72rem; font-weight: 700; padding: .05rem .5rem; border-radius: 999px;
              background: var(--c-gold-bg); color: var(--c-gold); border: 1px solid var(--c-gold); }
.sneak-chip.was-used { opacity: .6; border-style: dashed; }
.sneak-chip.rolled { background: var(--c-gold); color: #fff; opacity: 1; }
.sneak-chip:disabled:not(.rolled) { opacity: .3; }
@media (max-width: 640px) {
  .turn-grid { gap: .5rem; }
  .turn-chip { font-size: .85rem; padding: .45rem .5rem; }
  .vitals { flex-wrap: wrap; flex-shrink: 1; }
  .vital-conc { max-width: 8.5rem; }
}
@media (max-width: 380px) { .check-grid { grid-template-columns: 1fr; } }

/* ---------- Combat tab in four columns: turn + checks | attacks | spells | saves + skills ---------- */
.panels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 960px) { .panels > .panel-col:last-child { grid-column: auto; } }
@media (max-width: 640px) {
  /* Phone: one column, in the order you need it in a fight. */
  .panels { grid-template-columns: minmax(0, 1fr); }
  .panels > .panel-col { display: contents; }
  .panels > .panel-col > .card { min-width: 0; }
  .c-turn { order: 1; } .c-actions { order: 2; } .c-spell { order: 3; } .c-checks { order: 4; } .c-limited { order: 5; }
  .c-saves { order: 6; } .c-senses { order: 7; } .c-skills { order: 8; } .c-prof { order: 9; } .c-features { order: 10; }
}
/* Wide screens: the sheet uses the width (other pages, like settings, keep their narrow column). */
@media (min-width: 1280px) {
  main#top { max-width: 1800px; }
  body:has(main#top) .top { padding-left: max(1rem, calc((100% - 1800px) / 2 + 1rem)); padding-right: max(1rem, calc((100% - 1800px) / 2 + 1rem)); }
  .sheet-nav-inner { max-width: 1800px; }
  /* Stay centred under the header; room at the bottom lets you scroll anything out from under the open dice panel. */
  body:has(.roller:not(.collapsed)) main#top { padding-bottom: 24rem; }
  .panels { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .c-saves .saves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .skills td { padding: .16rem .35rem; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .inventory { columns: 3 14rem; }
  .sheet .notes, .sheet .features { max-width: 75ch; }
}

/* ---------- Spell slots as tappable pips (top bar and Overview) ---------- */
.slot-bar { display: inline-flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.slot-level { display: inline-flex; align-items: center; gap: .1rem; }
.slot-level form { margin: 0; display: inline-flex; }
.slot-lvl { font-size: .72rem; font-weight: 700; color: inherit; text-decoration: none; margin-right: .15rem; }
.slot-pip { all: unset; box-sizing: border-box; cursor: pointer; display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; }
.slot-pip::before { content: ""; width: .85rem; height: .85rem; border-radius: 50%; border: 1.5px solid var(--c-gold); background: transparent; }
.slot-pip.full::before { background: var(--c-gold); }
.slot-pip:hover::before, .slot-pip:focus-visible::before { box-shadow: 0 0 0 3px var(--c-gold-bg), 0 0 0 4.5px var(--c-gold); }
.vital-slots { padding-top: 0; padding-bottom: 0; gap: .1rem; }
.vital-slots .slot-pip { width: 1.45rem; height: 1.45rem; }
.slot-strip { display: flex; align-items: center; gap: .4rem 1rem; flex-wrap: wrap; padding: .45rem .9rem; border-radius: 10px;
              border: 1.5px solid var(--c-gold); background: var(--c-gold-bg); color: var(--c-gold); }
.slot-strip-label a, .slot-strip-conc { color: var(--c-gold); font-weight: 700; text-decoration: none; }
.slot-strip-label .muted { font-size: .78rem; margin-left: .3rem; }
.slot-strip .slot-pip { width: 2rem; height: 2rem; }
.slot-strip .slot-pip::before { width: 1.1rem; height: 1.1rem; }
.slot-strip .slot-lvl { font-size: .85rem; }
.slot-strip-conc { margin-left: auto; font-size: .88rem; }
.slot-strip-conc.needs-save { color: var(--c-hp); }
/* The card button colour rule is more specific than these, so restate them. */
.card button.turn-chip.used:not(.ghost):not(.item-pick) { background: var(--surface); color: var(--muted); border-color: var(--line); }
.card button.check-tile:not(.ghost):not(.item-pick) { background: var(--surface); color: var(--ink); border: 1px solid var(--c-req-bg); }
.card button.check-tile:hover { border-color: var(--c-req); }
.card button.slot-pip { background: none; border: 0; }
