/* Hianime extras on top of manga-rw-static tokens. */
html, body { overflow-x: hidden; }
html {
  scrollbar-gutter: auto;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--faint) 70%, transparent) transparent;
}
html::-webkit-scrollbar { width: 8px; height: 0; }
html::-webkit-scrollbar-track { background: transparent; }
html::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--faint) 55%, transparent);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
html::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }
.page-home { overflow-x: clip; }
.rail-track, .rail-track-hero { scrollbar-width: none !important; }
.rail-track::-webkit-scrollbar,
.rail-track-hero::-webkit-scrollbar { display: none !important; height: 0 !important; }
.sched-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 var(--s5);
}
.sched-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  border-radius: var(--r1);
  background: var(--surface);
  font-weight: 700;
  font-size: var(--t-sm);
  color: var(--muted);
}
.sched-day:hover { color: var(--ink); background: var(--raised); }
.sched-day[aria-current] { background: var(--accent); color: var(--on-accent); }
.sched-today { font-family: var(--font-data); font-size: 10px; font-weight: 600; opacity: 0.85; }
@media (max-width: 640px) {
  .sched-week { gap: 4px; }
  .sched-day { min-height: 40px; font-size: var(--t-xs); }
}
.lang-switch {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 2px;
  border-radius: var(--r-full);
  background: var(--surface);
  flex-shrink: 0;
}
.lang-switch button {
  height: 28px;
  padding: 0 10px;
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--muted);
  font: 700 var(--t-2xs)/1 var(--font-data);
  letter-spacing: 0.06em;
  cursor: pointer;
}
.lang-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: var(--s2); margin-top: var(--s4); }
.ep-grid a {
  display: flex; align-items: center; justify-content: center;
  height: 40px; border-radius: var(--r1); background: var(--surface);
  font-family: var(--font-data); font-size: var(--t-sm); font-weight: 600;
}
.ep-grid a:hover { background: var(--ink); color: var(--bg); }

body.hi-watch .tabbar { display: none; }

.bookmark-btn {
  width: 40px; height: 40px; border: none; border-radius: var(--r-full);
  background: var(--surface); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.bookmark-btn svg { width: 18px; height: 18px; }
.bookmark-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.bookmark-btn[aria-pressed="true"] svg { fill: currentColor; }
.ep-box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
}
.ep-box {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: var(--r1);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-data);
  font-size: var(--t-xs);
  font-weight: 600;
  content-visibility: auto;
}
.ep-box:hover { background: var(--raised); }
.chapter-ord {
  width: 40px; height: 40px; border: none; border-radius: var(--r1);
  background: var(--surface); color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.chapter-ord:hover { color: var(--ink); background: var(--raised); }
.chapter-ord svg { width: 18px; height: 18px; }
.chapter-ord[data-asc="1"] svg { transform: scaleY(-1); }
.page-title { font-size: var(--t-2xl); font-weight: 800; margin: 0 0 var(--s3); }
.detail-cover { width: 100%; border-radius: var(--r1); aspect-ratio: 3/4; object-fit: cover; background: var(--surface); }
.detail-actions { display: flex; gap: var(--s2); align-items: center; }
.detail-desc { max-width: 65ch; color: var(--muted); line-height: 1.6; }
.detail-facts { display: grid; gap: var(--s2); }
.detail-fact { margin: 0; display: flex; gap: var(--s2); font-size: var(--t-sm); }
.detail-fact-label { color: var(--faint); min-width: 6em; }

.section-title { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--t-lg); }
.section-title svg { width: 18px; height: 18px; }
.rail-btn svg { width: 16px; height: 16px; }

body.hi-watch .tabbar { display: none; }

