:root {
  --bg: #f2eadd;
  --surface: #fffdf8;
  --surface-2: #f5eee2;
  --border: #dfd2bd;
  --text: #2a1e24;
  --muted: #7b6b65;
  --accent: #c9255f;
  --accent-ink: #ffffff;
  --accent-soft: #fbe0ea;
  --gold: #a57c22;
  --pc: #2f78bd;
  --npc: #2a9366;
  --monster: #bf4410;
  --hp-good: #2f9e6e;
  --hp-mid: #d6951a;
  --hp-low: #d6336c;
  --temp: #5f80d0;
  --die-1: #fbd3e1; --die-2: #f28db0; --die-3: #e8628f; --die-4: #d6336c; --die-5: #b0234f; --die-6: #8a1a3d;
  --die-edge: #7a1636; --die-ink: #6b0f2c;
  --shadow: 0 1px 2px rgba(60, 35, 20, .08), 0 6px 18px rgba(60, 35, 20, .08);
  --shadow-lg: 0 24px 70px rgba(40, 20, 10, .35);
  --hi: rgba(255, 255, 255, .75);
  --grain: .05;
  --radius: 14px;
  --display: Cinzel, "Trajan Pro", Georgia, serif;
  --serif: Alegreya, Georgia, serif;
  --line: color-mix(in srgb, var(--gold) 45%, transparent);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #120d13; --surface: #1d161d; --surface-2: #281f28; --border: #3b2f3a;
    --text: #f5edf0; --muted: #ac9da6; --accent: #f06595; --accent-ink: #1f0a13;
    --accent-soft: #3e1c2c; --gold: #d8b36a; --pc: #6aa8e0; --npc: #4fc08d; --monster: #f08a4b;
    --hp-good: #4fc08d; --hp-mid: #f0b84a; --hp-low: #f06595; --temp: #8aa6ee;
    --die-edge: #3d0a1c;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.3);
    --shadow-lg: 0 24px 80px rgba(0,0,0,.6);
    --hi: rgba(255, 255, 255, .06);
    --grain: .07;
    color-scheme: dark;
  }
  select option, select optgroup { background: #2a2529; color: #ffffff; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { scrollbar-color: var(--border) transparent; }
body {
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, sans-serif;
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 50% -180px, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(900px 600px at 100% 100%, color-mix(in srgb, var(--gold) 12%, transparent), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
/* Paper grain, and a faint arcane d20 seal in the corner */
body::before, body::after { content: ""; position: fixed; z-index: -1; pointer-events: none; }
body::before {
  inset: 0; opacity: var(--grain);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}
body::after {
  right: -150px; bottom: -150px; width: 620px; height: 620px; opacity: .11; background: var(--gold);
  -webkit-mask: var(--seal) center / contain no-repeat; mask: var(--seal) center / contain no-repeat;
  --seal: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400' fill='none' stroke='%23000' stroke-width='1.6' stroke-linejoin='round'%3E%3Ccircle cx='200' cy='200' r='196'/%3E%3Ccircle cx='200' cy='200' r='186' stroke-dasharray='2 9' stroke-width='4'/%3E%3Ccircle cx='200' cy='200' r='172'/%3E%3Cpath d='M200 50 330 125V275L200 350 70 275V125zM200 120l70 120H130zM200 50v70M330 125l-130-5M70 125l130-5M330 125l-60 115M70 125l60 115M330 275l-60-35M70 275l60-35M200 350l70-110M200 350l-70-110'/%3E%3Cpath d='M200 4v24M200 372v24M4 200h24M372 200h24M61 61l17 17M322 322l17 17M339 61l-17 17M78 322l-17 17'/%3E%3C/svg%3E");
}
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
select option, select optgroup { background: #ffffff; color: #000000; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .03em; margin: 0; }
.spacer { flex: 1; }
.num, #roundNum, .init-badge .val, .stat .v, .hp-num, .roll-table .tot { font-family: var(--serif); font-variant-numeric: lining-nums tabular-nums; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 1px 0 var(--border), 0 8px 24px -18px rgba(0, 0, 0, .5);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--gold) 20%, var(--accent) 50%, var(--gold) 80%, transparent); opacity: .7;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 21px; letter-spacing: .06em; white-space: nowrap; }
.d20 { width: 42px; height: 42px; flex: none; filter: drop-shadow(0 2px 4px rgba(120, 20, 50, .45)); }

.bar-center { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.dead-count { color: var(--muted); font-weight: 500; }
.round-box {
  display: flex; align-items: center; gap: 2px; padding: 3px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line); border-radius: 12px; box-shadow: inset 0 1px 0 var(--hi);
}
.round { display: flex; flex-direction: column; align-items: center; line-height: 1; min-width: 54px; }
.round-label { font-family: var(--display); font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .16em; color: var(--gold); }
#roundNum { font-size: 24px; font-weight: 800; }
.step {
  width: 28px; height: 36px; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 14px;
}
.step:hover { background: var(--accent-soft); color: var(--accent); }
.turn-ctrl { display: flex; align-items: center; gap: 8px; }
.actions { display: flex; align-items: center; gap: 8px; justify-self: end; }

/* ---------- Campaign settings & XP ---------- */
.toggle-row {
  flex-direction: row; align-items: flex-start; gap: 12px; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); color: var(--text);
  transition: border-color .15s, background .15s;
}
.toggle-row input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.toggle-row b { display: block; font-size: 14px; }
.toggle-row small { display: block; font-weight: 400; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.toggle-row:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface-2)); }
.xp-only { display: none !important; }
body.xp-on .xp-only { display: revert !important; }
body.xp-on #xpRow { display: flex !important; }
#xpRow .btn { flex: none; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: linear-gradient(180deg, var(--surface), var(--surface-2));
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
  box-shadow: inset 0 1px 0 var(--hi), 0 1px 2px rgba(0, 0, 0, .08);
  transition: background .15s, border-color .15s, box-shadow .15s, filter .15s, transform .05s;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-accent, .btn-primary {
  color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 80%, #000);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 86%, #fff), var(--accent) 55%, color-mix(in srgb, var(--accent) 88%, #000));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 2px 10px color-mix(in srgb, var(--accent) 35%, transparent);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .12);
}
.btn-accent:hover, .btn-primary:hover { filter: brightness(1.08); border-color: color-mix(in srgb, var(--accent) 80%, #000); }
.btn-gold {
  color: var(--gold); border-color: var(--line);
  background: color-mix(in srgb, var(--gold) 9%, var(--surface));
}
.btn-gold:hover { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 18%, var(--surface)); }
.btn-ic { display: inline-flex; align-items: center; gap: 7px; }
.ic { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface-2)); cursor: pointer; font-size: 20px; line-height: 1;
  display: grid; place-items: center; box-shadow: inset 0 1px 0 var(--hi);
}
.icon-btn:hover { border-color: var(--gold); }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column;
  animation: pop .12s ease-out; z-index: 2;
}
.menu-list button {
  display: flex; align-items: center; gap: 10px; text-align: left; background: none; border: 0;
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-weight: 500;
}
.menu-list button .ic { color: var(--gold); }
.menu-list button:hover { background: var(--surface-2); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
.danger, .menu-list .danger .ic { color: var(--hp-low); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---------- Ornaments ---------- */
.flourish { display: flex; align-items: center; gap: 10px; width: min(260px, 70%); margin: 14px auto; color: var(--gold); }
.flourish::before, .flourish::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, currentColor); }
.flourish::after { transform: scaleX(-1); }
.flourish i { width: 7px; height: 7px; transform: rotate(45deg); background: currentColor; box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px currentColor; }

