:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #e4e4df;
  --accent: #0b6bcb;
  --thumb-bg: #e9e9e4;
  --sub-en: #f8fafc;
  --sub-vi: #fbbf24;
  --sub-scale: 1;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --panel: #1b1b1b;
    --text: #ecece8;
    --muted: #9a9a94;
    --line: #2d2d2a;
    --accent: #74b9ff;
    --thumb-bg: #262626;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.site-header-inner, .wrap { max-width: 1180px; margin: 0 auto; padding-inline: 1.4rem; }
.site-header-inner { display: flex; align-items: center; padding-block: 0.2rem; }
.brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  overflow-wrap: anywhere;
}
.brand:focus-visible, .folder-back:focus-visible, .crumbs a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.wrap { padding-block: 1.4rem; }
h1 { font-size: 1.35rem; margin: 0.2rem 0 0.4rem; font-weight: 650; }

.crumbs { color: var(--muted); margin: 0.2rem 0 1rem; word-break: break-word; }
.crumbs a { color: var(--muted); }
.crumbs .sep { padding: 0 0.25rem; }

.folder-back, .listing-mobile { display: none; }
.listing-heading { margin-bottom: 0.8rem; overflow-wrap: anywhere; }
.listing-resume {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.listing-progress {
  display: block;
  width: min(100%, 10rem);
  height: 3px;
  margin-top: 0.25rem;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) 0 var(--watched, 0%), var(--line) var(--watched, 0%) 100%);
}

.listing {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.listing th, .listing td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
.listing th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.listing tr:last-child td { border-bottom: 0; }
.listing tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.thumb-col { width: 176px; }
.thumb {
  display: block;
  width: 160px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--thumb-bg);
}
.fileicon { display: inline-block; width: 160px; font-size: 1.8rem; text-align: center; }
.name { font-weight: 500; overflow-wrap: anywhere; }
.subs-col { width: 88px; white-space: nowrap; }
.size-col { width: 90px; white-space: nowrap; color: var(--muted); }
.date-col { width: 150px; white-space: nowrap; color: var(--muted); }

.badge {
  display: inline-block;
  margin-right: 0.25rem;
  padding: 0.08rem 0.34rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--bg);
}
.count { color: var(--muted); font-size: 0.85rem; margin-top: 0.8rem; }

.watch-title { margin-top: 0.1rem; }
.meta { color: var(--muted); font-size: 0.88rem; margin: 0 0 0.9rem; }
.meta .dot { padding: 0 0.4rem; }

.player-wrap {
  position: relative;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  line-height: normal;
  isolation: isolate;
}
.player-wrap video {
  display: block;
  width: 100%;
  max-height: 78vh;
  background: #000;
  object-fit: contain;
}
.player-wrap.is-enhanced {
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.player-wrap:fullscreen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  border-radius: 0;
}
.player-wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  border-radius: 0;
}
.player-wrap.is-pseudo-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
}
/* A forgiving selector list keeps the standard rule in browsers without the WebKit alias. */
.player-wrap:is(:fullscreen, :-webkit-full-screen, .is-pseudo-fullscreen) video {
  height: 100%;
  max-height: none;
}
body.player-fullscreen-lock { overflow: hidden; }

