/* pages/shorts.css — trang Shorts (templates/pages/shorts.html). Bản vẽ: design/redesign-style-c/frames/SH_*.
   Máy tính: khung video dọc 9:16 + cột nút + cột thông tin. Điện thoại (≤ 860px): video phủ kín màn hình.
   Chỉ dùng biến trong tokens.css. Lớp phủ trên video dùng rgba (đen/trắng trong suốt) như base.css. */

.sh-root .cover { height: 100px; }
.page.sh-page { max-width: 1128px; padding: 0 64px 48px; }
.sh-page .page-lead { margin-bottom: 16px; }

.sh-layout { display: flex; flex-wrap: wrap; gap: 16px 16px; align-items: flex-start; }

/* ── Khung xem ──────────────────────────────────────────────────── */
.sh-stage { position: relative; display: flex; gap: 12px; flex-shrink: 0; }
.sh-stage[hidden] { display: none; }
.sh-frame {
  position: relative; flex-shrink: 0;
  height: min(800px, calc(100vh - 32px)); min-height: 480px; aspect-ratio: 9 / 16;
  border-radius: 12px; overflow: hidden; background: var(--video-bg);
}
.sh-feed {
  position: absolute; inset: 0;
  overflow-y: auto; overscroll-behavior: contain;
  scroll-snap-type: y mandatory; scrollbar-width: none;
}
.sh-feed::-webkit-scrollbar { display: none; }

.sh-item {
  position: relative; height: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  background: var(--video-bg); user-select: none; -webkit-user-select: none;
}
.sh-item video { display: block; width: 100%; height: 100%; object-fit: contain; background: var(--video-bg); cursor: pointer; }

.sh-play-ind {
  position: absolute; left: 50%; top: 50%; width: 72px; height: 72px; margin: -36px 0 0 -36px;
  border-radius: 50%; background: rgba(15, 23, 42, 0.45); color: var(--on-accent);
  display: none; place-items: center; pointer-events: none;
}
.sh-play-ind .icon { margin-left: 4px; }
.sh-item.is-paused .sh-play-ind { display: grid; }

/* Phụ đề (bôi đen được để tra từ) */
.sh-sub {
  position: absolute; left: 12px; right: 16px; bottom: 84px;
  padding: 10px 14px; border-radius: var(--r-md);
  background: rgba(15, 23, 42, 0.62); color: var(--on-accent); text-align: center;
}
.sh-sub[hidden] { display: none; }
.sh-sub-text { user-select: text; -webkit-user-select: text; cursor: text; }
.sh-sub-line { margin: 0; font-family: var(--font-jp); font-size: 20px; line-height: 1.5; }
.sh-sub-reading { margin: 2px 0 0; font-family: var(--font-jp); font-size: 13px; color: rgba(255, 255, 255, 0.72); }
.sh-sub.is-empty { font-size: 13px; color: rgba(255, 255, 255, 0.72); }
.sh-sub-text ::selection { background: rgba(56, 139, 253, 0.65); }

/* Thời gian + thanh tua */
.sh-progress { position: absolute; left: 14px; right: 14px; bottom: 14px; }
.sh-time { margin: 0 0 6px; font-size: 12px; color: rgba(255, 255, 255, 0.85); }
.sh-seek, .sh-range {
  --progress: 0%;
  display: block; width: 100%; margin: 0; background: transparent; cursor: pointer;
  appearance: none; -webkit-appearance: none;
}
.sh-seek { height: 16px; }
.sh-seek::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--on-accent) var(--progress), rgba(255, 255, 255, 0.3) var(--progress));
}
.sh-seek::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.3); }
.sh-seek::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--on-accent); }
.sh-seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--on-accent);
}
.sh-seek::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--on-accent); }

/* Video YouTube nhúng — chừa 56px dưới đáy cho thanh điều khiển của YouTube */
.sh-yt-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--video-bg); }
.sh-yt-tap {
  position: absolute; left: 0; right: 0; top: 0; bottom: 56px; z-index: 1;
  border: 0; padding: 0; background: transparent; cursor: pointer; touch-action: pan-y;
}
.sh-yt-badge {
  position: absolute; left: 12px; top: 12px; z-index: 2;
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px;
  border-radius: var(--r-sm); background: var(--bg); color: var(--red); font-size: 12px; font-weight: 600;
  pointer-events: none;
}
.sh-item.is-yt .sh-play-ind { z-index: 2; }