/* ---------- List of combatants ---------- */
main { padding: 22px 24px 48px; max-width: 1500px; margin: 0 auto; }
.empty { text-align: center; padding: 56px 16px 64px; color: var(--muted); }
.empty .d20 { width: 96px; height: 96px; filter: drop-shadow(0 10px 22px color-mix(in srgb, var(--accent) 45%, transparent)); animation: float 5s ease-in-out infinite; }
.empty h2 { color: var(--text); font-size: 28px; margin: 6px 0 8px; }
.empty p { margin: 0; font-family: var(--serif); font-size: 17px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
@keyframes float { 50% { transform: translateY(-6px) rotate(3deg); } }

.list-head, .row {
  display: grid;
  grid-template-columns: 58px minmax(200px, 1.3fr) 232px minmax(340px, 1.7fr) minmax(160px, 1.3fr) 150px;
  grid-template-areas: "badge name stats hp conds acts";
  column-gap: 16px; align-items: center;
}
body.xp-on .list-head, body.xp-on .row {
  grid-template-columns: 58px minmax(200px, 1.3fr) 300px minmax(340px, 1.7fr) minmax(160px, 1.3fr) 150px;
}
.row { min-height: 80px; }
.list-head {
  padding: 0 14px 8px 20px; font-family: var(--display); font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .14em; color: var(--gold);
}
.lh-stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 4px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-foot { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.switch { flex: none; flex-direction: row; align-items: center; gap: 9px; cursor: pointer; user-select: none; font-size: 13px; font-weight: 600; color: var(--text); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; width: 36px; height: 20px; border-radius: 999px; flex: none;
  background: var(--surface-2); border: 1px solid var(--border); transition: background .15s, border-color .15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform .15s, background .15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: var(--accent-ink); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.row {
  --kind: var(--pc);
  position: relative; border: 1px solid var(--border);
  background: linear-gradient(90deg, color-mix(in srgb, var(--kind) 9%, var(--surface)), var(--surface) 30%);
  border-radius: var(--radius); box-shadow: inset 0 1px 0 var(--hi), var(--shadow); padding: 10px 14px 10px 20px;
  transition: box-shadow .2s, border-color .2s, opacity .2s;
}
.row::before {
  content: ""; position: absolute; inset: 9px auto 9px 7px; width: 4px; border-radius: 4px; background: var(--kind);
  box-shadow: 0 0 10px color-mix(in srgb, var(--kind) 55%, transparent);
}
.row.kind-npc { --kind: var(--npc); }
.row.kind-monster { --kind: var(--monster); }
.row.active {
  border-color: var(--accent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 16%, var(--surface)), color-mix(in srgb, var(--accent) 4%, var(--surface)) 45%);
  box-shadow: inset 0 1px 0 var(--hi), 0 0 0 3px var(--accent-soft), 0 8px 28px -6px color-mix(in srgb, var(--accent) 45%, transparent);
}
.row.dead { opacity: .5; }
.row.dead .name { text-decoration: line-through; text-decoration-thickness: 2px; }
.row.benched { opacity: .45; border-style: dashed; }

.c-badge { grid-area: badge; }
.c-name { grid-area: name; min-width: 0; }
.c-stats { grid-area: stats; }
.c-hp { grid-area: hp; }
.c-conds { grid-area: conds; }
.c-acts { grid-area: acts; }

/* Initiative badge: a d20 silhouette. The outer shape is the border, ::before the face. */
.c-badge { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .18)); }
.init-badge {
  --hex: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  position: relative; width: 54px; height: 60px; background: var(--line); clip-path: var(--hex);
  display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; line-height: 1;
  transition: background .15s;
}
.init-badge::before {
  content: ""; position: absolute; inset: 1.5px; clip-path: var(--hex);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}
