:root {
  --paper: #faf7f2; --paper-2: #f3eee5; --ink: #1f1d1a; --ink-2: #4a4640; --muted: #7a746a;
  --rule: #e2dbcf; --rule-strong: #cfc6b6;
  --green: #1f5c45; --green-soft: #e3eee8; --amber: #8a5a14; --red: #a3321f; --red-soft: #f7e6e1;
  --serif: Literata, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171614; --paper-2: #211f1c; --ink: #ece7de; --ink-2: #c9c2b6; --muted: #958e82;
    --rule: #302d28; --rule-strong: #45413a;
    --green: #8cc7a8; --green-soft: #1d2e26; --amber: #e0b26a; --red: #f0a090; --red-soft: #351f1a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.55 var(--sans); }
button, select, input { font: inherit; color: inherit; }
svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
a { color: var(--green); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 24px 56px; }

/* ---------- masthead ---------- */
.masthead { border-bottom: 1px solid var(--rule); }
.masthead-inner { max-width: 1040px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 10px 24px; flex-wrap: wrap; }
.wordmark { font-family: var(--serif); font-weight: 600; font-size: 21px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.wordmark span { color: var(--green); font-weight: 500; padding: 0 1px; }
.context { display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap; font-size: 14px; }
.ctx { display: flex; align-items: baseline; gap: 6px; }
.ctx span { color: var(--muted); }
.ctx select { border: 0; border-bottom: 1px solid var(--rule-strong); background-color: transparent; padding: 2px 20px 2px 0; font-weight: 600; max-width: 300px; text-overflow: ellipsis; border-radius: 0; background-position: right 0 center; }
.ctx select:hover { border-bottom-color: var(--ink-2); }
.text-btn { display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; padding: 2px 0; color: var(--ink-2); cursor: pointer; font-size: 14px; }
.text-btn:hover { color: var(--ink); }
.text-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- controls ---------- */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a746a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; background-size: 14px;
}
input[type="search"], .field input, .selects select {
  background-color: var(--paper); border: 1px solid var(--rule-strong); border-radius: 3px; padding: 8px 10px; color: var(--ink);
}
.selects select { padding-right: 26px; font-size: 14px; }
.field input { width: 100%; font-size: 16px; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
input[type="checkbox"] { accent-color: var(--green); width: 15px; height: 15px; margin: 0; }
.btn { background: var(--green); color: var(--paper); border: 0; border-radius: 3px; padding: 10px 20px; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .6; cursor: progress; }
.link { background: none; border: 0; padding: 0; color: var(--green); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-size: inherit; }
.alert { background: var(--red-soft); color: var(--red); border-left: 3px solid var(--red); padding: 9px 12px; font-size: 14px; margin: 0 0 18px; }
.alert:empty { display: none; }

/* ---------- setup ---------- */
.intro { max-width: 600px; margin: 48px 0 32px; }
.intro h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(26px, 4vw, 34px); line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 12px; }
.intro p { color: var(--ink-2); margin: 0; font-size: 16px; }
.setup { max-width: 600px; }
.field { padding: 20px 0; border-top: 1px solid var(--rule); }
.field > label { display: block; font-weight: 600; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.more { margin-top: 12px; font-size: 14px; }
.more summary { cursor: pointer; color: var(--ink-2); }
.more input { margin-top: 8px; font-size: 15px; }
.saved-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-top: 10px; font-size: 14px; }
.saved-row:empty { display: none; }
.saved-row .label { color: var(--muted); }
.saved { display: inline-flex; align-items: baseline; gap: 4px; }
.saved button { background: none; border: 0; padding: 0; cursor: pointer; }
.saved .use { color: var(--green); text-decoration: underline; text-underline-offset: 2px; }
.saved .rm { color: var(--muted); font-size: 15px; line-height: 1; }
.saved .rm:hover { color: var(--red); }
.picked { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; font-weight: 600; font-size: 16px; }
.picked .link { font-weight: 400; font-size: 14px; }
#lib-results { list-style: none; margin: 4px 0 0; padding: 0; }
#lib-results:not(:empty) { border: 1px solid var(--rule-strong); border-radius: 3px; background: var(--paper); }
#lib-results li + li { border-top: 1px solid var(--rule); }
#lib-results li.none { padding: 9px 10px; color: var(--muted); font-size: 14px; }
#lib-results button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; cursor: pointer; }
#lib-results button:hover { background: var(--paper-2); }
#lib-results small { display: block; color: var(--muted); font-size: 13px; }
.setup-actions { display: flex; align-items: center; gap: 18px; padding-top: 20px; border-top: 1px solid var(--rule); }
.fineprint { color: var(--muted); font-size: 13px; margin: 18px 0 0; }

/* ---------- dashboard ---------- */
.page-head { margin: 36px 0 6px; }
.page-head h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(24px, 3.5vw, 30px); letter-spacing: -0.015em; line-height: 1.2; margin: 0; }
.meta { color: var(--muted); margin: 4px 0 0; font-size: 14px; }
.summary { font-family: var(--serif); font-size: 18px; line-height: 1.5; color: var(--ink-2); margin: 18px 0 24px; max-width: 720px; }
.summary b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.summary b.good { color: var(--green); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 14px 0; border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule); }
.toolbar input[type="search"] { flex: 1 1 220px; min-width: 0; }
.tabs { display: flex; gap: 16px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 3px 0; cursor: pointer; color: var(--muted); font-size: 14px; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--green); font-weight: 600; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; color: var(--ink-2); }
.checks label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.selects { display: flex; gap: 8px; flex-wrap: wrap; }

