@import url("https://fonts.googleapis.com/css2?family=Funnel+Sans:wght@400;500;600&family=Geist+Mono:wght@400;500;600&family=Newsreader:opsz,wght@6..72,500;6..72,600&display=swap");

:root {
  --bg: #f6f1e8;
  --surface: #fcfaf7;
  --surface-strong: #ffffff;
  --surface-muted: #eee9e1;
  --ink: #17140f;
  --muted: #6e675d;
  --soft: #8a8277;
  --rule: rgba(23, 20, 15, 0.13);
  --rule-strong: rgba(23, 20, 15, 0.34);
  --accent: #d35b32;
  --accent-soft: #fff0e7;
  --accent-paper: #fff5e8;
  --success: #3f7450;
  --success-soft: #e6f1e8;
  --error: #b25a45;
  --error-soft: #f4e7e2;
  --best-bg: #1d1914;
  --best-ink: #fff8ee;
  --best-muted: #c8bfb3;
  --best-soft: #948b80;
  --focus: #2764c7;
  --shadow: rgba(23, 20, 15, 0.16);
  --font-display: "Newsreader", Georgia, serif;
  --font-body: "Funnel Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, monospace;
}

body[data-theme="dark"] {
  --bg: #11100e;
  --surface: #1b1814;
  --surface-strong: #211d18;
  --surface-muted: #2c2721;
  --ink: #f4eedf;
  --muted: #b9b0a4;
  --soft: #8f877c;
  --rule: rgba(255, 255, 255, 0.12);
  --rule-strong: rgba(255, 255, 255, 0.34);
  --accent: #e56b43;
  --accent-soft: #35241e;
  --accent-paper: #2a211b;
  --success: #72ae7b;
  --success-soft: #1f3023;
  --error: #dc8168;
  --error-soft: #36211d;
  --best-bg: #211d18;
  --best-ink: #fff8ee;
  --best-muted: #c8bfb3;
  --best-soft: #948b80;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
}

body.overlay-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

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

