/* ==========================================================================
   Library of Me — warm & cosy (fog grey, charcoal, sage green)
   with a modern edge (tangerine and lime).
   Palette: #E8E9EB fog · #313638 charcoal · #4F9D69 sage · #FF622D tangerine · #C7FF4C lime
   The bright brand colours are used for fills and accents; text uses deeper
   shades of them so everything stays readable (WCAG AA).
   ========================================================================== */
:root {
  /* brand */
  --fog: #E8E9EB;
  --charcoal: #313638;
  --sage: #4F9D69;
  --tangerine: #FF622D;
  --lime: #C7FF4C;

  /* surfaces & text */
  --bg: var(--fog);
  --surface: #FAFAF7;
  --surface-2: #F0F0EC;
  --ink: var(--charcoal);
  --muted: #5E6467;
  --line: #DCDDD8;

  /* roles */
  --accent: #B8401A;          /* tangerine, deep enough for text */
  --accent-soft: #FFE6DB;
  --primary: var(--charcoal); /* main buttons */
  --primary-ink: #fff;
  --ok: #2F6E45;
  --ok-soft: #DCEFE2;
  --warn: #8A5A12;
  --warn-soft: #F8EBCF;
  --danger: #B3261E;
  --focus: var(--tangerine);

  --love: #367A4D;            /* sage, deep enough for white text */
  --love-soft: #DCEFE2;
  --love-ink: #2F6E45;
  --hate: #B8401A;
  --hate-soft: #FFE6DB;
  --hate-ink: #A93A14;

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(49, 54, 56, .05), 0 8px 24px -8px rgba(49, 54, 56, .12);
  --shadow-lift: 0 2px 4px rgba(49, 54, 56, .06), 0 14px 32px -10px rgba(49, 54, 56, .22);
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1E2224;
    --surface: #272C2E;
    --surface-2: #31373A;
    --ink: #ECEDEE;
    --muted: #AEB4B7;
    --line: #3B4245;
    --accent: #FF7A4D;
    --accent-soft: #3E2A22;
    --primary: var(--lime);
    --primary-ink: #1E2224;
    --ok: #7FD39B;
    --ok-soft: #22382A;
    --warn: #E8BC6E;
    --warn-soft: #3A3122;
    --danger: #FF8A80;
    --love: #6CC28A;
    --love-soft: #22382A;
    --love-ink: #8FDCAA;
    --hate: #FF7A4D;
    --hate-soft: #3E2A22;
    --hate-ink: #FF9C78;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -8px rgba(0,0,0,.45);
    --shadow-lift: 0 2px 4px rgba(0,0,0,.35), 0 14px 32px -10px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background-color: var(--bg);
  /* a soft glow of lime and tangerine behind everything */
  background-image:
    radial-gradient(60rem 30rem at 110% -10%, rgba(199, 255, 76, .28), transparent 60%),
    radial-gradient(50rem 30rem at -20% 110%, rgba(255, 98, 45, .12), transparent 60%);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
@media (prefers-color-scheme: dark) {
  body { background-image:
    radial-gradient(60rem 30rem at 110% -10%, rgba(199, 255, 76, .08), transparent 60%),
    radial-gradient(50rem 30rem at -20% 110%, rgba(255, 98, 45, .08), transparent 60%); }
}
::selection { background: var(--lime); color: var(--charcoal); }
a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; font-variation-settings: 'SOFT' 100; }
h1 { font-size: clamp(1.9rem, 6vw, 2.8rem); letter-spacing: -.02em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  background: var(--charcoal); color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.brand { white-space: nowrap; font-family: var(--serif); font-size: 1.35rem; font-weight: 700; color: #fff; text-decoration: none; letter-spacing: -.01em; display: inline-flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 11px;
  background: var(--tangerine); color: var(--charcoal);
  transition: transform .2s ease;
}
.brand-mark svg { display: block; }
.brand:hover .brand-mark { transform: rotate(-4deg) scale(1.06); }
#nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
#nav a, #nav button {
  font: 500 .95rem var(--sans); color: rgba(255,255,255,.78); text-decoration: none;
  padding: 7px 14px; border-radius: 999px; border: 0; background: none; cursor: pointer;
}
#nav a:hover, #nav button:hover { color: #fff; background: rgba(255,255,255,.1); }
#nav a.active { color: var(--charcoal); background: var(--lime); font-weight: 600; }
.topbar a:focus-visible, .topbar button:focus-visible { outline-color: var(--lime); }

