:root {
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "Avenir Next", Avenir, Seravek, "Segoe UI", system-ui, sans-serif;
  --paper: #f7f3ed;
  --paper-raised: #fffdf9;
  --paper-soft: #ebe4dc;
  --ink: #291f22;
  --ink-soft: #6f6266;
  --ink-faint: #94868a;
  --line: #ddd3cb;
  --line-strong: #b9aaa2;
  --accent: #882d48;
  --accent-hover: #74243b;
  --accent-ink: #fffaf7;
  --gold: #9b661d;
  --success: #28684a;
  --success-soft: #dcebe1;
  --danger: #a13b42;
  --shadow-small: 0 2px 8px rgb(64 38 45 / 8%);
  --shadow-cover: 0 7px 16px rgb(55 32 38 / 20%), -2px 0 0 rgb(66 39 44 / 10%);
  --shadow-cover-hover: 0 15px 28px rgb(55 32 38 / 24%), -2px 0 0 rgb(66 39 44 / 10%);
  --radius: 8px;
  --header-height: 72px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #191316;
    --paper-raised: #241b1f;
    --paper-soft: #302329;
    --ink: #f1e7e0;
    --ink-soft: #bdabb0;
    --ink-faint: #927f85;
    --line: #3c2d33;
    --line-strong: #5a424b;
    --accent: #d1647f;
    --accent-hover: #df7890;
    --accent-ink: #241015;
    --gold: #d8a14b;
    --success: #7fba91;
    --success-soft: #21372b;
    --danger: #e07a7f;
    --shadow-small: 0 2px 10px rgb(0 0 0 / 24%);
    --shadow-cover: 0 8px 18px rgb(0 0 0 / 45%), -2px 0 0 rgb(255 255 255 / 5%);
    --shadow-cover-hover: 0 16px 30px rgb(0 0 0 / 55%), -2px 0 0 rgb(255 255 255 / 5%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #191316;
  --paper-raised: #241b1f;
  --paper-soft: #302329;
  --ink: #f1e7e0;
  --ink-soft: #bdabb0;
  --ink-faint: #927f85;
  --line: #3c2d33;
  --line-strong: #5a424b;
  --accent: #d1647f;
  --accent-hover: #df7890;
  --accent-ink: #241015;
  --gold: #d8a14b;
  --success: #7fba91;
  --success-soft: #21372b;
  --danger: #e07a7f;
  --shadow-small: 0 2px 10px rgb(0 0 0 / 24%);
  --shadow-cover: 0 8px 18px rgb(0 0 0 / 45%), -2px 0 0 rgb(255 255 255 / 5%);
  --shadow-cover-hover: 0 16px 30px rgb(0 0 0 / 55%), -2px 0 0 rgb(255 255 255 / 5%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  min-width: 280px;
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(90% 48rem at 50% -22rem, color-mix(in srgb, var(--gold) 7%, transparent), transparent),
    var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button,
input { font: inherit; }

button,
summary { -webkit-tap-highlight-color: transparent; }

button { color: inherit; }

a { color: inherit; }

img { display: block; max-width: 100%; }

h1,
h2,
h3,
h4,
p { margin-top: 0; }

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  line-height: 1.05;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

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

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  transform: translateY(-150%);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-weight: 750;
}

.skip-link:focus { transform: translateY(0); }

.shell {
  width: min(100% - 32px, 1280px);
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--header-height);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  background: color-mix(in srgb, var(--paper-raised) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.header-inner {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand,
.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font: 750 1.27rem/1 var(--font-display);
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  transform: rotate(45deg);
  background: var(--gold);
}

.desktop-nav {
  display: none;
  align-items: stretch;
  align-self: stretch;
  gap: 4px;
}

.desktop-nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.desktop-nav a:hover { color: var(--ink); }

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

.desktop-nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: 0;
  left: 12px;
  height: 3px;
  background: var(--accent);
}

.account-menu {
  position: relative;
  margin-left: auto;
}

.account-menu summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 9px;
  list-style: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 700;
}

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

.account-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--paper-raised);
  color: var(--ink);
  font-weight: 800;
}

.account-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  box-shadow: 0 16px 36px rgb(47 29 35 / 16%);
}

