/*
 * Trang `/` — chiếu slide PDF. Chủ đề tối (data-theme="dark" trên <html>).
 * Slide là trung tâm: nền đen tuyệt đối, canvas không viền/bóng/bo góc,
 * thanh điều khiển tự ẩn. Chỉ viết bố cục; màu/chữ/thời lượng lấy từ tokens.css.
 */

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  overscroll-behavior: none;
}

/* Mọi thao tác vuốt/chạm là của trình chiếu, không phải của trình duyệt. */
.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Vị trí + kích thước CSS do slides.js đặt theo từng trang (khớp lưới điểm ảnh thiết bị). */
.slide {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
}

body[data-idle],
body[data-idle] .stage {
  cursor: none;
}

/* ---------- Đang tải lần đầu ---------- */
.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  color: var(--ink-muted);
  text-align: center;
  /* Máy local tải xong trong vài chục ms: đợi 300ms rồi mới hiện, khỏi nháy chữ. */
  animation: loader-in var(--dur) var(--ease) 300ms both;
}
body:not([data-state="loading"]) .loader {
  display: none;
}

.loader__text {
  font-size: var(--fs-md);
  font-weight: 500;
}

.loader__track {
  width: 220px;
  height: 3px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
}

.loader__fill {
  width: 100%;
  height: 100%;
  background: var(--ink);
  transform: scaleX(var(--loaded, 0));
  transform-origin: left center;
  transition: transform var(--dur-fast) linear;
}

.loader__bytes {
  min-height: 1.35em;
  font-size: var(--fs-xs);
}

@keyframes loader-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Màn hướng dẫn (chưa có file / file hỏng / lỗi tải) ---------- */
.guide {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(560px, calc(100vw - 2 * var(--space-5)));
  max-height: calc(100dvh - 2 * var(--space-5));
  overflow-y: auto;
  padding: var(--space-2) 0 var(--space-2) var(--space-6);
  transform: translate(-50%, -50%);
}

.guide__title {
  font-size: var(--fs-2xl);
  font-weight: 800;
  line-height: 1.15;
}

.guide__lead {
  margin-top: var(--space-4);
  font-size: var(--fs-lg);
  line-height: var(--lh-read);
  color: var(--ink-muted);
}

.guide__steps {
  counter-reset: step;
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-5);
  font-size: var(--fs-lg);
  line-height: var(--lh-read);
}

/* Lưới (số | chữ): toàn bộ chữ nằm trong một <span> để <code> không thành ô riêng. */
.guide__steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 1.5em minmax(0, 1fr);
  column-gap: var(--space-3);
  align-items: baseline;
}

.guide__steps li::before {
  content: counter(step);
  font-weight: 800;
  font-variant-numeric: lining-nums;
  color: var(--accent);
}

.guide code {
  padding: 0.05em 0.35em;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--ink);
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

.guide__lead code {
  color: var(--ink);
}

.guide .btn {
  margin-top: var(--space-6);
}

/* ---------- Ô nhảy trang khi gõ số ---------- */
.jump {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: var(--z-overlay);
  min-width: 200px;
  padding: var(--space-4) var(--space-6) var(--space-4);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.jump__value {
  font-size: var(--fs-3xl);
  font-weight: 800;
  line-height: 1.15;
}

.jump__hint {
  margin-top: var(--space-1);
  font-size: var(--fs-sm);
  color: var(--ink-muted);
}

.jump[data-invalid] .jump__hint {
  color: var(--accent);
}

/* ---------- Thanh điều khiển ---------- */
.chrome {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-dock);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: 0 var(--space-4) calc(var(--space-3) + 3px + env(safe-area-inset-bottom, 0px));
  /* Không phủ nền cả dải: chỉ hai cụm nút có nền tối (.chrome__group), phần còn lại của slide
   * (chân trang, dòng nguồn) vẫn đọc được khi thanh điều khiển đang hiện. */
  transition:
    opacity var(--dur) var(--ease),
    transform var(--dur) var(--ease),
    visibility 0s linear 0s;
}

/* Ẩn: mờ + tụt 8px, rồi mới tắt visibility (không còn bấm/tab vào được). */
body[data-idle] .chrome {
  opacity: 0;
  transform: translateY(8px);
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity var(--dur) var(--ease),
    transform var(--dur) var(--ease),
    visibility 0s linear var(--dur);
}

/* Thanh tiến độ sát mép dưới: rãnh tối để vẫn thấy trên slide nền trắng. */
.chrome__progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.55);
}

.chrome__progress-fill {
  height: 100%;
  background: var(--accent);   /* đỏ: thấy được trên cả slide nền sáng lẫn rãnh tối */
  transform: scaleX(var(--progress, 0));
  transform-origin: left center;
}

.chrome__group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: 4px;
  background: rgba(0, 0, 0, 0.78);
  border-radius: calc(var(--radius) + 4px);
}

.chrome__group--end {
  margin-inline-start: auto;
}

.chrome .btn {
  min-height: 40px;
  padding: 6px var(--space-4);
  font-size: var(--fs-sm);
}

/* Không có số đều: chừa chỗ cố định để nút "Sau" không nhảy khi 9 → 10. */
.pager {
  min-width: 5.5em;
  font-size: var(--fs-md);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

.pager__total {
  color: var(--ink-muted);
}

@media (max-width: 479px) {
  .chrome {
    padding-inline: var(--space-4);
  }
  .chrome__group--end {
    margin-inline-start: 0;
  }
}
