/* ==========================================================================
   Character Sheets v2 — Tabs, mobile-first, no horizontal overflow
   4 themes: dark, light, paper, night
   ========================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }

:root, :root[data-theme="dark"] {
  --bg-0: #0e0f12; --bg-1: #16181d; --bg-2: #1c1f25; --bg-3: #23272f;
  --bg-card: #1a1d23; --line: #2a2e36; --line-soft: #23272f;
  --text: #e6e8ec; --text-dim: #9aa1ac; --text-mute: #6b7280;
  --brass: #c8a55a; --brass-2: #e6c275; --brass-dim: #6b5722; --gold: #f0c14b;
  --good: #6ad36a; --bad: #e26a6a; --info: #6ab0e2; --warn: #e2b76a;
  --accent: var(--brass); --accent-2: var(--brass-2); --accent-dim: var(--brass-dim);
  --shadow: 0 4px 20px rgba(0,0,0,0.35);
  --hp-grad: linear-gradient(90deg, var(--bad), var(--warn) 50%, var(--good));
}
:root[data-theme="light"] {
  --bg-0: #f4f5f7; --bg-1: #ffffff; --bg-2: #f7f8fa; --bg-3: #ebedf0;
  --bg-card: #ffffff; --line: #d6d8dd; --line-soft: #e8eaee;
  --text: #1a1d23; --text-dim: #555a64; --text-mute: #8a8f99;
  --brass: #b18a3a; --brass-2: #8a6920; --brass-dim: #d4b87a; --gold: #b18a3a;
  --good: #2d8c2d; --bad: #b03030; --info: #2a72a8; --warn: #a87b1a;
  --accent: var(--brass); --accent-2: var(--brass-2); --accent-dim: var(--brass-dim);
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --hp-grad: linear-gradient(90deg, var(--bad), var(--warn) 50%, var(--good));
}
:root[data-theme="paper"] {
  --bg-0: #fff; --bg-1: #fff; --bg-2: #fafafa; --bg-3: #f0f0f0;
  --bg-card: #fff; --line: #1a1a1a; --line-soft: #ccc;
  --text: #000; --text-dim: #404040; --text-mute: #707070;
  --brass: #000; --brass-2: #000; --brass-dim: #707070; --gold: #000;
  --good: #1a1a1a; --bad: #000; --info: #000; --warn: #000;
  --accent: #000; --accent-2: #000; --accent-dim: #707070;
  --shadow: none;
  --hp-grad: #000;
}
:root[data-theme="night"] {
  --bg-0: #000; --bg-1: #0a0a0a; --bg-2: #111; --bg-3: #1a1a1a;
  --bg-card: #0a0a0a; --line: #fff; --line-soft: #404040;
  --text: #fff; --text-dim: #c0c0c0; --text-mute: #808080;
  --brass: #fff; --brass-2: #fff; --brass-dim: #808080; --gold: #fff;
  --good: #fff; --bad: #fff; --info: #fff; --warn: #fff;
  --accent: #fff; --accent-2: #fff; --accent-dim: #808080;
  --shadow: none;
  --hp-grad: #fff;
}

body {
  background: var(--bg-0); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; max-width: 100vw; width: 100%;
  padding-bottom: 80px; /* space for FAB */
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg-0);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  display: flex; align-items: center; gap: 8px;
}
.topbar .back {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-dim); padding: 6px 8px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); font-size: 12px;
  text-decoration: none;
  flex-shrink: 0;
}
.topbar .title { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; }
.topbar .title small { display: block; color: var(--text-dim); font-size: 10px; font-weight: 400; }
.topbar .actions { display: flex; gap: 5px; flex-shrink: 0; }
.tbtn {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 6px 8px; font-size: 12px;
  font-weight: 500; cursor: pointer; transition: all .15s; font-family: inherit;
  white-space: nowrap;
}
.tbtn:hover { border-color: var(--accent-dim); color: var(--accent-2); }
.tbtn.active { border-color: var(--accent); color: var(--accent); background: var(--bg-3); }
.tbtn .lab { display: none; }
@media (min-width: 600px) { .tbtn .lab { display: inline; } .tbtn { padding: 6px 10px; } }

.themer { position: relative; }
.theme-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
  padding: 4px; display: none; flex-direction: column;
  min-width: 160px; z-index: 60;
}
.theme-menu.open { display: flex; }
.theme-menu button {
  background: transparent; border: none; text-align: left;
  padding: 7px 10px; border-radius: 6px; font-size: 13px;
  color: var(--text); cursor: pointer; font-family: inherit;
}
.theme-menu button:hover { background: var(--bg-2); }
.theme-menu button.active { color: var(--accent); font-weight: 600; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg-0);
  position: sticky; top: 41px; z-index: 49;
  padding: 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 10px 14px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .badge {
  display: inline-block;
  background: var(--bg-3);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 0 6px;
  font-size: 10px;
  margin-left: 4px;
  font-weight: 700;
}

/* ---------- Tab panels ---------- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px;
  display: grid; gap: 12px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 0; /* prevent grid blowout */
}
.card h2 {
  margin: 0 0 10px;
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--accent); font-weight: 700;
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
}
.card h3 {
  margin: 12px 0 6px; font-size: 11px;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-dim); font-weight: 600;
}
.card p { margin: 0 0 8px; }
.card .muted { color: var(--text-dim); font-size: 12px; }

/* ---------- Hero ---------- */
.hero {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px; padding: 16px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow);
  min-width: 0;
}
.hero::before {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 4px;
  background: var(--accent);
}
.hero h1 { margin: 0; font-size: 22px; letter-spacing: .3px; font-weight: 700; }
.hero .sub { color: var(--text-dim); margin-top: 2px; font-size: 13px; }
.hero .tagrow { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  display: inline-flex; align-items: center;
  font-size: 11px; padding: 3px 8px;
  border-radius: 999px; background: var(--bg-2);
  color: var(--text-dim); border: 1px solid var(--line);
  white-space: nowrap;
}
.tag.brass { color: var(--accent-2); border-color: var(--accent-dim); }
.hero .persona {
  margin-top: 10px; padding: 9px 12px;
  background: var(--bg-1); border-left: 3px solid var(--accent-dim);
  border-radius: 6px; font-style: italic;
  color: var(--text-dim); font-size: 13px;
}

