@font-face {
  font-family: Inter;
  src: url("fonts/inter.woff2") format("woff2");
  font-weight: 400 600;
  font-display: swap;
}

@font-face {
  font-family: "Source Serif 4";
  src: url("fonts/source.woff2") format("woff2");
  font-weight: 500 600;
  font-display: swap;
}

@media (prefers-reduced-motion: no-preference) {
  /* Pages fade into each other, and the header and tab bar stay still. */
  @view-transition { navigation: auto; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 120ms; }
  html { scroll-behavior: smooth; }
}

:root {
  color-scheme: light dark;
  --paper: #faf7f2;
  --surface: #ffffff;
  --sunken: #f1ece3;
  --ink: #221d17;
  --muted: #655c50;
  --line: #e4dccf;
  --accent: #a8431a;
  --accent-hover: #8b3613;
  --on-accent: #ffffff;
  --success: #1c6e45;
  --success-soft: #e2f2e9;
  --danger: #b0261b;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --shadow: 0 1px 2px rgb(60 45 25 / 8%), 0 4px 12px rgb(60 45 25 / 6%);
  --radius: 10px;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #181511;
    --surface: #221e18;
    --sunken: #2c271f;
    --ink: #f2ece2;
    --muted: #b5aa9a;
    --line: #3b352b;
    --accent: #e08a5f;
    --accent-hover: #eba27d;
    --on-accent: #1d1209;
    --success: #7fd0a4;
    --success-soft: #1c3226;
    --danger: #f19a90;
    --danger-soft: #3a1f1b;
    --warn: #e6bd6b;
    --warn-soft: #362b14;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 12px rgb(0 0 0 / 25%);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--sans);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
}

h1 { font-size: clamp(1.6rem, 1.3rem + 1.2vw, 2.1rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

p { margin: 0; }

a { color: inherit; }

img { max-width: 100%; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.muted { color: var(--muted); }

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 30;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

.skip-link:focus { top: 12px; }

.link {
  color: var(--accent);
  font-weight: 500;
  text-underline-offset: 2px;
}

.link--icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow-wrap: anywhere;
}

/* Top bar */

.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: 100%;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  pointer-events: none;
}

html.is-loading .loading-bar {
  opacity: 1;
  transform: scaleX(0.85);
  transition: transform 1.2s cubic-bezier(0.1, 0.7, 0.2, 1);
}

html.is-loading button[aria-busy="true"] { opacity: 0.7; cursor: progress; }

[id] { scroll-margin-top: 16px; }

/* On phones the tab bar handles navigation, so the header scrolls away and gives the page more room. */
.topbar {
  position: relative;
  z-index: 20;
  view-transition-name: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "brand menu" "search search";
  align-items: center;
  gap: 8px 12px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 16px;
}

.brand {
  grid-area: brand;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--accent);
  font: 600 1.15rem var(--serif);
  text-decoration: none;
}

.brand--light { color: #fff; }

.search {
  grid-area: search;
  position: relative;
  display: flex;
  align-items: center;
}

.search .icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}

.search__results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: min(60vh, 460px);
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search__results[hidden] { display: none; }

.search__group {
  padding: 8px 10px 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.search__option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
}

.search__option:hover,
.search__option[aria-selected="true"] { background: var(--sunken); }

.search__option img,
.search__thumb {
  flex: none;
  width: 36px;
  height: 54px;
  border-radius: 3px;
  background: var(--sunken);
  object-fit: cover;
}

.search__option .avatar { flex: none; }

.search__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.search__text strong,
.search__text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search__text span {
  color: var(--muted);
  font-size: 0.82rem;
}

.search__empty {
  padding: 14px 10px;
  color: var(--muted);
  text-align: center;
}

.search__all {
  justify-content: center;
  color: var(--accent);
  font-weight: 500;
}

.search input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px 8px 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--sunken);
  color: var(--ink);
  font: inherit;
}

.menu {
  grid-area: menu;
  position: relative;
}

.menu summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  border-radius: 50%;
}

.menu summary::-webkit-details-marker { display: none; }

.menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.menu__name {
  padding: 8px 10px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

.menu__panel a,
.menu__panel button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu__panel a:hover,
.menu__panel button:hover { background: var(--sunken); }

/* Phones get a bottom tab bar, within thumb reach. */
.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  view-transition-name: tabbar;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: 6px 2px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
}

.nav a[aria-current="page"] { color: var(--accent); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.72rem;
  font-weight: 600;
}

.nav .badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 6px);
}

