/* ================= Palettes =================
   Each palette sets the same colour tokens. The page's palette is chosen with data-theme on
   <html> (set from the reader's settings by theme.js); "auto" or none follows the device:
   Parchment by day, Lamplight in dark mode. Preview cards on the settings page carry
   data-theme too, so each one shows its own palette. */

:root {
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .28 0 0 0 0 .14 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --- Light --- */

/* Parchment: cream paper and oxblood ink (the original). */
:root, [data-theme="parchment"] {
  /* Reading status: to read, reading, finished, set aside */
  --status-to-read: #b5852a;
  --status-reading: #8a3b2a;
  --status-finished: #4a7a4c;
  --status-abandoned: #9b9285;
  color-scheme: light;
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --ink: #1f1b16;
  --ink-soft: #5c544a;
  --ink-faint: #8f877b;
  --rule: #e4dccd;
  --accent: #8a3b2a;
  --accent-ink: #fffdf8;
  --accent-soft: #f1e2d8;
  --accent-strong: #6f2c1e;
  --focus: #b5583f;
  --gold: #a7802f;
  --glow: rgba(255, 252, 243, 0.95);
  --topbar-bg: rgba(247, 243, 234, 0.86);
  --shadow-card: 0 1px 2px rgba(70, 45, 20, 0.05), 0 14px 34px -22px rgba(70, 45, 20, 0.38);
  --shadow-lift: 0 2px 4px rgba(70, 45, 20, 0.06), 0 22px 44px -22px rgba(70, 45, 20, 0.45);
}

/* Reading Room: green-shaded lamps on sage paper. */
[data-theme="reading-room"] {
  /* Reading status: to read, reading, finished, set aside */
  --status-to-read: #b5852a;
  --status-reading: #2e5b43;
  --status-finished: #9b3a5c;
  --status-abandoned: #959486;
  color-scheme: light;
  --bg: #f1f0e4;
  --surface: #fbfaf2;
  --ink: #1b2119;
  --ink-soft: #4b5548;
  --ink-faint: #7d8576;
  --rule: #d9d8c4;
  --accent: #2e5b43;
  --accent-ink: #fbfaf2;
  --accent-soft: #dde7d7;
  --accent-strong: #204331;
  --focus: #3f7a5a;
  --gold: #a07f2e;
  --glow: rgba(253, 252, 240, 0.95);
  --topbar-bg: rgba(241, 240, 228, 0.86);
  --shadow-card: 0 1px 2px rgba(35, 50, 30, 0.06), 0 14px 34px -22px rgba(35, 50, 30, 0.38);
  --shadow-lift: 0 2px 4px rgba(35, 50, 30, 0.07), 0 22px 44px -22px rgba(35, 50, 30, 0.45);
}

/* Fountain Pen: navy ink on ivory, crisp and quiet. */
[data-theme="fountain-pen"] {
  /* Reading status: to read, reading, finished, set aside */
  --status-to-read: #b5852a;
  --status-reading: #2c467a;
  --status-finished: #b0412e;
  --status-abandoned: #9a978f;
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fdfbf7;
  --ink: #1b1e29;
  --ink-soft: #4e5366;
  --ink-faint: #838898;
  --rule: #ded9cf;
  --accent: #2c467a;
  --accent-ink: #fdfbf7;
  --accent-soft: #e1e6f1;
  --accent-strong: #1e3260;
  --focus: #3d5d9c;
  --gold: #a9843a;
  --glow: rgba(255, 253, 247, 0.95);
  --topbar-bg: rgba(244, 241, 234, 0.86);
  --shadow-card: 0 1px 2px rgba(30, 35, 60, 0.05), 0 14px 34px -22px rgba(30, 35, 60, 0.36);
  --shadow-lift: 0 2px 4px rgba(30, 35, 60, 0.06), 0 22px 44px -22px rgba(30, 35, 60, 0.42);
}

/* --- Dark --- */

/* Lamplight: warm brown-black with terracotta (the original, after dark). */
[data-theme="lamplight"] {
  /* Reading status: to read, reading, finished, set aside */
  --status-to-read: #86aacb;
  --status-reading: #e0927a;
  --status-finished: #9cc48a;
  --status-abandoned: #8a8274;
  color-scheme: dark;
  --bg: #17140f;
  --surface: #211d17;
  --ink: #ece5d8;
  --ink-soft: #b3aa9c;
  --ink-faint: #7f776b;
  --rule: #3a342b;
  --accent: #e0927a;
  --accent-ink: #17140f;
  --accent-soft: #3a2620;
  --accent-strong: #eba48e;
  --focus: #e0927a;
  --gold: #cfa95a;
  --glow: rgba(224, 146, 122, 0.07);
  --topbar-bg: rgba(23, 20, 15, 0.82);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 36px -22px rgba(0, 0, 0, 0.7);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.35), 0 24px 48px -22px rgba(0, 0, 0, 0.8);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]), :root[data-theme="auto"] {
    /* Reading status: to read, reading, finished, set aside */
    --status-to-read: #86aacb;
    --status-reading: #e0927a;
    --status-finished: #9cc48a;
    --status-abandoned: #8a8274;
    color-scheme: dark;
    --bg: #17140f;
    --surface: #211d17;
    --ink: #ece5d8;
    --ink-soft: #b3aa9c;
    --ink-faint: #7f776b;
    --rule: #3a342b;
    --accent: #e0927a;
    --accent-ink: #17140f;
    --accent-soft: #3a2620;
    --accent-strong: #eba48e;
    --focus: #e0927a;
    --gold: #cfa95a;
    --glow: rgba(224, 146, 122, 0.07);
    --topbar-bg: rgba(23, 20, 15, 0.82);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 36px -22px rgba(0, 0, 0, 0.7);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.35), 0 24px 48px -22px rgba(0, 0, 0, 0.8);
  }
}

/* Midnight Study: blue-black with brass, for late reading. */
[data-theme="midnight-study"] {
  /* Reading status: to read, reading, finished, set aside */
  --status-to-read: #8db6d9;
  --status-reading: #d6b26a;
  --status-finished: #9cc48a;
  --status-abandoned: #7d858d;
  color-scheme: dark;
  --bg: #11151a;
  --surface: #192027;
  --ink: #e8e3d8;
  --ink-soft: #aab0b5;
  --ink-faint: #757d85;
  --rule: #2b343d;
  --accent: #d6b26a;
  --accent-ink: #11151a;
  --accent-soft: #2d2a21;
  --accent-strong: #e6c78a;
  --focus: #d6b26a;
  --gold: #86aac0;
  --glow: rgba(214, 178, 106, 0.06);
  --topbar-bg: rgba(17, 21, 26, 0.82);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 16px 36px -22px rgba(0, 0, 0, 0.75);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.4), 0 24px 48px -22px rgba(0, 0, 0, 0.85);
}

