:root {
  --bg: #fbf6ee; --card: #fffdf8; --fg: #2a2118; --muted: #7a6a58; --accent: #b4532a; --accent2: #f1dfc9;
  --on-accent: #fff; --line: color-mix(in srgb, var(--fg) 12%, transparent);
  --shadow: 0 1px 2px rgba(60,40,20,.08), 0 6px 18px rgba(60,40,20,.07);
  --ok: #2f7d5b; --warn: #c27a10; --bad: #b3372d;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --r: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) { --bg: #17130f; --card: #221c16; --fg: #f2e9dc; --muted: #b3a390; --accent: #e08a57; --accent2: #3a2d22; --on-accent: #1a120b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); --ok: #62c496; --warn: #e6b04f; --bad: #ef7a6f; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 var(--sans); min-height: 100vh; transition: background .3s; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; margin-top: 1.5rem; } h3 { font-size: 1.05rem; }
a { color: var(--accent); text-decoration: none; }
p { margin: .4rem 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.row { display: flex; gap: .6rem; align-items: center; } .row.wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }

#topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem; padding: calc(.5rem + env(safe-area-inset-top)) 1rem .5rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
#topbar .brand { font: 700 1.15rem var(--serif); color: var(--fg); flex: 1; }
#topbar .who { border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: .25rem .7rem .25rem .3rem; display: flex; align-items: center; gap: .4rem; font: inherit; color: var(--fg); cursor: pointer; }
#app { max-width: 760px; margin: 0 auto; padding: 1rem 1rem calc(6.5rem + env(safe-area-inset-bottom)); }
#tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: center; background: color-mix(in srgb, var(--card) 94%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: .3rem .4rem calc(.3rem + env(safe-area-inset-bottom)); }
#tabs a { flex: 1; max-width: 120px; text-align: center; color: var(--muted); font-size: .7rem; padding: .25rem 0; border-radius: 12px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
#tabs a .ic { font-size: 1.4rem; line-height: 1.2; }
#tabs a.on { color: var(--accent); font-weight: 700; }
#tabs a.plus .ic { background: var(--accent); color: var(--on-accent); width: 2.6rem; height: 2.6rem; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem; margin-top: -1rem; box-shadow: var(--shadow); }

.card { background: var(--card); border-radius: var(--r); padding: 1rem; box-shadow: var(--shadow); }
.card + .card, .card + .list, .list + .card { margin-top: .8rem; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card.tint { background: var(--accent2); box-shadow: none; }
.card.alert { border-left: 5px solid var(--warn); }
.card.alert.bad { border-left-color: var(--bad); }
.list > * + * { margin-top: .6rem; }
.tiles > .card + .card { margin-top: 0; }

button, .btn { font: inherit; border: 0; border-radius: 12px; padding: .65rem 1rem; background: var(--accent); color: var(--on-accent); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
button.soft, .btn.soft { background: var(--accent2); color: var(--fg); }
button.danger { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1.5px var(--bad); }
button.small, .btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; border-radius: 10px; }
button.block { width: 100%; }
button:disabled { opacity: .5; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

label { display: block; font-size: .85rem; font-weight: 600; margin: .8rem 0 .25rem; color: var(--muted); }
input, select, textarea { width: 100%; font: inherit; color: var(--fg); background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: .65rem .75rem; min-height: 44px; }
textarea { min-height: 9rem; resize: vertical; font-family: var(--serif); font-size: 1.05rem; line-height: 1.55; }
input[type=checkbox] { width: auto; min-height: 0; }
input[type=file] { border: 0; padding: 0; background: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .65rem; border-radius: 999px; background: var(--accent2); color: var(--fg); font-size: .82rem; border: 0; min-height: 30px; font-weight: 500; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.seg { display: flex; background: var(--accent2); border-radius: 12px; padding: 3px; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.seg > * { flex: 1; text-align: center; padding: .45rem .6rem; border-radius: 9px; color: var(--fg); font-size: .88rem; white-space: nowrap; cursor: pointer; background: none; border: 0; min-height: 36px; font-weight: 500; }
.seg > .on { background: var(--card); font-weight: 700; box-shadow: var(--shadow); }

.avatar { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; font-size: 1.15rem; flex: none; background: color-mix(in srgb, var(--c, var(--accent)) 30%, var(--card)); box-shadow: inset 0 0 0 2px var(--c, var(--accent)); }
.avatar.lg { width: 4rem; height: 4rem; font-size: 2.2rem; } .avatar.xl { width: 5.5rem; height: 5.5rem; font-size: 3rem; } .avatar.sm { width: 1.5rem; height: 1.5rem; font-size: .9rem; }
.avstack { display: flex; } .avstack .avatar + .avatar { margin-left: -.5rem; }

/* covers */
.cover { display: block; width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 6px 10px 10px 6px; box-shadow: 0 2px 4px rgba(0,0,0,.25), 0 10px 20px rgba(0,0,0,.18), inset 4px 0 6px -3px rgba(0,0,0,.35); background: var(--accent2); }
.cover.gen { display: flex; flex-direction: column; justify-content: space-between; padding: 12% 10%; background: linear-gradient(160deg, var(--accent2), var(--bg)); color: var(--fg); overflow: hidden; border: 1px solid var(--line); }
.cover.gen b { font: 700 clamp(.8rem, 4.5vw, 1.15rem)/1.15 var(--serif); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.cover.gen span { font-size: .7rem; opacity: .8; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cover.gen::before { content: ''; height: 6px; width: 40%; background: var(--accent); border-radius: 3px; order: -1; }

/* minmax(0, 1fr): columns stay equal however long a title or author is, so every cover is the same size. */
.books { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem .8rem; }
@media (min-width: 560px) { .books { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 760px) { .books { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.bk { display: block; min-width: 0; color: var(--fg); border-radius: var(--r); padding: .6rem; background: var(--card); box-shadow: var(--shadow); border-bottom: 5px solid var(--accent); position: relative; }
.bk .t { font: 700 .95rem/1.2 var(--serif); margin-top: .55rem; min-height: 2.4em; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bk .a { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk .meta { display: flex; gap: .3rem; align-items: center; margin-top: .3rem; font-size: .78rem; flex-wrap: wrap; }
.bk .tag { position: absolute; top: .3rem; right: .3rem; background: var(--accent); color: var(--on-accent); font-size: .68rem; padding: .1rem .45rem; border-radius: 999px; font-weight: 700; }
.also { font-size: .74rem; color: var(--accent); margin-top: .25rem; display: flex; align-items: center; gap: .25rem; }
.stars { color: #e5a72b; letter-spacing: 1px; } .stars .off { color: var(--line); }

.bar { height: 10px; border-radius: 6px; background: var(--accent2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 6px; transition: width .6s; }
.stat { text-align: center; } .stat b { display: block; font: 700 1.6rem var(--serif); } .stat span { font-size: .75rem; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: .5rem; }
.pill { font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; background: var(--accent2); font-weight: 600; }
.pill.ok { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); } .pill.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); } .pill.bad { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }

/* ranking */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: .6rem; margin: 1rem 0 .5rem; }
.podium .p { flex: 1; max-width: 140px; text-align: center; }
.podium .step { border-radius: 12px 12px 0 0; margin-top: .4rem; display: grid; place-items: start center; padding-top: .4rem; font: 700 1.6rem var(--serif); color: var(--on-accent); background: var(--c, var(--accent)); }
.podium .p b { display: block; font-size: .95rem; } .podium .val { font: 700 1.3rem var(--serif); }
.rank-row { display: flex; align-items: center; gap: .7rem; padding: .7rem .8rem; }
.rank-row .n { font: 700 1.3rem var(--serif); width: 1.6rem; text-align: center; color: var(--muted); }
.rank-row.me { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.rank-row .v { font: 700 1.3rem var(--serif); }

/* sheet & toast */
#sheet-root .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
#sheet-root .sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom)); animation: up .2s; }
@media (min-width: 700px) { #sheet-root .backdrop { align-items: center; } #sheet-root .sheet { border-radius: 22px; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto .8rem; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } } @keyframes fade { from { opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--fg); color: var(--bg); padding: .7rem 1.1rem; border-radius: 14px; z-index: 60; opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw; text-align: center; font-weight: 600; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.confetti { position: fixed; top: 40%; font-size: 2rem; z-index: 70; pointer-events: none; animation: pop 1.4s ease-out forwards; }
@keyframes pop { from { transform: translate(0,0) scale(.5); opacity: 1; } to { transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(1.2); opacity: 0; } }

/* book page theme */
.booktheme { background: var(--bg); color: var(--fg); margin: -1rem -1rem calc(-6.5rem - env(safe-area-inset-bottom)); padding: 1rem 1rem calc(7rem + env(safe-area-inset-bottom)); min-height: 80vh; }
.booktheme .card { background: var(--card); color: var(--fg); }
.booktheme .muted { color: var(--muted); }
.booktheme .chip, .booktheme .seg, .booktheme .bar, .booktheme .pill { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.booktheme .chip.on, .booktheme .seg > .on { background: var(--accent); color: var(--on-accent); }
.booktheme input, .booktheme select, .booktheme textarea { background: var(--bg); color: var(--fg); border-color: color-mix(in srgb, var(--fg) 20%, transparent); }
.booktheme a { color: var(--accent); }
.booktheme .ghost { color: var(--accent); }
.hero { display: grid; grid-template-columns: 38% 1fr; gap: 1.1rem; align-items: end; padding: .5rem 0 1rem; }
.hero .cover { max-width: 240px; }
.hero h1 { font-size: 1.6rem; }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .6rem; }
.badge { text-align: center; padding: .7rem .3rem; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: .72rem; }
.badge .e { font-size: 2rem; display: block; } .badge.locked { opacity: .5; filter: grayscale(1); } .badge b { display: block; font-size: .78rem; }
.tile { display: flex; flex-direction: column; gap: .25rem; align-items: flex-start; color: var(--fg); }
.tile .e { font-size: 1.8rem; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.quest { display: flex; gap: .8rem; align-items: flex-start; padding: .8rem; cursor: pointer; }
.quest.done { opacity: .6; } .quest.done .qt { text-decoration: line-through; }
.quest .box { width: 1.7rem; height: 1.7rem; border-radius: 8px; border: 2px solid var(--accent); display: grid; place-items: center; flex: none; color: var(--on-accent); font-weight: 900; margin-top: .1rem; }
.quest.done .box { background: var(--accent); }
.feed li { list-style: none; display: flex; gap: .6rem; align-items: center; padding: .45rem 0; font-size: .92rem; border-bottom: 1px solid var(--line); }
.feed { padding: 0; margin: 0; }
.writing { border-left: 4px solid var(--accent); }
.writing .body { white-space: pre-wrap; font-family: var(--serif); }
.starter { font-family: var(--serif); font-style: italic; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty .big { font-size: 3rem; display: block; }
.err { color: var(--bad); font-weight: 600; }
.spinner { text-align: center; padding: 2rem; color: var(--muted); }
.emoji-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr)); gap: .3rem; }
.emoji-pick button { background: var(--card); min-height: 2.4rem; padding: 0; font-size: 1.4rem; box-shadow: inset 0 0 0 1.5px var(--line); }
.emoji-pick button.on { box-shadow: inset 0 0 0 3px var(--accent); }
.lang-grid { display: flex; flex-wrap: wrap; gap: .3rem; }
.swatches { display: flex; gap: .4rem; flex-wrap: wrap; } .swatches button { width: 2.2rem; height: 2.2rem; min-height: 0; padding: 0; border-radius: 50%; box-shadow: none; } .swatches button.on { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--fg); }

/* print */
.print-only { display: none; }
/* family favourites */
.fav-card { border-left: 6px solid #e5a72b; }
.fav-line { color: #b7791f; font-weight: 600; }
.fav-badge { font-size: .8rem; font-weight: 700; color: #b7791f; }

/* barcode scanner: the camera fills a wide box; the guide shows where the barcode should go */
.scanner-cam { position: relative; overflow: hidden; border-radius: var(--r); background: #000; }
.scanner-cam video { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.scanner-cam .scan-guide { position: absolute; left: 10%; right: 10%; top: 32%; height: 36%; border: 3px solid #fff; border-radius: 12px; box-shadow: 0 0 0 999px rgb(0 0 0 / 35%); pointer-events: none; }
.scanner p { margin: .6rem 0 0; }

@media print {
  body { background: #fff; color: #000; } #topbar, #tabs, #toast, .no-print { display: none !important; }
  #app { padding: 0; max-width: none; } .print-only { display: block; }
  .card { box-shadow: none; border: 1px solid #999; break-inside: avoid; }
}
.bingo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.bingo > div { border: 2px solid #333; border-radius: 10px; padding: .6rem; min-height: 8.5rem; font-size: .9rem; background: #fff; color: #000; display: flex; flex-direction: column; gap: .3rem; }
.bingo .e { font-size: 1.6rem; } .bingo small { margin-top: auto; opacity: .7; }
.bookmark { width: 6.5cm; height: 19cm; margin: 0 auto; border-radius: 12px; padding: 1.2rem .9rem; display: flex; flex-direction: column; align-items: center; text-align: center; gap: .8rem; background: var(--bg); color: var(--fg); border: 3px solid var(--accent); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.bookmark .cover { width: 70%; } .bookmark .ttl { font: 700 1.05rem var(--serif); } .bookmark .lines { width: 100%; flex: 1; background: repeating-linear-gradient(transparent 0 1.6rem, color-mix(in srgb, var(--fg) 35%, transparent) 1.6rem calc(1.6rem + 1px)); }
.logsheet { width: 100%; border-collapse: collapse; } .logsheet td, .logsheet th { border: 1px solid #555; padding: .55rem .4rem; text-align: left; color: #000; }
.logsheet tr { height: 2.1rem; }

/* reading places: the map (public/js/map.js) and the places' photos */
.map-wrap { position: relative; }
.map { position: relative; overflow: hidden; height: min(62vh, 520px); border-radius: var(--r); background: #e8e4d8; border: 1px solid var(--line); touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; outline-offset: 2px; }
.map.picking { height: min(45vh, 360px); }
.map.dragging { cursor: grabbing; }
.map-tiles img { position: absolute; left: 0; top: 0; width: 256px; height: 256px; max-width: none; pointer-events: none; }
.map-pins { position: absolute; inset: 0; pointer-events: none; }
.map-pin { position: absolute; left: 0; top: 0; pointer-events: auto; width: 0; height: 0; padding: 0; border: 0; background: none; min-height: 0; cursor: pointer; }
.map-pin span { position: absolute; left: -17px; top: -38px; width: 34px; height: 34px; display: grid; place-items: center; font-size: 1.05rem; background: var(--card); border: 2px solid var(--accent); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.map-pin.ours span { border-color: var(--ok); }
.map-pin span i { transform: rotate(45deg); font-style: normal; }
.map-zoom { position: absolute; right: .5rem; top: .5rem; display: flex; flex-direction: column; gap: 4px; }
.map-zoom button { width: 36px; height: 36px; min-height: 0; padding: 0; font-size: 1.2rem; line-height: 1; background: var(--card); color: var(--fg); border: 1px solid var(--line); box-shadow: var(--shadow); }
.map-credit { position: absolute; right: 0; bottom: 0; font-size: .65rem; padding: .1rem .4rem; background: rgba(255,255,255,.8); color: #333; border-top-left-radius: 6px; }
.map-credit a { color: #333; }
.map-locate { position: absolute; left: .5rem; bottom: .5rem; box-shadow: var(--shadow); }
.map-crosshair { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -100%); font-size: 2rem; pointer-events: none; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.spot-photo { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--r); margin-bottom: .6rem; background: var(--accent2); }
.spot-thumb { width: 64px; height: 64px; flex: none; object-fit: cover; border-radius: 10px; background: var(--accent2); }
.spot-thumb.gen { display: grid; place-items: center; font-size: 1.8rem; }
.tag-pending { color: var(--warn); font-weight: 600; } .tag-public { color: var(--ok); font-weight: 600; } .tag-hidden { color: var(--bad); font-weight: 600; }
