/* ชั้นหนังสือ "อ่านหนังสือ" — ใช้ token ของเว็บ (--bg --surface --text --muted --accent --line)
   ไม่ตั้ง overflow:hidden หรือ cursor:none บน html/body ไม่ fixed ที่ไม่ใช่ของตัวเอง */

.tshelf-root {
  isolation: isolate;
  position: relative;
}

.tshelf-intro {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 14px;
}

.tshelf {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

/* ---------- 3D stage (decorative only — pointer-events:none, aria-hidden) ---------- */
.tshelf-stage {
  position: relative;
  height: 460px;
  perspective: 1100px;
  pointer-events: none;
}
.tshelf[data-mode="flat"] .tshelf-stage { display: none; }

.tshelf-track {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.tshelf-tape {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 150px;
  height: 225px;
  margin: -112px 0 0 -75px;
  will-change: transform, opacity;
  transition: box-shadow .15s;
}
.tshelf-tape svg { display: block; width: 100%; height: 100%; border-radius: 3px; }
.tshelf-tape.is-center svg { box-shadow: 0 10px 30px rgba(0,0,0,.35); }

/* ---------- invisible hit layer (captures pointer input, geometry-based picking) ---------- */
.tshelf-hit {
  position: absolute;
  inset: 0;
  touch-action: pan-y;
  cursor: grab;
}
.tshelf-hit:active { cursor: grabbing; }
.tshelf[data-mode="flat"] .tshelf-hit { display: none; }

/* ---------- roving-tabindex link layer: real <a> elements, always present ----------
   3D mode: visually hidden but focusable (keyboard + screen reader path, and the
   no-JS fallback since the href always points at the real textbook page).
   flat mode: these ARE the visible UI (horizontal scroll-snap row). */
.tshelf-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 10px;
}

.tshelf[data-mode="3d"] .tshelf-links {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
  clip: rect(0 0 0 0);
}
.tshelf[data-mode="3d"] .tshelf-links a:focus-visible {
  position: fixed;
  width: auto;
  height: auto;
  clip: auto;
  top: 8px;
  left: 8px;
  z-index: 60;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
}

.tshelf[data-mode="flat"] .tshelf-links {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}
.tshelf[data-mode="flat"] .tshelf-links a {
  scroll-snap-align: center;
  flex: 0 0 min(42vw, 170px);
  display: block;
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  transition: transform .15s, box-shadow .15s;
}
.tshelf[data-mode="flat"] .tshelf-links a svg { display: block; width: 100%; height: auto; }
.tshelf[data-mode="flat"] .tshelf-links a:hover,
.tshelf[data-mode="flat"] .tshelf-links a:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
  outline: 2px solid var(--accent);
}

/* ---------- caption (announced only when the shelf is stationary) ---------- */
.tshelf-caption {
  text-align: center;
  padding: 10px 14px 14px;
  color: var(--muted);
  font-size: 13px;
  min-height: 1.4em;
}
.tshelf[data-mode="flat"] .tshelf-caption { display: none; }

/* ---------- controls row (mode toggle is user-overridable; drag/scroll hint) ---------- */
.tshelf-hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px 0;
  font-size: 12px;
  color: var(--muted);
}
.tshelf-hint button {
  font: inherit;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
}

/* ---------- detail dialog ---------- */
.tshelf-detail {
  width: min(420px, 92vw);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
.tshelf-detail::backdrop { background: rgba(0,0,0,.55); }
.tshelf-detail-body { padding: 20px 22px 22px; }
.tshelf-detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
}
.tshelf-detail h2 { margin: 6px 0 4px; font-size: 18px; }
.tshelf-detail .tshelf-detail-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.tshelf-detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.tshelf-detail-actions a {
  display: inline-block;
  padding: 9px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.tshelf-detail-actions a.primary { background: var(--accent); color: var(--on-accent); }
.tshelf-detail-actions a.secondary { border: 1px solid var(--line); color: var(--text); }

@media (max-width: 767px) {
  .tshelf-stage { height: 0; }
}
