/**
 * library.css — the HOME page (your books).
 *
 * A sideways-flipping book carousel (top) + the scrollable summary of the
 * centred book (below). Tapping a book opens it in the reader. No chapter/scene
 * navigator, no command bar. Loaded on library.html alongside page.css; uses
 * the design.css tokens (works in both themes).
 */

/* ===== Book carousel (flip sideways; tap a book to open) =============== */
/* Scroll affordance: brass chevrons overlaid at the edges so a first-time user
   sees the shelf is scrollable (in addition to the swipe gesture). Each arrow
   shows only when there's more shelf that way; tapping it scrolls one book.
   js/library.js wires the clicks + visibility. Palette: brass on a blurred
   ink disc, matching the app chrome. */
.lib-carousel-wrap { position: relative; }
.lib-arrow {
  position: absolute;
  top: 42%;                       /* over the covers, above the title/state row */
  transform: translateY(-50%);
  z-index: 6;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  border-radius: 50%;
  background: rgba(20, 23, 33, 0.8);
  color: var(--brass);
  border: 1px solid var(--brass);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.1s ease;
}
.lib-arrow svg { width: 20px; height: 20px; }
.lib-arrow:active { transform: translateY(-50%) scale(0.9); }
.lib-arrow-left  { left: 2px; }
.lib-arrow-right { right: 2px; }
.lib-arrow[hidden] { display: none; }
:root[data-theme="light"] .lib-arrow { background: rgba(239, 230, 210, 0.85); }

.lib-carousel {
  display: flex;
  gap: 0.9rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding: 0.3rem 0.1rem 1.2rem;
  margin-bottom: 0.6rem;
}
.lib-carousel::-webkit-scrollbar { height: 6px; }
.lib-carousel::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 100px; }

