:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2129;
  --muted: #646d7a;
  --border: #dde1e7;
  --accent: #2f5fa8;
  --accent-text: #ffffff;
  --good: #1a7a4f;
  --bad: #c0392b;
  --field: #ffffff;
  /* Chart series: print, Kindle, audio */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --card: #1b2028;
    --text: #e8ecf2;
    --muted: #99a3b1;
    --border: #2d3440;
    --accent: #6fa0e8;
    --accent-text: #0a1220;
    --good: #4fce94;
    --bad: #ff7b6b;
    --field: #141920;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; }
.wrap { max-width: 640px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
.wrap.wide { max-width: 980px; }
a { color: var(--accent); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 0.6rem; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.topnav { display: flex; gap: 4px; margin-bottom: 12px; padding: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.topnav a { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.topnav a.active { background: var(--accent); color: var(--accent-text); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin-bottom: 12px; }
.card.narrow { margin-top: 10vh; }
.card.narrow h1 { margin-bottom: 0.8rem; }

label { display: block; margin: 0.7rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }
input[type=text], input[type=password], input[type=date], input[type=number], select {
  width: 100%; min-height: 44px; padding: 0.5rem 0.65rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--field); color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */ }
input[type=text], input[type=password], input[type=date], input[type=number] {
  -webkit-appearance: none; appearance: none; }
input:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }

button, .button { display: inline-block; min-height: 44px; margin-top: 0.9rem; padding: 0.55rem 1.1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text);
  font: inherit; font-size: 1rem; font-weight: 600; text-align: center; text-decoration: none;
  cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.5; cursor: default; }
.flush { margin-top: 0; }
.hint { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); line-height: 1.45; }
.flash { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 0.9rem;
  line-height: 1.4; border: 1px solid var(--border); background: var(--card); }
.flash.ok { color: var(--good); }
.flash.error { color: var(--bad); }
form .flash { margin: 12px 0 0; }

.segmented { display: flex; gap: 4px; padding: 4px; margin: 0;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); }
.segmented label { flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 40px; margin: 0; padding: 6px 4px; border-radius: 7px; color: var(--muted);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid2 > div { min-width: 0; }

/* Books page */
.yearbar { display: flex; align-items: center; gap: 12px; margin: 4px 0 12px; }
.yearbar select { width: auto; min-width: 7.5rem; font-size: 1.25rem; font-weight: 700; }
.totals { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 14px; flex: 1;
  color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.totals strong { color: var(--text); }
.books { list-style: none; margin: 0; padding: 4px 0; }
.books li + li { border-top: 1px solid var(--border); }
.book { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 0; margin: 0;
  padding: 10px 16px; border: 0; border-radius: 0; background: none; font-weight: normal;
  text-align: left; }
.book:active { background: color-mix(in srgb, var(--text) 8%, transparent); }
@media (hover: hover) {
  .book:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
}
.book-main { flex: 1; min-width: 0; }
.book-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.meta { display: block; font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; }
.chev { color: var(--muted); font-size: 1.3rem; }
.fmt { flex: none; width: 22px; height: 22px; color: var(--muted); }
.empty { margin: 0; padding: 24px 16px; text-align: center; color: var(--muted); }
.card.list { padding: 0; overflow: hidden; }
.estimate { display: block; margin-top: 4px; font-size: 0.85rem; color: var(--muted);
  font-variant-numeric: tabular-nums; }

dialog { width: min(94vw, 480px); max-height: 92vh; padding: 16px; border: 1px solid var(--border);
  border-radius: 14px; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog h2 { margin-bottom: 0.2rem; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 88px);
  transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 0.7rem 1rem;
  border-radius: 10px; background: var(--text); color: var(--bg); font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); z-index: 40; }
.toast.is-error { background: var(--bad); color: #fff; }

/* Round add button floating over the page, at the bottom right of the column. */
.fab { position: fixed; z-index: 30; display: flex; align-items: center; justify-content: center;
  right: max(calc(16px + env(safe-area-inset-right)), calc(50% - 304px));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
.wrap:has(.fab) { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

/* Stats */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { min-width: 0; padding: 12px 8px; border: 1px solid var(--border); border-radius: 10px;
  text-align: center; }
.tile strong { display: block; font-size: 1.8rem; line-height: 1.2; font-weight: 600; }
.tile span { display: block; font-size: 0.8rem; color: var(--muted); }
.tile small { display: block; margin-top: 4px; font-size: 0.8rem; color: var(--muted);
  font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.chart { position: relative; height: 300px; }
.chart.short { height: 220px; }
.scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: right;
  white-space: nowrap; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
