/* ═══════════════════════════════════════════════════════════════════════════
   Arcane Ledger design system
   Every theme sets the same variable contract, including --font, so themes
   can change personality rather than just hue.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Every theme sets the same contract. Beyond colour they control corner
   radius, border weight, typeface, label casing and padding, so each one
   reads as a different piece of software rather than a recolour. */

:root,
[data-theme="ember"] {
  --bg: #12100a;         --surface: #1c1910;    --raised: #272317;
  --line: #3a3320;       --accent: #e8832a;     --accent-soft: rgba(232,131,42,.14);
  --text: #f2ead6;       --muted: #a29165;      --faint: #6b5f3c;
  --good: #4caf76;       --bad: #e8484a;        --warn: #e8a92a;
  --radius: 10px;        --radius-sm: 7px;      --border-w: 1px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-head: var(--font);
  --label-case: uppercase; --label-track: .09em;
  --pad: 14px;
  --shadow: 0 2px 14px rgba(0,0,0,.55);
}

[data-theme="crt"] {
  --bg: #000a02;         --surface: #001404;    --raised: #002108;
  --line: #00521f;       --accent: #24ff6a;     --accent-soft: rgba(36,255,106,.1);
  --text: #35f571;       --muted: #12b04a;      --faint: #0a7a31;
  --good: #24ff6a;       --bad: #ff5a2a;        --warn: #d4ff2a;
  --radius: 0px;         --radius-sm: 0px;      --border-w: 1px;
  --font: "Courier New", "Lucida Console", monospace;
  --font-head: var(--font);
  --label-case: uppercase; --label-track: .18em;
  --pad: 12px;
  --shadow: 0 0 14px rgba(36,255,106,.16);
}

[data-theme="parchment"] {
  --bg: #241a0c;         --surface: #f0dcae;    --raised: #e4cd9a;
  --line: #a9834a;       --accent: #7a3b18;     --accent-soft: rgba(122,59,24,.12);
  --text: #2e1e0c;       --muted: #6b5231;      --faint: #8d7248;
  --good: #4a6b28;       --bad: #9c2b18;        --warn: #9a6a12;
  --radius: 3px;         --radius-sm: 2px;      --border-w: 2px;
  --font: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-head: Georgia, "Iowan Old Style", serif;
  --label-case: none;    --label-track: .04em;
  --pad: 18px;
  --shadow: 0 3px 14px rgba(0,0,0,.45);
}

[data-theme="xp"] {
  --bg: #5a7edc;         --surface: #ece9d8;    --raised: #f6f4ec;
  --line: #7f9db9;       --accent: #0a246a;     --accent-soft: rgba(10,36,106,.1);
  --text: #10100f;       --muted: #4a4a44;      --faint: #7c7c72;
  --good: #157a3a;       --bad: #b81414;        --warn: #a67a00;
  --radius: 4px;         --radius-sm: 3px;      --border-w: 2px;
  --font: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
  --font-head: var(--font);
  --label-case: none;    --label-track: 0;
  --pad: 12px;
  --shadow: 0 2px 8px rgba(0,0,40,.4);
}

[data-theme="void"] {
  --bg: #06040e;         --surface: #100b21;    --raised: #1a1233;
  --line: #33236e;       --accent: #b45cff;     --accent-soft: rgba(180,92,255,.16);
  --text: #e8dcff;       --muted: #8f6dc4;      --faint: #503a85;
  --good: #4fd99a;       --bad: #ff3c6a;        --warn: #ffc23c;
  --radius: 20px;        --radius-sm: 14px;     --border-w: 1px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-head: var(--font);
  --label-case: uppercase; --label-track: .14em;
  --pad: 18px;
  --shadow: 0 4px 26px rgba(110,0,200,.35);
}

[data-theme="steel"] {
  --bg: #0a0e14;         --surface: #121922;    --raised: #1a2331;
  --line: #2b3849;       --accent: #4a9bff;
  --accent-soft: rgba(74,155,255,.12);
  --text: #cbdaea;       --muted: #62809c;      --faint: #3b4d61;
  --good: #34cf82;       --bad: #f2495e;        --warn: #f2b134;
  --radius: 3px;         --radius-sm: 2px;      --border-w: 1px;
  --font: "SF Mono", "Roboto Mono", ui-monospace, "Segoe UI", sans-serif;
  --font-head: -apple-system, "Segoe UI", system-ui, sans-serif;
  --label-case: uppercase; --label-track: .11em;
  --pad: 11px;
  --shadow: 0 1px 6px rgba(0,0,0,.6);
}

[data-theme="blood"] {
  --bg: #0c0304;         --surface: #190709;    --raised: #260b0e;
  --line: #58151a;       --accent: #d62b2b;     --accent-soft: rgba(214,43,43,.15);
  --text: #f0cfcf;       --muted: #a04d4d;      --faint: #6d2a2a;
  --good: #46c97e;       --bad: #ff2626;        --warn: #e8a02a;
  --radius: 1px;         --radius-sm: 1px;      --border-w: 2px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-head: "Iowan Old Style", Georgia, serif;
  --label-case: uppercase; --label-track: .07em;
  --pad: 14px;
  --shadow: 0 2px 16px rgba(120,0,0,.45);
}

