:root {
  --bg-1: #060a22; --bg-2: #12195a;
  --win-1: #2b41a3; --win-2: #141f66; --edge: #e8edff; --edge-in: #0a1140; --glow: #7186ec;
  --text: #f3f5ff; --dim: #b7c1ef; --cursor: #ffe27a; --select: #ffffff22;
  --action: #ff9466; --bonus: #ffd95e; --reaction: #6fd0ff; --free: #a8ef8a; --passive: #d4c4ff; --info: #c9d2ff;
  --temp-hp: #f3f5ff; --temp-edge: #7d86ad; --hp: #6be675; --hp-mid: #f5d04a; --hp-low: #ff6b5b;
  --you: #ffe27a; --target: #ff8fd8; --nat20: #7dffa0;
  --slot: #8fd3ff; --resource-1: #7dffd4; --resource-2: #ffb26b; --resource-3: #b5a8ff; --resource-4: #c6ff7a; --resource-5: #ff8b8b; --resource-6: #f2f28c; --resource-7: #ffffff;
  --radius: 10px;
  --font-heading: "Atkinson Hyperlegible", system-ui, sans-serif; --portrait-text: #fbefd2;
  /* Surfaces and lines inside Windows */
  --well: #0a1140; --well-soft: #0a114099; --on-accent: #10163f; --on-accent-line: #10163f66;
  --line-faint: #ffffff22; --line: #ffffff33; --line-strong: #ffffff55; --line-bold: #ffffff88;
  --shade-light: #00000044; --shade: #00000066; --shade-deep: #000000aa; --scrim: #000000cc;
  --error: #ffb4a8; --condition: #ff8b8b; --condition-text: #ffe0da; --effect-text: #e0f5ff;
  --toast: #3b3a1f; --current: #3a3f8a;
  /* Panel header strip */
  --tile-in: #00000066; --tile-hi: #ffffff55;
  --head-1: #1a2a7a; --head-2: #101a55; --head-edge: #ffffff33; --fact-label: #ffe27a;
  --head-icon-bg: #0a1140; --head-icon-text: #f3f5ff;
  /* Bottom hint band */
  --foot-bg: #04071a; --foot-text: #b7c1ef;
  --chrome-text: #f3f5ff; --chrome-dim: #b7c1ef; --chrome-btn-bg: #ffffff12; --chrome-btn-edge: #ffffff2e;
  --med-1: #e8b13e; --med-2: #b8860b; --med-line: #7a5a14; --med-num: #fff3d0;
}
/* The other presets (style guide: Theme). A theme's own color changes are set on the root element over these. */
:root[data-theme="parchment"] {
  --bg-1: #b9a37c; --bg-2: #e2d3b0;
  --win-1: #fbf4e2; --win-2: #f0e2c3; --edge: #5b4128; --edge-in: #eadbb8; --glow: #b08f5f;
  --text: #2b1d10; --dim: #5c4733; --cursor: #8a3b12; --select: #8a3b1222;
  --action: #b23f14; --bonus: #7d5e00; --reaction: #17658f; --free: #36721f; --passive: #6447a3; --info: #4a3d85;
  --temp-hp: #ffffff; --temp-edge: #8a6b45; --hp: #2e8a39; --hp-mid: #b07f00; --hp-low: #bf3324;
  --you: #8a3b12; --target: #9c2d74; --nat20: #1c7f45;
  --slot: #1f6fa8; --resource-1: #13806a; --resource-2: #b35a00; --resource-3: #5b46b8; --resource-4: #4f7d00; --resource-5: #b8322e; --resource-6: #857300; --resource-7: #4a3a2a;
  --well: #fffaf0; --well-soft: #fffaf099; --on-accent: #fff8e8; --on-accent-line: #fff8e866;
  --line-faint: #5b412822; --line: #5b412844; --line-strong: #5b412866; --line-bold: #5b412899;
  --shade-light: #3b2a1618; --shade: #3b2a1628; --shade-deep: #3b2a1640; --scrim: #2b1d10aa;
  --error: #a8321e; --condition: #bf3324; --condition-text: #7a1f12; --effect-text: #17507a;
  --toast: #f6e7b8; --current: #ead2a0;
  --head-1: #f0e4c8; --head-2: #e4d3ae; --head-edge: #5b412844; --fact-label: #8a3b12;
  --head-icon-bg: #5b4128; --head-icon-text: #fffaf0;
  --foot-bg: #2b1d10; --foot-text: #f0e2c3;
  --chrome-text: #2b1d10; --chrome-dim: #5c4733; --chrome-btn-bg: #5b41281a; --chrome-btn-edge: #5b412855;
}
:root[data-theme="night"] {
  --bg-1: #0b0d12; --bg-2: #161a24;
  --win-1: #1f2430; --win-2: #171b24; --edge: #6b7487; --edge-in: #0e1117; --glow: #3a4253;
  --text: #d9dde6; --dim: #a1a9b9; --cursor: #d8b45a; --select: #ffffff14;
  --action: #d98b6a; --bonus: #d6bf6a; --reaction: #7fb0cf; --free: #93c27e; --passive: #ab9dd2; --info: #a6aec6;
  --temp-hp: #ffffff; --temp-edge: #4a5060; --hp: #6fbf76; --hp-mid: #cfae4a; --hp-low: #d0645a;
  --you: #d8b45a; --target: #cf86b8; --nat20: #74c98e;
  --slot: #86b8d9; --resource-1: #7cc9b2; --resource-2: #d9a06e; --resource-3: #a99ad0; --resource-4: #a9c97a; --resource-5: #d98585; --resource-6: #cfcf86; --resource-7: #d9dde6;
  --well: #11141b; --well-soft: #11141b99; --on-accent: #1a1408; --on-accent-line: #1a140866;
  --line-faint: #ffffff14; --line: #ffffff22; --line-strong: #ffffff38; --line-bold: #ffffff5c;
  --error: #e29a8e; --condition: #d97b7b; --condition-text: #f0d0ca; --effect-text: #cfe3ef;
  --toast: #2c2a1c; --current: #2a3350;
  --head-1: #252a38; --head-2: #1b2029; --head-edge: #ffffff22; --fact-label: #d8b45a;
  --head-icon-bg: #11141b; --head-icon-text: #d9dde6;
  --foot-bg: #05060a; --foot-text: #a1a9b9;
  --chrome-text: #d9dde6; --chrome-dim: #a1a9b9; --chrome-btn-bg: #ffffff0d; --chrome-btn-edge: #ffffff24;
}
/* Tactics: cream panels on a stone floor; Status sits on the floor in light text, as a tactics game's status screen. */
:root[data-theme="tactics"] {
  --bg-1: #232220; --bg-2: #2e2c29;
  --win-1: #efe6cf; --win-2: #e6dbbf; --edge: #f5eedb; --edge-in: #b8a67c; --glow: #b8a67c;
  --text: #2b241a; --dim: #5f4f35; --cursor: #4a3c28; --select: #b8a67c55;
  --action: #8c3a26; --bonus: #6e5200; --reaction: #1f5f8b; --free: #3f6e2a; --passive: #5b3f8f; --info: #4a3d85;
  --temp-hp: #ffffff; --temp-edge: #6e6252; --hp: #3f8a2e; --hp-mid: #a87a00; --hp-low: #b8432e;
  --you: #6b3d0e; --target: #8f2d6a; --nat20: #1c7f45;
  --slot: #b8435c; --resource-1: #13806a; --resource-2: #b35a00; --resource-3: #5b46b8; --resource-4: #4f7d00; --resource-5: #b8322e; --resource-6: #857300; --resource-7: #4a3a2a;
  --well: #f7f1e1; --well-soft: #f7f1e199; --on-accent: #f7f1e1; --on-accent-line: #f7f1e166;
  --line-faint: #4a3c2818; --line: #4a3c2833; --line-strong: #4a3c2855; --line-bold: #4a3c2888;
  --shade-light: #3b2a1610; --shade: #3b2a161c; --shade-deep: #3b2a1633; --scrim: #0d0c0bcc;
  --error: #a8321e; --condition: #b8432e; --condition-text: #7a1f12; --effect-text: #17507a;
  --toast: #efe0c2; --current: #d8caa6;
  --floor-joint: #00000052; --floor-glint: #ffffff09;
  --font-heading: "Crimson Pro", Georgia, serif; --radius: 8px;
  /* Side tabs (commands, campaign layers) and the phone tab bar. */
  --tab-off-1: rgba(78,70,60,.82); --tab-off-2: rgba(52,47,41,.82); --tab-off-edge: rgba(255,255,255,.16); --tab-off-text: #d8cfbd;
  --tab-on-1: #f1e9d4; --tab-on-2: #e2d6b8; --tab-on-text: #2b241a;
  --tabbar-bg: #16110d;
  /* Panel header strip, and the Tactics pieces inside panels. */
  --head-1: #e2d6b6; --head-2: #d8cba8; --head-edge: #c4b38a; --fact-label: #6e5320;
  --head-icon-bg: #4a3c28; --head-icon-text: #f7f1e1;
  --row-edge: #e2d6b8; --row-sel: #d8caa6; --row-sel-edge: #b8a67c; --row-head: #4a3c28;
  --check-bg: #efe0c2; --check-edge: #c4a76c; --chip-edge: #c4b38a;
  --foot-bg: #0a0805; --foot-text: #e9e3d6;
  --chrome-text: #f2eee6; --chrome-dim: #d6cfc1; --chrome-btn-bg: #4e463c66; --chrome-btn-edge: #ffffff29;
}
:root[data-theme="tactics"] body {
  background-color: var(--bg-1);
  background-image: radial-gradient(ellipse at 50% 35%, transparent 35%, var(--floor-joint) 100%), linear-gradient(var(--floor-joint) 2px, transparent 2px),
    linear-gradient(90deg, var(--floor-joint) 2px, transparent 2px), linear-gradient(var(--floor-glint) 1px, transparent 1px);
  background-size: auto, 180px 96px, 180px 96px, 180px 96px; background-position: 0 0, 0 0, 0 0, 0 3px; background-attachment: fixed;
}
:root[data-theme="tactics"] .win { box-shadow: 0 0 0 1px var(--edge-in), 0 16px 40px var(--scrim); }
:root[data-theme="tactics"] .status {
  background: none; border: none; box-shadow: none; padding: 6px 4px 0;
  --text: #f2eee6; --dim: #d6cfc1; --cursor: #e8c879; --on-accent: #1b1a18; --edge: #d9c9a0; --select: #ffffff1a;
  --hp: #7fd05a; --hp-mid: #f5d04a; --hp-low: #ff7a66; --slot: #f08aa0; --reaction: #7fb0cf;
  --line: #ffffff33; --line-strong: #ffffff47; --line-bold: #ffffff80; --shade-light: #00000040; --shade: #00000059; --shade-deep: #000000a6;
  --condition: #d0705a; --condition-text: #ffd7cc; --effect-text: #cfe3ef;
  --resource-1: #7dffd4; --resource-2: #ffb26b; --resource-3: #b5a8ff; --resource-4: #c6ff7a; --resource-5: #ff8b8b; --resource-6: #f2f28c; --resource-7: #ffffff;
  color: var(--text);
}
:root[data-theme="tactics"] .status > .plate { display: none; }

