/* Engine styles shared by every library. Colours and fonts come from site/theme.css (tokens on :root). */
* { box-sizing: border-box; }
html { scroll-padding-top: 140px; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--ground);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--c-read); outline-offset: 2px; }

.wrap {
  max-width: 1120px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.label {
  font-family: var(--f-display); font-size: 11px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--muted); margin: 0;
}
.num { font-family: var(--f-data); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip {
  position: absolute; left: 8px; top: -80px; z-index: 20; padding: 10px 14px; border-radius: var(--r);
  background: var(--ink); color: var(--ground); font-family: var(--f-data); font-size: 13px;
}
.skip:focus { top: calc(8px + env(safe-area-inset-top, 0px)); }
main:focus { outline: none; }
.hero-ctl {
  position: absolute; top: 12px; right: max(16px, env(safe-area-inset-right, 0px)); z-index: 1;
  display: flex; gap: 8px; align-items: stretch;
}
/* Bottom right of the animated header, barely there until hovered or focused. */
.motion-btn {
  position: absolute; right: max(10px, env(safe-area-inset-right, 0px)); bottom: 6px; z-index: 1;
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0;
  color: var(--muted); background: none; border: 0; border-radius: var(--r); opacity: .45;
}
.motion-btn:hover, .motion-btn:focus-visible { opacity: 1; color: var(--ink); }
.motion-btn svg { width: 10px; height: 10px; fill: currentColor; }
.motion-btn .play, .motion-btn[aria-pressed="true"] .pause { display: none; }
.motion-btn[aria-pressed="true"] .play { display: block; }
@media (forced-colors: active) {
  .rate button::before, .track { forced-color-adjust: none; }
  .status button[aria-pressed="true"], .seg-ctl button[aria-pressed="true"], .chips button[aria-pressed="true"] { outline: 2px solid Highlight; }
}

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.hero canvas { position: absolute; inset: 0; pointer-events: none; }
.hero .wrap {
  position: relative; padding-block: 44px 36px;
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 32px; align-items: end;
}
.ident { min-width: 0; }
h1 {
  font-family: var(--f-display); font-weight: 400; text-transform: uppercase;
  font-size: clamp(30px, 6vw, 62px); line-height: 1.04; letter-spacing: .02em;
  margin: 14px 0 10px; text-wrap: balance;
}
.life { font-family: var(--f-data); font-size: 12px; color: var(--muted); margin: 0 0 18px; }
.lede { font-size: 19px; line-height: 1.45; max-width: 32em; margin: 0; text-wrap: pretty; }
.lede em { font-style: italic; }

.ledger {
  min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px; display: grid; gap: 18px;
}
.counts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.count b { display: block; font-family: var(--f-data); font-weight: 500; font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.count span { font-size: 14px; color: var(--muted); }
.count.read b { color: var(--c-read); }
.count.reading b { color: var(--c-reading); }
.count.fav b { color: var(--star); }
.avg { margin: -6px 0 0; font-size: 12px; color: var(--muted); }
.avg b { font-weight: 500; color: var(--ink); }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; gap: 4px; }
.bar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.bar-head .num { font-size: 12px; color: var(--muted); }
.track { height: 5px; background: var(--line); border-radius: 1px; display: flex; overflow: hidden; }
.track i { display: block; height: 100%; }
.track .f-read { background: var(--c-read); }
.track .f-reading { background: var(--c-reading); }
.next { border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 6px; }
.next-title { font-size: 21px; font-weight: 500; line-height: 1.2; margin: 0; }
.next-title button { all: unset; cursor: pointer; }
.next-title button:hover { text-decoration: underline; text-underline-offset: 3px; }
.next-title button:focus-visible { outline: 2px solid var(--c-read); outline-offset: 2px; }
.next-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.next-row .sub { font-size: 14px; color: var(--muted); }
.btn {
  font-family: var(--f-data); font-size: 12px; padding: 7px 12px; border-radius: var(--r);
  border: 1px solid var(--ink); background: var(--ink); color: var(--ground);
}
.btn:hover { opacity: .88; }
.sync { font-family: var(--f-data); font-size: 11px; color: var(--muted); margin: 0; display: flex; gap: 8px; align-items: center; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.sync[data-s="cloud"]::before { background: var(--c-read); }
.sync[data-s="warn"]::before { background: var(--c-reading); }
.link-btn {
  font-family: var(--f-data); font-size: 12px; color: var(--muted);
  background: none; border: 0; padding: 4px 0; min-height: 28px; text-align: left;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line);
}
.link-btn:hover { color: var(--ink); }
.links-row { display: flex; flex-wrap: wrap; gap: 0 18px; justify-self: start; margin-top: -8px; }

/* ---------- Sync dialog ---------- */
dialog {
  width: min(34rem, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; margin: auto; padding: 24px;
  color: var(--ink); background: var(--paper); border: 1px solid var(--ink); border-radius: var(--r);
}
dialog::backdrop { background: rgba(13, 15, 23, .6); }
dialog h2 { font-family: var(--f-display); font-weight: 400; font-size: 15px; letter-spacing: .1em; text-transform: uppercase; margin: 0 0 12px; }
dialog h2:focus { outline: none; }
dialog p { margin: 0 0 12px; }
.warn { padding: 12px 14px; border-left: 4px solid var(--c-reading); background: var(--c-reading-soft); border-radius: 0 var(--r) var(--r) 0; }
.sd-small { font-size: 14px; color: var(--muted); }
.code {
  font-family: var(--f-data); font-size: 18px; letter-spacing: .06em; padding: 12px 14px; margin: 0 0 10px;
  border: 1px dashed var(--ink); border-radius: var(--r); background: var(--ground); user-select: all; overflow-wrap: anywhere;
}
.sd-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; }
.btn.alt { background: transparent; color: var(--ink); }
.btn.danger { background: transparent; color: var(--c-reading); border-color: var(--c-reading); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0 0; }
.check input { margin-top: 5px; width: 18px; height: 18px; flex: none; }
.sd-field { display: grid; gap: 6px; font-family: var(--f-data); font-size: 12px; color: var(--muted); }
.sd-field input {
  width: 100%; font-family: var(--f-data); font-size: 16px; letter-spacing: .06em; padding: 10px;
  border: 1px solid var(--muted); border-radius: var(--r); background: var(--ground); color: var(--ink);
}
.sd-error { color: var(--c-reading); min-height: 1.5em; margin: 8px 0 0; }

/* ---------- Timeline ---------- */
.timeline .wrap { padding-block: 28px 20px; }
.tl-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 24px; margin-bottom: 10px; }
.tl-head h2 { font-family: var(--f-display); font-weight: 400; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; color: var(--muted); margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lg-read { background: var(--c-read); }
.lg-reading { background: var(--c-reading); }
.lg-pile { border: 1.5px solid var(--ink); }
.lg-none { background: var(--line); }
.lg-fav { border: 2.5px solid var(--star); }
.tl-note { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#tl { display: block; width: 100%; min-width: 680px; height: auto; }
#tl .axis { stroke: var(--muted); stroke-width: 1; }
#tl .tick { stroke: var(--muted); }
#tl .yr { fill: var(--muted); font-family: var(--f-data); font-size: 11px; }
#tl .mark { stroke: var(--muted); stroke-dasharray: 3 4; }
#tl .mark-t { fill: var(--muted); font-family: var(--f-data); font-size: 10.5px; }
#tl .tl-label { fill: var(--ink); font-family: var(--f-display); font-size: 10px; letter-spacing: .12em; }
#tl circle { cursor: pointer; stroke-width: 1.5; }
#tl circle.none { fill: var(--line); stroke: var(--line); }
#tl circle.pile { fill: var(--ground); stroke: var(--ink); }
#tl circle.reading { fill: var(--c-reading); stroke: var(--c-reading); }
#tl circle.read { fill: var(--c-read); stroke: var(--c-read); }
#tl circle.fav { stroke: var(--star); stroke-width: 3; }
#tl circle:hover, #tl circle:focus-visible { stroke: var(--ink); stroke-width: 2.5; outline: none; }

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--ground); border-block: 1px solid var(--line);
}
.toolbar .wrap { padding-block: 10px; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.seg-ctl { display: inline-flex; flex-wrap: wrap; }
.seg-ctl button {
  font-family: var(--f-data); font-size: 12px; padding: 7px 11px; background: var(--paper);
  border: 1px solid var(--line); margin-left: -1px;
}
.seg-ctl button:first-child { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.seg-ctl button:last-child { border-radius: 0 var(--r) var(--r) 0; }
.seg-ctl button[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); position: relative; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  font-family: var(--f-data); font-size: 12px; padding: 6px 10px; border-radius: var(--r);
  border: 1px solid var(--line); background: transparent; color: var(--muted);
}
.chips button[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); background: var(--paper); }
.chips .c { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }
.attach { display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-data); font-size: 12px; color: var(--muted); cursor: pointer; }
.attach input { accent-color: var(--ink); width: 16px; height: 16px; margin: 0; }
.book.child { margin-left: 24px; padding-left: 16px; border-left: 2px solid var(--line); border-top-style: dashed; padding-block: 14px; }
.book.child .b-title { font-size: 20px; }
.search { margin-left: auto; flex: 1 1 200px; max-width: 280px; }
.search input {
  width: 100%; font-family: var(--f-data); font-size: 12px; padding: 8px 10px;
  border: 1px solid var(--muted); border-radius: var(--r); background: var(--paper);
}
.search input::placeholder { color: var(--muted); }

