* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  /* Covers fill whatever vertical room the header leaves, so they stay as large
     as they can be at any window size. 306px is the space above the cover
     (header + gap) plus the title block below it; 0.886 undoes the 1.129x
     perspective magnification. The width cap keeps phones sane, and the height
     is derived back from it so the 0.677 cover ratio always holds. */
  --cover-fit: clamp(260px, calc((100vh - 344px) * 0.886), 640px);
  --cover-w: min(calc(var(--cover-fit) * 0.677), calc(100vw * 0.58));
  --cover-h: calc(var(--cover-w) / 0.677);
  --side-scale: 0.8;
  --title-color: #000;
  --author-color: #8d8d8d;

  /* Vertical rhythm: the same gap sits above the nav row and below it,
     so the header and the shelf are evenly spaced. */
  --shelf-gap: 76px;
  /* Bottom of the nav row: 20px padding + 36px header row + gap + 39px nav row. */
  --nav-bottom: calc(20px + 36px + var(--shelf-gap) + 39px);
  /* The centre cover is magnified about the shelf's perspective origin
     (50% 40%), so it renders this far above the container's top edge:
     0.4 x containerHeight x (scale - 1), where scale = 1400/(1400-160). */
  --cover-lift: calc((var(--cover-h) + 140px) * 0.0516);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #fff;
  font-family: 'Figtree', sans-serif;
  /* Lock the page: no rubber-band scroll, no text auto-sizing on rotate. */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Pins the app to the viewport so the page itself can never pan. */
body {
  position: fixed;
  inset: 0;
  touch-action: manipulation; /* also kills double-tap-to-zoom */
  -webkit-tap-highlight-color: transparent;
}

/* The shelf handles its own horizontal drag, so the browser gets no gestures. */
.stage { touch-action: none; }
/* List and grid scroll vertically, and stop at their own bounds. */
.browse { touch-action: pan-y; overscroll-behavior: contain; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 40;
  padding: 20px;
  display: flex;
  flex-direction: column;
  /* Translucent so list/grid content passes softly beneath it. */
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}

.logo { width: 80px; height: 36px; flex-shrink: 0; }

/* Search */
.search { flex: 1; display: flex; justify-content: center; }
.search input {
  width: 100%;
  max-width: 420px;
  height: 30px;
  padding: 7px 20px;
  border: 1px solid rgba(145, 145, 145, 0.08);
  border-radius: 36px;
  background: #f4f4f4;
  font-family: 'Figtree', sans-serif;
  font-weight: 500;
  font-size: 12px;
  color: #2b2b2b;
  text-align: center;
  outline: none;
}
.search input::placeholder { color: #b1b1b1; }
/* Stays centred while typing, so the query grows outward from the middle. */
.search input:focus { border-color: rgba(0, 75, 236, 0.35); }
.search input::-webkit-search-cancel-button { cursor: pointer; }

/* Nav row */
.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
  max-width: 1120px;
  margin: var(--shelf-gap) auto 0;
}

