:root {
  --bg: #0e1014;
  --bg-elev: #16191f;
  --bg-elev2: #1e222a;
  --line: #272c35;
  --line-soft: #20242c;
  --text: #eef1f6;
  --muted: #949cab;
  --accent: #5fd68f;          /* slightly desaturated from #4ade80 */
  --accent-strong: #6fe09a;
  --accent-ink: #06240f;
  --danger: #f0787a;
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 44px;
  --shadow: 0 10px 30px -12px rgba(4, 20, 10, 0.55), 0 2px 8px -4px rgba(0, 0, 0, 0.5);
  --shadow-lift: 0 18px 44px -14px rgba(5, 30, 16, 0.62), 0 4px 12px -4px rgba(0, 0, 0, 0.55);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --maxw: 1200px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

/* Subtle grain so dark surfaces don't read as flat vector. */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

.hidden { display: none !important; }

/* ---------- Top bar ---------- */
#library { position: relative; z-index: 1; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(14, 16, 20, 0.82);
  backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-inner { display: contents; }
.topbar h1 {
  font-size: 20px; margin: 0; font-weight: 600;
  letter-spacing: -0.02em;
}
.topbar .spacer { flex: 1; }
.iconbtn {
  min-width: var(--tap); min-height: var(--tap);
  display: grid; place-items: center;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; font-size: 18px; color: var(--text);
  transition: background 0.2s var(--ease), transform 0.15s var(--ease), border-color 0.2s var(--ease);
}
.iconbtn:hover { background: var(--bg-elev2); border-color: var(--line); }
.iconbtn:active { transform: scale(0.94); }

/* ---------- Search + chips ---------- */
.controls { padding: 14px 16px 4px; max-width: var(--maxw); margin-inline: auto; }
.search {
  width: 100%; height: var(--tap);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 14px; font-size: 16px;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.search::placeholder { color: var(--muted); }
.search:hover { border-color: #303643; }
.chips {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 12px 16px; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; max-width: var(--maxw); margin-inline: auto;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 9px 15px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--line);
  color: var(--muted); font-size: 14px; white-space: nowrap;
  transition: background 0.2s var(--ease), color 0.2s var(--ease),
              border-color 0.2s var(--ease), transform 0.12s var(--ease);
}
.chip:hover { color: var(--text); border-color: #333a45; }
.chip:active { transform: scale(0.96); }
.chip.active {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600;
  box-shadow: 0 6px 18px -8px var(--accent);
}

/* ---------- Grid ---------- */
.grid {
  display: grid; gap: 16px; padding: 10px 16px calc(36px + var(--safe-b));
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  max-width: var(--maxw); margin-inline: auto;
}
.card {
  background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--radius); overflow: hidden; text-align: left;
  padding: 0; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
  animation: cardIn 0.44s var(--ease) both;
}
@media (hover: hover) {
  .card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); border-color: var(--line); }
  .card:hover .thumb { transform: scale(1.04); }
}
.card:active { transform: translateY(-1px) scale(0.99); }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } html { scroll-behavior: auto; } }

.thumb-wrap { position: relative; overflow: hidden; }
.thumb {
  position: relative; aspect-ratio: 9 / 12; background: var(--bg-elev2);
  width: 100%; object-fit: cover; display: block;
  transition: transform 0.35s var(--ease);
}
.badge {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0,0,0,0.66); backdrop-filter: blur(6px);
  color: #fff; font-size: 12px; font-weight: 500;
  padding: 3px 8px; border-radius: 8px; font-variant-numeric: tabular-nums;
}
.card-title {
  padding: 11px 13px 14px; font-size: 14px; line-height: 1.32;
  letter-spacing: -0.01em; text-wrap: pretty;
}
.empty { padding: 72px 20px; text-align: center; color: var(--muted); grid-column: 1 / -1; }
.empty .big { font-size: 40px; opacity: 0.5; margin-bottom: 8px; }