/* Old Port: plum and claret, like a club room after hours. */
[data-theme="old-port"] {
  /* Reading status: to read, reading, finished, set aside */
  --status-to-read: #8fb2d8;
  --status-reading: #e39aa6;
  --status-finished: #a6c88e;
  --status-abandoned: #8f7f84;
  color-scheme: dark;
  --bg: #1a1215;
  --surface: #25191f;
  --ink: #f0e4e1;
  --ink-soft: #bfa9ab;
  --ink-faint: #8b737a;
  --rule: #3d2a32;
  --accent: #e39aa6;
  --accent-ink: #1a1215;
  --accent-soft: #3f242c;
  --accent-strong: #efb5be;
  --focus: #e39aa6;
  --gold: #cfa763;
  --glow: rgba(227, 154, 166, 0.07);
  --topbar-bg: rgba(26, 18, 21, 0.82);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.32), 0 16px 36px -22px rgba(0, 0, 0, 0.72);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.38), 0 24px 48px -22px rgba(0, 0, 0, 0.82);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  /* Faint paper grain, and a little more light at the top of the page. */
  background-image: var(--grain), radial-gradient(ellipse 90% 420px at 50% -80px, var(--glow), transparent 70%);
  background-repeat: repeat, no-repeat;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

input, select, textarea, button { font: inherit; color: var(--ink); }

input, select {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--surface);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--ink-faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 6px 16px -8px var(--accent);
}
.btn-primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
.btn-large { padding: 11px 20px; font-size: 15px; border-radius: 8px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-quiet { border-color: transparent; background: none; color: var(--ink-soft); }
.btn-quiet:hover { color: var(--accent); border-color: transparent; }

.link-btn {
  border: none;
  background: none;
  padding: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.stars { color: var(--accent); letter-spacing: 1px; font-size: 13px; white-space: nowrap; }
.stars-off { color: var(--rule); }

.shelf-hint { margin: 0; font-size: 13px; color: var(--ink-faint); }

/* Checkbox chip used in shelf pickers */
.pick { display: inline-flex; margin: 0 6px 6px 0; cursor: pointer; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick span {
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-soft);
}
.pick span::before { content: "+ "; color: var(--ink-faint); }
.pick input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.pick input:checked + span::before { content: "✓ "; color: var(--accent); }
.pick input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.chip {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  background: var(--surface);
  white-space: nowrap;
}

.field-label, .section-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
}
/* Section headings read like a running head: small caps, then a hairline to the edge. */
.section-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.shelves-head .section-label { flex: 1; margin-right: 16px; }


.empty { text-align: center; padding: 56px 16px; color: var(--ink-soft); }
.empty p { margin: 0 0 14px; font-family: var(--serif); font-size: 20px; color: var(--ink); }
.empty .empty-sub, .empty-sub { font-family: var(--sans); font-size: 14px; color: var(--ink-soft); max-width: 44ch; margin-inline: auto; }
.page-error { max-width: 1120px; margin: 0 auto; }

/* ---------- Top bar ---------- */
/* Full-width and sticky; the side padding lines its contents up with the 1120px page column. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px max(16px, calc((100% - 1088px) / 2));
  background: var(--topbar-bg);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}
/* The wordmark gets a short accent rule in front of it, like a note in a margin. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.brand::before {
  content: "";
  width: 3px;
  height: 1.05em;
  border-radius: 2px;
  background: linear-gradient(var(--accent), var(--gold));
}
/* Quick add */
.quick-add { position: relative; margin-left: auto; width: min(380px, 100%); }
.quick-add input { width: 100%; }
.qa-results {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: min(460px, calc(100vw - 32px));
  max-height: min(520px, 70vh);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px -18px rgba(0, 0, 0, 0.4);
}
.qa-hint { margin: 0; padding: 10px 14px 6px; font-size: 12px; color: var(--ink-faint); }
.qa-status { margin: 0; padding: 18px 14px; font-size: 14px; color: var(--ink-soft); }
.qa-error { color: var(--accent); }
.qa-list { list-style: none; margin: 0; padding: 0; }
.qa-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--rule);
}
.qa-item:hover { background: var(--bg); }
.qa-thumb .cover-face > * { visibility: hidden; }
.qa-thumb .cover-img { box-shadow: none; }
.qa-title { font-family: var(--serif); font-size: 16px; font-weight: 500; line-height: 1.25; }
.qa-meta { font-size: 12px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qa-ready { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--accent); margin-top: 2px; }
.qa-manual {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-top: 1px solid var(--rule);
  background: none;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
}
.qa-manual:hover { background: var(--bg); }

/* ---------- Generated cover (scales to its container) ---------- */
.cover {
  container-type: inline-size;
  aspect-ratio: 2 / 3;
  width: 100%;
  position: relative;
}
.cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 3px 6px 6px 3px;
  box-shadow: 0 10px 24px -14px rgba(0, 0, 0, 0.5);
  z-index: 1;
}
.cover-face {
  height: 100%;
  background: var(--cover-bg);
  color: var(--cover-fg);
  border-radius: 3px 6px 6px 3px;
  padding: 11cqw 9cqw;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-shadow: inset 2.5cqw 0 0 rgba(0, 0, 0, 0.18), 0 10px 24px -14px rgba(0, 0, 0, 0.5);
  font-family: var(--serif);
}
.c-title { font-size: 12cqw; line-height: 1.05; font-weight: 500; overflow-wrap: break-word; hyphens: auto; }
.c-sub { font-style: italic; font-size: 5.5cqw; margin-top: 4cqw; opacity: 0.85; }
.c-rule { width: 16cqw; height: 1px; background: currentColor; opacity: 0.5; margin-top: 7cqw; }
.c-author { font-family: var(--sans); font-size: 4.6cqw; letter-spacing: 0.16em; text-transform: uppercase; line-height: 1.3; }

/* ================= Home ================= */
.home { max-width: 1120px; margin: 0 auto; padding: 48px 16px 96px; }
.home-head { margin-bottom: 48px; }
.home-head h1 { font-size: clamp(38px, 5.5vw, 60px); }
.home-stats { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 16px 0 0; font-size: 14px; color: var(--ink-soft); }
.home-stats strong { font-family: var(--serif); font-size: 20px; font-weight: 500; color: var(--ink); margin-right: 4px; }
.home-stats a { color: var(--accent); }
.home-section { margin-bottom: 56px; }
.home-section-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.home-section-head .section-label { flex: 1; margin: 0; }
.home-section-head .link-btn { font-size: 13px; text-decoration: none; }

