:root {
  --bg: #0f0f0f;
  --bg-elev: #181818;
  --bg-elev2: #212121;
  --bg-hover: #2a2a2a;
  --border: #303030;
  --text: #f1f1f1;
  --text-dim: #aaaaaa;
  --text-faint: #717171;
  --accent: #ff4d4d;
  --accent-hover: #ff6b6b;
  --yt: #ff0000;
  --tt: #00f2ea;
  --ig: #e1306c;
  --fb: #1877f2;
  --radius: 12px;
  --topbar-h: 56px;
  --sidebar-w: 240px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #3d6dff55; border-color: #3d6dff; }
label { display: block; margin-bottom: 12px; color: var(--text-dim); font-size: 13px; }
label input, label select, label textarea { margin-top: 5px; color: var(--text); }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* Topbar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--border);
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 13px;
}
.brand-name span { color: var(--accent); }
.search-wrap { flex: 1; max-width: 640px; margin: 0 auto; }
.search-wrap input { border-radius: 999px; padding: 9px 18px; background: #121212; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: transparent; border: none; border-radius: 50%;
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; color: var(--text);
}
@media (hover: hover) { .icon-btn:hover { background: var(--bg-hover); } }
.icon-btn:focus { outline: none; }
.icon-btn:focus-visible { outline: 2px solid #4b8dff; outline-offset: 2px; }
.menu-btn { display: none; }
.menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 44px; min-width: 230px;
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); overflow: hidden; z-index: 60;
}
.dropdown button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 11px 14px; color: var(--text);
}
.dropdown button:hover { background: var(--bg-hover); }