main { max-width: 980px; margin: 0 auto; padding: 36px 20px 96px; outline: none; }
.narrow { max-width: 440px; margin: 0 auto; }

/* ---------- Cards & layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.grid-2 > .card + .card, .board > .card + .card, .received-grid > .card + .card, .grid-2 > .field + .field { margin-top: 0; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=url], textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1.5px solid transparent; border-radius: var(--radius-sm); padding: 11px 14px;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
input:hover, textarea:hover, select:hover { border-color: var(--line); }
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none; background: var(--surface); border-color: var(--charcoal);
  box-shadow: 0 0 0 4px rgba(199, 255, 76, .55);
}
@media (prefers-color-scheme: dark) {
  input:focus, textarea:focus, select:focus { border-color: var(--lime); box-shadow: 0 0 0 4px rgba(199, 255, 76, .18); }
}
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .8; }
.field + .field { margin-top: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 .95rem var(--sans); border-radius: 999px; padding: 11px 22px; cursor: pointer;
  border: 1.5px solid var(--primary); background: var(--primary); color: var(--primary-ink);
  text-decoration: none; transition: transform .12s ease, background-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: var(--lime); border-color: var(--charcoal); color: var(--charcoal); text-decoration: none; }
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn:disabled:hover { background: var(--primary); color: var(--primary-ink); }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn.secondary:hover { background: var(--lime); color: var(--charcoal); border-color: var(--charcoal); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--ink); color: var(--ink); }
.btn.small { padding: 7px 14px; font-size: .85rem; }
.btn.full { width: 100%; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) {
  .btn:hover { border-color: var(--lime); }
  .btn.secondary:hover, .btn.ghost:hover { border-color: var(--lime); }
}

.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: 8px 0 0; }
.notice { padding: 12px 16px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: .92rem; border-left: 4px solid currentColor; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice ul { margin: 4px 0 0; padding-left: 20px; }

/* ---------- Landing / auth ---------- */
.hero { text-align: center; padding: 20px 0 32px; }
.hero h1 {
  max-width: 14ch; margin-left: auto; margin-right: auto;
  text-decoration: underline; text-decoration-color: var(--lime); text-decoration-thickness: .28em;
  text-underline-offset: -.12em; text-decoration-skip-ink: none;
}
@media (prefers-color-scheme: dark) { .hero h1 { text-decoration-color: rgba(199, 255, 76, .35); } }
.hero p { color: var(--muted); max-width: 540px; margin: 0 auto; font-size: 1.08rem; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; margin-bottom: 20px; }
.tabs button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 999px; font: 600 .95rem var(--sans); color: var(--muted); cursor: pointer; }
.tabs button[aria-selected=true] { background: var(--charcoal); color: #fff; box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .tabs button[aria-selected=true] { background: var(--lime); color: var(--charcoal); } }

/* ---------- Chips & tags ---------- */
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; font-family: var(--serif); font-size: 1.08rem; }
legend .muted { font-family: var(--sans); font-weight: 500; font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.chip span {
  display: inline-block; padding: 7px 14px; border-radius: 999px; font-size: .88rem;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); user-select: none;
  transition: background-color .15s, border-color .15s;
}
.chip input:hover + span { border-color: var(--ink); }
.chip input:checked + span { background: var(--charcoal); border-color: var(--charcoal); color: var(--lime); }
.chip input:focus-visible + span { outline: 2.5px solid var(--focus); outline-offset: 2px; }
.chip.ick input:checked + span { background: var(--hate); border-color: var(--hate); color: #fff; }
@media (prefers-color-scheme: dark) { .chip input:checked + span { background: var(--lime); border-color: var(--lime); color: var(--charcoal); } }
.tag { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: .8rem; font-weight: 500; background: var(--surface-2); margin: 0 4px 4px 0; }
.tag.genre { background: var(--accent-soft); color: var(--accent); }
.tag.ick { text-decoration: line-through; text-decoration-color: var(--muted); }

/* ---------- Books ---------- */
.book { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: var(--radius-sm); }
.book .cover {
  width: 44px; height: 66px; flex: none; border-radius: 4px 8px 8px 4px; background: var(--surface-2);
  object-fit: cover; display: grid; place-items: center; font-family: var(--serif); color: var(--muted);
  box-shadow: inset 3px 0 0 rgba(0,0,0,.12), 0 2px 6px rgba(49, 54, 56, .18);
}
.book .meta { flex: 1; min-width: 0; }
.book .title { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.book .sub { color: var(--muted); font-size: .85rem; }
.book-results { margin-top: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 340px; overflow-y: auto; background: var(--surface); }
.book-results:empty { display: none; }
.book-results .book { border-radius: 0; border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; font: inherit; color: inherit; }
.book-results .book:last-child { border-bottom: 0; }
.book-results .book:hover, .book-results .book:focus { background: var(--surface-2); }
.picked .book { background: var(--surface-2); margin-bottom: 8px; }

/* ---------- Groups & swap board ---------- */
.group-list { display: grid; gap: 12px; }
.group-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-decoration: none; color: inherit; transition: transform .15s ease, box-shadow .15s ease, border-color .15s; }
.group-item:hover { border-color: var(--charcoal); box-shadow: var(--shadow-lift); transform: translateY(-2px); text-decoration: none; }
.group-item h2, .group-item h3 { margin-bottom: .2em; }
.code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: .1em; background: var(--charcoal); color: var(--lime); padding: 3px 9px; border-radius: 8px; font-size: .92em; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 16px; }
.reader { display: flex; flex-direction: column; gap: 12px; }
.board > .reader { position: relative; overflow: hidden; }
.board > .reader::before { content: ''; position: absolute; inset: 0 0 auto; height: 6px; background: linear-gradient(90deg, var(--sage), var(--lime)); }
.board > .reader:nth-child(3n+2)::before { background: linear-gradient(90deg, var(--tangerine), #FFB38F); }
.board > .reader:nth-child(3n)::before { background: linear-gradient(90deg, var(--charcoal), var(--sage)); }
.reader .alias { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; }
.section-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.reader .quote, .quote { font-family: var(--serif); font-style: italic; color: var(--ink); font-size: .98rem; line-height: 1.5; }
.looking-for { white-space: pre-line; margin: 0; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-sm); border-left: 4px solid var(--sage); }
.reader .actions { margin-top: auto; }
.reader.taken { opacity: .55; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.muted-badge { background: transparent; border: 1px solid var(--line); }
.match-card { border: 2px solid var(--sage); position: relative; overflow: hidden; }
.match-card::before { content: ''; position: absolute; inset: 0 0 auto; height: 8px; background: linear-gradient(90deg, var(--sage), var(--lime)); }
.address { font-style: normal; white-space: pre-line; background: var(--surface-2); padding: 14px 18px; border-radius: var(--radius-sm); line-height: 1.6; border: 1.5px dashed var(--line); overflow-wrap: anywhere; }

#toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--charcoal); color: #fff; padding: 11px 20px; border-radius: 999px; z-index: 60;
  opacity: 0; transition: .2s; pointer-events: none; font-size: .92rem; font-weight: 500; max-width: calc(100% - 32px);
  box-shadow: var(--shadow-lift); border: 1.5px solid var(--lime);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Utilities (inline style attributes are blocked by the CSP) */
.m-0 { margin: 0; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.between { justify-content: space-between; }
.center { text-align: center; }
.board-heading { margin: 32px 0 14px; }
.h3 { font-family: var(--serif); font-size: 1.1rem; font-weight: 700; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Custom tags, book notes, address form ---------- */
.stack-sm > * + * { margin-top: 10px; }
.chip.custom > span { display: inline-flex; align-items: center; gap: 4px; padding-right: 6px; background: var(--charcoal); border-color: var(--charcoal); color: var(--lime); }
.chip.custom.ick > span { background: var(--hate); border-color: var(--hate); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.custom > span { background: var(--lime); border-color: var(--lime); color: var(--charcoal); } }
.chip-remove { border: 0; background: none; color: inherit; font: inherit; font-size: 1rem; line-height: 1; padding: 0 4px; cursor: pointer; opacity: .8; min-width: 24px; min-height: 24px; }
.chip-remove:hover { opacity: 1; }
.tag-add { display: flex; gap: 8px; flex-wrap: wrap; }
.tag-add .tag-input { flex: 1; min-width: 180px; padding: 8px 14px; font-size: .9rem; border-radius: 999px; }
.picked-book { background: var(--surface-2); border-radius: var(--radius-sm); padding: 4px 14px 14px; margin-bottom: 10px; }
.picked-book .book { padding: 8px 0; }
.picked .picked-book .book { background: none; margin-bottom: 0; }
.picked-book label { font-size: .85rem; margin: 0; }
.picked-book textarea { min-height: 56px; margin-top: 4px; background: var(--surface); }
.book-note { margin: -2px 0 8px 56px; }
.addr-row { display: grid; gap: 12px 16px; grid-template-columns: 1fr; }
.addr-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.addr-row.cols-3 { grid-template-columns: 2fr 1.4fr 1fr; }
@media (max-width: 600px) { .addr-row.cols-2, .addr-row.cols-3 { grid-template-columns: 1fr; } }
.addr-row .field + .field { margin-top: 0; }
.field-error { color: var(--danger); font-size: .85rem; margin: 4px 0 0; }
.field-error:empty { display: none; }
input[aria-invalid=true], select[aria-invalid=true] { border-color: var(--danger); }
.notice.small { font-size: .85rem; }

/* ---------- Love it / Hate it sorting ---------- */
.legend-help { margin: -4px 0 10px; }
.rated { position: relative; }
.buckets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (max-width: 600px) { .buckets { grid-template-columns: 1fr; } }
.bucket { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 12px; min-height: 68px; }
.bucket-love { background: var(--love-soft); border-color: transparent; }
.bucket-hate { background: var(--hate-soft); border-color: transparent; }
.bucket-title { display: flex; justify-content: space-between; gap: 8px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.bucket-love .bucket-title { color: var(--love-ink); }
.bucket-hate .bucket-title { color: var(--hate-ink); }
.bucket-count { font-weight: 500; letter-spacing: 0; color: var(--muted); }
.bucket-count.over { color: var(--danger); font-weight: 700; }
.bucket-empty { margin: 0; font-size: .82rem; color: var(--muted); }
.pool-title { font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.chip-btn {
  font: inherit; font-size: .88rem; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  transition: border-color .15s, background-color .15s, transform .12s;
}
.chip-btn:hover { border-color: var(--ink); }
.chip-btn:active { transform: scale(.97); }
.chip-btn:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; }
.chip-btn.rated-love { background: var(--love); border-color: var(--love); color: #fff; }
.chip-btn.rated-hate { background: var(--hate); border-color: var(--hate); color: #fff; }
@media (prefers-color-scheme: dark) { .chip-btn.rated-love, .chip-btn.rated-hate { color: #1E2224; } }
.rate-menu {
  position: absolute; z-index: 10; display: flex; flex-wrap: wrap; gap: 4px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-lift);
  max-width: calc(100% - 8px);
}
.rate-menu[hidden] { display: none; }
.rate-opt { font: 600 .88rem var(--sans); border: 0; border-radius: 999px; padding: 8px 14px; cursor: pointer; background: var(--surface-2); color: var(--ink); }
.rate-opt:hover, .rate-opt:focus-visible { outline: 2px solid var(--ink); outline-offset: 0; }
.rate-opt.rate-love { color: var(--love-ink); }
.rate-opt.rate-hate { color: var(--hate-ink); }
.rate-opt.current { box-shadow: inset 0 0 0 2px currentColor; }
.rate-opt[disabled] { opacity: .45; cursor: not-allowed; }

/* Board tags */
.rated-line { margin-bottom: 4px; }
.rated-key { display: inline-block; min-width: 68px; font-size: .75rem; font-weight: 700; margin-right: 4px; }
.rated-key-love { color: var(--love-ink); }
.rated-key-hate { color: var(--hate-ink); }
.tag-love { background: var(--love-soft); color: var(--love-ink); }
.tag-hate { background: var(--hate-soft); color: var(--hate-ink); }
.tag-avoid { background: var(--warn-soft); color: var(--warn); }

/* ---------- Match card ---------- */
.match-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 20px; align-items: start; }
@media (max-width: 700px) { .match-grid { grid-template-columns: 1fr; } }
.shop-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.shop-list li { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.shop-list a { font-weight: 700; }
.shop-list .shop-kind { margin-bottom: 4px; font-size: .7rem; }
.shop-badge { margin-left: 6px; white-space: nowrap; display: inline-block; }

/* ---------- Confirmation dialog ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(30, 34, 36, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal h2 { margin-bottom: .4em; }
.modal-actions { justify-content: flex-end; margin-top: 8px; }

/* ---------- Goodreads ---------- */
label.btn { display: inline-flex; margin: 0; }
.gr-steps { margin: 0; padding-left: 20px; }
.gr-steps li + li { margin-top: 4px; }
.gr-checker { border-top: 1px solid var(--line); padding-top: 16px; }
.gr-row { border-bottom: 1px solid var(--line); padding: 0 8px 8px; }
.gr-row:last-child { border-bottom: 0; }
.gr-row .book { padding: 8px 0 4px; }
.gr-slot:empty { display: none; }
.gr-slot { padding-left: 56px; }
.gr-result { display: inline-block; font-size: .85rem; font-weight: 600; padding: 4px 12px; border-radius: 999px; }
.gr-read, .gr-reading { background: var(--warn-soft); color: var(--warn); }
.gr-toread, .gr-none { background: var(--ok-soft); color: var(--ok); }

/* ---------- Group management, invites, deadlines, received books ---------- */
.group-item.archived { opacity: .8; }
.archived-list > summary, .settings > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.settings > summary { list-style-position: outside; }
.settings hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0 8px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.settings-row .btn { flex-shrink: 0; }
.deadline { color: var(--ink); }
.deadline.soon { color: var(--warn); }
.deadline.late { color: var(--danger); }
.invite-box { background: var(--charcoal); color: #fff; border-radius: var(--radius-sm); padding: 16px 18px; }
.invite-box .section-label { color: var(--lime); }
.invite-box .muted, .invite-box p { color: rgba(255,255,255,.78); }
.invite-box .code { background: var(--lime); color: var(--charcoal); }
.invite-box .btn { background: var(--lime); border-color: var(--lime); color: var(--charcoal); }
.invite-box .btn:hover { background: #fff; border-color: #fff; }
.invite-box .btn.ghost, .invite-box .btn.secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.invite-box .btn.ghost:hover, .invite-box .btn.secondary:hover { border-color: var(--lime); color: var(--lime); }
.invite-box input { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.15); }
.invite-box input:focus { background: rgba(255,255,255,.12); border-color: var(--lime); }
.invite-box > * + * { margin-top: 10px; }
.invite-link-row { display: flex; gap: 8px; }
.invite-link-row input { flex: 1; min-width: 0; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .85rem; }
.invite-note { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.invite-note .btn { flex-shrink: 0; white-space: nowrap; }
.received-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 16px; }
.received-item > * + * { margin-top: 8px; }
.received-card h2 + p { margin-top: 4px; }

/* ---------- Drag and drop for rating tags ---------- */
.rate-chip { cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.drag-ghost { position: fixed; z-index: 1000; margin: 0; pointer-events: none; cursor: grabbing; box-shadow: var(--shadow-lift); transform: rotate(-3deg) scale(1.06); }
.drag-source { opacity: .35; }
body.dragging-chip, body.dragging-chip * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
.rated.is-dragging .bucket { border: 2px dashed var(--line); padding: 11px; }
.rated .pool { border: 2px dashed transparent; border-radius: var(--radius-sm); padding: 8px; margin: -10px -10px 0; }
.rated.is-dragging .pool { border-color: var(--line); }
.rated .drop-over.bucket, .rated .drop-over.pool { border-color: var(--charcoal); border-style: solid; box-shadow: 0 0 0 4px rgba(199, 255, 76, .55); }

/* ---------- Onboarding ---------- */
.onboarding-wrap { max-width: 720px; margin: 0 auto; }
.onboarding-intro { margin-bottom: 18px; }
.onboarding-intro .section-label { margin: 0 0 4px; color: var(--accent); }
.onboarding { gap: 0; }
.onboarding-title { font-size: clamp(1.35rem, 4.5vw, 1.75rem); margin: 0 0 6px; line-height: 1.2; }
.onboarding-progress .row span:last-child { font-weight: 700; }
.progress-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--sage), var(--lime)); border-radius: 999px; transition: width .35s cubic-bezier(.2, .8, .2, 1); }
.onboarding-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding-top: 18px; border-top: 1px solid var(--line); }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; text-underline-offset: .18em; cursor: pointer; }

/* ---------- Sent books ---------- */
.sent-box { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 16px 0; }
.sent-summary { flex-wrap: wrap; gap: 12px; }
.tracking { color: inherit; overflow-wrap: anywhere; }
.tracking .code { font-size: .85em; }

/* ==========================================================================
   Phones
   ========================================================================== */
@media (max-width: 600px) {
  .topbar { padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
  .brand { font-size: 1.2rem; }
  .brand-mark { width: 32px; height: 32px; border-radius: 10px; }
  .brand-mark svg { width: 24px; height: 24px; }
  main { padding: 22px 14px 48px; }
  body.has-tabbar main { padding-bottom: calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom)); }
  .card { padding: 20px 18px; border-radius: 18px; }
  .card + .card { margin-top: 14px; }
  h2 { font-size: 1.25rem; }
  .hero { padding: 8px 0 22px; }
  .hero p { font-size: 1rem; }

  /* Signed in: the nav becomes a bottom tab bar, within thumb reach. */
  #nav.signed-in {
    position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 30;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
    padding: 6px; height: var(--tabbar-h);
    background: rgba(49, 54, 56, .96); border-radius: 22px; box-shadow: var(--shadow-lift);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  }
  #nav.signed-in a, #nav.signed-in button {
    display: grid; place-items: center; text-align: center; height: 100%; padding: 0 6px;
    border-radius: 16px; font-size: .88rem; line-height: 1.15;
  }
  body.has-tabbar #toast { bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }

  /* Comfortable tap targets, and 16px text in fields so iOS doesn't zoom in. */
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .chip-btn, .chip span { padding: 8px 14px; }
  .tag-add .tag-input, .invite-link-row input, input, select, textarea { font-size: 16px; }

  .settings-row, .invite-note { flex-direction: column; align-items: stretch; }
  .invite-link-row { flex-wrap: wrap; }
  .invite-link-row input { flex-basis: 100%; }
  .invite-link-row .btn { flex: 1; }
  .modal-actions { flex-direction: column-reverse; align-items: stretch; }
  .onboarding-actions { flex-wrap: nowrap; gap: 8px; }
  .onboarding-actions .btn { white-space: nowrap; padding-left: 16px; padding-right: 16px; }
  .onboarding-actions > .row { flex: 1; justify-content: flex-end; flex-wrap: nowrap; gap: 8px; }
  .onboarding-actions > .row > .btn:last-child { flex: 1; max-width: 160px; }
  .tag-add .tag-input { flex-basis: 100%; }
  .tag-add .btn { flex: 1; }
  .group-item { flex-wrap: wrap; }
  .book-note, .gr-slot { margin-left: 0; padding-left: 0; }
  .rated-key { min-width: 0; display: block; margin-bottom: 2px; }
}

@media (hover: none) {
  .group-item:hover { transform: none; box-shadow: var(--shadow); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .brand-mark { transform: none; }
}

/* A field label sharing a row with a counter keeps the counter beside it on narrow screens. */
.row.between > label { flex: 1 1 12rem; margin-bottom: 0; }

/* Touchscreens keep :hover after a tap, so undo hover colours there. */
@media (hover: none) {
  .btn:hover { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
  .btn.secondary:hover { background: transparent; color: var(--ink); border-color: var(--ink); }
  .btn.ghost:hover { background: transparent; border-color: var(--line); color: var(--ink); }
  .btn.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; filter: none; }
  .invite-box .btn:hover { background: var(--lime); border-color: var(--lime); color: var(--charcoal); }
  .invite-box .btn.ghost:hover, .invite-box .btn.secondary:hover { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
  .chip-btn:hover, .chip input:hover + span { border-color: var(--line); }
  .chip-btn.rated-love:hover { border-color: var(--love); }
  .chip-btn.rated-hate:hover { border-color: var(--hate); }
  #nav a:hover, #nav button:hover { background: none; color: rgba(255,255,255,.78); }
  #nav a.active:hover { color: var(--charcoal); background: var(--lime); }
}