/* Tactics: This turn is a slim strip on the stone like Status — no window chrome, light text on the floor. */
:root[data-theme="tactics"] .turn {
  background: none; border: none; box-shadow: none; padding: 2px 4px 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 15px;
  --text: #f2eee6; --dim: #d6cfc1; --cursor: #e8c879; --on-accent: #1b1a18; --select: #ffffff1a;
  --action: #ff9a72; --bonus: #ffd95e; --reaction: #7fb0cf; --free: #a8ef8a; --passive: #d4c4ff; --info: #c9d2ff;
  --line: #ffffff33; --line-strong: #ffffff47; --line-bold: #ffffff80; --well: #00000052;
  --shade-light: #00000040; --shade: #00000059; --shade-deep: #000000a6; --current: #4a3c2880;
  color: var(--text);
}
:root[data-theme="tactics"] .turn.your-turn { border: none; box-shadow: none; }

/* Tactics: Commands are side tabs on the stone — dark cards, the active one cream with a right-pointing notch. */
:root[data-theme="tactics"] .commands { background: none; border: none; box-shadow: none; padding: 6px 16px 0 0; }
:root[data-theme="tactics"] .commands > .plate { display: none; }
:root[data-theme="tactics"] .commands ul { display: grid; gap: 10px; }
:root[data-theme="tactics"] .commands .cmd {
  min-height: 70px; border-radius: 6px; padding: 4px 8px;
  flex-direction: column; justify-content: center; gap: 0; text-align: center; white-space: normal;
  background: linear-gradient(180deg, var(--tab-off-1), var(--tab-off-2));
  border: 1px solid var(--tab-off-edge); color: var(--tab-off-text); font-size: 15px; font-weight: 700;
}
:root[data-theme="tactics"] .commands .cmd .ico { width: auto; font-size: 25px; line-height: 30px; }
:root[data-theme="tactics"] .commands .cmd .icon { width: 30px; height: 30px; }
:root[data-theme="tactics"] .commands .cmd .icon.has-pixel { width: 32px; height: 32px; }
:root[data-theme="tactics"] .commands .cmd.on {
  background: linear-gradient(180deg, var(--tab-on-1), var(--tab-on-2)); color: var(--tab-on-text);
  border: none; border-radius: 0;
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 0 100%);
}
:root[data-theme="tactics"] .commands .cmd.on::before { display: none; }
:root[data-theme="tactics"] .commands .cmd kbd { display: none; }

/* Tactics, inside the panel: pill rows, tile icons, chip buttons, switch and check styling. */
:root[data-theme="tactics"] .panel-title { font-size: 24px; }
:root[data-theme="tactics"] .row {
  min-height: 38px; border-radius: 19px; margin-bottom: 4px; gap: 10px; padding: 0 14px 0 22px;
  background: var(--well); border: 1px solid var(--row-edge);
}
:root[data-theme="tactics"] .row.sel { background: var(--row-sel); border-color: var(--row-sel-edge); }
:root[data-theme="tactics"] .row .label { font-family: var(--font-heading); font-size: 18px; font-weight: 600; }
:root[data-theme="tactics"] .row .right { font-size: 15px; font-weight: 700; color: var(--dim); }
:root[data-theme="tactics"] .type-icon { width: 28px; height: 28px; border-radius: 5px; box-shadow: inset 0 0 0 1px var(--tile-in), inset 0 1px 0 var(--tile-hi); color: var(--on-accent); }
:root[data-theme="tactics"] .type-icon .icon { width: 15px; height: 15px; }
:root[data-theme="tactics"] .group { color: var(--row-head); font-family: var(--font-heading); font-size: 18px; margin-top: 12px; }
:root[data-theme="tactics"] .group .icon { color: var(--group); }
:root[data-theme="tactics"] .group .state { color: var(--dim); font-size: 15px; font-family: "Atkinson Hyperlegible", sans-serif; }
:root[data-theme="tactics"] .detail h2 { font-family: var(--font-heading); }
/* Chip buttons: pills; the picked one is dark. */
:root[data-theme="tactics"] .btn { min-height: 40px; border-radius: 20px; border: 1px solid var(--chip-edge); background: var(--well); font-size: 15px; }
:root[data-theme="tactics"] .btn.primary { background: var(--cursor); border-color: var(--cursor); }
:root[data-theme="tactics"] .split .btn:first-child { border-radius: 20px 0 0 20px; }
:root[data-theme="tactics"] .split .split-more { border-radius: 0 20px 20px 0; }
:root[data-theme="tactics"] .btn.small { min-height: 32px; }
:root[data-theme="tactics"] .choice .btn { min-height: 40px; }
/* Switch rows: a 44px pill holding a 40×24 toggle. */
:root[data-theme="tactics"] .addon { min-height: 44px; border-radius: 22px; padding: 5px 12px; align-items: center; }
:root[data-theme="tactics"] .addon .switch { width: 40px; height: 24px; }
:root[data-theme="tactics"] .addon .switch i { width: 18px; height: 18px; top: 3px; left: 3px; }
:root[data-theme="tactics"] .addon.on .switch i { left: 19px; }
/* Check boxes on cream. */
:root[data-theme="tactics"] .check { border-radius: 8px; border-color: var(--check-edge); background: var(--check-bg); }
:root[data-theme="tactics"] .check .who { font-size: 15px; }

/* Tactics, campaign: layers as side tabs, like the sheet's commands. */
:root[data-theme="tactics"] .campaign-layers { display: grid; gap: 10px; }
:root[data-theme="tactics"] .campaign-layers .cmd {
  min-height: 70px; border-radius: 6px; padding: 4px 8px; flex-direction: column; justify-content: center; gap: 0;
  text-align: center; white-space: normal; background: linear-gradient(180deg, var(--tab-off-1), var(--tab-off-2));
  border: 1px solid var(--tab-off-edge); color: var(--tab-off-text); font-size: 15px; font-weight: 700;
}
:root[data-theme="tactics"] .campaign-layers .cmd .ico { width: auto; font-size: 25px; line-height: 30px; }
:root[data-theme="tactics"] .campaign-layers .cmd .icon { width: 30px; height: 30px; }
:root[data-theme="tactics"] .campaign-layers .cmd .icon.has-pixel { width: 32px; height: 32px; }
:root[data-theme="tactics"] .campaign-layers .cmd.on {
  background: linear-gradient(180deg, var(--tab-on-1), var(--tab-on-2)); color: var(--tab-on-text); border: none; border-radius: 0;
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 0 100%);
}
:root[data-theme="tactics"] .campaign-layers .cmd.on::before { display: none; }

/* Tactics: dialogs are cream panels; the roll pop-up is a cream card with a big serif total. */
:root[data-theme="tactics"] .campaign-dialog, :root[data-theme="tactics"] .theme-dialog, :root[data-theme="tactics"] .mode-menu {
  background: linear-gradient(180deg, var(--win-1), var(--win-2)); border: 2px solid var(--edge);
  box-shadow: 0 0 0 1px var(--edge-in), 0 16px 40px var(--scrim); color: var(--text);
}
:root[data-theme="tactics"] .roll-toast {
  background: linear-gradient(135deg, var(--win-1), var(--win-2) 70%); border: 2px solid var(--cursor); border-radius: 8px;
  box-shadow: 0 0 0 1px var(--edge-in), 0 16px 40px var(--scrim); color: var(--text);
}
:root[data-theme="tactics"] .roll-toast .roll-total { font-family: var(--font-heading); font-size: 36px; }
* { box-sizing: border-box; }
html { background: var(--bg-1); }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  font: 18px/1.5 "Atkinson Hyperlegible", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-2), var(--bg-1) 70%) fixed;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--cursor); outline-offset: 2px; }