.account-popover p {
  margin: 0 4px 8px;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.menu-button {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
}

.menu-button:hover { background: var(--paper-soft); }
.menu-button.danger { color: var(--danger); }
.menu-link { display: flex; align-items: center; color: var(--ink); text-decoration: none; }

.mobile-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 25;
  min-height: 66px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px max(12px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-raised) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.mobile-nav a {
  min-height: 48px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 800;
  text-decoration: none;
}

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

.app-body main { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }

.button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.button:active { transform: translateY(1px); }
.button:disabled { cursor: wait; opacity: 0.68; }
.button.primary { background: var(--accent); color: var(--accent-ink); }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary { border-color: var(--line-strong); background: var(--paper-raised); color: var(--ink); }
.button.secondary:hover { border-color: var(--ink-soft); }

.kicker {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 850;
  letter-spacing: 0.01em;
}

.library-app { padding-top: clamp(30px, 6vw, 72px); }

.search-hero {
  display: grid;
  gap: 24px;
  padding-bottom: clamp(28px, 5vw, 54px);
  border-bottom: 1px solid var(--line);
}

.search-intro { min-width: 0; }

.search-intro h1 {
  max-width: 17ch;
  margin-bottom: 12px;
  font-size: clamp(2.55rem, 11vw, 4.4rem);
}

.hero-copy {
  max-width: 45ch;
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: clamp(0.98rem, 2vw, 1.08rem);
}

.search-form {
  min-width: 0;
  display: grid;
  gap: 10px;
  align-self: end;
}

.search-form input {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  box-shadow: var(--shadow-small);
  font-size: 1rem;
}

.search-form input::placeholder { color: var(--ink-faint); }
.search-button { min-height: 54px; }

.relationship-panel {
  padding: clamp(30px, 5vw, 54px) 0;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}

.section-heading h2 { margin-bottom: 0; font-size: clamp(1.8rem, 4vw, 2.55rem); }
.section-heading > p { max-width: 47ch; margin-bottom: 0; color: var(--ink-soft); }

.relationship-groups { display: grid; gap: 24px; }
.relationship-group h3 { margin-bottom: 10px; font: 800 0.83rem/1.2 var(--font-ui); color: var(--ink-soft); }
.relationship-links { display: flex; flex-wrap: wrap; gap: 8px; }

.relationship-links a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  font-size: 0.84rem;
  font-weight: 750;
  text-decoration: none;
}

.relationship-links a:hover { border-color: var(--accent); color: var(--accent); }

.results-section { padding: 20px 0 48px; }

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.result-copy { min-width: 0; }
.result-copy strong,
.result-copy span { display: block; }
.result-copy strong { font: 800 1.08rem/1.25 var(--font-display); }
.result-copy span { margin-top: 2px; color: var(--ink-soft); font-size: 0.76rem; }

.view-switch {
  flex: 0 0 auto;
  display: flex;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--paper-soft);
}

.view-switch button {
  min-height: 40px;
  padding: 0 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 800;
}

.view-switch button[aria-pressed="true"] {
  background: var(--paper-raised);
  color: var(--ink);
  box-shadow: var(--shadow-small);
}

.filter-row {
  display: flex;
  gap: 6px;
  padding-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-row::-webkit-scrollbar { display: none; }

.filter-row button {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.filter-row button[aria-pressed="true"] {
  border-color: var(--line-strong);
  background: var(--paper-raised);
  color: var(--ink);
}

.filter-row span { color: var(--ink-faint); }

.state-panel {
  min-height: 148px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper-raised) 72%, transparent);
}

.state-panel p { margin-bottom: 0; color: var(--ink-soft); }
.state-panel .state-title { margin-bottom: 5px; color: var(--ink); font: 800 1.15rem/1.25 var(--font-display); }
.welcome-state { align-items: flex-end; }
.welcome-state > div:first-child { max-width: 46ch; }
.welcome-examples { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }

.welcome-examples button {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  cursor: pointer;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
}

.loading-state { justify-content: flex-start; }

