:root {
  color-scheme: dark;
  --bg: #070b12;
  --panel: #0f1724;
  --panel-2: #141f31;
  --text: #f7efe2;
  --muted: #a9b3c5;
  --line: rgba(255, 255, 255, 0.1);
  --gold: #d6ad60;
  --blue: #68b7ff;
  --danger: #ff6b6b;
  --ok: #5ee0a0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(104, 183, 255, 0.14), transparent 28rem),
    linear-gradient(180deg, #070b12 0%, #0a101a 54%, #070b12 100%);
  color: var(--text);
  line-height: 1.5;
}

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

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

.site-header,
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 18, 0.82);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-family: Georgia, serif;
  font-size: 1.45rem;
  color: var(--gold);
  font-weight: 700;
}

nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .85rem;
  color: var(--muted);
  font-size: .95rem;
}

.page-shell,
.admin-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 2rem;
}

.hero-copy {
  padding: clamp(1.2rem, 4vw, 2.4rem);
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(15, 23, 36, .94), rgba(20, 31, 49, .78));
  border-radius: 8px;
}

.eyebrow {
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .78rem;
  margin: 0 0 .6rem;
}

h1,
h2,
h3 {
  line-height: 1.12;
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-family: Georgia, serif;
  font-size: clamp(2.2rem, 7vw, 4.8rem);
}

.admin-shell h1 {
  font-size: clamp(2rem, 4vw, 3rem);
}

h2 { font-size: 1.45rem; margin: 2rem 0 1rem; }

.hero-copy p,
.muted {
  color: var(--muted);
}

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

.stat {
  border: 1px solid var(--line);
  background: rgba(15, 23, 36, .86);
  border-radius: 8px;
  padding: 1rem;
}

.stat strong {
  display: block;
  font-size: 1.85rem;
  color: var(--gold);
}

.filters,
.lookup-form,
.book-form,
.admin-panel {
  border: 1px solid var(--line);
  background: rgba(15, 23, 36, .9);
  border-radius: 8px;
  padding: 1rem;
}

.filters {
  display: grid;
  grid-template-columns: 1.4fr repeat(5, minmax(120px, 1fr));
  gap: .7rem;
  margin-bottom: 1.6rem;
}

input,
select,
textarea,
button,
.button {
  width: 100%;
  min-height: 2.65rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  padding: .7rem .8rem;
  font: inherit;
}

textarea { resize: vertical; }

label {
  display: grid;
  gap: .38rem;
  color: var(--muted);
  font-size: .9rem;
}

button,
.button {
  cursor: pointer;
  background: linear-gradient(135deg, var(--gold), #b9822d);
  border: 0;
  color: #111827;
  font-weight: 800;
  text-align: center;
}

.button.secondary,
button.secondary {
  background: #182336;
  color: var(--text);
  border: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0 .9rem;
}

.section-link {
  color: var(--blue);
  font-size: .95rem;
  white-space: nowrap;
}

.bookshelf-section {
  scroll-margin-top: 5rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 180px));
  gap: 1rem;
  align-items: start;
}

.carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 180px;
  grid-template-columns: none;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scroll-snap-type: inline mandatory;
  scroll-padding-inline: .25rem;
  padding: .15rem .2rem .9rem;
  scrollbar-color: rgba(214, 173, 96, .7) rgba(255, 255, 255, .08);
  scrollbar-width: thin;
}

.carousel .book-card {
  scroll-snap-align: start;
}

.carousel::-webkit-scrollbar {
  height: .65rem;
}

.carousel::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, .08);
  border-radius: 999px;
}

.carousel::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, var(--blue), var(--gold));
  border-radius: 999px;
}

.full-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 190px));
}

.book-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20, 31, 49, .94), rgba(12, 18, 29, .94));
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}

.cover {
  aspect-ratio: 2 / 3;
  background: #101827;
  overflow: hidden;
  max-height: 260px;
}

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

.book-card-body {
  padding: .9rem;
}

.book-card h3 {
  font-size: 1rem;
  margin-bottom: .25rem;
}

