/* =========================================================
   Clean — Apple-inspired design system
   Dark first · content-first · calm · confident
   ========================================================= */

:root {
  /* Neutral dark base — true near-black with cool-neutral surfaces */
  --bg:        #000000;
  --surface-1: #16171a;   /* raised card */
  --surface-2: #1e2024;   /* controls */
  --surface-3: #26282d;   /* hover / segmented track */

  /* Text — layered like iOS labels */
  --label:            #f5f5f7;
  --label-secondary:  rgba(235, 235, 245, 0.62);
  --label-tertiary:   rgba(235, 235, 245, 0.38);

  /* Restrained accent — soft system-blue */
  --accent:      #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.16);

  /* Hairlines & separators */
  --separator:  rgba(255, 255, 255, 0.08);
  --hairline:   rgba(255, 255, 255, 0.12);

  /* Translucent chrome material */
  --chrome:     rgba(22, 22, 24, 0.72);

  --radius-card:  12px;
  --radius-ctrl:  12px;
  --radius-pill:  980px;

  --shadow-card:  0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.35);
  --shadow-float: 0 12px 40px rgba(0,0,0,0.55);

  --max: 1240px;

  --ease-std: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--label);
}

body {
  font-family: system-ui, -apple-system, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  letter-spacing: 0;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
img, video { max-width: 100%; display: block; }

::selection { background: var(--accent-soft); }

/* =========================================================
   Topbar — translucent material with scroll edge
   ========================================================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: var(--safe-t);
  background: var(--chrome);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  transition: transform 0.32s var(--ease-out);
  will-change: transform;
}
/* Headroom: slides fully out of view (incl. safe area) */
.topbar.hidden { transform: translateY(calc(-100% - var(--safe-t))); }

.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 10px max(16px, var(--safe-l)) 8px max(16px, var(--safe-r));
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  transition: opacity 0.1s var(--ease-out), transform 0.1s var(--ease-out);
}
.brand:active { opacity: 0.6; transform: scale(0.96); }
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(160deg, #ffffff 0%, #c7c7cc 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 3px;
  background: #0a0a0b;
}
.brand-name {
  font-size: 1.06rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--label);
}

/* Search — iOS rounded field */
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 0 6px 0 12px;
  min-width: 0;
  height: 38px;
  transition: background 0.18s var(--ease-out), box-shadow 0.18s var(--ease-out);
}
.search:focus-within {
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-icon {
  width: 17px;
  height: 17px;
  color: var(--label-tertiary);
  flex: 0 0 auto;
}
.search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 8px 0;
  min-width: 0;
  font-size: 0.95rem;
}
.search input::placeholder { color: var(--label-tertiary); }
.search input::-webkit-search-cancel-button { display: none; }

.search-clear {
  border: 0;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  color: var(--label-tertiary);
  display: inline-flex;
  align-items: center;
  border-radius: 50%;
  transition: transform 0.1s var(--ease-out), color 0.15s var(--ease-out);
}
.search-clear svg { width: 18px; height: 18px; }
.search-clear:active { transform: scale(0.85); color: var(--label-secondary); }

/* Category strip — segmented pills, edge-faded */
.cats {
  max-width: var(--max);
  margin: 0 auto;
  padding: 2px max(12px, var(--safe-l)) 10px max(12px, var(--safe-r));
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
}
.cats::-webkit-scrollbar { display: none; }

.cat {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--label-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: transform 0.1s var(--ease-out), background 0.18s var(--ease-out),
    color 0.18s var(--ease-out);
}
.cat:active { transform: scale(0.94); }
.cat.active {
  color: #fff;
  background: var(--accent);
  font-weight: 600;
}

/* Scroll edge — soft gradient instead of hard border */
.scroll-edge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -18px;
  height: 18px;
  pointer-events: none;
  background: linear-gradient(rgba(0,0,0,0.28), transparent);
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
}
.topbar.scrolled .scroll-edge { opacity: 1; }

/* =========================================================
   Main
   ========================================================= */

.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px max(16px, var(--safe-l))
           calc(40px + var(--safe-b)) max(16px, var(--safe-r));
}

/* =========================================================
   States — spinner / empty / error
   ========================================================= */