.app a.lib-book,
.lib-book {
  flex: 0 0 auto;
  scroll-snap-align: center;
  width: clamp(150px, 58vw, 188px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  background: var(--canvas-elev);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 1.1rem 1rem 1rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 140ms, transform 140ms, box-shadow 140ms;
}
.lib-book.is-selected {
  border-color: var(--brass);
  box-shadow: 0 0 0 1px var(--brass), 0 10px 30px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}
.app a.lib-book:hover { border-color: var(--brass); }
.lib-book.is-soon { cursor: default; }
.lib-book-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(150deg, var(--indigo), #2f3a5a);
  border: 1px solid var(--tile-edge);
  border-radius: 10px;
  overflow: hidden;
}
/* Cover artwork fills the 4:5 box; the type tag + Save chip layer above it. */
.lib-book-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.lib-book-cover.has-art .lib-book-glyph { display: none; }
.lib-book-cover .lib-book-type, .lib-book-cover .lib-book-chip { z-index: 2; }
/* The big glyph is the fallback when a book has no cover artwork (e.g. Book 2). */
.lib-book-glyph { font-family: var(--font-jp); font-weight: 900; font-size: 3.3rem; color: var(--brass); opacity: 0.92; }
/* Type accent: STUDY = vermilion (the primary product), ORIGINAL = hanada blue
   (secondary). The cover colour AND the corner tag both carry the cue. */
.lib-book.is-study .lib-book-cover { background: linear-gradient(150deg, var(--vermilion), #6e1f17); }
.lib-book.is-original .lib-book-cover { background: linear-gradient(150deg, #2b3d5e, #1f2c44); }
.lib-book.is-original .lib-book-glyph { color: #c2d2e8; opacity: 0.62; }
/* Coming-soon: the cover artwork stays full-colour; only the TEXT is greyed. */
.lib-book.is-soon .lib-book-title, .lib-book.is-soon .lib-book-en { opacity: 0.5; }
.lib-book.is-soon .lib-book-glyph { color: var(--text-soft); }
/* The IMPORTER card — a <button> shaped like a book (always rightmost). Inherits the
   centered .lib-book layout (don't reset font/text-align — that's what made the title
   look off); just a transparent dashed frame + big ＋ glyph signal "add your own". */
.lib-book.is-upload { background: transparent; border-style: dashed; }
.lib-book.is-upload:hover { border-color: var(--brass); }
.lib-book.is-upload .lib-book-cover { background: linear-gradient(150deg, #262a3a, #1d2130); border-style: dashed; border-color: var(--brass); }
.lib-upload-glyph { font-family: var(--font-jp); font-weight: 900; font-size: 3.3rem; line-height: 1; color: var(--brass); opacity: 0.9; }
.lib-book.is-upload .lib-book-title, .lib-book.is-upload .lib-book-en { color: var(--brass); }
.lib-book.is-upload.is-busy { opacity: 0.6; pointer-events: none; }
.lib-book-title {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);          /* theme-aware — readable on the card in both themes */
  letter-spacing: 0.03em;
}
.lib-book-en {
  font-family: var(--font-en);
  font-style: italic;
  font-size: 0.8rem;
  color: var(--text-soft);
}
.lib-book-state {
  font-family: var(--font-ui);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.lib-book.is-selected .lib-book-state { color: var(--brass); }

/* per-book progress bar on the card */
.lib-book-progress { display: flex; align-items: center; gap: 0.5rem; width: 100%; margin-top: 0.55rem; }
.lib-book-bar { flex: 1 1 auto; height: 4px; border-radius: 3px; background: rgba(201, 164, 100, 0.22); overflow: hidden; }
.lib-book-bar-fill { display: block; height: 100%; border-radius: 3px; background: var(--brass); transition: width 0.3s ease; }
.lib-book-pct { flex: 0 0 auto; font-family: var(--font-en); font-size: 0.66rem; font-weight: 600; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.lib-book-progress.is-started .lib-book-pct { color: var(--brass); }

/* ----- Card chrome: type tag (top-left) + the single status/save chip (top-right) ----- */
.lib-book-type {
  position: absolute;
  top: 8px; left: 8px;
  padding: 2px 9px;
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  border-radius: 5px;
}
.lib-book-type.is-study { background: var(--vermilion); color: #fdeee9; }
.lib-book-type.is-original { background: var(--hanada); color: #f1f6fc; }

/* ONE control for offline: ↓ Save → N% → ✓ Saved (tap to remove). */
.lib-book-chip {
  position: absolute;
  top: 7px; right: 7px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.66rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--brass);
  background: rgba(20, 23, 33, 0.82);
  color: var(--brass);
  cursor: pointer;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.lib-book-chip .chip-i { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.lib-book-chip.is-saved { color: #e2ead9; border-color: rgba(127, 176, 105, 0.7); }
.lib-book-chip.is-saved .chip-i { stroke: #7fb069; }
.lib-book-chip.is-saving, .lib-book-chip.is-wait {
  color: var(--text-soft); border-color: var(--rule); cursor: default;
  font-variant-numeric: tabular-nums;
}
.lib-book-chip:active { transform: scale(0.95); }

/* ----- Meta row under the cover: chapter count + progress / read-only note ----- */
.lib-book-meta { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.lib-book-count {
  font-family: var(--font-en);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.lib-book.is-selected .lib-book-count { color: var(--brass); }
/* Study Part series: a bold "Part N" replaces the chapter count (the series differentiator). */
.lib-book-part { font-family: var(--font-en); font-size: 1.02rem; font-weight: 700; letter-spacing: 0.06em; color: var(--brass); text-transform: uppercase; }
.lib-book-part.is-soon { color: var(--text-soft); }
/* "Coming soon" printed across a part's (greyed) cover, replacing its part label. */
.lib-book-soon-cover { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; font-family: var(--font-en); font-size: 1rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #f1e8d6; background: rgba(20, 23, 42, 0.52); }
.lib-book-note {
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}
.lib-book-note.is-original { color: var(--hanada); }
.lib-book-note.is-soon { color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.08em; }

/* ===== Centred book — summary panel =================================== */
.lib-nav-head { margin-bottom: 0.9rem; }
.lib-nav-eyebrow {
  font-family: var(--font-ui);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 0.3rem;
}
.lib-nav-title {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--text);
  letter-spacing: 0.04em;
  margin: 0;
}
.lib-nav-en {
  font-family: var(--font-en);
  font-style: italic;
  font-size: 0.88rem;
  color: var(--text-soft);
  margin-top: 0.15rem;
}

/* primary "open this book" action (cards also open on tap) */
.app a.lib-open-btn,
.lib-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  margin: 0.2rem 0 1rem;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--brass);
  border-radius: 999px;
  background: var(--card-inset, rgba(201, 164, 100, 0.1));
  color: var(--brass);
  text-decoration: none;
  font-family: var(--font-en);
  font-weight: 600;
  font-size: 0.98rem;
  transition: filter 0.12s ease, transform 0.12s ease;
}
.lib-open-btn:hover { filter: brightness(1.08); }
.lib-open-btn:active { transform: translateY(1px); }
.lib-open-pct {
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
  padding-left: 0.6rem;
  border-left: 1px solid rgba(201, 164, 100, 0.45);
}

/* scrollable "about this book" summary */
.lib-summary { margin-top: 0.2rem; }
.lib-summary-label {
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--brass);
  margin-bottom: 0.55rem;
}
.lib-summary-body {
  max-height: 42vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--canvas-elev);
}
.lib-summary-body p {
  margin: 0;
  font-family: var(--font-en);
  font-size: 1.0rem;
  line-height: 1.7;
  color: var(--text-soft);
}

.lib-empty {
  font-family: var(--font-en);
  font-style: italic;
  color: var(--text-soft);
  line-height: 1.6;
  padding: 0.5rem 0;
}

/* ----- Kindle-model states (native wrap; web books are all same-origin) ---- */
/* Not-downloaded ('available'): greyed cover, stays in the carousel. */
.lib-book.is-remote .lib-book-cover {
  filter: grayscale(0.9);
  opacity: 0.55;
}
.lib-book.is-remote { cursor: pointer; }
.lib-book.is-downloading .lib-book-cover { opacity: 0.75; filter: grayscale(0.4); }

/* Cover badge: ✓ saved offline / ↓ tap to download. */
.lib-book-cover { position: relative; }
.lib-book-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-family: var(--font-ui, system-ui, sans-serif);
  background: rgba(26, 29, 44, 0.82);
  border: 1px solid var(--brass, #c9a464);
  color: var(--brass, #c9a464);
}
.lib-book-badge.is-saved { color: #e8dcc4; }

/* "Free" corner flag — top-left of the cover (download badge sits top-right). */
.lib-book-free {
  position: absolute;
  top: 8px;
  left: -5px;
  padding: 2px 8px 2px 7px;
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #1a1d2c;
  background: var(--brass, #c9a464);
  border-radius: 2px 3px 3px 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  z-index: 2;
}
/* little folded-ribbon corner under the flag */
.lib-book-free::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -4px;
  border-width: 0 5px 4px 0;
  border-style: solid;
  border-color: transparent #8a6f3e transparent transparent;
}
/* (old cover-bottom "Chapter x/25" strip removed — the count now lives in the
   meta row under the cover; see .lib-book-count above.) */

/* Summary-panel download row. */
.lib-dl-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0.9rem 0 0.2rem;
}
.lib-dl-btn {
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--brass, #c9a464);
  background: transparent;
  color: var(--brass, #c9a464);
  cursor: pointer;
}
.lib-dl-btn:active { transform: scale(0.97); }
.lib-dl-btn.is-remove { border-color: rgba(232, 220, 196, 0.35); color: var(--text-soft, #a89f8a); }
.lib-dl-state, .lib-dl-saved {
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: 0.76rem;
  color: var(--text-soft, #a89f8a);
}
.lib-dl-saved { color: var(--brass, #c9a464); }
