/* ============================================================
   Resource pages: book reader, audio player, image viewer,
   font preview and file card. Loaded only on resource pages.
   ============================================================ */

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The viewers' own display rules must not show what the script has hidden */
.book [hidden], .audio-card [hidden], .font-preview [hidden] { display: none !important; }

.resource-page { padding: 28px 0 72px; background: var(--bg-page); }

/* ── Heading ── */
.resource-head { margin-bottom: 24px; }
.resource-crumbs { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 0.86rem; font-weight: 600; }
.resource-crumbs a { color: var(--primary); text-decoration: none; }
.resource-crumbs a:hover { text-decoration: underline; }
.resource-crumbs i { font-size: 0.6rem; color: var(--text-muted); }
.resource-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.resource-head h1 { font-size: clamp(1.7rem, 3.6vw, 2.5rem); line-height: 1.2; color: var(--text-main); }
.resource-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; font-size: 0.9rem; color: var(--text-muted); }
.resource-meta i { color: var(--maroon); margin-right: 4px; }
.resource-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.resource-actions .btn-pill { padding: 11px 22px; cursor: pointer; font: inherit; font-weight: 600; }
.btn-pill-line { background: var(--bg-card); border-color: var(--border-color); color: var(--text-main); }
.btn-pill-line:hover { border-color: var(--forest); color: var(--forest); }

.resource-about { max-width: 780px; margin: 32px auto 0; }
.resource-related { margin-top: 56px; }
.resource-related h2 { margin-bottom: 18px; font-size: 1.45rem; color: var(--text-main); }