/* ---------- Window chrome ---------- */
.win {
  position: relative; border-radius: var(--radius); padding: 22px 16px 14px;
  background: linear-gradient(180deg, var(--win-1), var(--win-2));
  border: 2px solid var(--edge);
  box-shadow: inset 0 0 0 2px var(--edge-in), inset 0 0 0 4px color-mix(in srgb, var(--glow) 40%, transparent), 0 6px 0 var(--shade-deep), 0 0 24px var(--shade-deep);
}
.plate {
  position: absolute; top: -13px; left: 14px; padding: 0 10px; border-radius: 6px;
  background: var(--edge-in); border: 2px solid var(--edge); font-size: 13px; font-weight: 700; letter-spacing: .06em;
  white-space: nowrap; max-width: calc(100% - 28px); overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Layout ---------- */
.app {
  max-width: 1320px; margin: 0 auto; padding: 20px 16px 16px; display: grid; gap: 18px 16px;
  grid-template-columns: 200px minmax(0, 1fr) minmax(0, 440px);
  grid-template-areas: "status status status" "turn turn turn" "commands panel panel";
  padding-bottom: 84px;
}
/* The chrome row: the Path on the left, screen tools on the right, on the floor itself. */
.chrome { grid-area: chrome; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; color: var(--chrome-text); }
.chrome-path { font-size: 15px; font-weight: 700; color: var(--chrome-dim); }
.chrome-actions { display: flex; gap: 8px; align-items: center; }
.chrome-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px; border-radius: 18px; border: 1px solid var(--chrome-btn-edge); background: var(--chrome-btn-bg); color: var(--chrome-text); font: 700 15px "Atkinson Hyperlegible", sans-serif; cursor: pointer; }
.chrome-btn:hover, .chrome-btn:focus-visible { background: var(--select); }
.chrome-btn .icon { width: 16px; height: 16px; }
.chrome-btn.alert { background: var(--cursor); color: var(--on-accent); border-color: transparent; }
#turn[hidden] { display: none; }
/* The medallion: a golden d20 on an isometric tile, showing the last roll (or the round). */
.medallion { display: flex; flex-direction: column; align-items: center; gap: 4px; align-self: center; padding: 4px 10px; }
.med-cap { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--dim); }
.d20 { position: relative; display: block; width: 64px; height: 76px; }
.d20 svg { position: absolute; inset: 0 0 18px; width: 64px; height: 58px; filter: drop-shadow(0 3px 3px #00000066); }
.d20-body { fill: url(#none); fill: var(--med-1); stroke: var(--med-line); stroke-width: 1.5; }
.d20-facet { fill: none; stroke: var(--med-line); stroke-width: 1; opacity: .7; }
.d20-num { position: absolute; top: 17px; left: 0; width: 100%; text-align: center; font: 700 20px "Atkinson Hyperlegible", sans-serif; fill: var(--med-num); stroke: none; }
.d20-iso { position: absolute; left: 50%; bottom: 0; width: 76px; height: 38px; transform: translateX(-50%); background: var(--shade-deep); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); box-shadow: 0 4px 8px #00000080; }
.d20 svg { z-index: 1; }
.med-cap { font-size: 13px; font-weight: 700; color: var(--chrome-dim); text-align: center; }
/* This turn's slots as pips inside Status: filled circles in each slot's color, dimmed when used. */
.trunc { font-size: 13px; color: var(--dim); }
.summary.small { font-size: 13px; color: var(--dim); }
/* The attack flow: each swing's total and its hit/miss answer. */
.attack-flow { display: grid; gap: 6px; margin: 8px 0; }
.atk-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px; background: var(--well); border: 1px solid var(--line-strong); }
.atk-line.hit { border-color: var(--cursor); }
.atk-ask { display: inline-flex; gap: 8px; align-items: center; color: var(--dim); font-size: 15px; }
/* Condensed turn order: Turn X/Y plus a mark per combatant. */
.enemy-mark { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 5px; background: var(--side); color: var(--on-accent); font-weight: 700; font-size: 13px; }
/* Turn order: "Turn X / Y", then a 24 px mark per combatant; the current turn is ringed with ▾ over it. */
.order-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0; }
.turn-count { flex: none; font-weight: 700; font-size: 15px; }
.order-strip { flex: 1 1 160px; min-width: 0; display: flex; align-items: center; }
.ribbon { flex: 1 1 auto; min-width: 0; list-style: none; margin: 0; padding: 12px 2px 2px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; cursor: grab; }
.ribbon::-webkit-scrollbar { display: none; }
.order-mark { position: relative; flex: none; display: grid; place-items: center; width: 30px; height: 30px; border: 2px solid transparent; border-radius: 7px; }
.order-mark.now { border-color: var(--cursor); }
.order-mark.now::before { content: "▾"; position: absolute; top: -13px; left: 50%; transform: translateX(-50%); color: var(--cursor); font-size: 13px; line-height: 1; }
.order-mark .portrait { width: 24px; height: 24px; border-width: 1px; border-radius: 5px; }
.order-mark .portrait-initial { font-size: 13px; text-shadow: none; }
.order-arrow { flex: none; width: 24px; min-height: 36px; padding: 0; border: none; background: none; color: var(--cursor); font-size: 20px; line-height: 1; cursor: pointer; }
.order-arrow[hidden] { display: none; }
.check.cast-check { width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; background: var(--check-bg, var(--well)); border: 1px solid var(--check-edge, var(--line-strong)); display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 10px 14px; border-radius: 8px; }
.check.cast-check:hover { border-color: var(--cursor); }
.check.cast-check:disabled { opacity: .5; cursor: default; }
/* A real d20, tumbling when a roll lands. */
@keyframes d20tumble { 0% { transform: rotateY(0) rotateZ(0) scale(1); } 50% { transform: rotateY(540deg) rotateZ(180deg) scale(1.15); } 100% { transform: rotateY(720deg) rotateZ(360deg) scale(1); } }
.medallion.rolling .d20 svg { animation: d20tumble .7s ease-out; }
.medallion { cursor: pointer; border: none; background: none; font: inherit; }
@media (prefers-reduced-motion: reduce) { .medallion.rolling .d20 svg { animation: none; } }
/* Page tabs inside a List. */
.page-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.page-tab { min-height: 36px; padding: 4px 14px; border-radius: 18px; border: 1px solid var(--chip-edge, var(--line-strong)); background: var(--well); color: var(--text); font: 700 15px "Atkinson Hyperlegible", sans-serif; cursor: pointer; }
.page-tab.on { background: var(--cursor); color: var(--on-accent); border-color: var(--cursor); }
.pin-btn { float: right; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--well); color: var(--dim); cursor: pointer; }
.pin-btn .icon { width: 14px; height: 14px; }
.pin-btn.on { background: var(--cursor); color: var(--on-accent); border-color: var(--cursor); }
.app .win { padding: 18px 14px 12px; }
.status { grid-area: status; padding: 0 10px 2px; }
.turn { grid-area: turn; }
.commands { grid-area: commands; align-self: start; }
/* The sheet's one panel: a header strip (the Path, facts, Back) over the List and Info columns. */
.panel { grid-area: panel; min-height: 520px; display: flex; flex-direction: column; padding: 0; }
.app .win.panel { padding: 0; }
.panel-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 18px;
  background: linear-gradient(180deg, var(--head-1), var(--head-2)); border-bottom: 1px solid var(--head-edge);
  border-radius: calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0 0;
}
.panel-icon { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 5px; background: var(--head-icon-bg); color: var(--head-icon-text); }
.panel-icon .icon { width: 16px; height: 16px; }
.panel-title { display: flex; align-items: center; gap: 12px; font-family: var(--font-heading); font-size: 20px; font-weight: 700; }
.panel-facts { display: flex; flex-wrap: wrap; gap: 4px 16px; }
/* Back is a small arrow left of the menu's icon, in the same spot on every level. */
.panel-head .back { display: grid; place-items: center; min-width: 36px; min-height: 36px; padding: 0; margin-right: -4px; font-size: 20px; line-height: 1; }
.panel-head .back[hidden] { display: none; }
.fact { font-size: 13px; font-weight: 700; color: var(--fact-label); }
.fact b { color: var(--text); font-size: 15px; margin-left: 5px; }
.panel-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.85fr); flex: 1; min-height: 0; }
.list { min-width: 0; padding: 14px; }
.detail { min-width: 0; display: flex; flex-direction: column; padding: 0; border-left: 1px solid var(--line); }
.detail-body { padding: 14px 16px; }