.page-watch { padding-bottom: var(--s6); }
.watch-back {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: 36px;
  margin-bottom: var(--s3);
  padding: 0 var(--s3);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--t-sm);
  font-weight: 600;
  max-width: 100%;
}
.watch-back:hover { color: var(--ink); }
.watch-back svg { width: 16px; height: 16px; flex-shrink: 0; }
.watch-back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-layout {
  display: grid;
  gap: var(--s4);
}
@media (min-width: 1024px) {
  .watch-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
    align-items: start;
  }
}
.watch-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: hsl(240 6% 6%);
  border-radius: var(--r1);
  overflow: hidden;
}
.watch-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.watch-error,
.watch-load {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--s3);
  padding: var(--s5);
  background: hsl(240 6% 8%);
  color: var(--ink);
  text-align: center;
}
.watch-error[hidden],
.watch-load[hidden] { display: none; }
.watch-error p,
.watch-load p { margin: 0; font-weight: 700; }
.load-dots::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: load-dots 1.2s steps(4, end) infinite;
}
@keyframes load-dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}
@media (prefers-reduced-motion: reduce) {
  .load-dots::after { animation: none; content: "..."; }
}
.watch-error .watch-muted { font-weight: 500; }
.watch-error .btn { margin-top: var(--s2); }
.ep-box.is-dead,
.watch-ep.is-dead {
  opacity: 0.38;
  text-decoration: line-through;
}
.watch-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-top: var(--s4);
}
.watch-title { font-size: var(--t-xl); font-weight: 800; margin: 0; }
.watch-title span { color: var(--muted); font-family: var(--font-data); font-size: var(--t-sm); font-weight: 600; margin-left: var(--s2); }
.watch-step { display: flex; gap: var(--s2); }
.watch-step .btn svg { width: 16px; height: 16px; }
.watch-label {
  margin: 0 0 var(--s2);
  color: var(--muted);
  font-size: var(--t-sm);
  font-weight: 600;
}
.watch-label span { font-family: var(--font-data); font-weight: 500; }
.watch-servers { margin-top: var(--s4); }
.watch-server-list { display: grid; gap: var(--s3); }
.watch-track-row {
  display: flex;
  gap: 2px;
  width: max-content;
  padding: 3px;
  border-radius: var(--r1);
  background: var(--surface);
}
.watch-track {
  height: 30px;
  padding: 0 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-data);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.watch-track:hover { color: var(--ink); }
.watch-track[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
}
.watch-server-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.watch-server {
  height: 36px;
  min-width: 88px;
  padding: 0 var(--s3);
  border: none;
  border-radius: var(--r1);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-data);
  font-size: var(--t-xs);
  font-weight: 600;
  cursor: pointer;
}
.watch-server:hover { background: var(--raised); }
.watch-server[aria-current] { background: var(--accent); color: var(--on-accent); }
.watch-server-hint {
  margin: 0;
  color: var(--faint);
  font-size: var(--t-xs);
}
.watch-muted { color: var(--faint); font-size: var(--t-sm); }
.watch-aside {
  background: var(--surface);
  border-radius: var(--r2);
  padding: var(--s3);
  max-height: min(70vh, 640px);
  overflow: auto;
}
.watch-epgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 6px;
}
.watch-ep {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: var(--r1);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-data);
  font-size: var(--t-xs);
  font-weight: 600;
  content-visibility: auto;
}
.watch-ep:hover { background: var(--raised); }
.watch-ep[aria-current] { background: var(--accent); color: var(--on-accent); }
.watch-related { margin-top: var(--s6); }
.watch-related .card-grid { margin-top: var(--s3); }
@media (max-width: 1023px) {
  .watch-aside { max-height: none; }
}

