/* ---------- Header ---------- */
.dashboard-header {
  padding-block: var(--space-10) var(--space-8);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-10);
}

.dashboard-header__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
}

/* ---------- Book hero (chapters-list page header) ---------- */
.book-hero {
  display: flex;
  /* Stacked by default: squeezing the title into a narrow column beside
     a fixed-width cover is what forced mid-word breaks on longer titles.
     Full-width text at a smaller heading size (below) wraps at spaces
     normally, for any title length — not just the ones tested by hand. */
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-4);
  min-width: 0;
}

@media (min-width: 640px) {
  .book-hero {
    flex-direction: row;
    align-items: center;
    gap: var(--space-6);
  }
}

.book-hero__cover {
  position: relative;
  flex-shrink: 0;
  width: 96px;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background-color: var(--color-primary-900);
  box-shadow: var(--shadow-md);
  border: none;
  padding: 0;
  cursor: pointer;
}

@media (min-width: 640px) {
  .book-hero__cover {
    width: 140px;
  }
}

.book-hero__cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* contain, not cover: different books' cover art isn't all the same
     proportions, and letterboxing (shows the box's own background) beats
     cropping into the art on whichever book doesn't match the box ratio. */
  object-fit: contain;
}

.book-hero__cover.cover-failed .book-hero__cover-img {
  display: none;
}

.book-hero__zoom-hint {
  position: absolute;
  right: var(--space-2);
  bottom: var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background-color: rgba(0, 0, 0, 0.55);
  color: var(--color-white);
}

.book-hero__zoom-hint svg {
  width: 13px;
  height: 13px;
}

/* ---------- Cover modal (front/back showcase) ---------- */
body.cover-modal-open {
  overflow: hidden;
}

.cover-modal[hidden] {
  display: none;
}

.cover-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal, 300);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.cover-modal__backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(10, 14, 26, 0.72);
}

.cover-modal__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--space-8);
}

.cover-modal__close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-full);
  background-color: var(--color-border);
  color: var(--color-text-primary);
  cursor: pointer;
}

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

.cover-modal__close:hover {
  background-color: var(--color-border-strong);
}

.cover-modal__title {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-6);
  padding-right: var(--space-10);
}

.cover-modal__images {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

@media (min-width: 640px) {
  .cover-modal__images {
    flex-direction: row;
  }
}

.cover-modal__figure {
  flex: 1;
  min-width: 0;
  margin: 0;
  text-align: center;
}

.cover-modal__figure img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  object-fit: contain;
}

.cover-modal__figure figcaption {
  margin-top: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.dashboard-header__greeting {
  /* Flex items default to min-width:auto (won't shrink below their content's
     natural width) — without this override, a long enough title forces the
     row wider than the viewport instead of wrapping, causing a horizontal
     scrollbar on narrow screens. */
  min-width: 0;
}

.dashboard-header__greeting h1 {
  /* Scoped smaller than the global h1 (which the home-page hero also
     uses and wants to stay large) — this heading shares its row with a
     fixed-width cover once .book-hero goes horizontal, so it needs to
     stay reasonable at every width, not just desktop. */
  font-size: var(--font-size-2xl);
  margin-bottom: var(--space-2);
  overflow-wrap: break-word;
}

@media (min-width: 640px) {
  .dashboard-header__greeting h1 {
    font-size: var(--font-size-3xl);
  }
}

@media (min-width: 1024px) {
  .dashboard-header__greeting h1 {
    font-size: var(--font-size-4xl);
  }
}

.dashboard-header__greeting p {
  margin-bottom: 0;
}

.dashboard-header__stats {
  display: flex;
  gap: var(--space-8);
}

.dashboard-stat {
  text-align: right;
}

.dashboard-stat__value {
  display: block;
  font-family: var(--font-heading);
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-600);
  line-height: 1;
}

.dashboard-stat__label {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Search ---------- */
.dashboard-search {
  position: relative;
  max-width: 380px;
  margin-top: var(--space-8);
}

.dashboard-search svg {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.dashboard-search input {
  width: 100%;
  padding: var(--space-3) var(--space-4) var(--space-3) calc(var(--space-4) * 2 + 16px);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  transition: border-color var(--transition-fast) var(--ease-standard),
              box-shadow var(--transition-fast) var(--ease-standard);
}

.dashboard-search input:focus {
  outline: none;
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px var(--color-primary-100);
}

/* ---------- Tabs: Browse All / My Library ---------- */
.dashboard-tabbar {
  display: flex;
  gap: var(--space-8);
  margin-top: var(--space-8);
  border-bottom: 1px solid var(--color-border);
}

.dashboard-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: inherit;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-3) var(--space-1) var(--space-4);
  position: relative;
}

.dashboard-tab__count {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  background-color: var(--color-border);
  color: var(--color-text-secondary);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
}

.dashboard-tab[aria-selected="true"] {
  color: var(--color-text-primary);
}

.dashboard-tab[aria-selected="true"] .dashboard-tab__count {
  background-color: var(--color-accent-500);
  color: var(--color-white);
}

/* Reuses --color-link rather than a raw --color-primary-N step — it
   already has the dark-mode-adjusted value (variables.css), so the
   underline stays visible against a dark background without a separate
   override here. */
.dashboard-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2.5px;
  border-radius: 2px;
  background-color: var(--color-link);
}

.dashboard-tab-panel {
  padding-top: var(--space-10);
}

/* ---------- My Library access badge ---------- */
.book-card__access-badge {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  z-index: 1;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}