.meta {
  color: var(--muted);
  font-size: .86rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.65rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  color: #09111d;
  background: var(--blue);
  font-size: .78rem;
  font-weight: 800;
}

.badge.read { background: var(--ok); }
.badge.wishlist { background: var(--gold); }

.rating {
  color: var(--gold);
  margin: .55rem 0;
}

.progress {
  height: .55rem;
  background: #0a101b;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--gold));
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .35rem;
  color: var(--muted);
  font-size: .8rem;
}

.book-detail {
  display: grid;
  grid-template-columns: minmax(180px, 300px) minmax(0, 1fr);
  gap: 1.4rem;
  align-items: start;
}

.detail-copy {
  border: 1px solid var(--line);
  background: rgba(15, 23, 36, .9);
  border-radius: 8px;
  padding: 1.2rem;
}

.admin-list {
  display: grid;
  gap: .7rem;
}

.admin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(15, 23, 36, .84);
  border-radius: 8px;
  padding: .85rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.row-actions .button,
.row-actions button {
  width: auto;
  min-height: 2.25rem;
  padding: .45rem .65rem;
}

.inline-form { display: inline; }

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

.book-form {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.form-actions,
.inline-row {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  align-items: center;
}

.form-actions button,
.form-actions .button {
  width: auto;
  min-width: 12rem;
}

.lookup-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .8rem;
  margin: 1rem 0;
}

.lookup-card {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 31, 49, .88);
  padding: .8rem;
}

.lookup-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .45rem;
}

.lookup-actions button {
  min-height: 2.35rem;
  padding: .45rem .55rem;
}

.lookup-cover {
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  background: #0a101b;
  overflow: hidden;
}

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

.lookup-info {
  display: grid;
  align-content: start;
  gap: .25rem;
  min-width: 0;
}

.lookup-info strong,
.lookup-info span,
.lookup-info small {
  overflow-wrap: anywhere;
}

.lookup-info small {
  color: var(--muted);
}

.lookup-info em {
  color: var(--blue);
  font-size: .78rem;
  font-style: normal;
  text-transform: capitalize;
}

.flash {
  margin-bottom: 1rem;
  padding: .8rem 1rem;
  border-radius: 8px;
  background: rgba(94, 224, 160, .14);
  border: 1px solid rgba(94, 224, 160, .35);
}

.flash.error {
  background: rgba(255, 107, 107, .14);
  border-color: rgba(255, 107, 107, .36);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 1.5rem;
  color: var(--muted);
}

.debug-panel {
  display: grid;
  gap: 1rem;
}

.debug-card {
  border: 1px solid var(--line);
  background: rgba(15, 23, 36, .9);
  border-radius: 8px;
  padding: 1rem;
}

.debug-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 64px;
  gap: .75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.debug-summary img {
  width: 64px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 6px;
}

.debug-fields {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: .45rem .8rem;
  margin: 0;
}

.debug-fields dt {
  color: var(--muted);
}

.debug-fields dd {
  margin: 0;
  overflow-wrap: anywhere;
}

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

details {
  margin-top: 1rem;
}

pre {
  overflow: auto;
  max-height: 360px;
  padding: .8rem;
  border-radius: 6px;
  background: #070b12;
  border: 1px solid var(--line);
}

@media (max-width: 860px) {
  .hero,
  .book-detail {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .site-header,
  .admin-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-shell,
  .admin-shell {
    width: min(100% - 1rem, 1180px);
    padding-top: 1rem;
  }

  .stats-grid,
  .filters,
  .form-grid,
  .admin-row {
    grid-template-columns: 1fr;
  }

  .book-grid {
    gap: .7rem;
  }

  .carousel {
    grid-auto-columns: minmax(145px, 46vw);
  }

  .cover {
    max-height: 210px;
  }

  .book-card-body {
    padding: .75rem;
  }

  .form-actions,
  .inline-row {
    flex-direction: column;
  }

  .lookup-actions {
    grid-template-columns: 1fr 1fr;
  }
}
