/* ---------- Themes (from the Unfiltered Reads design canvas) ---------- */
:root, [data-theme="girlie"] {
  --bg: #EAF3FB; --surface: #FFFFFF; --ink: #3D0F20; --muted: #6B4A57; --line: #DCCAD2;
  --track: #F3E6EB; --accent: #7A1E3A; --on-accent: #FFFFFF; --link: #7A1E3A;
  --soft: #F9E1E8; --soft-ink: #5C1730; --ring: #F3B6C8; --ring-track: rgba(255,255,255,.25);
  --spice: #E04A7A; --spice-line: #C2185B; --star: #7A1E3A; --danger: #B3261E;
  --display: 'Playfair Display', Georgia, serif; --fstyle: italic;
  --cover-a: #BFD8EE; --cover-b: #E9C9D3; --cover-c: #F3B6C8;
}
[data-theme="gothic"] {
  --bg: #0E0B10; --surface: #1A1419; --ink: #F2E9E4; --muted: #B9B3BA; --line: #33262E;
  --track: #2A1D24; --accent: #C8344F; --on-accent: #FFFFFF; --link: #EE7D91;
  --soft: #3A1420; --soft-ink: #F2D9DF; --ring: #0E0B10; --ring-track: rgba(255,255,255,.3);
  --spice: #E04A5F; --spice-line: #E04A5F; --star: #EE7D91; --danger: #FF8A80;
  --display: 'Cinzel', Georgia, serif; --fstyle: normal;
  --cover-a: #2A2433; --cover-b: #6E1A2B; --cover-c: #4A1A28;
}
[data-theme="neutral"] {
  --bg: #F4F4F5; --surface: #FFFFFF; --ink: #111111; --muted: #5C5C63; --line: #E2E2E5;
  --track: #E9E9EC; --accent: #111111; --on-accent: #FFFFFF; --link: #111111;
  --soft: #E9E9EC; --soft-ink: #111111; --ring: #FFFFFF; --ring-track: rgba(255,255,255,.25);
  --spice: #3F3F46; --spice-line: #111111; --star: #111111; --danger: #B3261E;
  --display: 'Fraunces', Georgia, serif; --fstyle: normal;
  --cover-a: #A1A1AA; --cover-b: #D4D4D8; --cover-c: #EDEDF0;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif; font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; padding: calc(env(safe-area-inset-top) + 20px) 20px 110px; display: flex; flex-direction: column; gap: 18px; }
.screen.noNav { padding-bottom: 32px; }

h1, h2, h3, .display { font-family: var(--display); font-style: var(--fstyle); font-weight: 700; margin: 0; line-height: 1.15; }
h1 { font-size: 28px; } h2 { font-size: 20px; } h3 { font-size: 17px; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; } .between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 16px; }
.card.accent { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.soft { background: var(--soft); color: var(--soft-ink); border-radius: 14px; padding: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 24px; border: none; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 15px; text-decoration: none; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.soft { background: var(--soft); color: var(--soft-ink); padding: 0 16px; min-height: 40px; border-radius: 20px; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: none; background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.link-btn { background: none; border: none; color: var(--link); font-weight: 700; font-size: 14px; padding: 6px 0; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 700; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 400; font-size: 16px;
}
textarea.input { min-height: 96px; resize: vertical; }
.hint { font-weight: 400; font-size: 13px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 17px; font-size: 14px; font-weight: 500;
  background: transparent; color: var(--ink); border: 1px solid var(--line); }
.chip[aria-pressed="true"], .chip.on { background: var(--soft); color: var(--soft-ink); border-color: transparent; }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 700; background: var(--accent); color: var(--on-accent); }
.tag.outline { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex-shrink: 0; min-height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 700; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--on-accent); border-color: transparent; }

/* covers */
.cover { width: 70px; height: 104px; border-radius: 8px; flex-shrink: 0; background: var(--cover-c); object-fit: cover; display: flex; align-items: flex-end; padding: 6px;
  font-family: var(--display); font-style: var(--fstyle); font-weight: 700; font-size: 11px; line-height: 1.1; color: var(--ink); overflow: hidden; }
.cover.sm { width: 48px; height: 72px; font-size: 9px; }
.cover.lg { width: 120px; height: 180px; font-size: 14px; border-radius: 10px; }
.cover.c0 { background: var(--cover-a); } .cover.c1 { background: var(--cover-b); } .cover.c2 { background: var(--cover-c); }
[data-theme="gothic"] .cover.c1 { color: #F2E9E4; } [data-theme="gothic"] .cover.c0, [data-theme="gothic"] .cover.c2 { color: #F2E9E4; }

.book-row { display: flex; gap: 14px; padding: 12px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; align-items: center; }
.book-row .title { font-family: var(--display); font-style: var(--fstyle); font-weight: 700; font-size: 16px; line-height: 1.2; }

.progress { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 3px; }

.goal-ring { width: 72px; height: 72px; border-radius: 36px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.goal-ring > div { width: 56px; height: 56px; border-radius: 28px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 10px; border-radius: 14px; background: var(--soft); color: var(--soft-ink); }
.stat b { font-family: var(--display); font-size: 22px; }
.stat span { font-size: 12px; }

.rating { display: flex; gap: 4px; }
.rating button { width: 40px; height: 40px; border: none; background: none; padding: 4px; color: var(--star); }
.rating svg { width: 100%; height: 100%; }

.bar { height: 8px; border-radius: 4px; background: var(--track); } .bar > div { height: 8px; border-radius: 4px; background: var(--accent); }

/* bottom nav */
nav.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 520px; z-index: 10;
  display: flex; justify-content: space-around; align-items: center; height: calc(72px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line); }
nav.tabbar a { width: 52px; height: 48px; border-radius: 14px; color: var(--muted); display: flex; align-items: center; justify-content: center; }
nav.tabbar a[aria-current="page"] { background: var(--soft); color: var(--soft-ink); }
nav.tabbar a.add { width: 56px; height: 56px; border-radius: 28px; background: var(--accent); color: var(--on-accent); }

/* theme picker */
.theme-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.theme-opt { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); text-align: left; }
.theme-opt[aria-checked="true"] { border-color: var(--accent); }
.swatch { height: 64px; border-radius: 10px; display: flex; align-items: flex-end; padding: 6px; font-weight: 700; font-size: 14px; }

.post { display: flex; flex-direction: column; gap: 10px; }
.like-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; }
.like-btn[aria-pressed="true"] { background: var(--soft); color: var(--soft-ink); border-color: transparent; }

