:root {
  --bg: #f6f5f2; --surface: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --border: #dedbd4;
  --accent: #2f6f4f; --accent-text: #ffffff; --danger: #b3261e; --warn: #8a5a00;
  --ok-bg: #e5f2ea; --err-bg: #fbe9e7; --warn-bg: #fdf3dc; --chip: #ecebe6;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --surface: #1d1d20; --text: #ececee; --muted: #9a9aa2; --border: #34343a;
    --accent: #5fb98a; --accent-text: #0e1a13; --danger: #f2827a; --warn: #f0c46a;
    --ok-bg: #1d3328; --err-bg: #3a1f1d; --warn-bg: #3a2f17; --chip: #2a2a2f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 .8rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; }
main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.muted, small { color: var(--muted); }
code, pre { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
pre { background: var(--bg); border: 1px solid var(--border); padding: .6rem .8rem; border-radius: var(--radius); overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* header */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.top .search { flex: 1 1 280px; }
.top .search input { width: 100%; }
.top nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* forms */
input, select, textarea, button, .button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin: .5rem 0; font-weight: 500; }
label small { font-weight: 400; }
label > input, label > select, label > textarea { margin-top: .25rem; font-weight: 400; }
button, .button { display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .9rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); cursor: pointer; text-decoration: none; line-height: 1.3; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.danger { color: var(--danger); border-color: var(--danger); }
button.small { padding: .2rem .55rem; font-size: .85rem; }
.linklike { border: 0; background: none; padding: 0; color: var(--accent); }
.inline { display: inline; margin: 0; }
.buttons { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; align-items: center; }
.row { display: flex; flex-wrap: wrap; gap: 0 1rem; align-items: end; }
.row > label { flex: 0 1 180px; }
.row > .grow { flex: 1 1 260px; }
.row > .small { flex: 0 1 110px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 1rem 0; padding: .4rem 1rem .8rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.checks { display: flex; flex-wrap: wrap; gap: .2rem 1rem; }
.check { display: inline-flex; gap: .35rem; align-items: center; font-weight: 400; margin: .2rem 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1rem 0; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
.narrow { max-width: 480px; margin: 3rem auto; }
.login { max-width: 360px; margin: 12vh auto; }
.login button { width: 100%; justify-content: center; margin-top: .6rem; }

/* flash */
.flash { padding: .6rem .9rem; border-radius: var(--radius); margin: .5rem 0 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); }
.flash.error { background: var(--err-bg); color: var(--danger); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

/* list */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.2rem; margin-bottom: .8rem; }
.count { font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; }
.tabs a { padding: .2rem .7rem; border-radius: 999px; color: var(--text); }
.tabs a.active { background: var(--accent); color: var(--accent-text); }
.sort { margin-left: auto; }
.sort label { display: flex; gap: .5rem; align-items: center; margin: 0; font-weight: 400; }
.sort select { width: auto; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { background: var(--chip); color: var(--text); padding: .15rem .65rem; border-radius: 999px; font-size: .9rem; }
.chip.clear { background: none; color: var(--accent); }
.grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.2rem 1rem; }
.book { display: flex; flex-direction: column; min-width: 0; }
.book img { width: 100%; height: auto; aspect-ratio: 2/3; object-fit: cover; border-radius: 4px; background: var(--chip); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.book .title { display: block; margin-top: .4rem; font-weight: 600; color: var(--text); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .authors, .book .series { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book.archived img { opacity: .45; }
.badge { display: inline-block; align-self: flex-start; font-size: .75rem; padding: 0 .5rem; border-radius: 999px; background: var(--chip); margin-top: .2rem; }
.badge.done { background: var(--ok-bg); }
.badge.reading { background: var(--warn-bg); }
.empty { padding: 3rem 0; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 2rem 0 1rem; }

/* detail */
.detail { display: grid; grid-template-columns: minmax(160px, 300px) 1fr; gap: 1.5rem; align-items: start; }
.detail .cover img { width: 100%; height: auto; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.2); background: var(--chip); }
.detail .authors { font-size: 1.1rem; margin: 0 0 1rem; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag { background: var(--chip); color: var(--text); padding: 0 .55rem; border-radius: 999px; font-size: .9rem; }
.stars { color: #d49b00; letter-spacing: .1em; }
.segmented { display: inline-flex; margin: 0; }
.segmented button { border-radius: 0; margin-left: -1px; }
.segmented button:first-of-type { border-radius: var(--radius) 0 0 var(--radius); }
.segmented button:last-of-type { border-radius: 0 var(--radius) var(--radius) 0; }
.segmented button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); position: relative; }
.description { line-height: 1.6; overflow-wrap: anywhere; }
.files { list-style: none; padding: 0; margin: 0 0 1rem; }
.files li { display: flex; justify-content: space-between; align-items: center; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.danger-zone { border-color: var(--danger); }

/* upload */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: 2rem 1rem; border: 2px dashed var(--border);
  border-radius: var(--radius); text-align: center; cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--ok-bg); }
.dropzone span { font-size: 1.1rem; font-weight: 600; }
progress { width: 100%; height: 10px; margin-top: .8rem; accent-color: var(--accent); }
.results { list-style: none; padding: 0; }
.results li { padding: .4rem .2rem; border-bottom: 1px solid var(--border); }
.results .error { color: var(--danger); }

/* settings */
.sessions { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: .9rem; }
.sessions th, .sessions td { text-align: left; padding: .35rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.sessions .ua { color: var(--muted); overflow-wrap: anywhere; }
.copy { cursor: copy; }

@media (max-width: 640px) {
  main { padding: .7rem; }
  .detail { grid-template-columns: 1fr; }
  .detail .cover { max-width: 220px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 1rem .7rem; }
  .sort { margin-left: 0; }
  .top nav { gap: .7rem; font-size: .95rem; }
}

/* list (table) view */
.view { margin-left: auto; }
.view + .sort { margin-left: 0; }
.bulk-bar, .apply-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .8rem; margin: 0 0 .6rem; }
.bulk-bar .spacer { flex: 1; }
.bulk-bar label, .apply-bar label { display: flex; align-items: center; gap: .4rem; margin: 0; font-weight: 400; }
.bulk-bar select, .apply-bar select { width: auto; }
.apply-bar { padding: .5rem .8rem; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--ok-bg); }
.apply-bar .grow { flex: 1 1 220px; }
.apply-bar .grow > span { flex: 1; display: flex; }
.apply-bar .grow input, .apply-bar .grow select { margin: 0; }
#bulk-status.has-changes { color: var(--warn); font-weight: 600; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: "▾"; font-size: .8em; }
.menu-panel { position: absolute; z-index: 20; top: calc(100% + .3rem); left: 0; min-width: 14rem; max-height: 60vh; overflow-y: auto;
  padding: .5rem .8rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.menu-panel .check { display: flex; }

/* the table scrolls inside its own box so the header and the title column stay visible */
.table-wrap { overflow: auto; max-height: calc(100vh - 13rem); min-height: 16rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.books { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: .88rem; }
table.books th { position: sticky; top: 0; z-index: 2; text-align: left; font-weight: 600; padding: .5rem .5rem; white-space: nowrap;
  background: var(--surface); border-bottom: 1px solid var(--border); color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
table.books th .check { margin: 0; font-weight: 600; }
table.books td { padding: .15rem .3rem; border-bottom: 1px solid var(--border); vertical-align: top; background: var(--surface); }
table.books tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface) 96%, var(--text)); }
table.books tbody tr:hover td { background: color-mix(in srgb, var(--surface) 92%, var(--accent)); }
table.books .sticky { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 var(--border); }
table.books th.sticky { z-index: 3; }

/* cells read as text; the field shows up on hover and focus */
table.books input:not([type=checkbox]), table.books select, table.books textarea {
  margin: 0; padding: .3rem .4rem; min-width: 9rem; border-color: transparent; background: transparent; border-radius: 4px; }
table.books input:not([type=checkbox]):hover, table.books select:hover, table.books textarea:hover { border-color: var(--border); }
table.books input:not([type=checkbox]):focus, table.books select:focus, table.books textarea:focus { border-color: var(--accent); background: var(--surface); outline: none; }
table.books select { appearance: none; -webkit-appearance: none; min-width: 6.5rem; cursor: pointer; }
table.books select:hover, table.books select:focus { appearance: auto; -webkit-appearance: auto; }
table.books .num { min-width: 0; width: 3.6rem; }
table.books input[type=date] { min-width: 0; width: 9rem; }
table.books textarea { display: block; min-width: 14rem; height: 2rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; resize: none; }
table.books textarea.wide { min-width: 22rem; }
table.books textarea:focus { height: 10rem; overflow: auto; white-space: pre-wrap; resize: vertical; position: relative; z-index: 1; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
table.books td.sticky input:not([type=checkbox]) { min-width: 16rem; font-weight: 600; }
table.books td.sticky input.sub { font-weight: 400; }
.title-cell { display: flex; gap: .45rem; align-items: center; }
.title-cell input[type=checkbox] { flex: none; }
.title-cell img { width: 28px; height: 42px; object-fit: cover; border-radius: 2px; background: var(--chip); flex: none; }
.stack { display: flex; flex-direction: column; }
.pair { display: flex; gap: .2rem; }
input.sub { font-size: .78rem; color: var(--muted); }
table.books tbody tr.selected td { background: color-mix(in srgb, var(--surface) 85%, var(--accent)); }
table.books .changed { background: var(--warn-bg) !important; border-color: var(--warn) !important; }
table.books tbody tr.invalid td { background: var(--err-bg); }
tr[data-archived] img { opacity: .45; }
.row-error { color: var(--danger); margin: .2rem 0 .3rem; max-width: 22rem; white-space: normal; font-size: .8rem; }
.hint { font-size: .8rem; margin: .4rem 0 0; }
@media (max-width: 640px) {
  .table-wrap { max-height: calc(100vh - 9rem); }
  table.books td.sticky input:not([type=checkbox]) { min-width: 10rem; }
}