/* Phone / tablet chrome */
@media (max-width: 767px) {
  .topbar-inner {
    gap: var(--s2);
    height: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) var(--s3) 0;
  }
  .brand { font-size: var(--t-lg); }
  .topbar-tools { gap: 2px; }
  .lang-switch { height: 32px; }
  .lang-switch button { padding: 0 8px; }
  #app { padding: var(--s3) var(--s3) calc(72px + env(safe-area-inset-bottom, 0px)); }
  .page-title { font-size: var(--t-xl); }
  .browse-head { flex-wrap: wrap; gap: var(--s2); }
  .watch-track-row {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .watch-server, .watch-track { min-height: 44px; height: 44px; }
  .watch-step { width: 100%; }
  .watch-step .btn { flex: 1; min-height: 44px; justify-content: center; }
  .watch-title { font-size: var(--t-base); }
  .ep-box-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .sched-week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}

body.hi-watch #app { padding-bottom: var(--s4); }
@media (max-width: 767px) {
  body.hi-watch #app {
    padding: 0 0 calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .page-watch { padding: 0; }
  .watch-stage {
    border-radius: 0;
    width: 100%;
    max-height: min(56.25vw, 58dvh);
  }
  .watch-frame {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }
  .watch-back,
  .watch-toolbar,
  .watch-servers,
  .watch-aside,
  .watch-related {
    padding-left: var(--s3);
    padding-right: var(--s3);
  }
  .watch-back { margin: var(--s3) var(--s3) 0; }
  .watch-aside { border-radius: var(--r2); margin: 0 var(--s3); }
}

/* Landscape phone: player fills screen */
@media (orientation: landscape) and (max-height: 500px) {
  body.hi-watch .topbar { display: none; }
  body.hi-watch .watch-back,
  body.hi-watch .watch-toolbar,
  body.hi-watch .watch-servers,
  body.hi-watch .watch-aside,
  body.hi-watch .watch-related { display: none; }
  body.hi-watch #app { padding: 0; }
  body.hi-watch .watch-stage {
    position: fixed;
    inset: 0;
    z-index: 80;
    width: 100%;
    height: 100dvh;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 0;
  }
}

@media (pointer: coarse) {
  .watch-server, .watch-track, .bookmark-btn, .chapter-ord { min-height: 44px; min-width: 44px; }
  .search-field-input { font-size: 16px; }
}

/* player riêng (video + hls.js) */
.watch-video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; border: 0; display: block; }
.watch-video[hidden] { display: none; }

/* ===== player custom: control bar riêng, settings menu, skip OP, next-up =====
   Shape lock: interactive 10px / pill cho seek + next-up, card+menu 12px. 1 accent. */