.book-card__access-badge--full {
  background-color: var(--color-success-bg);
  color: var(--color-success);
}

.book-card__access-badge--expiring {
  background-color: var(--color-warning-bg);
  color: var(--color-warning);
}

/* ---------- My Library empty state (no access granted yet) ---------- */
.library-empty {
  border: 1.5px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-16) var(--space-6);
  text-align: center;
  color: var(--color-text-secondary);
}

.library-empty p {
  max-width: 42ch;
  margin-inline: auto;
}

.library-empty .btn {
  margin-top: var(--space-5);
}

.dashboard-browse-link {
  text-align: center;
  margin-top: var(--space-8);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* ---------- Grid ---------- */
.dashboard-section {
  padding-bottom: var(--space-20);
}

.dashboard-section__header {
  margin-bottom: var(--space-8);
}

.dashboard-section__header h2 {
  font-size: var(--font-size-xl);
  margin-bottom: 0;
}

.topics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
}

@media (min-width: 640px) {
  .topics-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .topics-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ---------- Topic card ---------- */
.topic-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  border-left: 3px solid transparent;
}

.topic-card:hover {
  border-left-color: var(--color-accent-500);
}

.topic-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.topic-card__number {
  display: block;
  font-family: var(--font-heading);
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  color: var(--color-primary-300);
}

:root[data-theme="dark"] .topic-card__number {
  color: var(--color-primary-400);
}

.topic-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: var(--radius-lg);
  background-color: var(--color-accent-500);
  color: var(--color-white);
  box-shadow: var(--shadow-sm);
}

.topic-card__icon svg {
  width: 28px;
  height: 28px;
}

.topic-card h3 {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-3);
}

.topic-card__description {
  flex: 1;
  margin-bottom: 0;
  font-size: var(--font-size-sm);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.topic-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
}

.topic-card__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  color: var(--color-link);
}

.topic-card__link svg {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-fast) var(--ease-standard);
}

.topic-card:hover .topic-card__link {
  color: var(--color-link-hover);
  text-decoration: none;
}

.topic-card:hover .topic-card__link svg {
  transform: translateX(3px);
}

/* ---------- Empty state ---------- */
.dashboard-empty {
  display: none;
  text-align: center;
  padding-block: var(--space-16);
  color: var(--color-text-muted);
}

.dashboard-empty.is-visible {
  display: block;
}

.book-card.is-hidden {
  display: none;
}

[data-book-section].is-hidden {
  display: none;
}

/* ---------- Book cover ---------- */
.book-card__cover {
  position: relative;
  aspect-ratio: 2 / 3;
  margin: calc(var(--space-6) * -1) calc(var(--space-6) * -1) var(--space-5);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  background-color: var(--color-primary-900);
}

.book-card__cover-slider {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  width: 200%;
  height: 100%;
  transition: transform var(--transition-base) var(--ease-standard);
}

.book-card__cover.is-flipped .book-card__cover-slider {
  transform: translateX(-50%);
}

.book-card__cover-img {
  width: 50%;
  height: 100%;
  flex-shrink: 0;
  /* contain, not cover — see .book-hero__cover-img for why. */
  object-fit: contain;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .book-card__cover-slider {
    transition: none;
  }
}

.book-card__cover-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  transform: translateY(-50%);
  border: none;
  border-radius: var(--radius-full);
  background-color: rgba(0, 0, 0, 0.45);
  color: var(--color-white);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast) var(--ease-standard),
              background-color var(--transition-fast) var(--ease-standard);
}

.book-card__cover-nav svg {
  width: 16px;
  height: 16px;
}

.book-card__cover-nav--prev {
  left: var(--space-3);
}

.book-card__cover-nav--next {
  right: var(--space-3);
}

.book-card__cover-nav:hover {
  background-color: rgba(0, 0, 0, 0.7);
}

.book-card:hover .book-card__cover-nav,
.book-card__cover-nav:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  /* No hover on touch — arrows stay visible so they're discoverable. */
  .book-card__cover-nav {
    opacity: 1;
  }
}

.book-card__cover-fallback {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-inverse);
}

.book-card__cover-fallback svg {
  width: 40px;
  height: 40px;
  opacity: 0.85;
}

.book-card__cover-fallback-title {
  font-family: var(--font-heading);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
}

/* Shown instead of the <img> once it fails to load — see book-cards.js.
   Scoped to [data-book-cover] rather than .book-card__cover specifically
   so it also covers .book-hero__cover on the chapters-list page. */
[data-book-cover].cover-failed .book-card__cover-img {
  display: none;
}

[data-book-cover].cover-failed .book-card__cover-fallback {
  display: flex;
}

.book-card__cover-fallback--0 { background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-900)); }
.book-card__cover-fallback--1 { background: linear-gradient(135deg, var(--color-accent-500), var(--color-primary-700)); }
.book-card__cover-fallback--2 { background: linear-gradient(135deg, var(--color-primary-400), var(--color-accent-600)); }
.book-card__cover-fallback--3 { background: linear-gradient(135deg, var(--color-accent-400), var(--color-primary-800)); }

/* ---------- Chapter card (locked state) ---------- */
.chapter-card.is-locked {
  opacity: 0.65;
}

.chapter-card__lock {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background-color: var(--color-border);
  color: var(--color-text-muted);
}

.chapter-card__lock svg {
  width: 16px;
  height: 16px;
}

.chapter-card__locked-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
}