/* ---------- Status: who they are and their bars, their numbers in boxed groups, then chips ---------- */
.status-head { display: flex; flex-wrap: nowrap; gap: 12px 16px; align-items: flex-start; }
.status-who { flex: 1 1 0; min-width: 0; display: flex; gap: 10px; align-items: flex-start; }
/* The portrait with the campaign day under it, exactly as wide as the portrait. */
.who-side { flex: none; width: 104px; display: flex; flex-direction: column; gap: 6px; }
.calendar { display: grid; justify-items: center; padding: 2px 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--shade); color: var(--text); font-size: 13px; line-height: 1.3; cursor: pointer; }
.calendar:hover { border-color: var(--line-bold); }
.calendar .missed { color: var(--hp-low); }
.stat-groups { display: flex; flex-wrap: nowrap; gap: 8px; }
.portrait {
  position: relative; flex: none; width: 104px; height: 104px; padding: 0; border-radius: var(--radius); border: 2px solid var(--edge); cursor: pointer;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--portrait) 55%, white), var(--portrait) 62%, color-mix(in srgb, var(--portrait) 55%, black));
  box-shadow: 0 6px 16px var(--shade-deep); display: grid; place-items: center;
}
.portrait img { width: 100%; height: 100%; object-fit: cover; border-radius: calc(var(--radius) - 2px); }
.portrait-initial { font-family: var(--font-heading); font-size: 56px; font-weight: 700; color: var(--portrait-text); text-shadow: 0 3px 0 var(--shade-deep); }
.portrait-level {
  position: absolute; top: -10px; left: -10px; min-width: 30px; height: 30px; padding: 0 6px; box-sizing: border-box; border-radius: 15px;
  border: 2px solid var(--edge); background: var(--cursor); color: var(--on-accent); display: grid; place-items: center; font-size: 15px; font-weight: 700;
}
.portrait-swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.portrait-swatch { width: 40px; height: 40px; border-radius: var(--radius); border: 2px solid var(--line-strong); background: var(--portrait); cursor: pointer; }
.portrait-swatch[aria-pressed="true"] { outline: 3px solid var(--cursor); outline-offset: 2px; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
/* The identity sits right after the name, as in the owner's mock-up, and moves under it when the line is full. */
.who-name { display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: baseline; gap: 0 10px; min-width: 0; }
.who-name h1 { flex: none; min-width: 0; }
.who-name .identity { flex: 0 1 auto; max-width: 100%; white-space: normal; }
.who h1 { margin: 0; font-family: var(--font-heading); font-size: 24px; line-height: 1.15; }
/* One identity line under the name; tapping it opens the portrait's Character card (the full text is its tooltip). */
.identity { display: inline-flex; align-items: center; min-height: 36px; border: none; background: none; padding: 0; margin: 0; font: inherit; font-size: 15px; color: var(--dim); cursor: pointer; text-align: left; max-width: 100%; }
.identity:hover { color: var(--cursor); }
/* Vitals rows: a short colored label, a slim bar, and value/max — HP, Turn, spell slots, resources. */
/* Vitals are the owner’s compact spec: one shared three-column grid so every bar is the same length —
   label at its content width, bar 1fr, value right-aligned. Rows are 18-20 px by the owner’s call. */
.vitals { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0 8px; align-content: start; margin-top: 2px; }
button.vitals { width: 100%; padding: 0; border: none; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
button.vitals:focus-visible { outline: 2px solid var(--chrome-text); outline-offset: 2px; }
.vital { display: grid; grid-template-columns: subgrid; grid-column: 1 / -1; align-items: center; min-height: 19px; min-width: 0; padding: 0 4px; border: none; border-radius: 4px; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.vital:hover { background: var(--select); }
.v-label { font-size: 13px; font-family: var(--font-heading); font-weight: 700; color: color-mix(in srgb, var(--v) 30%, var(--chrome-text, var(--text))); white-space: nowrap; }
.v-bar { display: flex; gap: 2px; height: 8px; position: relative; }
.v-bar:has(.v-fill) { background: var(--shade-deep); border-radius: 4px; box-shadow: inset 0 0 0 1px var(--line-strong); }
.v-bar.spells { gap: 6px; }
.v-level { display: flex; gap: 2px; flex: 1; }
.v-seg b { display: grid; place-items: center; width: 100%; height: 100%; font-size: 8px; font-weight: 400; color: var(--chrome-text, var(--text)); opacity: .65; }
.v-seg { flex: 1; border-radius: 3px; background: var(--shade-deep); box-shadow: inset 0 0 0 1px var(--line-strong); }
.v-seg.on { background: var(--seg, var(--v)); box-shadow: none; }
.v-seg.spent { opacity: .3; }
.v-seg.t-action.on { background: var(--action); } .v-seg.t-bonus.on { background: var(--bonus); }
.v-seg.t-reaction.on { background: var(--reaction); } .v-seg.t-free.on { background: var(--free); }
.v-fill { display: block; height: 8px; border-radius: 4px; background: var(--v); }
.v-temp { position: absolute; top: 0; height: 8px; border-radius: 4px; background: var(--temp-hp); box-shadow: inset 0 0 0 1px var(--temp-edge); }
.v-val { flex: none; font-size: 13px; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.v-val small { font-size: 13px; font-weight: 400; color: var(--dim); }
.conds { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: center; }
.stat-group { flex: 0 1 auto; min-width: 0; overflow: hidden; display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--shade-light); overflow: hidden; }
.stat-label {
  writing-mode: vertical-rl; transform: rotate(180deg); display: grid; place-items: center; padding: 6px 2px;
  border-left: 1px solid var(--line-strong); background: var(--select); font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--dim);
}
.ability-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: row; gap: 0 4px; padding: 2px 4px; align-content: center; }
.ability { display: grid; grid-template-columns: 32px 22px 30px; align-items: baseline; align-content: center; gap: 5px; min-height: 36px; padding: 0 6px; border: none; border-radius: 6px; background: none; cursor: pointer; text-align: left; }
.ab-short { font-size: 13px; font-weight: 700; letter-spacing: .06em; color: var(--cursor); }
.ab-score { font-size: 15px; color: var(--dim); text-align: right; }
.ability b, .defense b { font-size: 18px; text-align: right; }
.defense-grid { display: grid; padding: 4px 8px; align-content: center; }
.defense { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 36px; padding: 0 4px; border: none; border-radius: 6px; background: none; cursor: pointer; }
.defense span { font-size: 15px; color: var(--dim); }
.ability:hover, .defense:hover { background: var(--select); }
.clock-line { color: var(--dim); font-size: 15px; line-height: 1.3; margin: 2px 0 0; }
/* The Calendar's month: today ringed, days with something due marked. */
.month { display: grid; grid-template-columns: repeat(var(--week), minmax(0, 1fr)); gap: 3px; margin: 0 0 12px; text-align: center; }
.month-name { grid-column: 1 / -1; font-weight: 700; text-align: left; margin-bottom: 2px; }
.month .weekday { font-size: 13px; color: var(--dim); }
.month .day { font-size: 15px; padding: 2px 0; border-radius: 6px; background: var(--shade); }
.month .day.today { outline: 2px solid var(--cursor); color: var(--cursor); font-weight: 700; }
.month .day.due { background: var(--select); text-decoration: underline; text-decoration-color: var(--target); }
.campaign-bar .clock-line { margin: -4px 0 10px; }
.clock-now { font-size: 18px; margin: 0 0 8px; }
.clock-date { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0 8px; }

/* ---------- Trackers ---------- */
.tracker { border: 1.5px solid var(--line); border-left: 6px solid var(--side); border-radius: 10px; background: var(--well-soft); padding: 8px 12px; margin-bottom: 10px; }
.tracker header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.tracker h3 { margin: 0; font-size: 20px; }
.tracker-tags { color: var(--dim); font-size: 15px; }
.tracker-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 4px 0; }
.tracker-value b { font-size: 20px; color: var(--cursor); }
.tracker-value small { color: var(--dim); font-size: 13px; }
.segments { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.segments i { width: 14px; height: 14px; border-radius: 3px; border: 1.5px solid var(--side, var(--cursor)); }
.segments i.on { background: var(--side, var(--cursor)); }
.tracker-standing { font-weight: 700; }
.tracker-due { margin: 2px 0 6px; font-size: 15px; color: var(--dim); }
.tracker-due.missed { color: var(--hp-low); font-weight: 700; }
.tracker-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
.tracker-controls input[type=number] { width: 64px; font: inherit; font-size: 18px; padding: 4px 8px; border-radius: 8px; border: 1.5px solid var(--edge); background: var(--well); color: var(--text); }
.tracker-why { flex: 1; min-width: 140px; font: inherit; font-size: 15px; padding: 4px 8px; border-radius: 8px; border: 1.5px solid var(--edge); background: var(--well); color: var(--text); }
.tracker details summary { cursor: pointer; color: var(--dim); font-size: 15px; }
.tracker-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line-faint); }
.tracker-note input, .tracker-note select { font: inherit; font-size: 15px; padding: 3px 6px; border-radius: 8px; border: 1.5px solid var(--edge); background: var(--well); color: var(--text); }
.tracker-note input[id^="nText"] { flex: 1; min-width: 160px; }
.tracker-note .check-label { margin: 0; }
.small-btn { border: 1.5px solid var(--line-strong); background: var(--shade); border-radius: 8px; padding: 2px 10px; min-height: 32px; font-size: 15px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.hp-bar { flex: 1; min-width: 60px; height: 10px; border-radius: 5px; background: var(--shade-deep); border: 1px solid var(--line-strong); overflow: hidden; }
.hp-bar i { display: block; height: 100%; background: var(--hp); transition: width .3s, background .3s; }
/* The DM's HP lines (party cards, unit panel). */
.hp-line { display: flex; align-items: center; gap: 8px; }
.hp-line .hp-bar { max-width: 260px; }
.tray { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; }
.tray-label { font-size: 13px; font-weight: 700; color: var(--dim); margin-right: 2px; }
.res { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; background: var(--shade); border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; cursor: pointer; }
.res:hover { border-color: var(--line-bold); }
/* Resource meters use --res, the resource's own color, everywhere it appears. */
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 12px; height: 12px; border: 2px solid var(--res); background: var(--res); transform: rotate(45deg) scale(.85); border-radius: 2px; }
.pips i.spent { background: transparent; border-color: var(--line-strong); }
.res-count { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--res); }
.res-count::before { content: ""; width: 9px; height: 9px; background: var(--res); transform: rotate(45deg); }
.res-count.mini { font-size: 15px; }
.die-track { font-weight: 700; color: var(--res); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 8px; background: var(--res); transform: rotate(45deg); outline: 1px solid var(--on-accent); }
.cond-chip { border: 1.5px solid var(--condition); color: var(--condition-text); background: var(--shade); border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 13px; font-weight: 700; }
.cond-chip.effect { border-color: var(--reaction); color: var(--effect-text); }
.none { color: var(--dim); font-size: 15px; }

/* ---------- This turn / Initiative ---------- */
.turn.your-turn { border-color: var(--cursor); box-shadow: inset 0 0 0 2px var(--edge-in), 0 0 0 3px color-mix(in srgb, var(--cursor) 33%, transparent), 0 6px 0 var(--shade-deep); }
.your-turn-text { color: var(--cursor); font-size: 20px; }
/* Turn order: each side's color on the left edge, the current turn outlined. */

/* ---------- Commands ---------- */
.commands ul { list-style: none; margin: 0; padding: 0; }
.cmd { white-space: nowrap; width: 100%; display: flex; gap: 10px; align-items: center; background: none; border: none; border-radius: 6px; padding: 5px 8px 5px 28px; position: relative; cursor: pointer; text-align: left; }
.cmd .ico { width: 24px; text-align: center; }
.cmd.on { background: var(--select); }
.cmd.on::before, .row.sel::before { content: "▶"; position: absolute; left: 8px; color: var(--cursor); animation: bob .6s infinite alternate ease-in-out; }
@keyframes bob { to { transform: translateX(4px); } }
.cmd kbd { margin-left: auto; color: var(--dim); font: 13px "Atkinson Hyperlegible", sans-serif; }

