:root {
  --paper: #faf6ef;
  --card: #ffffff;
  --ink: #2b2620;
  --muted: #776d61;
  --line: #e7dfd2;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e4f0e9;
  --warn: #a4471f;
  --warn-soft: #fbe9e0;
  --shadow: 0 1px 2px rgb(60 40 10 / 6%), 0 4px 16px rgb(60 40 10 / 6%);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1b1915;
    --card: #25221d;
    --ink: #f1ebe1;
    --muted: #a99f91;
    --line: #3a352d;
    --accent: #7cc4a0;
    --accent-ink: #10231a;
    --accent-soft: #23362c;
    --warn: #f0a07c;
    --warn-soft: #3a2519;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1b1915; --card: #25221d; --ink: #f1ebe1; --muted: #a99f91; --line: #3a352d;
  --accent: #7cc4a0; --accent-ink: #10231a; --accent-soft: #23362c; --warn: #f0a07c; --warn-soft: #3a2519;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.5 var(--sans);
}
main { max-width: 680px; margin: 0 auto; padding: 24px 16px 64px; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0; font-weight: 600; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 28px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* buttons + inputs */
button, .btn {
  font: inherit; font-weight: 600; font-size: 0.95rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--muted); }
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.primary:hover { border-color: var(--accent); filter: brightness(1.06); }
.big { min-height: 56px; font-size: 1.05rem; padding: 0 26px; width: 100%; }
.quiet { background: transparent; border-color: transparent; color: var(--muted); padding: 0 10px; }
.quiet:hover { color: var(--ink); border-color: transparent; }
.danger { color: var(--warn); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.hint { font-weight: 400; color: var(--muted); }
fieldset.bare { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.bare legend { padding: 0; font-weight: 600; font-size: 0.9rem; margin-bottom: 8px; }
input, textarea {
  font: inherit; width: 100%;
  padding: 11px 14px; min-height: 46px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }

/* header */
.masthead { display: flex; gap: 14px; align-items: flex-start; }
.masthead .logo { flex: none; width: 44px; height: 44px; }
.eyebrow { font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; font-size: 0.92rem; color: var(--muted); }
.stats strong { color: var(--ink); font-size: 1.05rem; }

/* book list */
.books { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.book {
  display: grid; grid-template-columns: 56px 1fr; gap: 14px; align-items: start;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.book .meta { min-width: 0; }
.book .title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; line-height: 1.25; overflow-wrap: anywhere; }
.book .author { color: var(--muted); font-size: 0.92rem; }
.book .age { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
.book .age.stale { color: var(--warn); }
.book .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.book .actions button { min-height: 38px; padding: 0 14px; font-size: 0.88rem; }
.cover {
  width: 56px; height: 84px; border-radius: 4px; object-fit: cover;
  background: var(--line); box-shadow: 0 1px 3px rgb(0 0 0 / 18%);
}
.cover.fallback {
  display: flex; align-items: flex-end; padding: 6px 5px;
  color: #fff; font: 600 0.6rem/1.15 var(--serif); overflow: hidden;
  border-left: 5px solid rgb(0 0 0 / 18%);
}
.tag { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: 2px; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* donate */
.donate { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; }
.donate .qr svg { width: 108px; height: 108px; display: block; border-radius: 8px; background: #fff; }
@media (max-width: 480px) { .donate { grid-template-columns: 1fr; } .donate .qr { display: none; } }

/* sheet (bottom dialog) */
dialog.sheet {
  border: none; padding: 0; margin: auto auto 0; width: 100%; max-width: 520px;
  background: var(--card); color: var(--ink);
  border-radius: 20px 20px 0 0; box-shadow: 0 -8px 40px rgb(0 0 0 / 25%);
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgb(20 15 8 / 45%); }
.sheet-body { padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); }

/* scanner */
.scanner { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.scanner .frame {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  width: min(78vw, 360px); height: min(36vw, 170px);
  border: 3px solid rgb(255 255 255 / 85%); border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 40%);
  pointer-events: none;
}
.scanner .frame.hit { border-color: #7cf0b2; }
.scanner .bar {
  background: var(--card); color: var(--ink);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.scanner .status { min-height: 1.5em; font-weight: 600; }
.scanner .top { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; }
.scanner .top button { background: rgb(0 0 0 / 55%); color: #fff; border-color: transparent; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: 0.95rem;
  display: flex; gap: 14px; align-items: center; z-index: 60;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgb(0 0 0 / 25%);
}
.toast button { min-height: 30px; padding: 0 12px; background: transparent; color: inherit; border-color: color-mix(in srgb, var(--paper) 40%, transparent); font-size: 0.85rem; }

.notice { background: var(--warn-soft); color: var(--ink); border-radius: 12px; padding: 14px 16px; }
.notice.good { background: var(--accent-soft); }
.copyfield { display: flex; gap: 8px; }
.copyfield input { font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; }

footer.site { text-align: center; color: var(--muted); font-size: 0.82rem; margin-top: 40px; }
footer.site a { color: inherit; }

/* signup: web address field with a fixed prefix */
.slugfield {
  display: flex; align-items: stretch;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  overflow: hidden;
}
.slugfield:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.slugfield .prefix {
  display: flex; align-items: center; padding: 0 2px 0 14px;
  color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; white-space: nowrap;
}
.slugfield input {
  border: none; border-radius: 0; padding-left: 2px; min-width: 0; flex: 1;
  font-family: ui-monospace, Menlo, monospace; font-size: 0.95rem;
}
.slugfield input:focus { box-shadow: none; }
.good-text { color: var(--accent); font-weight: 600; }
.linkish {
  display: inline; min-height: 0; padding: 0; border: none; background: none;
  color: var(--accent); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer;
}
.notice.attention { outline: 2px solid var(--warn); }
p.notice { margin-top: 8px; padding: 10px 14px; }

/* header: title takes the space, icon buttons sit top-right */
.masthead > .stack { flex: 1; min-width: 0; }
.icon-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}
.icon-btn:hover { color: var(--ink); border-color: var(--muted); }

/* owner stats tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile, button.tile {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 2px;
  min-height: 0; padding: 12px; text-align: left; white-space: normal;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  font-weight: 400;
}
button.tile:disabled { opacity: 1; cursor: default; }
button.tile:not(:disabled):hover { border-color: var(--muted); }
.tile-num { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; line-height: 1.1; }
.tile-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); line-height: 1.2; }
.tile-sub { font-size: 0.75rem; color: var(--accent); font-weight: 600; line-height: 1.25; margin-top: 2px; }
.tile-sub.stale { color: var(--warn); }
@media (max-width: 380px) { .tile { padding: 10px; } .tile-num { font-size: 1.35rem; } }

/* segmented toggle */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--card); }
.seg button { min-height: 32px; padding: 0 12px; font-size: 0.82rem; border: none; background: transparent; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- library colors ----------
   The owner picks one for their library's pages (data-color on <html>). Green is the default,
   so it needs no rule. Each pairs a light accent (white text on it) with a dark one (dark text),
   all at least 5.7:1 contrast. Keep in sync with COLORS in src/worker.js and public/js/common.js. */
:root[data-color="blue"] { --accent: #2c5d8f; --accent-soft: #e3edf7; }
:root[data-color="red"] { --accent: #a3352f; --accent-soft: #f8e4e2; }
:root[data-color="plum"] { --accent: #6b3f7a; --accent-soft: #efe6f3; }
:root[data-color="amber"] { --accent: #94500f; --accent-soft: #f8ebdc; }
:root[data-color="slate"] { --accent: #3f4652; --accent-soft: #e8eaee; }
@media (prefers-color-scheme: dark) {
  :root[data-color="blue"]:not([data-theme="light"]) { --accent: #8db8e6; --accent-ink: #0f1d2c; --accent-soft: #1f2d3b; }
  :root[data-color="red"]:not([data-theme="light"]) { --accent: #f0958c; --accent-ink: #2a0f0d; --accent-soft: #3a2220; }
  :root[data-color="plum"]:not([data-theme="light"]) { --accent: #c9a0d8; --accent-ink: #24132b; --accent-soft: #302337; }
  :root[data-color="amber"]:not([data-theme="light"]) { --accent: #f1b072; --accent-ink: #2b1806; --accent-soft: #3a2a1a; }
  :root[data-color="slate"]:not([data-theme="light"]) { --accent: #b9c0cc; --accent-ink: #16191e; --accent-soft: #2c3038; }
}
:root[data-theme="dark"][data-color="blue"] { --accent: #8db8e6; --accent-ink: #0f1d2c; --accent-soft: #1f2d3b; }
:root[data-theme="dark"][data-color="red"] { --accent: #f0958c; --accent-ink: #2a0f0d; --accent-soft: #3a2220; }
:root[data-theme="dark"][data-color="plum"] { --accent: #c9a0d8; --accent-ink: #24132b; --accent-soft: #302337; }
:root[data-theme="dark"][data-color="amber"] { --accent: #f1b072; --accent-ink: #2b1806; --accent-soft: #3a2a1a; }
:root[data-theme="dark"][data-color="slate"] { --accent: #b9c0cc; --accent-ink: #16191e; --accent-soft: #2c3038; }

.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatch { position: relative; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch span { display: block; width: 38px; height: 38px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1px var(--line); }
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--ink); }
.swatch input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 6px; }

/* The public shelf page wears the library's color: a band across the top, the label, and the take buttons. */
.shelf-page { border-top: 6px solid var(--accent); }
.shelf-page .eyebrow { color: var(--accent); }
.shelf-page .book .actions button { color: var(--accent); border-color: var(--accent); }