.init-badge > * { position: relative; }
.init-badge:hover { background: var(--accent); }
.init-badge .val { font-weight: 800; font-size: 25px; }
.init-badge .lbl { font-family: var(--display); font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin-top: 1px; }
.init-badge.nat20 { background: var(--accent); }
.init-badge.nat20::before { background: var(--accent-soft); }
.init-badge.nat20 .val { color: var(--accent); }
.row.active .init-badge { background: color-mix(in srgb, var(--accent) 70%, #000); }
.row.active .init-badge::before { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 85%, #fff), var(--accent)); }
.row.active .init-badge .val, .row.active .init-badge .lbl { color: var(--accent-ink); }

.name {
  font-family: var(--serif); font-weight: 800; font-size: 20px; line-height: 1.2; letter-spacing: 0; margin: 0; cursor: text;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 6px;
}
.name:hover, .hp-cur:hover { background: var(--surface-2); box-shadow: 0 0 0 4px var(--surface-2); }
/* One line, cut off rather than wrapped, so rows never change height */
.meta { display: flex; gap: 6px; align-items: center; margin-top: 2px; flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
.meta > * { flex: none; }
.meta .roll-detail { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--kind); background: color-mix(in srgb, var(--kind) 14%, transparent); padding: 2px 7px; border-radius: 999px;
}
.tag.status { color: var(--hp-low); background: color-mix(in srgb, var(--hp-low) 14%, transparent); }
.tag.stable { color: var(--hp-good); background: color-mix(in srgb, var(--hp-good) 14%, transparent); }
.roll-detail { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.notes { font-family: var(--serif); font-style: italic; font-size: 13px; color: var(--muted); margin: 1px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.inline-input {
  font: inherit; width: 100%; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--surface-2); outline: none;
}

.c-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; cursor: pointer; }
body.xp-on .c-stats, body.xp-on .lh-stats { grid-template-columns: repeat(4, 1fr) 1.4fr; }
.stat {
  background: var(--surface-2); border-radius: 9px; padding: 5px 2px; text-align: center;
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent); transition: border-color .15s;
}
.c-stats:hover .stat { border-color: var(--line); }
.stat .v { font-weight: 700; font-size: 17px; line-height: 1.25; }
.stat .k { display: none; font-family: var(--display); font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }

.c-hp { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 4px 12px; align-items: center; min-width: 0; }
.hp-ctrl button { flex: none; }
.hp-read { display: flex; flex-direction: column; gap: 5px; }
.hp-num { font-weight: 800; font-size: 20px; line-height: 1; white-space: nowrap; }
.hp-cur { cursor: text; border-radius: 4px; }
.hp-num small { color: var(--muted); font-weight: 500; font-size: 14px; }
.hp-num .inline-input { width: 54px; font-size: 16px; }
.hp-temp { font-family: Inter, sans-serif; font-size: 11px; font-weight: 700; color: var(--temp); margin-left: 5px; }
.bar {
  position: relative; height: 9px; border-radius: 999px; overflow: hidden; display: flex;
  background: color-mix(in srgb, var(--hp-low) 28%, var(--surface-2));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hp-low) 40%, transparent), inset 0 2px 3px rgba(0, 0, 0, .25);
}
/* Gloss and quarter marks over the fill */
.bar::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .38), transparent 55%),
    repeating-linear-gradient(90deg, transparent 0 calc(25% - 1px), rgba(0, 0, 0, .28) calc(25% - 1px) 25%);
}
.bar .fill { height: 100%; background: var(--hp-good); box-shadow: 2px 0 0 0 var(--surface); transition: width .3s, background .3s; }
.bar .fill[style*="width:100%"] { box-shadow: none; }
.bar .tmp { height: 100%; background: var(--temp); transition: width .3s; }
.hp-ctrl { display: flex; gap: 4px; }
.hp-ctrl input {
  flex: 1; width: 0; min-width: 48px; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); font-variant-numeric: tabular-nums; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .08);
}
.hp-ctrl input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.hp-ctrl button {
  --c: var(--muted);
  border: 1px solid color-mix(in srgb, var(--c) 35%, var(--border)); border-radius: 8px;
  background: color-mix(in srgb, var(--c) 9%, var(--surface)); color: var(--c);
  padding: 0 9px; cursor: pointer; font-size: 12px; font-weight: 700; transition: background .15s, border-color .15s;
}
.hp-ctrl button:hover { border-color: var(--c); background: color-mix(in srgb, var(--c) 20%, var(--surface)); }
.hp-ctrl .dmg { --c: var(--hp-low); }
.hp-ctrl .heal { --c: var(--hp-good); }
.hp-ctrl .tmpb { --c: var(--temp); }