/* Trạng thái tải / lỗi trong khung */
.sh-state {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 24px; text-align: center; color: rgba(255, 255, 255, 0.85);
}
.sh-state p { margin: 0; font-size: 14px; }
.sh-spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2); border-top-color: var(--on-accent);
  animation: sh-spin 0.8s linear infinite;
}
@keyframes sh-spin { to { transform: rotate(360deg); } }

/* Chữ nổi khi tua */
.sh-scrub, .sh-seek-flash {
  position: absolute; left: 50%; top: 42%; z-index: 3; transform: translate(-50%, -50%);
  padding: 8px 14px; border-radius: var(--r-md);
  background: rgba(15, 23, 42, 0.62); color: var(--on-accent); font-size: 16px; font-weight: 600;
  font-variant-numeric: tabular-nums; pointer-events: none; opacity: 0; transition: opacity 0.15s ease;
}
.sh-seek-flash.is-left { left: 25%; }
.sh-seek-flash.is-right { left: 75%; }
.sh-scrub.is-shown, .sh-seek-flash.is-shown { opacity: 1; }

/* ── Cột nút cạnh video ─────────────────────────────────────────── */
.sh-rail { display: flex; flex-direction: column; justify-content: space-between; align-items: center; }
.sh-rail[hidden] { display: none; }
.sh-nav, .sh-actions { display: flex; flex-direction: column; align-items: center; }
.sh-nav { gap: 8px; }
.sh-actions { gap: 14px; }
.sh-nav-btn, .sh-icon-btn {
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}
.sh-nav-btn:hover:not(:disabled), .sh-icon-btn:hover { border-color: var(--faint); color: var(--ink); }
.sh-nav-btn:disabled { opacity: 0.4; cursor: default; }
.sh-icon-btn { width: 36px; height: 36px; border: 0; color: var(--muted); }