/* ---------- Book list ---------- */
#list { padding-bottom: 48px; }
.group { padding-block: 30px 6px; }
.group + .group { border-top: 1px solid var(--line); }
.g-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 24px; margin-bottom: 8px; }
.g-head h2 { font-family: var(--f-display); font-weight: 400; font-size: 16px; letter-spacing: .1em; text-transform: uppercase; margin: 0; text-wrap: balance; }
.g-head p { margin: 2px 0 0; font-style: italic; color: var(--muted); font-size: 16px; }
.g-prog { display: flex; align-items: center; gap: 10px; font-family: var(--f-data); font-size: 12px; color: var(--muted); }
.g-prog .track { width: 110px; }
.subseries { font-family: var(--f-data); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 22px 0 0; padding-bottom: 6px; border-bottom: 1px solid var(--line); }

.book {
  display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) auto; gap: 2px 24px;
  padding-block: 18px; border-top: 1px solid var(--line);
  scroll-margin-top: 150px;
}
.subseries + .book, .g-head + .book { border-top: 0; }
.b-yr { font-family: var(--f-data); font-size: 13px; color: var(--muted); padding-top: 5px; display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.b-yr::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.book[data-status="pile"] .b-yr::before { background: transparent; border: 1.5px solid var(--ink); }
.book[data-status="reading"] .b-yr::before { background: var(--c-reading); }
.book[data-status="read"] .b-yr::before { background: var(--c-read); }
.b-main { min-width: 0; }
.b-main.has-cover { display: flex; gap: 16px; align-items: flex-start; }
.cover { flex: none; width: 64px; height: auto; border-radius: 2px; background: var(--paper); box-shadow: 0 1px 4px rgb(0 0 0 / .3); margin-top: 4px; }
.b-text { min-width: 0; }
.b-meta { font-family: var(--f-data); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0; }
.b-title { font-size: 24px; font-weight: 500; line-height: 1.18; margin: 3px 0 2px; text-wrap: balance; }
.b-by { font-size: 15px; color: var(--muted); margin: 0; }
.b-orig { white-space: nowrap; }
.b-orig em { color: var(--ink); }
.b-tn { font-size: 14px; color: var(--muted); margin: 6px 0 0; max-width: 62ch; }
.b-tn b { font-family: var(--f-data); font-size: 10.5px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--c-reading); margin-right: 8px; }
@media (max-width: 640px) { .b-orig { white-space: normal; } }
.b-desc { font-size: 16.5px; margin: 8px 0 0; max-width: 62ch; text-wrap: pretty; }
.book[data-status="read"] .b-title { color: var(--c-read); }