.tabs { display: flex; align-items: center; gap: 36px; }
.tab-link {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 0 4px;
  border: none;
  border-bottom: 4px solid transparent;
  background: none;
  font-family: 'Geist Mono', monospace;
  font-weight: 400;
  font-size: 18px;
  color: rgba(43, 43, 43, 0.5);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.tab-link:hover { color: rgba(43, 43, 43, 0.8); }
/* The underline is a single shared bar (.tab-indicator) that slides between
   tabs, so the transparent border here only reserves its height. */
.tab-link.active { color: #2b2b2b; }

.tab-indicator {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 0;
  background: #004bec;
  border-radius: 2px;
  pointer-events: none;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
              width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.tab-caret { width: 18px; height: 18px; display: none; }

/* View toggles */
.view-ctas { display: flex; align-items: center; gap: 6px; }
.view-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 6px;
  border-radius: 29px;
  cursor: pointer;
}
/* State is carried by the icon — filled when selected, outline when not —
   so the glass chrome itself stays identical across all three. */
.view-cta img { width: 24px; height: 24px; display: block; }
.view-cta .icon-on { display: none; }
.view-cta.active .icon-on { display: block; }
.view-cta.active .icon-off { display: none; }
.view-cta:hover { box-shadow: 0 0 6px rgba(0, 0, 0, 0.28); }

/* ---------- Cover Flow stage ---------- */
.stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Anchored below the header rather than centred, so the gap stays even
     regardless of viewport height. */
  justify-content: flex-start;
  padding-top: calc(var(--nav-bottom) + var(--shelf-gap) + var(--cover-lift));
  user-select: none;
}

.coverflow {
  position: relative;
  width: 100%;
  height: calc(var(--cover-h) + 140px);
  perspective: 1400px;
  perspective-origin: 50% 40%;
  transform-style: preserve-3d;
}

.book {
  position: absolute;
  left: 50%;
  top: 0;
  width: var(--cover-w);
  height: var(--cover-h);
  margin-left: calc(var(--cover-w) / -2);
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.55s ease;
  cursor: pointer;
  will-change: transform;
}

.book .cover,
.book .reflection {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4.5px;
  display: block;
}

.book .cover {
  top: 0;
  box-shadow: 0 0 15.9px rgba(0, 0, 0, 0.15);
  background: #eee;
}

/* Mirrored copy of the cover, faded with a mask */
.book .reflection {
  top: calc(100% + 3px);
  transform: scaleY(-1);
  opacity: 1;
  pointer-events: none;
  /* Falls off quickly from the cover's edge so the title and author stay
     legible where they sit over it. (Local-space gradient, then flipped.) */
  -webkit-mask-image: linear-gradient(to top,
    rgba(0, 0, 0, 0.42) 0%, rgba(0, 0, 0, 0.12) 18%, transparent 34%);
  mask-image: linear-gradient(to top,
    rgba(0, 0, 0, 0.42) 0%, rgba(0, 0, 0, 0.12) 18%, transparent 34%);
}

.book-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  /* Sits 12px below the magnified centre cover. The container is
     (--cover-h + 140px) tall while the cover renders 1.129x its height about
     the perspective origin, so the offset scales with the cover. */
  margin-top: calc(var(--cover-h) * 0.07742 - 135.23px);
  text-align: center;
  max-width: 420px;
  z-index: 30;
}
.book-title {
  font-weight: 600;
  font-size: 17px;
  color: var(--title-color);
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-author {
  font-weight: 600;
  font-size: 15px;
  color: var(--author-color);
}

/* ---------- List & grid views ---------- */
/* Scrolls beneath the header so the glass has real content to refract. */
.browse {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: calc(var(--nav-bottom) + 28px) 20px 60px;
}
.browse-inner {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}

.browse-empty {
  max-width: 1120px;
  margin: 40px auto;
  text-align: center;
  font-family: 'Figtree', sans-serif;
  font-size: 15px;
  color: #8d8d8d;
}

/* Grid */
.browse-inner.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 32px 24px;
}
.grid .browse-item { cursor: pointer; }
.grid .browse-item img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4.5px;
  box-shadow: 0 0 13.5px rgba(0, 0, 0, 0.15);
  background: #eee;
  display: block;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.grid .browse-item:hover img {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}
