/* Horus Heresy reading tracker. Light tokens on :root; dark via [data-theme=dark] or
   (no explicit light) prefers-color-scheme. No inline styles: data-driven values are
   classes (fac-*) or CSSOM custom properties (--pct). */
:root {
  --bg: #f6f6f4; --card: #ffffff; --line: #e3e3de; --ink: #1b1b1f; --ink-2: #4a4a52; --dim: #6c6c75;
  --accent: #8a5a00; --accent-ink: #ffffff; --accent-soft: #f6ead0;
  --field: #f1f1ee; --danger: #b42318; --have: #2a78d6; --read: #1b8f5f;
  --shadow: 0 1px 2px rgba(20,20,30,.06), 0 4px 16px rgba(20,20,30,.05);
  --r: 14px; --tap: 48px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fac-dark-angels: #1f5a34; --fac-emperors-children: #e0509b; --fac-iron-warriors: #6b7078; --fac-white-scars: #aeb4bd; --fac-space-wolves: #4f6a8c; --fac-imperial-fists: #e0b000; --fac-night-lords: #5f73cf; --fac-blood-angels: #c1272d; --fac-iron-hands: #a89b70; --fac-world-eaters: #8a1414; --fac-ultramarines: #1f5fbf; --fac-death-guard: #8fbf1a; --fac-thousand-sons: #2aa7e0; --fac-sons-of-horus: #3f9e8a; --fac-word-bearers: #e8806b; --fac-salamanders: #19b53c; --fac-raven-guard: #1c1c22;
  --fac-alpha-legion: #14948f; --fac-knights: #9a86d9; --fac-custodes: #d9930d; --fac-mechanicum: #7d1f2f; --fac-assassinorum: #f2705f; --fac-perpetuals: #5fcf9c; --fac-siege: #b08d1a; --fac-none: #8d8d97;
}
[data-theme="dark"] {
  --bg: #121214; --card: #1b1b1f; --line: #2c2c33; --ink: #f1f1f4; --ink-2: #c4c4cc; --dim: #9a9aa5;
  --accent: #f0b232; --accent-ink: #1a1305; --accent-soft: #3a2d0e;
  --field: #232328; --danger: #ff8a7a; --have: #3987e5; --read: #2fc58b;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --fac-dark-angels: #3f9a63; --fac-emperors-children: #f06bb2; --fac-iron-warriors: #9aa0a8; --fac-white-scars: #d6dae0; --fac-space-wolves: #7f9bc0; --fac-imperial-fists: #f2c824; --fac-night-lords: #8c9ef0; --fac-blood-angels: #ec5a5f; --fac-iron-hands: #d8cca6; --fac-world-eaters: #c8483a; --fac-ultramarines: #4a8cf0; --fac-death-guard: #b4e03a; --fac-thousand-sons: #5cc4f0; --fac-sons-of-horus: #5cc9b0; --fac-word-bearers: #f29a85; --fac-salamanders: #3fdc62; --fac-raven-guard: #7b7b88;
  --fac-alpha-legion: #3fc8c1; --fac-knights: #b9a8f0; --fac-custodes: #f0b232; --fac-mechanicum: #b8485c; --fac-assassinorum: #ff8f80; --fac-perpetuals: #86e8bb; --fac-siege: #d4b240; --fac-none: #7c7c88;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214; --card: #1b1b1f; --line: #2c2c33; --ink: #f1f1f4; --ink-2: #c4c4cc; --dim: #9a9aa5;
    --accent: #f0b232; --accent-ink: #1a1305; --accent-soft: #3a2d0e;
    --field: #232328; --danger: #ff8a7a; --have: #3987e5; --read: #2fc58b;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    --fac-dark-angels: #3f9a63; --fac-emperors-children: #f06bb2; --fac-iron-warriors: #9aa0a8; --fac-white-scars: #d6dae0; --fac-space-wolves: #7f9bc0; --fac-imperial-fists: #f2c824; --fac-night-lords: #8c9ef0; --fac-blood-angels: #ec5a5f; --fac-iron-hands: #d8cca6; --fac-world-eaters: #c8483a; --fac-ultramarines: #4a8cf0; --fac-death-guard: #b4e03a; --fac-thousand-sons: #5cc4f0; --fac-sons-of-horus: #5cc9b0; --fac-word-bearers: #f29a85; --fac-salamanders: #3fdc62; --fac-raven-guard: #7b7b88;
    --fac-alpha-legion: #3fc8c1; --fac-knights: #b9a8f0; --fac-custodes: #f0b232; --fac-mechanicum: #b8485c; --fac-assassinorum: #ff8f80; --fac-perpetuals: #86e8bb; --fac-siege: #d4b240; --fac-none: #7c7c88;
  }
}
.fac-dark_angels { --stripe: var(--fac-dark-angels); }
.fac-emperors_children { --stripe: var(--fac-emperors-children); }
.fac-iron_warriors { --stripe: var(--fac-iron-warriors); }
.fac-white_scars { --stripe: var(--fac-white-scars); }
.fac-space_wolves { --stripe: var(--fac-space-wolves); }
.fac-imperial_fists { --stripe: var(--fac-imperial-fists); }
.fac-night_lords { --stripe: var(--fac-night-lords); }
.fac-blood_angels { --stripe: var(--fac-blood-angels); }
.fac-iron_hands { --stripe: var(--fac-iron-hands); }
.fac-world_eaters { --stripe: var(--fac-world-eaters); }
.fac-ultramarines { --stripe: var(--fac-ultramarines); }
.fac-death_guard { --stripe: var(--fac-death-guard); }
.fac-thousand_sons { --stripe: var(--fac-thousand-sons); }
.fac-sons_of_horus { --stripe: var(--fac-sons-of-horus); }
.fac-word_bearers { --stripe: var(--fac-word-bearers); }
.fac-salamanders { --stripe: var(--fac-salamanders); }
.fac-raven_guard { --stripe: var(--fac-raven-guard); }
.fac-alpha_legion { --stripe: var(--fac-alpha-legion); }
.fac-knights { --stripe: var(--fac-knights); }
.fac-custodes { --stripe: var(--fac-custodes); }
.fac-mechanicum { --stripe: var(--fac-mechanicum); }
.fac-assassinorum { --stripe: var(--fac-assassinorum); }
.fac-perpetuals { --stripe: var(--fac-perpetuals); }
.fac-siege { --stripe: var(--fac-siege); }
.fac-none { --stripe: var(--fac-none); }

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: light dark; }
[data-theme="light"] { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; min-height: 100vh; color: var(--ink); font: 16px/1.45 var(--sans); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, p, ul { margin: 0; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--accent); }
.app { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(40px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }

/* controls */
.btn { min-height: var(--tap); padding: 0 20px; border-radius: 12px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); filter: brightness(.95); }
.btn:focus-visible, .chip:focus-visible, .tog:focus-visible, .input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.quiet { background: var(--field); color: var(--ink); border-color: var(--line); }
.btn.quiet:hover { border-color: var(--accent); filter: none; }
.btn.quiet:active { background: var(--line); }
.btn.small { padding: 0 16px; font-size: .95rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.input { width: 100%; min-height: var(--tap); padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font: inherit; }
.input::placeholder { color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: var(--tap); padding: 0 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font: inherit; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip:active { background: var(--line); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.note.err { color: var(--danger); font-size: .9rem; }

/* login */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login { width: 100%; max-width: 380px; }
.brand { font-size: 1.5rem; font-weight: 700; text-align: center; }

/* header + progress */
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.progress { display: flex; flex-direction: column; gap: 12px; }
.prog-head { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; margin-bottom: 4px; flex-wrap: wrap; }
.prog-label { font-weight: 650; }
.prog-nums { color: var(--dim); font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 12px; border-radius: 99px; background: var(--field); border: 1px solid var(--line); overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--pct, 0) * 1%); }
.bar i.have { background: var(--have); opacity: .45; }
.bar i.read { background: var(--read); }

/* toolbar */
.toolbar { display: flex; flex-direction: column; gap: 10px; }
select.input { appearance: auto; }

/* list */
.books { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.group { margin-top: 10px; padding: 0 2px; font-size: .85rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.empty { padding: 24px 8px; text-align: center; color: var(--dim); }
.book { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 12px 12px 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-left: 6px solid var(--stripe, var(--fac-none)); border-radius: 12px; }
.book .info { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.title { font-weight: 650; overflow-wrap: anywhere; }
.sub { color: var(--dim); font-size: .88rem; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.tag { font-size: .75rem; padding: 2px 9px; border-radius: 99px; background: var(--field); border: 1px solid var(--line); color: var(--ink-2); }
.tag.star { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.togs { display: flex; gap: 8px; flex: 0 0 auto; }
.tog { min-height: 44px; min-width: 84px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink-2);
  font: inherit; font-weight: 600; cursor: pointer; }
.tog:hover { border-color: var(--accent); color: var(--ink); }
.tog:active { transform: translateY(1px); background: var(--line); }
.tog.have[aria-pressed="true"] { background: var(--have); border-color: var(--have); color: #fff; }
.tog.read[aria-pressed="true"] { background: var(--read); border-color: var(--read); color: #fff; }
.tog[aria-pressed="true"]:hover { filter: brightness(1.08); color: #fff; }
.tog:disabled { opacity: .7; cursor: default; }
.tog:disabled:hover { filter: none; border-color: var(--have); }
@media (max-width: 480px) {
  .togs { flex: 1 1 100%; }
  .tog { flex: 1; }
}

.foot { color: var(--dim); font-size: .85rem; display: flex; flex-direction: column; gap: 6px; padding: 8px 2px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: 90vw; }

/* ── header: compact, tabs ─────────────────────────────────────────────── */
.head { padding: 12px 14px; gap: 10px; }
.head h1 { font-size: 1.25rem; }
.head .progress { gap: 6px; }
.head .prog-line { display: flex; align-items: center; gap: 10px; }
.head .prog-head { display: contents; }
.head .prog-label { flex: 0 0 76px; font-size: .85rem; }
.head .prog-nums { order: 3; flex: 0 0 auto; font-size: .78rem; }
.head .bar { order: 2; flex: 1 1 auto; height: 8px; }
.tabs { display: flex; gap: 8px; }
.tabs .tab { flex: 1; border-radius: 12px; font-weight: 600; }
.app.mode-chart { max-width: none; min-height: 100dvh; }
.tabview { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.chart-tab { flex: 1 1 auto; }
.list-tab { gap: 14px; }

/* ── chart view ────────────────────────────────────────────────────────── */
.chart-search { position: relative; }
.hits { position: absolute; z-index: 1100; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 6px; list-style: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.hit { width: 100%; min-height: 44px; padding: 6px 12px; border-radius: 10px; border: 1px solid transparent; background: var(--field); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.hit:hover { border-color: var(--accent); }
.hit:active { background: var(--line); }
.hit:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.map { flex: 1 1 auto; min-height: 60vh; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); overflow: hidden; }
.foot.line { padding: 0 2px; font-size: .8rem; display: block; }

/* Leaflet theming (tokens, so both themes work) */
/* The chart's own paper colour, in both themes: the edge tiles are padded with it,
   so any other map background shows as a pale block beside the chart. */
.leaflet-container { font: inherit; background: #f9f9f9; outline: 0; }
.leaflet-bar { border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-bar a, .leaflet-bar a:hover { width: 44px; height: 44px; line-height: 44px; font-size: 22px; background: var(--card); color: var(--ink); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: var(--field); }
.leaflet-bar a:active { background: var(--line); }
.leaflet-bar a.leaflet-disabled { color: var(--dim); background: var(--card); }
.leaflet-top.leaflet-left { z-index: 900; }

/* node overlays: classes win over the attributes Leaflet writes */
path.node { stroke: none !important; fill: var(--have) !important; fill-opacity: 0 !important; cursor: pointer; }
path.node:hover { fill-opacity: .14 !important; }
/* The node rectangles are invisible hit areas; the state classes stay on them for
   the tests, but nothing is drawn over the book. Status is shown by the marks
   (green circle = own the physical book, yellow check = read) drawn in their own
   pane by chart.js. */
path.node { stroke: none !important; fill-opacity: 0 !important; }
.leaflet-marks-pane { pointer-events: none; }
.mark-read-under { opacity: .9; }

/* sheet */
.sheet { position: fixed; z-index: 1150; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 720px; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.25);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; animation: sheet-up .18s ease-out; }
.sheet[hidden] { display: none; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-titles { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sheet-togs .tog { flex: 1; }
.sheet-anth { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: .92rem; color: var(--ink-2); }
.tog.small { min-width: 72px; }
.toast { z-index: 1200; }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

/* ── full screen (header + footer hidden, chart takes the viewport) ─────── */
.chart-tab { position: relative; }
.full-ctl { border: 1px solid var(--line); box-shadow: var(--shadow); }
.full-btn { display: block; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 4px; background: var(--card); color: var(--ink);
  font: inherit; font-size: 22px; line-height: 44px; text-align: center; cursor: pointer; }
.full-btn:hover { background: var(--field); }
.full-btn:active { background: var(--line); }
.full-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
body.chart-full .app { max-width: none; padding: 0; gap: 0; min-height: 100dvh; }
body.chart-full .head, body.chart-full .foot.line, body.chart-full #list-tab { display: none !important; }
body.chart-full .chart-tab { gap: 0; }
body.chart-full .map { height: 100dvh; min-height: 100dvh; border: 0; border-radius: 0; }
body.chart-full .chart-search { position: absolute; z-index: 1000; top: 10px; left: 64px; right: 64px; max-width: 480px; margin: 0 auto; }
body.chart-full .chart-search .input { box-shadow: var(--shadow); }