.banner { padding: 10px 14px; border-radius: 14px; background: var(--soft); color: var(--soft-ink); font-size: 14px; }
.offline-pill { position: fixed; top: calc(env(safe-area-inset-top) + 8px); left: 50%; transform: translateX(-50%); z-index: 20; background: var(--ink); color: var(--bg); padding: 4px 12px; border-radius: 12px; font-size: 13px; font-weight: 700; }

#toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 500; transition: .2s; max-width: 90vw; z-index: 30; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.splash { flex: 1; display: flex; align-items: center; justify-content: center; }
.splash-logo { width: 88px; height: 88px; border-radius: 24px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-style: var(--fstyle); font-size: 34px; font-weight: 700; }
.hero { text-align: center; padding-top: 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
details summary { cursor: pointer; font-weight: 700; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* legal pages */
.legal-body { gap: 4px; font-size: 15px; line-height: 1.6; }
.legal-body h2 { font-size: 18px; margin: 14px 0 2px; }
.legal-body p { margin: 4px 0; }
.legal-body ul, .legal-body ol { margin: 4px 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* Community preview for non-members */
.peek { position: relative; overflow: hidden; }
.peek-text { filter: blur(4px); user-select: none; }

/* Partial stars (quarter / half ratings) */
.star-part { position: relative; display: inline-block; line-height: 0; }
.star-part > svg { position: absolute; left: 0; top: 0; }
.star-fill { position: absolute; left: 0; top: 0; height: 100%; overflow: hidden; line-height: 0; }
/* Stats: books per month */
.month-chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; height: 150px; align-items: end; }
.mcol { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.mbar { width: 100%; min-height: 3px; border-radius: 6px 6px 2px 2px; background: var(--accent); }
/* Wrapped */
.wrap-slide { min-height: 150px; justify-content: center; text-align: center; align-items: center; }

/* Spice scale, spice limit, content notes */
.tag.warn { background: transparent; color: var(--spice-line); border: 1px solid var(--spice-line); }
.tag.founding { background: var(--soft); color: var(--soft-ink); }
fieldset.spice-q { border: none; margin: 0; padding: 0; min-width: 0; }
fieldset.spice-q legend { font-weight: 700; font-size: 14px; padding: 0; margin-bottom: 2px; }
.spice-opt { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; }
.spice-opt:has(input:checked) { background: var(--soft); color: var(--soft-ink); border-color: transparent; }
.spice-opt input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; margin: 0; }
.spice-scale { display: flex; flex-direction: column; gap: 6px; }
.spice-step { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.spice-step[aria-checked="true"] { background: var(--soft); color: var(--soft-ink); border-color: transparent; }
.spice-num { width: 28px; height: 28px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; background: var(--soft); color: var(--soft-ink); flex-shrink: 0; font-size: 14px; }
.spice-step[aria-checked="true"] .spice-num { background: var(--accent); color: var(--on-accent); }

/* Buddy read vote */
.poll-opt { position: relative; overflow: hidden; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.poll-opt > * { position: relative; z-index: 1; }
.poll-opt[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.poll-opt .poll-bar { position: absolute; left: 0; top: 0; bottom: 0; z-index: 0; background: var(--soft); opacity: .7; }

/* stats / wrapped tiles */
.card.tile { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; padding: 16px; flex: 1 1 0; min-width: 0; }
.card.tile b { font-family: var(--display); font-style: var(--fstyle); font-size: 17px; }
.tile-ic { font-size: 26px; line-height: 1; }
/* wrapped save overlay */
.wrap-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; color: #fff; text-align: center; }
.wrap-overlay img { max-height: 70vh; max-width: 100%; border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,.5); -webkit-touch-callout: default; }
.wrap-overlay p { margin: 0; font-size: 15px; line-height: 1.4; }

/* series view */
.series-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.series-item { display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none; color: inherit; flex-shrink: 0; width: 64px; text-align: center; }
.series-item .cover { width: 64px; height: 96px; }

/* share image background picker */
.color-dots { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.color-dot { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 0 0 1px rgba(0,0,0,.25); cursor: pointer; padding: 0; }
.color-dot[aria-checked="true"] { box-shadow: 0 0 0 3px var(--accent), 0 0 0 5px #fff; transform: scale(1.08); }
.wrap-overlay .color-dot[aria-checked="true"] { box-shadow: 0 0 0 3px #fff; }
.chip input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.chip:has(input:checked) { background: var(--soft); color: var(--soft-ink); border-color: transparent; }