.grid .browse-item h3 {
  margin-top: 12px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid .browse-item p {
  margin-top: 2px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #8d8d8d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* List */
.browse-inner.list { display: flex; flex-direction: column; }
.list .browse-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 8px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s ease;
}
.list .browse-item:hover { background: #fafafa; }
.list .browse-item img {
  width: 44px;
  height: 66px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);
  background: #eee;
  flex-shrink: 0;
}
.list .browse-item h3 {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: #000;
}
.list .browse-item p {
  margin-top: 2px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #8d8d8d;
}

/* ---------- Add button ---------- */
/* ---------- Liquid Glass ----------
   The header sits on white, so the glass reads through its edges rather than
   through refraction: a bright specular rim along the top, a darker settling
   edge at the bottom, and a soft cast shadow lifting it off the page. */
.glass {
  position: relative;
  isolation: isolate;
  border: 1px solid rgba(255, 255, 255, 0.8);
  background:
    linear-gradient(150deg,
      rgba(255, 255, 255, 0.92) 0%,
      rgba(255, 255, 255, 0.32) 46%,
      rgba(255, 255, 255, 0.78) 100%),
    rgba(228, 230, 238, 0.72);
  backdrop-filter: blur(18px) saturate(190%);
  -webkit-backdrop-filter: blur(18px) saturate(190%);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.05),
    0 6px 16px rgba(0, 0, 0, 0.1),
    inset 0 1px 1.5px rgba(255, 255, 255, 1),
    inset 0 -2px 3px rgba(120, 125, 145, 0.14),
    inset 0 0 14px rgba(255, 255, 255, 0.55);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

/* Glossy sheen across the top half */
.glass::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(to bottom,
    rgba(255, 255, 255, 0.7) 0%,
    rgba(255, 255, 255, 0.15) 45%,
    rgba(255, 255, 255, 0) 60%);
  pointer-events: none;
  z-index: -1;
}

/* Panels opt out of the lift with .glass--static; only controls react. */
.glass:not(.glass--static):hover {
  transform: translateY(-1px);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.06),
    0 10px 22px rgba(0, 0, 0, 0.12),
    inset 0 1px 1px rgba(255, 255, 255, 1),
    inset 0 -1px 2px rgba(0, 0, 0, 0.055),
    inset 0 0 12px rgba(255, 255, 255, 0.6);
}
.glass:not(.glass--static):active {
  transform: translateY(0);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 3px 8px rgba(0, 0, 0, 0.1),
    inset 0 1px 3px rgba(0, 0, 0, 0.09),
    inset 0 -1px 1px rgba(255, 255, 255, 0.7);
}

.add-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 21px;
  border-radius: 29px;
  color: #1d1d1f;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 20px; font-weight: 600; }
.modal-close {
  border: none;
  background: none;
  font-size: 28px;
  line-height: 1;
  color: #8d8d8d;
  cursor: pointer;
}

