:root {
  --bg: #F3F4F6; --surface: #FFFFFF; --ink: #111827; --ink-2: #374151; --muted: #4B5563; --line: #E5E7EB; --line-2: #D1D5DB;
  --accent: #1F6F54; --accent-dark: #174F3C; --accent-tint: #E3F1EB;
  --amber: #B45309; --amber-ink: #92400E; --amber-tint: #FDF0E1; --amber-track: #F3E6D6;
  --danger: #B42318;
  --accent-fill: #1F6F54; --accent-fill-hover: #174F3C; --amber-fill: #B45309; --on-ink: #fff; --raised: #FFFFFF; --bm-now: #FDF6EC;
  --display: 'Bricolage Grotesque', Inter, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
/* screen only, so print stays light; the *-fill variables carry white text and are not overridden */
@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0F1318; --surface: #181E25; --ink: #F3F4F6; --ink-2: #D1D5DB; --muted: #9CA3AF; --line: #29313B; --line-2: #3A4450;
    --accent: #5CC4A0; --accent-dark: #8AD9BC; --accent-tint: #17352B;
    --amber: #F0A04B; --amber-ink: #F5B46B; --amber-tint: #36260F; --amber-track: #3D3020;
    --danger: #F97066;
    --on-ink: #111827; --raised: #2C353F; --bm-now: #2A2115;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 Inter, system-ui, -apple-system, sans-serif; }
body { min-height: 100vh; min-height: 100dvh; }
a { color: var(--accent); } a:hover { color: var(--accent-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg.i.sm { width: 16px; height: 16px; }

#app { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: 76px; }
.top { background: var(--surface); border-bottom: 1px solid var(--line); padding: 18px 20px 14px; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.title { font-family: var(--display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.content { padding: 14px 16px 20px; display: flex; flex-direction: column; gap: 12px; }

.btn { min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.btn.primary:hover { background: var(--accent-fill-hover); }
.btn.amber { background: var(--amber-fill); border-color: var(--amber-fill); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 52px; font-size: 16px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 48px; height: 48px; border-radius: 14px; background: var(--accent-fill); color: #fff; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; border: 0; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.input { height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); font-size: 16px; color: var(--ink); width: 100%; }
textarea.input { height: auto; padding: 10px 12px; line-height: 1.45; resize: vertical; }
.search { position: relative; display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 16px; color: var(--ink); outline: none; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chip { min-height: 40px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.chip .n { font-weight: 500; opacity: .75; margin-left: 2px; }
.sortbar { display: flex; align-items: center; gap: 6px; padding: 10px 16px 0; overflow-x: auto; }
.pill { min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 500; white-space: nowrap; }
.pill[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-dark); font-weight: 600; }
.seg { display: flex; gap: 6px; }
.seg .pill { flex: 1; min-height: 44px; font-size: 14px; }
/* four labels do not fit one phone-width line: let them wrap inside their buttons */
#tabs .pill { flex: 1 1 auto; padding: 0 4px; white-space: normal; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.book-row { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; text-decoration: none; color: var(--ink); }
.book-row:hover { color: var(--ink); border-color: var(--line-2); }
.cover { width: 46px; height: 68px; flex-shrink: 0; border-radius: 3px 6px 6px 3px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: #fff; font: 700 20px var(--display); box-shadow: inset 5px 0 0 rgba(0,0,0,.2); position: relative; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover.lg { width: 92px; height: 136px; font-size: 34px; border-radius: 4px 8px 8px 4px; }
.b-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st { font-size: 12px; font-weight: 600; margin-top: 4px; display: inline-flex; align-items: center; gap: 4px; }
.st.reading { color: var(--amber-ink); } .st.finished { color: var(--accent); } .st.to_read { color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--amber-track); overflow: hidden; flex: 1; }
.bar > i { display: block; height: 100%; background: var(--amber); }
.badge { align-self: flex-start; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.badge.reading { background: var(--amber-tint); color: var(--amber-ink); }
.badge.finished { background: var(--accent-tint); color: var(--accent-dark); }
.badge.to_read { background: var(--bg); color: var(--ink-2); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.note { font-size: 13px; color: var(--muted); padding: 8px 10px; border-radius: 8px; background: var(--bg); margin: 0; }
.warn { background: var(--amber-tint); color: var(--amber-ink); }
.ok { background: var(--accent-tint); color: var(--accent-dark); }
.label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.bm-now { padding: 12px; border-radius: 10px; background: var(--bm-now); display: flex; flex-direction: column; gap: 4px; }
.bm-big { font: 700 22px var(--display); color: var(--amber-ink); }
.hist { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--ink-2); }
.hist span:last-child { color: var(--muted); white-space: nowrap; }
.stars { display: flex; gap: 2px; }
.stars button { width: 40px; height: 44px; border: 0; background: transparent; font-size: 24px; color: var(--line-2); padding: 0; }
.stars button[aria-pressed="true"] { color: var(--amber); }

.nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); z-index: 5; }
.nav-in { display: flex; width: 100%; max-width: 720px; }
.nav a { flex: 1; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--accent); }

/* scanner */
.scan { background: #0B0F14; color: #F9FAFB; }
.scan-top { display: flex; align-items: center; justify-content: space-between; padding: 8px; }
.scan-top a, .scan-top button { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; color: #F9FAFB; background: transparent; border: 0; }
.cam { position: relative; height: 46vh; min-height: 260px; max-height: 440px; background: #151B23; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.finder { position: relative; width: min(78%, 320px); aspect-ratio: 2 / 1; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.45); }
.finder::before, .finder::after { content: ""; position: absolute; left: 10px; right: 10px; top: 50%; height: 2px; background: #34D399; box-shadow: 0 0 12px #34D399; }
.finder::after { display: none; }
.finder b { position: absolute; width: 28px; height: 28px; border-color: #34D399; border-style: solid; border-width: 0; }
.finder b:nth-child(1) { left: 0; top: 0; border-left-width: 4px; border-top-width: 4px; border-top-left-radius: 10px; }
.finder b:nth-child(2) { right: 0; top: 0; border-right-width: 4px; border-top-width: 4px; border-top-right-radius: 10px; }
.finder b:nth-child(3) { left: 0; bottom: 0; border-left-width: 4px; border-bottom-width: 4px; border-bottom-left-radius: 10px; }
.finder b:nth-child(4) { right: 0; bottom: 0; border-right-width: 4px; border-bottom-width: 4px; border-bottom-right-radius: 10px; }
.cam-msg { position: absolute; left: 16px; right: 16px; bottom: 14px; text-align: center; font-size: 14px; color: #D1D5DB; }
.cam-msg .btn { margin-top: 8px; background: #fff; border-color: #D1D5DB; color: #111827; }
.scan-form { display: flex; gap: 8px; padding: 14px 16px; }
.scan-form .input { background: #0B0F14; border-color: #374151; color: #F9FAFB; }
.scan-form .btn { white-space: nowrap; background: #1F2937; border-color: #374151; color: #F9FAFB; }
.sheet { background: var(--surface); color: var(--ink); border-radius: 20px 20px 0 0; padding: 18px 20px 24px; display: flex; flex-direction: column; gap: 14px; min-height: 40vh; }
.found { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.tag { font-size: 12px; font-weight: 500; padding: 3px 8px; border-radius: 6px; background: var(--bg); color: var(--ink-2); }

/* bookmark card */
.bm-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px 16px; }
.bookmark { width: 300px; min-height: 900px; border-radius: 18px; color: #F9FAFB; padding: 22px 28px 30px; display: flex; flex-direction: column; justify-content: space-between; gap: 22px; background: #1E3140; }
.bookmark .hole { width: 22px; height: 22px; border-radius: 50%; background: #F3F4F6; align-self: center; box-shadow: inset 0 2px 4px rgba(0,0,0,.35); }
.bookmark .brand { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: #CBD5E1; }
.bookmark h1 { font: 700 32px/1.05 var(--display); letter-spacing: -0.02em; margin-top: 14px; overflow-wrap: anywhere; }
.bookmark .by { margin: 6px 0 0; font-size: 15px; color: #CBD5E1; }
.bookmark .mid { border-top: 1px solid rgba(255,255,255,.22); border-bottom: 1px solid rgba(255,255,255,.22); padding: 26px 0; display: flex; flex-direction: column; gap: 10px; }
.bookmark .lbl { font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: #CBD5E1; }
.bookmark .pg { font: 800 112px/.9 var(--display); letter-spacing: -0.04em; color: #F5B46B; }
.bookmark .of { font-size: 15px; color: #E5E7EB; }
.bookmark .bar { background: rgba(255,255,255,.18); height: 8px; flex: none; }
.bookmark .bar > i { background: #F5B46B; }
.bookmark .pct { font-size: 13px; font-weight: 600; color: #F5B46B; }
.bookmark .quote { margin: 0; font-size: 16px; line-height: 1.45; font-style: italic; overflow-wrap: anywhere; }
.bookmark .saved { font-size: 13px; line-height: 1.5; color: #CBD5E1; }
.bookmark .qr { width: 88px; height: 88px; flex-shrink: 0; border-radius: 8px; background: #F9FAFB; padding: 6px; }
.bookmark .qr svg, .bookmark .qr img { width: 100%; height: 100%; display: block; }
.swatches { display: flex; gap: 8px; }
.swatches button { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; }
.swatches button[aria-pressed="true"] { border-color: var(--ink); }

.toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%); background: var(--ink); color: var(--on-ink); padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; z-index: 20; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
table.res { width: 100%; border-collapse: collapse; font-size: 13px; }
table.res td { padding: 6px 4px; border-top: 1px solid var(--line); }
.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: s .8s linear infinite; display: inline-block; }
@keyframes s { to { transform: rotate(360deg); } }

@media print {
  body { background: #fff; }
  .nav, .no-print { display: none !important; }
  #app { padding: 0; }
  .bm-wrap { padding: 0; }
  .bookmark { -webkit-print-color-adjust: exact; print-color-adjust: exact; width: 2in; min-height: 6in; padding: 12px 16px; gap: 12px; }
  .bookmark h1 { font-size: 20px; } .bookmark .pg { font-size: 64px; } .bookmark .qr { width: 64px; height: 64px; }
}