.death { display: flex; align-items: center; gap: 8px; height: 9px; }
.pips { display: inline-flex; gap: 3px; }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; background: transparent; cursor: pointer; padding: 0; }
.pips.s { color: var(--hp-good); }
.pips.f { color: var(--hp-low); }
.pip.on { background: currentColor; }

.c-conds { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chip {
  font-size: 12px; font-weight: 600; padding: 2px 3px 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; gap: 3px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}
.chip input.rounds {
  width: 30px; padding: 0 2px; border: 0; border-radius: 6px; text-align: center; font-size: 11px; font-weight: 700;
  background: color-mix(in srgb, var(--accent) 15%, transparent); color: inherit; -moz-appearance: textfield;
}
.chip input.rounds::-webkit-inner-spin-button, .chip input.rounds::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.chip input.rounds::placeholder { color: inherit; opacity: .6; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1; }
.c-conds select {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px dashed var(--border);
  background: transparent; color: var(--muted); cursor: pointer; appearance: none;
}
.c-conds select:hover { border-color: var(--accent); color: var(--accent); }

.c-acts { display: flex; gap: 2px; justify-content: flex-end; }
.c-acts button {
  width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: none;
  color: var(--muted); border-radius: 8px; cursor: pointer; padding: 0; transition: background .15s, color .15s;
}
.c-acts button:hover { background: var(--surface-2); color: var(--text); }
.c-acts button.rm:hover { color: var(--hp-low); background: color-mix(in srgb, var(--hp-low) 12%, transparent); }
.c-acts svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Event log ---------- */
.log {
  margin-top: 36px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--hi), var(--shadow); overflow: hidden;
}
.log-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.log-head h2 { font-size: 16px; letter-spacing: .1em; text-transform: uppercase; }
.log-head h2::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 10px; transform: rotate(45deg) translateY(-2px); background: var(--gold); }
.log-body { max-height: 360px; overflow: auto; border-top: 1px solid var(--border); }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.log-table th {
  position: sticky; top: 0; background: var(--surface-2); text-align: left; font-family: var(--display); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em; color: var(--gold); padding: 8px 16px; box-shadow: 0 1px 0 var(--border);
}
.log-table td { padding: 6px 16px; border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.log-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.log-table tbody tr:hover td { background: var(--accent-soft); }
.log-table td:first-child { color: var(--muted); width: 70px; }
.log-table .who { font-weight: 600; }
.log-table .before { color: var(--muted); }
.log-empty { color: var(--muted); font-size: 13px; padding: 12px 16px 16px; margin: 0; }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 32px));
  background:
    radial-gradient(420px 160px at 50% 0, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    var(--surface);
  color: var(--text); box-shadow: var(--shadow-lg);
  outline: 1px solid color-mix(in srgb, var(--gold) 28%, transparent); outline-offset: -6px;
}
dialog[open] { animation: rise .16s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.985); } }
dialog.wide { width: min(620px, calc(100vw - 32px)); }
dialog.xwide { width: min(1452px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 8, 12, .6); backdrop-filter: blur(4px); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font-size: 21px; letter-spacing: .05em; }
dialog form > h2 { padding-bottom: 12px; border-bottom: 1px solid transparent; border-image: linear-gradient(90deg, var(--gold), transparent 85%) 1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); flex: 1; }
label input, label select, label textarea {
  padding: 9px 11px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 15px; font-weight: 500; width: 100%; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .06);
}
label input:focus, label select:focus, label textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label input:read-only { opacity: .7; }
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row .grow { flex: 2; }
.hint { font-size: 12px; color: var(--muted); margin: 0; flex: 2; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 4px; }