.home-clubs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr)); gap: 20px; }
.home-club {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 26px;
  padding: 24px;
  background: linear-gradient(135deg, var(--surface) 35%, color-mix(in srgb, var(--accent-soft) 50%, var(--surface)));
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}
.home-club-cover .cover { transform: rotate(-1.5deg); }
.home-club-cover .cover-img, .home-club-cover .cover-face { box-shadow: 0 18px 32px -16px rgba(40, 20, 5, 0.55); }
.home-club-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.home-club-name { margin: 0; text-decoration: none; }
.home-club-name:hover { text-decoration: underline; }
.home-club h3 { font-family: var(--serif); font-size: 26px; font-weight: 500; line-height: 1.15; margin: 0; }
.home-club-author { margin: -6px 0 6px; font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--ink-soft); }
.home-club .meter-label { margin: 4px 0 6px; }
.home-club-actions { margin-top: 8px; }
.home-club-idle { display: flex; flex-direction: column; gap: 8px; text-decoration: none; }
.home-club-idle .kicker { margin: 0; }
.home-club-empty { margin: 0; font-family: var(--serif); font-size: 20px; }
.home-invite { border: 1px dashed var(--rule); border-radius: 16px; padding: 32px 24px; text-align: center; }
.home-invite p:first-child { margin: 0 0 8px; font-family: var(--serif); font-size: 22px; }
.home-invite .empty-sub { margin-bottom: 18px; }
.now-body .meter-label { margin: auto 0 6px; font-size: 12px; }

.shelf-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 24px; }

/* ================= Library page ================= */
.library { max-width: 1120px; margin: 0 auto; padding: 40px 16px 80px; }

.library-head { margin-bottom: 36px; }
.library-head h1 { margin-bottom: 6px; }
.stats { margin: 0; color: var(--ink-soft); font-size: 14px; }

/* Currently reading */
.now-reading { margin-bottom: 48px; }
.now-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 16px; }
.now-card {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 18px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.2s, transform 0.2s;
}
.now-card:hover { border-color: var(--ink-faint); box-shadow: var(--shadow-lift); transform: translateY(-2px); }
.now-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.now-title { font-family: var(--serif); font-size: 19px; font-weight: 500; line-height: 1.2; }
.now-author { font-size: 13px; color: var(--ink-soft); margin-bottom: auto; }
.now-extras { display: flex; gap: 12px; font-size: 12px; color: var(--ink-faint); }
.now-extras:empty { display: none; }

/* Shelves */
.shelves-bar { margin-bottom: 40px; }
.shelves-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.shelves-head .section-label { margin: 0; }
.shelf-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.shelf-tab {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}
.shelf-tab:hover { color: var(--ink); border-color: var(--ink-faint); }
.shelf-tab[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.shelf-tab .count { font-size: 12px; opacity: 0.65; margin-left: 2px; }
.shelf-tabs .shelf-hint { margin-left: 6px; }

.shelf-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 16px; }
.shelf-title h2 { margin: 0; font-size: 30px; }
.shelf-count { color: var(--ink-faint); font-size: 14px; }
.shelf-actions { margin-left: auto; align-self: center; }

/* Small dropdown menu */
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  min-width: 170px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
}
.menu button {
  text-align: left;
  border: none;
  background: none;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.menu button, .menu a { color: var(--ink); text-decoration: none; }
.menu a { padding: 8px 10px; border-radius: 6px; font-size: 14px; }
.menu button:hover, .menu button:focus-visible, .menu a:hover, .menu a:focus-visible { background: var(--bg); outline: none; }
.menu button.danger { color: var(--accent); }
.menu-label { margin: 0 0 4px; padding: 6px 10px 8px; border-bottom: 1px solid var(--rule); font-size: 13px; font-weight: 600; }
.menu-label span { display: block; font-weight: 400; color: var(--ink-faint); font-size: 12px; }

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  align-self: center;
  margin-left: -6px;
  transition: border-color 0.15s, background 0.15s;
}
.icon-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.icon-btn-plain { margin-left: 0; color: var(--ink-soft); }
.icon-btn-plain:hover, .icon-btn-plain[aria-expanded="true"] { color: var(--ink); border-color: var(--ink-faint); background: var(--surface); }

.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* Picker for adding existing books to a shelf */
.pick-search { width: 100%; margin-bottom: 12px; }
.pick-list {
  max-height: min(420px, 55vh);
  overflow-y: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
}
.pick-row {
  display: grid;
  grid-template-columns: 18px 32px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.pick-row:last-child { border-bottom: none; }
.pick-row:hover { background: var(--bg); }
.pick-row:has(input:checked) { background: var(--accent-soft); }
.pick-row input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.pick-row .row-title { font-size: 16px; }
.pick-empty { padding: 24px 16px; text-align: center; }
.pick-summary { margin-right: auto; align-self: center; font-size: 13px; color: var(--ink-faint); }

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
}
.toolbar input[type="search"] { flex: 1 1 220px; }
.toolbar-end { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
  max-width: 100%;
  overflow-x: auto;
}
.segmented button {
  border: none;
  background: none;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.segmented button + button { border-left: 1px solid var(--rule); }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 500; }
.segmented .count { color: var(--ink-faint); font-size: 12px; margin-left: 2px; }

.result-count { font-size: 13px; color: var(--ink-faint); margin: 12px 0 0; min-height: 20px; }

/* Grid view */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 36px 28px;
  margin-top: 16px;
}
.book-card { text-decoration: none; display: flex; flex-direction: column; min-width: 0; }
.book-card .cover { transition: transform 0.15s; }
.book-card .cover { transition: transform 0.2s; }
.book-card:hover .cover { transform: translateY(-4px) rotate(-0.4deg); }
.card-title { font-family: var(--serif); font-size: 17px; font-weight: 500; line-height: 1.25; margin-top: 14px; }

/* Reading status: a coloured rule down the side of a book's title, author and status, and a
   matching dot on the status filter (and the list view's status column). Set aside is dashed,
   so it doesn't rely on colour alone. */
[data-status="to-read"] { --status-color: var(--status-to-read); }
[data-status="reading"] { --status-color: var(--status-reading); }
[data-status="finished"] { --status-color: var(--status-finished); }
[data-status="abandoned"] { --status-color: var(--status-abandoned); }
.card-text { margin-top: 14px; padding: 1px 0 2px 11px; border-left: 3px solid var(--status-color); }
.card-text .card-title { margin-top: 0; }
.card-text .card-rating { margin-top: 6px; }
.card-text .status-line { margin-top: 6px; }
.book-row .row-main { padding: 2px 0 2px 12px; border-left: 3px solid var(--status-color); }
[data-status="abandoned"].card-text, .book-row .row-main[data-status="abandoned"] { border-left-style: dashed; }
.book-row .status-line[data-status]::before,
.segmented button[data-status]:not([data-status="all"])::before {
  content: "";
  flex: none;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-color);
}
.segmented button[data-status]::before { margin-right: 7px; vertical-align: 1px; }
.book-row .status-line[data-status="abandoned"]::before,
.segmented button[data-status="abandoned"]::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--status-color); }
.card-author { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.card-rating { margin-top: 4px; line-height: 1; }
.status-line { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-style: italic; font-size: 14px; color: var(--ink-soft); margin-top: 8px; }

/* List view */
.book-list { margin-top: 8px; }
.book-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 2fr) minmax(0, 1.5fr) 80px 150px;
  align-items: center;
  gap: 20px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}
