/* Reusable components: cards, book grid, goal, dialogs, toasts, controls. */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------- Empty state ---------- */
.empty {
  display: grid;
  justify-items: center;
  gap: 0.625rem;
  padding: clamp(1.5rem, 6vw, 3rem) 1rem;
  text-align: center;
}
.empty__icon {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
}
.empty__title {
  font: 600 1.125rem/1.3 var(--font-display);
}
.empty__text {
  max-width: 26rem;
  color: var(--muted);
  font-size: 0.9375rem;
}
.empty .btn {
  margin-top: 0.5rem;
}

/* ---------- Book grid & cards ---------- */
.book-grid {
  display: grid;
  gap: clamp(0.875rem, 2.5vw, 1.5rem);
  grid-template-columns: repeat(auto-fill, minmax(8.25rem, 1fr));
}
@media (min-width: 40rem) {
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  }
}
@media (min-width: 64rem) {
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  }
}
.book-grid__item {
  min-width: 0;
}

.book-card {
  display: grid;
  gap: 0.625rem;
  min-width: 0;
}
.book-card__cover {
  position: relative;
  aspect-ratio: 3 / 4;
  isolation: isolate;
  overflow: hidden;
  cursor: pointer;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  box-shadow:
    var(--shadow-sm),
    inset 0 0 0 1px rgb(0 0 0 / 0.06);
  transition:
    transform 0.25s var(--ease),
    box-shadow 0.25s var(--ease);
}
@media (hover: hover) {
  .book-card:hover .book-card__cover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
  }
}

.cover {
  position: absolute;
  inset: 0;
}
.cover__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cover__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: end;
  gap: 0.25rem;
  padding: 0.875rem;
  color: #fff;
  background: linear-gradient(
    160deg,
    hsl(var(--hue) 34% 36%),
    hsl(calc(var(--hue) + 28) 36% 22%)
  );
}
.cover__title {
  font: 600 1rem/1.2 var(--font-display);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cover__author {
  font-size: 0.75rem;
  opacity: 0.8;
}

.book-card__badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 1;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-full);
  background: rgb(255 255 255 / 0.92);
  color: #14171c;
  font-size: 0.6875rem;
  font-weight: 600;
}
.book-card[data-finished="true"] .book-card__badge {
  background: var(--accent);
  color: var(--accent-contrast);
}
.book-card__fav-mark {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.45);
  color: #ff8da1;
}
.book-card__fav-mark svg {
  fill: currentColor;
}

.book-card__overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  background: linear-gradient(
    to top,
    rgb(8 10 12 / 0.86),
    rgb(8 10 12 / 0.5) 60%,
    rgb(8 10 12 / 0.62)
  );
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}
.book-card__overlay-main {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.5rem;
}
.book-card__percent {
  font-size: 0.75rem;
  color: rgb(255 255 255 / 0.82);
  min-height: 1em;
}
.book-card__actions {
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
  padding-bottom: 0.25rem;
}
.book-card__action {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.16);
  color: #fff;
  transition:
    background-color 0.15s,
    transform 0.15s var(--ease);
}
.book-card__action:hover {
  background: rgb(255 255 255 / 0.3);
}
.book-card__action:active {
  transform: scale(0.92);
}
.book-card__action[aria-pressed="true"] {
  color: #ff8da1;
}
.book-card__action[aria-pressed="true"] svg {
  fill: currentColor;
}
.book-card__action[data-action="delete"]:hover {
  background: rgb(220 60 50 / 0.6);
}
.book-card__action:focus-visible,
.book-card__primary:focus-visible {
  outline-color: #fff;
}

.book-card:has(:focus-visible) .book-card__overlay,
.book-card[data-active="true"] .book-card__overlay {
  opacity: 1;
  pointer-events: auto;
}
@media (hover: hover) {
  .book-card:hover .book-card__overlay {
    opacity: 1;
    pointer-events: auto;
  }
}

.book-card__progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  height: 4px;
  background: rgb(255 255 255 / 0.28);
}
.book-card__progress-fill {
  display: block;
  height: 100%;
  background: #5eead4;
  transition: width 0.4s var(--ease);
}