.loading-mark {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

@keyframes spin { to { transform: rotate(1turn); } }

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

.book-card { min-width: 0; }

.book-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.cover-media {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 2px 6px 6px 2px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 80%, #6d5f39), color-mix(in srgb, var(--ink) 82%, #6d5f39));
  box-shadow: var(--shadow-cover);
  isolation: isolate;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.cover-media::after {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 0 auto 0 0;
  width: 9px;
  background: linear-gradient(90deg, rgb(0 0 0 / 25%), rgb(255 255 255 / 8%), transparent);
  pointer-events: none;
}

.cover-media img {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-fallback {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 15px 13px;
  color: #fff8ee;
}

.cover-fallback small { font-size: 0.62rem; font-weight: 800; letter-spacing: 0.05em; }
.cover-fallback strong { margin-top: 6px; font: 800 clamp(0.9rem, 4vw, 1.2rem)/1.02 var(--font-display); }

.book-link:hover .cover-media {
  transform: translateY(-4px);
  box-shadow: var(--shadow-cover-hover);
}

.book-card h2 {
  margin: 10px 0 2px;
  overflow-wrap: anywhere;
  font-size: clamp(0.93rem, 2vw, 1.08rem);
  line-height: 1.18;
}

.book-author {
  margin-bottom: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.format-line {
  margin-top: 7px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.01em;
}

.owned-line { margin-top: 3px; color: var(--success); font-size: 0.68rem; font-weight: 800; }

.book-list { border-top: 1px solid var(--line); }

.book-list-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 4px 12px;
  align-items: center;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}

.book-list-row:hover { background: color-mix(in srgb, var(--paper-raised) 56%, transparent); }

.list-cover {
  position: relative;
  grid-row: 1 / 3;
  width: 40px;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 1px 4px 4px 1px;
  background: linear-gradient(145deg, var(--accent), var(--ink));
  box-shadow: 0 3px 7px rgb(55 32 38 / 18%);
}

.list-cover img { width: 100%; height: 100%; object-fit: cover; }
.list-title { min-width: 0; }
.list-title strong,
.list-title span { display: block; }
.list-title strong { overflow-wrap: anywhere; font: 800 0.94rem/1.2 var(--font-display); }
.list-title span { margin-top: 3px; color: var(--ink-soft); font-size: 0.73rem; }
.list-format { color: var(--accent); font-size: 0.7rem; font-weight: 800; }
.list-meta { display: none; color: var(--ink-soft); font-size: 0.74rem; text-align: right; }

.book-detail { padding-top: 6px; }
.back-link { min-height: 44px; display: inline-flex; align-items: center; margin-bottom: 18px; color: var(--ink-soft); font-size: 0.8rem; font-weight: 800; text-decoration: none; }
.back-link:hover { color: var(--accent); }

.book-detail-layout {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 18px;
}

.book-detail-cover { width: 100%; }
.book-detail-copy { min-width: 0; }
.book-detail-copy h1 { margin: 0 0 7px; overflow-wrap: anywhere; font-size: clamp(2rem, 9vw, 4rem); }

.book-byline {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.book-byline a { color: var(--accent); text-underline-offset: 3px; }
.book-context { grid-column: 1 / -1; margin: 2px 0 0; color: var(--ink-soft); font-size: 0.9rem; }

.format-stack {
  grid-column: 1 / -1;
  margin-top: 12px;
  border-top: 1px solid var(--line-strong);
}

.format-section { padding: 22px 0; border-bottom: 1px solid var(--line); }

.format-section-main {
  display: grid;
  gap: 14px;
}

.format-heading h2 { margin-bottom: 3px; font-size: 1.35rem; }
.format-heading p { margin-bottom: 0; color: var(--ink-soft); font-size: 0.75rem; }
.edition-facts { min-width: 0; }
.edition-facts strong { display: block; margin-bottom: 4px; font-size: 0.87rem; }
.edition-facts p { margin-bottom: 0; color: var(--ink-soft); font-size: 0.76rem; overflow-wrap: anywhere; }
.format-action { width: 100%; }

.edition-options { margin-top: 14px; }
.edition-options summary { min-height: 44px; display: inline-flex; align-items: center; cursor: pointer; color: var(--accent); font-size: 0.75rem; font-weight: 850; }
.edition-option { display: grid; gap: 10px; padding: 14px 0; border-top: 1px solid var(--line); }
.edition-option .button { width: 100%; }

.book-note {
  grid-column: 1 / -1;
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--paper-soft);
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.page-heading { max-width: 760px; padding: clamp(38px, 7vw, 82px) 0 28px; }
.page-heading h1 { margin-bottom: 12px; font-size: clamp(2.6rem, 8vw, 4.6rem); }
.page-heading > p:last-child { max-width: 52ch; margin-bottom: 0; color: var(--ink-soft); }

.downloads-page { padding-bottom: 36px; }
.download-section { margin-top: 30px; }
.download-section-heading { display: flex; align-items: baseline; gap: 9px; margin-bottom: 6px; }
.download-section-heading h2 { margin-bottom: 0; font-size: 1.35rem; }
.download-section-heading span { color: var(--ink-soft); font-size: 0.75rem; }
.download-list { border-top: 1px solid var(--line-strong); }

.download-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 8px 12px;
  align-items: center;
  padding: 16px 2px;
  border-bottom: 1px solid var(--line);
}

.download-thumb {
  grid-row: 1 / 3;
  width: 42px;
  aspect-ratio: 2 / 3;
  display: grid;
  place-items: center;
  border-radius: 1px 4px 4px 1px;
  background: linear-gradient(145deg, var(--accent), var(--ink));
  color: var(--accent-ink);
  box-shadow: 0 3px 7px rgb(55 32 38 / 18%);
  font: 800 0.72rem/1 var(--font-display);
}

.download-title { min-width: 0; }
.download-title strong,
.download-title span { display: block; }
.download-title strong { overflow-wrap: anywhere; font: 800 0.92rem/1.2 var(--font-display); }
.download-title span { margin-top: 3px; color: var(--ink-soft); font-size: 0.72rem; }
.download-status { grid-column: 2; }
.download-status p { margin-bottom: 5px; color: var(--ink-soft); font-size: 0.73rem; }

.progress-track {
  width: 100%;
  max-width: 280px;
  height: 5px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--paper-soft);
}

.progress-track span { display: block; height: 100%; background: var(--accent); }
.ready-label { color: var(--success); font-size: 0.74rem; font-weight: 850; }
.download-actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: 8px; }
.download-actions .button { flex: 1 1 130px; }

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 50;
  max-width: 420px;
  margin-left: auto;
  padding: 13px 15px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 15px 36px rgb(32 20 24 / 28%);
  font-size: 0.82rem;
  font-weight: 750;
}