.book-row:hover { background: var(--surface); }
.row-cover .cover-face { box-shadow: inset 2.5cqw 0 0 rgba(0, 0, 0, 0.18); }
/* Thumbnails are too small to read: show a plain spine colour. */
.row-cover .cover-face > * { visibility: hidden; }
.row-title { font-family: var(--serif); font-size: 17px; font-weight: 500; line-height: 1.25; }
.row-author { font-size: 13px; color: var(--ink-soft); }
.row-shelves { display: flex; flex-wrap: wrap; gap: 6px; overflow: hidden; max-height: 26px; }
.row-status { margin-top: 0; }

/* Add dialog */
.add-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  padding: 28px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.5);
}
.add-dialog::backdrop { background: rgba(20, 16, 10, 0.45); }
.add-dialog h2 { margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid.one-col { grid-template-columns: 1fr; }
.small-dialog { width: min(420px, calc(100vw - 32px)); }
.shelf-picks { border: none; padding: 0; margin: 4px 0 0; min-width: 0; }
.shelf-picks legend { font-size: 13px; font-weight: 500; color: var(--ink-soft); padding: 0; margin-bottom: 8px; }
.form-error { color: var(--accent); font-size: 13px; min-height: 20px; margin: 12px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.duplicate-notice {
  margin-top: 16px;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  font-size: 14px;
}
.duplicate-notice p { margin: 0 0 6px; }
.duplicate-sub { color: var(--ink-soft); font-size: 13px; }
.duplicate-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ================= Book page ================= */
.book-page {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 56px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 16px 80px;
}

.record { display: flex; flex-direction: column; gap: 24px; position: sticky; top: calc(var(--topbar-h, 60px) + 24px); align-self: start; }
.record #cover .cover-img, .record #cover .cover-face { box-shadow: 0 22px 40px -20px rgba(40, 20, 5, 0.55); }

.status-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.status-card select { background: var(--bg); }
.label-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--ink-soft); }

.meta { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.meta dt { color: var(--ink-faint); }
.meta dd { margin: 0; color: var(--ink-soft); }

/* Rating input: hovering lights every star up to the pointer. */
.rating-block { margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 4px; }
.star-input { display: flex; gap: 2px; }
.star-input button {
  border: none;
  background: none;
  padding: 0 2px;
  font-size: 26px;
  line-height: 1;
  color: var(--rule);
  cursor: pointer;
  transition: color 0.1s, transform 0.1s;
}
.star-input button.on { color: var(--accent); }
.star-input:hover button { color: var(--accent); }
.star-input button:hover ~ button { color: var(--rule); }
.star-input button:hover { transform: scale(1.12); }

.shelf-box { display: flex; flex-direction: column; gap: 10px; }
.shelves { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-removable { display: inline-flex; align-items: center; gap: 4px; padding-right: 4px; }
.chip-removable a { text-decoration: none; }
.chip-removable a:hover { color: var(--accent); }
.chip-removable button {
  border: none;
  background: none;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
}
.chip-removable button:hover { color: var(--accent); }
.shelf-picker {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 14px 8px;
}
.shelf-picker .shelf-hint { margin-bottom: 10px; }
.shelf-create { display: flex; gap: 6px; margin-top: 6px; }
.shelf-create input { flex: 1; padding: 5px 8px; font-size: 13px; background: var(--bg); }
.shelf-picker .form-error { margin-top: 6px; min-height: 0; }

.title-block { margin-bottom: 32px; position: relative; padding-right: 44px; }
.title-actions { position: absolute; top: 0; right: 0; }

.form-grid textarea { min-height: 72px; font-size: 14px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Cover picker in the edit dialog */
.cover-picker { border: none; padding: 0; margin: 0 0 20px; min-width: 0; }
.cover-picker legend { font-size: 13px; font-weight: 500; color: var(--ink-soft); padding: 0; margin-bottom: 8px; }
.cover-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 10px;
  max-height: 232px;
  overflow-y: auto;
  padding: 4px;
  margin: -4px;
}
.cover-tile {
  padding: 0;
  border: none;
  background: none;
  border-radius: 6px;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.1s, transform 0.1s;
}
.cover-tile:hover { transform: translateY(-2px); }
.cover-tile[aria-pressed="true"] { outline-color: var(--accent); }
.cover-tile:focus-visible { outline-color: var(--focus); }
.cover-tile .cover-face > * { visibility: hidden; }
.cover-tile .cover-face { box-shadow: inset 2.5cqw 0 0 rgba(0, 0, 0, 0.18); }
.cover-tile .cover-img { box-shadow: none; }
.cover-upload { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.cover-upload .btn { position: relative; }
.cover-upload .btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.form-grid .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.form-grid .check input { accent-color: var(--accent); }
.kicker { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); font-weight: 600; margin: 0 0 8px; min-height: 1px; }
h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(36px, 5vw, 56px); line-height: 1.05; margin: 0; letter-spacing: -0.01em; }
.byline { font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--ink-soft); margin: 8px 0 0; }
.blurb { font-family: var(--serif); font-size: 18px; line-height: 1.55; color: var(--ink); max-width: 62ch; margin: 20px 0 0; }
.blurb:empty { display: none; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--rule); margin-bottom: 32px; }
.tabs button {
  font-weight: 500;
  color: var(--ink-faint);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  margin-bottom: -1px;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.badge { font-size: 11px; color: var(--ink-faint); font-weight: 400; margin-left: 4px; }

.panel { max-width: 68ch; }

/* Primer */
/* Flex rather than grid so the cells on a short last row stretch to fill it. */
.glance {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0 0 40px;
}
.glance div { flex: 1 1 180px; background: var(--surface); padding: 14px 16px; }
.glance dt { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; margin-bottom: 4px; }
.glance dd { margin: 0; font-family: var(--serif); font-size: 16px; }

/* Contents bar: sticks under the top bar while reading, with the current section underlined. */
.primer-toc {
  position: sticky;
  top: var(--topbar-h, 60px);
  z-index: 5;
  display: flex;
  gap: 4px 20px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 0 36px;
  padding: 12px 0;
  font-size: 13px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.primer-toc::-webkit-scrollbar { display: none; }
.primer-toc a { flex: none; color: var(--ink-soft); text-decoration: none; padding-bottom: 2px; border-bottom: 2px solid transparent; white-space: nowrap; }
.primer-toc a:hover { color: var(--ink); }
.primer-toc a[aria-current] { color: var(--accent); border-bottom-color: var(--accent); }

.primer-section { margin-bottom: 44px; scroll-margin-top: calc(var(--topbar-h, 60px) + 64px); }
/* A drop cap opens each primer section. */
.primer-section > h2 + p::first-letter {
  float: left;
  font-size: 3.3em;
  line-height: 0.82;
  padding: 6px 8px 0 0;
  color: var(--accent);
  font-weight: 500;
}
h2 { font-family: var(--serif); font-weight: 500; font-size: 26px; margin: 0 0 12px; }
.primer-section p { font-family: var(--serif); font-size: 18px; line-height: 1.65; margin: 0 0 14px; }

.cast { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--rule); }
.cast li { display: grid; grid-template-columns: 180px 1fr; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.cast strong { font-family: var(--serif); font-weight: 600; font-size: 16px; }
.cast span { color: var(--ink-soft); font-size: 14px; }

.empty code { font-size: 13px; background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: 1px 5px; }
.empty .form-error { margin: 0 auto 14px; max-width: 48ch; }

.generating .spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 18px;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .generating .spinner { animation-duration: 3s; } }

.primer-caveat {
  margin: 0 0 28px;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  font-size: 14px;
  color: var(--ink-soft);
}
.primer-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 14px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 12px;
  color: var(--ink-faint);
}
.primer-foot .form-error { width: 100%; margin: 0; }