/* ---------- HP / Structure block (the big one, per user mockup) ---------- */
.hp-block { display: grid; gap: 10px; }
.hp-head {
  display: flex; align-items: center; gap: 10px;
}
.hp-head .lab {
  font-size: 12px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--text-dim);
  flex: 1; min-width: 0;
}
.hp-pct {
  display: inline-block;
  background: var(--good);
  color: #000;
  font-size: 11px; font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.hp-num {
  font-size: 24px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--good);
  letter-spacing: -.5px;
  white-space: nowrap;
}
.hp-num small { font-size: 14px; color: var(--text-dim); font-weight: 500; }
.hp-bar {
  height: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  position: relative; overflow: hidden;
}
.hp-bar .fill {
  position: absolute; inset: 0 auto 0 0;
  background: var(--good);
  width: 100%; border-radius: 999px;
  transition: width .4s, background .4s;
}
.hp-bar.critical .fill { background: var(--bad); }
.hp-bar.bloodied .fill { background: var(--warn); }
.hp-temp {
  position: absolute; top: 0; right: 0; bottom: 0;
  background: var(--info); opacity: .35;
  border-left: 1px solid var(--info);
}
.hp-controls {
  display: grid; grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px;
}
.hp-input {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 6px;
  color: var(--text); font-size: 14px; font-weight: 600;
  text-align: center; font-family: inherit;
  font-variant-numeric: tabular-nums;
  width: 100%; min-width: 0;
}
.hp-input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.hp-btn {
  border: 1.5px solid; border-radius: 10px;
  padding: 9px 6px; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .12s;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.hp-btn.dmg  { color: var(--bad);  border-color: var(--bad);  background: rgba(226,106,106,.08); }
.hp-btn.heal { color: var(--good); border-color: var(--good); background: rgba(106,211,106,.10); }
.hp-btn.temp { color: var(--info); border-color: var(--info); background: rgba(106,176,226,.10); }
.hp-btn.reset{ color: var(--text-dim); border-color: var(--line); background: var(--bg-2); }
.hp-btn:active { transform: scale(.97); }

/* ---------- Stat cards (clickable for rolls) ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.stat {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  padding: 9px 4px 7px;
  cursor: pointer; transition: all .12s;
  user-select: none;
  min-width: 0;
}
.stat:hover { border-color: var(--accent-dim); transform: translateY(-1px); }
.stat:active { transform: translateY(0); }
.stat .lab { font-size: 10px; font-weight: 700; letter-spacing: 1.2px; color: var(--accent); text-transform: uppercase; }
.stat .score { font-size: 20px; font-weight: 700; margin: 3px 0 2px; color: var(--text); font-variant-numeric: tabular-nums; }
.stat .mod {
  display: inline-block; font-size: 11px;
  padding: 1px 7px; border-radius: 999px;
  background: var(--bg-3); color: var(--accent-2);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.stat .note { display: block; font-size: 9px; color: var(--text-mute); margin-top: 3px; line-height: 1.2; }

/* ---------- Combat metric cards (clickable) ---------- */
.combat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
}
.metric {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 6px;
  text-align: center;
  cursor: pointer;
  transition: all .12s;
  user-select: none;
  min-width: 0;
}
.metric:hover { border-color: var(--accent-dim); }
.metric:active { background: var(--bg-3); }
.metric .lab { font-size: 9px; font-weight: 700; letter-spacing: 1.2px; color: var(--text-dim); text-transform: uppercase; }
.metric .val { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; color: var(--text); }
.metric .val.brass { color: var(--accent-2); }
.metric .sub { font-size: 10px; color: var(--text-mute); margin-top: 1px; line-height: 1.2; }

/* ---------- Saves / Skills ---------- */
.list { display: grid; gap: 3px; }
.row {
  display: grid; grid-template-columns: 18px 1fr auto;
  align-items: center; gap: 9px;
  padding: 5px 9px;
  border-radius: 8px;
  cursor: pointer; transition: background .12s;
  user-select: none;
  min-width: 0;
}
.row:hover { background: var(--bg-2); }
.row:active { background: var(--bg-3); }
.row .pip {
  width: 16px; height: 16px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
  color: var(--text-mute); background: var(--bg-1);
}
.row .pip.prof { color: var(--accent); border-color: var(--accent-dim); background: var(--bg-2); }
.row .pip.expert { color: var(--accent-2); border-color: var(--accent); background: var(--bg-3); }
.row .name { font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.row .mod {
  font-size: 13px; font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  padding: 1px 8px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line);
  min-width: 42px; text-align: center;
}
.row .mod.prof { color: var(--accent-2); border-color: var(--accent-dim); }
.row .mod.expert { color: var(--accent); border-color: var(--accent); background: var(--bg-3); }

/* ---------- Spell slots / Resources ---------- */
.slots { display: grid; gap: 6px; }
.slot-row {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}
.slot-row .lab { font-size: 13px; font-weight: 600; flex: 1; min-width: 0; }
.slot-row .lab small { color: var(--text-mute); font-weight: 400; margin-left: 3px; font-size: 11px; }
.pips { display: flex; gap: 4px; flex-shrink: 0; }
.pip {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--bg-1);
  cursor: pointer; transition: all .15s;
}
.pip.full { background: var(--accent); border-color: var(--accent); }
.pip:hover { transform: scale(1.18); }
.pip:active { transform: scale(.95); }