.state {
  min-height: 46vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--label-secondary);
}
.state .state-title { font-size: 1.02rem; font-weight: 600; color: var(--label); }
.state .state-sub { font-size: 0.9rem; color: var(--label-tertiary); max-width: 30ch; }
.state.error .state-title { color: #ff6b6b; }

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--surface-3);
  border-top-color: var(--label-secondary);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   Grid + Cards — cover-forward, soft depth
   ========================================================= */

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
}
@media (min-width: 1040px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.card {
  position: relative;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
  transition: transform 0.12s var(--ease-out);
  will-change: transform;
}
.card:active { transform: scale(0.97); }

.card-cover {
  aspect-ratio: 3 / 4;
  background: #0a0a0b center/cover no-repeat;
  position: relative;
}
/* vibrancy scrim so overlaid title stays legible */
.card-cover::after {
  content: "";
  position: absolute;
  inset: 40% 0 0 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.82));
}

.card-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 12px 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 1;
}
.card-title {
  font-size: 0.9rem;
  line-height: 1.28;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #fff;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.card-meta {
  color: rgba(255,255,255,0.7);
  font-size: 0.75rem;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* =========================================================
   Pager
   ========================================================= */

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 28px 0 6px;
}
.pager button {
  background: var(--surface-2);
  border: 0;
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--label);
  transition: transform 0.1s var(--ease-out), background 0.18s var(--ease-out);
}
.pager button:not(:disabled):active { transform: scale(0.95); background: var(--surface-3); }
.pager button:disabled { cursor: default; }
.pager button.pager-page {
  background: transparent;
  color: var(--label-tertiary);
  font-variant-numeric: tabular-nums;
}
.pager button.pager-nav:disabled { opacity: 0.32; }

/* =========================================================
   Detail page
   ========================================================= */

.back {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--accent);
  margin-bottom: 16px;
  font-size: 1rem;
  font-weight: 500;
  transition: opacity 0.1s var(--ease-out), transform 0.1s var(--ease-out);
}
.back svg { width: 20px; height: 20px; }
.back:active { opacity: 0.55; transform: scale(0.96); }

.detail {
  max-width: 820px;
  margin: 0 auto;
}

.detail-head { margin-bottom: 20px; }
.detail-head h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
  font-weight: 700;
}
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--label-tertiary);
  font-size: 0.85rem;
}
.meta-row .date { font-variant-numeric: tabular-nums; margin-right: 2px; }

.chip {
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--label-secondary);
  transition: transform 0.1s var(--ease-out), color 0.15s var(--ease-out);
}
.chip:active { transform: scale(0.93); color: var(--accent); }
.chip a { display: block; }