.sh-act {
  width: 60px; padding: 0; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.sh-act[hidden] { display: none; }
.sh-act-circle {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: var(--bg-soft); color: var(--text);
}
.sh-act:hover .sh-act-circle { color: var(--ink); background: var(--line); }
.sh-act-label { font-size: 12px; color: var(--muted); }
.sh-act.is-on .sh-act-circle { background: var(--blue-tag); color: var(--accent); }
.sh-act.is-on .sh-act-circle .icon g { fill: currentColor; fill-opacity: 0.25; }
.sh-fs-off { display: none; }
.sh-stage.is-fs .sh-fs-on { display: none; }
.sh-stage.is-fs .sh-fs-off { display: contents; }

.sh-float-fish {
  position: absolute; z-index: 5; color: var(--accent); pointer-events: none;
  animation: sh-fish-up 1.2s ease-out forwards;
}
@keyframes sh-fish-up {
  from { opacity: 1; transform: translateY(0) rotate(0) scale(0.8); }
  to { opacity: 0; transform: translateY(-120px) rotate(var(--rot, 0deg)) scale(1.2); }
}

/* Thanh trên (chỉ hiện trên điện thoại & khi toàn màn hình) */
.sh-topbar { display: none; }
.sh-topbar-title { flex-grow: 1; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-topbar-level { padding: 2px 6px; border-radius: var(--r-sm); background: rgba(255, 255, 255, 0.22); font-size: 11px; }
.sh-topbar-level[hidden] { display: none; }
.sh-exit-fs {
  display: none; align-items: center; gap: 8px; height: 40px; padding: 0 14px; margin-left: 8px;
  border: 0; border-radius: var(--r-md); background: rgba(255, 255, 255, 0.12); color: var(--on-accent);
  font-size: 14px; cursor: pointer;
}
.sh-stage .sh-menu-btn { border: 0; background: none; color: var(--on-accent); }

/* Nút kính lúp nổi dưới vùng bôi đen (điện thoại) */
.sh-lookup-fab {
  position: fixed; z-index: 95; width: 46px; height: 46px; padding: 0;
  border: 0; border-radius: 50%; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.sh-lookup-fab[hidden] { display: none; }

/* ── Cột thông tin ──────────────────────────────────────────────── */
.sh-info { flex: 1 1 300px; min-width: 0; padding-left: 20px; }
.sh-info-title { margin: 0 0 8px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; overflow-wrap: anywhere; }
.sh-info-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.sh-tag-yt { background: var(--red-bg); color: var(--red); }
.sh-info .prop-value .tag { font-size: 12px; }
.sh-tips { padding: 14px 16px; border-radius: var(--r-md); background: var(--callout); }
.sh-tips-title { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.sh-tips ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.75; color: var(--text); }
.sh-empty-info { margin: 10px 0 0; font-size: 14px; line-height: 1.6; color: var(--text); }

/* Thẻ tra từ (static/js/dict_popup.js) đặt trong cột thông tin thay vì nổi cạnh con trỏ.
   dict_popup.js gán left/top trực tiếp → cần !important để giữ thẻ đứng yên trong cột. */
.sh-lookup-note { display: none; margin: 12px 0 0; font-size: 13px; }
.sh-info.is-lookup #sh-info-body { display: none; }
.sh-info.is-lookup .sh-lookup-note { display: block; }
.dict-popup.sh-dict {
  /* z-index 1: thẻ nằm trong cột, KHÔNG được đè lên thanh trên cùng (z 20) khi trang đã cuộn */
  position: relative !important; z-index: 1; left: auto !important; top: auto !important;
  max-width: none; min-width: 0; max-height: min(640px, calc(100vh - 160px));
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  transform: none; transition: none;
}
.dict-popup.sh-dict:not(.show) { display: none; }
/* Toàn màn hình: thẻ được chuyển vào trong khung xem, đứng bên phải */
.sh-stage > .dict-popup.sh-dict {
  position: absolute !important; z-index: 6; left: auto !important; top: 80px !important; right: 24px;
  width: min(400px, calc(100% - 32px)); max-height: calc(100% - 120px);
}

/* ── Chưa có video ──────────────────────────────────────────────── */
.sh-empty {
  width: 450px; max-width: 100%; min-height: 520px; flex-shrink: 0; padding: 32px;
  border: 1px dashed var(--faint); border-radius: 12px; background: var(--bg-side);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.sh-empty-icon {
  width: 56px; height: 56px; border-radius: 12px; background: var(--bg-soft); color: var(--muted);
  display: grid; place-items: center;
}
.sh-empty-title { margin: 14px 0 4px; font-size: 17px; font-weight: 600; }
.sh-empty-text { margin: 0 0 18px; font-size: 14px; line-height: 1.55; color: var(--muted); }

/* ── Hộp cài đặt ────────────────────────────────────────────────── */
.sh-settings { width: min(440px, calc(100vw - 32px)); border-radius: 12px; }
.sh-settings-head { display: flex; align-items: center; padding: 14px 14px 14px 22px; border-bottom: 1px solid var(--line); }
.sh-settings-head .dialog-title { flex-grow: 1; }
.sh-settings-body { padding: 20px 22px 24px; }
.sh-settings-row { display: flex; align-items: center; font-size: 14px; font-weight: 600; }
.sh-settings-row span { flex-grow: 1; }
.sh-settings-row b { font-size: 15px; color: var(--accent); }
.sh-range { height: 22px; margin: 10px 0 4px; }
.sh-range::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--progress), var(--line) var(--progress));
}
.sh-range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
.sh-range::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
.sh-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px;
  border: 2px solid var(--accent); border-radius: 50%; background: var(--bg);
}
.sh-range::-moz-range-thumb { width: 18px; height: 18px; border: 2px solid var(--accent); border-radius: 50%; background: var(--bg); }
.sh-range-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--faint); }
.sh-settings-note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.sh-settings-label { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.sh-chips { display: flex; gap: 8px; }
.sh-chip {
  min-width: 64px; height: 40px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg); color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
}
.sh-chip:hover { border-color: var(--faint); }
.sh-chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ── Toàn màn hình (SH_5_Fullscreen) — dùng cả khi Fullscreen API không có ── */
body.sh-fs-open { overflow: hidden; }
.sh-stage.is-fs {
  position: fixed; inset: 0; z-index: 90; display: block;
  background: var(--video-bg); color: var(--on-accent);
}
.sh-stage.is-fs .sh-frame {
  position: absolute; left: 50%; top: 0; height: 100%; min-height: 0; max-width: 100%;
  transform: translateX(-50%); border-radius: 0;
}
.sh-stage.is-fs .sh-sub { bottom: 96px; }
.sh-stage.is-fs .sh-topbar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 8px; padding: 14px 24px;
  pointer-events: none;
}
.sh-stage.is-fs .sh-topbar > * { pointer-events: auto; }
.sh-stage.is-fs .sh-topbar-title { flex-grow: 0; max-width: 40%; }
.sh-stage.is-fs .sh-topbar .sh-exit-fs { display: inline-flex; margin-left: auto; }
.sh-stage.is-fs .sh-menu-btn { display: none; }
.sh-stage.is-fs .sh-rail {
  position: absolute; z-index: 4; bottom: 110px;
  left: min(calc(50% + 28.125vh + 20px), calc(100% - 80px));
}
.sh-stage.is-fs .sh-nav { display: none; }