/* Questions */
.stage-count { font-weight: 400; letter-spacing: 0.04em; margin-left: 6px; text-transform: none; }
.spoiler-gate {
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: center;
  color: var(--ink-soft);
}
.spoiler-gate p { margin: 0 0 12px; font-size: 14px; }
.companion-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 36px; }
.companion-progress { flex: 1; max-width: 420px; }
.companion-intro { color: var(--ink-soft); margin: 12px 0 0; font-size: 14px; }
.stage { margin-bottom: 36px; }
.stage h3 { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; margin: 0 0 14px; }
.question {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  margin-bottom: 12px;
}
.question { transition: border-color 0.2s; }
.question.answered { border-left: 3px solid var(--accent); }
.question:focus-within { border-color: var(--ink-faint); }
.q-head { display: flex; gap: 14px; align-items: baseline; margin-bottom: 14px; }
.q-num { flex: none; font-family: var(--serif); font-size: 15px; font-style: italic; color: var(--accent); min-width: 22px; }
.question p { font-family: var(--serif); font-size: 18px; line-height: 1.5; margin: 0; }
/* Answers are written on faintly ruled paper. */
textarea.lined {
  --line: 28px;
  line-height: var(--line);
  padding: 4px 12px;
  min-height: calc(var(--line) * 3 + 10px);
  background-color: var(--bg);
  background-image: repeating-linear-gradient(transparent 0, transparent calc(var(--line) - 1px), color-mix(in srgb, var(--rule) 70%, transparent) calc(var(--line) - 1px), color-mix(in srgb, var(--rule) 70%, transparent) var(--line));
  background-position: 0 4px;
  background-attachment: local;
  font-family: var(--serif);
  font-size: 17px;
}
.q-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 24px; margin-top: 6px; }
.q-foot .saved { margin: 0; }
.q-foot .link-btn { font-size: 13px; }
textarea {
  width: 100%;
  min-height: 84px;
  font-size: 15px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 10px 12px;
  resize: vertical;
}
.saved { font-size: 12px; color: var(--ink-faint); margin-top: 6px; min-height: 18px; transition: color 0.3s; }
.saved.flash { color: var(--accent); }

/* Notes */
.note-form { display: grid; grid-template-columns: 90px 1fr auto; gap: 8px; margin-bottom: 28px; }
.note { display: grid; grid-template-columns: 56px 1fr 28px; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--rule); }
.note .pg { font-size: 12px; color: var(--ink-faint); padding-top: 4px; }
.note blockquote { margin: 0; font-family: var(--serif); font-style: italic; font-size: 18px; line-height: 1.55; border-left: 2px solid var(--accent); padding-left: 14px; }
.note .plain { margin: 0; font-size: 15px; color: var(--ink-soft); }
.note-body { min-width: 0; }
.note-talk { margin-top: 8px; font-size: 12px; opacity: 0; transition: opacity 0.15s; }
.note:hover .note-talk, .note-talk:focus-visible { opacity: 1; }
.note-delete {
  border: none;
  background: none;
  color: var(--ink-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  align-self: start;
}
.note:hover .note-delete, .note-delete:focus-visible { opacity: 1; }
.note-delete:hover { color: var(--accent); }

/* ================= Navigation and account ================= */
.mainnav { display: flex; gap: 4px; }
.mainnav a {
  position: relative;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--ink-soft);
  text-decoration: none;
}
.mainnav a:hover { color: var(--ink); background: var(--surface); }
.mainnav a[aria-current="page"] { color: var(--ink); font-weight: 500; }
.mainnav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -13px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.account { margin-left: auto; }
.quick-add + .account { margin-left: 12px; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.avatar:hover, .avatar[aria-expanded="true"] { border-color: var(--accent); }
.account .menu { min-width: 220px; }

/* ================= Sign in ================= */
.auth-page { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; padding: 10vh 16px 40px; }
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow-lift);
  padding: 32px 28px;
}
.auth-brand { display: block; font-size: 28px; margin: 0; }
.auth-tagline { color: var(--ink-soft); font-family: var(--serif); font-style: italic; font-size: 17px; line-height: 1.4; margin: 8px 0 24px; }
.auth-notice { background: var(--accent-soft); border-radius: 8px; padding: 10px 14px; font-size: 14px; margin: 0 0 20px; }
.auth-tabs { display: flex; margin-bottom: 20px; }
.auth-tabs button { flex: 1; }
.auth-submit { width: 100%; margin-top: 6px; padding: 10px; }
.auth-foot { font-size: 13px; color: var(--ink-faint); margin: 18px 0 0; }
.label-hint { font-weight: 400; color: var(--ink-faint); }
.form-grid input { width: 100%; }

/* ================= Welcome (sign in) ================= */
/* The left panel keeps its own warm, dark colours in both themes, like a book's endpaper. */
.welcome {
  --panel-pad: clamp(32px, 5vw, 72px);
  --panel-ink: #f1e6d6;
  --panel-soft: #cdbba5;
  --panel-faint: #a8937c;
  --panel-gold: #d6b06a;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  min-height: 100vh;
}
.welcome-panel {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 48px var(--panel-pad) 0;
  color: var(--panel-ink);
  background-color: #2b1915;
  background-image:
    var(--grain),
    radial-gradient(circle at 12% 8%, rgba(224, 146, 122, 0.2), transparent 48%),
    radial-gradient(circle at 92% 78%, rgba(214, 176, 106, 0.14), transparent 45%);
}
.welcome-brand { margin: 0; font-size: 26px; }
.welcome-brand::before { background: linear-gradient(#e0927a, var(--panel-gold)); }
.welcome-headline {
  margin: clamp(40px, 10vh, 120px) 0 36px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(42px, 4.8vw, 68px);
  line-height: 1.02;
  letter-spacing: -0.015em;
}
.welcome-headline em { color: #e9b08f; }

.welcome-quote { margin: 0 0 40px; max-width: 46ch; min-height: 8em; transition: opacity 0.6s, transform 0.6s; }
.welcome-quote.fading { opacity: 0; transform: translateY(6px); }
.welcome-quote blockquote {
  margin: 0;
  padding-left: 18px;
  border-left: 2px solid var(--panel-gold);
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  line-height: 1.5;
}
.welcome-quote figcaption {
  margin-top: 12px;
  padding-left: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--panel-faint);
}

.welcome-features { list-style: none; margin: 0 0 48px; padding: 0; display: grid; gap: 18px; max-width: 46ch; }
.welcome-features li { display: flex; gap: 14px; font-size: 14px; line-height: 1.5; color: var(--panel-soft); }
.welcome-features strong { display: block; font-family: var(--serif); font-size: 17px; font-weight: 500; color: var(--panel-ink); }
.feature-mark {
  flex: none;
  width: 30px;
  height: 30px;
  margin-top: 1px;
  border-radius: 50%;
  border: 1px solid rgba(214, 176, 106, 0.5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--panel-gold);
}

/* A drawn bookshelf along the bottom of the panel. */
.shelf {
  margin: auto calc(-1 * var(--panel-pad)) 0;
  padding: 0 var(--panel-pad);
  height: 210px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  border-bottom: 14px solid #4a2c1d;
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.04) inset;
}
.spine {
  flex: none;
  width: 40px;
  height: var(--h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
  overflow: hidden;
  writing-mode: vertical-rl;
  white-space: nowrap;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--t, var(--panel-ink));
  border-radius: 3px 3px 0 0;
  border-top: 3px double rgba(214, 176, 106, 0.55);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.28), transparent 18%, rgba(255, 255, 255, 0.1) 45%, transparent 62%, rgba(0, 0, 0, 0.3)),
    var(--c);
  box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.5);
}
.spine.thin { width: 30px; font-size: 11px; }
.spine.lean { margin-left: 22px; transform-origin: bottom left; transform: rotate(-9deg); }
.bookend { flex: none; width: 14px; height: 46%; margin-left: 8px; border-radius: 2px 8px 0 0; background: var(--panel-gold); opacity: 0.85; }