/* ── Book reader ── */
.book {
  position: relative;
  padding: clamp(16px, 3vw, 36px) clamp(8px, 3vw, 36px) 16px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.08), transparent 60%),
    linear-gradient(180deg, #24382e 0%, #15241c 100%);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.book-stage { position: relative; min-height: 360px; display: flex; align-items: center; justify-content: center; }
.book.is-ready .book-stage { min-height: 0; display: block; }
.book-pages { width: 100%; margin: 0 auto; }
.book-page { background: #fdfcf7; overflow: hidden; }
.book-page-inner { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #fdfcf7; }
.book-page-inner canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
/* A real book: the paper curves into the spine, page edges stack on the outside */
.book-page-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.book-page.--left .book-page-inner::after {
  background:
    linear-gradient(to left, rgba(0, 0, 0, 0.22) 0, rgba(0, 0, 0, 0.08) 2.5%, rgba(0, 0, 0, 0) 7%),
    linear-gradient(to right, rgba(255, 255, 255, 0.18) 0, rgba(255, 255, 255, 0) 3%);
}
.book-page.--right .book-page-inner::after {
  background:
    linear-gradient(to right, rgba(0, 0, 0, 0.22) 0, rgba(0, 0, 0, 0.08) 2.5%, rgba(0, 0, 0, 0) 7%),
    linear-gradient(to left, rgba(255, 255, 255, 0.18) 0, rgba(255, 255, 255, 0) 3%);
}
.book-page.--left { box-shadow: -2px 0 0 #f1ede2, -4px 1px 0 #d9d2bf, -6px 2px 0 #ece6d6, -8px 3px 0 #cfc7b2, 0 18px 40px rgba(0, 0, 0, 0.45); }
.book-page.--right { box-shadow: 2px 0 0 #f1ede2, 4px 1px 0 #d9d2bf, 6px 2px 0 #ece6d6, 8px 3px 0 #cfc7b2, 0 18px 40px rgba(0, 0, 0, 0.45); }
.book-page[data-density="hard"].--left, .book-page[data-density="hard"].--right { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5); }
.book-page[data-density="hard"] .book-page-inner { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.book-page-wait, .book-spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(15, 70, 51, 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: book-spin 0.9s linear infinite;
}
.book-spinner { border-color: rgba(255, 255, 255, 0.2); border-top-color: var(--gold-soft); }
@keyframes book-spin { to { transform: rotate(360deg); } }
.book-status { display: flex; flex-direction: column; align-items: center; gap: 14px; color: #dfe8e0; font-size: 0.95rem; }

.book-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 18px auto 0;
  padding: 6px;
  width: fit-content;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}
.book-bar[hidden] { display: none; }
.book-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  border: 0; border-radius: 50%;
  background: transparent; color: #fff;
  font-size: 1rem; cursor: pointer;
  transition: background 0.15s ease;
}
.book-btn:hover, .book-btn:focus-visible { background: rgba(255, 255, 255, 0.16); }
.book-count { display: flex; align-items: center; gap: 8px; color: #dfe8e0; font-size: 0.92rem; }
.book-count input {
  width: 3.6em; padding: 6px 4px;
  border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 8px;
  background: rgba(0, 0, 0, 0.2); color: #fff;
  text-align: center; font: inherit;
  -moz-appearance: textfield;
}
.book-count input::-webkit-outer-spin-button, .book-count input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.book-btn-full { margin-left: 4px; }
.book-hint { margin: 10px 0 0; text-align: center; font-size: 0.8rem; color: rgba(223, 232, 224, 0.65); }
.book-fallback { padding: 40px 16px; text-align: center; color: #dfe8e0; }
.book-fallback i { font-size: 2.4rem; color: var(--gold-soft); margin-bottom: 12px; }
.book-fallback a, .book-noscript a { color: var(--gold-soft); font-weight: 600; }
.book.is-failed .book-stage { display: none; }

/* Full screen: the book fills the screen on its dark desk */
.book:fullscreen { display: flex; flex-direction: column; justify-content: center; border-radius: 0; padding: 24px; overflow: auto; }
.book:fullscreen .book-hint { display: none; }

/* ── Audio player ── */
.audio-card {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 28px;
  align-items: center;
  max-width: 860px;
  margin: 0 auto;
  padding: 24px;
  background: linear-gradient(135deg, var(--forest) 0%, var(--forest-deep) 100%);
  border-radius: 14px;
  color: #fff;
}
.audio-art { aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: rgba(255, 255, 255, 0.06); display: flex; align-items: center; justify-content: center; }
.audio-art img { width: 100%; height: 100%; object-fit: cover; }
.audio-disc {
  display: flex; align-items: center; justify-content: center;
  width: 78%; aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--maroon) 0 18%, #1b2a22 19% 21%, #0b1712 22% 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 0 0 6px rgba(255, 255, 255, 0.04);
  font-family: var(--font-chakma); font-size: 2.2rem; color: var(--gold-soft);
}
.audio-card.is-playing .audio-disc { animation: book-spin 6s linear infinite; }
.audio-title { margin-bottom: 14px; font-family: var(--font-display); font-size: 1.35rem; line-height: 1.3; }
.audio-card audio { width: 100%; }
.audio-card.is-custom audio { display: none; }
.audio-ui[hidden] { display: none; }
.audio-seek input {
  --fill: 0%;
  width: 100%; height: 6px; margin: 0;
  -webkit-appearance: none; appearance: none;
  background: linear-gradient(90deg, var(--gold-soft) var(--fill), rgba(255, 255, 255, 0.2) var(--fill));
  border-radius: 999px; cursor: pointer;
}
.audio-seek input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); }
.audio-seek input::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; }
.audio-times { display: flex; justify-content: space-between; margin-top: 6px; font-size: 0.8rem; color: #bccdbf; font-variant-numeric: tabular-nums; }
.audio-controls { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 10px; }
.audio-play {
  display: inline-flex; align-items: center; justify-content: center;
  width: 62px; height: 62px;
  border: 0; border-radius: 50%;
  background: var(--gold-soft); color: #2a1e04;
  font-size: 1.3rem; cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}
.audio-play:hover { transform: scale(1.05); }
.audio-play .fa-play { margin-left: 3px; }
.audio-skip, .audio-speed {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08); color: #fff;
  cursor: pointer; font: inherit; font-size: 0.85rem; font-weight: 600;
}
.audio-skip small { position: absolute; font-size: 0.55rem; font-weight: 700; }
.audio-skip i { font-size: 1.15rem; opacity: 0.85; }
.audio-skip:hover, .audio-speed:hover { background: rgba(255, 255, 255, 0.16); }
.audio-speed { width: auto; min-width: 48px; padding: 0 12px; border-radius: 999px; }

/* ── Image viewer ── */
.image-view { margin: 0; }
.image-open {
  position: relative;
  display: block;
  width: 100%;
  padding: clamp(10px, 2vw, 20px);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-card);
  cursor: zoom-in;
}
.image-open img { display: block; max-width: 100%; max-height: 72vh; margin: 0 auto; border-radius: 6px; }
.image-zoom-hint {
  position: absolute; right: 18px; bottom: 18px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(7, 36, 26, 0.78); color: #fff;
  font-size: 0.8rem; font-weight: 600;
}
.lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: rgba(8, 14, 11, 0.96);
}
.lightbox::backdrop { background: rgba(8, 14, 11, 0.96); }
.lightbox-canvas { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; cursor: zoom-in; }
.lightbox-canvas.is-zoomed { cursor: grab; }
.lightbox-canvas img { max-width: 94vw; max-height: 86vh; transform-origin: center; transition: transform 0.08s linear; user-select: none; }
.lightbox-bar {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 6px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.12);
}
.lightbox-bar button, .lightbox-bar a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent; color: #fff; font-size: 1rem; cursor: pointer; text-decoration: none;
}
.lightbox-bar button:hover, .lightbox-bar a:hover { background: rgba(255, 255, 255, 0.16); }