/* Page */

.page {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  /* Keeps the end of the page clear of the phone tab bar. */
  padding: 24px 16px calc(80px + env(safe-area-inset-bottom));
}

.narrow {
  max-width: 600px;
  margin: 0 auto;
}

.narrow > h1 { margin-bottom: 4px; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 24px;
}

.section { margin-top: 32px; }

.section > h2,
.section-title { margin-bottom: 16px; }

.page-head + .section { margin-top: 0; }

.footer {
  display: none;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

.notice {
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-weight: 500;
}

.notice--success { background: var(--success-soft); color: var(--success); }
.notice--error { background: var(--danger-soft); color: var(--danger); }
.notice--info { background: var(--sunken); color: var(--ink); font-weight: 400; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: 500 0.95rem var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms, border-color 150ms;
}

.btn:disabled { opacity: 0.6; cursor: progress; }
.btn--block { width: 100%; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: var(--sunken); }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); }

.btn-text {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  text-decoration: underline;
  cursor: pointer;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--sunken);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}

.tag--success,
.tag--accepted { background: var(--success-soft); color: var(--success); }
.tag--pending { background: var(--warn-soft); color: var(--warn); }
.tag--declined { background: var(--danger-soft); color: var(--danger); }
.tag--completed { background: var(--success-soft); color: var(--success); }
.tag--give { background: var(--success-soft); color: var(--success); }
.tag--swap { background: var(--warn-soft); color: var(--warn); }
.tag--overdue { background: var(--danger-soft); color: var(--danger); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.filters__city {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.filters__city select { width: auto; min-width: 150px; }

.book-facts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.book-facts li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.book-facts .icon {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.request-form {
  width: 100%;
  max-width: 480px;
  margin-top: 8px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  border: 0;
}

.choices legend {
  margin-bottom: 4px;
  padding: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.swap__note {
  margin: 0;
  padding: 8px 12px;
  background: var(--sunken);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  overflow-x: auto;
  background: var(--sunken);
  border-radius: 10px;
}

.tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.tabs a[aria-current="page"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.tabs--spaced {
  width: fit-content;
  max-width: 100%;
  margin-bottom: 24px;
}

/* Book covers */

.cover {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: var(--sunken);
  box-shadow: var(--shadow);
}

.cover--blank {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: 12% 10%;
  overflow: hidden;
  color: #fff;
  border-left: 6px solid rgb(0 0 0 / 22%);
}

.cover__title {
  font: 600 clamp(0.85rem, 0.75rem + 0.5vw, 1.1rem)/1.2 var(--serif);
  overflow-wrap: anywhere;
}

.cover__author {
  font-size: 0.72rem;
  opacity: 0.9;
}

.cover--tone-0 { background: #7a3b22; }
.cover--tone-1 { background: #24505c; }
.cover--tone-2 { background: #4a5a2b; }
.cover--tone-3 { background: #5d3a5c; }
.cover--tone-4 { background: #2e4470; }
.cover--tone-5 { background: #7d5a16; }

/* Book cards */

.book-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px 16px;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.book-card__link { text-decoration: none; }

.book-card__link:hover .book-card__title { color: var(--accent); }

.book-card__title {
  margin-top: 10px;
  overflow-wrap: anywhere;
  transition: color 150ms;
}

.book-card__meta {
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.book-card__where {
  display: flex;
  align-items: center;
  gap: 4px;
}

.book-card__where .icon {
  width: 14px;
  height: 14px;
}

.book-card .tag {
  align-self: flex-start;
  margin-top: 4px;
  white-space: normal;
}

.book-card__action {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: flex-end;
  margin-top: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 32px;
}

/* Book detail */

.book-detail {
  display: grid;
  gap: 24px;
}

.book-detail__cover {
  width: min(60vw, 240px);
  margin: 0 auto;
}

.book-detail__info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.book-detail__author { font-size: 1.1rem; }

.person {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  text-decoration: none;
}

.person > span:last-child {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.person .muted { font-size: 0.85rem; }

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: var(--sunken);
  color: var(--accent);
  font-weight: 600;
  object-fit: cover;
}

.avatar--40 { width: 40px; height: 40px; font-size: 0.85rem; }
.avatar--80 { width: 80px; height: 80px; font-size: 1.5rem; }

/* Feedback */

.feedback { max-width: 720px; }

.feedback__list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
}

.feedback__item {
  display: flex;
  gap: 12px;
}

.feedback__body {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.feedback__reply {
  margin: 8px 0 0;
  padding: 10px 14px;
  background: var(--sunken);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
}

.feedback__reply strong {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.feedback__respond summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

/* People and profile */

.people {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.people .person {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.profile-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.profile-head__text {
  flex: 1;
  min-width: 200px;
  overflow-wrap: anywhere;
}

/* Requests */

.swap-list {
  display: grid;
  gap: 12px;
}

.swap {
  display: flex;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.swap__cover {
  flex: none;
  width: 72px;
  text-decoration: none;
}

.swap__cover .cover__author { display: none; }
.swap__cover .cover__title { font-size: 0.62rem; }

.swap__body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.swap__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px 12px;
}

.swap__head a { text-decoration: none; }
.swap__head a:hover { color: var(--accent); }

.contact {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px;
  background: var(--success-soft);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.contact h4 {
  margin: 0;
  font-size: 0.9rem;
}

/* Accepting a loan */

.due-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.due-form label { font-size: 0.9rem; font-weight: 600; }
.due-form input[type="date"] { width: auto; }

/* Ratings and reports */

.rating-summary { color: var(--warn); font-weight: 600; }

.star-choice {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
}

.star-choice legend { margin-bottom: 4px; padding: 0; font-size: 0.9rem; font-weight: 600; }

.star-choice label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.star-choice input {
  width: 20px;
  height: 20px;
  min-height: 0;
  accent-color: var(--accent);
}

.star-choice label:has(input:checked) { border-color: var(--accent); background: var(--sunken); }

.report summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
}

.report[open] { width: 100%; max-width: 420px; }

/* Admin */

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 16px;
}

.admin-nav a { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; font-weight: 500; }
.admin-nav a[aria-current="page"] { color: var(--accent); }
.admin-nav form { margin-left: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stat strong { display: block; font: 600 1.8rem var(--serif); }

.admin-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }

.admin-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}

.admin-row__main { flex: 1 1 280px; min-width: 0; }
.admin-row__actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.admin-row details summary { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.admin-row details[open] { flex-basis: 100%; }
.admin-search { display: flex; gap: 8px; max-width: 520px; margin-bottom: 16px; }
.admin-search input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #8f8576;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.prose { max-width: 720px; }
.prose h2 { margin-top: 36px; margin-bottom: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.prose h3 { margin-top: 18px; margin-bottom: 6px; }
.prose p { margin-bottom: 10px; }
.prose__contents { margin: 12px 0 0; padding: 12px 16px 12px 32px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.prose li { margin-bottom: 6px; }

/* Forms */

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
}

.form__row {
  display: grid;
  gap: 16px;
}

.form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > label {
  font-size: 0.9rem;
  font-weight: 600;
}

.optional {
  color: var(--muted);
  font-weight: 400;
}

input:not([type="checkbox"], [type="hidden"], [type="search"]),
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #8f8576;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

textarea { resize: vertical; }

.help {
  color: var(--muted);
  font-size: 0.85rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 0.9rem;
}

.check input {
  flex: none;
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.upload {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1.5px dashed #8f8576;
  border-radius: var(--radius);
  transition: background-color 150ms, border-color 150ms;
}

.upload:hover,
.upload--drag {
  background: var(--sunken);
  border-color: var(--accent);
}

.upload:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.upload--error { border-color: var(--danger); }
.upload--error .help { color: var(--danger); }

.upload__picture {
  flex: none;
  display: grid;
  place-items: center;
  width: 72px;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: var(--sunken);
  border-radius: 6px;
}

.upload--round .upload__picture {
  width: 80px;
  aspect-ratio: 1;
  border-radius: 50%;
}

.upload__picture > [hidden] { display: none; }

.upload__current,
.upload__current .cover { width: 100%; }
.upload__current .cover { box-shadow: none; border-radius: 0; }
.upload__current .cover__author { display: none; }
.upload__current .cover__title { font-size: 0.55rem; }

.upload__placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.upload__placeholder .icon { width: 26px; height: 26px; }

.upload__preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.upload__text strong { color: var(--accent); font-weight: 600; }

/* Invisible, but it fills the box so a click or a dropped file lands on the real input. */
input.upload__input.upload__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.upload__clear {
  position: relative;
  z-index: 1;
  flex: none;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  margin: 0;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel legend {
  float: left;
  width: 100%;
  padding: 0;
  font: 600 1.15rem var(--serif);
}

.panel legend + * { clear: both; }

.panel--danger {
  align-items: flex-start;
  margin-top: 32px;
  border-color: var(--danger);
}

/* Landing page */

.landing {
  flex: 1;
  width: 100%;
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

.landing > .notice { max-width: 1200px; margin: 16px auto; }

.hero {
  display: flex;
  align-items: center;
  min-height: min(70vh, 560px);
  padding: 48px 16px;
  color: #fff;
  background: linear-gradient(90deg, rgb(20 14 8 / 88%), rgb(20 14 8 / 55%)), url("bookwall.jpg") center / cover #2a2118;
}

.hero__inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.hero h1 {
  max-width: 16em;
  font-size: clamp(2rem, 1.4rem + 3vw, 3.6rem);
}

.hero__lead {
  max-width: 34em;
  font-size: 1.1rem;
}

.btn--large {
  min-height: 52px;
  padding: 12px 24px;
  font-size: 1.05rem;
}

.btn--light { background: #fff; color: #221d17; }
.btn--light:hover { background: #f1ece3; }
.hero .btn--primary { background: #a8431a; color: #fff; }
.hero .btn--primary:hover { background: #8b3613; }

.landing__section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 16px;
}

.landing__section--tint {
  max-width: none;
  background: var(--sunken);
}

.landing__inner {
  max-width: 1200px;
  margin: 0 auto;
}

.landing__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin-bottom: 20px;
}

.landing__section h2 { font-size: clamp(1.4rem, 1.2rem + 1vw, 1.9rem); }

.steps {
  display: grid;
  gap: 16px;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.steps h3 { margin-bottom: 6px; font-size: 1.15rem; }

.landing__cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.landing__cta p { max-width: 36em; }

select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #8f8576;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

/* Sign in and sign up */

.auth {
  display: grid;
  grid-template-rows: auto 1fr;
}

.auth__aside {
  padding: 20px 16px;
  color: #fff;
  background: linear-gradient(rgb(20 14 8 / 70%), rgb(20 14 8 / 80%)), url("bookwall.jpg") center / cover #2a2118;
}

.auth__pitch {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 480px;
}

.auth__quote {
  font: 600 clamp(1.3rem, 1rem + 2vw, 2.6rem)/1.15 var(--serif);
}

.auth__main {
  display: flex;
  justify-content: center;
  padding: 32px 16px 48px;
}

.auth__card {
  width: 100%;
  max-width: 420px;
}

.auth__switch {
  margin-top: 20px;
  text-align: center;
}

/* Tablet */

@media (min-width: 640px) {
  .book-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px 20px; }
  .form__row { grid-template-columns: 1fr 1fr; }
  .people { grid-template-columns: repeat(2, 1fr); }
  .swap__cover { width: 88px; }
  .steps { grid-template-columns: repeat(3, 1fr); }
  .book-detail { grid-template-columns: 240px 1fr; gap: 32px; }
  .book-detail__cover { width: 100%; margin: 0; }
}

/* Desktop: the tab bar moves up into the header. */

@media (min-width: 960px) {
  .topbar {
    position: sticky;
    top: 0;
  }

  [id] { scroll-margin-top: 80px; }

  .topbar__inner {
    grid-template-columns: auto minmax(200px, 1fr) auto auto;
    grid-template-areas: "brand search nav menu";
    gap: 20px;
    padding: 10px 24px;
  }

  .nav {
    grid-area: nav;
    position: static;
    view-transition-name: none;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
  }

  .nav a {
    flex-direction: row;
    gap: 8px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.92rem;
  }

  .nav a:hover { background: var(--sunken); color: var(--ink); }
  .nav a[aria-current="page"] { background: var(--sunken); }

  .nav .badge { position: static; }

  .nav__add.nav__add {
    margin-left: 6px;
    background: var(--accent);
    color: var(--on-accent);
  }

  .nav__add.nav__add:hover { background: var(--accent-hover); color: var(--on-accent); }

  .page { padding: 32px 24px 56px; }
  .landing { padding-bottom: 0; }
  .hero { padding: 64px 24px; }
  .landing__section { padding: 56px 24px; }
  .footer { display: block; }
  .book-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .book-detail { grid-template-columns: 300px 1fr; gap: 48px; }

  .auth {
    grid-template-rows: none;
    grid-template-columns: 1fr 1fr;
  }

  /* The brand sits at the top, with the message centered in the panel. */
  .auth__aside {
    position: relative;
    display: flex;
    align-items: center;
    padding: 48px;
  }

  .auth__pitch .brand {
    position: absolute;
    top: 32px;
    left: 48px;
  }

  .auth__main { align-items: center; padding: 48px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