.book-card__body {
  min-width: 0;
  padding-inline: 0.125rem;
}
.book-card__title {
  font: 600 0.9375rem/1.3 var(--font-display);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.book-card__author {
  margin-top: 0.125rem;
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Continue reading ---------- */
.continue__list {
  display: grid;
  gap: 0.75rem;
}
.continue-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.continue-item__cover {
  position: relative;
  width: 3.5rem;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 0.5rem;
}
.continue-item__cover .cover__fallback {
  padding: 0.375rem;
}
.continue-item__cover .cover__title {
  font-size: 0.5625rem;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}
.continue-item__cover .cover__author {
  display: none;
}
.continue-item__title {
  font: 600 0.9375rem/1.3 var(--font-display);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.continue-item__author {
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.continue-item__progress {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-top: 0.5rem;
}
.continue-item__percent {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bar {
  flex: 1;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  overflow: hidden;
}
.bar__fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}
@media (max-width: 26rem) {
  .continue-item {
    grid-template-columns: auto minmax(0, 1fr);
  }
  .continue-item__cta {
    grid-column: 1 / -1;
  }
}

/* ---------- Daily goal ---------- */
.goal {
  display: grid;
  gap: 1.25rem;
  padding: clamp(1rem, 3vw, 1.5rem);
}
.goal__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.goal__streak {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.875rem 0.375rem 0.625rem;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--muted);
}
.goal__streak[data-active="true"] {
  background: var(--streak-soft);
  color: var(--streak);
}
.goal__streak[data-active="true"] svg {
  fill: currentColor;
}
.goal__streak-count {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
}
.goal__best {
  display: block;
  font-size: 0.6875rem;
  line-height: 1.2;
  color: var(--muted);
}

.goal__body {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.goal__ring {
  position: relative;
  flex: none;
  width: 5.75rem;
  height: 5.75rem;
}
.goal__ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.goal__ring-track,
.goal__ring-fill {
  fill: none;
  stroke-width: 8;
}
.goal__ring-track {
  stroke: var(--surface-2);
}
.goal__ring-fill {
  stroke: var(--streak);
  stroke-linecap: round;
  transition:
    stroke-dashoffset 0.6s var(--ease),
    stroke 0.3s;
}
.goal__ring[data-met="true"] .goal__ring-fill {
  stroke: var(--accent);
}
.goal__ring-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  line-height: 1.1;
}
.goal__minutes {
  font: 600 1.75rem/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}
.goal__target {
  margin-top: 0.125rem;
  font-size: 0.6875rem;
  color: var(--muted);
}
.goal__message {
  color: var(--muted);
  font-size: 0.9375rem;
  min-width: 0;
}

.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.25rem;
}
.week__day {
  display: grid;
  justify-items: center;
  gap: 0.375rem;
}
.week__label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}
.week__day[data-today="true"] .week__label {
  color: var(--text);
  font-weight: 700;
}
.week__dot {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 50%;
  border: 2px dashed var(--border);
  color: var(--muted);
}
.week__day[data-status="done"] .week__dot {
  border: 0;
  background: var(--accent);
  color: var(--accent-contrast);
}
.week__day[data-status="missed"] .week__dot {
  border: 2px solid var(--danger-soft);
  background: var(--danger-soft);
  color: var(--danger);
}
.week__day[data-status="progress"] .week__dot {
  border: 0;
  background: conic-gradient(
    var(--streak) calc(var(--ratio) * 1turn),
    var(--surface-2) 0
  );
}
.week__day[data-status="progress"] .week__dot::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--surface);
}
.week__day[data-status="none"] .week__dot {
  border-style: solid;
  border-color: transparent;
  background: var(--surface-2);
  opacity: 0.6;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}
.legend__dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
}
.legend__dot[data-status="done"] {
  background: var(--accent);
}
.legend__dot[data-status="progress"] {
  background: var(--streak);
}
.legend__dot[data-status="missed"] {
  background: var(--danger);
}