.welcome-main { display: flex; align-items: center; justify-content: center; padding: 56px 24px; }
.welcome-card { width: min(400px, 100%); }
.welcome-title { font-size: clamp(36px, 4vw, 46px); }
.welcome-sub { margin: 10px 0 28px; color: var(--ink-soft); font-size: 15px; }
.welcome-card .auth-notice { margin-bottom: 24px; }
.welcome-card .form-grid input { padding: 11px 12px; }
.welcome-card .auth-submit { margin-top: 8px; padding: 12px; }
.welcome-card .auth-foot { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--rule); }

@media (max-width: 860px) {
  .welcome { grid-template-columns: 1fr; }
  .welcome-panel { padding-top: 24px; }
  .welcome-headline { margin: 18px 0 20px; font-size: 36px; }
  .welcome-quote, .welcome-features { display: none; }
  .shelf { height: 96px; gap: 3px; border-bottom-width: 10px; }
  .spine { width: 24px; padding: 8px 0; font-size: 9px; }
  .spine.thin { width: 18px; font-size: 8px; }
  .spine.lean { margin-left: 12px; }
  .welcome-main { align-items: flex-start; padding: 32px 20px 56px; }
}

/* ================= Clubs ================= */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.club-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.club-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  text-decoration: none;
}
.club-card { box-shadow: var(--shadow-card); transition: border-color 0.15s, box-shadow 0.2s, transform 0.2s; }
.club-card:hover { border-color: var(--ink-faint); box-shadow: var(--shadow-lift); transform: translateY(-2px); }
.club-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.club-card h2 { margin: 0; font-size: 22px; }
.club-meta { margin: 0; font-size: 13px; color: var(--ink-faint); }
.club-pick { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center; margin-top: 8px; }
.club-pick .section-label { margin: 0 0 2px; font-family: var(--sans); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; color: var(--ink-faint); }
.club-pick .section-label::after { display: none; }
.join-box { margin-top: 48px; max-width: 520px; }
.join-form { display: flex; gap: 8px; }
.join-form input { flex: 1; }

.club-page { max-width: 1120px; margin: 0 auto; padding: 40px 16px 80px; }
.club-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 36px; }
.club-head-actions { display: flex; align-items: center; gap: 10px; }
.club-head-actions .icon-btn { margin-left: 0; }
.club-byline { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.club-byline .stats { margin: 0; }
.club-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 56px; align-items: start; }
.club-side { display: flex; flex-direction: column; gap: 20px; }

/* Member initials: overlapped in the header, one per row in the member list. */
.avatar-stack { display: flex; }
.avatar-stack:empty { display: none; }
.mini-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: var(--accent-soft);
  border: 2px solid var(--bg);
}
.mini-avatar:nth-child(3n + 2) { background: color-mix(in srgb, var(--gold) 26%, var(--surface)); }
.mini-avatar:nth-child(3n + 3) { background: color-mix(in srgb, var(--ink-faint) 24%, var(--surface)); }
.avatar-stack .mini-avatar + .mini-avatar { margin-left: -9px; }
.mini-avatar.more { background: var(--surface); color: var(--ink-soft); font-weight: 500; font-size: 11px; }

/* The book the club is reading now */
.club-now { margin-bottom: 56px; }
.hero-card {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 44px;
  padding: 36px;
  background: linear-gradient(135deg, var(--surface) 30%, color-mix(in srgb, var(--accent-soft) 55%, var(--surface)));
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}
/* A printer's flourish, very faint, in the corner. */
.hero-card::after {
  content: "\201C";
  position: absolute;
  right: 36px;
  bottom: -150px;
  font-family: var(--serif);
  font-size: 340px;
  line-height: 1;
  color: var(--accent);
  opacity: 0.06;
  pointer-events: none;
}
.hero-cover { align-self: start; }
.hero-cover .cover { transform: rotate(-1.5deg); }
.hero-cover .cover-img, .hero-cover .cover-face { box-shadow: 0 24px 40px -18px rgba(40, 20, 5, 0.55); }
.hero-body { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.hero-body h3 { font-family: var(--serif); font-weight: 500; font-size: clamp(30px, 4vw, 44px); line-height: 1.08; margin: 0; letter-spacing: -0.01em; }
.pick-meta { color: var(--ink-soft); margin: 8px 0 0; font-size: 14px; }
.pick-author { font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--ink); }
.hero-due, .hero-progress { max-width: 460px; }
.hero-progress.muted { margin: 0; font-size: 14px; color: var(--ink-soft); }
.hero-body .pick-status { margin: 0; }
.hero-body .pick-actions { margin-top: 2px; }
.hero-body .buy-links { margin-top: -6px; }