/* ---------- List ---------- */
/* The bottom hint band: a solid dark band on the edge; desktop only. */
.sheet-foot { display: none; }
@media (min-width: 881px) {
  .sheet-foot { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; pointer-events: none;
    padding: 8px 24px 10px; background: var(--foot-bg); }
  .hint-band { margin: 0; text-align: center; font-size: 15px; color: var(--foot-text); }
  .list > .intro { display: none; }
  /* Info stays in view beside a long List: it sticks inside the panel, clear of the hint band, and scrolls on its own.
     It no longer stretches to the List's height, so the List draws the divider. */
  .detail { position: sticky; top: 12px; align-self: start; max-height: calc(100vh - 24px - 48px); border-left: none; }
  .list { border-right: 1px solid var(--line); }
}
.list-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.back { border: 1.5px solid var(--edge); background: var(--shade); border-radius: 8px; padding: 0 12px; min-height: 32px; cursor: pointer; white-space: nowrap; }
.intro { color: var(--dim); margin: 0 0 6px; font-size: 15px; line-height: 1.4; }
.group { display: flex; align-items: center; gap: 8px; margin: 12px 0 2px; padding-bottom: 2px; border-bottom: 1px solid var(--line); font-size: 15px; font-weight: 700; color: var(--group, var(--dim)); }
.group .state { margin-left: auto; font-weight: 400; color: var(--dim); }
.row {
  width: 100%; display: grid; grid-template-columns: 26px minmax(min(14ch, 50%), 1fr) minmax(0, auto); gap: 10px; align-items: center; min-height: 40px;
  background: none; border: none; border-radius: 6px; padding: 3px 8px 3px 28px; position: relative; text-align: left; cursor: pointer;
  -webkit-touch-callout: none; user-select: none;
}
.row.sel { background: var(--select); }
.row.spent .label { opacity: .5; }
.row .label small { color: var(--dim); margin-left: 6px; }
.row .right { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; color: var(--dim); }
/* A preview on the right is cut off, never the name beside it. */
.row .right .trunc { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail .text-head { margin: 14px 0 4px; font-size: 15px; font-weight: 700; color: var(--dim); }
.row .right b { color: var(--text); }
.row .more { color: var(--cursor); font-weight: 700; }
/* A List's own note (an empty Pinned tab): quiet text, not a Row. */
.list-note { margin: 8px 4px; color: var(--dim); font-size: 15px; line-height: 1.4; }
.type-icon { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 13px; color: var(--on-accent); font-weight: 700; }
.t-action { --c: var(--action); } .t-bonus { --c: var(--bonus); } .t-reaction { --c: var(--reaction); }
.t-free { --c: var(--free); } .t-passive { --c: var(--passive); } .t-info { --c: var(--info); }
.type-icon { background: var(--c); }
.mini-pips { display: inline-flex; gap: 2px; }
.mini-pips i { width: 9px; height: 9px; transform: rotate(45deg); background: var(--res); }
.mini-pips i.spent { background: transparent; outline: 1px solid var(--line-strong); }

/* ---------- Detail: choices and switches, then the roll, then what it does ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; background: var(--c); color: var(--on-accent); font-weight: 700; border-radius: 999px; padding: 0 10px 0 8px; font-size: 13px; }
.detail h2 { margin: 4px 0 4px; font-size: 20px; line-height: 1.25; }
.summary { margin: 0 0 10px; font-size: 18px; }
.lead { margin: 2px 0 10px; font-size: 18px; }
.facts { margin: 0 0 10px; padding-left: 20px; color: var(--dim); font-size: 15px; }
.facts b { color: var(--text); }
.cost { margin: 0 0 10px; display: flex; gap: 8px; align-items: center; background: var(--shade-light); border: 1px solid var(--line); border-radius: 8px; min-height: 36px; padding: 3px 10px; cursor: pointer; font-size: 15px; }
.meter-large { margin: 0 0 10px; transform: scale(1.3); transform-origin: left center; }

/* "You roll" and "Target rolls" always look and sit the same, so players learn the two kinds of roll by sight. */
.check { --who: var(--you); display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; border: 1.5px solid var(--who); border-radius: 10px; padding: 6px 10px; margin: 0 0 10px; background: var(--shade); }
.check.target { --who: var(--target); }
/* Not Status's .who (a growing column): the Check's label is one inline line. */
.check .who { flex: none; display: inline-flex; flex-direction: row; align-items: center; gap: 4px; min-width: auto; font-size: 13px; font-weight: 700; color: var(--who); white-space: nowrap; }
.check .what { flex: 1; min-width: 160px; font-size: 18px; }
.check-cost { display: block; font-size: 15px; color: var(--dim); }
.check-buttons { display: flex; gap: 6px; }
.check-notes { flex-basis: 100%; font-size: 15px; font-weight: 700; color: var(--who); }
/* A Roll button with its Advantage menu beside it. */
.split { display: inline-flex; }
.split .btn:first-child { border-radius: 8px 0 0 8px; }
.split .split-more { border-radius: 0 8px 8px 0; border-left-color: var(--on-accent-line); padding: 0 10px; }
[data-modes] { -webkit-touch-callout: none; user-select: none; }

/* Add-on switches: what can join this roll. */
.addons { display: grid; gap: 6px; margin: 0 0 10px; }
.addon { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 6px 10px; border-radius: 10px; border: 1.5px solid var(--line-strong); background: var(--well-soft); cursor: pointer; }
.addon.on { border-color: var(--free); background: color-mix(in srgb, var(--free) 12%, transparent); }
.addon:disabled { opacity: .55; cursor: not-allowed; }
.switch { flex: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative; margin-top: 2px; }
.switch i { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: left .15s; }
.addon.on .switch { background: var(--free); }
.addon.on .switch i { left: 19px; background: var(--on-accent); }
.addon-text { flex: 1; min-width: 0; font-size: 15px; line-height: 1.35; }
.addon-cost { font-size: 13px; font-weight: 700; color: var(--dim); }
.addon-text small { display: block; color: var(--dim); font-size: 15px; }

/* Imported rules text, a tap away, formatted for scanning. */
.rules-box { border-top: 1px solid var(--line); padding-top: 8px; margin-bottom: 10px; }
.rules-box summary { cursor: pointer; font-weight: 700; font-size: 15px; }
.rules { font-size: 18px; padding-top: 8px; }
.rules p { margin: 0 0 10px; }
.rules ul { margin: 0 0 10px; padding-left: 22px; }
.hl-dice { color: var(--cursor); font-weight: 700; }
.hl-dc { color: var(--target); font-weight: 700; }
.hl-type { color: var(--c); font-weight: 700; }
.form label { display: block; margin-bottom: 10px; }
.form input[type=text], .form input[type=number], .form textarea, .form select { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 4px 8px; border-radius: 8px; border: 1.5px solid var(--edge); background: var(--well); color: var(--text); }
.buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.btn { border: 1.5px solid var(--edge); background: var(--well); border-radius: 8px; padding: 4px 12px; min-height: 38px; cursor: pointer; font-weight: 700; font-size: 15px; }
.btn.primary { background: var(--cursor); color: var(--on-accent); border-color: var(--cursor); }
.btn.small { min-height: 32px; padding: 2px 10px; font-size: 15px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.hint { color: var(--dim); font-size: 15px; margin: 4px 0 10px; }
.detail-body { flex: 1; overflow: auto; min-height: 0; }
.hp-input { width: 90px; font: inherit; font-size: 20px; padding: 3px 8px; border-radius: 8px; border: 1.5px solid var(--edge); background: var(--well); color: var(--text); }
.check-label { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.lbl-short { display: none; }
/* Back from Info or a picked unit; only on a phone, where they replace the level before them. */
.unit-back { display: none; margin-bottom: 8px; }

/* The DM's roll card (unit panel, dice dialog). */
.roll-card { display: block; border: 3px solid var(--cursor); border-radius: 12px; padding: 8px 14px; margin-bottom: 10px; background: linear-gradient(135deg, color-mix(in srgb, var(--cursor) 20%, transparent), var(--shade)); }
.roll-card summary { cursor: pointer; font-size: 15px; }
/* The picked unit's verdict: green on a hit, red on a miss. */
.roll-card.hit { border-color: var(--hp); } .roll-card.hit summary { color: var(--hp); }
.roll-card.miss { border-color: var(--hp-low); } .roll-card.miss summary { color: var(--hp-low); }
.roll-card .roll-what { display: flex; flex-direction: column; margin-top: 6px; }
.unit-checks { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 13px; }
.unit-checks .check-label { gap: 6px; margin-bottom: 8px; }
.roll-total { font-size: 36px; font-weight: 700; line-height: 1; min-width: 60px; text-align: center; color: var(--cursor); }
.roll-what { display: flex; flex-direction: column; min-width: 0; }
.roll-what small { color: var(--dim); }
.roll-note { color: var(--cursor); font-weight: 700; }
.roll-card.nat20, .roll-toast.nat20 { border-color: var(--nat20); } .nat20 .roll-total, .nat20 .roll-note { color: var(--nat20); }
.roll-card.nat1, .roll-toast.nat1 { border-color: var(--hp-low); } .nat1 .roll-total, .nat1 .roll-note { color: var(--hp-low); }
@keyframes pop { from { transform: scale(.92); opacity: .3; } }

/* Roll pop-ups: over everything for a moment, then they fade. */
.roll-toasts { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); width: min(460px, calc(100vw - 20px)); z-index: 60; display: grid; gap: 8px; pointer-events: none; }
.roll-toast { pointer-events: auto; width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; padding: 8px 14px; border-radius: 12px; border: 2.5px solid var(--cursor); background: linear-gradient(135deg, var(--toast), var(--well) 60%); box-shadow: 0 8px 24px var(--shade-deep); color: var(--text); cursor: pointer; animation: pop .3s ease-out; transition: opacity .6s; }
.roll-toast.fading { opacity: 0; }
.roll-toast .roll-total { font-size: 36px; min-width: 48px; }
.roll-toast .roll-what b { font-size: 18px; line-height: 1.25; }
.roll-toast .roll-what small { font-size: 15px; }
.roll-toast .roll-note { font-size: 15px; }

/* The Advantage menu of a Roll button. */
.mode-menu { position: fixed; z-index: 70; width: 280px; border-radius: 10px; border: 2px solid var(--edge); background: var(--well); box-shadow: 0 10px 30px var(--scrim); padding: 6px; }
.mode-menu button { display: block; width: 100%; text-align: left; background: none; border: none; border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.mode-menu button:hover, .mode-menu button:focus-visible { background: var(--select); }
.mode-menu small { display: block; color: var(--dim); font-size: 15px; }
.mode-menu p { margin: 4px 0 0; padding: 4px 8px 2px; border-top: 1px solid var(--line); font-size: 13px; color: var(--dim); }

/* ---------- Phone: commands become a tab bar; Info takes the List's place when something is picked ---------- */
@media (max-width: 880px) {
  .order-arrow { min-height: 40px; }
  .pin-btn { width: 40px; height: 40px; }
  .cost { min-height: 40px; }
  :root[data-theme="tactics"] .row { min-height: 40px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "chrome" "status" "turn" "panel"; gap: 18px; padding: 16px 8px 96px; }
  .app .win { padding: 16px 10px 10px; }
  /* Status on a phone: the medallion shares the top row with the name and bars; the stat groups take the row below. */
  /* portrait | name | d20 on the first rows; identity, vitals and the groups take the full width below. */
  .status-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 3px 10px; }
  .status-who, .who, .who-side { display: contents; }
  /* On a phone the day is one compact line under the class line. */
  .calendar { grid-column: 2; grid-row: 3; justify-self: start; display: flex; gap: 6px; min-height: 0; padding: 1px 8px; }
  .calendar span + span::before { content: "· "; }
  .status-who .portrait { grid-column: 1; grid-row: 1 / 3; width: 64px; height: 64px; }
  .status-who .portrait .portrait-initial { font-size: 36px; }
  .who-name { grid-column: 2; grid-row: 1 / 3; align-self: center; flex-wrap: wrap; }
  .who-name .identity { flex: 1 1 100%; white-space: normal; overflow: visible; font-size: 13px; min-height: 40px; text-align: left; }
  .medallion { grid-column: 3; grid-row: 1 / 3; align-self: center; width: 56px; padding: 2px 2px; }
  .medallion .d20 svg { width: 44px; height: 44px; }
  .conds { grid-column: 1 / -1; }
  .vitals { grid-column: 1 / -1; margin-top: 0; }
  .stat-groups { grid-column: 1 / -1; display: flex; gap: 8px; }
  .stat-group { flex: 1 1 0; min-width: 0; }
  /* The class line under the name repeats what the class chip says; the pips already show which turn slots are left. */
  /* The chrome row can take two lines rather than squeeze the Path into a column. */
  .chrome { flex-wrap: wrap; }
  .chrome-path { min-width: 0; }
  .portrait { width: 64px; height: 64px; }
  .portrait-initial { font-size: 36px; }
  .portrait-level { top: -8px; left: -8px; min-width: 26px; height: 26px; font-size: 13px; }
  .who h1 { font-size: 20px; }
  .bars { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0 14px; }
  .chrome-btn, .page-tab, .identity { min-height: 40px; }
  .stat-groups { flex-wrap: nowrap; }
  /* Short labels across the top: a vertical label would make each box as tall as its word. */
  .stat-group { flex-direction: column; }
  .stat-label { writing-mode: horizontal-tb; transform: none; place-items: start; padding: 2px 10px; border-left: none; border-bottom: 1px solid var(--line-strong); }
  /* Uses scroll sideways in one row, so the header leaves room for the turn below it. */
  .ability-grid { flex: 1; grid-template-rows: none; grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 2px; padding: 2px 4px; }
  .ability { grid-template-columns: auto; justify-items: center; gap: 0; padding: 0 2px; }
  .ability .ab-score { font-size: 13px; }
  .ability { grid-template-columns: none; justify-items: center; gap: 0; min-height: 40px; padding: 2px 0; }
  .ability b, .defense b { font-size: 17px; text-align: center; }
  .ab-score { display: none; }
  .defense-grid { flex: 1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 2px; padding: 2px 4px; }
  .defense { flex-direction: column; justify-content: center; gap: 0; min-height: 40px; padding: 2px 0; }
  .tray { margin-top: 4px; }
  .defense span { font-size: 13px; }
  .res { font-size: 15px; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .commands { grid-area: auto; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; border-radius: 0; border-width: 2px 0 0; box-shadow: 0 -4px 12px var(--shade-deep); }
  .app .commands { padding: 0; }
  .commands .plate { display: none; }
  .commands ul { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
  .cmd { flex-direction: column; justify-content: center; gap: 0; min-height: 60px; padding: 4px 0; border-radius: 0; text-align: center; font-size: 13px; font-weight: 700; letter-spacing: -0.01em; color: var(--dim); }
  .cmd .ico { font-size: 18px; }
  .cmd.on { color: var(--cursor); }
  .cmd.on::before, .cmd kbd { display: none; }
  /* Tactics: the tab bar is a dark band of small cards, the active one cream. */
  :root[data-theme="tactics"] .commands { background: var(--tabbar-bg); border: none; box-shadow: 0 -4px 12px #00000080; padding: 4px; }
  :root[data-theme="tactics"] .commands ul { gap: 4px; }
  /* Phone tab labels use the Label size (13), so five fit at 360 px. */
  :root[data-theme="tactics"] .commands .cmd { min-height: 56px; border-radius: 8px; padding: 4px 0; font-size: 13px; color: var(--tab-off-text); }
  :root[data-theme="tactics"] .commands .cmd.on { clip-path: none; border-radius: 8px; color: var(--tab-on-text); }
  .list { min-height: 0; }
  .panel { min-height: 0; }
  .panel-cols { display: block; }
  .detail { display: none; border-left: none; scroll-margin-top: 20px; }
  body.detail-open .detail { display: flex; }
  body.detail-open .list { display: none; }
  /* The header stays at the top on a phone, so Back is always under the same thumb. */
  .panel-head { position: sticky; top: 0; z-index: 20; }
  .panel-head .back { min-width: 40px; min-height: 40px; }
  .detail h2 { font-size: 18px; }
}

/* ---------- Home: players and characters ---------- */
.home { max-width: 560px; margin: 12vh auto 0; padding: 0 16px; }
.home .win { padding: 28px 22px 22px; }
.home h1 { margin: 0 0 8px; font-size: 24px; }
.home p { color: var(--dim); margin: 0 0 16px; }
.home label.btn { display: inline-block; }
.home input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.pick { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.pick button { width: 100%; text-align: left; padding: 10px 14px; border: 2px solid var(--edge); border-radius: 8px; background: var(--well); cursor: pointer; }
.pick button:has(.portrait) { display: flex; align-items: center; gap: 12px; }
.pick-text { min-width: 0; }
.pick .portrait { width: 48px; height: 48px; border-width: 1.5px; }
.pick .portrait-initial { font-size: 24px; }
.pick button:hover { background: var(--select); }
.pick small { display: block; color: var(--dim); font-size: 15px; }
.pick-empty { color: var(--dim); font-size: 15px; }
.add-player { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.add-player label { flex-basis: 100%; color: var(--dim); }
.add-player input { flex: 1; min-width: 0; padding: 6px 10px; border: 2px solid var(--edge); border-radius: 8px; background: var(--well); }
.home.wide { max-width: 900px; margin-top: 4vh; }
.home input[type=file] + .btn, .home .btn + .btn { margin-left: 8px; }
.pack-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.pack-actions .btn + .btn { margin-left: 0; }
.field { display: block; margin-bottom: 12px; color: var(--dim); }
.field input, .field textarea, .field select { display: block; width: 100%; margin-top: 4px; padding: 6px 10px; border: 2px solid var(--edge); border-radius: 8px; background: var(--well); color: var(--text); font: inherit; }
.field textarea { font: 15px/1.5 ui-monospace, Consolas, monospace; resize: vertical; }
.pack-result { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.pack-result h2 { margin: 0 0 6px; font-size: 18px; }
.pack-result ul { margin: 0 0 12px; padding-left: 20px; }
.pack-result.problems h2 { color: var(--error); }
.save-error { flex-basis: 100%; margin: 6px 0 0; color: var(--error); font-weight: 700; }
.error { color: var(--error); margin-top: 12px; }
.warnings { margin-top: 10px; font-size: 15px; color: var(--dim); }
.warnings summary { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Additions to the sheet ---------- */
.related { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.related h3 { margin: 0 0 6px; font-size: 15px; color: var(--dim); }
.related p { margin: 0 0 8px; }
.notice { margin-top: 16px; color: var(--dim); font-size: 15px; }
.notice a { color: var(--dim); }
.choice { margin-bottom: 4px; }
.choice-label { display: block; font-size: 13px; font-weight: 700; color: var(--dim); margin-bottom: 4px; }

/* ---------- Game log on the sheet ---------- */
.row.struck .label { text-decoration: line-through; opacity: .6; }

/* ---------- Home: campaigns ---------- */
.home-sub { font-size: 18px; margin: 20px 0 8px; color: var(--dim); letter-spacing: .04em; }

/* ---------- Campaign (the DM's table) ---------- */
.campaign {
  display: grid; gap: 18px 16px; padding: 22px 16px 84px; max-width: 1900px; margin: 0 auto;
  grid-template-columns: 190px minmax(0, 1fr) minmax(0, 0.8fr);
  grid-template-areas: "chrome chrome chrome" "bar main side";
  align-items: start;
}
.campaign .chrome { grid-area: chrome; }
.campaign.no-side { grid-template-columns: 190px minmax(0, 1fr); grid-template-areas: "chrome chrome" "bar main"; }
/* The log drawer is its own column while open, so it never covers the table. */
.campaign.log-open { grid-template-columns: 190px minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 0.8fr); grid-template-areas: "chrome chrome chrome chrome" "bar main side log"; }
.campaign.log-open.no-side { grid-template-columns: 190px minmax(0, 1fr) minmax(0, 0.8fr); grid-template-areas: "chrome chrome chrome" "bar main log"; }
.campaign.no-side .campaign-side { display: none; }
.campaign-bar { grid-area: bar; position: sticky; top: 22px; }
.campaign-layers { list-style: none; margin: 0 0 10px; padding: 0; }
.campaign-tools { flex-direction: column; align-items: stretch; }
.campaign-main { grid-area: main; }
.campaign-side { grid-area: side; position: sticky; top: 22px; }
/* Panels scroll inside their window, so the window's name plate stays in view. */
.panel-scroll { max-height: calc(100vh - 82px); overflow-y: auto; padding-right: 6px; }
/* The sticky side panel must also clear the fixed hint band at the bottom. */
.campaign-side .panel-scroll { max-height: calc(100vh - 104px); }
.panel-toggle { position: absolute; top: 4px; right: 8px; background: none; border: none; color: var(--dim); font-size: 20px; cursor: pointer; }
.phone-only { display: none; }
.campaign h1 { margin: 0 0 10px; font-size: 20px; overflow-wrap: anywhere; }
.campaign-description { color: var(--dim); white-space: pre-line; margin: 0 0 8px; }
.party-card {
  display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left; cursor: pointer;
  border: 2px solid var(--edge); border-radius: 8px; background: var(--well); padding: 10px 12px; margin-bottom: 10px;
}
.party-card:hover { background: var(--select); }
.party-name { font-size: 20px; font-weight: 700; }
.party-class, .party-resources { color: var(--dim); font-size: 15px; }
.party-conditions { display: flex; flex-wrap: wrap; gap: 6px; }
.party-stats b, .party-card .hp-line b { color: var(--cursor); }
.initiative { margin: 0 0 8px; padding-left: 28px; font-size: 18px; }
.initiative b { display: inline-block; min-width: 2.2em; color: var(--cursor); }
.initiative-total { flex: 0 0 5.5em !important; }
.roster { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.roster li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.roster small { color: var(--dim); }
.log-session { font-size: 15px; letter-spacing: .06em; color: var(--dim); margin: 14px 0 6px; border-bottom: 1px solid var(--line); }
.log-entry { border-bottom: 1px solid var(--line-faint); padding: 6px 0; }
.log-entry summary { cursor: pointer; }
.log-entry .facts { margin: 6px 0; }
.log-entry.struck summary { text-decoration: line-through; opacity: .6; }
.log-entry.hidden-entry summary { color: var(--passive); }
.log-time { color: var(--dim); font-size: 15px; }
.log-day { font-size: 15px; color: var(--cursor); margin: 10px 0 4px; }
@media (min-width: 881px) and (max-width: 1250px) {
  .campaign { grid-template-columns: 180px minmax(0, 1fr) minmax(0, 0.8fr); }
  .campaign.no-side { grid-template-columns: 180px minmax(0, 1fr); }
  .campaign-side { position: relative; }
  .panel-scroll { max-height: 60vh; }
}
/* Phone: layers as tabs across the top, the log as a layer, and the picked unit in the layer's place. */
@media (max-width: 880px) {
  .campaign, .campaign.no-side { grid-template-columns: minmax(0, 1fr); grid-template-areas: "chrome" "bar" "main" "side"; padding: 12px 8px 96px; gap: 18px; }
  .campaign.log-open, .campaign.log-open.no-side { grid-template-areas: "chrome" "bar" "main" "side" "log"; }
  .log-drawer { position: relative; top: auto; max-height: none; }
  .campaign-bar { position: relative; top: auto; }
  .campaign-bar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; align-items: center; padding: 10px 6px 6px; }
  .campaign-bar .plate { display: none; }
  .campaign h1 { grid-area: name; margin: 0; font-size: 18px; }
  /* The name gets its own line, so the tools can wrap without squeezing it. */
  .campaign-bar { grid-template-areas: "name" "clock" "tools" "layers"; }
  .campaign-bar .clock-line { grid-area: clock; margin: 0; }
  .campaign-tools { grid-area: tools; flex-direction: row; flex-wrap: wrap; margin: 0; }
  .campaign-layers { grid-area: layers; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; margin: 0; }
  .campaign-layers .phone-only { display: block; }
  .tracker-row { grid-template-columns: 2em minmax(0, 1fr) auto auto; gap: 8px; padding: 4px 8px; }
  .tracker-hp, .tracker-ac { font-size: 15px; }
  .campaign-layers .cmd { flex-direction: column; justify-content: center; gap: 0; min-height: 50px; padding: 4px 0; border-radius: 8px; text-align: center; font-size: 13px; font-weight: 700; letter-spacing: -0.01em; color: var(--dim); }
  :root[data-theme="tactics"] .campaign-layers .cmd { padding: 4px 0; font-size: 13px; }
  :root[data-theme="tactics"] .campaign-layers .cmd.on { clip-path: none; border-radius: 8px; }
  .campaign-layers .cmd.on { color: var(--cursor); }
  .campaign-layers .cmd.on::before { display: none; }
  .campaign:not(.layer-log) .campaign-log { display: none; }
  .campaign.layer-log .campaign-main { display: none; }
  .campaign .campaign-side { display: none; position: relative; top: auto; scroll-margin-top: 20px; }
  .campaign.has-selection:not(.no-side) .campaign-side { display: block; }
  .campaign.has-selection:not(.no-side) .campaign-main { display: none; }
  .campaign-side .panel-scroll { max-height: none; overflow: visible; }
  .unit-back { display: inline-flex; align-items: center; }
  .log-tab { flex-direction: row; justify-content: center; }
  .log-tab span { writing-mode: horizontal-tb; }
}
.party-card.sel { background: var(--select); border-color: var(--cursor); }
.campaign-dialog, .theme-dialog { width: min(560px, calc(100vw - 32px)); overflow: visible; color: var(--text); margin: auto; }
.campaign-dialog::backdrop, .theme-dialog::backdrop { background: var(--shade-deep); }
.dialog-body { max-height: calc(100vh - 140px); overflow-y: auto; }
.dialog-close { position: absolute; top: 6px; right: 8px; background: none; border: none; color: var(--dim); font-size: 20px; cursor: pointer; }

/* ---------- Encounter (the DM's tracker) ---------- */
.tracker { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.tracker-row {
  display: grid; grid-template-columns: 32px 24px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; width: 100%; text-align: left;
  border: 2px solid var(--edge); border-radius: 8px; background: var(--well); padding: 6px 10px; cursor: pointer;
}
.tracker-init { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--well); border: 1.5px solid var(--line-strong); font-weight: 700; color: var(--cursor); }
/* The row's column caption, like the players' "Initiative · HP · AC". */
.tracker-head { display: flex; justify-content: space-between; margin: 0 4px 4px; color: var(--dim); font-size: 15px; }
/* Who's on the row: an enemy's letter, an ally's shield, or a portrait — on its side's color. */
.tracker-mark { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 5px; background: var(--side, var(--edge)); color: var(--on-accent); font-weight: 700; font-size: 13px; box-shadow: inset 0 0 0 1px var(--tile-in), inset 0 1px 0 var(--tile-hi); }
.tracker-mark .icon { width: 14px; height: 14px; }
.tracker-row > .portrait { width: 24px; height: 24px; border-width: 1px; border-radius: 5px; }
.tracker-row .portrait-initial { font-size: 13px; text-shadow: none; }
/* The game log pulls out beside the table as its own column on any layer; the DM keeps it open and it remembers. */
.log-drawer { grid-area: log; position: sticky; top: 22px; max-height: calc(100vh - 104px); display: flex; flex-direction: column; overflow: hidden; }
.log-drawer[hidden] { display: none; }
.log-drawer .panel-head { border-radius: calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0 0; }
.log-drawer .panel-scroll { max-height: none; flex: 1; overflow-y: auto; }
.tracker-bar { display: inline-block; width: 120px; height: 10px; vertical-align: middle; }
.tracker-name { min-width: 0; }
@media (max-width: 1100px) { .tracker-bar { width: 72px; } .tracker-row { gap: 8px; } }
.tracker-row:hover, .tracker-row.sel { background: var(--select); }
.tracker-row.current { border-color: var(--cursor); box-shadow: 0 0 0 2px var(--cursor); }
.tracker-row.down { opacity: .5; text-decoration: line-through; }
.tracker-hp, .tracker-ac { color: var(--dim); font-size: 15px; white-space: nowrap; }
.tracker-hp .hp-bar i { background: var(--hp); }
/* The encounter's main panel: the header strip sits edge to edge, its buttons on the right. */
.campaign-main.has-head { padding: 0; }
.campaign-main .panel-head { border-radius: calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0 0; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.encounter-body { padding: 12px 16px; }
.side-log { display: grid; gap: 4px; }
.side-log-line { margin: 0; font-size: 15px; color: var(--dim); border-bottom: 1px solid var(--line-faint); padding-bottom: 4px; }
/* The picked unit's HP: bar and value, then the segmented amount − ＋ ⋯ control — all on one line. */
.hp-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.hp-row .hp-label { font-size: 13px; font-weight: 700; color: var(--hp); }
.hp-row .hp-bar { flex: 1; }
.hp-row .hp-max { color: var(--dim); }
.hp-row .hp-max b { color: var(--reaction); }
.hp-ctrl { display: flex; gap: 2px; align-items: stretch; margin-left: auto; }
.hp-ctrl input { width: 40px; padding: 2px 6px; border: 2px solid var(--edge); border-radius: 8px 0 0 8px; background: var(--well); text-align: center; }
.hp-ctl { min-width: 30px; min-height: 26px; padding: 1px 7px; border-radius: 0; font-size: 15px; }
.hp-ctl:last-child { border-radius: 0 8px 8px 0; }
.hp-menu { letter-spacing: 1px; }
@media (max-width: 540px) { .hp-ctl { min-height: 40px; } .hp-ctrl input { width: 48px; } }
/* The compact action row in the picked unit's Info: name, "+4 · 1d6+2", one button. */
.unit-action summary { display: flex; align-items: center; gap: 8px; padding: 2px 6px; border-radius: 6px; }
.unit-action summary b { flex: none; }
.unit-action .abbrev { flex: 1; min-width: 0; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit-action .btn { flex: none; min-height: 28px; padding: 2px 8px; font-size: 13px; }
@media (max-width: 540px) { .unit-action .btn { min-height: 40px; } }
/* Turn-order rows: the current turn is ringed; those who acted this round are dimmed. */
.tracker-row.acted { opacity: .55; }
.tracker-add { color: var(--dim); font-style: italic; justify-content: center; }
.tag { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; font-size: 13px; font-weight: 700; vertical-align: middle; }
.tag.now { background: var(--cursor); color: var(--on-accent); }
.tag.ally { background: var(--bonus); color: var(--well); }
/* Party cards: portrait before the name. */
.party-name { display: flex; align-items: center; gap: 8px; }
.party-name .portrait { width: 40px; height: 40px; border-width: 1.5px; }
.party-name .portrait-initial { font-size: 20px; }
.party-name .portrait-level { display: none; }
.condition-badge {
  display: inline-block; min-width: 1.4em; margin-left: 2px; padding: 0 4px; border-radius: 5px; text-align: center; text-decoration: none;
  background: var(--passive); color: var(--well); font-size: 13px; font-weight: 700; line-height: 1.5; cursor: help;
}
.condition-badge sub { font-size: inherit; }
.encounter-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.encounter-notes summary { cursor: pointer; color: var(--dim); }
/* The notes field grows as the DM types instead of needing a manual resize. */
.encounter-notes .field { margin: 8px 0; }
.encounter-notes textarea { field-sizing: content; min-height: 9em; max-height: 50vh; }
.difficulty { margin: 0 0 10px; }
.difficulty small { display: block; color: var(--dim); font-size: 15px; }
.difficulty-low { color: var(--hp); }
.difficulty-moderate { color: var(--hp-mid); }
.difficulty-high, .difficulty-above-high { color: var(--hp-low); }
.unit-name { margin: 0 0 6px; font-size: 20px; border-left: 6px solid var(--side, transparent); padding-left: 8px; }
.unit-section { margin: 14px 0 6px; font-size: 15px; letter-spacing: .06em; color: var(--dim); text-transform: uppercase; }
.effect-badge { background: var(--reaction); }
.effect-duration { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.death-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.death-row .unit-section { margin: 8px 0; }
.death-marks i { font-style: normal; margin: 0 1px; color: var(--dim); }
.death-marks i.on { color: var(--cursor); }
.death-row.dead b { color: var(--hp-low); }
.death-row.stable b { color: var(--hp); }
.unit-abilities, .unit-skills { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.unit-stats b, .unit-skills b { color: var(--cursor); }
/* The picked unit's title row: color, side, rename, and remove sit top right as compact icon buttons. */
.unit-title { display: flex; align-items: flex-start; gap: 8px; }
.unit-title .unit-name { flex: 1; min-width: 0; }
.unit-tools { display: flex; gap: 4px; flex: none; padding-top: 2px; }
.tool-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; min-height: 0; padding: 0; }
.tool-btn .icon { width: 16px; height: 16px; }
/* Color presets in the unit's color dialog. */
.color-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.swatch { width: 34px; height: 34px; padding: 0; border: 2px solid var(--edge); border-radius: 8px; background: var(--swatch); cursor: pointer; }
.swatch:hover, .swatch:focus-visible { border-color: var(--cursor); }
/* The unit panel's sections wear the sheets' action-type icons. */
.unit-section { display: flex; align-items: center; gap: 6px; }
.unit-section .type-icon { width: 18px; height: 18px; flex: none; border-radius: 4px; }
.unit-section .type-icon .icon { width: 12px; height: 12px; }
/* The attacker's target: one slim labeled row. */
.unit-target { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--dim); font-size: 13px; }
.unit-target select { flex: 1; min-width: 0; padding: 2px 6px; border: 1.5px solid var(--edge); border-radius: 6px; background: var(--well); color: var(--text); font-size: 15px; }
.unit-damage { margin-top: -4px; }
.monster-action summary { cursor: pointer; }
.abbrev { color: var(--dim); font-size: 15px; }
/* A wrapping inline abbreviation reads as its own line under the action's name. */
.monster-action summary .abbrev { display: block; }
.condition-toggles { margin: 8px 0; }
.condition-toggles .btn { padding: 2px 10px; font-size: 15px; }
.stat-block h4 { margin: 14px 0 6px; font-size: 15px; letter-spacing: .06em; color: var(--dim); text-transform: uppercase; }
.monster-action { border-bottom: 1px solid var(--line-faint); padding: 4px 0 8px; }
.monster-action p { margin: 0 0 6px; }

/* ---------- Class tables (Character menu) ---------- */
.class-table-wrap { overflow-x: auto; margin: 8px 0 12px; }
.class-table { border-collapse: collapse; font-size: 15px; min-width: 100%; }
.class-table th, .class-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: center; white-space: nowrap; }
/* Roll tables: results are sentences, so they wrap. */
.roll-table { border-collapse: collapse; width: 100%; font-size: 15px; margin-top: 8px; }
.roll-table th, .roll-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.roll-table th { white-space: nowrap; color: var(--dim); }
.roll-table tr.current { background: var(--select); outline: 2px solid var(--cursor); }
.table-result { margin: 0 0 10px; padding: 6px 10px; border: 1.5px solid var(--cursor); border-radius: 8px; background: var(--shade); }
.class-table thead th { color: var(--dim); font-size: 13px; }
.class-table tr.current { background: var(--select); outline: 2px solid var(--cursor); }
.class-table tr.current th { color: var(--cursor); }
/* Class tables: the header row and the Level column stay put while it scrolls; numbers and dice line up on the right, words on the left. */
.class-table td { text-align: left; }
.class-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.class-table thead th:not(:first-child) { text-align: left; }
.class-table thead th { position: sticky; top: 0; z-index: 1; background: var(--well); }
.class-table tbody th { position: sticky; left: 0; background: var(--well); }
.class-table thead th:first-child { left: 0; z-index: 2; }
.class-table tr.current, .class-table tr.current th { background: var(--row-sel, var(--select)); }
/* Wide view: a class table across both panel columns, the List hidden until ‹ Back. */
@media (min-width: 881px) {
  .panel-cols.wide { grid-template-columns: minmax(0, 1fr); }
  .panel-cols.wide .list { display: none; }
  .panel-cols.wide .class-table-wrap { max-height: calc(100vh - 260px); overflow: auto; }
}

/* A closed <details> still lays out its children in some engines; keep them out of the box. */
details:not([open]) > *:not(summary) { display: none !important; }
.campaign-main > h2 { margin: 0 0 10px; font-size: 20px; }

/* ---------- Tap targets (style guide: at least 36 tall on desktop, 40 on a phone) ---------- */
.btn, .small-btn, .back, .res, .cond-chip, .calendar, .dialog-close, .panel-toggle,
.mode-menu button, .addon, input:not([type=checkbox]):not([type=radio]):not([type=color]), select { min-height: 36px; }
.res, .cond-chip { display: inline-flex; align-items: center; }
details > summary { padding-block: 5px; min-height: 36px; }
@media (max-width: 880px) {
  .btn, .small-btn, .back, .res, .cond-chip, .dialog-close, .panel-toggle,
  .mode-menu button, .addon, input:not([type=checkbox]):not([type=radio]):not([type=color]), select { min-height: 40px; }
  details > summary { padding-block: 8px; min-height: 40px; }
}

/* ---------- Motion: off when the device asks for less ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Read by screen readers, not shown. */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Theme settings ---------- */
.theme-title { margin: 0 40px 6px 0; font-size: 20px; }
.theme-group { margin: 12px 0 6px; font-size: 15px; color: var(--dim); }
.theme-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 12px; }
.theme-swatch { display: flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.theme-swatch input { width: 44px; height: 32px; padding: 0; border: 2px solid var(--edge); border-radius: 6px; background: none; cursor: pointer; }
.theme-contrast { color: var(--error); font-weight: 700; margin: 8px 0; }
.theme-contrast:empty { display: none; }

/* ---------- Icons: Drawn by default; Pixel when the theme picks it, at whole-pixel sizes so it stays crisp ---------- */
.icon { width: 1.2em; height: 1.2em; vertical-align: -0.25em; flex: none; overflow: visible; }
.icon-pixel { display: none; }
:root[data-icons="pixel"] .icon.has-pixel { width: 16px; height: 16px; vertical-align: -3px; }
:root[data-icons="pixel"] .icon.has-pixel .icon-drawn { display: none; }
:root[data-icons="pixel"] .icon-pixel { display: inline; }
@media (max-width: 880px) {
  .commands .icon, .campaign-layers .icon { width: 24px; height: 24px; }
  :root[data-icons="pixel"] .commands .icon.has-pixel, :root[data-icons="pixel"] .campaign-layers .icon.has-pixel { width: 32px; height: 32px; }
}