.b-act { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; padding-top: 2px; }
.status { display: inline-flex; }
.status button {
  font-family: var(--f-data); font-size: 12px; padding: 7px 10px; background: var(--paper);
  border: 1px solid var(--line); margin-left: -1px; white-space: nowrap;
}
.status button:first-child { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.status button:last-child { border-radius: 0 var(--r) var(--r) 0; }
.status button:hover { border-color: var(--muted); position: relative; }
.status button[aria-pressed="true"] { position: relative; }
.status button[data-v="pile"][aria-pressed="true"] { border-color: var(--ink); background: var(--ground); font-weight: 500; }
.status button[data-v="reading"][aria-pressed="true"] { background: var(--c-reading); border-color: var(--c-reading); color: var(--on-accent); }
.status button[data-v="read"][aria-pressed="true"] { background: var(--c-read); border-color: var(--c-read); color: var(--on-accent); }
.b-top { display: flex; gap: 8px; align-items: center; }
button.fav {
  width: 34px; height: 33px; display: grid; place-items: center; padding: 0; flex: none;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--paper);
}
button.fav svg { width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linejoin: round; }
button.fav:hover svg { stroke: var(--star); }
button.fav[aria-pressed="true"] { border-color: var(--star); }
button.fav[aria-pressed="true"] svg { fill: var(--star); stroke: var(--star); }