.roll-scroll { max-height: 60vh; overflow: auto; }
.roll-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.roll-table th { text-align: left; font-family: var(--display); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--gold); font-weight: 700; padding: 4px 6px; }
.roll-table td { padding: 6px; border-top: 1px solid var(--border); height: 44px; }
.roll-table td.nm { font-weight: 600; }
.roll-table select { padding: 5px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }
.roll-table .die { font-weight: 700; font-size: 16px; white-space: nowrap; }
.roll-table .die .drop { color: var(--muted); font-weight: 500; text-decoration: line-through; font-size: 14px; }
.roll-table .die .sep { color: var(--muted); font-weight: 400; margin: 0 4px; }
.roll-table .tot { font-weight: 800; font-size: 20px; color: var(--accent); }

/* ---------- Avatars ---------- */
.c-name { display: flex; align-items: center; gap: 12px; }
.name-text { min-width: 0; flex: 1; }
.avatar {
  flex: none; width: 46px; height: 46px; border-radius: 50%; overflow: hidden; padding: 0;
  display: grid; place-items: center; border: 2px solid var(--kind, var(--accent));
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--kind, var(--accent)) 34%, var(--surface)), color-mix(in srgb, var(--kind, var(--accent)) 14%, var(--surface-2)));
  color: var(--kind, var(--accent)); font-family: var(--display); font-weight: 700; font-size: 15px; letter-spacing: .04em; cursor: pointer;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px color-mix(in srgb, var(--kind, var(--accent)) 35%, transparent);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar:hover { filter: brightness(1.08); }