.players {
  display: grid;
  gap: 16px;
  margin: 4px 0 24px;
}
.player-card {
  background: #000;
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.player-card .ptitle {
  padding: 10px 14px;
  color: var(--label-secondary);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---- Custom video player ---- */
.player-shell {
  position: relative;
  width: 100%;
  background: #000;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
/* free height when user resizes / theater */
.player-shell.sized,
.player-shell.theater {
  aspect-ratio: auto;
  height: var(--pl-h, min(78vh, 720px));
  max-height: 92vh;
}
.player-shell video {
  width: 100%;
  height: 100%;
  max-height: none;
  background: #000;
  object-fit: contain;
  display: block;
}
.player-shell.resizing {
  cursor: ns-resize;
}
.player-shell.resizing * {
  cursor: ns-resize !important;
}

/* bottom resize handle */
.pl-resize {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 14px;
  z-index: 7;
  cursor: ns-resize;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(transparent, rgba(0,0,0,0.25));
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
}
.player-shell.show-controls .pl-resize,
.player-shell.resizing .pl-resize,
.pl-resize:focus-visible {
  opacity: 1;
}
.pl-resize::after {
  content: "";
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.55);
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.pl-resize:hover::after,
.pl-resize:focus-visible::after {
  background: #fff;
}
.pl-resize:focus-visible {
  outline: none;
}
.pl-resize:focus-visible::after {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* theater / website fill mode */
body.theater-mode {
  overflow: hidden;
}
body.theater-mode .topbar {
  transform: translateY(calc(-100% - var(--safe-t)));
  pointer-events: none;
}
body.theater-mode .main {
  max-width: none;
  padding: 0;
  margin: 0;
  height: 100dvh;
}
/* Post detail page */
body.theater-mode .detail {
  max-width: none;
  margin: 0;
  padding: 0;
}
body.theater-mode .detail-head,
body.theater-mode .content,
body.theater-mode .tags,
body.theater-mode .back,
body.theater-mode .meta-row {
  display: none !important;
}
body.theater-mode .players {
  margin: 0;
  gap: 0;
}
/* Watch page — hide chrome, let player fill */
body.theater-mode .watch-page {
  padding: 0;
  height: 100dvh;
  overflow: hidden;
}
body.theater-mode .watch-chrome,
body.theater-mode .watch-meta,
body.theater-mode .watch-err {
  display: none !important;
}
body.theater-mode .watch-stage {
  max-width: none;
  gap: 0;
  width: 100%;
  height: 100%;
}
/* Shared player-card behavior in theater */
body.theater-mode .player-card,
body.theater-mode .watch-player-card {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #000;
  width: 100%;
  height: 100%;
}
body.theater-mode .player-card .ptitle {
  display: none;
}
body.theater-mode .player-parts {
  order: 2;
  justify-content: center;
  padding: 10px max(14px, var(--safe-l)) max(12px, var(--safe-b)) max(14px, var(--safe-r));
  background: rgba(0,0,0,0.88);
}
body.theater-mode .player-shell,
body.theater-mode .watch-player-shell {
  order: 1;
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  overflow: visible;
}
body.theater-mode .player-shell video,
body.theater-mode .watch-player-shell video {
  max-height: none;
  object-fit: contain;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* system fullscreen on card or document */
.player-card:fullscreen,
.player-card:-webkit-full-screen,
:fullscreen body,
:-webkit-full-screen body {
  background: #000;
}
.player-card:fullscreen,
.player-card:-webkit-full-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 0;
  background: #000;
}
.player-card:fullscreen .ptitle,
.player-card:fullscreen .player-parts,
.player-card:-webkit-full-screen .ptitle,
.player-card:-webkit-full-screen .player-parts { display: none; }
.player-card:fullscreen .player-shell,
.player-card:-webkit-full-screen .player-shell {
  aspect-ratio: auto;
  height: 100%;
  max-height: none;
}
.player-card:fullscreen .player-shell video,
.player-card:-webkit-full-screen .player-shell video { max-height: 100%; }
.player-card:fullscreen .pl-bar,
.player-card:-webkit-full-screen .pl-bar,
html:fullscreen .pl-bar,
html:-webkit-full-screen .pl-bar {
  padding-left: max(14px, var(--safe-l));
  padding-right: max(14px, var(--safe-r));
  padding-bottom: max(12px, var(--safe-b));
}
/* when document is fullscreen, force theater-like fill */
html:fullscreen body.theater-mode .player-shell,
html:-webkit-full-screen body.theater-mode .player-shell {
  height: var(--pl-h, 100dvh);
}

/* tap layer + center play */
.pl-tap { position: absolute; inset: 0; cursor: pointer; }
.pl-center {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.pl-big {
  pointer-events: auto;
  width: 72px; height: 72px;
  border: 0; border-radius: 50%;
  background: rgba(28, 28, 30, 0.55);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: opacity 0.28s var(--ease-out), transform 0.12s var(--ease-out);
}
.pl-big svg { width: 34px; height: 34px; margin-left: 2px; }
.pl-big:active { transform: scale(0.9); }
/* center button only while paused */
.player-shell:not(.paused) .pl-center { opacity: 0; }
.player-shell.paused .pl-big { opacity: 1; }

/* spinner overlay */
.pl-spinner {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.pl-spinner .spinner { border-top-color: #fff; border-color: rgba(255,255,255,0.25); border-top-color: #fff; }

/* error / spinner / toast: honor hidden attribute over display:flex */
.pl-error[hidden],
.pl-spinner[hidden],
.pl-toast[hidden],
.pl-tip[hidden],
.pl-rate-menu[hidden] {
  display: none !important;
}

/* error overlay */
.pl-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: rgba(0,0,0,0.6);
  color: #fff; z-index: 5;
}
.pl-error-title { font-size: 0.95rem; font-weight: 600; color: rgba(255,255,255,0.85); }
.pl-retry {
  border: 0; border-radius: var(--radius-pill);
  background: var(--accent); color: #fff;
  font-size: 0.9rem; font-weight: 600;
  padding: 8px 18px; cursor: pointer;
  transition: transform 0.1s var(--ease-out);
}
.pl-retry:active { transform: scale(0.94); }

/* toast */
.pl-toast {
  position: absolute; top: 14px; left: 50%;
  transform: translate(-50%, -8px);
  background: rgba(28,28,30,0.7);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  color: #fff; font-size: 0.82rem; font-weight: 600;
  padding: 6px 14px; border-radius: var(--radius-pill);
  opacity: 0; pointer-events: none; z-index: 6;
  transition: opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out);
}
.pl-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* bottom control bar — translucent material */
.pl-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.35));
  z-index: 4;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.28s var(--ease-out), transform 0.28s var(--ease-out);
}
.pl-bar::before {
  content: "";
  position: absolute; inset: 0;
  background: rgba(22,22,24,0.5);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  -webkit-mask-image: linear-gradient(transparent, #000 40%);
          mask-image: linear-gradient(transparent, #000 40%);
  z-index: -1;
}
.player-shell.show-controls .pl-bar { opacity: 1; transform: translateY(0); }
.player-shell:not(.show-controls) { cursor: none; }

.pl-icon {
  border: 0; background: transparent;
  color: #fff; cursor: pointer;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; flex: 0 0 auto;
  transition: transform 0.1s var(--ease-out), opacity 0.15s var(--ease-out);
}
.pl-icon svg { width: 22px; height: 22px; }
.pl-icon:active { transform: scale(0.86); }
.pl-icon:hover { opacity: 0.82; }
.pl-rate { font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; width: auto; min-width: 40px; padding: 0 8px; }

/* volume cluster */
.pl-vol {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  max-width: 140px;
}
.pl-vol-rail {
  width: 0;
  opacity: 0;
  overflow: hidden;
  height: 28px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
  transition: width 0.2s var(--ease-out), opacity 0.2s var(--ease-out);
}
.pl-vol:hover .pl-vol-rail,
.pl-vol:focus-within .pl-vol-rail,
.pl-vol-rail:active,
.player-shell.show-controls .pl-vol-rail:focus {
  width: 72px;
  opacity: 1;
}
/* always show a usable rail on touch / coarse pointers */
@media (hover: none), (pointer: coarse) {
  .pl-vol-rail { width: 64px; opacity: 1; }
}
.pl-vol-track {
  position: relative;
  width: 100%;
  height: 4px;
  border-radius: 3px;
  background: rgba(255,255,255,0.28);
}
.pl-vol-fill {
  position: absolute; inset: 0 auto 0 0;
  height: 100%; width: 100%;
  border-radius: 3px;
  background: #fff;
}
.pl-vol-knob {
  position: absolute; top: 50%; left: 100%;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* rate panel — free continuous control */
.pl-rate-wrap {
  position: relative;
  flex: 0 0 auto;
}
.pl-rate-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(260px, 78vw);
  padding: 12px;
  border-radius: 14px;
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 8;
}
.pl-rate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.pl-rate-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.02em;
}
.pl-rate-value-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pl-rate-step {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s var(--ease-out), background 0.15s var(--ease-out);
}
.pl-rate-step:hover { background: rgba(255,255,255,0.14); }
.pl-rate-step:active { transform: scale(0.9); }
.pl-rate-input {
  width: 52px;
  height: 28px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}
.pl-rate-input::-webkit-outer-spin-button,
.pl-rate-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.pl-rate-input:focus {
  border-color: rgba(10, 132, 255, 0.65);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.pl-rate-unit {
  color: rgba(255,255,255,0.55);
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 12px;
}
.pl-rate-slider-row { padding: 0 2px; }
.pl-rate-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.22);
  outline: none;
  cursor: pointer;
}
.pl-rate-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
  border: 0;
  cursor: grab;
}
.pl-rate-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
  cursor: grab;
}
.pl-rate-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
}
.pl-rate-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pl-rate-opt {
  border: 0;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s var(--ease-out), background 0.15s var(--ease-out), color 0.15s var(--ease-out);
}
.pl-rate-opt:hover { background: rgba(255,255,255,0.14); color: #fff; }
.pl-rate-opt.active {
  background: var(--accent);
  color: #fff;
}
.pl-rate-opt:active { transform: scale(0.95); }

.pl-time {
  color: #fff; font-size: 0.78rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto; min-width: 40px; text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* scrubber */
.pl-scrub {
  position: relative; flex: 1; min-width: 0;
  height: 28px; display: flex; align-items: center;
  cursor: pointer; touch-action: none;
}
.pl-track {
  position: relative; width: 100%; height: 4px;
  border-radius: 3px; background: rgba(255,255,255,0.28);
  transition: height 0.15s var(--ease-out);
}
.pl-scrub:hover .pl-track,
.pl-scrub.active .pl-track { height: 6px; }
.pl-buffered {
  position: absolute; inset: 0 auto 0 0; height: 100%;
  border-radius: 3px; background: rgba(255,255,255,0.4); width: 0;
}
.pl-played {
  position: absolute; inset: 0 auto 0 0; height: 100%;
  border-radius: 3px; background: var(--accent); width: 0;
}
.pl-knob {
  position: absolute; top: 50%; left: 0;
  width: 13px; height: 13px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.15s var(--ease-out);
}
.pl-scrub:hover .pl-knob,
.pl-scrub.active .pl-knob { transform: translate(-50%, -50%) scale(1); }
.pl-scrub.active .pl-knob { transform: translate(-50%, -50%) scale(1.15); }
.pl-scrub:focus-visible { outline: none; }
.pl-scrub:focus-visible .pl-track { box-shadow: 0 0 0 3px var(--accent-soft); }
.pl-tip {
  position: absolute; bottom: 22px; left: 0;
  transform: translateX(-50%);
  background: rgba(28,28,30,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff; font-size: 0.72rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 3px 7px; border-radius: 6px;
  pointer-events: none; white-space: nowrap;
}

/* episode / parts strip */
.player-parts {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 14px 4px;
}
.player-parts .pl-part {
  border: 0; cursor: pointer;
  min-width: 40px; height: 34px; padding: 0 12px;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--label-secondary);
  font-size: 0.85rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: transform 0.1s var(--ease-out), background 0.18s var(--ease-out), color 0.18s var(--ease-out);
}
.player-parts .pl-part:active { transform: scale(0.92); }
.player-parts .pl-part.active { background: var(--accent); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .pl-bar, .pl-big, .pl-toast, .pl-resize {
    transition: opacity 0.2s ease !important;
    transform: none !important;
  }
  .player-shell.show-controls .pl-bar { transform: none; }
  .pl-knob { transition: none; }
  .pl-icon:active, .pl-big:active, .pl-retry:active, .player-parts .pl-part:active { transform: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .pl-bar::before { background: rgba(10,10,11,0.92); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .pl-big { background: rgba(28,28,30,0.9); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .pl-toast { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(20,20,22,0.95); }
  .pl-rate-menu { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(20,20,22,0.96); }
}

.content {
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--label);
}
.content img {
  margin: 16px auto;
  border-radius: 10px;
  max-height: 90vh;
  object-fit: contain;
  box-shadow: var(--shadow-card);
}
.content p { margin: 0 0 16px; color: rgba(235,235,245,0.85); }
.content h2, .content h3 {
  margin: 26px 0 12px;
  letter-spacing: -0.01em;
  font-weight: 700;
  line-height: 1.2;
}
.content a { color: var(--accent); }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--separator);
}
.tag {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--label-secondary);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  background: var(--surface-2);
}

/* =========================================================
   Enter animations — transform + opacity only
   ========================================================= */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.enter { animation: rise 0.5s var(--ease-out) both; }
.enter-fade { animation: fade 0.4s var(--ease-out) both; }

/* Staggered card reveal (first two rows only, keeps it snappy) */
.grid.enter > .card { animation: rise 0.5s var(--ease-out) both; }
.grid.enter > .card:nth-child(1) { animation-delay: 0.02s; }
.grid.enter > .card:nth-child(2) { animation-delay: 0.05s; }
.grid.enter > .card:nth-child(3) { animation-delay: 0.08s; }
.grid.enter > .card:nth-child(4) { animation-delay: 0.11s; }
.grid.enter > .card:nth-child(5) { animation-delay: 0.14s; }
.grid.enter > .card:nth-child(6) { animation-delay: 0.16s; }
.grid.enter > .card:nth-child(7) { animation-delay: 0.18s; }
.grid.enter > .card:nth-child(8) { animation-delay: 0.20s; }
.grid.enter > .card:nth-child(n+9) { animation-delay: 0.22s; }

/* =========================================================
   Accessibility preferences
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .enter, .enter-fade, .grid.enter > .card { animation: fade 0.25s ease both; }
  .card:active, .cat:active, .pager button:active,
  .chip:active, .back:active, .brand:active { transform: none; }
  .spinner { animation: spin 0.7s linear infinite !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar { background: #0f0f10; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .search:focus-within { box-shadow: none; }
}

@media (prefers-contrast: more) {
  :root {
    --surface-1: #1c1d21;
    --surface-2: #26272c;
    --label-secondary: rgba(235,235,245,0.85);
    --label-tertiary: rgba(235,235,245,0.6);
    --separator: rgba(255,255,255,0.2);
  }
  .topbar { background: #0d0d0e; border-bottom: 1px solid var(--hairline); }
  .card { box-shadow: 0 0 0 1px var(--hairline), var(--shadow-card); }
  .cat { box-shadow: inset 0 0 0 1px var(--hairline); }
}

/* =========================================================
   Media library
   ========================================================= */

.media-page { max-width: var(--max); margin: 0 auto; padding: 8px 0 40px; }
.media-head {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  justify-content: space-between;
  padding: 8px max(16px, var(--safe-l)) 12px max(16px, var(--safe-r));
}
.media-title { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.media-sub { margin: 4px 0 0; color: var(--label-secondary); font-size: 0.86rem; }
.media-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.media-tab {
  display: inline-flex; align-items: center;
  padding: 7px 12px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--label-secondary);
  font-size: 0.86rem; border: 1px solid transparent;
}
.media-tab.active {
  background: var(--accent-soft); color: var(--label);
  border-color: rgba(10,132,255,0.35);
}
.media-toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 0 max(16px, var(--safe-l)) 14px max(16px, var(--safe-r));
}
.media-search { display: flex; gap: 8px; flex: 1; min-width: 220px; }
.media-search input {
  flex: 1; min-width: 0; height: 38px; border: 0; outline: 0;
  border-radius: var(--radius-pill); padding: 0 14px;
  background: var(--surface-2);
}
.media-search button {
  border: 0; border-radius: var(--radius-pill); padding: 0 14px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.media-count { color: var(--label-tertiary); font-size: 0.82rem; }
.media-grid .media-card {
  text-align: left; border: 0; padding: 0; cursor: pointer;
  background: var(--surface-1); width: 100%;
  border-radius: var(--radius-card); overflow: hidden;
  box-shadow: var(--shadow-card);
}
.media-badge {
  position: absolute; left: 8px; top: 8px;
  background: rgba(0,0,0,0.62); color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px; padding: 3px 8px; font-size: 11px;
}
.card-cover { position: relative; }
.card-cover.is-video { aspect-ratio: 16 / 10; }
.path-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem; word-break: break-all;
  color: var(--label-tertiary);
}
/* ---- Cards — press response on pointer-down ---- */
.media-grid .media-card {
  display: block;
  text-align: left;
  color: inherit;
  text-decoration: none;
  transition:
    transform 0.18s var(--ease-out),
    box-shadow 0.2s var(--ease-out),
    opacity 0.15s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  will-change: transform;
}
.media-grid .media-card:active,
.media-grid .media-card.is-pressing {
  transform: scale(0.97);
  opacity: 0.92;
}
.media-card .card-cover {
  aspect-ratio: 3 / 4;
  background: var(--surface-2);
  overflow: hidden;
  position: relative;
}
.media-card .card-cover.is-video { aspect-ratio: 16 / 10; }
.media-play-affordance {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: transform 0.18s var(--ease-out), opacity 0.18s var(--ease-out);
}
.media-play-affordance svg {
  width: 22px;
  height: 22px;
  margin-left: 2px; /* optical center for play triangle */
}
.media-grid .media-card:active .media-play-affordance,
.media-grid .media-card.is-pressing .media-play-affordance {
  transform: scale(0.92);
  opacity: 0.9;
}
.media-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
  transition: transform 0.45s var(--ease-out);
}
.media-grid .media-card:active .media-thumb,
.media-grid .media-card.is-pressing .media-thumb {
  transform: scale(1.03);
}
.media-ph {
  width: 100%;
  height: 100%;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--label-tertiary);
  font-size: 0.85rem;
  background: linear-gradient(180deg, var(--surface-2), var(--surface-1));
}