.modal-tabs {
  display: flex;
  gap: 8px;
  background: #f2f2f2;
  border-radius: 12px;
  padding: 4px;
}
.tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 9px;
  background: none;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #6f6f6f;
  cursor: pointer;
}
.tab.active { background: #fff; color: #000; box-shadow: 0 1px 4px rgba(0,0,0,0.12); }

.camera-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #111;
  aspect-ratio: 4 / 3;
}
.camera-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.scan-frame {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: 38%;
  border: 2.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.25);
}
.camera-wrap.photo-mode .scan-frame {
  width: 52%;
  height: 86%;
}
.camera-note {
  position: absolute;
  left: 0; right: 0; bottom: 10px;
  text-align: center;
  color: #fff;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}

.camera-fallback { font-size: 15px; display: flex; flex-direction: column; gap: 10px; }

.modal-actions { display: flex; justify-content: center; }
.manual-isbn { display: flex; gap: 8px; width: 100%; }
.manual-isbn input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #ddd;
  border-radius: 10px;
  font-family: 'Figtree', sans-serif;
  font-size: 15px;
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: #1d24e0; color: #fff; }
.btn.primary:hover { background: #161cb8; }
.btn.secondary { background: #f2f2f2; color: #2b2b2b; }
.btn.secondary:hover { background: #e6e6e6; }
.btn:disabled { opacity: 0.5; cursor: default; }

.modal-status {
  text-align: center;
  font-size: 14px;
  color: #6f6f6f;
  min-height: 20px;
}
.modal-status.error { color: #c62828; }

.confirm-card {
  display: flex;
  gap: 16px;
  background: #f8f8f8;
  border-radius: 14px;
  padding: 16px;
}
.confirm-card img {
  width: 96px;
  height: 142px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  background: #ddd;
}
.confirm-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}
.confirm-fields input {
  padding: 9px 12px;
  border: 1.5px solid #ddd;
  border-radius: 9px;
  font-family: 'Figtree', sans-serif;
  font-size: 15px;
}
.confirm-buttons { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- Small screens ---------- */
/* Shorter viewports: tighten the header rhythm; the covers size themselves. */
@media (min-width: 901px) and (max-height: 820px) { :root { --shelf-gap: 56px; } }
@media (min-width: 901px) and (max-height: 700px) { :root { --shelf-gap: 40px; } }

@media (max-width: 900px) {
  :root {
    --shelf-gap: 38px;
    /* 20px padding + 36px logo row + 30px gap + 44px search + gap + 39px nav */
    --nav-bottom: calc(20px + 36px + 30px + 44px + var(--shelf-gap) + 39px);
  }

  /* Stacked header: logo + CTA, then a full-width search field */
  .topbar-row { flex-wrap: wrap; gap: 0; }
  .search {
    order: 3;
    flex-basis: 100%;
    margin-top: 30px;
  }
  .search input {
    max-width: none;
    height: auto;
    padding: 14px 20px;
  }

  /* Tabs collapse to the current one with a caret */
  .tab-link { display: none; }
  .tab-link.active { display: flex; }
  .tab-caret { display: block; }

  .browse-inner.grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 24px 16px; }

  .book-title { font-size: 15px; max-width: 220px; }
  .book-author { font-size: 13px; }
}

/* ---------- Book detail tray ---------- */
.tray-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 22, 30, 0.28);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.32s ease;
}
.tray-scrim.open { opacity: 1; }

.tray {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 70;
  width: min(880px, calc(100vw - 32px));
  max-height: min(74vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 28px 28px;
  border-radius: 28px 28px 0 0;
  border-bottom: none;
  transform: translate(-50%, 100%);
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  /* Deeper cast than the header glass, since it floats over the shelf. */
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.06),
    0 -8px 40px rgba(0, 0, 0, 0.18),
    inset 0 1px 1.5px rgba(255, 255, 255, 1),
    inset 0 0 20px rgba(255, 255, 255, 0.5);
}
.tray.open { transform: translate(-50%, 0); }

/* Drag-handle affordance, doubles as a close button */
.tray-grip {
  display: block;
  width: 44px;
  height: 5px;
  margin: 0 auto 18px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: rgba(60, 64, 80, 0.28);
  cursor: pointer;
}
.tray-grip:hover { background: rgba(60, 64, 80, 0.45); }

.tray-body { display: flex; gap: 24px; align-items: flex-start; }

.tray-cover {
  width: 132px;
  flex-shrink: 0;
  aspect-ratio: 0.677;
  object-fit: cover;
  border-radius: 5px;
  background: #eee;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

.tray-text { flex: 1; min-width: 0; }
.tray-title {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 22px;
  color: #1d1d1f;
  line-height: 1.25;
}
.tray-author {
  margin-top: 4px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #8d8d8d;
}
.tray-synopsis {
  margin-top: 14px;
  font-family: 'Figtree', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: #3a3a40;
}

.tray-ctas { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.tray-cta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 18px;
  border-radius: 29px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: #1d1d1f;
  text-decoration: none;
  white-space: nowrap;
}
.tray-cta.primary {
  background: #004bec;
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.12),
    0 6px 16px rgba(0, 75, 236, 0.32),
    inset 0 1px 1px rgba(255, 255, 255, 0.45);
}
.tray-cta.primary::before {
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.28) 0%, rgba(255, 255, 255, 0) 58%);
}
.tray-cta.primary:hover {
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.14),
    0 10px 22px rgba(0, 75, 236, 0.4),
    inset 0 1px 1px rgba(255, 255, 255, 0.5);
}