/* Skeleton loaders while the catalog loads */
.skel {
  border-radius: var(--radius); overflow: hidden; background: var(--bg-elev);
  border: 1px solid var(--line-soft);
}
.skel .thumb-wrap { aspect-ratio: 9 / 12; }
.skel-bar, .skel .thumb-wrap {
  background: linear-gradient(100deg, var(--bg-elev2) 20%, #262b34 40%, var(--bg-elev2) 60%);
  background-size: 220% 100%; animation: shimmer 1.3s var(--ease) infinite;
}
.skel-bar { height: 12px; border-radius: 6px; margin: 12px 13px; }
.skel-bar.short { width: 55%; }
@keyframes shimmer { from { background-position: 180% 0; } to { background-position: -40% 0; } }

/* ---------- Player ---------- */
.player-view {
  position: fixed; inset: 0; z-index: 40; background: #000;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; /* dvh: excludes mobile browser chrome */
}
.player-stage {
  position: relative; flex: 1 1 auto; min-height: 42vh; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  background: #000; overflow: hidden;
}
/* Keep the video's true aspect ratio, centered, never stretched —
   works for both portrait (9:16) and landscape (16:9) clips. */
.player-stage video {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  object-fit: contain; background: #000; display: block;
}

.player-topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
  z-index: 3; pointer-events: none;                 /* taps fall through to video */
}
.player-topbar .iconbtn, .player-topbar .player-title { pointer-events: auto; }
.player-title { font-size: 15px; font-weight: 600; flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

/* Immersive (fullscreen) mode — video fills the screen, controls hidden.
   Works on every platform incl. iOS where div requestFullscreen is unsupported. */
#exitFsBtn { display: none; }
.player-view.immersive { flex-direction: column; }
.player-view.immersive .controls-bar { display: none; }
.player-view.immersive .player-stage { min-height: 100dvh; }
.player-view.immersive #exitFsBtn { display: grid; }

/* Tap indicator that flashes on play/pause */
.tap-hint {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.8);
  width: 84px; height: 84px; border-radius: 50%;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
  display: grid; place-items: center; font-size: 34px; color: #fff;
  z-index: 2; opacity: 0; pointer-events: none;
}
.tap-hint.flash { animation: tapFlash 0.5s var(--ease); }
@keyframes tapFlash {
  0% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.7); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); }
}

/* Floating speed pill — only visible in immersive/fullscreen */
.fs-speed {
  position: absolute; left: 50%; bottom: calc(20px + var(--safe-b));
  transform: translateX(-50%);
  display: none; align-items: center; gap: 12px; z-index: 4; pointer-events: auto;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px; padding: 8px 10px;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.6);
}
.player-view.immersive .fs-speed { display: flex; }
.fs-speed button {
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, 0.16); color: #fff; font-size: 24px; line-height: 1;
  display: grid; place-items: center;
  transition: background 0.18s var(--ease), transform 0.12s var(--ease);
}
.fs-speed button:hover { background: rgba(255, 255, 255, 0.26); }
.fs-speed button:active { transform: scale(0.9); }
.fs-speed span {
  min-width: 72px; text-align: center; font-weight: 700; font-size: 17px;
  font-variant-numeric: tabular-nums; color: #fff; letter-spacing: -0.01em;
}

.controls-bar {
  background: var(--bg-elev); border-top: 1px solid var(--line);
  padding: 12px 14px calc(12px + var(--safe-b));
  display: flex; flex-direction: column; gap: 12px;
  flex: 0 0 auto; max-height: 55vh; overflow-y: auto;
}

/* progress */
.scrub-row { display: flex; align-items: center; gap: 10px; }
.time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 40px; }
.time.right { text-align: right; }
.scrub {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 999px; background: var(--bg-elev2);
}
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: none; margin-top: -0.5px;
}
.scrub::-moz-range-thumb { width: 18px; height: 18px; border: none; border-radius: 50%; background: var(--accent); }

/* transport */
.transport { display: flex; align-items: center; justify-content: center; gap: 18px; }
.transport button {
  min-width: var(--tap); min-height: var(--tap); border-radius: 12px;
  background: transparent; border: none; font-size: 22px; color: var(--text);
  display: grid; place-items: center;
  transition: transform 0.14s var(--ease), background 0.2s var(--ease);
}
.transport button:hover { background: var(--bg-elev2); }
.transport button:active { transform: scale(0.92); }
.transport .play {
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 26px;
  box-shadow: 0 10px 26px -8px var(--accent);
}
.transport .play:hover { background: var(--accent-strong); }