/* ---- Dedicated watch / view page ---- */
html.watch-mode .topbar.compact {
  /* Soft hide library chrome while watching — content first */
  transform: translateY(calc(-100% - var(--safe-t)));
  pointer-events: none;
}
html.watch-mode .main {
  min-height: 100dvh;
}

.watch-page {
  min-height: 100dvh;
  background: #000;
  color: var(--label);
  padding:
    max(10px, var(--safe-t))
    max(12px, var(--safe-r))
    max(20px, var(--safe-b))
    max(12px, var(--safe-l));
}
.watch-stage {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.watch-chrome {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
.watch-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  height: 36px;
  padding: 0 12px 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform 0.1s var(--ease-out), background 0.15s var(--ease-out), opacity 0.15s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.watch-back:hover { background: rgba(255, 255, 255, 0.16); }
.watch-back:active { transform: scale(0.96); opacity: 0.88; }
.watch-title-wrap {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.watch-title {
  margin: 0;
  font-size: clamp(1rem, 2.6vw, 1.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.watch-sub {
  color: var(--label-tertiary);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.watch-player-card {
  margin: 0;
  background: transparent;
  box-shadow: none;
  border: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.watch-player-shell {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: min(42dvh, 280px);
  max-height: min(78dvh, 820px);
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  background: #0a0a0a;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 20px 50px rgba(0, 0, 0, 0.55);
}
.watch-player-shell video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
/* On phones, prefer taller stage */
@media (max-width: 640px) {
  .watch-player-shell {
    aspect-ratio: 16 / 10;
    border-radius: 14px;
    max-height: min(70dvh, 640px);
  }
  .watch-back span { display: none; }
  .watch-back { width: 36px; padding: 0; justify-content: center; }
}

/* System fullscreen: hide watch chrome, fill viewport */
.watch-page:fullscreen,
.watch-page:-webkit-full-screen {
  padding: 0;
  background: #000;
}
.watch-page:fullscreen .watch-chrome,
.watch-page:fullscreen .watch-meta,
.watch-page:fullscreen .watch-err,
.watch-page:-webkit-full-screen .watch-chrome,
.watch-page:-webkit-full-screen .watch-meta,
.watch-page:-webkit-full-screen .watch-err {
  display: none;
}
.watch-page:fullscreen .watch-stage,
.watch-page:-webkit-full-screen .watch-stage {
  max-width: none;
  gap: 0;
  width: 100%;
  height: 100dvh;
}
.watch-page:fullscreen .watch-player-card,
.watch-page:-webkit-full-screen .watch-player-card {
  width: 100%;
  height: 100%;
}
.watch-page:fullscreen .watch-player-shell,
.watch-page:-webkit-full-screen .watch-player-shell {
  width: 100%;
  height: 100%;
  max-height: none;
  min-height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}
.watch-page:fullscreen .watch-player-shell video,
.watch-page:-webkit-full-screen .watch-player-shell video {
  object-fit: contain;
}
.watch-page:fullscreen .pl-bar,
.watch-page:-webkit-full-screen .pl-bar {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.watch-image-stage {
  background: #0a0a0a;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 20px 50px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(50dvh, 420px);
}
.watch-image-stage .media-preview-img {
  width: 100%;
  max-height: min(82dvh, 900px);
  object-fit: contain;
  display: block;
  background: #000;
}

.watch-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px 0;
  color: var(--label-secondary);
  font-size: 0.82rem;
}
.media-meta-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  min-width: 0;
}
.media-meta-k {
  flex: 0 0 auto;
  color: var(--label-tertiary);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  min-width: 2.5em;
}
.watch-meta code,
.media-meta-row code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--label-secondary);
}
.watch-meta a { color: var(--accent); }
.watch-err {
  color: #ff6b7a;
  font-size: 0.86rem;
  padding: 8px 2px;
}

@media (prefers-reduced-motion: reduce) {
  .media-grid .media-card,
  .media-thumb,
  .media-play-affordance,
  .watch-back {
    transition-duration: 0.01ms !important;
  }
  .media-grid .media-card:active,
  .media-grid .media-card.is-pressing {
    transform: none;
  }
}
@media (prefers-reduced-transparency: reduce) {
  .media-play-affordance {
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .watch-back { background: #2c2c2e; }
}
