:root {
  color-scheme: dark;
  --ink: #edf3ef;
  --muted: #a8b5ae;
  --paper: #0f1512;
  --panel: #18211c;
  --field: #101713;
  --surface-muted: #222e27;
  --line: #37463e;
  --accent: #28795e;
  --accent-hover: #1f674f;
  --link: #7ad9b3;
  --danger: #ff968d;
  --danger-surface: #a54139;
  --radius: 0.7rem;
  --shadow: 0 8px 28px rgb(0 0 0 / 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
}

a {
  color: var(--link);
  text-underline-offset: 0.18em;
}

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

::selection {
  color: var(--ink);
  background: #275842;
}

.shell {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 10;
  padding: 0.6rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
}

.site-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.nav-row {
  min-height: 4.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--ink);
}

nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.inline {
  display: inline;
}

.link-button,
.text-action {
  border: 0;
  background: none;
  color: var(--link);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
  padding: 0;
}

.main-content {
  padding-block: 2.3rem 4rem;
  min-height: calc(100vh - 10rem);
}

h1,
h2,
h3 {
  line-height: 1.15;
  letter-spacing: -0.025em;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.35rem);
  margin: 0.15rem 0;
}

h2 {
  font-size: 1.25rem;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.73rem;
  font-weight: 800;
  color: var(--muted);
  margin: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.65rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.45rem;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button.secondary {
  background: var(--field);
  color: var(--link);
  border-color: var(--line);
}

.button.secondary:hover {
  background: var(--surface-muted);
}

.button.small {
  min-height: 2.1rem;
  padding: 0.3rem 0.7rem;
}

.button.danger {
  background: var(--danger-surface);
  border-color: var(--danger-surface);
}

.tabs {
  gap: 0.2rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.2rem;
}

.tabs a {
  padding: 0.7rem 0.9rem;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}

.tabs a[aria-current="page"] {
  color: var(--ink);
  border-color: var(--link);
  font-weight: 700;
}

.tabs span {
  font-size: 0.78rem;
  background: var(--surface-muted);
  border-radius: 99px;
  padding: 0.08rem 0.4rem;
}

.filter-bar,
.search-form {
  display: flex;
  gap: 0.8rem;
  align-items: flex-end;
  background: var(--panel);
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field.grow {
  flex: 1;
}

.field label {
  font-weight: 700;
  font-size: 0.86rem;
}

.field input:not([type="radio"]):not([type="checkbox"]),
.field textarea,
.field select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  border: 1px solid #526158;
  border-radius: 0.4rem;
  background: var(--field);
  padding: 0.62rem 0.72rem;
  min-height: 2.65rem;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #89978f;
}

.field textarea {
  resize: vertical;
}

input[type="checkbox"],
input[type="radio"],
progress {
  accent-color: var(--link);
}

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

.book-card {
  display: grid;
  grid-template-columns: 105px 1fr;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 175px;
}

.cover-frame,
.result-cover,
.detail-cover {
  background: var(--surface-muted);
  overflow: hidden;
}

.cover-frame img,
.result-cover img,
.detail-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #293b32, #1c2a23);
  color: #9fc3b1;
  font: 800 2.2rem Georgia, serif;
}

.card-body {
  padding: 1rem;
  min-width: 0;
}

.card-body h2 {
  margin: 0.5rem 0 0.2rem;
}

.card-body h2 a {
  text-decoration: none;
  color: var(--ink);
}

.card-meta {
  display: flex;
  gap: 0.65rem;
  justify-content: space-between;
  font-size: 0.75rem;
}

.status {
  display: inline-block;
  color: #8de0bd;
  background: #163a2c;
  border-radius: 99px;
  padding: 0.15rem 0.5rem;
  font-size: 0.76rem;
  font-weight: 800;
}

.authors {
  color: var(--muted);
  margin: 0.2rem 0;
}

.book-dates {
  display: flex;
  gap: 0.25rem 0.8rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0.45rem 0;
}

.excerpt {
  font-size: 0.88rem;
  margin: 0.7rem 0;
  color: #c8d1cc;
}

.text-action {
  font-size: 0.84rem;
}

.empty-state {
  text-align: center;
  background: var(--panel);
  border: 1px dashed #59685f;
  border-radius: var(--radius);
  padding: 4rem 1rem;
}

.empty-state.compact {
  padding: 2.5rem 1rem;
}

.pagination {
  justify-content: center;
  margin-top: 2rem;
}

.search-panel {
  margin-bottom: 2rem;
}

.small-copy {
  margin-top: -0.8rem;
}

