/* Bookshelf list and book-detail surface. The immersive reader remains in styles.css. */

#books-detail-view[hidden],
#books-library-view[hidden],
#books-reader-panel[hidden] {
  display: none !important;
}

.books-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

.books-card {
  width: 100%;
  min-width: 0;
  grid-template-columns: 94px minmax(0, 1fr);
  grid-template-rows: minmax(124px, auto);
  gap: 18px;
  align-items: start;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.books-card:first-child {
  padding-top: 0;
}

.books-card:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.books-card:hover .books-card-body strong {
  color: var(--cinnabar);
}

.books-card-cover,
.books-card-dir .books-card-cover {
  width: 94px;
  height: 124px;
  aspect-ratio: auto;
  box-sizing: border-box;
  padding: 10px;
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(33, 36, 31, 0.14);
}

.books-card-body {
  min-width: 0;
  min-height: 124px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  padding: 2px 0;
}

.books-card-body strong {
  max-width: 100%;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.35;
  transition: color 0.18s ease;
}

.books-card-author,
.books-card-summary {
  margin: 0;
  color: var(--muted);
}

.books-card-author {
  font-size: 13px;
}

.books-card-summary {
  width: 100%;
  display: -webkit-box;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.books-card-meta {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
}

.books-card-meta span {
  max-width: 100%;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  padding: 3px 9px;
  border: 1px solid rgba(32, 35, 33, 0.08);
  border-radius: 999px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.books-card-meta [data-books-card-words] {
  background: rgba(185, 65, 50, 0.08);
  color: #8f3d32;
}

.books-card-meta [data-books-card-readers] {
  background: rgba(47, 116, 80, 0.09);
  color: #2f6f50;
}

.books-card-dir .books-card-body {
  justify-content: center;
}

.books-card-dir .books-card-body span {
  color: var(--muted);
  font-size: 13px;
}

/* My Library keeps the original upright cover-card shelf. */
.books-grid.is-library {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 18px 14px;
}

.books-grid.is-library .books-card {
  width: auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto;
  gap: 10px;
  align-items: stretch;
  padding: 0;
  border: 0;
}

.books-grid.is-library .books-card-cover {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  padding: 12px;
  border-radius: 8px;
  box-shadow: 0 14px 26px rgba(33, 36, 31, 0.12);
}

.books-grid.is-library .books-card-body {
  min-height: 0;
  display: grid;
  gap: 4px;
  align-items: initial;
  padding: 0;
}

.books-grid.is-library .books-card-body strong {
  font-size: 15px;
  line-height: 1.35;
}

.books-grid.is-library .books-card-status {
  color: var(--muted);
  font-size: 12px;
}

.books-detail-view {
  flex: 1 0 auto;
  min-width: 0;
  min-height: calc(100dvh - 56px);
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
}

.books-detail-topbar {
  min-height: 52px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.books-detail-topbar strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.books-detail-topbar .topbar-back {
  justify-self: start;
}

.books-detail-content {
  width: min(820px, 100%);
  margin: 0 auto;
}

.books-detail-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 8px 20px 34px;
  text-align: center;
}

.books-detail-cover .books-card-cover {
  width: 164px;
  height: 218px;
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 18px 34px rgba(33, 36, 31, 0.18);
}

.books-detail-cover .books-spine {
  top: 20px;
  right: 14px;
  bottom: 20px;
  min-width: 34px;
  max-width: 66px;
  font-size: 14px;
}

.books-detail-identity {
  min-width: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
}

.books-detail-identity h1,
.books-detail-identity span {
  margin: 0;
}

.books-detail-identity h1 {
  max-width: min(680px, 100%);
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 32px;
  line-height: 1.28;
}

.books-detail-identity span {
  color: var(--muted);
  font-size: 16px;
}

.books-detail-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  padding: 26px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.books-detail-stats > div {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 9px;
  padding: 0 16px;
  text-align: center;
}

.books-detail-stats > div + div {
  border-left: 1px solid var(--line);
}

.books-detail-stats dt {
  color: var(--muted);
  font-size: 13px;
}

.books-detail-stats dd {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 21px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.books-detail-intro {
  padding: 32px 20px 120px;
}

.books-detail-intro h2 {
  margin: 0 0 18px;
  color: var(--ink);
  font-size: 20px;
}

.books-detail-intro p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 2;
  white-space: pre-line;
}

.books-detail-actions {
  position: sticky;
  z-index: 40;
  bottom: 18px;
  width: min(720px, calc(100% - 32px));
  min-height: 66px;
  display: grid;
  grid-template-columns: minmax(104px, 0.8fr) minmax(104px, 0.8fr) minmax(160px, 1.4fr);
  gap: 10px;
  margin: auto auto 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.96);
  box-shadow: 0 14px 32px rgba(33, 36, 31, 0.14);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.books-detail-actions button {
  min-width: 0;
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: rgba(32, 35, 33, 0.06);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.books-detail-actions button:disabled {
  opacity: 0.58;
  cursor: default;
}

.books-detail-actions button i,
.books-detail-actions button svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
}

.books-detail-actions .books-detail-read {
  background: var(--cinnabar);
  color: #fffdf7;
}

body.books-detail-mode .reader-scroll-tools {
  display: none !important;
}

.reader-library-button {
  border: 1px solid var(--reader-active);
  background: var(--reader-soft);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.reader-library-button:disabled,
.reader-library-button.is-added {
  border-color: var(--reader-line);
}

@media (max-width: 760px) {
  body.books-detail-mode .bottom-nav {
    display: none !important;
  }

  body.books-detail-mode .main-content {
    min-height: 100dvh;
    padding-bottom: 0;
  }

  .books-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .books-card {
    grid-template-columns: 78px minmax(0, 1fr);
    grid-template-rows: minmax(104px, auto);
    gap: 13px;
    padding: 13px 0;
  }

  .books-card-cover,
  .books-card-dir .books-card-cover {
    width: 78px;
    height: 104px;
    padding: 8px;
    border-radius: 5px;
  }

  .books-card-body {
    min-height: 104px;
    gap: 4px;
    padding: 0;
  }

  .books-card-body strong {
    font-size: 16px;
    line-height: 1.35;
  }

  .books-card-author {
    font-size: 12px;
  }

  .books-card-summary {
    font-size: 12px;
    line-height: 1.5;
  }

  .books-card-meta {
    gap: 5px 6px;
    font-size: 11px;
  }

  .books-card-meta span {
    min-height: 24px;
    padding: 2px 7px;
  }

  .books-grid.is-library {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px 10px;
  }

  .books-grid.is-library .books-card {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    gap: 7px;
    padding: 0;
  }

  .books-grid.is-library .books-card-cover {
    width: 100%;
    height: auto;
    padding: 8px;
    border-radius: 8px;
  }

  .books-grid.is-library .books-card-body {
    min-height: 0;
    gap: 3px;
  }

  .books-grid.is-library .books-card-body strong {
    font-size: 12px;
  }

  .books-grid.is-library .books-card-status {
    font-size: 10px;
  }

  .books-spine {
    top: 10px;
    right: 7px;
    bottom: 10px;
    min-width: 24px;
    max-width: 46px;
    padding: 5px 3px;
    font-size: 10px;
  }

  .books-detail-view {
    min-height: 100dvh;
    padding-bottom: calc(88px + env(safe-area-inset-bottom));
  }

  .books-detail-topbar {
    min-height: calc(52px + env(safe-area-inset-top));
    margin-bottom: 12px;
    padding-top: env(safe-area-inset-top);
  }

  .books-detail-content {
    width: 100%;
  }

  .books-detail-hero {
    gap: 16px;
    padding: 18px 12px 30px;
  }

  .books-detail-cover .books-card-cover {
    width: 116px;
    height: 156px;
    padding: 11px;
  }

  .books-detail-cover .books-spine {
    top: 14px;
    right: 10px;
    bottom: 14px;
    min-width: 28px;
    max-width: 54px;
    font-size: 11px;
  }

  .books-detail-identity {
    gap: 7px;
  }

  .books-detail-identity h1 {
    font-size: 24px;
  }

  .books-detail-identity span {
    font-size: 14px;
  }

  .books-detail-stats {
    padding: 22px 0;
  }

  .books-detail-stats > div {
    padding: 0 8px;
  }

  .books-detail-stats dt {
    font-size: 12px;
  }

  .books-detail-stats dd {
    font-size: 17px;
  }

  .books-detail-intro {
    padding: 28px 10px 42px;
  }

  .books-detail-intro h2 {
    margin-bottom: 14px;
    font-size: 18px;
  }

  .books-detail-intro p {
    font-size: 15px;
    line-height: 1.9;
  }

  .books-detail-actions {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    min-height: calc(72px + env(safe-area-inset-bottom));
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 0.9fr) minmax(0, 1.4fr);
    gap: 8px;
    margin: 0;
    padding: 8px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border-width: 1px 0 0;
    border-radius: 0;
  }

  .books-detail-actions button {
    min-height: 52px;
    gap: 5px;
    padding: 0 8px;
    font-size: 14px;
  }

  .books-detail-actions button:not(.books-detail-read) {
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    line-height: 1.15;
  }

  .books-detail-actions button span {
    white-space: nowrap;
  }
}

@media (max-width: 360px) {
  .books-detail-hero {
    gap: 14px;
  }

  .books-detail-cover .books-card-cover {
    width: 102px;
    height: 138px;
  }

  .books-detail-identity h1 {
    font-size: 21px;
  }

  .books-detail-stats dd {
    font-size: 15px;
  }

  .books-detail-actions button {
    font-size: 13px;
  }
}