.goal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}
.goal__footer-label {
  color: var(--muted);
}
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: var(--radius-full);
  background: var(--surface-2);
}
.stepper__btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.stepper__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.stepper__btn:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent);
}
.stepper__value {
  min-width: 4.25rem;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Library shelf (drop zone) ---------- */
.shelf {
  position: relative;
  border-radius: var(--radius-lg);
  transition:
    outline-color 0.15s,
    background-color 0.15s;
  outline: 2px dashed transparent;
  outline-offset: 0.5rem;
}
.shelf.is-dragging {
  outline-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Segmented controls ---------- */
.segmented {
  display: flex;
  gap: 0.25rem;
  margin: 0;
  padding: 0.25rem;
  min-width: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--surface-2);
}
.segmented__option {
  position: relative;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.segmented__input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.segmented__text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 2.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition:
    background-color 0.15s,
    color 0.15s;
}
.segmented__input:checked + .segmented__text {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.segmented__input:focus-visible + .segmented__text {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.segmented--pills {
  display: inline-flex;
}
.segmented--pills .segmented__option {
  flex: none;
}

.segmented--font .segmented__text {
  flex-direction: column;
  gap: 0;
  padding-block: 0.375rem;
  font-size: 0.75rem;
}
.segmented__sample {
  font-size: 1.25rem;
  line-height: 1.1;
  color: var(--text);
}
.segmented__text[data-font="sans"] > .segmented__sample {
  font-family: var(--font-sans);
}
.segmented__text[data-font="serif"] > .segmented__sample {
  font-family: var(--font-serif);
}
.segmented__text[data-font="mono"] > .segmented__sample {
  font-family: var(--font-mono);
}

.segmented--theme {
  background: none;
  padding: 0;
  gap: 0.5rem;
}
.segmented--theme .segmented__text {
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.5rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
}
.segmented--theme .segmented__input:checked + .segmented__text {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: var(--surface);
}
.swatch {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 1px solid var(--border);
}
.segmented__text[data-theme="paper"] > .swatch {
  background: linear-gradient(135deg, #fbfaf7 50%, #222 50%);
}
.segmented__text[data-theme="sepia"] > .swatch {
  background: linear-gradient(135deg, #f4ecd8 50%, #4a3a2a 50%);
}
.segmented__text[data-theme="dark"] > .swatch {
  background: linear-gradient(135deg, #1d1e22 50%, #d6d6da 50%);
}
.segmented__text[data-theme="oled"] > .swatch {
  background: linear-gradient(135deg, #000 50%, #c9c9c9 50%);
}

/* ---------- Labelled stepper row (reader settings) ---------- */
.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.875rem;
}
.stepper-row__label {
  min-width: 0;
}
.stepper-row .stepper {
  flex: none;
}
.stepper-row .stepper__btn {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.setting {
  display: grid;
  gap: 0.75rem;
}
.setting + .setting {
  margin-top: 1.5rem;
}
.setting__title {
  font-size: 0.875rem;
  font-weight: 600;
}
.stack {
  display: grid;
  gap: 0.5rem;
}

/* ---------- Dialog ---------- */
.dialog {
  width: 100%;
  max-width: 100%;
  max-height: min(98dvh, 44rem);
  margin: auto auto 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog[open] {
  display: flex;
  flex-direction: column;
  animation: sheet-in 0.25s var(--ease);
}
.dialog::backdrop {
  background: rgb(8 10 12 / 0.5);
  backdrop-filter: blur(2px);
}
.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.75rem 0.5rem 1.25rem;
}
.dialog__title {
  font: 600 1.125rem/1.3 var(--font-display);
}
.dialog__body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1.25rem 1.25rem;
  overscroll-behavior: contain;
}
.dialog__footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.dialog__footer:empty {
  display: none;
}
.dialog__text {
  color: var(--muted);
  font-size: 0.9375rem;
}

@media (min-width: 40rem) {
  .dialog--modal {
    width: min(100% - 2rem, 30rem);
    margin: auto;
    border-radius: var(--radius-lg);
  }
  .dialog--modal[open],
  .dialog--sheet[open] {
    animation-name: pop-in;
  }
  .dialog--sheet {
    width: min(100% - 2rem, 30rem);
    margin: auto;
    border-radius: var(--radius-lg);
  }
  .dialog--panel {
    width: min(100%, 24rem);
    height: 100dvh;
    max-height: none;
    margin: 0 0 0 auto;
    border-radius: 0;
    border-width: 0 0 0 1px;
  }
  .dialog--panel[open] {
    animation-name: panel-in;
  }
}
@media (max-width: 39.999rem) {
  .dialog--panel {
    max-height: 78dvh;
  }
}
@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(1.5rem);
  }
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
}
@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateX(1.5rem);
  }
}

.toc {
  display: grid;
  gap: 0.125rem;
}
.toc__item {
  width: 100%;
  padding: 0.625rem 0.75rem 0.625rem calc(0.75rem + var(--depth, 0) * 1rem);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  font-size: 0.9375rem;
  line-height: 1.35;
}
.toc__item:hover {
  background: var(--surface-2);
}
.toc__item[aria-current="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Toasts ---------- */
#toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 0.75rem);
  z-index: 60;
  display: grid;
  gap: 0.5rem;
  width: min(100% - 2rem, 26rem);
  transform: translateX(-50%);
  pointer-events: none;
}
@media (min-width: 48rem) {
  #toasts {
    bottom: 1.5rem;
  }
}
body[data-route="reader"] #toasts {
  bottom: calc(3.75rem + env(safe-area-inset-bottom));
}
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  pointer-events: auto;
  border-radius: var(--radius-md);
  background: #1b1e22;
  color: #f2f4f6;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s var(--ease);
}
.toast.is-leaving {
  animation: toast-out 0.25s var(--ease) forwards;
}
.toast__action {
  padding: 0.25rem 0.5rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #6ee7d0;
  font-weight: 600;
}
.toast__action:hover {
  background: rgb(255 255 255 / 0.1);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: clamp(1.5rem, 4vw, 2.5rem);
  padding-block: 0.25rem;
  max-width: 100%;
}
.pagination[hidden] {
  display: none !important;
}
.pagination__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.625rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    color 0.15s,
    transform 0.15s var(--ease);
}
.pagination__btn:hover:not(:disabled) {
  background: var(--surface-2);
}
.pagination__btn:active:not(:disabled) {
  transform: scale(0.95);
}
.pagination__btn[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  cursor: default;
}
.pagination__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.pagination__ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 2.25rem;
  color: var(--muted);
  user-select: none;
  font-size: 0.875rem;
}
@media (max-width: 32rem) {
  .pagination {
    gap: 0.25rem;
  }
  .pagination__btn {
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.375rem;
    font-size: 0.8125rem;
  }
  .pagination__label {
    display: none;
  }
  .pagination__btn--prev,
  .pagination__btn--next {
    width: 2rem;
    min-width: 2rem;
    padding: 0;
  }
  .pagination__ellipsis {
    width: 1.25rem;
    height: 2rem;
  }
}