.meter-label { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }
.meter { height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--rule) 80%, transparent); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.5s ease; }
.meter-time span { background: var(--gold); }
.due-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.due-pill.soon { background: color-mix(in srgb, var(--gold) 20%, var(--surface)); border-color: color-mix(in srgb, var(--gold) 55%, var(--rule)); }
.due-pill.late { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Up next and past books, as covers */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 36px 24px; }
.pick-grid-past { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 28px 20px; }
.pick-grid-past .tile-title { font-size: 15px; }
.pick-tile { display: flex; flex-direction: column; min-width: 0; }
.tile-cover { position: relative; margin-bottom: 14px; }
.tile-cover .pick-gear { position: absolute; top: 6px; right: 6px; z-index: 2; }
.tile-cover .icon-btn { background: var(--surface); box-shadow: var(--shadow-card); }
.tile-title { font-family: var(--serif); font-size: 17px; font-weight: 500; line-height: 1.25; }
.tile-author { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.tile-date { font-size: 12px; color: var(--ink-faint); margin-top: 6px; }
.pick-tile .buy-links.compact { margin-top: 6px; }
.pick-tile .pick-status { font-size: 12px; margin: 6px 0 0; }
.pick-tile .pick-status + .btn { margin-top: 8px; align-self: flex-start; }
.tile-actions { margin-top: 10px; }

.side-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}
.organizer-card { background: transparent; border-style: dashed; box-shadow: none; }
.pick-status { font-size: 14px; color: var(--ink-soft); margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.pick-status.ready { color: var(--accent); font-weight: 500; }
.pick-status.ready::before { content: "✓"; }
.pick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pick-empty { border: 1px dashed var(--rule); border-radius: 16px; padding: 48px 16px; }
.spinner-inline {
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.pick-search input { width: 100%; }
.pick-results { margin-top: 8px; border-radius: var(--radius); overflow: hidden; }
.pick-results .qa-item { background: var(--surface); }
.club-page > .pick-search {
  margin: -12px 0 40px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}
.club-section + .club-section { margin-top: 48px; }
.overdue { color: var(--accent); }
.row-date { font-size: 13px; margin-top: 2px; }
.pick-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.pick-gear { flex: none; }
.pick-gear .menu { min-width: 210px; }
.list-empty { padding: 4px 0; }
.stage-choice { border: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
.stage-choice label { display: flex; align-items: baseline; gap: 8px; font-size: 14px; cursor: pointer; }
.stage-choice input { accent-color: var(--accent); }
#schedule-book { margin: -12px 0 18px; }

.member-list { list-style: none; margin: 0; padding: 0; }
.member { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.member:last-child { border-bottom: none; padding-bottom: 0; }
.member:first-child { padding-top: 0; }
.member > div { flex: 1; min-width: 0; }
.member > .member-actions { flex: 1 1 100%; }
.member .mini-avatar { border-color: var(--surface); }
.member-name { font-weight: 500; }
.member-you, .member-email { color: var(--ink-faint); font-size: 12px; font-weight: 400; }
.member-email { overflow-wrap: anywhere; }
.member-actions { display: flex; gap: 12px; width: 100%; padding-left: 42px; }
.link-btn.danger { color: var(--ink-faint); }
.link-btn.danger:hover { color: var(--accent); }
.invite-row { display: flex; gap: 6px; margin: 10px 0 8px; }
.invite-row input { flex: 1; font-size: 13px; background: var(--surface); }

/* ================= Settings ================= */
.settings { max-width: 1120px; margin: 0 auto; padding: 40px 16px 96px; }
.settings-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 56px; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar-h, 60px) + 24px); display: flex; flex-direction: column; gap: 2px; }
.settings-nav a {
  padding: 8px 12px;
  border-radius: 8px;
  border-left: 2px solid transparent;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 14px;
}
.settings-nav a:hover { color: var(--ink); background: var(--surface); border-left-color: var(--accent); }
.settings-body { max-width: 760px; }
.settings-section { margin-bottom: 56px; scroll-margin-top: calc(var(--topbar-h, 60px) + 24px); }
.settings-section > h2 { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.settings-desc { margin: 0 0 20px; color: var(--ink-soft); font-size: 14px; }
.settings-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-card);
}
.settings-card input[readonly] { background: var(--bg); color: var(--ink-soft); }
.settings-actions { display: flex; justify-content: flex-end; align-items: center; gap: 14px; margin-top: 20px; }
.settings-status { font-size: 13px; color: var(--accent); }
.settings-status.error { color: var(--accent); font-weight: 500; }
.settings-desc .settings-status { margin-left: 6px; font-weight: 500; }
.soon-chip {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 2px 9px;
}

/* Palette picker. Each card holds a miniature page in its own palette. */
.theme-picker { border: none; margin: 0; padding: 0; min-width: 0; }
.theme-picker > .section-label { margin: 28px 0 14px; }
.theme-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.theme-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px 10px 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.2s, transform 0.2s;
}
.theme-card:hover { border-color: var(--ink-faint); transform: translateY(-2px); box-shadow: var(--shadow-card); }
.theme-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-card); }
.theme-card:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 3px; }
.theme-meta { display: flex; flex-direction: column; gap: 2px; padding: 0 4px; }
.theme-name { font-family: var(--serif); font-size: 18px; font-weight: 500; }
.theme-note { font-size: 12px; color: var(--ink-soft); line-height: 1.4; }
.theme-check {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 2;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.theme-card:has(input:checked) .theme-check { display: inline-flex; }
.theme-auto { flex-direction: row; align-items: center; gap: 20px; padding: 10px 20px 10px 10px; }
.theme-auto .theme-art { flex: none; width: min(320px, 55%); }
.theme-auto .theme-check { top: 50%; transform: translateY(-50%); }
.theme-auto .theme-meta { padding-right: 36px; }

.tp {
  border-radius: 9px;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  aspect-ratio: 16 / 10;
  display: flex;
  flex-direction: column;
}
.tp-split { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tp-bar { display: flex; align-items: center; gap: 6px; padding: 7px 9px; background: var(--topbar-bg); border-bottom: 1px solid var(--rule); }
.tp-bar i { display: block; height: 5px; border-radius: 3px; }
.tp-brand { width: 30%; background: var(--ink); }
.tp-nav { width: 18%; background: var(--ink-faint); opacity: 0.6; }
.tp-dot { width: 9px !important; height: 9px !important; border-radius: 50% !important; margin-left: auto; background: var(--accent-soft); border: 1px solid var(--rule); }
.tp-body { flex: 1; display: grid; grid-template-columns: 30% 1fr; gap: 10%; padding: 10% 10% 0; }
.tp-cover {
  border-radius: 2px 4px 4px 2px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.2), transparent 14%), var(--accent);
  box-shadow: 0 6px 12px -6px rgba(0, 0, 0, 0.45);
  aspect-ratio: 2 / 3;
}
.tp-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tp-title { font-family: var(--serif); font-weight: 500; font-size: 22px; line-height: 1; color: var(--ink); }
.tp-line { display: block; height: 4px; border-radius: 2px; background: var(--ink-soft); opacity: 0.55; }
.tp-line.short { width: 60%; }
.tp-meter { height: 4px; border-radius: 2px; background: var(--rule); overflow: hidden; margin-top: 2px; }
.tp-meter span { display: block; width: 58%; height: 100%; background: var(--gold); }
.tp-btn { display: block; width: 52%; height: 12px; border-radius: 4px; background: var(--accent); margin-top: auto; margin-bottom: 10%; }
.tp-split .tp-title { font-size: 18px; }

/* Subscription */
.plan-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.plan-row:first-child { padding-top: 0; }
.plan-title { margin: 0 0 2px; font-family: var(--serif); font-size: 18px; font-weight: 500; }
.plan-chip { flex: none; font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--rule); color: var(--ink-faint); }
.plan-chip.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, var(--rule)); color: var(--ink); }
.plan-foot { margin: 16px 0 0; font-size: 13px; color: var(--ink-faint); }
.settings-placeholder { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-style: dashed; box-shadow: none; background: transparent; }
.placeholder-title { margin: 0 0 2px; font-family: var(--serif); font-size: 18px; }