@media (max-width: 900px) {
  .tray { width: 100%; padding: 12px 20px 24px; border-radius: 22px 22px 0 0; }
  .tray-body { gap: 16px; }
  .tray-cover { width: 92px; }
  .tray-title { font-size: 19px; }
  .tray-synopsis { font-size: 14px; margin-top: 10px; }
  .tray-ctas { gap: 6px; margin-top: 16px; }
  .tray-cta { height: 36px; padding: 0 14px; font-size: 13px; }
}

/* ---------- Entrance motion ----------
   Everything except the shelf eases in. The carousel keeps its own transform
   transition, so its movement is untouched.
   fill-mode is `backwards`, not `both`: the first keyframe holds during the
   delay, but once the run finishes the element returns to its normal styles,
   so hover lifts and other transforms still work afterwards. */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.logo,
.search,
.add-btn,
.tab-link,
.view-cta,
.book-meta {
  animation: rise-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

/* Staggered so the header assembles left to right, then the nav row */
.logo      { animation-delay: 0.04s; }
.search    { animation-delay: 0.10s; }
.add-btn   { animation-delay: 0.16s; }
.tab-link:nth-of-type(1) { animation-delay: 0.22s; }
.tab-link:nth-of-type(2) { animation-delay: 0.27s; }
.tab-link:nth-of-type(3) { animation-delay: 0.32s; }
.tab-link:nth-of-type(4) { animation-delay: 0.37s; }
.view-cta:nth-of-type(1) { animation-delay: 0.30s; }
.view-cta:nth-of-type(2) { animation-delay: 0.35s; }
.view-cta:nth-of-type(3) { animation-delay: 0.40s; }
.book-meta { animation-delay: 0.46s; }

/* Title and author cross-fade when the shelf lands on a new book */
.book-meta.swap { animation: fade-in 0.4s ease backwards; }

/* List and grid tiles ease in; the delay is set per item in app.js */
.browse-item { animation: rise-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) backwards; }

/* Add-book modal */
.modal-backdrop { animation: fade-in 0.22s ease backwards; }
.modal { animation: rise-in 0.38s cubic-bezier(0.22, 1, 0.36, 1) backwards; }

/* Respect a reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Mobile tab dropdown ---------- */
.tabs { position: relative; }