.results-head { display: flex; align-items: center; gap: 14px; margin: 14px 0 0; min-height: 22px; }
#count { margin: 0; color: var(--muted); font-size: 13px; }
#progress { flex: 0 1 160px; height: 2px; background: var(--rule); overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--green); transition: width .25s; }
#progress.done { display: none; }

/* book grid */
#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 12px; }
.book { display: grid; grid-template-columns: 60px minmax(0, 1fr); grid-template-rows: auto 1fr; gap: 10px 14px; padding: 14px; border: 1px solid var(--rule); border-radius: 3px; background: color-mix(in srgb, var(--paper) 60%, white 40%); align-content: start; }
@media (prefers-color-scheme: dark) { .book { background: var(--paper-2); } }
.book .cover { grid-row: span 2; }
.book .editions, .book .note, .book .skeleton { grid-column: 2; align-self: end; }
.cover { width: 60px; height: 90px; object-fit: cover; background: var(--paper-2); border: 1px solid var(--rule); display: block; }
.book h3 { font-family: var(--serif); font-weight: 600; font-size: 17px; line-height: 1.3; margin: 0; }
.book h3 a { color: var(--ink); text-decoration: none; }
.book h3 a:hover { text-decoration: underline; text-underline-offset: 3px; }
.byline { color: var(--ink-2); font-size: 14px; margin: 2px 0 0; }
.byline .rating { color: var(--muted); }
.editions { list-style: none; margin: 0; padding: 0; }
.editions li + li { border-top: 1px dotted var(--rule-strong); }
.ed { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 16px; padding: 7px 0; align-items: start; color: var(--ink); text-decoration: none; font-size: 14px; }
.ed:hover .ed-fmt { text-decoration: underline; text-underline-offset: 2px; }
.ed-fmt { display: flex; align-items: center; gap: 6px; white-space: nowrap; min-width: 0; }
.ed-fmt svg { color: var(--muted); }
.ed-fmt .ext { width: 12px; height: 12px; opacity: 0; transition: opacity .15s; }
.ed:hover .ext, .ed:focus-visible .ext { opacity: 1; }
.ed-main { min-width: 0; }
.ed-main .tags { display: block; color: var(--muted); font-size: 12px; padding-left: 21px; }
.ed-main .tags .lucky { color: var(--green); }
.ed-status { text-align: right; white-space: nowrap; }
.ed-status .now { color: var(--green); font-weight: 600; }
.ed-status .wait { color: var(--amber); font-weight: 600; }
.ed-status small { display: block; color: var(--muted); font-size: 12px; }
.note { color: var(--muted); font-size: 14px; margin: 0; font-style: italic; }
.note.err { color: var(--red); font-style: normal; }
.skeleton { height: 14px; width: 70%; background: var(--paper-2); animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: .45; } }
.empty { padding: 40px 0; color: var(--ink-2); }
.empty p { margin: 0 0 8px; font-family: var(--serif); font-size: 17px; }

footer { max-width: 1040px; margin: 0 auto; padding: 20px 24px 32px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 12px; }
footer { display: flex; justify-content: space-between; align-items: center; gap: 12px 32px; flex-wrap: wrap; }
footer p { margin: 0; max-width: 640px; }
.coffee { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--green); text-decoration: none; white-space: nowrap; }
.coffee:hover { text-decoration: underline; text-underline-offset: 3px; }
.coffee svg { width: 16px; height: 16px; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .wrap, .masthead-inner { padding-left: 16px; padding-right: 16px; }
  .context { width: 100%; justify-content: space-between; }
  .ctx { min-width: 0; flex: 1 1 100%; }
  .ctx select { flex: 1; min-width: 0; max-width: none; }
  #grid { grid-template-columns: 1fr; }
  .selects { width: 100%; }
  .selects select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .summary { font-size: 17px; }
  .intro { margin-top: 32px; }
}