.player-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.3rem;
  pointer-events: none;
}
.player-wrap:not(.is-enhanced) .player-ui { display: none; }
.player-wrap.is-native-fullscreen .player-ui { visibility: hidden; }
.player-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
.icon {
  display: inline;
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.player-wrap .icon-pause,
.player-wrap .icon-volume-muted,
.player-wrap .icon-fullscreen-exit { display: none; }
.player-wrap.is-playing .icon-play { display: none; }
.player-wrap.is-playing .icon-pause { display: inline; }
.player-wrap.is-muted .icon-volume-on { display: none; }
.player-wrap.is-muted .icon-volume-muted { display: inline; }
.player-wrap.is-fullscreen .icon-fullscreen-enter { display: none; }
.player-wrap.is-fullscreen .icon-fullscreen-exit { display: inline; }

.gesture-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.seek-zone {
  height: 100%;
  cursor: pointer;
}
.seek-zone.left,
.seek-zone.right { width: 35%; }
.seek-zone.center { flex: 1; }

.subtitle-overlay {
  flex: none;
  container-type: inline-size;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
  pointer-events: none;
  text-align: center;
}
.player-wrap.controls-hidden .subtitle-overlay {
  /* Leave the controls in place for keyboard focus, but no longer stack above them. */
  position: absolute;
  inset-inline: 0;
  bottom: calc(clamp(6px, 4%, 16px) + env(safe-area-inset-bottom));
}
.sub-line {
  max-width: 86%;
  padding: 0.06em 0.35em;
  font-size: calc(14px * var(--sub-scale));
  font-weight: 650;
  line-height: 1.28;
  white-space: pre-line;
  text-shadow: 0 1px 2px #000, 0 0 6px rgba(0, 0, 0, 0.9);
  overflow-wrap: anywhere;
}
@supports (font-size: 1cqi) {
  .sub-line { font-size: calc(clamp(12px, 3.5cqi, 32px) * var(--sub-scale)); }
}
.sub-line:empty { display: none; }
.sub-line.en { color: var(--sub-en); }
.sub-line.vi { color: var(--sub-vi); }

.seek-flash {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 5.5rem;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) scale(0.95);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.seek-flash.left { left: 7%; }
.seek-flash.right { right: 7%; }
.seek-flash.show {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}
.seek-flash strong { font-size: 1.05rem; }
.seek-flash span { font-size: 0.75rem; color: #ccc; }

.player-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: player-spin 0.8s linear infinite;
  pointer-events: none;
}
@keyframes player-spin {
  to { transform: rotate(360deg); }
}

.rotate-hint {
  position: absolute;
  top: calc(0.8rem + env(safe-area-inset-top));
  left: 50%;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.82rem;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}
.rotate-icon {
  width: 0.95rem;
  height: 1.15rem;
  border: 2px solid currentColor;
  border-radius: 3px;
  transform: rotate(90deg);
}

.player-toast {
  position: absolute;
  left: 50%;
  bottom: calc(6.2rem + env(safe-area-inset-bottom));
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: calc(100% - 2rem);
  padding: 0.5rem 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(18, 18, 18, 0.94);
  color: #fff;
  font-size: 0.82rem;
  line-height: 1.3;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  transform: translateX(-50%);
}
.player-toast button {
  border: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.player-toast .toast-action {
  color: #8ec5ff;
  font-weight: 600;
  white-space: nowrap;
}
.player-toast .toast-close {
  padding: 0 0.2rem;
  color: #bbb;
  font-size: 1.1rem;
  line-height: 1;
}

.sub-settings-backdrop { display: none; }

.sub-settings {
  position: absolute;
  right: 0.7rem;
  bottom: calc(5.9rem + env(safe-area-inset-bottom));
  z-index: 8;
  width: min(19rem, calc(100vw - 1.4rem));
  padding: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(20, 20, 20, 0.97);
  color: #fff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}
.sub-settings h3 {
  margin: 0 0 0.55rem;
  padding-right: 1.6rem;
  font-size: 0.9rem;
  font-weight: 650;
}
.sub-settings-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #bbb;
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.sub-settings-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.sub-settings-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}
.sub-settings label {
  display: block;
  margin-top: 0.5rem;
  color: #d6d6d6;
  font-size: 0.78rem;
}
.sub-settings select {
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.3rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  background: #2a2a2a;
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
}
.sub-size-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.sub-size-row label {
  flex: 0 0 auto;
  margin-top: 0;
}
.sub-size-row input {
  flex: 1;
  accent-color: #fff;
}
.sub-size-row output {
  min-width: 2.8rem;
  color: #cfcfcf;
  font-size: 0.75rem;
  text-align: right;
}
.sub-settings-note {
  margin: 0.7rem 0 0;
  color: #aaa;
  font-size: 0.72rem;
  line-height: 1.35;
}

.player-controls {
  --controls-fade-height: 1.7rem;
  position: relative;
  flex: none;
  z-index: 5;
  padding: 0 0.7rem calc(0.55rem + env(safe-area-inset-bottom));
  color: #fff;
  pointer-events: auto;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.player-controls::before {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--controls-fade-height)) 0 0;
  z-index: -1;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.55) 60%, transparent);
  pointer-events: none;
}
.player-wrap.controls-hidden .player-controls {
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
}
.player-wrap.controls-hidden:fullscreen,
.player-wrap.controls-hidden.is-pseudo-fullscreen { cursor: none; }