.avatar-edit { display: flex; align-items: center; gap: 16px; }
.avatar-btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.avatar-btns .hint { flex-basis: 100%; }
.avatar.lg { width: 72px; height: 72px; font-size: 22px; }
.avatar.sm { width: 36px; height: 36px; font-size: 12px; cursor: default; }
.row.dead .avatar { filter: grayscale(1); }

/* ---------- Event log archive ---------- */
.arch-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.arch-filters label { flex: 0 1 130px; }
.arch-filters .arch-search { flex: 1 1 220px; }
.arch-filters label:first-child { flex: 0 1 auto; }
.arch-date { display: flex; gap: 6px; align-items: center; }
.arch-date input { width: auto; }
.arch-scroll { height: min(56vh, 560px); overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.arch-table td { white-space: nowrap; }
.arch-table td:first-child { width: auto; }
.arch-table .when { color: var(--muted); }
#archInfo { font-size: 12px; }

/* ---------- Search lists ---------- */
.search-input {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-size: 15px;
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.list-empty { color: var(--muted); text-align: center; padding: 30px 0; margin: 0; font-family: var(--serif); font-size: 16px; font-style: italic; }

/* ---------- Victory / XP award ---------- */
.victory-head { display: flex; align-items: center; gap: 14px; }
.victory-flag {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--gold);
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--gold) 30%, var(--surface)), color-mix(in srgb, var(--gold) 10%, var(--surface)));
  box-shadow: inset 0 0 0 1px var(--line), 0 0 0 4px color-mix(in srgb, var(--gold) 12%, transparent);
}
.victory-flag .ic { width: 24px; height: 24px; }
.victory-head h2 { font-size: 26px; }
.xp-award { display: flex; flex-direction: column; gap: 10px; }
.xp-list { display: flex; flex-direction: column; gap: 6px; max-height: 44vh; overflow: auto; }
.xp-item { display: flex; align-items: center; gap: 12px; padding: 6px 10px; border-radius: 12px; background: var(--surface-2); border: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.xp-item .pool-main { flex: 1; }
.xp-item input {
  width: 96px; padding: 7px 9px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
  font-variant-numeric: tabular-nums; text-align: right;
}
.xp-item input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Combatant pool ---------- */
.pool-count { font-family: Inter, sans-serif; font-size: 13px; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-left: 6px; }
.pool-list { display: flex; flex-direction: column; gap: 6px; height: min(48vh, 420px); overflow: auto; padding: 2px; }
.pool-list > * { flex: none; }
.pool-list .art-head { margin: 8px 2px 0; }
.pool-filter { display: flex; gap: 8px; }
.pool-filter input { flex: 1; min-width: 0; }
.pool-filter select { flex: 0 1 220px; min-width: 0; }
.pool-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); border: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.pool-item:hover { border-color: var(--line); }
.pool-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pool-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pool-main small { color: var(--muted); font-size: 12px; }
.pool-forget { width: 32px; height: 32px; color: var(--muted); }
.pool-forget svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pool-forget:hover { color: var(--hp-low); border-color: var(--hp-low); }

