/* Layout: one narrow phone column; sticky top bar with two tabs; a two-up grid of book cards; a big "Add books" button fixed to the bottom. */
:root {
  --bg: #F3F5F1;
  --surface: #FFFFFF;
  --ink: #17231D;
  --muted: #5B6A61;
  --line: #DCE3DD;
  --green: #1E5B43;
  --green-ink: #FFFFFF;
  --green-soft: #E2EEE7;
  --marigold: #F2B233;
  --marigold-soft: #FDF1D6;
  --marigold-ink: #5A3D00;
  --blue-soft: #E4ECF8;
  --blue-ink: #24467A;
  --danger: #A33A2A;
  --shadow: 0 1px 2px rgba(23,35,29,.06), 0 4px 14px rgba(23,35,29,.06);
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Nunito Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #111814; --surface: #19231D; --ink: #E8EFE9; --muted: #9BABA1; --line: #2A3830;
  --green: #5FBF92; --green-ink: #0D1A13; --green-soft: #1F3329;
  --marigold: #F2B233; --marigold-soft: #3A2E12; --marigold-ink: #F6D58C;
  --blue-soft: #1D2A3E; --blue-ink: #A9C2EA; --danger: #F08A78;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #111814; --surface: #19231D; --ink: #E8EFE9; --muted: #9BABA1; --line: #2A3830;
  --green: #5FBF92; --green-ink: #0D1A13; --green-soft: #1F3329;
  --marigold: #F2B233; --marigold-soft: #3A2E12; --marigold-ink: #F6D58C;
  --blue-soft: #1D2A3E; --blue-ink: #A9C2EA; --danger: #F08A78;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; padding-top: env(safe-area-inset-top, 0px); background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.45; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--marigold); outline-offset: 2px; }
.wrap { max-width: 760px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

header.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
header.top .wrap { display: flex; flex-direction: column; gap: 10px; padding-block: 14px 10px; }
.brand { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.brand h1 { font-family: var(--display); font-weight: 800; font-size: 1.5rem; letter-spacing: -.01em; margin: 0; line-height: 1.1; }
.brand h1 span { color: var(--green); }
.me { font-size: .85rem; color: var(--muted); background: none; border: 0; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; text-align: right; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 12px; font-weight: 700; font-size: .95rem; }
.tab[aria-selected="true"] { background: var(--green); color: var(--green-ink); border-color: var(--green); }
.tab .count { font-weight: 600; opacity: .8; }

main .wrap { display: flex; flex-direction: column; gap: 16px; padding-block: 16px 120px; }

.notice { background: var(--marigold-soft); color: var(--marigold-ink); border-radius: 14px; padding: 12px 14px; font-size: .95rem; }
.notice b { font-weight: 700; }
.howto { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.howto div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; font-size: .82rem; color: var(--muted); }
.howto strong { display: block; color: var(--ink); font-family: var(--display); font-size: .95rem; margin-bottom: 2px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search { flex: 1 1 180px; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 11px; font-size: .85rem; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

h2.sec { font-family: var(--display); font-size: 1.1rem; font-weight: 800; margin: 6px 0 -4px; }
.sub { color: var(--muted); font-size: .9rem; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.cover { aspect-ratio: 3 / 4; width: 100%; max-width: 100%; background: var(--green-soft); object-fit: cover; display: block; }
.cover.none { display: grid; place-items: center; font-family: var(--display); font-weight: 800; color: var(--green); font-size: 2rem; }
.card .body { padding: 10px 11px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.card h3 { font-family: var(--display); font-weight: 700; font-size: 1rem; line-height: 1.2; margin: 0; overflow-wrap: anywhere; }
.author { font-size: .82rem; color: var(--muted); margin-top: -3px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: .72rem; font-weight: 700; background: var(--green-soft); color: var(--green); border-radius: 6px; padding: 2px 7px; }
.tag.age { background: var(--blue-soft); color: var(--blue-ink); }
.desc { font-size: .84rem; margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.desc.open { -webkit-line-clamp: unset; display: block; }
.more { background: none; border: 0; padding: 0; color: var(--green); font-size: .8rem; font-weight: 700; align-self: flex-start; }
.from { font-size: .8rem; color: var(--muted); margin-top: auto; }
.from b { color: var(--ink); font-weight: 700; }
.status { font-size: .8rem; border-radius: 10px; padding: 7px 9px; }
.status.req { background: var(--marigold-soft); color: var(--marigold-ink); }
.status.sent { background: var(--green-soft); color: var(--green); font-weight: 700; }
.btn { border: 0; border-radius: 12px; padding: 10px 12px; font-weight: 700; font-size: .92rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--green); color: var(--green-ink); }
.btn.gold { background: var(--marigold); color: #2B1E00; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.link { background: none; padding: 4px 0; color: var(--muted); font-weight: 600; font-size: .8rem; text-decoration: underline; text-underline-offset: 3px; }
.btn.danger { color: var(--danger); }
.btn[disabled] { opacity: .55; cursor: default; }
.tick { width: 20px; height: 20px; border-radius: 6px; border: 2px solid currentColor; display: inline-grid; place-items: center; flex: none; }
.tick svg { width: 13px; height: 13px; }
.actions { display: flex; flex-direction: column; gap: 4px; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; border: 2px dashed var(--line); border-radius: 16px; }
.empty strong { display: block; font-family: var(--display); color: var(--ink); font-size: 1.1rem; margin-bottom: 4px; }

.fab { position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); background: linear-gradient(to top, var(--bg) 60%, transparent); display: flex; justify-content: center; pointer-events: none; }
.fab .btn { pointer-events: auto; width: 100%; max-width: 420px; padding: 15px 18px; font-size: 1.05rem; border-radius: 16px; box-shadow: 0 6px 20px rgba(30,91,67,.3); }

dialog { border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10,20,15,.5); }
.dlg { display: flex; flex-direction: column; gap: 14px; padding: 18px; }
.dlg h2 { font-family: var(--display); font-weight: 800; font-size: 1.3rem; margin: 0; }
.dlg .row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.drop { border: 2px dashed var(--green); border-radius: 16px; padding: 22px 14px; text-align: center; background: var(--green-soft); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.drop p { margin: 0; color: var(--muted); font-size: .9rem; }
.preview { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: var(--bg); }
.found { display: flex; flex-direction: column; gap: 10px; }
.fitem { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; border: 1px solid var(--line); border-radius: 14px; padding: 8px; align-items: start; }
.fitem.off { opacity: .45; }
.fitem img { width: 64px; height: 86px; object-fit: cover; border-radius: 8px; background: var(--green-soft); }
.fitem .fields { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fitem input, .fitem select, .fitem textarea, .field { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg); font-size: .88rem; }
.fitem textarea { resize: vertical; min-height: 76px; }
.fitem .two { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 5px; }
.keep { display: flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700; color: var(--green); }
.keep input { width: 18px; height: 18px; accent-color: var(--green); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--green-soft); border-top-color: var(--green); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.err { color: var(--danger); font-size: .9rem; margin: 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .9rem; z-index: 20; max-width: calc(100vw - 32px); }
.ex { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

img { max-width: 100%; }
[hidden] { display: none !important; }
.gate { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 18px; max-width: 440px; margin: 0 auto; padding-block: 32px; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); }
.gate h1 { font-family: var(--display); font-weight: 800; font-size: 2.2rem; line-height: 1.05; margin: 0; letter-spacing: -.02em; }
.gate h1 span { color: var(--green); }
.gate p { margin: 0; color: var(--muted); }
.gate form { display: flex; flex-direction: column; gap: 10px; }
.gate label { font-weight: 700; font-size: .9rem; }
.gate .field { padding: 12px 14px; font-size: 1rem; border-radius: 12px; background: var(--surface); }
.gate .btn { padding: 14px; font-size: 1rem; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.demo-banner { background: var(--blue-soft); color: var(--blue-ink); font-size: .85rem; padding: 8px 12px; border-radius: 10px; }
.thumbpick { cursor: pointer; display: block; }
.tab { white-space: nowrap; padding: 8px 10px; } .tab .count { font-size: .85em; }
.privacy { font-size: .78rem; color: var(--muted); margin-top: 14px; line-height: 1.4; }
.price { font-size: .9rem; margin: 2px 0 4px; }
.price s { color: var(--muted); margin-right: 4px; }
.price b { color: var(--green); }
.saved { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 0 0 12px; font-size: .95rem; text-align: center; }
.saved b { font-size: 1.15rem; color: var(--green); }
.suggest { display: grid; grid-auto-flow: column; grid-auto-columns: 46%; gap: 12px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scroll-snap-type: x mandatory; }
.suggest > div { scroll-snap-align: start; display: flex; flex-direction: column; }
.suggest .card { flex: 1; }
.why { font-size: .8rem; font-weight: 700; color: var(--green); margin: 0 2px 6px; min-height: 2.4em; }
.btn.small { font-size: .8rem; opacity: .75; }
.reported { font-size: .8rem; color: var(--muted); text-align: center; padding: 6px; }
img.cover { object-fit: contain; padding: 8px; }  /* show the whole cover, whatever its shape */
.reading { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; }
.reading .spinner { width: 18px; height: 18px; border-width: 3px; }
/* Shop cover from Open Library / Google Books, with the giver's own photo in the corner */
.coverwrap { position: relative; }
.inset { position: absolute; right: 6px; bottom: 6px; width: 26%; max-width: 56px; padding: 0; border: 2px solid var(--surface); border-radius: 8px; overflow: hidden; background: var(--surface); box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; }
.inset img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.inset span { font-size: .6rem; font-weight: 700; line-height: 1.6; text-align: center; color: var(--ink, inherit); }
.pics { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.shopcover { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.shopcover img { width: 64px; height: 86px; object-fit: contain !important; background: var(--surface) !important; border: 1px solid var(--line); }
.shopcover .btn.link { font-size: .7rem; padding: 0; min-height: 0; }
/* Admin page */
.tab[hidden] { display: none !important; }
.adm-pick { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: 4px 0 8px; }
.adm-pick select { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--surface); font: inherit; }
.adm-msg { background: var(--green-soft); color: var(--green); font-weight: 700; border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.adm-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.adm-card h3 { margin: 0; font-family: var(--display); }
.adm-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: .9rem; }
.adm-card .row { display: flex; gap: 8px; justify-content: flex-end; }
.hint { color: var(--muted); font-weight: 400; font-size: .8rem; }
.adm-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.adm-row { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.adm-row .who { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.adm-row .acts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.adm-row .btn.ghost { padding: 7px 10px; font-size: .82rem; }
.badge { display: inline-block; font-size: .7rem; font-weight: 800; border-radius: 6px; padding: 1px 7px; vertical-align: 1px; }
.badge.admin { background: var(--marigold-soft); color: var(--marigold-ink); }
.badge.owner { background: var(--green); color: var(--green-ink); }
#admQ { margin-bottom: 8px; }
#tabAdmin { flex: 0 0 auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin: 8px 0; }
.stat { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 12px; display: flex; flex-direction: column; }
.stat b { font-family: var(--display); font-size: 1.6rem; line-height: 1.1; color: var(--green); }
.stat span { font-size: .78rem; color: var(--muted); line-height: 1.25; }
/* Children */
.kids { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.kid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.kid .btn.link { font-size: 1rem; padding: 4px 6px; text-decoration: none; }
.kidchips { align-items: center; margin-bottom: 6px; }
.kidchips .hint { flex: none; margin-right: 2px; }
/* Reviews */
.rev { font-size: .82rem; line-height: 1.35; }
.rev q { display: block; font-style: italic; margin-top: 2px; overflow-wrap: anywhere; }
.stars-sm span { color: var(--line); } .stars-sm span.on { color: var(--marigold); }
.stars { display: flex; gap: 6px; justify-content: center; margin: 4px 0 8px; }
.star { border: 0; background: none; font-size: 2.3rem; line-height: 1; color: var(--line); padding: 2px 4px; cursor: pointer; }
.star.on { color: var(--marigold); }
#reviewWho { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.adm-q { display: block; font-style: italic; font-size: .85rem; margin-top: 2px; }
.err.blocked { margin: 0 0 4px; font-size: .85rem; }