[data-theme="gold"] {
  --bg: #0b0900;         --surface: #171203;    --raised: #221b06;
  --line: #6b5410;       --accent: #f3b81a;     --accent-soft: rgba(243,184,26,.13);
  --text: #fdf3cf;       --muted: #b09338;      --faint: #715c18;
  --good: #56d66a;       --bad: #f2402e;        --warn: #f3b81a;
  --radius: 6px;         --radius-sm: 4px;      --border-w: 1px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-head: "Iowan Old Style", Georgia, serif;
  --label-case: uppercase; --label-track: .16em;
  --pad: 16px;
  --shadow: 0 2px 18px rgba(0,0,0,.7);
}

[data-theme="obsidian"] {
  --bg: #000000;         --surface: #0b0b0b;    --raised: #151515;
  --line: #2e2e2e;       --accent: #ffffff;     --accent-soft: rgba(255,255,255,.08);
  --text: #ededed;       --muted: #767676;      --faint: #454545;
  --good: #ffffff;       --bad: #ff4040;        --warn: #d0d0d0;
  --radius: 0px;         --radius-sm: 0px;      --border-w: 2px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-head: var(--font);
  --label-case: uppercase; --label-track: .22em;
  --pad: 16px;
  --shadow: none;
}


/* ── Reset ────────────────────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ═══════════════════════════════════════════════════════════════════════════
   Theme personality
   Structure stays identical across themes. What changes is the way surfaces,
   headings, tabs and buttons are drawn, so each one feels like a different
   application.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── CRT: a terminal. Blocky, bracketed, scanlined. ─────────────────────── */
