:root {
  --bg: #faf7f2;
  --bg-card: #ffffff;
  --bg-sunk: #f1ece3;
  --ink: #1d1a16;
  --ink-soft: #5f594f;
  --ink-faint: #8d8578;
  --line: #e3dcd0;
  --accent: #9a3412;
  --accent-soft: #fdeee6;
  --shadow: 0 1px 2px rgba(29, 26, 22, .06), 0 6px 20px rgba(29, 26, 22, .05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100e;
    --bg-card: #1b1815;
    --bg-sunk: #221e1a;
    --ink: #f2ede5;
    --ink-soft: #b3aa9c;
    --ink-faint: #857d71;
    --line: #2e2823;
    --accent: #f0996a;
    --accent-soft: #2b1f18;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { width: min(880px, 100% - 2rem); margin-inline: auto; }

/* --- masthead --- */
.masthead { padding: 2.2rem 0 1.4rem; border-bottom: 1px solid var(--line); background: var(--bg-card); }
.masthead h1 {
  margin: 0;
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  letter-spacing: -.03em;
  font-weight: 700;
}
.masthead h1 span { color: var(--accent); }
.tagline { margin: .4rem 0 0; color: var(--ink-soft); max-width: 46ch; }
.stats { margin: .7rem 0 0; color: var(--ink-faint); font-size: .85rem; }

/* --- controls --- */
.controls { padding: 1.1rem 0 .3rem; position: sticky; top: 0; background: var(--bg); z-index: 5; }
#search {
  width: 100%;
  padding: .7rem .9rem;
  font-size: 1rem;
  color: var(--ink);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.controls .row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }

.segmented { display: inline-flex; background: var(--bg-sunk); border-radius: 999px; padding: 3px; }
.seg {
  border: 0; background: none; color: var(--ink-soft);
  font: inherit; font-size: .85rem; padding: .35rem .8rem; border-radius: 999px; cursor: pointer;
}
.seg.active { background: var(--bg-card); color: var(--ink); box-shadow: var(--shadow); }

.tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag {
  border: 1px solid var(--line); background: none; color: var(--ink-soft);
  font: inherit; font-size: .78rem; padding: .25rem .6rem; border-radius: 999px; cursor: pointer;
}
.tag.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* --- cards --- */
main { padding: 1rem 0 2rem; display: grid; gap: .9rem; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.book-head { display: flex; gap: .9rem; padding: .9rem; }
/* The title tile is always in the DOM; a real cover fades in over it once it loads.
   covers.openlibrary.org can be slow or unreachable, and it answers with a 1x1 pixel
   for ISBNs it doesn't have — the tile has to survive all three cases. */
.cover {
  position: relative;
  width: 62px; min-width: 62px; height: 92px; border-radius: 6px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  display: grid; place-items: center; text-align: center;
  font-size: .62rem; line-height: 1.2; color: var(--ink-faint); padding: .3rem; overflow: hidden;
}
.cover img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .2s ease;
}
.cover img.ready { opacity: 1; }
.book-title { margin: 0; font-size: 1.08rem; letter-spacing: -.01em; }
.book-sub { margin: .1rem 0 0; color: var(--ink-soft); font-size: .92rem; }
.meta { margin: .4rem 0 0; color: var(--ink-faint); font-size: .78rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.meta span::after { content: "·"; margin-left: .4rem; color: var(--line); }
.meta span:last-child::after { content: ""; }

.recs { border-top: 1px solid var(--line); }
.rec { padding: .75rem .9rem; border-top: 1px solid var(--line); }
.rec:first-child { border-top: 0; }
.rec-who { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
a.who-name { color: inherit; text-decoration: none; }
a.who-name:hover { color: var(--accent); text-decoration: underline; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: .7rem; font-weight: 700;
}
.who-name { font-weight: 600; font-size: .93rem; }
.who-handle { color: var(--ink-faint); font-size: .82rem; margin-left: .35rem; font-weight: 400; }
.badge {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
  padding: .12rem .45rem; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-soft);
}
.badge.loved, .badge.liked { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.read { color: var(--ink-faint); }
.quote { margin: .4rem 0 0; color: var(--ink); font-size: .95rem; }
.quote::before { content: "“"; color: var(--ink-faint); }
.quote::after { content: "”"; color: var(--ink-faint); }
.context { margin: .3rem 0 0; color: var(--ink-faint); font-size: .78rem; }
.src { margin: .35rem 0 0; font-size: .78rem; }
.src a { color: var(--accent); text-decoration: none; }
.src a:hover { text-decoration: underline; }

/* --- people view: a compact directory of collapsed, tappable cards --- */
.person-head {
  display: flex; align-items: center; gap: .7rem; padding: .8rem .9rem;
  cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none;
}
.person-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.person-head .avatar { width: 40px; height: 40px; font-size: .9rem; flex-shrink: 0; align-self: flex-start; margin-top: .15rem; }
.person-info { min-width: 0; flex: 1; }
.person-name { margin: 0; font-size: 1.05rem; display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
.person-name .who-handle { text-decoration: none; }
.person-name a.who-handle:hover { text-decoration: underline; color: var(--accent); }
.person-bio { margin: .15rem 0 0; color: var(--ink-soft); font-size: .85rem; }
.person-summary { margin: .45rem 0 0; display: flex; flex-wrap: wrap; gap: .3rem; }
.chevron {
  color: var(--ink-faint); font-size: 1.3rem; line-height: 1;
  transition: transform .15s ease; flex-shrink: 0;
}
.person-card.open .chevron { transform: rotate(90deg); }
.person-card.open .person-head { border-bottom: 1px solid var(--line); }
.person-name a { color: inherit; text-decoration: none; }
.person-name a:hover { color: var(--accent); text-decoration: underline; }

/* --- dedicated person page (#p/<id>) --- */
.person-head.static { cursor: default; }
.person-head.static .person-head { border-bottom: 1px solid var(--line); }
.avatar.big { width: 52px; height: 52px; font-size: 1.1rem; }
.backlink { margin: .2rem 0 .8rem; }
.backlink a { color: var(--accent); text-decoration: none; font-size: .9rem; }
.backlink a:hover { text-decoration: underline; }

.empty { color: var(--ink-faint); text-align: center; padding: 2.5rem 0; }

/* On phones the sticky controls must stay short: tag chips collapse into one
   horizontally scrollable row instead of stacking under the segmented controls. */
@media (max-width: 640px) {
  .controls { padding-top: .7rem; }
  .controls .row { margin-top: .5rem; }
  .tags {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; width: 100%; padding-bottom: .15rem;
  }
  .tags::-webkit-scrollbar { display: none; }
  .tag { white-space: nowrap; flex-shrink: 0; }
}

footer { padding-bottom: 2.5rem; }
.foot { color: var(--ink-faint); font-size: .78rem; }
.foot code { background: var(--bg-sunk); padding: .1rem .35rem; border-radius: 5px; font-size: .95em; }
.problems { color: #b91c1c; font-size: .8rem; white-space: pre-wrap; }