/* Nút trên nền tối (toàn màn hình + điện thoại) */
.sh-stage.is-fs .sh-act-circle { background: rgba(15, 23, 42, 0.45); color: var(--on-accent); }
.sh-stage.is-fs .sh-act-label { color: var(--on-accent); }
.sh-stage.is-fs .sh-act.is-on .sh-act-circle { background: var(--accent); }

/* ── Điện thoại & máy tính bảng ─────────────────────────────────── */
@media (max-width: 1100px) {
  .page.sh-page { padding: 0 32px 48px; }
  .sh-info { padding-left: 4px; }
}

@media (max-width: 860px) {
  /* Có video: khung xem phủ kín màn hình (SH_M_Feed); thanh bên vẫn mở được bằng nút menu. */
  .sh-root:not(.is-empty) .cover,
  .sh-root:not(.is-empty) .page-icon,
  .sh-root:not(.is-empty) .page-title,
  .sh-root:not(.is-empty) .page-lead,
  .sh-root:not(.is-empty) .preview-note { display: none; }
  .page.sh-page { padding: 0 16px 48px; }
  .sh-layout { flex-direction: column; }
  .sh-stage, .sh-stage.is-fs {
    position: fixed; inset: 0; z-index: 30; display: block;
    background: var(--video-bg); color: var(--on-accent);
  }
  .sh-stage.is-fs { z-index: 90; }
  .sh-frame, .sh-stage.is-fs .sh-frame {
    position: absolute; inset: 0; left: 0; height: auto; min-height: 0; aspect-ratio: auto;
    transform: none; border-radius: 0;
  }
  .sh-stage .sh-topbar {
    position: absolute; left: 0; right: 0; top: 0; z-index: 4;
    display: flex; align-items: center; gap: 6px; height: 64px; padding: 0 12px 0 6px;
    background: linear-gradient(rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0));
  }
  .sh-stage.is-fs .sh-topbar { height: 64px; padding: 0 12px 0 16px; }
  .sh-stage.is-fs .sh-topbar-title { flex-grow: 1; max-width: none; }
  .sh-stage .sh-exit-fs span { display: none; }
  .sh-stage .sh-exit-fs { padding: 0 12px; }
  .sh-stage .sh-rail, .sh-stage.is-fs .sh-rail {
    position: absolute; z-index: 4; left: auto; right: 6px; bottom: 150px;
  }
  .sh-stage .sh-nav { display: none; }
  .sh-stage .sh-act-circle { background: rgba(15, 23, 42, 0.45); color: var(--on-accent); }
  .sh-stage .sh-act-label { color: var(--on-accent); }
  .sh-stage .sh-act.is-on .sh-act-circle { background: var(--accent); }
  .sh-sub { right: 76px; bottom: 72px; }
  .sh-sub-line { font-size: 18px; }
  .sh-stage.is-fs .sh-sub { bottom: 72px; }
  .sh-seek { height: 20px; }

  /* Thông tin bên phải ẩn đi; chỉ còn thẻ tra từ dạng tấm trượt dưới đáy (SH_M_Lookup). */
  .sh-root:not(.is-empty) .sh-info { padding: 0; }
  .sh-root:not(.is-empty) #sh-info-body, .sh-info.is-lookup .sh-lookup-note { display: none; }
  .sh-root.is-empty .sh-info { padding: 0; }
  .sh-empty { width: 100%; min-height: 360px; }
  .dict-popup.sh-dict, .sh-stage > .dict-popup.sh-dict {
    position: fixed !important; z-index: 96; left: 0 !important; right: 0; top: auto !important; bottom: 0;
    width: auto; max-width: none; max-height: 62vh;
    border: 0; border-radius: 14px 14px 0 0; box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.25);
  }
  .sh-stage.is-lookup .sh-sub { bottom: calc(62vh + 12px); }
}

@media (prefers-reduced-motion: reduce) {
  .sh-spinner, .sh-float-fish { animation: none; }
  .sh-feed { scroll-behavior: auto; }
}

/* Phụ đề tiếng Trung: pinyin TRÊN từng từ — sáng cho nền tối (13/10/2026) */
.sh-sub-line .jf-ruby rt { color: rgba(255, 255, 255, 0.78); }
