:root {
  --orange: #e8702a;
  --orange-deep: #c95a1c;
  --paper: #fbf7ee;
  --cream: #f3ecdc;
  --ink: #1d1d1b;
  --muted: #6b6457;
  --line: #ddd3bf;
  --serif: "Gill Sans", "Gill Sans MT", "Seravek", "Trebuchet MS", "Segoe UI", sans-serif;
  --radius: 4px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--cream); color: var(--ink);
  font: 17px/1.45 var(--serif);
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- The cover: three horizontal bands ---------- */
.cover {
  display: grid; grid-template-rows: 1fr auto 1fr;
  min-height: min(46dvh, 400px);
  background: var(--orange);
  padding-top: env(safe-area-inset-top);
}
.band { display: flex; align-items: center; justify-content: center; padding: 18px 16px; }
.band-top { align-items: center; }
.cartouche {
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 50%;
  padding: 10px 22px;
  font-size: 13px; font-weight: 600; letter-spacing: .22em;
}
.band-mid {
  flex-direction: column; background: var(--paper);
  padding: 20px 20px 18px; text-align: center;
}
.band-mid h1 {
  margin: 0; font-weight: 400; font-size: clamp(2.1rem, 11vw, 3.2rem);
  line-height: 1.05; letter-spacing: .01em;
}
.rule { width: 56%; max-width: 220px; border: 0; border-top: 2px solid var(--orange); margin: 14px auto 12px; }
.tally { margin: 0; font-size: 1.05rem; color: var(--ink); }
#year-count { font-size: 1.7rem; font-weight: 600; vertical-align: -2px; margin-right: 2px; }
.band-bottom { justify-content: space-between; gap: 12px; padding: 16px 20px; }
.mark { width: 38px; height: 42px; flex: none; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 44px; padding: 10px 18px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--ink); background: transparent; font-weight: 600;
  letter-spacing: .02em;
}
.btn-cover { background: var(--paper); border-color: var(--paper); color: var(--ink); font-size: 1.05rem; padding: 10px 22px; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-ghost { background: transparent; }
.btn:active { transform: translateY(1px); }
.link { background: none; border: 0; padding: 10px 4px; min-height: 44px; text-decoration: underline; cursor: pointer; color: var(--ink); }
.link.danger { color: #a3301b; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------- Sections ---------- */
main { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
.section-h {
  font-weight: 400; font-size: .85rem; letter-spacing: .25em; text-transform: uppercase;
  margin: 26px 0 12px; display: flex; align-items: center; gap: 12px; color: var(--muted);
}
.section-h::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.empty { color: var(--muted); margin: 6px 0 4px; }
.empty[hidden] { display: none; }
ul { list-style: none; margin: 0; padding: 0; }

/* Now-reading cards: a tiny cover beside the details */
.reading { display: grid; gap: 12px; }
.card {
  display: grid; grid-template-columns: 54px 1fr; gap: 14px; align-items: center;
  width: 100%; text-align: left; cursor: pointer;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; min-height: 92px;
}
.mini {
  width: 54px; height: 78px; display: grid; grid-template-rows: 1fr 1.1fr 1fr;
  background: var(--orange); border-radius: 2px; box-shadow: 1px 2px 0 rgba(0,0,0,.15);
}
.mini::before { content: ""; grid-row: 2; background: var(--paper); }
.card-title { font-size: 1.1rem; line-height: 1.2; margin: 0; overflow-wrap: anywhere; }
.card-author { margin: 2px 0 8px; color: var(--muted); font-size: .92rem; }
.bar { height: 6px; background: var(--cream); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--orange); }
.card-progress { font-size: .85rem; color: var(--muted); margin-top: 5px; }

/* The shelf: spines standing on a plank */
.shelf-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.shelf {
  display: flex; align-items: flex-end; gap: 4px; min-height: 0;
  padding: 0 6px; width: max-content; min-width: 100%;
}
.shelf:empty { min-height: 40px; }
.spine {
  display: grid; grid-template-rows: 1fr auto 1fr;
  width: 44px; border: 0; padding: 0; cursor: pointer; border-radius: 2px 2px 0 0;
  background: var(--orange); box-shadow: inset -3px 0 0 rgba(0,0,0,.08);
}
.spine:nth-child(3n+2) { background: var(--orange-deep); }
.spine-label {
  grid-row: 2; background: var(--paper); color: var(--ink);
  writing-mode: vertical-rl; transform: rotate(180deg);
  padding: 10px 0; font-size: .82rem; line-height: 44px; max-height: 112px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.spine-stars { grid-row: 3; align-self: end; color: #fff; font-size: 9px; letter-spacing: -1px; padding-bottom: 6px; }
.plank { height: 12px; background: linear-gradient(#8a5a33, #6d4424); border-radius: 2px; box-shadow: 0 3px 0 rgba(0,0,0,.12); min-width: 100%; }

.foot { text-align: center; margin-top: 36px; }
.foot .btn { font-size: .95rem; }
.small { font-size: .85rem; color: var(--muted); }
#lab-offline-status:empty { display: none; }

/* ---------- Dialogs as paperback sheets ---------- */
dialog {
  width: min(28rem, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 0; padding: 0 20px 18px; border-radius: 6px; background: var(--paper); color: var(--ink);
  box-shadow: 0 20px 50px rgba(0,0,0,.35); overflow-y: auto;
}
dialog::backdrop { background: rgba(29,29,27,.55); }
.sheet-band { height: 18px; background: var(--orange); margin: 0 -20px 14px; }
dialog h2 { font-weight: 400; font-size: 1.6rem; line-height: 1.15; margin: 4px 0 10px; overflow-wrap: anywhere; }
.byline { margin: -4px 0 12px; color: var(--muted); }
.kicker { margin: 0; font-size: .75rem; letter-spacing: .25em; text-transform: uppercase; color: var(--orange-deep); }
label { display: block; margin: 12px 0 0; font-size: .92rem; }
.opt { color: var(--muted); font-size: .85em; }
input:not([type=radio]), textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; min-height: 44px;
  background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius); font-size: 17px;
}
input:focus, textarea:focus { border-color: var(--orange); outline: none; }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 14px 0 0; }
legend { font-size: .92rem; padding: 0; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.actions.secondary { justify-content: space-between; align-items: center; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.error { color: #a3301b; margin: 8px 0 0; font-size: .9rem; }
.error:empty { display: none; }

/* Segmented control */
.seg { display: flex; flex-wrap: wrap; gap: 0; }
.seg legend { width: 100%; margin-bottom: 4px; }
.seg label { margin: 0; flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { text-align: center; padding: 10px; min-height: 44px; border: 1.5px solid var(--ink); cursor: pointer; }
.seg label:first-of-type { border-radius: 999px 0 0 999px; }
.seg label:last-of-type { border-radius: 0 999px 999px 0; border-left: 0; }
.seg label:has(input:checked) { background: var(--ink); color: var(--paper); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--orange); outline-offset: 2px; }

/* Star rating: radios with label stars */
.stars { display: flex; gap: 4px; }
.stars input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.stars label { margin: 0; width: 48px; height: 48px; cursor: pointer; display: grid; place-items: center; }
.stars label::before { content: "☆"; font-size: 34px; line-height: 1; color: var(--orange); }
.stars label.on::before { content: "★"; }
.stars input:focus-visible + label { outline: 3px solid var(--ink); border-radius: 6px; }
.stars-static { color: var(--orange); font-size: 1.5rem; letter-spacing: 2px; margin: 0 0 6px; }
blockquote { margin: 8px 0; padding: 4px 0 4px 14px; border-left: 3px solid var(--orange); font-style: italic; overflow-wrap: anywhere; white-space: pre-wrap; }
blockquote:empty { display: none; }
[hidden] { display: none !important; }

/* Errors shown on screen, never silent */
.app-error { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 2000;
  margin: 0; padding: 12px 14px; background: #a3301b; color: #fff; border-radius: 6px; font-size: .95rem; }
/* <dialog> fallback for browsers without showModal (compat.js) */
dialog:not([open]) { display: none; }
dialog.dialog-fallback[open] { display: block; position: fixed; top: 12px; left: 0; right: 0; margin: 0 auto; z-index: 1001;
  max-height: calc(100vh - 24px); -webkit-overflow-scrolling: touch; }
.dialog-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1000; background: rgba(29,29,27,.55); }
/* Segmented control without :has() support */
.seg label.on { background: var(--ink); color: var(--paper); }