@media (max-width: 820px) {
  .settings-layout { grid-template-columns: 1fr; gap: 24px; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; gap: 4px; border-bottom: 1px solid var(--rule); padding-bottom: 8px; }
  .settings-nav a { border-left: none; white-space: nowrap; }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .theme-auto { flex-direction: column; align-items: stretch; padding: 10px 10px 14px; }
  .theme-auto .theme-art { width: 100%; }
  .theme-auto .theme-check { top: 18px; transform: none; }
  .settings-placeholder { flex-direction: column; align-items: flex-start; }
}

/* ================= Admin ================= */
.admin-help { max-width: 70ch; margin-bottom: 16px; }
.admin-table { border-top: 1px solid var(--rule); }
.admin-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.admin-who { flex: 1; min-width: 220px; }
.admin-toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.admin-toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.admin-reset { width: 100%; }

/* ---------- Narrow screens ---------- */
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .mainnav a { padding: 6px 8px; }
  .mainnav a[aria-current="page"]::after { left: 8px; right: 8px; bottom: -11px; }
  .quick-add { width: 100%; margin-left: 0; order: 10; }
  .quick-add + .account { margin-left: auto; }
  .club-layout { grid-template-columns: 1fr; gap: 48px; }
  .hero-card { grid-template-columns: 130px minmax(0, 1fr); gap: 24px; padding: 24px; }
  .pick-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 28px 18px; }
  .qa-results { left: 0; right: auto; width: 100%; }
  .book-page { display: flex; flex-direction: column; gap: 28px; padding-top: 24px; }
  .book-page > .content { display: contents; }
  .title-block { order: 0; margin-bottom: 0; }
  .record { order: 1; position: static; align-self: stretch; display: grid; grid-template-columns: 120px 1fr; gap: 16px; }
  .tabs button { padding: 10px 9px; font-size: 14px; }
  .tabs { order: 2; margin-bottom: 4px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .panel { order: 3; }
  .discuss-hint { display: none; }
  .msg, .msg-user { max-width: 100%; }
  .note-talk { opacity: 1; }
  .record #cover { grid-row: span 2; }
  .meta, .shelf-box { grid-column: 1 / -1; }
  .cast li { grid-template-columns: 1fr; gap: 2px; }
  .note-form { grid-template-columns: 70px 1fr; }
  .note-form button { grid-column: 1 / -1; }
  .note-delete { opacity: 1; }
  .companion-head { flex-direction: column; }

  .book-row { grid-template-columns: 36px minmax(0, 1fr) auto; }
  .row-shelves, .row-rating { display: none; }
  .toolbar-end { margin-left: 0; }
}

@media (max-width: 900px) {
  .shelf-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .shelf-row > :nth-child(n + 5) { display: none; }
}

@media (max-width: 560px) {
  .home { padding-top: 32px; }
  .home-club { grid-template-columns: 88px minmax(0, 1fr); gap: 18px; padding: 18px; }
  .home-club h3 { font-size: 22px; }
  .shelf-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .shelf-row > :nth-child(n + 4) { display: none; }
  .shelf-row .card-title { font-size: 14px; }
  .hero-card { grid-template-columns: 1fr; gap: 22px; padding: 22px 20px; }
  .hero-cover { width: 132px; }
  .hero-body { gap: 18px; }
  .club-head { align-items: flex-start; }
  .club-head .club-title { width: 100%; }
}

@media (max-width: 480px) {
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .add-dialog { padding: 20px; }
}

.edit-hint { margin: -12px 0 18px; }

/* Buy links on club books */
.buy-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.buy-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; margin-right: 2px; }
.btn-buy { font-weight: 500; }
.buy-links.compact { margin-top: 4px; gap: 4px 12px; }
.buy-link { font-size: 13px; color: var(--accent); text-decoration: none; }
.buy-link:hover { text-decoration: underline; }
.affiliate-note { margin: 40px 0 0; font-size: 12px; color: var(--ink-faint); }
.club-edition { margin: 6px 0 0; font-size: 12px; color: var(--ink-faint); }
#edition-book { margin: -12px 0 18px; }
#edition-clear { margin-right: auto; }

/* Discuss: the reading mentor */
.premium-chip {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: 2px;
}
.discuss-head { display: flex; gap: 16px; align-items: flex-start; padding-bottom: 24px; margin-bottom: 28px; border-bottom: 1px solid var(--rule); }
.mentor-mark {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--rule));
}
.discuss-title { font-size: 22px; margin: 2px 0 4px; }
.discuss-intro { color: var(--ink-soft); margin: 0; font-size: 14px; max-width: 58ch; }

/* The conversation reads like annotations: the mentor's notes sit in the margin with a rule,
   the reader's own lines are set off to the right. The page scrolls; the box stays at the bottom. */
.discuss-log { display: flex; flex-direction: column; gap: 26px; padding-bottom: 8px; }
.msg { max-width: 88%; }
.msg p { margin: 0 0 10px; }
.msg p:last-child { margin-bottom: 0; }
.msg-user {
  align-self: flex-end;
  max-width: 80%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px 14px 4px 14px;
  box-shadow: var(--shadow-card);
  font-size: 15px;
}
.msg-mentor {
  align-self: flex-start;
  padding: 2px 0 2px 20px;
  border-left: 2px solid var(--accent);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
}
.msg-who {
  display: block;
  margin-bottom: 6px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.msg-thinking { display: flex; align-items: center; gap: 10px; font-family: var(--sans); font-size: 14px; color: var(--ink-faint); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0.3; animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 40% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: 0.7; } }

.discuss-empty { padding: 8px 0 4px; }
.discuss-empty > p { color: var(--ink-soft); margin: 0 0 12px; font-size: 14px; }
.starters { display: grid; gap: 8px; }
.starter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--serif);
  font-size: 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.starter span { color: var(--accent); }
.starter:hover { border-color: var(--accent); transform: translateX(2px); }
.starter-tip { margin: 14px 0 0; font-size: 13px; color: var(--ink-faint); }

.discuss-form {
  position: sticky;
  bottom: 0;
  z-index: 4;
  margin-top: 20px;
  padding: 24px 0 10px;
  background-color: transparent;
  background-image: var(--grain), linear-gradient(transparent, var(--bg) 22px);
}
.discuss-form .form-error { min-height: 0; margin-top: 6px; }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow-lift);
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  min-height: 0;
  padding: 6px 0;
  border: none;
  background: none;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
}
.composer-send { flex: none; }
.discuss-bar { display: flex; align-items: center; gap: 14px; margin-top: 8px; font-size: 12px; }
.discuss-meta { color: var(--ink-faint); }
.discuss-hint { margin-right: auto; color: var(--ink-faint); }
.discuss-bar .link-btn { margin-left: auto; }
.discuss-meta:empty { display: none; }