button {
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
.book-card:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  transform: translateY(-180%);
  border-radius: 3px;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

.skip-link:focus {
  transform: none;
}

.app-shell {
  min-height: 100dvh;
}

.site-header,
.overlay-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-inner,
.overlay-header {
  width: min(100%, 1440px);
  margin: 0 auto;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 80px;
  padding: 0 48px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.4px;
}

.brand-mark {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  background: var(--ink);
  color: var(--bg);
}

.brand-mark svg {
  width: 19px;
  height: 19px;
}

.primary-nav {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 32px;
  margin-left: auto;
  margin-right: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  height: 100%;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 3px 0 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.nav-link.active {
  border-bottom-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.source-status {
  display: flex;
  align-items: center;
  gap: 7px;
}

.source-status span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.source-status b {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.locale-switch {
  display: flex;
  gap: 2px;
  height: 34px;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 3px;
}

.locale-switch button {
  min-width: 34px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  cursor: pointer;
}

.locale-switch button.active {
  background: var(--ink);
  color: var(--bg);
}

.icon-control {
  display: inline-grid;
  width: 36px;
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  place-items: center;
  background: transparent;
  cursor: pointer;
}

.icon-control svg {
  width: 17px;
  height: 17px;
}

body[data-theme="light"] .moon-icon,
body[data-theme="dark"] .sun-icon {
  display: none;
}

.library-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 0 11px;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.library-toggle svg {
  width: 15px;
  height: 15px;
}

.library-toggle b {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9px;
}

.portal {
  width: min(100%, 1440px);
  margin: 0 auto;
}

.command-panel {
  display: grid;
  grid-template-columns: 458px minmax(0, 1fr);
  align-items: end;
  gap: 72px;
  min-height: 286px;
  padding: 44px 48px 36px;
}

.hero-copy,
.search-side {
  display: grid;
}

.hero-copy {
  gap: 10px;
}

.eyebrow,
.overline,
.control-label {
  margin: 0;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero-copy h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 50px;
  font-weight: 500;
  letter-spacing: -1.4px;
  line-height: 0.92;
}

.hero-copy > p:last-child {
  width: min(100%, 420px);
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.search-side {
  gap: 13px;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  height: 70px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  padding: 0 8px 0 18px;
  background: var(--surface-strong);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.search-box svg {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 20px;
  font-weight: 500;
}

.search-box input::placeholder {
  color: var(--soft);
}

.search-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.search-button {
  height: 54px;
  padding: 0 22px;
}

.search-button svg {
  width: 17px;
  height: 17px;
}

.search-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.quick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.quick-row > span {
  margin-right: 2px;
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.quick-row button {
  height: 30px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0 11px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.quick-row button:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.workspace {
  padding: 0 48px 30px;
}

.results-panel {
  min-height: 600px;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  gap: 24px;
}

.results-heading {
  display: flex;
  align-items: baseline;
  gap: 16px;
  min-width: 0;
}

.results-heading h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 29px;
  font-weight: 500;
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.results-heading .overline {
  color: var(--soft);
  font-size: 8px;
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: 18px;
}

.inline-select {
  display: grid;
  align-items: center;
  height: 100%;
  border-bottom: 3px solid transparent;
  padding-top: 3px;
}

.inline-select:first-child {
  border-bottom-color: var(--accent);
}

.inline-select > span {
  display: none;
}

.inline-select select,
.sort-select select {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.language-filter select {
  color: var(--muted);
  font-weight: 500;
}

.sort-select {
  display: inline-flex;
  align-items: center;
  height: 34px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0 8px;
}

.sort-select select {
  font-size: 11px;
}

.filter-button,
.source-link {
  display: none;
  align-items: center;
  justify-content: center;
  height: 38px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0 12px;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.status {
  min-height: 0;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.status:not(:empty) {
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}

.status.error {
  color: var(--error);
}

.empty-state {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  min-height: 250px;
  padding: 40px 0;
}

.empty-index {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 500;
}

.empty-state p {
  max-width: 54ch;
  margin: 0;
  color: var(--muted);
}

.results-list {
  display: grid;
}

.book-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 170px 34px 118px;
  align-items: center;
  gap: 16px;
  min-height: 80px;
  border: 0;
  border-top: 1px solid var(--rule);
  border-radius: 0;
  padding: 9px 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.book-card:hover,
.book-card.active {
  background: color-mix(in srgb, var(--surface) 62%, transparent);
}

.book-card.best-match {
  grid-template-columns: 126px minmax(0, 1fr) 220px;
  align-items: stretch;
  gap: 24px;
  min-height: 248px;
  margin: 18px 0;
  border: 0;
  padding: 20px;
  background: var(--best-bg);
  color: var(--best-ink);
}

.cover {
  display: grid;
  width: 42px;
  height: 58px;
  overflow: hidden;
  place-items: center;
  background: #596a7a;
  color: #fff8ee;
}

.book-card:nth-child(3n + 1):not(.best-match) .cover {
  background: #a77b37;
}

.book-card:nth-child(3n + 2):not(.best-match) .cover {
  background: #4e6852;
}

.book-card.best-match .cover {
  width: 126px;
  height: 208px;
  background: #c95638;
}

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

.cover svg {
  width: 18px;
  height: 18px;
}

.cover-wordmark {
  display: none;
  height: 100%;
  padding: 14px;
  flex-direction: column;
  justify-content: space-between;
  color: #fff8ee;
}

.best-match .cover-wordmark {
  display: flex;
}

.cover-wordmark b {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  line-height: 0.9;
}

.cover-wordmark small {
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.08em;
}

.book-main {
  display: grid;
  align-content: center;
  gap: 3px;
  min-width: 0;
}

.best-match .book-main {
  align-content: stretch;
  gap: 7px;
}

.best-match-label {
  margin: 0;
  color: #f08258;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.book-title-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.book-title-row h3 {
  overflow: hidden;
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.best-match .book-title-row h3 {
  overflow: visible;
  color: var(--best-ink);
  font-size: 30px;
  letter-spacing: -0.7px;
  white-space: normal;
}

.edition-count {
  display: none;
}

.book-meta,
.book-description,
.edition-meta {
  margin: 0;
}

.book-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.best-match .book-meta {
  color: var(--best-muted);
  font-size: 14px;
}

.book-description {
  display: none;
  max-width: 72ch;
  color: var(--best-soft);
  font-size: 13px;
  line-height: 1.45;
}

.best-match .book-description {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.result-metadata,
.format-row,
.badge-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.result-metadata {
  align-self: end;
  margin-top: auto;
  color: var(--best-muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge-row span {
  color: var(--success);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.format-row {
  justify-content: flex-start;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
}

.edition-meta,
.edition-details {
  display: none;
}

.book-actions {
  display: contents;
}

.book-actions-summary {
  display: grid;
  gap: 4px;
  width: 170px;
  font-family: var(--font-mono);
  font-size: 8px;
  color: var(--soft);
  text-transform: uppercase;
}

.book-actions-summary strong {
  color: var(--accent);
  font-size: 9px;
}

.best-match .book-actions {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
  padding: 2px 0 2px 22px;
}

.availability {
  display: grid;
  gap: 8px;
}

.availability small {
  color: var(--best-muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.availability strong {
  color: var(--best-ink);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
}

.icon-save {
  display: inline-grid;
  width: 34px;
  height: 34px;
  border: 0;
  place-items: center;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.icon-save.active {
  color: var(--accent);
}

.download-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0 12px;
  background: transparent;
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.book-card:not(.best-match) .download-button {
  display: none;
}

.book-card:not(.best-match) .secondary-button {
  width: 118px;
}

.best-match .icon-save {
  order: 3;
  width: 100%;
  color: var(--best-muted);
}

.best-match .icon-save.active {
  color: #f08258;
}

.best-match .download-button.primary {
  min-height: 50px;
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  font-size: 13px;
}

.best-match .secondary-button {
  min-height: 38px;
  border: 0;
  padding: 0 2px;
  justify-content: space-between;
  color: var(--best-ink);
}

.download-unavailable {
  color: var(--soft);
  font-size: 11px;
}

.skeleton {
  pointer-events: none;
}

.skeleton .cover,
.skeleton .book-main span {
  animation: pulse 1.2s ease-in-out infinite alternate;
  background: var(--surface-muted);
}

.skeleton .book-main span {
  display: block;
  width: 70%;
  height: 9px;
}

.skeleton .book-main span:nth-child(2) {
  width: 46%;
}

@keyframes pulse {
  to { opacity: 0.38; }
}

.how-it-works {
  border-top: 1px solid var(--rule);
  padding: 48px;
}

.how-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 20px;
  border-top: 1px solid var(--rule);
}

.how-grid article {
  min-height: 180px;
  border-right: 1px solid var(--rule);
  padding: 24px 28px 24px 0;
}

.how-grid article + article {
  padding-left: 28px;
}

.how-grid article:last-child {
  border-right: 0;
}

.how-grid span {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 9px;
}

.how-grid h2 {
  margin: 24px 0 6px;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 500;
}

.how-grid p {
  margin: 0;
  color: var(--muted);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(23, 20, 15, 0.62);
}

.filter-rail {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 120;
  display: grid;
  gap: 24px;
  max-height: 82dvh;
  transform: translateY(110%);
  border-radius: 12px 12px 0 0;
  padding: 10px 32px 28px;
  background: var(--bg);
  box-shadow: 0 -18px 50px var(--shadow);
  transition: transform 180ms ease;
}

.filter-rail.open {
  transform: none;
}

.filter-handle {
  width: 44px;
  height: 4px;
  margin: 0 auto;
  border-radius: 4px;
  background: var(--rule-strong);
}

.panel-heading,
.filter-actions,
.overlay-header,
.library-title-row,
.library-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-heading h2 {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 500;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}

.control-label {
  margin-bottom: 10px;
  color: var(--soft);
}

.check-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.check-list button {
  min-height: 44px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}

.check-list button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-paper);
  color: var(--accent);
  font-weight: 600;
}

.year-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.year-grid label {
  display: grid;
  gap: 5px;
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 8px;
  text-transform: uppercase;
}

.year-grid input {
  min-width: 0;
  height: 44px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0 12px;
  background: var(--surface-strong);
  color: var(--ink);
}

.filter-actions {
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--rule);
  padding-top: 18px;
}

.filter-actions .primary-button,
.filter-actions .secondary-button {
  min-width: 160px;
  min-height: 48px;
}

.library-panel,
.book-drawer {
  position: fixed;
  inset: 0;
  z-index: 110;
  overflow: auto;
  transform: translateX(102%);
  background: var(--bg);
  transition: transform 220ms ease;
}

.library-panel.open,
.book-drawer.open {
  transform: none;
}

.overlay-header {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 72px;
  padding: 0 40px;
}

.overlay-header .brand {
  font-size: 21px;
}

.overlay-header .brand-mark {
  width: 32px;
  height: 32px;
}

.overlay-header .brand-mark svg {
  width: 16px;
  height: 16px;
}

.overlay-nav {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: 28px;
  color: var(--muted);
  font-size: 13px;
}

.overlay-nav b {
  display: inline-flex;
  align-items: center;
  height: 100%;
  border-bottom: 3px solid var(--accent);
  color: var(--ink);
  font-weight: 600;
}

.library-body {
  width: min(100%, 1440px);
  min-height: calc(100dvh - 72px);
  margin: 0 auto;
  padding: 34px 40px 38px;
}

.library-title-row {
  align-items: flex-end;
}

.library-title-row h2 {
  margin: 4px 0 2px;
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.8px;
}

.library-title-row p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.library-tabs {
  display: flex;
  align-items: stretch;
  gap: 28px;
  height: 48px;
  margin-top: 22px;
  border-bottom: 1px solid var(--rule);
}

.library-tabs button {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.library-tabs button.active {
  border-bottom-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}

.library-tabs b {
  display: inline-grid;
  min-width: 24px;
  height: 20px;
  border-radius: 3px;
  place-items: center;
  background: var(--surface-muted);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 7.5px;
}

.library-tabs button.active b {
  background: var(--ink);
  color: var(--bg);
}

.library-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 30px;
  min-height: 540px;
  margin-top: 22px;
}

.library-list-header {
  height: 40px;
}

.library-list-header h3,
.library-activity h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 500;
}

.library-list-header span {
  color: var(--muted);
  font-size: 10.5px;
}

.stack-list {
  display: grid;
}

.library-list {
  display: none;
}

.library-list.active {
  display: grid;
}

.library-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 90px;
  border-top: 1px solid var(--rule);
  padding: 12px 0;
}

.library-item-cover {
  display: grid;
  width: 46px;
  height: 66px;
  place-items: center;
  background: #596a7a;
  color: #fff8ee;
}

.library-item:nth-child(3n + 1) .library-item-cover {
  background: #c95638;
}

.library-item:nth-child(3n + 2) .library-item-cover {
  background: #a77b37;
}

.library-item-cover svg {
  width: 15px;
  height: 15px;
}

.library-item-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.library-item-copy strong {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-item-copy span {
  color: var(--muted);
  font-size: 10.5px;
}

.library-item-copy small {
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.library-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.library-item-actions button,
.library-item-actions a {
  min-height: 36px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0 10px;
  background: transparent;
  color: var(--ink);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
}

.library-item-actions .complete {
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  background: var(--success-soft);
  color: var(--success);
}

.library-activity {
  display: grid;
  align-content: start;
  gap: 16px;
  border-left: 1px solid var(--rule);
  padding-left: 24px;
}

.activity-card {
  display: grid;
  gap: 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: 4px;
  padding: 13px;
  background: var(--accent-paper);
}

.activity-card:empty {
  display: none;
}

.activity-card strong {
  font-size: 11px;
}

.activity-card small {
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 7.5px;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 18%, var(--bg));
}

.progress-track span {
  display: block;
  width: 68%;
  height: 100%;
  background: var(--accent);
}

.recent-searches {
  display: grid;
}

.recent-searches > b {
  margin-bottom: 6px;
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.recent-searches button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 0;
  background: transparent;
  font-size: 10.5px;
  cursor: pointer;
}

.recent-searches button small {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 7.5px;
}

.library-danger {
  display: grid;
  justify-items: start;
  gap: 4px;
  border-top: 1px solid var(--rule);
  padding-top: 10px;
}

.text-button {
  min-height: 30px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--soft);
  font-size: 10px;
  cursor: pointer;
}

.muted {
  margin: 20px 0;
  color: var(--muted);
}

.book-drawer {
  z-index: 130;
}

.drawer-breadcrumb {
  max-width: 60vw;
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-body {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 40px;
  width: min(100%, 1440px);
  min-height: calc(100dvh - 72px);
  margin: 0 auto;
  padding: 36px 40px 40px;
}

.drawer-overview {
  display: grid;
  align-content: start;
  gap: 18px;
}

.drawer-book {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 20px;
}

.drawer-cover {
  display: grid;
  width: 150px;
  height: 220px;
  overflow: hidden;
  place-items: center;
  background: #c95638;
  color: #fff8ee;
}

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

.drawer-cover .cover-wordmark {
  display: flex;
}

.drawer-identity {
  display: grid;
  align-content: start;
  gap: 8px;
}

.drawer-identity h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 29px;
  font-weight: 500;
  letter-spacing: -0.6px;
  line-height: 0.96;
}

.drawer-identity > p {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.drawer-description {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.metadata-grid {
  display: grid;
  border: 1px solid var(--rule);
}

.metadata-grid span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  border-top: 1px solid var(--rule);
  padding: 0 11px;
  font-size: 11px;
}

.metadata-grid span:first-child {
  border-top: 0;
}

.metadata-grid b {
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.editions-area {
  display: grid;
  align-content: start;
  gap: 18px;
}

.editions-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.editions-header h3 {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
}

.edition-list {
  display: grid;
  gap: 10px;
}

.edition-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 140px;
  align-items: center;
  gap: 18px;
  min-height: 112px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 16px 18px;
  background: var(--surface-strong);
}

.edition-row:first-child {
  border: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  background: var(--accent-paper);
}

.edition-copy {
  display: grid;
  gap: 5px;
}

.edition-copy strong {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
}

.edition-copy span {
  color: var(--muted);
  font-size: 11.5px;
}

.edition-copy small {
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: 0.06em;
}

.edition-format {
  display: grid;
  gap: 4px;
}

.edition-format strong {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
}

.edition-format small {
  color: var(--soft);
  font-family: var(--font-mono);
  font-size: 8px;
}

.edition-actions {
  display: grid;
  gap: 6px;
}

.edition-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
}

.edition-row:first-child .edition-actions a:first-child {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.drawer-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  border: 1px solid color-mix(in srgb, var(--success) 38%, transparent);
  border-radius: 4px;
  padding: 0 14px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 180;
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 13px 15px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 16px 44px var(--shadow);
  font-size: 12px;
}

.toast button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 1180px) {
  .source-status {
    display: none;
  }

  .command-panel {
    grid-template-columns: minmax(360px, 0.9fr) minmax(440px, 1.1fr);
    gap: 40px;
  }

  .toolbar-actions {
    gap: 10px;
  }

  .book-card {
    grid-template-columns: 42px minmax(0, 1fr) 130px 34px 100px;
  }

  .book-actions-summary {
    width: 130px;
  }

  .book-card:not(.best-match) .secondary-button {
    width: 100px;
  }
}

@media (max-width: 1023px) {
  .header-inner {
    padding: 0 32px;
  }

  .primary-nav {
    display: none;
  }

  .command-panel {
    grid-template-columns: 1fr;
    gap: 26px;
    padding: 38px 32px 32px;
  }

  .workspace,
  .how-it-works {
    padding-right: 32px;
    padding-left: 32px;
  }

  .results-toolbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px 0;
  }

  .toolbar-actions {
    align-self: auto;
    width: 100%;
  }

  .filter-button,
  .source-link {
    display: inline-flex;
  }

  .source-link {
    margin-left: auto;
  }

  .book-card.best-match {
    grid-template-columns: 110px minmax(0, 1fr) 180px;
  }

  .best-match .cover {
    width: 110px;
  }

  .drawer-body {
    grid-template-columns: 320px minmax(0, 1fr);
    padding-right: 32px;
    padding-left: 32px;
  }

  .drawer-book {
    grid-template-columns: 120px minmax(0, 1fr);
  }

  .drawer-cover {
    width: 120px;
    height: 176px;
  }
}

@media (max-width: 767px) {
  .site-header {
    position: static;
  }

  .header-inner {
    height: 64px;
    padding: 0 18px;
  }

  .brand {
    gap: 8px;
    font-size: 18px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .brand-mark svg {
    width: 15px;
    height: 15px;
  }

  .header-actions {
    gap: 8px;
  }

  .locale-switch,
  .library-toggle span,
  .library-toggle b {
    display: none;
  }

  .library-toggle,
  .icon-control {
    width: 32px;
    min-width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
  }

  .command-panel {
    gap: 15px;
    min-height: 0;
    padding: 22px 18px 14px;
  }

  .hero-copy {
    gap: 5px;
  }

  .hero-copy h1 {
    font-size: 34px;
    letter-spacing: -0.7px;
    line-height: 0.94;
  }

  .hero-copy > p:last-child {
    display: none;
  }

  .search-side {
    gap: 10px;
  }

  .search-form {
    height: 56px;
    padding: 0 5px 0 14px;
  }

  .search-box {
    gap: 10px;
  }

  .search-box svg {
    width: 18px;
    height: 18px;
  }

  .search-box input {
    font-size: 16px;
  }

  .search-button {
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .search-button span {
    display: none;
  }

  .quick-row {
    overflow: hidden;
  }

  .quick-row > span,
  .quick-row button:nth-of-type(n + 4) {
    display: none;
  }

  .workspace {
    padding: 0 18px 26px;
  }

  .results-toolbar {
    gap: 10px;
    min-height: 70px;
    padding: 10px 0;
  }

  .results-heading {
    display: grid;
    gap: 2px;
  }

  .results-heading h2 {
    font-size: 22px;
    white-space: normal;
  }

  .results-heading .overline {
    grid-row: 1;
  }

  .toolbar-actions {
    gap: 8px;
  }

  .inline-select,
  .sort-select,
  .source-link {
    display: none;
  }

  .filter-button {
    display: inline-flex;
    height: 36px;
  }

  .empty-state {
    min-height: 210px;
  }

  .empty-state h3 {
    font-size: 24px;
  }

  .book-card {
    grid-template-columns: 42px minmax(0, 1fr) 34px;
    gap: 12px;
    min-height: 88px;
    padding: 10px 0;
  }

  .book-card.best-match {
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 14px;
    min-height: 278px;
    padding: 14px;
  }

  .book-card.best-match .cover {
    width: 78px;
    height: 132px;
  }

  .cover-wordmark {
    padding: 9px;
  }

  .cover-wordmark b {
    font-size: 13px;
  }

  .book-title-row h3 {
    font-size: 17px;
  }

  .best-match .book-title-row h3 {
    font-size: 23px;
    line-height: 0.98;
  }

  .best-match .book-description,
  .best-match .result-metadata {
    display: none;
  }

  .best-match .book-meta {
    font-size: 11px;
  }

  .book-actions-summary {
    display: none;
  }

  .book-card:not(.best-match) .book-actions {
    display: contents;
  }

  .book-card:not(.best-match) .icon-save {
    grid-column: 3;
  }

  .book-card:not(.best-match) .secondary-button {
    display: none;
  }

  .best-match .book-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 44px;
    border: 0;
    padding: 0;
  }

  .best-match .availability,
  .best-match .secondary-button {
    display: none;
  }

  .best-match .download-button.primary {
    min-height: 44px;
  }

  .best-match .icon-save {
    grid-column: 2;
    grid-row: 1;
    width: 44px;
    min-height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.24);
  }

  .how-it-works {
    padding: 36px 18px;
  }

  .how-grid {
    grid-template-columns: 1fr;
  }

  .how-grid article,
  .how-grid article + article {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 20px 0;
  }

  .how-grid article:last-child {
    border-bottom: 0;
  }

  .how-grid h2 {
    margin-top: 12px;
  }

  .filter-rail {
    gap: 18px;
    padding: 10px 18px 22px;
  }

  .filter-grid {
    grid-template-columns: 1fr;
    gap: 18px;
    overflow-y: auto;
  }

  .check-list {
    grid-template-columns: 1fr;
  }

  .filter-actions .primary-button,
  .filter-actions .secondary-button {
    min-width: 0;
    flex: 1;
  }

  .overlay-header {
    height: 64px;
    padding: 0 18px;
  }

  .overlay-nav,
  .drawer-breadcrumb {
    display: none;
  }

  .library-body {
    padding: 22px 18px 20px;
  }

  .library-title-row {
    display: grid;
    gap: 14px;
  }

  .library-title-row h2 {
    font-size: 34px;
  }

  .library-title-row .secondary-button {
    justify-self: start;
  }

  .library-tabs {
    gap: 6px;
    height: 40px;
  }

  .library-tabs button {
    flex: 1;
    justify-content: center;
    gap: 5px;
    font-size: 11px;
  }

  .library-content {
    grid-template-columns: 1fr;
    gap: 18px;
    margin-top: 14px;
  }

  .library-activity {
    border-top: 1px solid var(--rule);
    border-left: 0;
    padding: 18px 0 0;
  }

  .library-item {
    grid-template-columns: 42px minmax(0, 1fr) auto;
  }

  .library-item-cover {
    width: 42px;
    height: 60px;
  }

  .library-item-actions button span,
  .library-item-actions a span {
    display: none;
  }

  .drawer-body {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 24px 18px 32px;
  }

  .drawer-book {
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 16px;
  }

  .drawer-cover {
    width: 110px;
    height: 162px;
  }

  .drawer-identity h2 {
    font-size: 26px;
  }

  .edition-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    min-height: 124px;
    padding: 14px;
  }

  .edition-format {
    grid-column: 2;
    grid-row: 1;
  }

  .edition-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast {
    right: 18px;
    bottom: 18px;
    left: 18px;
  }
}