.watch-ov { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.watch-ov[hidden] { display: none; }
.watch-ov.is-idle { cursor: none; }
.watch-ov.is-idle .wp-bar,
.watch-ov.is-idle .wp-big { opacity: 0; transform: translateY(6px); pointer-events: none; }
.wp-bar, .wp-big, .wp-skip, .wp-next, .wp-menu { pointer-events: auto; }
.wp-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 36px 8px 8px;
  background: linear-gradient(to top, hsl(0 0% 0% / .84), hsl(0 0% 0% / .38) 44%, transparent);
  transition: opacity .18s, transform .18s;
}
.wp-row { display: flex; align-items: center; gap: 2px; }
.wp-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 0; background: transparent; color: var(--ink); border-radius: 10px; cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
}
.wp-btn:hover { background: hsl(0 0% 100% / .13); }
.wp-btn:active { transform: scale(.94); }
.wp-btn svg { width: 20px; height: 20px; }
.wp-gap { flex: 1 1 auto; }
/* thanh seek: vùng chạm 22px, phần thấy 4px -> 7px khi hover/focus */
.wp-prog { position: relative; height: 22px; margin: 0 2px; display: flex; align-items: center; cursor: pointer; }
.wp-prog::after {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 4px; margin-top: -2px;
  border-radius: 999px; background: hsl(0 0% 100% / .2); transition: height .12s, margin-top .12s;
}
.wp-prog:hover::after, .wp-prog:focus-visible::after { height: 7px; margin-top: -3.5px; }
.wp-prog:focus-visible { outline: none; }
.wp-buf, .wp-play { position: absolute; top: 50%; left: 0; height: 4px; margin-top: -2px; border-radius: 999px; transition: height .12s, margin-top .12s; }
.wp-prog:hover .wp-buf, .wp-prog:hover .wp-play,
.wp-prog:focus-visible .wp-buf, .wp-prog:focus-visible .wp-play { height: 7px; margin-top: -3.5px; }
.wp-buf { background: hsl(0 0% 100% / .28); }
/* dải đánh dấu OP/ED trên thanh tiến độ (màu --live, khác accent của phần đã xem) */
.wp-seg { position: absolute; top: 50%; height: 4px; margin-top: -2px; background: hsl(352 85% 78%); border-radius: 2px; transition: height .12s, margin-top .12s; }
.wp-prog:hover .wp-seg, .wp-prog:focus-visible .wp-seg { height: 7px; margin-top: -3.5px; }
.wp-seg[hidden] { display: none; }
.wp-play { background: var(--accent); }
.wp-dot {
  position: absolute; top: 50%; left: 0; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 4px hsl(0 0% 0% / .5);
  opacity: 0; transition: opacity .12s;
}
.wp-prog:hover .wp-dot, .wp-prog:focus-visible .wp-dot { opacity: 1; }
.wp-tip {
  position: absolute; bottom: 24px; transform: translateX(-50%);
  padding: 4px 7px; border-radius: 7px; background: hsl(240 6% 10% / .96);
  border: 1px solid var(--line); color: var(--ink);
  font: 500 11.5px/1 var(--mono, ui-monospace, monospace); font-variant-numeric: tabular-nums;
  pointer-events: none; white-space: nowrap;
}
.wp-tip[hidden] { display: none; }
.wp-time {
  font: 500 12px/1 var(--mono, ui-monospace, SFMono-Regular, monospace);
  color: var(--ink); opacity: .78; padding: 0 6px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.wp-volbox { display: flex; align-items: center; }
.wp-vol { width: 0; opacity: 0; height: 22px; accent-color: var(--accent); cursor: pointer; transition: width .18s, opacity .18s; }
.wp-volbox:hover .wp-vol, .wp-vol:focus-visible { width: 72px; opacity: 1; margin-right: 6px; }
.wp-setbox { position: relative; }
.wp-menu {
  position: absolute; right: 0; bottom: 44px; min-width: 200px; max-height: 62vh; overflow: auto;
  padding: 5px; background: hsl(240 6% 10% / .97); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-lg); backdrop-filter: blur(12px);
}
.wp-menu[hidden] { display: none; }
.wp-mi {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%;
  padding: 9px 10px; border: 0; background: transparent; color: var(--ink); font-size: 12.5px;
  text-align: left; border-radius: 8px; cursor: pointer; transition: background .12s;
}
.wp-mi:hover { background: hsl(0 0% 100% / .1); }
.wp-mi em { font-style: normal; color: var(--muted); font-size: 11.5px; }
.wp-mi.is-on { color: var(--accent-ink); }
.wp-mi svg { width: 14px; height: 14px; color: var(--accent); flex: 0 0 auto; }
.wp-back { color: var(--muted); margin-bottom: 3px; border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.wp-btn:focus-visible, .wp-mi:focus-visible, .wp-skip:focus-visible, .wp-next:focus-visible, .wp-big:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.wp-big {
  position: absolute; inset: 0; margin: auto; width: 68px; height: 68px;
  border: 0; border-radius: 50%; background: hsl(0 0% 0% / .55); color: #fff;
  display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px);
  box-shadow: var(--shadow-lg); transition: opacity .18s, transform .18s, background .15s;
}
.wp-big[hidden] { display: none; }
.wp-big:hover { background: hsl(0 0% 0% / .72); transform: scale(1.05); }
.wp-big:active { transform: scale(.97); }
.wp-big svg { width: 30px; height: 30px; margin-left: 3px; }
.wp-spin { position: absolute; inset: 0; margin: auto; width: 44px; height: 44px; z-index: 1; pointer-events: none; }
.wp-spin[hidden] { display: none; }
.wp-spin span {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  border: 3px solid hsl(0 0% 100% / .2); border-top-color: var(--accent);
  animation: wp-rot .8s linear infinite;
}
@keyframes wp-rot { to { transform: rotate(360deg); } }
/* góc phải: skip OP + next-up (1 pill bấm được), không đè nhau */
.wp-corner { position: absolute; right: 12px; bottom: 58px; display: flex; flex-direction: column; gap: 7px; align-items: flex-end; z-index: 2; pointer-events: auto; }
.watch-ov.is-menu .wp-corner { opacity: 0; pointer-events: none; }
.wp-corner { transition: opacity .15s; }
.wp-skip {
  border: 1px solid hsl(0 0% 100% / .22); background: hsl(0 0% 0% / .58); color: #fff;
  font-weight: 600; font-size: 12.5px; padding: 10px 15px; border-radius: 10px; cursor: pointer;
  backdrop-filter: blur(8px); transition: border-color .15s, color .15s, background .15s, transform .1s;
}
.wp-skip:hover { border-color: var(--accent); color: var(--accent-ink); background: hsl(0 0% 0% / .74); }
.wp-skip:active { transform: scale(.97); }
.wp-skip[hidden] { display: none; }
.wp-next {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 13px; border-radius: 999px; border: 1px solid hsl(0 0% 100% / .22);
  background: hsl(240 6% 10% / .84); color: var(--ink); font-size: 12.5px; font-weight: 600;
  backdrop-filter: blur(10px); cursor: pointer;
  transition: border-color .15s, color .15s, background .15s, transform .1s;
}
.wp-next:hover { border-color: var(--accent); color: var(--accent-ink); background: hsl(240 6% 10% / .96); }
.wp-next:active { transform: scale(.97); }
.wp-next[hidden] { display: none; }
.wp-next svg { width: 14px; height: 14px; }
@media (max-width: 640px) {
  .wp-bar { padding: 30px 6px 6px; }
  .wp-vol { display: none; }
  .wp-btn { width: 44px; height: 44px; }
  .wp-btn svg { width: 22px; height: 22px; }
  .wp-time { font-size: 11.5px; padding: 0 3px; }
  .wp-corner { bottom: 62px; right: 8px; }
  .wp-big { width: 60px; height: 60px; }
  .wp-big svg { width: 26px; height: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .watch-ov .wp-bar, .watch-ov .wp-big, .wp-btn, .wp-mi, .wp-skip, .wp-next, .wp-prog::after,
  .wp-buf, .wp-play, .wp-dot, .wp-vol { transition: none; }
  .wp-big:hover { transform: none; }
  .wp-spin span { animation-duration: 1.6s; }
}

/* phụ đề tự render: nhấc lên khi thanh điều khiển hiện, hạ xuống khi thanh ẩn */
.watch-stage { container-type: inline-size; }
.wp-subs {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  max-width: 88%; padding: 2px 12px; border-radius: 8px;
  background: hsl(0 0% 0% / .42); color: #fff; text-align: center;
  font-size: calc(var(--cue, 1.25) * 2.4cqw); line-height: 1.35; font-weight: 600;
  text-shadow: 0 1px 2px hsl(0 0% 0% / .85);
  white-space: pre-line; pointer-events: none;
  transition: bottom .18s ease, opacity .18s ease;
}
.watch-ov:not(.is-idle) .wp-subs { bottom: 82px; }
.wp-subs:empty { opacity: 0; }
@media (max-width: 640px) { .watch-ov:not(.is-idle) .wp-subs { bottom: 72px; } }
@media (prefers-reduced-motion: reduce) { .wp-subs { transition: none; } }