.seek {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 20px;
  margin: 0 0 0.1rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background:
    linear-gradient(
      to right,
      #fff 0 var(--played, 0%),
      rgba(255, 255, 255, 0.35) var(--played, 0%) var(--buffered, 0%),
      rgba(255, 255, 255, 0.16) var(--buffered, 0%) 100%
    )
    center / 100% 4px no-repeat;
  cursor: pointer;
}
.seek::-webkit-slider-runnable-track { background: transparent; }
.seek::-moz-range-track { background: transparent; }
.seek::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #fff;
}
.seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #fff;
}
.seek:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.controls-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}
.player-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.25rem;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}
.player-btn:hover { background: rgba(255, 255, 255, 0.14); }
.player-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.player-btn .icon {
  width: 20px;
  height: 20px;
}
.play-btn { min-width: 2.2rem; }
.skip-btn {
  font-size: 0.7rem;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.volume-group {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.volume-slider {
  width: 4.5rem;
  accent-color: #fff;
}
.time {
  margin: 0 0.15rem;
  color: #e8e8e8;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.time-sep {
  padding: 0 0.25rem;
  color: #aaa;
}
.spacer {
  flex: 1;
  min-width: 0.2rem;
}
.speed-control select {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: inherit;
  font-size: 0.72rem;
  padding: 0.2rem 0.3rem;
  cursor: pointer;
}
.speed-control option {
  color: #111;
  background: #fff;
}
.cc-btn {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.cc-btn.is-active { background: rgba(255, 255, 255, 0.2); }

.playback-error {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  margin: 0;
  padding: 0.8rem 1rem;
  background: rgba(43, 27, 27, 0.96);
  color: #ffd8d8;
  font-size: 0.9rem;
  line-height: 1.4;
}
.playback-error a { color: #ffb3b3; }

.sub-downloads {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.8rem;
  font-size: 0.9rem;
}
.button {
  display: inline-block;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  line-height: 1.2;
}
.button:hover { border-color: var(--accent); text-decoration: none; }
.button.small { padding: 0.2rem 0.45rem; font-size: 0.8rem; }
.muted { color: var(--muted); }

@media (max-width: 700px) {
  .site-header-inner, .wrap { padding-inline: 0.9rem; }
  .wrap { padding-block: 0.9rem; }
  .listing, .crumbs { display: none; }
  .folder-back {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    width: fit-content;
    min-height: 44px;
    padding: 0.55rem 0;
    font-size: 0.88rem;
    overflow-wrap: anywhere;
  }
  .listing-heading { font-size: 1.5rem; line-height: 1.2; }
  .listing-mobile {
    display: block;
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }
  .listing-mobile li + li { border-top: 1px solid var(--line); }
  .listing-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 48px;
    padding: 0.55rem 0.75rem;
    color: var(--text);
  }
  .listing-row:hover, .listing-row:active {
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    text-decoration: none;
  }
  .listing-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .listing-row .thumb { flex: none; width: 96px; height: 54px; }
  .listing-row .fileicon { flex: none; width: 1.5rem; font-size: 1.1rem; }
  .listing-row-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
  .listing-row-name { display: block; font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
  .listing-row-subs { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.75rem; }
  .listing-chevron {
    flex: none;
    width: 0.45rem;
    height: 0.45rem;
    margin-right: 0.2rem;
    border: solid var(--muted);
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(-45deg);
  }
  .sub-line { max-width: 89%; }
  .player-controls {
    --controls-fade-height: 1.2rem;
    padding: 0 0.45rem calc(0.45rem + env(safe-area-inset-bottom));
  }
  .player-btn { min-width: 1.8rem; height: 2rem; }
  .skip-btn, .volume-slider { display: none; }
  .time { margin: 0 0.1rem; font-size: 0.72rem; }
  .speed-control select { font-size: 0.68rem; }
  .sub-settings {
    position: fixed;
    left: 0.5rem;
    right: 0.5rem;
    bottom: calc(5.5rem + env(safe-area-inset-bottom));
    width: auto;
    max-height: calc(100vh - 7rem - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 7rem - env(safe-area-inset-bottom));
    overflow-y: auto;
    z-index: 20;
  }
  .sub-settings-backdrop:not([hidden]) {
    position: fixed;
    inset: 0;
    display: block;
    z-index: 19;
    background: rgba(0, 0, 0, 0.4);
    pointer-events: auto;
  }
  .seek-flash {
    min-width: 4.6rem;
    padding: 0.55rem 0.8rem;
  }
}

@media (max-width: 420px) {
  .time-sep, #time-duration { display: none; }
}

@supports (-webkit-touch-callout: none) {
  .volume-slider { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .player-controls,
  .seek-flash { transition: none; }
  .player-spinner { animation-duration: 1.6s; }
}