/* ---------- Access gate & roles ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; overflow: auto;
  background:
    radial-gradient(700px 420px at 50% 30%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(14px);
}
.gate-card {
  width: min(400px, 100%); border: 1px solid var(--line); border-radius: 22px;
  background: radial-gradient(360px 200px at 50% 0, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%), var(--surface);
  box-shadow: var(--shadow-lg); padding: 34px 28px 26px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  outline: 1px solid color-mix(in srgb, var(--gold) 28%, transparent); outline-offset: -7px;
}
.gate-die .d20 { width: 84px; height: 84px; filter: drop-shadow(0 10px 22px color-mix(in srgb, var(--accent) 50%, transparent)); animation: float 5s ease-in-out infinite; }
.gate-card h2 { font-size: 28px; letter-spacing: .08em; }
.gate-tag { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--gold); margin: -6px 0 0; }
.gate-msg { color: var(--muted); margin: 0 0 6px; }
.gate-fields { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.gate-fields input {
  padding: 12px 14px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface-2); font-size: 16px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .06);
}
.gate-fields input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.gate-fields .btn { padding: 12px; font-size: 15px; }
.gate-err { color: var(--hp-low); font-size: 13px; margin: 0; min-height: 1em; }
.gate-err:empty { display: none; }
.acct { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.acct .recent .gate-hint { width: 100%; }
.gate-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.gate-or::before, .gate-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.gate-hint { color: var(--muted); font-size: 12px; margin: 0; }
.gate-msg b { color: var(--text); }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; padding: 4px; }
.link-btn:hover { color: var(--text); }
.recent { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.recent:empty { display: none; }
.recent button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 5px 12px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.recent button:hover { border-color: var(--accent); color: var(--accent); }
.recent button small { color: var(--muted); font-size: 11px; margin-left: 4px; }
.recent .gate-hint { width: 100%; text-align: center; }
.recent .gate-hint .link-btn { font-size: 12px; padding: 0 2px; }
.copy-link {
  position: relative; color: var(--accent); font-weight: 600; cursor: copy;
  text-decoration: underline; text-underline-offset: 2px; word-break: break-all;
}
.copy-link:hover { filter: brightness(1.15); }
.copy-link.copied::after {
  content: "Copied!"; position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); font-size: 11px; padding: 2px 8px; border-radius: 6px; white-space: nowrap;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.camp-name { font-family: var(--serif); font-style: italic; font-size: 14px; font-weight: 500; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.camp-name:empty { display: none; }
.live-only { display: none !important; }
body.is-live .live-only { display: revert !important; }
body.is-live label.live-only, body.is-live .menu-list .live-only { display: flex !important; }

.live {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px 2px 7px; background: var(--surface);
}
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live.on { color: var(--hp-good); border-color: color-mix(in srgb, var(--hp-good) 40%, var(--border)); }
.live.on::before { background: var(--hp-good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hp-good) 25%, transparent); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }

.guest-only { display: none; }
body.readonly .guest-only { display: block; }
body.readonly .edit-only, body.readonly .step, body.readonly .c-acts, body.readonly .hp-ctrl,
body.readonly .c-conds select, body.readonly .chip button { display: none !important; }
body.readonly .list { pointer-events: none; }
body.readonly .c-hp { grid-template-columns: 1fr; }
body.readonly .chip { padding-right: 9px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; inset: auto auto 24px 50%; margin: 0; transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: #241a22; color: #f7eef2; padding: 11px 18px; border-radius: 12px; border: 1px solid var(--line);
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); z-index: 50; animation: rise .18s ease-out;
}

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .list-head { display: none !important; }
  .row, body.xp-on .row {
    grid-template-columns: 58px minmax(0, 1fr) 232px auto;
    grid-template-areas: "badge name stats acts" "badge hp hp hp" "badge conds conds conds";
    row-gap: 10px;
  }
  body.xp-on .row { grid-template-columns: 58px minmax(0, 1fr) 300px auto; }
  .stat .k { display: block; }
  .stat .v { line-height: 1.1; }
  .topbar { grid-template-columns: 1fr auto; }
  .bar-center { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 680px) {
  body::after { width: 380px; height: 380px; right: -120px; bottom: -120px; }
  dialog form { padding: 20px 18px; }
  dialog.xwide form { padding: 16px; }
  .arch-filters label, .arch-filters label:first-child { flex: 1 1 40%; }
  .arch-table th, .arch-table td { padding: 6px 10px; }
  .arch-scroll { height: 46vh; }
  .topbar { padding: 8px 14px 10px; gap: 8px 10px; }
  .brand h1 { font-size: 17px; }
  .d20 { width: 34px; height: 34px; }
  .bar-center { flex-wrap: nowrap; gap: 6px; }
  .bar-center .btn { padding: 9px 12px; }
  .bar-center .btn .lbl-wide { display: none; }
  #nextTurn { flex: 1; }
  .turn-ctrl { flex: 1; gap: 6px; }
  main { padding: 14px 12px 40px; }
  .row, body.xp-on .row {
    grid-template-columns: 54px minmax(0, 1fr);
    grid-template-areas: "badge name" "stats stats" "hp hp" "conds conds" "acts acts";
    padding: 12px 12px 8px 18px;
  }
  .c-hp { grid-template-columns: 1fr; }
  .bar { height: 10px; }
  /* 16px inputs stop iOS zooming in on focus; bigger touch targets */
  .hp-ctrl input, label input, label select, label textarea, .search-input, .xp-item input { font-size: 16px; }
  .hp-ctrl input, .hp-ctrl button { height: 40px; }
  .hp-ctrl button { padding: 0 12px; font-size: 13px; }
  .c-conds select { padding: 6px 12px; font-size: 13px; }
  .c-acts { justify-content: space-between; border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent); padding-top: 4px; }
  .c-acts button { width: 44px; height: 40px; }
  .c-acts svg { width: 18px; height: 18px; }
  .field-row { flex-wrap: wrap; }
  .list-foot .btn { flex: 1; padding: 11px 14px; }
  .log-table th, .log-table td { padding: 6px 10px; }
  .log-table td:first-child { width: 48px; }
  .toast { bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Premium ---------- */
.pro-tag {
  margin-left: auto; font-family: var(--display); font-size: 9px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--gold); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; background: color-mix(in srgb, var(--gold) 9%, transparent);
}
b > .pro-tag { margin-left: 8px; vertical-align: 2px; }
body.premium .pro-tag { display: none; }
.toggle-row:has(input:disabled) { opacity: .6; cursor: default; }
.pro-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; }
.pro-list li { padding-left: 22px; position: relative; }
.pro-list li::before { content: ""; position: absolute; left: 4px; top: 7px; width: 7px; height: 7px; transform: rotate(45deg); background: var(--gold); }
.pro-price { margin: 0; font-family: var(--serif); font-size: 19px; }
.pro-price b { font-size: 26px; color: var(--accent); }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { flex: 1; border: 0; background: none; padding: 7px 10px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Picture picker ---------- */
.btn > .pro-tag { margin-left: 6px; }
.art-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; height: min(40vh, 340px); overflow: auto; padding: 2px; align-content: start; }
.art-head { grid-column: 1 / -1; margin: 4px 0 0; font-family: var(--display); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.art-grid .list-empty { grid-column: 1 / -1; }
.art-tile {
  padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--surface-2);
  display: flex; flex-direction: column; transition: border-color .15s, transform .1s, box-shadow .15s;
}
.art-tile:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--accent) 50%, transparent); }
.art-tile img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.art-tile span { padding: 5px 6px; font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.art-gen { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.art-gen .hint { flex: 1; }
/* Preset art is waist-up: zoom the round avatar in on the head and chest */
.avatar img[src^="art/"] { transform: scale(1.55); transform-origin: 50% 8%; }

/* Popups with tabs keep one size whichever tab is showing */
dialog.fixed form { height: min(88vh, 680px); }
dialog.fixed form > * { flex: none; } /* .hint is flex: 2 elsewhere and would swallow the space */
dialog.fixed form > .pool-list, dialog.fixed form > .art-grid { flex: 1; height: auto; min-height: 0; }
.art-gen.off { visibility: hidden; }