/* speed — the headline control */
.speed-block { display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-elev2); border-radius: 12px; padding: 12px; }
.speed-head { display: flex; align-items: baseline; justify-content: space-between; }
.speed-head .label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.speed-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.speed-slider { -webkit-appearance: none; appearance: none; width: 100%;
  height: 8px; border-radius: 999px; background: var(--bg-elev); }
.speed-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px;
  border-radius: 50%; background: var(--accent); border: 3px solid var(--bg-elev2); }
.speed-slider::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg-elev2); }
.speed-chips { display: flex; gap: 8px; }
.speed-chips button {
  flex: 1; min-height: 40px; border-radius: 10px; font-size: 14px; font-weight: 600;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
  transition: background 0.18s var(--ease), color 0.18s var(--ease),
              border-color 0.18s var(--ease), transform 0.12s var(--ease);
}
.speed-chips button:hover { border-color: #333a45; }
.speed-chips button:active { transform: scale(0.96); }
.speed-chips button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* toggles row */
.toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle {
  flex: 1 1 0; min-width: 68px; min-height: 44px; padding: 0 6px;
  border-radius: 10px; font-size: 13px; white-space: nowrap;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: background 0.18s var(--ease), color 0.18s var(--ease),
              border-color 0.18s var(--ease), transform 0.12s var(--ease);
}
.toggle:hover { color: var(--text); border-color: #333a45; }
.toggle:active { transform: scale(0.96); }
.toggle.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* ---------- Login ---------- */
.center-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.card-panel {
  width: 100%; max-width: 360px; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: 18px; padding: 26px;
}
.card-panel h1 { margin: 0 0 4px; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.card-panel p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.field { width: 100%; height: var(--tap); background: var(--bg-elev2);
  border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; font-size: 16px;
  transition: border-color 0.2s var(--ease); }
.field:focus { outline: none; border-color: var(--accent); }
.btn-primary {
  width: 100%; height: var(--tap); margin-top: 12px; border: none;
  border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-size: 16px; font-weight: 700;
  box-shadow: 0 10px 26px -10px var(--accent);
  transition: background 0.18s var(--ease), transform 0.12s var(--ease);
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; box-shadow: none; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- Admin ---------- */
.admin-wrap { max-width: 900px; margin: 0 auto; padding: 16px; }
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 30px 20px; text-align: center; color: var(--muted);
  background: var(--bg-elev);
}
.dropzone.drag { border-color: var(--accent); color: var(--text); background: var(--bg-elev2); }
.upload-row, .manage-row {
  display: flex; gap: 12px; align-items: center; padding: 12px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; margin-top: 10px;
}
.upload-row img, .manage-row img { width: 54px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--bg-elev2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.row-main input, .row-main select {
  height: 38px; background: var(--bg-elev2); border: 1px solid var(--line);
  border-radius: 10px; padding: 0 10px; font-size: 15px; width: 100%;
}
.row-status { font-size: 12px; color: var(--muted); min-width: 92px; text-align: right; }
.row-status.live { color: var(--accent); }
.row-status.err { color: var(--danger); }
.progress { height: 6px; background: var(--bg-elev2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.section-title { margin: 26px 0 6px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.btn-sm { height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-elev2); color: var(--text); font-size: 14px;
  transition: background 0.18s var(--ease), transform 0.12s var(--ease), border-color 0.18s var(--ease); }
.btn-sm:hover { border-color: #333a45; }
.btn-sm:active { transform: scale(0.96); }
.btn-sm:disabled { opacity: 0.5; }
.btn-danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); color: var(--danger); background: transparent; }
.btn-danger:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.admin-wrap { position: relative; z-index: 1; }
.section-title { font-weight: 600; }

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .player-view { flex-direction: row; }
  .player-stage { flex: 1; }
  .controls-bar { width: 360px; flex: 0 0 360px; max-height: none; border-top: none; border-left: 1px solid var(--line); overflow-y: auto; }
}