/* ── Font preview ── */
.font-preview { padding: clamp(18px, 3vw, 32px); background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 14px; }
.font-preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.font-preview-label { font-weight: 700; color: var(--text-main); }
.font-preview-label i { color: var(--maroon); margin-right: 6px; }
.font-size-control { display: flex; align-items: center; gap: 10px; color: var(--text-muted); }
.font-size-control input { width: 160px; accent-color: var(--forest); }
.font-status { margin-bottom: 12px; color: var(--text-muted); font-size: 0.92rem; }
.font-sample { color: var(--text-main); line-height: 1.5; overflow-wrap: anywhere; }
.font-sample p { margin-bottom: 0.3em; }
.font-try { display: block; margin-top: 20px; }
.font-try span { display: block; margin-bottom: 6px; font-size: 0.86rem; font-weight: 600; color: var(--text-muted); }
.font-try textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border-color); border-radius: 10px;
  background: var(--bg-page); color: var(--text-main); line-height: 1.4; resize: vertical;
}
.font-try textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ── File card (installers, documents) ── */
.file-card {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: clamp(18px, 3vw, 28px);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
}
.file-card-icon {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 76px; height: 88px; flex: none;
  border-radius: 10px;
  background: var(--primary-light); color: var(--forest);
  font-size: 1.7rem;
}
.file-card-icon small { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; }
.file-card-text { flex: 1 1 260px; min-width: 0; }
.file-card-name { font-weight: 700; color: var(--text-main); overflow-wrap: anywhere; }
.file-card-meta { margin-top: 2px; font-size: 0.88rem; color: var(--text-muted); }
.file-card-help { margin-top: 10px; font-size: 0.92rem; line-height: 1.55; color: var(--text-body); }
.file-card-help a { color: var(--primary); }

@media (max-width: 600px) {
  .resource-page { padding-top: 18px; }
  .resource-actions { width: 100%; }
  .resource-actions .btn-pill { flex: 1 1 0; justify-content: center; }
  .book { margin: 0 -16px; border-radius: 0; padding: 14px 10px 12px; }
  .audio-card { grid-template-columns: 1fr; gap: 18px; padding: 20px; }
  .audio-art { width: 150px; margin: 0 auto; }
  .audio-title { text-align: center; }
  .file-card .btn-pill { width: 100%; justify-content: center; }
  .font-size-control input { width: 120px; }
}
