:root {
  --bg: #f7f3ee;
  --panel: #fffdf9;
  --text: #2a2420;
  --muted: #7a6f66;
  --line: #e4dcd2;
  --accent: #7a4b2a;
  --accent-text: #fff;
  --accent-soft: #f1e5d8;
  --danger: #a33a2c;
  --ok: #3f7a4a;
  --star: #d9a21b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 2px 8px rgba(60, 40, 20, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815;
    --panel: #24201c;
    --text: #ece5dc;
    --muted: #a3978b;
    --line: #3a332c;
    --accent: #d39b6a;
    --accent-text: #1b1815;
    --accent-soft: #3a2d22;
    --danger: #e0786a;
    --ok: #7cc28a;
    --shadow: none;
  }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
img { max-width: 100%; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .4rem; font-family: var(--serif); font-weight: 700; font-size: 1.2rem; color: var(--text); }
.mainnav { display: flex; gap: .2rem; flex-wrap: wrap; }
.mainnav a { padding: .35rem .7rem; border-radius: 999px; color: var(--text); }
.mainnav a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mainnav a:hover { text-decoration: none; background: var(--accent-soft); }
.topsearch { margin-left: auto; }
.topsearch input { width: 14rem; }
.logout { margin: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }
section { margin-bottom: 1.6rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.panel.narrow { max-width: 28rem; margin: 2rem auto; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.count { font-size: .9em; font-weight: normal; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); font-weight: 600; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: .6rem .8rem; }
.flash { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: .6rem .9rem; border-radius: 6px; margin-bottom: 1rem; }
.hint { color: var(--muted); font-size: .8rem; font-weight: normal; }

input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], input[type=url], input[type=password], input[type=date], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; min-width: 0; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { width: 100%; resize: vertical; }
input.short { width: 6rem; }
label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: .4rem; }
.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font-weight: 600; font-size: .95rem; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.danger, .link.danger { color: var(--danger); }
.link { background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.wrap > label { flex: 1 1 9rem; }
.inline { display: inline-flex; gap: .5rem; align-items: center; margin: 0; flex-wrap: wrap; }
.inline label { flex-direction: row; align-items: center; gap: .4rem; }
.actions { margin-top: 1rem; }
details > summary { cursor: pointer; color: var(--accent); }
details[open] > summary { margin-bottom: .5rem; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: none; }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.st-reading { background: #dcebdc; color: #2f6b3a; }
.st-read { background: #dfe6f3; color: #34518a; }
.st-dnf { background: #f3dedb; color: #8f3529; }
.st-paused { background: #f4ecd2; color: #7a6216; }
@media (prefers-color-scheme: dark) {
  .st-reading { background: #24382a; color: #8fd19e; }
  .st-read { background: #252f42; color: #9db6e6; }
  .st-dnf { background: #3d2522; color: #eb9b8f; }
  .st-paused { background: #3a3220; color: #e2c66f; }
}
.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; background: var(--accent-soft); font-size: .85rem; margin: .1rem 0; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }

.stars { position: relative; display: inline-block; color: var(--line); letter-spacing: 1px; font-size: .95rem; line-height: 1; white-space: nowrap; }
.stars-fill { position: absolute; left: 0; top: 0; overflow: hidden; color: var(--star); }

/* covers */
.cover { position: relative; aspect-ratio: 2 / 3; border-radius: 4px; overflow: hidden; background: var(--line); flex: none; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.cover-ph { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; padding: .5rem; color: #fff; font-family: var(--serif); text-align: center; gap: .3rem; overflow: hidden; }
.cover-ph span { font-weight: 700; font-size: .85rem; line-height: 1.15; }
.cover-ph small { font-size: .7rem; opacity: .85; font-family: var(--font); }
.cover.xs { width: 36px; } .cover.xs .cover-ph * { display: none; }
.cover.sm { width: 72px; } .cover.sm .cover-ph small { display: none; } .cover.sm .cover-ph span { font-size: .65rem; }
.cover.md { width: 100%; }
.cover.lg { width: 100%; max-width: 260px; }

/* library */
.lib-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.viewtoggle a, .years a { padding: .2rem .6rem; border-radius: 6px; }
.viewtoggle a[aria-current], .years a[aria-current] { background: var(--accent-soft); font-weight: 700; }
.years { display: flex; flex-wrap: wrap; gap: .2rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1 1 14rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1.2rem 1rem; }
.card { display: flex; flex-direction: column; gap: .4rem; color: var(--text); }
.card:hover { text-decoration: none; }
.card:hover .cover { box-shadow: 0 0 0 2px var(--accent); }
.card-title { font-weight: 700; line-height: 1.25; font-size: .92rem; }
.card-author { color: var(--muted); font-size: .85rem; }
.card-meta { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.tablewrap { overflow-x: auto; }
.booktable { width: 100%; border-collapse: collapse; font-size: .92rem; }
.booktable th, .booktable td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.booktable th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.5rem; }

/* dashboard */
.dash { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.6rem; }
.dash section { margin: 0; }
.goal-num { font-size: 1.1rem; margin-bottom: .4rem; }
.goal-num strong { font-size: 1.8rem; font-family: var(--serif); }
.countlist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.countlist li { display: flex; flex-direction: column; }
.countlist a, .countlist li { color: var(--text); }
.countlist strong { display: block; font-size: 1.4rem; font-family: var(--serif); }
.reading-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 1rem; }
.reading-item { display: flex; gap: 1rem; align-items: flex-start; }
.reading-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .4rem; }
.reading-body h3 { margin: 0; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 1rem; }
.shelf-item { display: flex; flex-direction: column; gap: .2rem; align-items: flex-start; color: var(--text); }

/* progress */
.progress { flex: 1; height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.progress-row { display: flex; align-items: center; gap: .6rem; }
.pct { font-weight: 700; min-width: 3.2rem; text-align: right; }
.progress-form { display: flex; flex-direction: column; gap: .5rem; margin: .5rem 0 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; align-self: flex-start; flex-wrap: wrap; }
.seg label { flex-direction: row; font-weight: 600; font-size: .85rem; padding: .25rem .65rem; cursor: pointer; border-right: 1px solid var(--line); }
.seg label:last-child { border-right: none; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.pf-fields { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.pf { display: inline-flex; gap: .4rem; align-items: center; }
.pf input:not(.short) { width: 7.5rem; }
.js .pf[hidden] { display: none; }

/* book page */
.book { display: grid; grid-template-columns: 260px 1fr; gap: 2rem; align-items: start; }
.book-side { position: sticky; top: 4.5rem; display: flex; flex-direction: column; gap: .8rem; }
.book-title { font-size: 2rem; margin-bottom: .1em; }
.subtitle { font-family: var(--serif); font-size: 1.15rem; color: var(--muted); margin: 0 0 .4rem; }
.authors { font-size: 1.1rem; margin: .2rem 0; }
.meta { display: flex; flex-wrap: wrap; gap: .3rem .9rem; align-items: center; color: var(--muted); font-size: .92rem; }
.status-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1rem 0 1.4rem; }
.inline-details { display: inline-flex; gap: .4rem; align-items: center; }
.inline-details[open] { display: inline-flex; }
.inline-details[open] > summary { margin: 0; }
.book-main .panel { margin-bottom: 1.2rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.details dt { color: var(--muted); font-size: .9rem; }
.details dd { margin: 0; }
.prose p { margin: 0 0 .8em; }
.prose p:last-child { margin-bottom: 0; }
.note { border-top: 1px solid var(--line); padding: .7rem 0; }
.note blockquote { margin: .3rem 0; padding-left: .9rem; border-left: 3px solid var(--accent); font-family: var(--serif); font-style: italic; }
.note-form .row input[type=text] { flex: 1; }
.readform { display: flex; flex-direction: column; gap: .6rem; margin: .4rem 0 .6rem; }
.reads li { display: block; }
.coveredit form { margin-top: .5rem; }

/* forms */
.formgrid { display: grid; grid-template-columns: 180px 1fr; gap: 1.5rem; }
.form-cover { display: flex; flex-direction: column; gap: .8rem; }
.form-fields, .formgrid-inner { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .8rem 1rem; align-content: start; }
.form-fields .wide, .formgrid-inner .wide { grid-column: 1 / -1; }
.form-fields input, .form-fields select { width: 100%; }
.searchrow { display: flex; gap: .5rem; flex-wrap: wrap; }
.searchrow input { flex: 1 1 16rem; }
#scanner { margin-top: 1rem; }
#scan-video { width: 100%; max-width: 480px; border-radius: 8px; background: #000; display: block; }

/* results */
.results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .6rem; }
.result { display: flex; gap: 1rem; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem; }
.result-body { flex: 1; min-width: 0; }
.result-act { display: flex; flex-direction: column; gap: .4rem; align-items: flex-end; }

/* goals */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: .4rem; align-items: end; }
.bar { display: flex; flex-direction: column; align-items: center; gap: .2rem; }
.bar-col { height: 120px; width: 100%; display: flex; align-items: flex-end; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.bar-n { font-weight: 700; font-size: .85rem; min-height: 1.2em; }
.bar-label { font-size: .75rem; color: var(--muted); }

@media (max-width: 760px) {
  .topbar { gap: .5rem; }
  .topsearch { order: 3; width: 100%; margin: 0; }
  .topsearch input { width: 100%; }
  .mainnav a { padding: .3rem .5rem; }
  .dash { grid-template-columns: 1fr; }
  .book { grid-template-columns: 1fr; gap: 1rem; }
  .book-side { position: static; flex-direction: row; align-items: flex-start; }
  .book-side .cover.lg { width: 140px; }
  .book-title { font-size: 1.5rem; }
  .formgrid { grid-template-columns: 1fr; }
  .form-cover .cover { width: 120px; }
  .reading-list { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 1rem .7rem; }
  .result { flex-wrap: wrap; }
  .result-act { flex-direction: row; width: 100%; justify-content: flex-end; }
  .bars { gap: .15rem; }
  .bar-label { font-size: .6rem; }
}
.bigstars .stars { font-size: 1.4rem; }
.review { margin-bottom: .6rem; }
.dotlist > span + span::before { content: " · "; }
.form-fields { align-items: end; }
.form-fields input[type=checkbox] { width: auto; }
.form-fields label.check { padding-bottom: .5rem; }
#lib-results[aria-busy="true"] { opacity: .55; transition: opacity .15s; }
.lib-head h1 { margin-right: auto; }
.dupe-bar { position: sticky; top: 3.6rem; z-index: 5; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; background: var(--bg); padding: .6rem 0; margin-bottom: .6rem; }
.dupe-group { margin-bottom: 1rem; padding-top: .7rem; }
.dupe-head { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: .4rem; }
.dupe-actions { margin-left: auto; display: flex; gap: .4rem; }

/* book menu */
.bm-item { position: relative; }
.bm-btn { display: none; }
.js .bm-btn {
  display: flex; align-items: center; justify-content: center; position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 30px; height: 30px; border-radius: 50%; border: none; background: rgba(20, 15, 10, .62); color: #fff;
  font-size: 18px; line-height: 1; cursor: pointer; opacity: .85; padding: 0;
}
.js .bm-btn:hover, .js .bm-btn:focus-visible, .js .bm-btn[aria-expanded=true] { opacity: 1; background: var(--accent); color: var(--accent-text); }
.js .bm-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.js .bm-btn:disabled { opacity: .4; cursor: progress; }
.reading-item .thumb .bm-btn { width: 24px; height: 24px; font-size: 15px; top: 4px; right: 4px; }
.thumb-cell { white-space: nowrap; }
.thumb-cell > a { display: inline-block; vertical-align: middle; }
.js .thumb-cell .bm-btn { position: static; display: inline-flex; vertical-align: middle; margin-left: .3rem; width: 26px; height: 26px; background: transparent; color: var(--muted); }
.js .thumb-cell .bm-btn:hover, .js .thumb-cell .bm-btn[aria-expanded=true] { background: var(--accent-soft); color: var(--accent); }
.bm-menu { position: absolute; z-index: 50; min-width: 210px; display: flex; flex-direction: column; padding: .35rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(0, 0, 0, .2); }
.bm-mi { display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem; border: none; background: none; border-radius: 6px;
  font: inherit; font-size: .92rem; color: var(--text); text-align: left; cursor: pointer; text-decoration: none; }
.bm-mi:hover, .bm-mi:focus { background: var(--accent-soft); outline: none; text-decoration: none; }
.bm-mi.danger { color: var(--danger); }
.bm-check { width: 1em; color: var(--accent); font-weight: 700; }
.bm-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .2rem .7rem; }
.bm-sep { height: 1px; background: var(--line); margin: .3rem 0; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 60; max-width: 90vw;
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }

/* settings */
.narrow-form { max-width: 26rem; }
.add-location input { flex: 1 1 14rem; max-width: 26rem; }
.locations { margin-top: .8rem; }
.loc-row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; }
.loc-name { font-weight: 600; min-width: 10rem; }
.loc-edit[open] { flex-basis: 100%; order: 5; }
.loc-edit[open] > summary { margin-bottom: .3rem; }

/* navigation with icons; bottom tab bar on small screens */
.mainnav a { display: inline-flex; align-items: center; gap: .35rem; }
.mainnav .icon { width: 18px; height: 18px; }
.search-btn { display: none; color: var(--text); padding: .3rem; border-radius: 999px; }
.search-btn .icon { display: block; }
.settings-links { display: flex; flex-wrap: wrap; gap: .8rem 1.6rem; align-items: center; }
.settings-link { display: flex; flex-direction: column; color: var(--text); }
.settings-link:hover { text-decoration: none; }
.settings-link:hover strong { color: var(--accent); }
.settings-link-form { margin: 0 0 0 auto; }

/* pull to refresh (installed app) */
.ptr { position: fixed; top: calc(env(safe-area-inset-top) + 6px); left: 50%; z-index: 30; width: 36px; height: 36px;
  margin-left: -18px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; opacity: 0; transform: translateY(-60px); pointer-events: none; }
.ptr-spin { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; }
.ptr.ready .ptr-spin { border-color: var(--accent); }
.ptr.loading .ptr-spin { animation: ptr-spin .7s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .topbar { padding: calc(env(safe-area-inset-top) + .45rem) 1rem .45rem; flex-wrap: nowrap; }
  .topsearch { display: none; }
  .search-btn { display: block; margin-left: auto; }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 0; background: var(--panel); border-top: 1px solid var(--line);
    padding: .3rem .25rem calc(env(safe-area-inset-bottom) + .3rem);
  }
  .mainnav a { flex-direction: column; gap: .1rem; padding: .3rem 0; border-radius: 10px; font-size: .68rem; font-weight: 600; color: var(--muted); }
  .mainnav a:hover { background: none; }
  .mainnav a[aria-current] { background: none; color: var(--accent); }
  .mainnav .icon { width: 24px; height: 24px; }
  main { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .foot { display: none; }
  .bm-menu { max-width: calc(100vw - 16px); }
  .toast { bottom: calc(5rem + env(safe-area-inset-bottom)); }
  .dupe-bar { top: 3rem; }
}
