:root {
  --bg: #16181d;
  --panel: #1f2229;
  --panel-2: #262a33;
  --line: #333845;
  --text: #f1ece2;
  --muted: #a2a7b2;
  --accent: #e3a64a;
  --accent-ink: #1b1306;
  --good: #5cc28a;
  --bad: #ef6b6f;
  --mid: #e8c15a;
  --temp: #6fa8ec;
  --npc: #8a8f9c;
  --radius: 14px;
  --display: 'Cinzel', Georgia, serif;
  --body: 'Alegreya Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.4 var(--body);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px; }
/* Pages without the top bar: keep content below the iPhone status bar / notch. */
#app > .wrap { padding-top: calc(16px + env(safe-area-inset-top)); }
.center { text-align: center; padding-top: 30vh; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.pad { padding: 8px 4px; }
.pre { white-space: pre-line; }
.row { display: flex; gap: 8px; align-items: center; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.brand { font-family: var(--display); font-weight: 700; letter-spacing: .04em; font-size: 24px; margin: 0; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; background: var(--panel-2); color: var(--muted); margin-left: 8px; vertical-align: middle; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); font-weight: 700; text-decoration: none; color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: #3a1f23; border-color: #6b2d33; color: #ffc9cb; }
.btn.good { background: #1b3328; border-color: #2c5e45; color: #c3f0d6; }
.btn:disabled { opacity: .45; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: 12px; border: 0; background: transparent; color: var(--muted); text-decoration: none; font-size: 24px;
}
.icon-btn:hover, .icon-btn.active { background: var(--panel-2); color: var(--text); }
.link { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 8px; min-height: 44px; }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.sync.on .dot { background: var(--good); box-shadow: 0 0 0 3px rgba(92, 194, 138, .18); }

/* Home */
.home-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 0 4px; }
.char-list { display: grid; gap: 10px; margin: 12px 0 20px; }
.char-card {
  display: flex; align-items: center; gap: 14px; padding: 14px; min-height: 72px;
  border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
  color: var(--text); text-decoration: none; border-left: 5px solid var(--pc);
}
.char-card.last { border-color: var(--pc); }
.avatar {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: color-mix(in srgb, var(--pc) 25%, var(--panel-2)); font-family: var(--display); font-weight: 700;
}
.cc-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cc-name { font-weight: 700; font-size: 18px; }
.cc-hp { font-size: 20px; }
.home-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Sheet */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 4px; padding-top: calc(8px + env(safe-area-inset-top));
  padding-left: calc(4px + env(safe-area-inset-left)); padding-right: calc(8px + env(safe-area-inset-right));
  background: rgba(22, 24, 29, .94); backdrop-filter: blur(8px); border-bottom: 2px solid var(--pc);
}
.tb-title { flex: 1; min-width: 0; }
.tb-name { font-family: var(--display); font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

.hp-card { border-color: color-mix(in srgb, var(--pc) 40%, var(--line)); }
.hp-card.down { border-color: var(--bad); }
.hp-top { display: flex; justify-content: space-between; align-items: center; }
.hp-num .big { font-size: 48px; font-weight: 700; line-height: 1; }
.hp-num .muted { font-size: 22px; }
.temp-tag { margin-left: 10px; color: var(--temp); font-weight: 700; font-size: 16px; }
.hp-step { display: flex; gap: 8px; }
.step {
  min-width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); font-weight: 700; font-size: 18px;
}
.hpbar { position: relative; display: flex; height: 10px; border-radius: 99px; background: #2b2f39; overflow: hidden; margin: 10px 0; }
.hpbar .fill { height: 100%; transition: width .25s; }
.hpbar .ok { background: var(--good); }
.hpbar .mid { background: var(--mid); }
.hpbar .low { background: var(--bad); }
.hpbar .temp { background: var(--temp); }
.hp-ctrl { display: grid; grid-template-columns: 1fr 64px 1fr 64px; gap: 6px; }
.hp-ctrl .btn { padding: 0 6px; min-width: 0; }
.hp-ctrl.compact { grid-template-columns: auto 1fr auto; }
.amt {
  width: 100%; min-height: 44px; text-align: center; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-size: 18px; font-weight: 700;
}
input.amt.tiny { width: 52px !important; min-height: 38px; font-size: 15px; padding: 4px; flex: none; }
.death { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.death-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.ds-row { display: flex; justify-content: space-between; align-items: center; }

.pips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.pip {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; padding: 0;
  position: relative;
}
.pip::after { content: ''; position: absolute; inset: -7px; } /* bigger touch target */
.pip.lit { background: var(--pc, var(--accent)); border-color: var(--pc, var(--accent)); }
.pip.good.lit { background: var(--good); border-color: var(--good); }
.pip.bad.lit { background: var(--bad); border-color: var(--bad); }

.stat-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-strip.three { grid-template-columns: repeat(3, 1fr); }
.stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 64px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); padding: 6px 2px;
}
.stat b { font-size: 22px; line-height: 1.1; }
.stat span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
button.stat:active { background: var(--panel-2); }

.tabs {
  position: sticky; top: calc(62px + env(safe-area-inset-top)); z-index: 4; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 12px; padding: 6px 16px; background: var(--bg);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-weight: 700;
}
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab-body { padding-bottom: 90px; }

.row-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.insp {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: transparent; color: var(--muted); font-weight: 700;
}
.insp.on { background: #3a2e14; border-color: var(--accent); color: var(--accent); }
.insp.on .ic { fill: var(--accent); }
.insp.mini { padding: 0; width: 40px; min-height: 40px; justify-content: center; }
.exh { display: flex; align-items: center; gap: 10px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.step-val { min-width: 32px; text-align: center; font-weight: 700; font-size: 18px; }
.stepper.sm .step { min-width: 38px; height: 38px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 15px; font-weight: 500;
}
.chip.on { background: #3a1f23; border-color: var(--bad); color: #ffd1d3; }
.chip.warn { background: #3a3014; border-color: var(--mid); color: #f6e2a8; display: inline-flex; align-items: center; }
.chip.add { border-style: dashed; }
.chips.picker { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }

.res { padding: 8px 0; border-top: 1px solid var(--line); }
.res:first-of-type { border-top: 0; padding-top: 0; }
.res-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.res-name { font-weight: 700; }
.res-edit { display: grid; grid-template-columns: 1fr 64px auto 44px; gap: 6px; margin-bottom: 4px; }

input:not([type=checkbox]):not([type=color]), select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
textarea { resize: vertical; line-height: 1.45; }
input.num { text-align: center; }
input[type=color] { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 4px; }

.atk { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.atk:first-of-type { border-top: 0; }
.atk-main { flex: 1; min-width: 0; }
.atk-name { font-weight: 700; }
.roll-btn {
  min-width: 52px; min-height: 44px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); font-weight: 700; white-space: nowrap;
}
.roll-btn.dmg { color: var(--accent); }
.atk-edit, .spell-edit { display: grid; grid-template-columns: 1fr 64px 92px 44px; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.spell-edit { grid-template-columns: 1fr 64px 44px; }
.atk-edit .full, .spell-edit .full { grid-column: 1 / -1; }

.abil-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.abil {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; min-height: 96px;
  border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
}
.abil-name { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.abil-mod { font-size: 30px; font-weight: 700; line-height: 1.1; }
.abil-score { font-size: 14px; padding: 1px 10px; border-radius: 99px; background: var(--panel-2); }
.abil-input { text-align: center; font-size: 20px; font-weight: 700; max-width: 80px; }

.list { display: grid; }
.list.two { grid-template-columns: 1fr 1fr; column-gap: 12px; }
.li { display: flex; align-items: center; gap: 8px; }
.li-main {
  flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  min-height: 44px; border: 0; background: transparent; padding: 0 4px; text-align: left; border-bottom: 1px solid var(--line);
}
.prof {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; padding: 0; flex: none; position: relative;
}
.prof:not(:disabled)::after { content: ''; position: absolute; inset: -12px; }
.prof.on { background: var(--pc, var(--accent)); border-color: var(--pc, var(--accent)); }
.prof.exp { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--pc, var(--accent)); }
.prof:disabled { opacity: 1; }
.prof-spacer { width: 18px; flex: none; }

.spell { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.spell:first-of-type { border-top: 0; }
.spell .prof { margin-top: 3px; }
.spell-name { font-weight: 700; }

.coins { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.coin { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.coin input { text-align: center; padding: 8px 2px; font-weight: 700; }
.coin-gp span { color: var(--accent); }
.coin-pp span { color: #cfd6e4; }
.coin-cp span { color: #d2895a; }

.inv { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.inv:first-of-type { border-top: 0; }
.inv-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.small-in { min-height: 36px !important; font-size: 14px; }

.feat { border-top: 1px solid var(--line); }
.feat:first-of-type { border-top: 0; }
.feat summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; cursor: pointer; list-style: none; gap: 4px; }
.feat summary::-webkit-details-marker { display: none; }
.feat summary::before { content: '›'; display: inline-block; width: 16px; color: var(--muted); transition: transform .15s; }
.feat[open] summary::before { transform: rotate(90deg); }
.feat p { margin: 0 0 12px 16px; color: #ddd7cc; }
.feat.hb .tag { background: color-mix(in srgb, var(--pc) 30%, var(--panel-2)); color: var(--text); }
.feat-edit { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.feat-edit .row input { flex: 1; }
.concept { border-left: 4px solid var(--pc); }
.concept p { margin: 0; }

.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row input { flex: 1; }

.editor { border-color: var(--accent); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.field input, .field select { color: var(--text); font-size: 16px; }
.field.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text); min-height: 44px; }
.field.check input { width: 22px; height: 22px; }
.danger-zone { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* Dice */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
.fab .ic { width: 28px; height: 28px; }
.quick-dice {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; flex-direction: column; gap: 6px;
}
.quick-dice.inline { position: static; flex-direction: row; flex-wrap: wrap; }
.die {
  min-width: 58px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); font-weight: 700; box-shadow: 0 4px 12px rgba(0, 0, 0, .35);
}
.roll-sheet {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  width: min(420px, calc(100% - 32px)); transform: translate(-50%, 140%); transition: transform .22s ease;
  background: #262a33; border: 1px solid var(--accent); border-radius: 18px; padding: 14px 16px 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
}
.roll-sheet.show { transform: translate(-50%, 0); }
.roll-head { display: flex; justify-content: space-between; align-items: center; }
.roll-label { font-weight: 700; }
.roll-total { font-family: var(--display); font-size: 56px; font-weight: 700; text-align: center; line-height: 1.1; }
.roll-total.crit { color: var(--good); }
.roll-total.fumble { color: var(--bad); }
.roll-detail { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 10px; word-break: break-word; }
.roll-actions { display: flex; gap: 8px; justify-content: center; }
.roll-actions .btn { flex: 1; }

#toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); z-index: 40; transform: translate(-50%, -150%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700;
  transition: transform .2s; max-width: calc(100% - 32px);
}
#toast.show { transform: translate(-50%, 0); }

/* Login */
.login { max-width: 360px; margin: 18vh auto 0; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); text-align: center; }
.login form { display: grid; gap: 10px; margin-top: 14px; }
.err { color: var(--bad); }

/* Host */
.host { padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); max-width: 1600px; margin: 0 auto; }
.host-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.host-head .brand { flex: 1; }
.host-grid { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(360px, 1.25fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px; min-width: 0; }
.panel-title { font-family: var(--display); font-size: 18px; margin: 0 0 12px; letter-spacing: .04em; }
.party { display: grid; gap: 10px; }
.pcard { background: var(--bg); border: 1px solid var(--line); border-left: 5px solid var(--pc); border-radius: 14px; padding: 12px; }
.pcard.down { border-color: var(--bad); border-left-color: var(--bad); }
.pcard-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pc-name { color: var(--text); font-weight: 700; font-size: 18px; text-decoration: none; }
.pc-name:hover { text-decoration: underline; }
.pc-hp { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px; margin-top: 6px; }
.pc-hp .big { font-size: 30px; font-weight: 700; line-height: 1; }
.pc-stats { margin-left: auto; display: flex; gap: 12px; color: var(--muted); font-size: 14px; }
.pc-stats b { color: var(--text); font-size: 17px; }
.pcard .chips { margin-top: 8px; }
.ds-mini { color: #ffc9cb; margin-top: 6px; letter-spacing: .02em; }
.res-line { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.res-mini b { color: var(--text); }
.res-mini.empty b { color: var(--bad); }

.ini-head { display: flex; justify-content: space-between; align-items: baseline; }
.round { color: var(--muted); }
.round b { color: var(--accent); font-size: 22px; }
.ini-ctrl { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ini-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 10px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line); border-left: 5px solid var(--pc);
}
.ini-row.active { border-color: var(--accent); background: #2a2416; box-shadow: 0 0 0 1px var(--accent); }
.ini-row.dead { opacity: .5; }
.ini-row.dead .ini-name { text-decoration: line-through; }
.ini-num { width: 58px !important; padding: 4px !important; text-align: center; font-size: 20px; font-weight: 700; flex: none; }
.ini-main { flex: 1; min-width: 0; }
.ini-main .hpbar { margin: 6px 0 0; height: 6px; }
.ini-name { font-weight: 700; }
.pc-tag { background: color-mix(in srgb, var(--pc) 30%, var(--panel-2)); color: var(--text); }
.ini-meta { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.ini-meta b { color: var(--text); }
.warn-text { color: #ffb3b6; }
.npc-hp { display: flex; align-items: center; gap: 4px; }
.npc-hp .step { min-width: 38px; height: 38px; }
.monster-form {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line);
}
.mf-title { width: 100%; font-weight: 700; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.mf { display: grid; gap: 2px; font-size: 13px; color: var(--muted); width: 72px; }
.mf.grow { flex: 1; min-width: 140px; }
.mf input { color: var(--text); }

.loot .sub { font-weight: 700; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; margin: 16px 0 8px; }
.loot .sub:first-child { margin-top: 0; }
.loot-row { display: grid; grid-template-columns: 1fr 62px 110px 44px; gap: 6px; margin-bottom: 6px; }
.quest { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); }
.qcheck { display: flex; align-items: center; gap: 10px; min-height: 44px; flex: 1; cursor: pointer; }
.qcheck input { width: 20px; height: 20px; accent-color: var(--accent); }
.quest.done span { text-decoration: line-through; color: var(--muted); }

@media (max-width: 1100px) {
  .host-grid { grid-template-columns: 1fr 1fr; }
  .host-grid > .panel:nth-child(2) { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 720px) {
  .host-grid { grid-template-columns: 1fr; }
}
@media (max-width: 380px) {
  .stat b { font-size: 19px; }
  .hp-ctrl { grid-template-columns: 1fr 56px 1fr; }
  .hp-ctrl .ghost { grid-column: 1 / -1; }
  .list.two { grid-template-columns: 1fr; }
}

/* ---- v2: explanations, signature moves, switches ---- */
.hint { margin: -4px 0 12px; font-size: 13px; color: var(--muted); text-align: center; }
.help-btn {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-weight: 700; font-size: 14px; line-height: 1; padding: 0; flex: none; position: relative;
}
.help-btn::after { content: ''; position: absolute; inset: -9px; }
.help-btn:hover { color: var(--text); border-color: var(--muted); }
.card-head .row { gap: 8px; }
.card-head.bare { margin: 4px 2px 8px; }
.help-sheet {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 35;
  width: min(460px, calc(100% - 32px)); transform: translate(-50%, 160%); transition: transform .22s ease;
  background: #262a33; border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
}
.help-sheet.show { transform: translate(-50%, 0); }
.help-title { font-family: var(--display); font-weight: 700; font-size: 18px; }
.help-body { margin: 8px 0 12px; line-height: 1.5; }
.help-sheet .btn { margin-bottom: 10px; width: 100%; }
.help-sheet .link { padding: 0; min-height: 0; text-decoration: none; }
.sig-card { border-color: color-mix(in srgb, var(--pc) 55%, var(--line)); background: linear-gradient(var(--panel), var(--panel)) padding-box; }
.sig { border-top: 1px solid var(--line); }
.sig:first-of-type { border-top: 0; }
.sig summary { list-style: none; cursor: pointer; padding: 10px 0; display: grid; gap: 2px; }
.sig summary::-webkit-details-marker { display: none; }
.sig-name { font-weight: 700; font-size: 18px; color: var(--pc); filter: brightness(1.25); }
.sig-short { color: var(--muted); font-size: 15px; }
.sig p { margin: 0 0 12px; color: #ddd7cc; line-height: 1.5; }
.sig[open] .sig-short { display: none; }
.flaw { margin: 10px 0 0; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 15px; color: #e6c9c9; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.toggle {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px 0 8px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--bg); font-weight: 700; color: var(--muted);
}
.toggle .knob { width: 36px; height: 22px; border-radius: 99px; background: #3a3f4b; position: relative; transition: background .15s; }
.toggle .knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #c9ccd3; transition: transform .15s; }
.toggle.on { color: var(--text); border-color: var(--pc); }
.toggle.on .knob { background: var(--pc); }
.toggle.on .knob::after { transform: translateX(14px); background: #fff; }
.toggle-edit { margin: 8px 0; padding-top: 8px; border-top: 1px dashed var(--line); }
.toggle-edit .grow { flex: 1; }
.spell-label { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: var(--panel-2); color: var(--muted); font-style: italic; }
.row-card .help-btn { margin-left: -4px; }
.chip.toggle-chip.on { background: color-mix(in srgb, var(--pc) 30%, var(--bg)); border-color: var(--pc); color: var(--text); }
.state-text { color: var(--accent); font-weight: 700; }
.sed-text { color: #9fc6ff; }
.sed { display: flex; align-items: center; gap: 4px; }
.sed-lbl { font-size: 12px; color: #9fc6ff; text-transform: uppercase; letter-spacing: .05em; }
.sed-n { min-width: 18px; text-align: center; font-weight: 700; color: #9fc6ff; }
.step.sm { min-width: 32px; height: 32px; font-size: 15px; }

/* ---- v3: portraits & character select ---- */
.portrait {
  display: inline-grid; place-items: center; flex: none; border-radius: 50%; overflow: hidden;
  background: color-mix(in srgb, var(--pc) 32%, #15171c); box-shadow: 0 0 0 2px var(--pc);
  font-family: var(--display); font-weight: 700; color: var(--text);
}
.portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.portrait.icon svg, .icon-pick svg { width: 60%; height: 60%; fill: none; stroke: #f6efe3; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.pick-title { font-family: var(--display); font-size: 20px; margin: 14px 0 12px; }
.char-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.char-tile {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 18px 12px 14px;
  border-radius: 18px; background: var(--panel); border: 1px solid var(--line); color: var(--text); text-decoration: none;
  position: relative; overflow: hidden;
}
.char-tile::before { content: ''; position: absolute; inset: 0 0 auto; height: 64px; background: linear-gradient(color-mix(in srgb, var(--pc) 30%, transparent), transparent); }
.char-tile > * { position: relative; }
.char-tile.last { border-color: var(--pc); }
.char-tile:active { transform: scale(.98); }
.tile-portrait { margin-bottom: 8px; box-shadow: 0 0 0 3px var(--pc), 0 8px 20px rgba(0,0,0,.4); }
.tile-player { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--pc); filter: brightness(1.3); }
.tile-name { font-weight: 700; font-size: 17px; line-height: 1.2; }
.tile-class { font-size: 14px; color: var(--muted); }
.char-tile .hpbar { width: 100%; height: 6px; margin: 8px 0 2px; }
.tile-hp { font-size: 13px; color: var(--muted); }
.tb-portrait { border: 0; background: none; padding: 0; border-radius: 50%; flex: none; }
.edit-portrait { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.edit-portrait p { margin: 2px 0 0; }
.portrait-btn { position: relative; border: 0; background: none; padding: 4px; border-radius: 50%; flex: none; }
.portrait-edit { position: absolute; right: 0; bottom: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.portrait-edit .ic { width: 16px; height: 16px; }
.picker-sheet { max-height: 80vh; overflow-y: auto; }
.picker-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.picker-actions .btn { width: auto; margin: 0; flex: 1; cursor: pointer; }
.icon-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.icon-pick { aspect-ratio: 1; border-radius: 50%; border: 0; background: color-mix(in srgb, var(--pc) 32%, #15171c); display: grid; place-items: center; padding: 0; }
.icon-pick.on { box-shadow: 0 0 0 3px var(--accent); }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.pcard-head { align-items: center; gap: 10px; }
.pcard-head .grow { flex: 1; min-width: 0; }
.ini-row .portrait { box-shadow: 0 0 0 2px var(--pc); }
@media (min-width: 560px) { .char-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- Levels, XP and point buy ---------- */
.levelup-banner {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 44px; margin-bottom: 12px;
  padding: 8px 12px; border-radius: 12px; border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--panel));
  color: var(--text); font-weight: 700; font-size: 15px;
}
.card.ready { border-color: var(--accent); }
.xp-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.xp-level { font-size: 18px; }
.xp-level b { font-size: 28px; }
.xpbar .fill { background: var(--accent); }
.xp-ctrl { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.xp-award { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.levelup-tag { background: var(--accent); color: var(--accent-ink); text-decoration: none; }
.gets { margin: 0 0 12px; padding-left: 20px; display: grid; gap: 4px; }
.gain { margin: 10px 0 4px; }
.tab-body .sub { font-weight: 700; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; margin: 16px 0 8px; }
.tab-body .sub:first-of-type { margin-top: 4px; }
.lu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.budgets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.budget { padding: 4px 10px; border-radius: 99px; background: var(--panel-2); font-size: 14px; color: var(--muted); }
.budget b { color: var(--text); }
.budget.full b { color: var(--good); }
.budget.over { background: #3a1f23; }
.budget.over b { color: var(--bad); }
.build-row { padding: 10px 0; border-top: 1px solid var(--line); }
.build-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.build-name { font-weight: 700; }
.build-total b { font-size: 22px; }
.build-steps, .asi-grid { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.mini-step { display: inline-flex; align-items: center; gap: 6px; }
.mini-step .mini-label { font-size: 13px; color: var(--muted); min-width: 0; }
.mini-step .step-val { min-width: 26px; font-size: 16px; }
.mini-step .step:disabled { opacity: .35; }
.asi-grid .mini-label { min-width: 52px; }
.rcheck { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rcheck .grow { flex: 1; }
.rcheck-mark { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--panel-2); color: var(--muted); }
.rcheck.ok .rcheck-mark { background: #1b3328; color: var(--good); }
.rcheck.bad .rcheck-mark { background: #3a1f23; color: var(--bad); }
.level-table summary { font-weight: 700; min-height: 32px; cursor: pointer; }
.level-table table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.level-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 6px; }
.level-table td { padding: 6px; border-top: 1px solid var(--line); }
.level-table tr.now td { background: color-mix(in srgb, var(--accent) 16%, transparent); font-weight: 700; }
.level-table { overflow-x: auto; }
.cost-strip { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 4px 0 8px; }
.cost-strip span { display: grid; justify-items: center; padding: 4px 0; border-radius: 8px; background: var(--panel-2); font-size: 12px; color: var(--muted); }
.cost-strip b { font-size: 15px; color: var(--text); }

/* ---------- Table screen, DM screen, giving items ---------- */
.dm-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; margin-top: 16px; }
@media (max-width: 1100px) { .dm-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px) { .dm-grid { grid-template-columns: 1fr; } }
.lib-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.lib-row .grow { flex: 1; min-width: 160px; }
.lib-row select { width: auto; min-width: 110px; flex: none; }
.lib-name { font-weight: 700; }
.mf.full { width: 100%; }
.mf.wide { width: 130px; }
.mf textarea, .mf select { color: var(--text); }
.sub-title { font-weight: 700; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; margin: 14px 0 8px; }
.sub-title:first-child { margin-top: 0; }
span.ini-num.ro { display: grid; place-items: center; min-height: 40px; width: 48px !important; color: var(--muted); }
.host.table .pc-name { font-family: var(--display); font-weight: 700; }
.host.table .coin b { font-size: 18px; color: var(--text); }
.host.table .quest { min-height: 40px; }
.inv-wrap + .inv-wrap { border-top: 1px solid var(--line); }
.give-box { display: grid; gap: 8px; padding: 10px 12px; margin: 0 0 10px; border-radius: 12px; background: var(--panel-2); }

/* ---------- DM columns, side tabs, inventories, quests ---------- */
.host-grid > .col { display: grid; gap: 16px; align-content: start; min-width: 0; }
@media (max-width: 1100px) { .host-grid.dm-cols > .col:nth-child(2) { grid-column: 1 / -1; order: -1; } }
.seg { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; min-height: 40px; padding: 0 10px; border-radius: 99px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-weight: 700; white-space: nowrap; }
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.inv-block { border-left: 4px solid var(--pc); padding: 4px 0 12px 12px; margin-top: 14px; }
.inv-owner { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.inv-owner .grow { flex: 1; min-width: 0; }
.lib-row.tight { padding: 6px 0; flex-wrap: nowrap; }
.lib-row.tight .grow { min-width: 0; }
.q-card { border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; background: var(--bg); }
.q-card.tracked { border-color: var(--accent); }
.q-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
.q-head input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.q-title { flex: 1; min-width: 0; min-height: 44px; text-align: left; background: none; border: 0; color: var(--text); font-weight: 700; font-size: 16px; }
.q-card.done .q-title span:first-child { text-decoration: line-through; color: var(--muted); }
.q-body { display: grid; gap: 8px; padding: 4px 12px 12px; border-top: 1px dashed var(--line); }
.quest-track { border: 1px solid var(--accent); border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; background: color-mix(in srgb, var(--accent) 9%, var(--bg)); }
.quest-track.done { border-color: var(--good); background: color-mix(in srgb, var(--good) 9%, var(--bg)); }
.qt-label { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.quest-track.done .qt-label { color: var(--good); }
.qt-title { font-family: var(--display); font-weight: 700; font-size: 24px; line-height: 1.2; margin: 2px 0 6px; }
.qt-desc { margin: 0 0 8px; color: #ddd7cc; }
.qt-steps { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
.qt-steps li { display: flex; gap: 10px; align-items: baseline; font-size: 18px; }
.qt-steps li.done { color: var(--muted); text-decoration: line-through; }
.qt-mark { flex: none; width: 20px; text-align: center; color: var(--accent); text-decoration: none; display: inline-block; }
.qt-steps li.done .qt-mark { color: var(--good); }
.qt-reward { margin-top: 8px; font-size: 15px; color: var(--muted); }
.qt-reward b { color: var(--text); }

/* ---------- Money ---------- */
.money-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.money-head .grow { flex: 1; min-width: 120px; }
.money-head + .give-box { margin-top: 10px; }
.chip:disabled { opacity: .4; }
.wealth { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--panel-2); }
.wealth b { font-size: 20px; color: var(--accent); }
.purses { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 14px; color: var(--muted); }
.purse b { color: var(--text); }
.ledger { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.wealth-box { margin-bottom: 4px; }
.wealth-box .wealth { margin-top: 0; }
.wealth-box .wealth span { font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .04em; }
.wealth-box .wealth b { font-size: 28px; }
.loot .wealth-box + .sub { margin-top: 16px; }
.loot .wealth-box { margin-top: 16px; }