.login-body { padding: 24px 16px; }

.login-layout {
  width: min(100%, 980px);
  min-height: calc(100dvh - 48px);
  display: grid;
  align-items: center;
  gap: 36px;
  margin: 0 auto;
}

.login-welcome { max-width: 510px; }
.login-brand { margin-bottom: 34px; }
.login-welcome h1 { max-width: 10ch; margin-bottom: 17px; font-size: clamp(3rem, 13vw, 5.5rem); }
.login-welcome > p { max-width: 42ch; color: var(--ink-soft); font-size: 1.02rem; }

.book-spines {
  height: 86px;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  margin-top: 34px;
  padding-bottom: 7px;
  border-bottom: 7px solid var(--gold);
}

.book-spines i { display: block; width: 24px; border-radius: 2px 3px 0 0; background: var(--accent); box-shadow: inset -3px 0 rgb(0 0 0 / 12%); }
.book-spines i:nth-child(1) { height: 58px; }
.book-spines i:nth-child(2) { height: 74px; background: #496b63; }
.book-spines i:nth-child(3) { width: 32px; height: 64px; background: #c07a32; }
.book-spines i:nth-child(4) { height: 80px; background: #675b82; }
.book-spines i:nth-child(5) { width: 20px; height: 51px; background: #a6554d; }
.book-spines i:nth-child(6) { width: 29px; height: 70px; background: #56709a; }

.login-card {
  width: min(100%, 420px);
  justify-self: end;
  padding: clamp(24px, 6vw, 38px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  box-shadow: 0 20px 55px rgb(55 32 38 / 12%);
}

.login-card h2 { margin-bottom: 26px; font-size: 2.1rem; }
.field { margin-bottom: 18px; }
.field label { display: block; margin-bottom: 6px; font-size: 0.79rem; font-weight: 800; }
.field input { width: 100%; min-height: 50px; padding: 0 13px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--paper); color: var(--ink); font-size: 1rem; }
.field input::placeholder { color: var(--ink-faint); }
.login-button { width: 100%; min-height: 50px; }
.form-error { min-height: 1.25em; margin: 12px 0 0; color: var(--danger); font-size: 0.8rem; font-weight: 750; }
.form-success { min-height: 1.25em; margin: 12px 0 0; color: var(--success); font-size: 0.8rem; font-weight: 750; }
.auth-link { margin: 18px 0 0; text-align: center; font-size: 0.82rem; }
.auth-link a { color: var(--accent); }
.login-note { margin: 22px 0 0; color: var(--ink-faint); font-size: 0.74rem; text-align: center; }

.auth-layout {
  width: min(100%, 460px);
  min-height: calc(100dvh - 48px);
  display: grid;
  align-items: center;
  margin: 0 auto;
}

.auth-card { width: 100%; justify-self: stretch; }
.auth-card h1 { margin-bottom: 12px; font-size: clamp(2rem, 8vw, 2.75rem); }
.auth-card > p:not(.kicker) { margin-bottom: 24px; color: var(--ink-soft); }

.account-page { padding-top: clamp(36px, 7vw, 80px); padding-bottom: 72px; }
.account-card {
  width: min(100%, 620px);
  padding: clamp(24px, 5vw, 42px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  box-shadow: var(--shadow-small);
}
.account-card h1 { margin-bottom: 12px; font-size: clamp(2.2rem, 7vw, 3.4rem); }
.account-card > p { color: var(--ink-soft); }
.account-card form { margin-top: 28px; }
.recovery-note { padding: 12px 14px; border-radius: var(--radius); background: var(--paper-soft); font-size: 0.86rem; }
.recovery-note.warning { color: var(--danger); }

@media (min-width: 560px) {
  .shell { width: min(100% - 48px, 1280px); }
  .search-form { grid-template-columns: minmax(0, 1fr) auto; }
  .search-button { min-width: 118px; }
  .book-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 34px 20px; }
  .format-section-main { grid-template-columns: 110px minmax(0, 1fr) auto; align-items: center; }
  .format-action { width: auto; }
  .edition-option { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .edition-option .button { width: auto; }
}

@media (min-width: 760px) {
  .shell { width: min(100% - 64px, 1280px); }
  .desktop-nav { display: flex; }
  .account-name { display: inline; }
  .mobile-nav { display: none; }
  .app-body main { padding-bottom: 0; }
  .toast { bottom: 24px; }
  .relationship-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 40px 24px; }
  .book-list-row { grid-template-columns: 48px minmax(0, 1.2fr) minmax(160px, 0.65fr) minmax(120px, 0.4fr); gap: 14px; padding: 13px 4px; }
  .list-cover { grid-row: auto; width: 44px; }
  .list-format { text-align: right; }
  .list-meta { display: block; }
  .download-row { grid-template-columns: 50px minmax(0, 1.2fr) minmax(220px, 0.7fr) auto; gap: 16px; padding: 18px 4px; }
  .download-thumb { grid-row: auto; width: 46px; }
  .download-status { grid-column: auto; }
  .download-actions { grid-column: auto; justify-content: flex-end; }
  .download-actions .button { flex: 0 0 auto; }
  .login-layout { grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); }
}

@media (min-width: 920px) {
  .book-detail-layout { grid-template-columns: minmax(190px, 250px) minmax(0, 1fr); gap: 38px; }
  .book-detail-cover { grid-row: 1 / 5; }
  .book-context,
  .format-stack,
  .book-note { grid-column: 2; }
  .book-context { margin-top: 8px; }
  .format-stack { margin-top: 20px; }
}

@media (min-width: 1080px) {
  .search-hero {
    grid-template-columns: minmax(300px, 0.78fr) minmax(520px, 1.22fr);
    gap: clamp(38px, 5vw, 70px);
    align-items: end;
  }
  .search-intro h1 { font-size: clamp(3.4rem, 5.3vw, 4.7rem); }
  .book-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (max-width: 559px) {
  .welcome-state { align-items: stretch; flex-direction: column; }
  .welcome-examples { justify-content: flex-start; }
  .state-panel.error-state { align-items: stretch; flex-direction: column; }
}

@media (max-width: 759px) {
  .login-layout { align-content: center; }
  .login-card { justify-self: stretch; }
  .book-spines { display: none; }
  .login-welcome { padding-top: 18px; }
  .login-welcome h1 { max-width: 12ch; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .site-header,
  .mobile-nav { background: var(--paper-raised); backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* ---------- Hardcover metadata (book detail) ---------- */
.book-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 14px 0 0;
  font-family: var(--font-ui);
}

.rating-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  color: var(--gold);
}

.rating-badge svg { align-self: center; }
.rating-badge strong { font-size: 1.05rem; color: var(--ink); }
.rating-badge span { font-size: 0.82rem; color: var(--ink-faint); }

.book-facts { font-size: 0.9rem; color: var(--ink-soft); }

.genre-chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }

.genre-chip {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-soft);
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.book-description { margin: 16px 0 0; max-width: 62ch; }

.book-description p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--ink-soft);
  white-space: pre-line;
}

.book-description p.clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
}

.text-toggle {
  margin-top: 6px;
  padding: 4px 0;
  border: 0;
  background: none;
  font: inherit;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  min-height: 44px;
}

/* ---------- member/guest roles ---------- */
.role-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

.library-note {
  margin: 4px 0 0;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--success);
}