/* ---------- Spells grid ---------- */
.spell-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 5px;
}
.spell {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px 5px;
  font-size: 12px;
  transition: all .12s;
  min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.spell:hover { border-color: var(--accent-dim); }
.spell .spell-top { min-width: 0; }
.spell .lvl { font-size: 9px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 1px; }
.spell .nm { font-weight: 600; color: var(--text); line-height: 1.2; }
.spell-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin-top: 4px;
}
.spell-btn {
  background: transparent;
  border: 1px solid var(--line-soft);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  min-width: 0;
  white-space: nowrap;
  padding: 3px 6px;
  border-radius: 5px;
  opacity: 0.65;
  transition: all .12s;
  cursor: pointer;
}
.spell-btn:hover { opacity: 1; border-color: var(--accent-dim); color: var(--text); }
.spell-btn:active { opacity: 1; background: var(--bg-2); }
.spell-btn.cast { color: var(--accent-2); }
.spell-btn.more { color: var(--text-dim); }

/* Spell modal: bigger Cast button */
.spell-modal-links {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin-bottom: 12px;
}
.spell-modal-links a {
  font-size: 12px;
  padding: 6px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  transition: all .12s;
}
.spell-modal-links a:hover { border-color: var(--accent); color: var(--accent-2); text-decoration: none; }
.spell-modal-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 14px;
}
.btn-modal {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border: 1.5px solid;
  transition: all .12s;
}
.btn-modal.btn-secondary { background: var(--bg-2); color: var(--text); border-color: var(--line); }
.btn-modal.btn-secondary:hover { border-color: var(--accent); }
.btn-modal.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-modal.btn-primary:hover { filter: brightness(1.1); }