[data-theme="crt"] body::after {
  content: "";
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px,
              rgba(0,0,0,.25) 2px, rgba(0,0,0,.25) 4px);
}
[data-theme="crt"] .card,
[data-theme="crt"] .entry,
[data-theme="crt"] .row-card { box-shadow: inset 0 0 0 1px rgba(36,255,106,.08); }
[data-theme="crt"] .card-head::before,
[data-theme="crt"] .section-head h2::before { content: "[ "; }
[data-theme="crt"] .card-head::after,
[data-theme="crt"] .section-head h2::after { content: " ]"; }
[data-theme="crt"] .btn::before { content: "["; margin-right: 1px; }
[data-theme="crt"] .btn::after { content: "]"; margin-left: 1px; }
[data-theme="crt"] .btn { text-transform: uppercase; letter-spacing: .08em; }
[data-theme="crt"] .btn-primary { background: var(--accent); color: #001404; }
[data-theme="crt"] .tab { border-bottom-width: 0; }
[data-theme="crt"] .tab[aria-selected="true"] { background: var(--accent); color: #001404; }
[data-theme="crt"] .stat-mod,
[data-theme="crt"] .big-num,
[data-theme="crt"] .topbar-title { text-shadow: 0 0 7px currentColor; }
[data-theme="crt"] .pip { border-radius: 0; }
[data-theme="crt"] .avatar { border-radius: 0; }
[data-theme="crt"] .chip { border-radius: 0; }
[data-theme="crt"] .step,
[data-theme="crt"] .mini-step { border-radius: 0; }

/* ── Parchment: an illuminated page. Light surfaces, ruled headings. ───── */
[data-theme="parchment"] body {
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(120,80,30,.18), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(90,60,20,.16), transparent 55%);
}
[data-theme="parchment"] .shell {
  background: #e8d4a6;
  box-shadow: 0 0 40px rgba(0,0,0,.55);
}
[data-theme="parchment"] .topbar {
  background: #d9c08c;
  border-bottom: 2px solid var(--line);
}
[data-theme="parchment"] .card,
[data-theme="parchment"] .entry,
[data-theme="parchment"] .row-card,
[data-theme="parchment"] .hp-panel {
  box-shadow: 0 1px 0 rgba(255,255,255,.5) inset, 0 2px 5px rgba(90,60,20,.2);
}
[data-theme="parchment"] .card-head,
[data-theme="parchment"] .section-head h2 {
  font-variant: small-caps;
  font-size: 14px;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
}
[data-theme="parchment"] .btn-primary { background: var(--accent); color: #f5e6c4; }
[data-theme="parchment"] .btn-ghost { background: #e0c894; }
[data-theme="parchment"] .tab[aria-selected="true"] { border-bottom-width: 3px; }
[data-theme="parchment"] .note { background: #e4cd9a; border: 1px solid var(--line); }
[data-theme="parchment"] .init-row { background: #e4cd9a; }
[data-theme="parchment"] .toast { background: #e8d4a6; color: var(--text); }

/* ── Classic Blue: bevelled chrome, the way desktops used to look. ──────── */
[data-theme="xp"] .shell { background: var(--surface); }
[data-theme="xp"] .topbar {
  background: linear-gradient(180deg, #3f8ae8 0%, #1d5fc4 48%, #14459b 100%);
  border-bottom: 1px solid #0a2f6e;
  color: #fff;
}
[data-theme="xp"] .topbar-title { color: #fff; text-shadow: 1px 1px 1px rgba(0,0,0,.5); }
[data-theme="xp"] .topbar .icon-btn, [data-theme="xp"] .crumb { color: #dbe9ff; }
[data-theme="xp"] .card,
[data-theme="xp"] .entry,
[data-theme="xp"] .row-card,
[data-theme="xp"] .hp-panel {
  background: var(--raised);
  border-top-color: #fff; border-left-color: #fff;
  border-right-color: #9a9a8e; border-bottom-color: #9a9a8e;
}
[data-theme="xp"] .btn {
  border: 2px solid;
  border-top-color: #fff; border-left-color: #fff;
  border-right-color: #7d7d72; border-bottom-color: #7d7d72;
  background: linear-gradient(180deg, #f8f7f2 0%, #dedbcc 100%);
  color: #10100f;
}
[data-theme="xp"] .btn:active {
  border-top-color: #7d7d72; border-left-color: #7d7d72;
  border-right-color: #fff; border-bottom-color: #fff;
  transform: none;
}
[data-theme="xp"] .btn-primary {
  background: linear-gradient(180deg, #6db2ff 0%, #2a6fd4 100%);
  color: #fff; text-shadow: 1px 1px 1px rgba(0,0,0,.35);
}
[data-theme="xp"] .btn-danger { background: linear-gradient(180deg, #ff8a8a, #c62020); }
[data-theme="xp"] .btn-good { background: linear-gradient(180deg, #8ce0a5, #1e8a45); color: #fff; }
[data-theme="xp"] .tabs { background: #d8d4c2; }
[data-theme="xp"] .tab {
  background: linear-gradient(180deg, #f2f0e6, #d4d0be);
  border: 1px solid #9a9a8e; border-bottom: none;
  border-radius: 4px 4px 0 0; margin-right: 2px; color: #3a3a34;
}
[data-theme="xp"] .tab[aria-selected="true"] {
  background: var(--raised); color: #0a246a; font-weight: 700;
  position: relative; top: 1px;
}
[data-theme="xp"] .modal { border: 2px solid #0a2f6e; }
[data-theme="xp"] .modal-head {
  background: linear-gradient(180deg, #3f8ae8, #14459b);
  color: #fff; border-bottom: none;
}
[data-theme="xp"] .modal-head h3 { color: #fff; }
[data-theme="xp"] .modal-head .icon-btn { color: #fff; }
[data-theme="xp"] .input,
[data-theme="xp"] .field input,
[data-theme="xp"] .field select,
[data-theme="xp"] .field textarea { background: #fff; border-color: #7f9db9; }

/* ── Void: soft, rounded and glowing. ──────────────────────────────────── */
[data-theme="void"] body {
  background-image:
    radial-gradient(ellipse at 15% 0%, rgba(120,40,220,.2), transparent 55%),
    radial-gradient(ellipse at 85% 100%, rgba(60,20,160,.22), transparent 55%);
}
[data-theme="void"] .card,
[data-theme="void"] .entry,
[data-theme="void"] .row-card,
[data-theme="void"] .hp-panel { box-shadow: 0 4px 22px rgba(90,0,180,.22); }
[data-theme="void"] .btn-primary {
  background: linear-gradient(135deg, #d07aff 0%, #8b3ce0 100%);
  color: #fff; box-shadow: 0 3px 16px rgba(180,92,255,.4);
}
[data-theme="void"] .tab[aria-selected="true"] {
  background: var(--accent-soft); border-radius: 14px 14px 0 0;
}
[data-theme="void"] .avatar { box-shadow: 0 0 16px rgba(180,92,255,.3); }
[data-theme="void"] .pip { box-shadow: 0 0 9px rgba(180,92,255,.5); }
[data-theme="void"] .topbar { background: rgba(16,11,33,.85); backdrop-filter: blur(12px); }

/* ── Steel: dense and technical. Thin rules, accent spine on every card. ── */
[data-theme="steel"] .card,
[data-theme="steel"] .entry,
[data-theme="steel"] .hp-panel { border-left: 2px solid var(--accent); }
[data-theme="steel"] .card-head,
[data-theme="steel"] .section-head h2 { font-size: 10px; }
[data-theme="steel"] .btn { text-transform: uppercase; font-size: 12px; letter-spacing: .06em; }
[data-theme="steel"] .btn-primary { background: var(--accent); color: #05080d; }
[data-theme="steel"] .tabs { border-bottom-width: 2px; }
[data-theme="steel"] .tab { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; }
[data-theme="steel"] .page { padding: 12px; }
[data-theme="steel"] .row-card { padding: 9px 11px; }
[data-theme="steel"] .avatar { border-radius: 3px; }
[data-theme="steel"] .chip { border-radius: 2px; }

/* ── Blood: heavy and severe. ──────────────────────────────────────────── */
[data-theme="blood"] .card,
[data-theme="blood"] .entry,
[data-theme="blood"] .hp-panel { border-left: 4px solid var(--accent); }
[data-theme="blood"] .card-head,
[data-theme="blood"] .section-head h2,
[data-theme="blood"] .topbar-title { font-family: var(--font-head); font-size: 13px; }
[data-theme="blood"] .btn { text-transform: uppercase; font-weight: 700; letter-spacing: .05em; }
[data-theme="blood"] .btn-primary { background: var(--accent); color: #fff; }
[data-theme="blood"] .tab { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
[data-theme="blood"] .tab[aria-selected="true"] { border-bottom-width: 3px; }
[data-theme="blood"] .avatar { border-radius: 2px; border-width: 2px; }
[data-theme="blood"] .topbar { border-bottom-width: 2px; }

/* ── Gold: ornate, double-ruled, serif headings. ───────────────────────── */
[data-theme="gold"] .card,
[data-theme="gold"] .entry,
[data-theme="gold"] .hp-panel { box-shadow: inset 0 0 0 1px rgba(243,184,26,.14); }
[data-theme="gold"] .card-head,
[data-theme="gold"] .section-head h2 {
  font-family: var(--font-head); font-size: 13px; color: var(--accent);
  border-bottom: 1px solid rgba(243,184,26,.22); padding-bottom: 5px;
}
[data-theme="gold"] .topbar {
  border-bottom: 1px solid var(--accent);
  box-shadow: 0 1px 0 rgba(243,184,26,.2);
}
[data-theme="gold"] .topbar-title { font-family: var(--font-head); }
[data-theme="gold"] .btn-primary {
  background: linear-gradient(180deg, #ffd45c, #d99a08); color: #1a1400;
}
[data-theme="gold"] .avatar { border-color: var(--accent); }
[data-theme="gold"] .tab[aria-selected="true"] { border-bottom-width: 3px; }

/* ── Obsidian: brutalist monochrome. Thick rules, no colour, no radius. ── */
[data-theme="obsidian"] .card,
[data-theme="obsidian"] .entry,
[data-theme="obsidian"] .row-card,
[data-theme="obsidian"] .hp-panel { border-width: 2px; }
[data-theme="obsidian"] .card-head,
[data-theme="obsidian"] .section-head h2 { color: var(--text); font-size: 10px; }
[data-theme="obsidian"] .btn {
  text-transform: uppercase; letter-spacing: .12em; font-size: 12px;
  border: 2px solid var(--text); background: transparent; color: var(--text);
}
[data-theme="obsidian"] .btn-primary { background: var(--text); color: #000; }
[data-theme="obsidian"] .btn-danger { background: var(--bad); color: #000; border-color: var(--bad); }
[data-theme="obsidian"] .btn-good { background: var(--text); color: #000; }
[data-theme="obsidian"] .tabs { border-bottom-width: 2px; }
[data-theme="obsidian"] .tab { text-transform: uppercase; letter-spacing: .16em; font-size: 11px; }
[data-theme="obsidian"] .tab[aria-selected="true"] { background: var(--text); color: #000; }
[data-theme="obsidian"] .avatar { border-radius: 0; border-width: 2px; }
[data-theme="obsidian"] .chip { border-radius: 0; border-width: 2px; }
[data-theme="obsidian"] .pip { border-radius: 0; border-width: 2px; }
[data-theme="obsidian"] .step,
[data-theme="obsidian"] .mini-step { border-radius: 0; }
[data-theme="obsidian"] .hp-fill { border-radius: 0; }
[data-theme="obsidian"] .hp-track { border-radius: 0; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.shell {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}
@media (min-width: 721px) {
  .shell { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

.page { flex: 1; padding: 16px; padding-bottom: 96px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 54px;
}
.topbar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title .mark { color: var(--accent); }

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 17px;
  padding: 8px;
  border-radius: 8px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--raised); color: var(--text); }

.crumb {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  padding: 6px 8px;
  line-height: 1;
}
.crumb:hover { color: var(--text); }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  z-index: 90;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs.sticky-top { top: 54px; }

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 12px 14px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 12px;
}
.card-head {
  font-family: var(--font-head);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: var(--label-track);
  text-transform: var(--label-case);
  color: var(--muted);
  margin-bottom: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px 0 10px;
}
.section-head:first-child { margin-top: 0; }
.section-head h2 {
  font-family: var(--font-head);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: var(--label-track);
  text-transform: var(--label-case);
  color: var(--muted);
}

/* ── Row cards (campaigns, characters) ────────────────────────────────────── */
.row-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  transition: border-color 0.15s;
  text-align: left;
  width: 100%;
  color: inherit;
}
.row-card.clickable { cursor: pointer; }
.row-card.clickable:hover { border-color: var(--accent); }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--raised);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}
.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 600; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.row-meta { text-align: right; flex-shrink: 0; }

/* ── HP ───────────────────────────────────────────────────────────────────── */
.hp-panel {
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 12px;
}
.hp-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.hp-label {
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.hp-figure { font-size: 13px; color: var(--muted); }
.hp-figure b { font-size: 22px; color: var(--text); }

.hp-track {
  background: var(--raised);
  border-radius: 5px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 14px;
}
.hp-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.35s ease, background 0.35s ease;
}

.hp-controls { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.hp-amount {
  flex: 1;
  background: var(--raised);
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 26px;
  font-weight: 700;
  padding: 12px 8px;
  text-align: center;
  outline: none;
  min-width: 0;
  transition: border-color 0.15s;
}
.hp-amount:focus { border-color: var(--accent); }

.step {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid;
  font-size: 26px;
  font-weight: 700;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform 0.1s, filter 0.15s;
}
.step:active { transform: scale(0.9); }
.step.minus { background: rgba(232, 72, 74, 0.16); color: var(--bad); border-color: rgba(232, 72, 74, 0.4); }
.step.plus { background: rgba(76, 175, 118, 0.16); color: var(--good); border-color: rgba(76, 175, 118, 0.4); }

.hp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.hp-temp {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.hp-temp label { flex: 1; font-size: 12px; color: var(--muted); }
.hp-temp input {
  width: 74px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #6cb6ff;
  font-size: 17px;
  font-weight: 700;
  padding: 6px;
  text-align: center;
  outline: none;
}

/* ── Stats ────────────────────────────────────────────────────────────────── */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.stat-tile {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 6px;
  text-align: center;
  transition: border-color 0.15s;
}
.stat-tile.editable { cursor: pointer; }
.stat-tile.editable:hover { border-color: var(--accent); }
.stat-value { font-size: 23px; font-weight: 700; line-height: 1.1; }
.stat-mod { font-size: 14px; font-weight: 700; color: var(--accent); margin: 2px 0; }
.stat-name {
  font-size: 10px;
  letter-spacing: var(--label-track);
  text-transform: var(--label-case);
  color: var(--faint);
}

.quick-tile {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 6px;
  text-align: center;
}
.big-num { font-size: 22px; font-weight: 700; color: var(--accent); line-height: 1.1; }
.quick-tile input.big-num {
  background: none;
  border: none;
  width: 100%;
  text-align: center;
  outline: none;
  color: var(--accent);
}
.quick-label {
  font-size: 10px;
  letter-spacing: var(--label-track);
  text-transform: var(--label-case);
  color: var(--faint);
  margin-top: 2px;
}

/* ── Skills ───────────────────────────────────────────────────────────────── */
.skill-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--raised);
}
.skill-row:last-child { border-bottom: none; }
.pip-prof {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--line);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.pip-prof.prof { background: var(--accent); border-color: var(--accent); }
.pip-prof.expert { background: var(--text); border-color: var(--text); box-shadow: 0 0 0 2px var(--accent-soft); }
.skill-name { flex: 1; font-size: 13px; }
.skill-abbr { font-size: 10px; color: var(--faint); width: 26px; }
.skill-bonus { font-size: 14px; font-weight: 700; width: 38px; text-align: right; color: var(--accent); }

/* ── Spell slots ──────────────────────────────────────────────────────────── */
.slot-group { margin-bottom: 12px; }
.slot-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.slot-level { font-size: 12px; color: var(--muted); font-weight: 600; }
.slot-count { font-size: 11px; color: var(--faint); }
.pips { display: flex; gap: 7px; flex-wrap: wrap; }
.pip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--accent);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.pip.spent { background: transparent; border-color: var(--line); }
.pip:active { transform: scale(0.88); }

/* ── Conditions ───────────────────────────────────────────────────────────── */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  font-size: 12px;
  padding: 3px 8px 3px 11px;
  cursor: pointer;
}
.chip .x {
  background: none;
  border: none;
  color: inherit;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0.7;
}
.chip .x:hover { opacity: 1; }

.condition-grid { display: grid; grid-template-columns: 1fr; gap: 7px; }
@media (min-width: 480px) { .condition-grid { grid-template-columns: 1fr 1fr; } }
.condition-opt {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.condition-opt:hover { border-color: var(--accent); }
.condition-opt.on { background: var(--accent-soft); border-color: var(--accent); }
.condition-opt .c-name { font-size: 13px; font-weight: 700; }
.condition-opt .c-desc { font-size: 11px; color: var(--muted); margin-top: 3px; line-height: 1.35; }

/* ── Initiative ───────────────────────────────────────────────────────────── */
.init-row {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--raised);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  margin-bottom: 7px;
  transition: border-color 0.2s, background 0.2s;
}
.init-row.current {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.init-row.on-deck { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

.init-score {
  width: 46px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  padding: 4px;
  outline: none;
  flex-shrink: 0;
}
.init-body { flex: 1; min-width: 0; }
.init-name { font-size: 14px; font-weight: 600; }
.init-name.veiled { color: var(--faint); font-style: italic; }
.init-conds { font-size: 10px; color: var(--accent); margin-top: 2px; }

.init-hp { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.mini-step {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.mini-step:active { transform: scale(0.85); }
.mini-step.minus { background: rgba(232, 72, 74, 0.16); color: var(--bad); border-color: rgba(232, 72, 74, 0.4); }
.mini-step.plus { background: rgba(76, 175, 118, 0.16); color: var(--good); border-color: rgba(76, 175, 118, 0.4); }
.init-hp-field {
  width: 46px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  padding: 3px;
  outline: none;
  color: var(--text);
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--muted);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.badge.danger { background: rgba(232, 72, 74, 0.14); color: var(--bad); border-color: rgba(232, 72, 74, 0.4); }
.badge.good { background: rgba(76, 175, 118, 0.14); color: var(--good); border-color: rgba(76, 175, 118, 0.4); }

/* ── Turn banner ──────────────────────────────────────────────────────────── */
.turn-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  margin: 10px 16px 0;
  border-radius: 9px;
  font-weight: 700;
  font-size: 15px;
  border: 2px solid;
  animation: pulse-soft 1.6s ease-in-out infinite;
}
.turn-banner.mine { display: flex; background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.turn-banner.next { display: flex; background: rgba(76, 175, 118, 0.1); border-color: var(--good); color: var(--good); }
@keyframes pulse-soft { 0%, 100% { opacity: 1; } 50% { opacity: 0.62; } }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  transition: filter 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }

.btn-primary { background: var(--accent); color: #14100a; }
[data-theme="void"] .btn-primary,
[data-theme="blood"] .btn-primary,
[data-theme="steel"] .btn-primary,
[data-theme="xp"] .btn-primary { color: #fff; }
[data-theme="obsidian"] .btn-primary,
[data-theme="gold"] .btn-primary,
[data-theme="crt"] .btn-primary { color: #000; }

.btn-ghost { background: var(--raised); color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-good { background: var(--good); color: #06210f; }
.btn-sm { font-size: 12px; padding: 6px 11px; border-radius: 7px; }
.btn-xs { font-size: 11px; padding: 4px 9px; border-radius: 6px; }
.btn-block { width: 100%; }

.fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 140;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--accent);
  color: #14100a;
  border: none;
  font-size: 20px;
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  justify-content: center;
}
.fab.show { display: flex; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 600;
}
.input,
.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--raised);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 78px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 9px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.check input { width: auto; }

.form-error {
  color: var(--bad);
  font-size: 12px;
  margin-top: 7px;
  display: none;
}
.form-error.show { display: block; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-bg.open { opacity: 1; pointer-events: auto; }
@media (min-width: 600px) { .modal-bg { align-items: center; } }

.modal {
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  transform: translateY(30px);
  transition: transform 0.25s ease;
}
.modal-bg.open .modal { transform: translateY(0); }
.modal.narrow { max-width: 300px; }
.modal.wide { max-width: 580px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 18px; }
.modal-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 9px;
  justify-content: flex-end;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 7px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 420px;
}
.toast {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 15px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease, toast-out 0.3s ease 3.2s forwards;
  line-height: 1.4;
}
.toast.good { border-color: var(--good); color: var(--good); }
.toast.bad { border-color: var(--bad); color: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }

/* ── Loading skeleton ─────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--raised) 25%, var(--surface) 50%, var(--raised) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  height: 16px;
  margin-bottom: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  color: var(--faint);
  padding: 34px 16px;
  font-size: 14px;
}
.empty .glyph { font-size: 34px; margin-bottom: 8px; opacity: 0.7; }
.empty .hint { font-size: 12px; margin-top: 10px; }

/* ── Lists ────────────────────────────────────────────────────────────────── */
.line-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--raised);
}
.line-item:last-child { border-bottom: none; }
.line-main { flex: 1; min-width: 0; }
.qty {
  font-size: 12px;
  color: var(--muted);
  background: var(--raised);
  border-radius: 5px;
  padding: 2px 7px;
}

/* ── Notes ────────────────────────────────────────────────────────────────── */
.note {
  background: var(--raised);
  border-radius: 9px;
  padding: 12px;
  margin-bottom: 9px;
}
.note.dm-only { border-left: 3px solid var(--accent); }
.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--faint);
  margin-bottom: 6px;
}
.note-text { font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.note-sketch { position: relative; display: inline-block; max-width: 100%; }
.note-sketch img { max-width: 100%; border-radius: 6px; display: block; }
.note-sketch .edit-btn { position: absolute; top: 7px; right: 7px; opacity: 0.9; }

/* ── Sketch canvas ────────────────────────────────────────────────────────── */
.sketch-frame { position: relative; background: #f0dcae; border-radius: 6px; overflow: hidden; }
.sketch-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(150,110,50,.55) 0%, rgba(0,0,0,0) 7%,
                    rgba(0,0,0,0) 93%, rgba(150,110,50,.55) 100%),
    linear-gradient(90deg, rgba(150,110,50,.4) 0%, rgba(0,0,0,0) 4%,
                    rgba(0,0,0,0) 96%, rgba(150,110,50,.4) 100%),
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(120,90,40,.06) 28px);
}
#sketch-pad { display: block; width: 100%; touch-action: none; cursor: crosshair; position: relative; z-index: 1; }
.sketch-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 11px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.sketch-tools input[type="color"] { width: 32px; height: 28px; border: none; background: none; padding: 0; cursor: pointer; }
.sketch-tools input[type="range"] { width: 76px; }

/* ── Spell / monster cards ────────────────────────────────────────────────── */
.entry {
  background: var(--surface);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 8px;
}
.entry-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 5px; }
.entry-title { font-size: 15px; font-weight: 700; flex: 1; min-width: 0; }
.entry-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 6px;
}
.entry-text { font-size: 13px; color: var(--muted); line-height: 1.5; }
.entry-text.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.entry.dimmed { opacity: 0.55; }

.school-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  border: 1px solid;
}

.mon-detail { display: none; margin-top: 11px; border-top: 1px solid var(--line); padding-top: 10px; }
.entry.open .mon-detail { display: block; }
.mon-stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin: 9px 0; }
.mon-stat { background: var(--raised); border-radius: 6px; padding: 5px 2px; text-align: center; }
.mon-stat .v { font-size: 13px; font-weight: 700; color: var(--accent); }
.mon-stat .l { font-size: 9px; text-transform: uppercase; color: var(--faint); }
.mon-entry { padding: 6px 0; border-bottom: 1px solid var(--raised); font-size: 12px; line-height: 1.45; }
.mon-entry:last-child { border-bottom: none; }

/* ── Currency ─────────────────────────────────────────────────────────────── */
.coin-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.coin {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
}
.coin input {
  background: none;
  border: none;
  width: 100%;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  outline: none;
  color: inherit;
}
.coin .l { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.cp { color: #c0803a; } .sp { color: #b8b8b8; } .ep { color: #cbbd6a; }
.gp { color: #f3c31a; } .pp { color: #dfe6ea; }

/* ── Theme picker ─────────────────────────────────────────────────────────── */
.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  padding: 0;
}
.swatch:active { transform: scale(0.92); }
.swatch[aria-pressed="true"] { border-color: var(--text); }
.swatch[data-t="ember"] { background: #e8832a; }
.swatch[data-t="crt"] { background: #24ff6a; }
.swatch[data-t="parchment"] { background: #d19a2a; }
.swatch[data-t="xp"] { background: #4a9bff; }
.swatch[data-t="void"] { background: #b45cff; }
.swatch[data-t="steel"] { background: #3f7fd0; }
.swatch[data-t="blood"] { background: #d62b2b; }
.swatch[data-t="gold"] { background: #f3b81a; }
.swatch[data-t="obsidian"] { background: #dcdcdc; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 30px;
  width: 100%;
  max-width: 360px;
}
.login-title { font-size: 23px; font-weight: 700; }
.login-title .mark { color: var(--accent); }
.login-sub { font-size: 13px; color: var(--muted); margin: 4px 0 24px; }

/* ── Blood overlay (low HP feedback) ──────────────────────────────────────── */
#blood-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.5s ease;
  mix-blend-mode: multiply;
}
#blood-layer.pulsing { animation: blood-throb 2.6s ease-in-out infinite; }
@keyframes blood-throb { 0%, 100% { opacity: 0.85; } 50% { opacity: 1; } }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.center { display: flex; align-items: center; gap: 8px; }
.gap-6 { gap: 6px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.mt-6 { margin-top: 6px; }
.mt-10 { margin-top: 10px; }
.mt-16 { margin-top: 16px; }
.mb-10 { margin-bottom: 10px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.accent { color: var(--accent); }
.danger { color: var(--bad); }
.good { color: var(--good); }
.t-xs { font-size: 11px; }
.t-sm { font-size: 13px; }
.t-c { text-align: center; }
.t-r { text-align: right; }
.divider { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.scroll-y { max-height: 300px; overflow-y: auto; }

/* ═══════════════════════════════════════════════════════════════════════════
   Desktop layout
   Phone is the default. Adding data-layout="desktop" to <html> widens the
   shell and flows the stacked cards into columns. Button placement and
   behaviour are unchanged, so nothing has to be relearned.
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 900px) {

  [data-layout="desktop"] .shell {
    max-width: 1240px;
    border-left: var(--border-w) solid var(--line);
    border-right: var(--border-w) solid var(--line);
  }

  [data-layout="desktop"] .page { padding: 22px 26px 60px; }

  [data-layout="desktop"] .topbar { height: 62px; padding: 0 22px; }
  [data-layout="desktop"] .topbar-title { font-size: 18px; }
  [data-layout="desktop"] .tabs.sticky-top { top: 62px; }
  [data-layout="desktop"] .tab { font-size: 14px; padding: 14px 20px; }

  /* Campaign list and party: cards side by side */
  [data-layout="desktop"] #campaign-list,
  [data-layout="desktop"] #party-list,
  [data-layout="desktop"] #user-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(370px, 1fr));
    gap: 12px;
    align-items: start;
  }
  [data-layout="desktop"] #campaign-list .row-card,
  [data-layout="desktop"] #party-list .row-card,
  [data-layout="desktop"] #user-list .row-card { margin-bottom: 0; }

  /* Character sheet: two columns, with the HP panel spanning the top */
  [data-layout="desktop"] #tab-combat {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
  }
  [data-layout="desktop"] #tab-combat > .hp-panel { grid-column: 1 / -1; }
  [data-layout="desktop"] #tab-combat > .grid-3 { grid-column: 1 / -1; }
  [data-layout="desktop"] #tab-combat > .card { margin-bottom: 0; }

  /* The HP panel has room to put its controls on one line */
  [data-layout="desktop"] .hp-panel .hp-controls { max-width: 420px; }
  [data-layout="desktop"] .hp-panel .hp-actions { max-width: 420px; }

  /* Library and spell lists flow into columns */
  [data-layout="desktop"] #spell-results,
  [data-layout="desktop"] #item-results,
  [data-layout="desktop"] #ability-results,
  [data-layout="desktop"] #monster-results,
  [data-layout="desktop"] #ability-list,
  [data-layout="desktop"] #notes-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 10px;
    align-items: start;
  }
  [data-layout="desktop"] #spell-results .entry,
  [data-layout="desktop"] #item-results .entry,
  [data-layout="desktop"] #ability-results .entry,
  [data-layout="desktop"] #monster-results .entry,
  [data-layout="desktop"] #ability-list .entry,
  [data-layout="desktop"] #notes-list .note { margin-bottom: 0; }

  /* Spells on the character sheet keep their level headings full width */
  [data-layout="desktop"] #spell-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 10px;
    align-items: start;
  }
  [data-layout="desktop"] #spell-list .section-head { grid-column: 1 / -1; margin-bottom: 0; }
  [data-layout="desktop"] #spell-list .entry { margin-bottom: 0; }

  /* Skills read better in two columns when there is room */
  [data-layout="desktop"] #skill-list {
    columns: 2;
    column-gap: 26px;
  }
  [data-layout="desktop"] #skill-list .skill-row { break-inside: avoid; }

  /* Initiative rows get more breathing room */
  [data-layout="desktop"] .init-row { padding: 12px 14px; }
  [data-layout="desktop"] .init-name { font-size: 15px; }

  /* Wider modals */
  [data-layout="desktop"] .modal { max-width: 620px; }
  [data-layout="desktop"] .modal.wide { max-width: 780px; }
  [data-layout="desktop"] .modal.narrow { max-width: 360px; }

  /* The floating button sits clear of the wider content */
  [data-layout="desktop"] .fab { right: calc(50% - 600px + 20px); }
}

/* Below 900px the toggle has no effect, so the phone layout always applies. */
[data-layout="desktop"] .layout-toggle .glyph-phone { display: none; }
[data-layout="desktop"] .layout-toggle .glyph-desktop { display: inline; }
.layout-toggle .glyph-phone { display: inline; }
.layout-toggle .glyph-desktop { display: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   Stop the page sliding sideways
   Something wider than the viewport lets the whole page be dragged left and
   right on a phone. These rules cap everything at the screen width and let
   flex children shrink, which is what actually causes most of it.
   ═══════════════════════════════════════════════════════════════════════════ */
html { overflow-x: hidden; }
body { overflow-x: hidden; width: 100%; max-width: 100%; position: relative; }
.shell { max-width: 100%; overflow-x: clip; }
@media (min-width: 721px) { .shell { max-width: 720px; } }

.page, .card, .entry, .row-card, .hp-panel, .note, .init-row, .line-item,
.modal, .turn-banner { max-width: 100%; }

/* Flex and grid children default to min-width:auto, which refuses to shrink
   below their content. This is the usual culprit behind a stray scrollbar. */
.row-body, .line-main, .init-body, .entry-title, .grow { min-width: 0; }
.row-card, .line-item, .init-row, .entry-head, .between, .center { min-width: 0; }

img, canvas, svg, video { max-width: 100%; height: auto; }
pre, code { white-space: pre-wrap; word-break: break-word; }
.note-text, .entry-text, .row-sub, .row-title { overflow-wrap: anywhere; }

/* The blood overlay is decorative and must never create scroll */
#blood-layer { overflow: hidden; }

/* ═══════════════════════════════════════════════════════════════════════════
   Skills: proficiency and expertise at a glance
   ═══════════════════════════════════════════════════════════════════════════ */
.skill-row { gap: 8px; }
.skill-tier {
  flex-shrink: 0;
  width: 42px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  text-align: center;
  padding: 3px 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-transform: uppercase;
  line-height: 1.2;
  background: var(--raised);
  color: var(--faint);
  border-color: var(--line);
  transition: background .15s, color .15s, border-color .15s;
}
.skill-tier.prof {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.skill-tier.expert {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.skill-row.is-prof .skill-name { color: var(--text); font-weight: 600; }
.skill-row.is-expert .skill-name { color: var(--accent); font-weight: 700; }
.skill-legend {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 10px; color: var(--faint);
  padding-bottom: 8px; margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.skill-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-chip {
  width: 22px; height: 12px; border-radius: 3px;
  border: 1px solid var(--line); background: var(--raised);
}
.legend-chip.prof { background: var(--accent-soft); border-color: var(--accent); }
.legend-chip.expert { background: var(--accent); border-color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════════
   Overridden values
   ═══════════════════════════════════════════════════════════════════════════ */
.is-overridden { position: relative; }
.override-dot {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--warn);
  vertical-align: middle;
  margin-left: 4px;
}
.override-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--raised);
}
.override-row:last-child { border-bottom: none; }
.override-row .label { flex: 1; font-size: 13px; min-width: 0; }
.override-row .calc { font-size: 11px; color: var(--faint); width: 54px; text-align: right; }
.override-row input {
  width: 62px; text-align: center; font-weight: 700;
  background: var(--raised); border: var(--border-w) solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
  padding: 6px 4px; outline: none; font-size: 15px;
}
.override-row input:focus { border-color: var(--accent); }
.override-row input.set { border-color: var(--warn); color: var(--warn); }

/* ═══════════════════════════════════════════════════════════════════════════
   Pinned abilities on the Combat tab
   ═══════════════════════════════════════════════════════════════════════════ */
.pin-btn { opacity: .45; transition: opacity .15s, transform .1s; }
.pin-btn.on { opacity: 1; }
.pin-btn:active { transform: scale(.88); }
.pinned-ability {
  background: var(--raised);
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.pinned-ability:last-child { margin-bottom: 0; }
.pinned-ability .pa-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 3px;
}
.pinned-ability .pa-name { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; }
.pinned-ability .pa-body { font-size: 12px; color: var(--muted); line-height: 1.45; }
.pinned-ability .pa-uses { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* ═══════════════════════════════════════════════════════════════════════════
   Initiative: down but not gone, plus the manage sheet
   ═══════════════════════════════════════════════════════════════════════════ */
.init-row { cursor: pointer; }
.init-row.dead { opacity: .5; }
.init-row.dead .init-name { text-decoration: line-through; }
.init-row.dead.current { opacity: .72; }
.init-skull { font-size: 13px; flex-shrink: 0; }

.init-hp-readout {
  display: flex; flex-direction: column; align-items: flex-end;
  flex-shrink: 0; min-width: 62px;
}
.init-hp-readout .figure { font-size: 15px; font-weight: 700; line-height: 1.1; }
.init-hp-readout .bar {
  width: 58px; height: 4px; border-radius: 2px;
  background: var(--raised); overflow: hidden; margin-top: 3px;
}
.init-hp-readout .bar span { display: block; height: 100%; border-radius: 2px; }

.init-ac {
  flex-shrink: 0; text-align: center; min-width: 30px;
  font-size: 11px; color: var(--faint);
}
.init-ac b { display: block; font-size: 14px; color: var(--text); font-weight: 700; }

/* The manage sheet reuses the character HP controls at a smaller size */
.manage-hp .hp-controls { margin-bottom: 8px; }
.manage-hp .step { width: 46px; height: 46px; font-size: 22px; }
.manage-hp .hp-amount { font-size: 22px; padding: 10px 6px; }
.manage-figure {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px;
}
.manage-figure .big { font-size: 26px; font-weight: 700; }
.manage-figure .max { font-size: 13px; color: var(--muted); }