/* Buttons */
.btn {
  background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 8px 16px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-danger { color: #ff8080; border-color: #5a2a2a; }
.btn-danger:hover { background: #3a1f1f; }

/* Layout */
.layout { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  overflow-y: auto; padding: 12px 10px; border-right: 1px solid var(--border); background: var(--bg);
}
.side-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.side-link {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: none; border-radius: 10px; padding: 9px 12px;
  color: var(--text); text-align: left;
}
.side-link:hover { background: var(--bg-hover); }
.side-link.active { background: var(--bg-elev2); font-weight: 600; }
.side-ico { width: 20px; text-align: center; }
.side-section { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
.side-heading { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 0 12px 8px; }
.count { margin-left: auto; color: var(--text-faint); font-size: 12px; }
.plat-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.plat-dot.yt { background: var(--yt); }
.plat-dot.tt { background: var(--tt); }
.plat-dot.ig { background: var(--ig); }
.plat-dot.fb { background: var(--fb); }
.collection-list { display: flex; flex-direction: column; gap: 2px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 8px; }
.tag-pill {
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; color: var(--text-dim);
}
.tag-pill:hover, .tag-pill.active { background: var(--bg-hover); color: var(--text); }
.side-footer { margin-top: 18px; padding: 12px; font-size: 11px; color: var(--text-faint); }
.main { flex: 1; margin-left: var(--sidebar-w); padding: 18px 24px 60px; min-width: 0; }

/* Banner / toolbar */
.demo-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #1d2733; border: 1px solid #2c405a; color: #cfe3ff;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
}
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 14px; color: var(--text);
}
.chip:hover { background: var(--bg-hover); }
.chip.active { background: #f1f1f1; color: #0f0f0f; border-color: #f1f1f1; font-weight: 600; }
.toolbar-right { display: flex; align-items: center; gap: 12px; }
.result-count { color: var(--text-dim); font-size: 13px; }
.toolbar-right select { width: auto; padding: 6px 10px; }
.active-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: #263344; border: 1px solid #34506e; color: #cfe3ff;
  border-radius: 999px; padding: 4px 12px; font-size: 12px;
}
.filter-tag button { background: none; border: none; color: inherit; padding: 0; font-size: 13px; }

/* Grid / cards */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 20px 16px;
}
.card { cursor: pointer; border-radius: var(--radius); }
.card:focus-visible { outline: 2px solid #3d6dff; outline-offset: 3px; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: var(--bg-elev2);
}
.thumb img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .18s ease; }
.card:hover .thumb img { transform: scale(1.03); }
.thumb-placeholder {
  position: absolute; inset: 0; z-index: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: #fff; font-weight: 700; font-size: 15px; text-align: center; padding: 12px;
}
.thumb-placeholder .big { font-size: 34px; }
.ph-youtube { background: linear-gradient(135deg, #4a0d0d, #1a1a1a); }
.ph-tiktok { background: linear-gradient(135deg, #0b3b3a, #2a0b2e); }
.ph-instagram { background: linear-gradient(135deg, #5b1f4b, #7a3b1f); }
.ph-facebook { background: linear-gradient(135deg, #12305e, #1a1a1a); }
.play-overlay {
  position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.25); opacity: 0; transition: opacity .15s ease;
}
.card:hover .play-overlay { opacity: 1; }
.play-overlay span {
  width: 52px; height: 52px; border-radius: 50%; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff;
}
.badge {
  position: absolute; z-index: 2; top: 8px; left: 8px; padding: 3px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .02em;
}
.badge.youtube { background: var(--yt); }
.badge.tiktok { background: #111; border: 1px solid var(--tt); color: var(--tt); }
.badge.instagram { background: var(--ig); }
.badge.facebook { background: var(--fb); }
.type-badge {
  position: absolute; z-index: 2; bottom: 8px; right: 8px; background: rgba(0,0,0,.75);
  padding: 2px 7px; border-radius: 5px; font-size: 11px; color: #fff; text-transform: uppercase;
}
.demo-badge { position: absolute; z-index: 2; top: 8px; right: 8px; background: rgba(0,0,0,.7); color: #ffd479; font-size: 10px; padding: 2px 7px; border-radius: 5px; }
.card-body { padding: 10px 4px 0; }
.card-title {
  font-size: 15px; font-weight: 600; line-height: 1.35; margin: 0 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-author { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }
.card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mini-tag { background: var(--bg-elev2); border-radius: 5px; padding: 1px 7px; font-size: 11px; color: var(--text-dim); }
.card-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.card:hover .card-actions { opacity: 1; }
.card-actions button { background: none; border: none; color: var(--text-dim); font-size: 14px; padding: 2px 5px; border-radius: 5px; }
.card-actions button:hover { color: var(--text); background: var(--bg-hover); }
.card-actions .fav-on { color: #ffd479; }
.watched-mark { color: #7bd88f; font-size: 12px; }

/* Empty */
.empty { text-align: center; padding: 80px 20px; color: var(--text-dim); }
.empty-ico { font-size: 52px; margin-bottom: 12px; }
.empty h2 { color: var(--text); margin: 0 0 8px; }
.empty .btn { margin-top: 16px; }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab { background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 16px; }
.tab.active { background: #f1f1f1; color: #0f0f0f; font-weight: 600; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detected { margin: -6px 0 12px; font-size: 13px; color: var(--text-dim); min-height: 18px; }
.detected .ok { color: #7bd88f; }
.detected .bad { color: #ff8080; }
.bulk-result { margin-top: 14px; font-size: 13px; color: var(--text-dim); white-space: pre-wrap; }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; }
.check-label { display: flex; align-items: center; gap: 8px; padding-top: 24px; }
.check-label input { width: auto; margin: 0; }

/* Player */
.player-shell {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 1100px; max-height: 94vh; display: flex; flex-direction: column; overflow: hidden;
}
.player-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 18px; }
.player-title { font-size: 17px; font-weight: 600; }
.player-sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.player-nav { display: flex; gap: 4px; flex-shrink: 0; }
.player-stage {
  background: #000; display: flex; align-items: center; justify-content: center;
  min-height: 240px; overflow: hidden;
}
.player-stage iframe { border: 0; display: block; }
.stage-video { width: 100%; aspect-ratio: 16 / 9; max-height: 72vh; }
.stage-video iframe { width: 100%; height: 100%; }
.stage-vertical { height: min(74vh, 720px); aspect-ratio: 9 / 16; max-width: 100%; }
.stage-vertical iframe { width: 100%; height: 100%; }
.stage-fb { height: min(70vh, 600px); aspect-ratio: 16 / 9; max-width: 100%; }
.stage-fb-auto { max-width: 100%; }
.stage-fb-auto iframe { width: 100%; height: 100%; }
.stage-fb iframe { width: 100%; height: 100%; }
.stage-post { width: min(500px, 100%); height: min(72vh, 680px); }
.stage-post iframe { width: 100%; height: 100%; }
.player-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 18px; }
.embed-note { color: var(--text-faint); font-size: 12px; flex-basis: 100%; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #f1f1f1; color: #0f0f0f; padding: 11px 20px; border-radius: 10px;
  font-weight: 500; z-index: 200; box-shadow: 0 6px 24px rgba(0,0,0,.5); max-width: 90vw;
}

/* Responsive */
@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .sidebar { transform: translateX(-100%); transition: transform .18s ease; z-index: 45; box-shadow: 8px 0 28px rgba(0,0,0,.5); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 14px 14px 60px; }
  .brand-name { display: none; }
  .row-2 { grid-template-columns: 1fr; }
  .demo-banner { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .topbar { gap: 8px; padding: 0 10px; }
  #addBtn { padding: 8px 12px; }
  .player-actions { gap: 6px; padding: 10px 12px; }
  .player-actions .btn { flex: 0 1 auto; text-align: center; font-size: 12px; padding: 7px 10px; }
  .embed-note { font-size: 11px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .embed-note.expanded { -webkit-line-clamp: unset; }
  .upnext { padding: 8px 12px 10px; }
  .upnext-list { max-height: 62px; }
}

/* ================= v8: fullscreen, theatre, TV mode, up-next ================= */

/* --- theatre: fill the window, but never spill past it --- */
#playerModal.theatre { padding: 0; }
#playerModal.theatre .player-shell {
  max-width: 100%; width: 100%;
  height: 100vh; height: 100dvh; max-height: 100%;
  border-radius: 0; border: 0;
}

/* --- fullscreen: the VIDEO owns the screen, everything else becomes an overlay --- */
.player-shell:fullscreen,
.player-shell.pseudo-fs { background: #000; max-width: 100%; width: 100%; height: 100%; max-height: 100%; border-radius: 0; border: 0; }
.player-shell.pseudo-fs { position: fixed; inset: 0; z-index: 9999; }

/* the stage fills the whole shell and is sized independently of the overlays,
   so the video can never be squeezed or cropped by the furniture */
.player-shell:fullscreen .player-stage,
.player-shell.pseudo-fs .player-stage {
  position: absolute; inset: 0; width: 100%; height: 100%;
  flex: none; min-height: 0; max-height: none;
}
.player-shell:fullscreen .stage-video,
.player-shell.pseudo-fs .stage-video,
.player-shell:fullscreen .stage-vertical,
.player-shell.pseudo-fs .stage-vertical { height: 100%; max-height: none; }

/* no buttons, no explanation paragraph, no up-next thumbnails in fullscreen */
.player-shell:fullscreen .player-actions,
.player-shell.pseudo-fs .player-actions,
.player-shell:fullscreen .upnext-list,
.player-shell.pseudo-fs .upnext-list { display: none !important; }

/* the title bar and the autoplay bar float over the picture instead of taking space */
.player-shell:fullscreen .player-top,
.player-shell.pseudo-fs .player-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 4;
  justify-content: flex-end; padding: 10px 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,.82), rgba(0,0,0,0));
  transition: opacity .22s ease;
}
.player-shell:fullscreen .player-title-wrap,
.player-shell.pseudo-fs .player-title-wrap { display: none; }
.player-shell:fullscreen .upnext,
.player-shell.pseudo-fs .upnext {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 4;
  border-top: 0; padding: 10px 12px 14px;
  background: linear-gradient(to top, rgba(0,0,0,.82), rgba(0,0,0,0));
  transition: opacity .22s ease;
}
.player-shell:fullscreen .icon-btn,
.player-shell.pseudo-fs .icon-btn { color: #fff; background: rgba(0,0,0,.35); }

/* idle = controls faded away; a running countdown always stays reachable */
.player-shell.fs-idle:not(.counting) .player-top,
.player-shell.fs-idle:not(.counting) .upnext { opacity: 0; pointer-events: none; }
.player-shell.fs-idle { cursor: none; }
.player-shell.counting .upnext { opacity: 1 !important; pointer-events: auto !important; }

/* edge strips that catch a tap/hover to bring the controls back.
   They sit above the video but below the control bars. */
.fs-hit { display: none; }
.player-shell:fullscreen .fs-hit,
.player-shell.pseudo-fs .fs-hit { display: block; position: absolute; left: 0; right: 0; z-index: 2; }
/* kept thin so they do not sit on top of the platform's own player controls;
   tapping the video itself also reveals the bar (the window blurs to the iframe) */
.fs-hit-top { top: 0; height: 48px; }
.fs-hit-bottom { bottom: 0; height: 52px; }

/* swap the fullscreen glyph without touching the SVG in JS */
#fullscreenBtn .ico-exit { display: none; }
.player-shell:fullscreen #fullscreenBtn .ico-enter,
.player-shell.pseudo-fs #fullscreenBtn .ico-enter { display: none; }
.player-shell:fullscreen #fullscreenBtn .ico-exit,
.player-shell.pseudo-fs #fullscreenBtn .ico-exit { display: inline; }

/* --- progress bar on cards --- */
.thumb-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.28); z-index: 2; }
.thumb-progress i { display: block; height: 100%; background: var(--accent, #ff4d4d); }
.resume-badge {
  position: absolute; bottom: 10px; left: 8px; z-index: 2; font-size: 10px; font-weight: 800;
  background: rgba(0,0,0,.78); color: #fff; padding: 2px 7px; border-radius: 5px;
}

/* --- continue watching rail --- */
.continue { margin: 0 0 22px; }
.continue-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.continue-head h2 { font-size: 16px; margin: 0; }
.rail { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
.rail .card { flex: 0 0 220px; scroll-snap-align: start; }
.rail::-webkit-scrollbar { height: 8px; }
.rail::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 4px; }

/* --- up next --- */
.upnext { border-top: 1px solid var(--border); padding: 10px 18px 14px; }
.upnext-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 9px; }
.advance-label { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.advance-label select { padding: 4px 6px; font-size: 12px; }
.upnext-status { font-size: 12px; color: var(--text-faint); }
.countdown { font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.countdown strong { color: #4b8dff; font-variant-numeric: tabular-nums; }
.upnext-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.upnext-item {
  display: flex; gap: 9px; align-items: center; flex: 0 0 250px; text-align: left;
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 10px; padding: 7px; cursor: pointer;
}
.upnext-item:hover { border-color: #555; }
.upnext-item img { width: 68px; height: 42px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: #222; }
.upnext-item .un-t { font-size: 12px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.upnext-item .un-m { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.upnext-empty { font-size: 12px; color: var(--text-faint); }

/* --- TV / remote mode --- */
body.tv-mode { font-size: 18px; }
body.tv-mode .sidebar { display: none; }
body.tv-mode .main { margin-left: 0; padding: 18px 22px 70px; }
body.tv-mode .grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 22px; }
body.tv-mode .card-title { font-size: 19px; -webkit-line-clamp: 2; }
body.tv-mode .card-author { font-size: 15px; }
body.tv-mode .mini-tag { font-size: 12px; }
body.tv-mode .chip { font-size: 16px; padding: 10px 16px; }
body.tv-mode .btn { font-size: 16px; padding: 11px 16px; }
body.tv-mode .btn-small { font-size: 15px; }
body.tv-mode .rail .card { flex: 0 0 300px; }
body.tv-mode .card-actions { display: none; }
body.tv-mode #tvModeBtn { background: #4b8dff; color: #fff; border-radius: 8px; }
body.tv-mode .player-title { font-size: 22px; }
body.tv-mode .upnext-item { flex: 0 0 320px; }
body.tv-mode .upnext-item .un-t { font-size: 15px; }

/* unmistakable focus for a remote / keyboard */
.card:focus-visible, body.tv-mode .card:focus {
  outline: 4px solid #4b8dff; outline-offset: 3px; border-radius: var(--radius);
}
body.tv-mode .card:focus { transform: scale(1.03); transition: transform .12s ease; }
body.tv-mode .btn:focus-visible, body.tv-mode .chip:focus-visible,
body.tv-mode .upnext-item:focus-visible, body.tv-mode .icon-btn:focus-visible,
body.tv-mode select:focus-visible {
  outline: 4px solid #4b8dff; outline-offset: 2px;
}
.tv-hint {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(0,0,0,.85); border: 1px solid #3a3a3a; color: #ddd;
  font-size: 13px; padding: 7px 14px; border-radius: 999px; z-index: 55; display: none;
}
body.tv-mode .tv-hint { display: block; }

/* ================= v9: room for the picture, no spill, no crop ================= */

/* A long title must never steal the video's height. Two lines, then ellipsis. */
.player-title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.player-title-wrap { min-width: 0; }

/* A definite shell height means the stage height is the space left over and does
   NOT depend on the video box — that is what stops the measure/resize feedback
   loop which was cropping Facebook reels. 100% caps it to the visible area, so
   it can never hang off the top or bottom on a phone. */
.player-shell {
  height: 94vh;
  height: min(94dvh, 100%);
  max-height: 100%;
}
.player-stage { flex: 1 1 auto; min-height: 0; }
#stageBox { max-width: 100%; max-height: 100%; }
/* The shell is the containing block for the fullscreen overlays. */
.player-shell { position: relative; }
/* The chrome keeps its natural height and the stage absorbs all the slack.
   Without this the stage height would depend on the video box, which is what
   created the measure -> resize -> measure loop. */
.player-top, .player-actions, .upnext { flex-shrink: 0; }

/* very short viewports (phone in landscape): give the picture the room */
@media (max-height: 560px) {
  .upnext-list { display: none; }
  .embed-note { display: none; }
  .player-title { -webkit-line-clamp: 1; }
  .player-top { padding: 8px 12px; }
}

/* the explanation is tap-to-expand where it is clamped */
.embed-note { cursor: pointer; }
.embed-note.expanded { cursor: default; }

/* theatre keeps a slim title so you still know what you are watching */
#playerModal.theatre .player-title { -webkit-line-clamp: 1; }

/* on a phone in portrait there is no room for a wide theatre bar of buttons */
@media (max-width: 560px) {
  .player-top { padding: 10px 12px; gap: 8px; }
  .player-title { font-size: 15px; }
  .player-nav { gap: 2px; }
  .player-nav .icon-btn { width: 34px; height: 34px; }
}

/* ================= v10: Instagram crop + our own fullscreen chrome ================= */

/* In fullscreen our old title bar and up-next bar are replaced by fsBar, so they
   must not sit on top of Instagram's own header any more. */
.player-shell:fullscreen .player-top,
.player-shell.pseudo-fs .player-top,
.player-shell:fullscreen .upnext,
.player-shell.pseudo-fs .upnext { display: none !important; }

/* Always-visible exit, top-LEFT (Instagram puts "View profile" top-right). */
.fs-exit { display: none; }
.player-shell:fullscreen .fs-exit,
.player-shell.pseudo-fs .fs-exit {
  display: flex; align-items: center; justify-content: center;
  position: absolute; top: 10px; left: 10px; z-index: 7;
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(0,0,0,.78); color: #fff; border: 1px solid rgba(255,255,255,.28);
  font-size: 19px; cursor: pointer;
}
.player-shell:fullscreen .fs-exit:hover,
.player-shell.pseudo-fs .fs-exit:hover { background: rgba(0,0,0,.95); }

/* Bottom control bar — opaque enough to read over any video, wraps on a phone,
   and is inside the shell so it can never be cut off. */
.fs-bar { display: none; }
.player-shell:fullscreen .fs-bar,
.player-shell.pseudo-fs .fs-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0,0,0,.92) 55%, rgba(0,0,0,0));
  transition: opacity .22s ease;
}
.fs-btn {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.fs-btn:hover { background: rgba(255,255,255,.26); }
.fs-btn[aria-pressed="true"] { background: #4b8dff; border-color: #4b8dff; }
.fs-count { color: #fff; font-size: 13px; display: inline-flex; align-items: center; gap: 8px; }
.fs-count b { color: #7fb2ff; font-variant-numeric: tabular-nums; }
.player-shell.fs-idle:not(.counting) .fs-bar { opacity: 0; pointer-events: none; }
.player-shell.counting .fs-bar { opacity: 1 !important; pointer-events: auto !important; }

/* Adjust-picture panel */
.crop-adjust { display: none; }
.crop-adjust.open {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  position: absolute; left: 12px; right: 12px; bottom: 74px; z-index: 8;
  background: rgba(12,12,14,.96); border: 1px solid #3a3a42; border-radius: 12px; padding: 12px;
}
.ca-row { display: flex; align-items: center; gap: 6px; color: #ddd; font-size: 13px; }
.ca-hint { color: #8a8a94; font-size: 11px; flex-basis: 100%; }

/* --- the crop window --- */
/* One iframe, restyled rather than re-created, so entering fullscreen never
   restarts the video. */
.ig-window { position: relative; background: #000; }
.ig-window > iframe { border: 0; display: block; transform-origin: 0 0; }
.ig-window.cropping {
  position: absolute !important; inset: 0 !important;
  width: 100% !important; height: 100% !important; max-width: none !important;
  aspect-ratio: auto !important; overflow: hidden;
}
.ig-window.fullpost {
  position: absolute !important; inset: 0 !important;
  width: 100% !important; height: 100% !important; max-width: none !important;
  aspect-ratio: auto !important; overflow: auto; background: #fff;
}
.ig-window.fullpost > iframe { width: 100%; height: 100%; }

/* the edge strips must not swallow the new bar */
.player-shell:fullscreen .fs-hit-bottom,
.player-shell.pseudo-fs .fs-hit-bottom { height: 40px; }