.result-list {
  display: grid;
  gap: 0.75rem;
}

.search-result {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.result-cover {
  height: 104px;
}

.result-body h3 {
  margin: 0;
}

.result-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.book-form,
.auth-card,
.confirm-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 4vw, 2rem);
  box-shadow: var(--shadow);
}

.narrow {
  max-width: 520px;
  margin-inline: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.2rem;
}

.field.wide {
  grid-column: 1 / -1;
}

.help,
.field-error {
  font-size: 0.82rem;
  margin: 0.1rem 0;
}

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

.field-error,
.error-text {
  color: var(--danger);
}

.checkbox {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.rating-field > div {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.rating-field > div > div label {
  font-weight: 400;
}

.form-actions,
.detail-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.detail-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: clamp(2rem, 6vw, 5rem);
}

.detail-cover {
  aspect-ratio: 2 / 3;
  border-radius: 0.45rem;
  box-shadow: var(--shadow);
}

.detail-layout aside > .status {
  margin-top: 1rem;
}

.rating-display {
  font-size: 1.3rem;
  color: #f3bf54;
}

.rating-display span {
  color: var(--muted);
  font-size: 0.85rem;
}

.detail-main h1 {
  max-width: 18ch;
}

.detail-authors {
  font-size: 1.2rem;
  color: var(--muted);
}

.detail-actions {
  justify-content: flex-end;
  margin: 0 0 2rem;
}

.danger-link {
  color: var(--danger);
}

.tag-list {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
}

.tag-list li {
  background: var(--surface-muted);
  padding: 0.25rem 0.65rem;
  border-radius: 99px;
  font-size: 0.82rem;
}

.prose {
  max-width: 72ch;
  margin-top: 2rem;
}

.prose p,
.note-box p {
  white-space: normal;
}

.note-box {
  margin-top: 2rem;
  padding: 1rem 1.2rem;
  border-left: 4px solid var(--link);
  background: #152a21;
}

.source-link {
  font-size: 0.85rem;
  margin-top: 2rem;
}

.messages {
  margin-bottom: 1rem;
}

.message,
.notice {
  padding: 0.8rem 1rem;
  border-radius: 0.4rem;
  background: #163326;
  border: 1px solid #316a50;
}

.message.error,
.notice.error {
  background: #351d1c;
  border-color: #81423d;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding-block: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline;
}

.auth-card h1,
.confirm-card h1 {
  font-size: 2rem;
}

.auth-card form {
  display: grid;
  gap: 1rem;
}

.result-source {
  font-size: 0.75rem;
  margin: 0.25rem 0 0;
}

.heading-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.import-details {
  padding-left: 1.25rem;
  margin: 1.25rem 0 1.5rem;
}

.import-details li + li {
  margin-top: 0.45rem;
}

.import-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 3rem;
  padding: 1.25rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.import-option h2,
.import-option p {
  margin: 0.2rem 0;
}

#goodreads-progress progress {
  display: block;
  width: 100%;
  height: 1rem;
  margin: 1rem 0 1.25rem;
}

#goodreads-progress form {
  margin-top: 1rem;
}

@media (max-width: 780px) {
  .book-grid {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filter-bar .grow {
    grid-column: 1 / -1;
  }

  .filter-submit {
    align-self: end;
  }

  .detail-layout {
    grid-template-columns: 150px 1fr;
    gap: 1.5rem;
  }

  .search-result {
    grid-template-columns: 60px 1fr;
  }

  .result-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 1.1rem, 1120px);
  }

  .nav-row {
    align-items: flex-start;
    padding-block: 0.8rem;
  }

  .nav-row nav {
    flex-wrap: wrap;
    justify-content: flex-end;
    font-size: 0.88rem;
  }

  .nav-row nav > a:first-child {
    display: none;
  }

  .page-heading {
    align-items: flex-start;
  }

  .filter-bar,
  .search-form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .book-card {
    grid-template-columns: 86px 1fr;
  }

  .detail-layout {
    display: block;
  }

  .detail-layout aside {
    width: 145px;
    margin-bottom: 1.5rem;
  }

  .detail-actions {
    justify-content: flex-start;
  }

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

  .field.wide {
    grid-column: auto;
  }

  .result-actions form,
  .result-actions .button {
    width: 100%;
  }

  .result-actions .button {
    display: flex;
  }

  .site-footer {
    margin-top: 1rem;
  }

  .heading-actions {
    justify-content: flex-start;
  }

  .import-option {
    align-items: flex-start;
    flex-direction: column;
  }

  .import-option .button {
    width: 100%;
  }
}

.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