/* Score out of 10: ten segments, filled up to the score */
.rate { display: inline-flex; align-items: center; }
.score { display: inline-flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 0 8px; }
.score-btn {
  font-family: var(--f-data); font-size: 12px; color: var(--muted); background: none; border: 0; padding: 4px 2px; min-height: 28px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line);
}
.score-btn:hover { color: var(--ink); }
.score-btn.has { color: var(--c-read); text-decoration: none; font-variant-numeric: tabular-nums; }
.rate button { width: 24px; height: 32px; border: 0; background: transparent; display: grid; place-items: center; padding: 0; }
.rate button::before {
  content: ""; width: 9px; height: 16px; border-radius: 1px;
  border: 1.5px solid var(--c-read); background: transparent; opacity: .8;
}
.rate button.on::before { background: var(--c-read); opacity: 1; }
.rate button:hover::before { background: var(--c-read); opacity: .8; }
.rate button:has(~ button:hover)::before { background: var(--c-read); opacity: .8; }
.rate button:hover ~ button::before { background: transparent; opacity: .8; }
.rank { font-family: var(--f-display); font-size: 20px; color: var(--ink); line-height: 1; }
.notes-btn {
  font-family: var(--f-data); font-size: 12px; color: var(--muted); background: none; border: 0; padding: 4px 2px; min-height: 28px;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line);
}
.notes-btn:hover { color: var(--ink); }
.notes-btn.has::after { content: " ●"; color: var(--c-reading); }
.b-links { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0 16px; }
.shop {
  font-family: var(--f-data); font-size: 12px; color: var(--muted); padding: 4px 2px; min-height: 28px;
  display: inline-flex; align-items: center;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line);
}
.shop:hover { color: var(--ink); }

.panel {
  grid-column: 2 / -1; margin-top: 12px; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 13rem)); gap: 12px 16px;
}
.panel label { display: grid; gap: 4px; font-family: var(--f-data); font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.panel .full { grid-column: 1 / -1; }
.panel input, .panel textarea {
  font-family: var(--f-body); font-size: 16px; padding: 7px 9px; border: 1px solid var(--muted);
  border-radius: var(--r); background: var(--ground); width: 100%; min-width: 0;
}
.panel textarea { resize: vertical; min-height: 80px; line-height: 1.45; }

.flash { animation: flash 1.8s ease-out; }
@keyframes flash { from { background: var(--c-read-soft); } to { background: transparent; } }

.era { margin: 26px 0 0; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.era h3 { font-family: var(--f-data); font-weight: 500; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; margin: 0; }
.era p { margin: 2px 0 0; font-style: italic; color: var(--muted); font-size: 16px; }
.era + .book { border-top: 0; }

.empty { padding-block: 48px; text-align: left; }
.empty p { margin: 0 0 12px; font-size: 18px; }

footer { border-top: 1px solid var(--line); }
footer .wrap { padding-block: 24px 36px; font-size: 14px; color: var(--muted); display: grid; gap: 6px; }
footer p { margin: 0; max-width: 70ch; }
footer a { color: var(--ink); text-underline-offset: 3px; }
footer .ver { font-family: var(--f-data); font-size: 11px; opacity: .6; margin-top: 6px; }
footer .ver a { color: inherit; }

@media (max-width: 860px) {
  .hero .wrap { grid-template-columns: minmax(0, 1fr); align-items: start; }
  .search { margin-left: 0; max-width: none; }
}
@media (max-width: 640px) {
  .book { grid-template-columns: 3.4rem minmax(0, 1fr); gap: 2px 12px; }
  .cover { width: 48px; }
  .b-main.has-cover { gap: 12px; }
  .b-act { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-start; margin-top: 12px; gap: 10px 14px; }
  .panel { grid-column: 1 / -1; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .b-title { font-size: 21px; }
  .counts .count b { font-size: 24px; }
  /* The toolbar wraps onto several lines here: let it scroll away rather than cover the screen. */
  .toolbar { position: static; }
  html { scroll-padding-top: 16px; }
  .book { scroll-margin-top: 16px; }
  .score { justify-content: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .flash { animation: none; outline: 2px solid var(--c-read); }
}