.tab-menu {
  position: absolute;
  top: calc(100% + 14px);
  left: 0;
  min-width: 240px;
  padding: 8px;
  border-radius: 22px;
  z-index: 80;
  display: none;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transform-origin: top left;
  transition: opacity 0.2s ease, transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
.tab-menu.open { opacity: 1; transform: translateY(0) scale(1); }

.tab-menu button {
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  border: none;
  background: none;
  border-radius: 14px;
  font-family: 'Geist Mono', monospace;
  font-weight: 400;
  font-size: 16px;
  color: #2b2b2b;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab-menu button:hover { background: rgba(255, 255, 255, 0.55); }
.tab-menu button.current { color: #004bec; }

/* Only phones collapse the tabs into a menu. */
@media (max-width: 900px) {
  .tab-menu { display: flex; }
  .tab-link.active { cursor: pointer; }
}

/* ---------- Cover-match candidates ---------- */
.candidates { display: flex; flex-direction: column; gap: 10px; }
.candidates-label {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: #2b2b2b;
}
.candidate-list { display: flex; flex-direction: column; gap: 6px; }

.candidate {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1.5px solid #eee;
  border-radius: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.candidate:hover { border-color: #004bec; background: #f7f9ff; }
.candidate img {
  width: 40px;
  height: 60px;
  object-fit: cover;
  border-radius: 3px;
  background: #eee;
  flex-shrink: 0;
}
.candidate-text { min-width: 0; }
.candidate-text strong {
  display: block;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: #1d1d1f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.candidate-text span {
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  color: #8d8d8d;
}

/* ---------- Remove & empty state ---------- */
.tray-remove {
  margin-top: 18px;
  padding: 0;
  border: none;
  background: none;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #9a9aa2;
  cursor: pointer;
  transition: color 0.15s ease;
}
.tray-remove:hover { color: #c62828; }
/* Second click confirms — destructive, and there is no undo. */
.tray-remove.confirming { color: #c62828; }

.empty-shelf {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 320px;
  text-align: center;
  font-family: 'Figtree', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #8d8d8d;
  z-index: 5;
}
.empty-shelf strong { color: #2b2b2b; }

/* ---------- Add-book: match, loading & error states ---------- */
.match-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 44px 0;
}
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #e6e6ef;
  border-top-color: #004bec;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.match-loading p {
  font-family: 'Figtree', sans-serif;
  font-weight: 500;
  font-size: 14px;
  color: #6f6f6f;
}

/* Matched book — the confirmation */
.match-confirm {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.match-question {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: #8d8d8d;
}
.match-cover-wrap {
  margin: 14px 0 16px;
  animation: match-pop 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
@keyframes match-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.match-cover {
  width: 150px;
  aspect-ratio: 0.66;
  object-fit: cover;
  border-radius: 6px;
  background: #eee;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}
.match-title {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 20px;
  line-height: 1.25;
  color: #1d1d1f;
}
.match-author {
  margin-top: 3px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #8d8d8d;
}
.match-year {
  margin-top: 5px;
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  color: #b1b1b1;
}
.match-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 20px;
}
.match-actions .btn { width: 100%; height: 44px; }

.match-others {
  width: 100%;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
  text-align: left;
}

/* Text-only button, used for the quiet fallbacks */
.link-btn {
  display: block;
  margin: 10px auto 0;
  padding: 6px;
  border: none;
  background: none;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #8d8d8d;
  cursor: pointer;
  transition: color 0.15s ease;
}
.link-btn:hover { color: #004bec; }

/* Error state */
.match-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 26px 8px 6px;
}
.error-art {
  margin-bottom: 12px;
  animation: match-pop 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.error-title {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 19px;
  color: #1d1d1f;
}
.error-msg {
  margin-top: 8px;
  font-family: 'Figtree', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #8d8d8d;
  max-width: 340px;
}
.error-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 18px;
}
.error-actions .btn { width: 100%; height: 44px; }

/* ============================== Tab pages ============================== */
.tab-page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: calc(var(--nav-bottom) + 24px) 20px 60px;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.page-inner {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
}

/* ---------- Shared empty state ---------- */
.empty-state {
  max-width: 380px;
  margin: 8vh auto 0;
  text-align: center;
  animation: rise-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.empty-art { margin-bottom: 16px; }
.empty-state h2 {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 22px;
  color: #1d1d1f;
}
.empty-state p {
  margin-top: 8px;
  font-family: 'Figtree', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: #8d8d8d;
}

/* ============================== Explore ============================== */
.explore-hero {
  display: flex;
  gap: 28px;
  align-items: center;
  padding: 28px;
  border-radius: 22px;
  background: linear-gradient(120deg, #f4f7ff 0%, #eef1fb 100%);
  margin-bottom: 40px;
  animation: rise-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.explore-hero-cover {
  width: 150px;
  flex-shrink: 0;
  aspect-ratio: 0.66;
  object-fit: cover;
  border-radius: 6px;
  background: #eee;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24);
  cursor: pointer;
  transition: transform 0.2s ease;
}
.explore-hero-cover:hover { transform: translateY(-3px); }
.explore-hero-body { min-width: 0; }
.explore-eyebrow {
  font-family: 'Geist Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #004bec;
}
.explore-hero-title {
  margin-top: 8px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 26px;
  line-height: 1.2;
  color: #1d1d1f;
}
.explore-hero-author {
  margin-top: 4px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #8d8d8d;
}
.explore-hero-synopsis {
  margin-top: 12px;
  font-family: 'Figtree', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #3a3a40;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.explore-hero-btn {
  margin-top: 18px;
  height: 40px;
  padding: 0 22px;
  border: none;
  border-radius: 29px;
  background: #004bec;
  color: #fff;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.explore-hero-btn:hover { background: #0038b8; transform: translateY(-1px); }

.shelf-row { margin-bottom: 36px; }
.shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.shelf-title {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 18px;
  color: #1d1d1f;
}
.shelf-count {
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  color: #b1b1b1;
}
.shelf-scroll {
  display: flex;
  gap: 18px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.shelf-item {
  flex: 0 0 auto;
  width: 118px;
  scroll-snap-align: start;
  cursor: pointer;
}
.shelf-item img {
  width: 118px;
  aspect-ratio: 0.66;
  object-fit: cover;
  border-radius: 5px;
  background: #eee;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.shelf-item:hover img {
  transform: translateY(-4px);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
}
.shelf-item h4 {
  margin-top: 9px;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #1d1d1f;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.shelf-item span {
  font-family: 'Figtree', sans-serif;
  font-size: 12px;
  color: #8d8d8d;
}

/* ============================== Settings ============================== */
.settings-group { margin-bottom: 30px; animation: rise-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards; }
.settings-group > h2 {
  font-family: 'Geist Mono', monospace;
  font-weight: 400;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8d8d8d;
  margin-bottom: 10px;
}
.settings-card {
  border: 1px solid #ececf2;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}
.settings-row + .settings-row { border-top: 1px solid #f0f0f4; }
.settings-row-text { min-width: 0; }
.settings-row-text strong {
  display: block;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: #1d1d1f;
}
.settings-row-text span {
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: #8d8d8d;
}
.settings-row-control { flex-shrink: 0; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 28px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d7d7e0;
  transition: background 0.2s ease;
}
.switch .track::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
.switch input:checked + .track { background: #004bec; }
.switch input:checked + .track::before { transform: translateX(18px); }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 11px;
  background: #f2f2f5;
}
.segmented button {
  padding: 6px 14px;
  border: none;
  border-radius: 9px;
  background: none;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #6f6f6f;
  cursor: pointer;
  transition: color 0.15s ease;
}
.segmented button.active {
  background: #fff;
  color: #1d1d1f;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.settings-btn {
  padding: 9px 16px;
  border: 1px solid #e0e0e8;
  border-radius: 10px;
  background: #fff;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #2b2b2b;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.settings-btn:hover { background: #f6f6f9; }
.settings-btn.danger { color: #c62828; border-color: #f0d4d4; }
.settings-btn.danger:hover { background: #fdf3f3; }
.settings-btn.danger.confirming { background: #c62828; border-color: #c62828; color: #fff; }

.settings-about {
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  line-height: 1.6;
  color: #8d8d8d;
  padding: 2px 2px;
}
.settings-about a { color: #004bec; text-decoration: none; }
.settings-about a:hover { text-decoration: underline; }

/* Optional visual preferences driven from Settings */
.no-reflections .book .reflection { display: none; }
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-delay: 0ms !important;
  transition-duration: 0.01ms !important;
}

@media (max-width: 900px) {
  .explore-hero { flex-direction: column; text-align: center; gap: 18px; padding: 22px; }
  .explore-hero-cover { width: 130px; }
  .explore-hero-synopsis { -webkit-line-clamp: 4; }
}

/* ============================== Read status & lists ============================== */

/* Read badge on a cover (Explore shelves, browse grid/list, list page) */
.shelf-item, .browse-item { position: relative; }
.read-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #004bec;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* ---------- Tray: status toggle + add-to-list ---------- */
.tray-shelf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
}
.tray-status {
  display: inline-flex;
  padding: 3px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.05);
}
.tray-status button {
  padding: 7px 15px;
  border: none;
  border-radius: 9px;
  background: none;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #6f6f6f;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tray-status button.active { background: #fff; color: #1d1d1f; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.tray-status button[data-read="true"].active { background: #004bec; color: #fff; }

.tray-listwrap { position: relative; }
.tray-listbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid #e0e0e8;
  border-radius: 29px;
  background: #fff;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #2b2b2b;
  cursor: pointer;
  transition: background 0.15s ease;
}
.tray-listbtn:hover { background: #f6f6f9; }
.tray-listbtn img { width: 15px; height: 15px; opacity: 0.55; }

.tray-listmenu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 236px;
  max-height: 264px;
  overflow-y: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.2);
  padding: 6px;
  z-index: 5;
}
.listmenu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: none;
  border-radius: 9px;
  font-family: 'Figtree', sans-serif;
  font-weight: 500;
  font-size: 14px;
  color: #2b2b2b;
  cursor: pointer;
  text-align: left;
}
.listmenu-item:hover { background: #f4f4f7; }
.listmenu-check {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 5px;
  border: 1.5px solid #ccced9;
  display: flex;
  align-items: center;
  justify-content: center;
}
.listmenu-item.checked .listmenu-check { background: #004bec; border-color: #004bec; }
.listmenu-item.checked .listmenu-check::after {
  content: '';
  width: 5px;
  height: 9px;
  margin-top: -2px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.listmenu-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listmenu-create {
  display: flex;
  gap: 6px;
  padding: 8px 6px 4px;
  margin-top: 4px;
  border-top: 1px solid #f0f0f4;
}
.listmenu-create input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
}
.listmenu-create button {
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: #004bec;
  color: #fff;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- Lists page ---------- */
.lists-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.lists-title {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 26px;
  color: #1d1d1f;
}
.lists-new-btn {
  flex-shrink: 0;
  height: 38px;
  padding: 0 18px;
  border: none;
  border-radius: 29px;
  background: #004bec;
  color: #fff;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lists-new-btn:hover { background: #0038b8; }

.list-creator { display: flex; gap: 8px; align-items: center; margin-bottom: 24px; }
.list-creator input {
  flex: 1;
  max-width: 320px;
  height: 38px;
  padding: 0 14px;
  border: 1.5px solid #ddd;
  border-radius: 10px;
  font-family: 'Figtree', sans-serif;
  font-size: 14px;
}

.list-section { margin-bottom: 34px; animation: rise-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards; }
.list-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.list-section-headleft { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.list-section-title {
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 18px;
  color: #1d1d1f;
}
.list-section-count {
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  color: #b1b1b1;
}
.list-del-btn {
  flex-shrink: 0;
  border: none;
  background: none;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #9a9aa2;
  cursor: pointer;
  transition: color 0.15s ease;
}
.list-del-btn:hover, .list-del-btn.confirming { color: #c62828; }
.list-empty-hint {
  font-family: 'Figtree', sans-serif;
  font-size: 14px;
  color: #b1b1b1;
  padding: 6px 0;
}

/* ---------- Explore: discovery cards & add ---------- */
.explore-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14vh 0;
}
.explore-loading p {
  font-family: 'Figtree', sans-serif;
  font-weight: 500;
  font-size: 14px;
  color: #6f6f6f;
}

.explore-card { display: flex; flex-direction: column; }
.explore-add {
  margin-top: 8px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid #d7d9e3;
  border-radius: 8px;
  background: #fff;
  font-family: 'Figtree', sans-serif;
  font-weight: 600;
  font-size: 12px;
  color: #004bec;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.explore-add:hover { background: #f0f4ff; }
.explore-add.owned {
  color: #8d8d8d;
  background: #f6f6f9;
  border-color: #ececf2;
  cursor: default;
}

.explore-hero-btn.owned { background: #eef1fb; color: #6f6f6f; }
.explore-hero-btn.owned:hover { background: #eef1fb; transform: none; }