/* ---------- Attacks ---------- */
.atk {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
  padding: 7px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer; transition: all .12s;
  min-width: 0;
}
.atk:hover { border-color: var(--accent-dim); }
.atk .nm { font-weight: 600; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.atk .note { font-size: 10px; color: var(--text-mute); }
.atk .tohit, .atk .dmg {
  font-size: 12px; font-weight: 600;
  padding: 2px 6px; border-radius: 6px;
  background: var(--bg-1); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  min-width: 60px; text-align: center;
}
.atk .tohit { color: var(--accent-2); }
.atk .dmg { color: var(--bad); }

/* ---------- Features ---------- */
.feat {
  padding: 7px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 5px;
  cursor: pointer; transition: border-color .12s;
  min-width: 0;
  position: relative;
}
.feat:hover { border-color: var(--accent-dim); }
.feat .nm { font-weight: 600; color: var(--accent-2); font-size: 13px; }
.feat .desc { font-size: 12px; color: var(--text-dim); margin-top: 2px; line-height: 1.35; }
.feat .src { font-size: 10px; color: var(--text-mute); margin-top: 3px; text-transform: uppercase; letter-spacing: .8px; }
.feat .feat-links {
  position: absolute;
  top: 7px; right: 9px;
  display: flex; gap: 4px;
}
.feat .feat-links a {
  font-size: 10px;
  padding: 2px 5px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.feat .feat-links a:hover { color: var(--accent-2); border-color: var(--accent-dim); text-decoration: none; }
.feat-triggers {
  margin-top: 6px;
  display: flex; flex-direction: column; gap: 3px;
}
.feat-trigger {
  font-size: 11px;
  background: var(--bg-1);
  border-left: 2px solid var(--accent);
  padding: 4px 8px;
  border-radius: 0 4px 4px 0;
  color: var(--text-dim);
  font-weight: 500;
}

/* Inventory link chips */
.inv {
  position: relative;
}
.inv-links {
  position: absolute;
  top: 6px; right: 8px;
  display: flex; gap: 3px;
}
.inv-links a {
  font-size: 9px;
  padding: 1px 4px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text-mute);
  text-decoration: none;
  font-weight: 600;
}
.inv-links a:hover { color: var(--accent-2); border-color: var(--accent-dim); text-decoration: none; }

/* ---------- Inventory ---------- */
.inv-list { display: grid; gap: 4px; }
.inv {
  padding: 6px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  display: flex; gap: 6px; align-items: baseline;
  flex-wrap: wrap;
  cursor: pointer; transition: border-color .12s;
  min-width: 0;
}
.inv:hover { border-color: var(--accent-dim); }
.inv .nm { font-weight: 600; color: var(--accent-2); }
.inv .desc { color: var(--text-dim); font-size: 12px; }

/* Items with equip/attune toggles (v6.3: refactored for mobile-first vertical layout) */
.inv-item {
  padding: 9px 11px;
  display: flex; flex-direction: column; gap: 5px;
  cursor: default;
  overflow: hidden;       /* contain any overflowing children */
  min-width: 0;
  position: relative;
}
.inv-item.active { border-color: var(--accent-dim); background: linear-gradient(0deg, var(--bg-2), rgba(200,165,90,0.04)); }
.inv-item.inactive { opacity: 0.78; }
.inv-item * { max-width: 100%; min-width: 0; box-sizing: border-box; }
.inv-top {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.inv-top .nm { font-size: 13px; flex: 1 1 auto; min-width: 0; word-wrap: break-word; overflow-wrap: anywhere; }
.inv-toggles { display: flex; gap: 5px; flex-shrink: 0; }
.tgl {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 7px; border-radius: 5px; border: 1px solid var(--line);
  font-size: 10px; color: var(--text-dim);
  background: var(--bg-1); cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.5px;
  user-select: none;
}
.tgl input { display: none; }
.tgl:has(input:checked) { background: var(--bg-3); border-color: var(--accent-dim); color: var(--accent-2); }
.tgl.disabled { opacity: 0.4; cursor: not-allowed; }
.tgl:hover { border-color: var(--accent-dim); }
.inv-state {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 10px; color: var(--text-mute);
  width: 100%;
}
.state-tag {
  padding: 1px 6px; border-radius: 8px; font-size: 9px; font-weight: 700;
  letter-spacing: 0.5px; text-transform: uppercase;
}
.state-tag.on { background: var(--good); color: #000; }
.state-tag.off { background: var(--line); color: var(--text-dim); }
.inv-item .inv-links { position: static; margin-left: 0; display: flex; gap: 4px; }
.inv-item .inv-links a { font-size: 9px; padding: 1px 5px; }
.inv-item .inv-desc { font-size: 11px; line-height: 1.4; width: 100%; word-wrap: break-word; overflow-wrap: anywhere; color: var(--text-dim); }
.inv-item .inv-desc.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inv-item .inv-more {
  align-self: flex-start;
  margin-top: 2px;
  font-size: 10px; font-weight: 600;
  padding: 3px 10px; border-radius: 5px;
  background: var(--bg-2); color: var(--accent);
  border: 1px solid var(--accent-dim);
  cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.inv-item .inv-more:hover { background: var(--accent); color: #000; }
.inv-item .inv-more:active { transform: translateY(1px); }

.currency { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.coin {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 8px;
  font-size: 12px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.coin .n { color: var(--gold); }
.coin .k { color: var(--text-mute); font-size: 10px; margin-right: 3px; text-transform: uppercase; }

/* ---------- Active roll toggles (per user mockup) ---------- */
.active-roll {
  display: grid; gap: 6px;
}
.roll-toggle {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all .15s;
  min-width: 0;
}
.roll-toggle:hover { border-color: var(--accent-dim); }
.roll-toggle.active { border-color: var(--accent); background: var(--bg-3); }
.roll-toggle .checkbox {
  width: 22px; height: 22px;
  border: 2px solid var(--line);
  border-radius: 5px;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-1);
  transition: all .15s;
}
.roll-toggle.active .checkbox { background: var(--accent); border-color: var(--accent); color: #000; }
.roll-toggle .checkbox::after {
  content: "✓"; color: #000; font-size: 14px; font-weight: 900;
  display: none;
}
.roll-toggle.active .checkbox::after { display: block; }
.roll-toggle .lbl { flex: 1; min-width: 0; }
.roll-toggle .lbl .nm { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 1.2px; color: var(--accent-2); }
.roll-toggle .lbl .ds { font-size: 13px; font-weight: 600; color: var(--text); margin-top: 1px; }
.roll-toggle .badge { font-size: 10px; padding: 2px 6px; border-radius: 999px; background: var(--bg-3); color: var(--text-dim); flex-shrink: 0; }

.adv-dis {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  margin-top: 6px;
}
.adv-btn {
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  color: var(--text);
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.adv-btn.adv:hover, .adv-btn.adv.active { border-color: var(--good); color: var(--good); }
.adv-btn.dis:hover, .adv-btn.dis.active { border-color: var(--bad); color: var(--bad); }
.adv-btn.active { background: var(--bg-3); }

.roll-d20-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 16px; font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  margin-top: 6px;
  transition: filter .12s;
}
.roll-d20-btn:hover { filter: brightness(1.1); }
.roll-d20-btn:active { transform: scale(.98); }

/* ---------- FAB with d20 icon ---------- */
.fab {
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 80;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 50%;
  width: 60px; height: 60px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s;
  font-family: inherit;
  padding: 0;
}
.fab:hover { transform: scale(1.08); }
.fab:active { transform: scale(.95); }
.fab-icon { display: block; color: #000; }
.fab .lab {
  position: absolute;
  bottom: -22px; right: 0;
  font-size: 10px;
  color: var(--text-mute);
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 16px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.4);
  animation: slideUp .25s;
}
@media (min-width: 600px) {
  .modal-back { align-items: center; padding: 20px; }
  .modal { border-radius: 16px; }
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal h2 {
  margin: 0 0 12px;
  font-size: 14px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--accent); font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
}
.modal h2 .close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer; padding: 0; line-height: 1;
}
.modal .quick-row {
  display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px;
}
.modal .quick-row .dbtn {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 10px; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.modal .quick-row .dbtn:hover { border-color: var(--accent); color: var(--accent-2); }
.modal .custom-row { display: flex; gap: 6px; }
.modal .custom-row input {
  flex: 1; min-width: 0;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px;
  color: var(--text); font-size: 14px;
  font-family: inherit;
}
.modal .custom-row input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.modal .custom-row button {
  background: var(--accent); color: #000;
  border: none; border-radius: 8px;
  padding: 8px 14px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}

/* ---------- Roll tray (toasts) ---------- */
.roll-tray {
  position: fixed; bottom: 80px; right: 12px; left: 12px;
  z-index: 70;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
  max-width: 360px; margin-left: auto;
}
.roll {
  background: var(--bg-card);
  border: 1px solid var(--accent-dim);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 9px 11px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: rollIn .3s;
  font-size: 13px;
  max-width: 100%;
}
@keyframes rollIn { from { transform: translateY(20px) scale(.95); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.roll.fading { animation: rollOut .3s forwards; }
@keyframes rollOut { to { transform: translateX(120%); opacity: 0; } }
.roll .head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-bottom: 3px; min-width: 0; }
.roll .label { color: var(--accent-2); font-weight: 600; font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.roll .total { font-size: 17px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.roll .breakdown { color: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; }
:root[data-theme="dark"] .roll.crit .total { color: var(--good); text-shadow: 0 0 8px rgba(106,211,106,.5); }
:root[data-theme="dark"] .roll.fumble .total { color: var(--bad); text-shadow: 0 0 8px rgba(226,106,106,.5); }
.roll .nat { font-size: 10px; padding: 1px 4px; border-radius: 4px; margin-left: 4px; background: var(--bg-2); color: var(--text-dim); }
:root[data-theme="dark"] .roll .nat.crit { color: var(--good); border: 1px solid var(--good); }
:root[data-theme="dark"] .roll .nat.fumble { color: var(--bad); border: 1px solid var(--bad); }
.roll .badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.roll .badges .b {
  font-size: 9px; padding: 1px 5px; border-radius: 4px;
  background: var(--bg-2); color: var(--text-dim);
  font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
}

/* ---------- Roll log ---------- */
.log { max-height: 200px; overflow-y: auto; }
.log-entry {
  font-size: 12px; padding: 3px 0;
  border-bottom: 1px dashed var(--line-soft);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  display: flex; gap: 6px; align-items: baseline;
}
.log-entry:last-child { border-bottom: none; }
.log-entry .ts { color: var(--text-mute); font-size: 10px; min-width: 38px; }
.log-entry .lbl { color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.log-entry .t { color: var(--accent-2); font-weight: 600; }

/* ---------- Definition popup (spell/feature tap) ---------- */
.def-pop {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.def-pop.open { display: flex; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.def-box {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  max-width: 480px; width: 100%;
  max-height: 80vh; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.def-box h3 {
  margin: 0 0 4px; font-size: 18px; color: var(--text);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.def-box h3 .close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 0;
}
.def-box .src {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-mute); margin-bottom: 12px;
}
.def-box .meta, .spell-modal-meta {
  display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 12px;
}
.def-box .meta .m, .spell-modal-meta .m {
  font-size: 11px; padding: 3px 8px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 6px;
  white-space: nowrap;
}
.def-box .meta .m strong, .spell-modal-meta .m strong { color: var(--accent-2); margin-right: 4px; }
.def-box .desc { font-size: 13px; line-height: 1.5; color: var(--text); margin: 0 0 14px; }
.def-box .links { display: flex; flex-wrap: wrap; gap: 6px; }
.def-box .links a {
  font-size: 12px; padding: 6px 10px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.def-box .links a:hover { border-color: var(--accent); color: var(--accent-2); text-decoration: none; }

/* ---------- Notes tab ---------- */
.notes-textarea {
  width: 100%; min-height: 60vh;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  resize: vertical;
  font-family: inherit;
}
.notes-textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.notes-hint { color: var(--text-mute); font-size: 11px; margin-top: 6px; }

/* ---------- Lore tab ---------- */
.lore-grid { display: grid; gap: 12px; }
.lore-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--accent); font-weight: 700; margin: 0 0 6px;
}
.lore-section .field {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 6px;
}
.lore-section .field .nm {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-mute); font-weight: 700; margin-bottom: 3px;
}
.lore-section .field .val {
  font-size: 13px; color: var(--text); line-height: 1.5;
  white-space: pre-wrap;
}
.lore-section .field input, .lore-section .field textarea {
  width: 100%;
  background: transparent; border: none; padding: 0;
  color: var(--text); font: inherit; resize: vertical;
  font-family: inherit;
}
.lore-section .field input:focus, .lore-section .field textarea:focus { outline: none; }

.portrait {
  width: 100%;
  aspect-ratio: 1/1;
  max-width: 240px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-mute);
  font-size: 13px;
  overflow: hidden;
  position: relative;
  margin: 0 auto 12px;
}
.portrait img { width: 100%; height: 100%; object-fit: cover; }
.portrait .upload {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5);
  opacity: 0; transition: opacity .15s;
  cursor: pointer;
  color: #fff; font-size: 12px; font-weight: 600;
}
.portrait:hover .upload { opacity: 1; }
.portrait input[type=file] { display: none; }

/* ---------- Index page (character list) ---------- */
.char-grid {
  display: grid; grid-template-columns: 1fr; gap: 12px;
}
.char-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  cursor: pointer; transition: all .15s;
  text-decoration: none; color: inherit;
  position: relative; overflow: hidden;
  display: block;
}
.char-card:hover { border-color: var(--accent-dim); transform: translateY(-1px); text-decoration: none; }
.char-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent);
}
.char-card h3 { margin: 0; font-size: 18px; color: var(--text); font-weight: 700; }
.char-card .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.char-card .meta { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.char-card .meter {
  margin-top: 10px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px;
}
.char-card .meter div {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 4px;
  text-align: center;
}
.char-card .meter .lab { font-size: 9px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 1.2px; font-weight: 700; }
.char-card .meter .v { font-size: 14px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

.index-header { padding: 24px 14px 8px; text-align: center; }
.index-header h1 {
  margin: 0; font-size: 24px; color: var(--accent);
  font-weight: 800; letter-spacing: .5px;
}
.index-header p { color: var(--text-dim); margin: 4px 0 0; font-size: 13px; }

/* ============================================================
   ACTION ECONOMY (Actions tab)
   ============================================================ */
.action-econ {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}
.ae-pip {
  background: var(--bg-2);
  border: 2px solid var(--good);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  min-width: 0;
  user-select: none;
}
.ae-pip .ae-icon { font-size: 24px; line-height: 1; }
.ae-pip .ae-lab {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--good);
  margin-top: 6px;
}
.ae-pip.used {
  background: var(--bg-1);
  border-color: var(--line);
  opacity: .5;
}
.ae-pip.used .ae-lab { color: var(--text-mute); }
.ae-pip.used .ae-icon { filter: grayscale(1) opacity(.4); }
.ae-endturn {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 12px;
  padding: 12px 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  font-family: inherit;
  transition: filter .12s;
}
.ae-endturn:hover { filter: brightness(1.1); }
.ae-endturn:active { transform: scale(.97); }

@media (min-width: 600px) {
  .action-econ { grid-template-columns: 1fr 1fr 1fr 1fr; }
}

/* ============================================================
   EDITION TOGGLE
   ============================================================ */
.edition-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-2);
}
.edition-toggle .ed-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border-radius: 0;
  border-right: 1px solid var(--line);
  letter-spacing: 0.5px;
}
.edition-toggle .ed-btn:last-child { border-right: none; }
.edition-toggle .ed-btn.active { background: var(--accent); color: #000; }

/* ============================================================
   CUSTOM CREATOR MODAL
   ============================================================ */
.modal.modal-wide { max-width: 540px; max-height: 92vh; }
.creator { display: flex; flex-direction: column; gap: 10px; }
.creator-row { display: grid; gap: 4px; }
.creator-row.triple { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.creator-row.double { grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 500px) {
  .creator-row.triple, .creator-row.double { grid-template-columns: 1fr; }
}
.creator-row > label, .creator-row > div > label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-dim);
}
.creator-row input, .creator-row textarea, .creator-row select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
.creator-row input:focus, .creator-row textarea:focus, .creator-row select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.cc-cost { display: flex; gap: 4px; }
.cc-cost button {
  flex: 1;
  background: var(--bg-1);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.cc-cost button.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* v6: Spell-slot behavior picker — uses cc-slot-behavior class for its own styles */
.cc-slot-behavior { display: flex; gap: 4px; flex-wrap: wrap; }
.cc-slot-behavior button {
  flex: 1;
  min-width: 130px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.cc-slot-behavior button.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* v6.1: Edit Stats modal */
.es-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  margin-bottom: 6px;
}
@media (min-width: 600px) { .es-grid { grid-template-columns: repeat(3, 1fr); } }
.es-stat {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 6px; align-items: center;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px;
}
.es-lab { font-size: 11px; font-weight: 700; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.5px; }
.es-base {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 4px 6px; color: var(--text); font-size: 14px; font-weight: 600;
  text-align: center; font-family: ui-monospace, "SF Mono", monospace;
  width: 100%;
}
.es-eff { font-size: 12px; color: var(--text-dim); font-family: ui-monospace, monospace; min-width: 50px; text-align: right; }
.es-eff .es-mod { color: var(--accent); font-weight: 700; }
.es-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.es-row label { font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; min-width: 110px; }
.es-row.triple { display: grid; grid-template-columns: 1fr 80px 1fr; gap: 8px; align-items: center; }
.es-row.triple > div label { display: block; font-size: 10px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px; }
.es-row.triple input, .es-row.triple select { width: 100%; }
.es-row input, .es-row select, .es-race input, .es-race select {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 5px;
  padding: 5px 8px; color: var(--text); font-size: 12px; font-family: inherit;
}
.es-feat-row {
  display: grid; grid-template-columns: 60px 60px 1fr 30px; gap: 6px; align-items: center;
  margin-bottom: 4px;
}
.es-feat-row select, .es-feat-row input {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 5px;
  padding: 4px 6px; color: var(--text); font-size: 12px; font-family: inherit;
}
.es-feat-del {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--bad);
  border-radius: 5px; padding: 4px 8px; font-size: 14px; font-weight: 700;
  cursor: pointer;
}
.es-preview {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px;
}
.es-pv-scores { display: flex; flex-wrap: wrap; gap: 6px; }
.es-pv-stat {
  flex: 1; min-width: 60px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 4px 6px; text-align: center;
}
.es-pv-lab { font-size: 9px; font-weight: 700; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.5px; }
.es-pv-num { font-size: 18px; font-weight: 800; color: var(--text); }
.es-pv-mod { font-size: 10px; color: var(--text-dim); font-family: ui-monospace, monospace; }

/* v6: Actionable list (one-tap activation on Actions tab) */
.actionable {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 5px;
  font-size: 13px;
  flex-wrap: wrap;
}
.actionable-res { background: linear-gradient(0deg, var(--bg-1), rgba(200,165,90,0.04)); }
.actionable-item { border-color: var(--accent-dim); }
.actionable-spell { border-left: 3px solid var(--accent-dim); }
.actionable-main { flex: 1 1 100%; min-width: 0; }
.actionable-name { font-weight: 500; min-width: 0; word-wrap: break-word; overflow-wrap: anywhere; }
.actionable-sub { font-size: 10.5px; color: var(--text-mute); margin-top: 2px; line-height: 1.35; word-wrap: break-word; overflow-wrap: anywhere; }
.actionable-pips { font-size: 11px; color: var(--text-mute); margin-left: 4px; }
.actionable-cost {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 5px;
  background: var(--bg-2); color: var(--text-dim);
  border: 1px solid var(--line);
  max-width: 100%;
  min-width: 0;
  word-wrap: break-word; overflow-wrap: anywhere;
  white-space: normal; line-height: 1.3;
}
.actionable-use {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 5px 12px; border-radius: 6px;
  background: var(--accent); color: #000;
  border: 1px solid var(--accent);
  cursor: pointer; flex-shrink: 0;
  min-width: 60px;
}
.actionable-use:hover { background: var(--accent-2); }
.actionable-use:active { transform: translateY(1px); }

/* v6: Effect category picker (replaces dropdown) */
.cc-effect-cats {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
}
.cc-cat {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 9px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 11px; font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  transition: all 0.12s;
}
.cc-cat:hover { border-color: var(--accent-dim); }
.cc-cat input { display: none; }
.cc-cat.on { background: var(--accent); color: #000; border-color: var(--accent); }

.cc-effect {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.cc-effect-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px;
}
.cc-effect-kind {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--accent-2);
  flex-shrink: 0;
}
.cc-effect-sum {
  font-size: 12px; color: var(--text); flex: 1;
  font-family: ui-monospace, "SF Mono", monospace;
}
.cc-remove {
  background: transparent; border: none; color: var(--bad);
  font-size: 18px; font-weight: 700; cursor: pointer;
  padding: 0 4px; line-height: 1;
}
.cc-effect-body {
  font-size: 12px; color: var(--text-dim);
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.cc-effect-body input, .cc-effect-body select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 6px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.cc-add { display: flex; gap: 6px; }
.cc-add select { flex: 1; }
.cc-add .btn { flex-shrink: 0; }
.cc-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px;
}
.creator-edit-btn {
  font-size: 12px; padding: 5px 9px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 6px; color: var(--text);
  text-decoration: none; cursor: pointer;
  display: inline-block; margin-right: 4px;
}
.creator-edit-btn.danger { color: var(--bad); border-color: var(--bad); }
.creator-edit-btn:hover { border-color: var(--accent); text-decoration: none; }

/* ============================================================
   CUSTOM SECTIONS (per-tab)
   ============================================================ */
.custom-section { display: flex; flex-direction: column; gap: 6px; }
.custom-add-btn {
  background: transparent;
  border: 1.5px dashed var(--line);
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
  text-align: center;
  width: 100%;
}
.custom-add-btn:hover { border-color: var(--accent); color: var(--accent-2); }
.custom-add-btn-top {
  margin-bottom: 8px;
}

/* ============================================================
   PROFICIENCY SOURCES (rendered in Features tab)
   ============================================================ */
.prof-list { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.prof-chip {
  display: inline-block;
  padding: 3px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.prof-chip.expert {
  background: var(--bg-3);
  border-color: var(--accent-dim);
  color: var(--accent-2);
}
.prof-chip small { color: var(--text-mute); font-size: 9px; margin-left: 3px; }
.src-tag {
  color: var(--text-mute);
  font-size: 9px;
  margin-left: 2px;
}

@media (min-width: 600px) {
  .wrap { padding: 18px; }
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
  .combat-grid { grid-template-columns: repeat(4, 1fr); }
  .row2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
  .spell-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
  .index-header { padding: 40px 18px 16px; }
  .index-header h1 { font-size: 32px; }
  .hero h1 { font-size: 28px; }
  .hp-num { font-size: 28px; }
  .roll-tray { left: auto; max-width: 360px; }
  .tabs { padding: 0 18px; }
}
@media (min-width: 880px) {
  .wrap { padding: 22px; gap: 14px; }
  .topbar { padding: 12px 22px; }
  .topbar .title { font-size: 16px; }
  .topbar .title small { font-size: 11px; }
  .card { padding: 16px 18px; }
  .tabs { top: 49px; padding: 0 22px; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

@media print {
  .dicebar, .roll-tray, .hp-controls, .topbar, .tabs, .fab, .modal-back, .def-pop, button { display: none !important; }
  body { background: white; color: black; }
  .card, .hero { box-shadow: none; }
}

/* v6.2: Toast for non-blocking notifications (e.g. render errors) */
.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%) translateY(-100px);
  z-index: 200; padding: 10px 18px; border-radius: 8px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--accent);
  font-size: 13px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transition: transform .25s ease, opacity .25s ease;
  opacity: 0; pointer-events: none;
  max-width: 92vw;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.toast.bad { border-color: var(--bad); }
.toast.warn { border-color: var(--warn); }
.toast.good { border-color: var(--good); }

/* ==========================================================================
   Character Builder
   ========================================================================== */
.step { display: none; }
.step.active { display: block; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-dim); }
.form-group input, .form-group select { 
  width: 100%; padding: 10px 12px; 
  background: var(--bg-2); border: 1px solid var(--line); 
  border-radius: 6px; color: var(--text); font-size: 14px;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-box { background: var(--bg-2); padding: 8px; border-radius: 6px; text-align: center; }
.stat-box .muted { font-size: 11px; }
.stat-box .val { font-size: 18px; color: var(--accent); }
.stat-box .mod { font-size: 12px; color: var(--text-dim); }

.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; max-height: 300px; overflow-y: auto; }
.class-card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px; cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}
.class-card:hover { border-color: var(--accent); }
.class-card.selected { border-color: var(--accent); background: rgba(200,165,90,0.15); }
.class-card h3 { margin: 0 0 6px 0; font-size: 14px; }
.class-card .meta { font-size: 11px; color: var(--text-dim); }
.class-card .meta span { display: block; }

.btn-row { display: flex; gap: 12px; margin-top: 20px; }
.btn { padding: 10px 20px; border-radius: 6px; font-size: 14px; cursor: pointer; border: none; }
.btn.primary { background: var(--accent); color: var(--bg-0); }
.btn.secondary { background: var(--bg-2); color: var(--text); border: 1px solid var(--line); }
.btn.accent { background: var(--accent-2); color: var(--bg-0); }

.summary-box { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }

.loading { text-align: center; padding: 20px; color: var(--text-dim); }
.spinner { 
  width: 20px; height: 20px; border: 2px solid var(--line); 
  border-top-color: var(--accent); border-radius: 50%; 
  animation: spin 0.8s linear infinite; margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.accent { color: var(--accent); }
.bad { color: var(--bad); }
.muted { color: var(--text-dim); font-size: 13px; }

/* ==========================================================================
   Builder Modals
   ========================================================================== */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; max-height: 250px; overflow-y: auto; }
.choice-card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.choice-card:hover { border-color: var(--accent); }
.choice-card.selected { border-color: var(--accent); background: rgba(200,165,90,0.15); }
.choice-card h3 { margin: 0 0 4px; font-size: 13px; }
.choice-card .meta { font-size: 11px; color: var(--text-dim); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 100; display: none;
}
.modal-backdrop.open { display: block; }

.modal-content {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 90%; max-width: 500px; max-height: 80vh;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; z-index: 101; display: none; overflow: hidden;
}
.modal-content.open { display: flex; flex-direction: column; }

.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; color: var(--text);
  font-size: 24px; cursor: pointer;
}

.modal-tabs {
  display: flex; gap: 8px; margin: 16px 0; border-bottom: 1px solid var(--line);
}
.modal-tabs .tab {
  padding: 8px 12px; background: none; border: none;
  color: var(--text-dim); cursor: pointer; border-radius: 6px 6px 0 0;
}
.modal-tabs .tab.active { color: var(--accent); background: var(--bg-2); }

.modal-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.feature-item, .subclass-item {
  background: var(--bg-2); border-radius: 6px; padding: 10px; margin-bottom: 8px;
  cursor: pointer;
}
.feature-item strong, .subclass-item strong { font-size: 13px; display: block; }
.feature-item p, .subclass-item p { font-size: 12px; color: var(--text-dim); margin: 4px 0 0; }
.subclass-item.selected { border-color: var(--accent); background: rgba(200,165,90,0.15); }

.modal-actions { display: flex; gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ==========================================================================
   Builder Accordion
   ========================================================================== */
.accordion { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.accordion-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--bg-2); cursor: pointer;
  font-weight: 600;
}
.accordion-header::after { content: "▼"; font-size: 10px; }
.accordion-header.open::after { content: "▲"; }
.accordion-header .check { display: none; color: var(--good); font-size: 14px; }
.accordion-header.open .check { display: block; }

.accordion-content { display: none; padding: 16px; background: var(--bg-1); }
.accordion-content.open { display: block; }

.accordion-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .accordion-split { grid-template-columns: 1fr; } }

.grid-panel { max-height: 300px; overflow-y: auto; }
.detail-panel { max-height: 300px; overflow-y: auto; }

.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.detail-header h3 { margin: 0; color: var(--accent); }
.detail-header .source { font-size: 12px; color: var(--text-dim); background: var(--bg-2); padding: 4px 8px; border-radius: 4px; }

.detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.detail-stats > div { background: var(--bg-2); padding: 8px; border-radius: 6px; text-align: center; }
.detail-stats .label { display: block; font-size: 10px; color: var(--text-dim); }
.detail-stats span:last-child { font-size: 14px; color: var(--accent); font-weight: 600; }

.detail-section { margin-top: 16px; }
.detail-section h4 { margin: 0 0 8px; font-size: 12px; color: var(--text-dim); text-transform: uppercase; }

.detail-item { background: var(--bg-2); padding: 10px; border-radius: 6px; margin-bottom: 6px; }
.detail-item strong { font-size: 12px; display: block; }
.detail-item p { font-size: 11px; color: var(--text-dim); margin: 4px 0 0; }

.subclass-list { display: flex; flex-wrap: wrap; gap: 6px; }
.subclass-chip {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.subclass-chip:hover { border-color: var(--accent); }
.subclass-chip.selected { background: var(--accent); color: var(--bg-0); border-color: var(--accent); }

/* ==========================================================================
   Builder v5 — Mobile-first
   ========================================================================== */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 16px;
}
.pick-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.pick-card:hover { border-color: var(--accent); }
.pick-card.selected { border-color: var(--accent); background: rgba(200,165,90,0.15); }
.pick-card strong { display: block; font-size: 14px; }
.pick-card span { font-size: 11px; color: var(--text-dim); }

.section-title {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin: 16px 0 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}
.modal.open { display: block; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
}
.modal-content {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 95%;
  max-width: 500px;
  max-height: 85vh;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  z-index: 10;
}
.modal-tabs {
  display: flex;
  gap: 4px;
  margin: 8px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.modal-tabs .tab {
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 6px 6px 0 0;
}
.modal-tabs .tab.active { color: var(--accent); background: var(--bg-2); }
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.btn.full { width: 100%; }

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.stat-row span { color: var(--text-dim); font-size: 13px; }
.stat-row strong { color: var(--accent); }

.stat-row-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.feature-card {
  background: var(--bg-2);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}
.feature-card strong { display: block; font-size: 13px; margin-bottom: 4px; }
.feature-card p { font-size: 12px; color: var(--text-dim); margin: 0; line-height: 1.5; }

.subclass-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.subclass-card:hover { border-color: var(--accent); }
.subclass-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.subclass-header strong { font-size: 14px; }
.subclass-header .check { color: var(--accent); font-size: 16px; }
.subclass-card p { font-size: 12px; color: var(--text-dim); margin: 8px 0 0; }

@media (max-width: 480px) {
  .pick-grid { grid-template-columns: 1fr 1fr; }
  .stat-row-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Modal Accordions
   ========================================================================== */
.modal-section {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.section-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-item {
  background: var(--bg-2);
  padding: 10px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  text-align: center;
}
.stat-item span { font-size: 11px; color: var(--text-dim); }
.stat-item strong { font-size: 14px; color: var(--accent); }

.accordion-item {
  border-bottom: 1px solid var(--line);
}
.accordion-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.accordion-toggle::after { content: ""; }
.accordion-toggle .arrow {
  font-size: 10px;
  color: var(--text-dim);
}
.accordion-content {
  display: none;
  padding: 0 0 12px;
  max-height: 300px;
  overflow-y: auto;
}
.accordion-content.open { display: block; }

/* Builder screen accordions */
.builder-accordion { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.builder-accordion .accordion-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-2);
  border: none;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.builder-accordion .accordion-toggle.open { background: var(--bg-3); }
.builder-accordion .accordion-content { display: none; padding: 12px; background: var(--bg-1); max-height: 280px; overflow-y: auto; }
.builder-accordion .accordion-content.open { display: block; }

/* Filter bar */
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-bar input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-2); color: var(--text); font-size: 14px; }
.filter-bar select { padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-2); color: var(--text); font-size: 13px; min-width: 100px; }

/* Accordion arrow alignment */
.builder-accordion .accordion-toggle .arrow { flex-shrink: 0; margin-left: 8px; }

.feature-item {
  background: var(--bg-2);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}
.feature-item strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}
.feature-item p {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
}

.subclass-item {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.subclass-item:hover { border-color: var(--accent); }
.subclass-item.selected { border-color: var(--accent); background: rgba(200,165,90,0.15); }
.subclass-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.subclass-header strong { font-size: 14px; }
.subclass-header .check { color: var(--accent); font-size: 16px; }
.subclass-item p { font-size: 12px; color: var(--text-dim); margin: 8px 0 0; }
