/* ==========================================================================
   Trailer player chrome (variant "H"): js/features/player_chrome.js
   The YouTube iframe is taller than the 16:9 screen; YouTube letterboxes the picture and draws
   its title bar and end-screen bits on the black margins, which .screen (overflow:hidden) clips.
   ========================================================================== */

.screen.pc-on {
  --pc-e: 140px;            /* crop margin above and below the picture */
  --pc-fg: rgb(255 255 255);
  --pc-dim: rgb(255 255 255 / 0.72);
  --pc-glass: rgb(18 19 24 / 0.94);
  --pc-bezel-bg: rgb(0 0 0 / 0.6);          /* youtube.com's frosted bezel */
  --pc-bezel-ease: cubic-bezier(0.05, 0, 0, 1); /* youtube.com's motion curve */
}

.screen.pc-on:fullscreen {
  --pc-e: 260px;
}

/* ---- Crop ----
   The iframe is 2 x --pc-e taller than the screen, and YouTube contain-fits the picture inside it. A
   16:9 picture then fills the visible screen exactly. A narrower picture (a native 4:3 upload) would
   instead grow to the iframe's full width and overflow the screen above and below, so the iframe is
   narrowed to the picture's own shape: width = min(screen width, screen height x --pc-ar), centered.
   The picture lands inside the screen with black bars left and right (pillarbox) and nothing cut off.
   --pc-ar (width / height) is set per video by player_chrome.js from js/video_aspect.js. */
.screen.pc-on .player-host {
  position: absolute;
  inset: 0;
  overflow: hidden;
  container-type: size;
  background: rgb(0 0 0);
}

.screen.pc-on .player-host iframe {
  --pc-w: min(100cqw, 100cqh * var(--pc-ar, 1.7778));
  position: absolute;
  left: calc((100cqw - var(--pc-w)) / 2);
  top: calc(-1 * var(--pc-e));
  width: var(--pc-w);
  height: calc(100cqh + 2 * var(--pc-e));
  max-width: none;
  border: 0;
}

/* Sharper picture: render the player at 2x and scale it down, so YouTube streams a higher
   resolution. Everything YouTube draws (including its center icon) is half size too. */
.screen.pc-on.pc-hq .player-host iframe {
  width: calc(2 * var(--pc-w));
  height: calc(200cqh + 4 * var(--pc-e));
  transform: scale(0.5);
  transform-origin: 0 0;
}

/* Shield: while a trailer plays, the page (not YouTube) receives the pointer. While it is still
   loading, taps reach YouTube, so a blocked autoplay can be started on its own play button. */
.screen.pc-on.pc-active .player-host iframe {
  pointer-events: none;
}

.screen.pc-active {
  cursor: pointer;
}

.screen.pc-active:not(.pc-show):not(.pc-paused):not(.pc-menu-open) {
  cursor: none;
}

/* Ended: hide YouTube's end screen; the stage art and its Replay button show instead. */
.screen.pc-active.pc-ended .screen__player {
  visibility: hidden;
}

.screen.pc-on.pc-active.pc-ended .screen__overlay {
  display: grid;
}

/* ---- Center icon (js bezel()): a copy of youtube.com's play/pause bezel ----
   78 px frosted circle with a 54 px icon (64 / 36 px when the player is 528 px wide or less).
   One 1 s run per press: fade in while growing to 1.33x, hold, fade out while shrinking back. */
.pc-bezel {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  margin: -39px 0 0 -39px;
  border-radius: 50%;
  background: var(--pc-bezel-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  color: var(--pc-fg);
  opacity: 0;
  pointer-events: none;
}

.pc-bezel svg {
  display: none;
  width: 54px;
  height: 54px;
}

.pc-bezel[data-g="play"] .pc-bezel__play,
.pc-bezel[data-g="pause"] .pc-bezel__pause {
  display: block;
}

.screen.pc-narrow .pc-bezel {
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
}

.screen.pc-narrow .pc-bezel svg {
  width: 36px;
  height: 36px;
}

.pc-bezel.is-on {
  animation: pc-bezel 1s var(--pc-bezel-ease) forwards;
}

.screen.pc-ended .pc-bezel {
  display: none;
}

@keyframes pc-bezel {
  0% { opacity: 0; transform: scale(1); }
  25%, 75% { opacity: 1; transform: scale(1.33); }
  100% { opacity: 0; transform: scale(1); }
}

@keyframes pc-bezel-still {
  0% { opacity: 0; }
  25%, 75% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- Control bar ---- */
.pc {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 40px var(--space-2) var(--space-1);
  background: linear-gradient(to top, rgb(0 0 0 / 0.78), rgb(0 0 0 / 0.35) 60%, rgb(0 0 0 / 0));
  color: var(--pc-fg);
  font-family: var(--font-sans);
  opacity: 0;
  transform: translateY(6px);
  visibility: hidden;
  pointer-events: none;
  cursor: default;
  transition: opacity var(--dur-hover) var(--ease), transform var(--dur-hover) var(--ease), visibility 0s linear var(--dur-hover);
}

.screen.pc-active.pc-show .pc,
.screen.pc-active.pc-paused .pc,
.screen.pc-active.pc-drag .pc,
.screen.pc-active.pc-menu-open .pc {
  opacity: 1;
  transform: none;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--dur-hover) var(--ease), transform var(--dur-hover) var(--ease), visibility 0s;
}

.screen.pc-ended .pc {
  display: none;
}

.pc-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.pc-spacer {
  flex: 1;
}

.pc-btn {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--pc-fg);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.pc-btn[hidden] {
  display: none;
}

@media (hover: hover) {
  .pc-btn:hover {
    background: rgb(255 255 255 / 0.12);
  }
}

.pc-btn svg {
  width: 22px;
  height: 22px;
}

.pc-cc svg {
  width: 24px;
  height: 24px;
}

.pc-cc[aria-pressed='true']::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 3px;
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
}

.pc-cc.is-none {
  opacity: 0.45;
}

.pc-btn:focus-visible,
.pc-seek:focus-visible,
.pc-yt:focus-visible,
.pc-menu button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.pc-time {
  padding: 0 var(--space-2);
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pc-sep {
  color: var(--pc-dim);
}

/* ---- Timeline: 3 px (5 px on hover). Played part amber, buffered part faint white, rest fainter.
   The dot is always there whenever the bar is. ---- */
.pc-seek {
  --p: 0%;
  --b: 0%;
  --pc-track: linear-gradient(to right,
    var(--accent) var(--p),
    rgb(255 255 255 / 0.4) var(--p),
    rgb(255 255 255 / 0.4) max(var(--p), var(--b)),
    rgb(255 255 255 / 0.2) max(var(--p), var(--b)));
  display: block;
  width: 100%;
  height: 20px;
  margin: 0 0 2px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.pc-seek::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: var(--pc-track);
  transition: height var(--dur-hover) var(--ease);
}

.pc-seek::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--pc-track);
}

.pc-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4.5px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  transition: transform var(--dur-hover) var(--ease);
}

.pc-seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

.pc-seek:hover::-webkit-slider-runnable-track,
.screen.pc-drag .pc-seek::-webkit-slider-runnable-track {
  height: 5px;
}

.pc-seek:hover::-webkit-slider-thumb,
.screen.pc-drag .pc-seek::-webkit-slider-thumb {
  margin-top: -3.5px;
  transform: scale(1.2);
}

/* ---- YouTube logo, top-right corner of the picture ---- */
.pc-yt {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 5;
  display: block;
  line-height: 0;
  color: var(--pc-fg);
  opacity: 0;
  visibility: hidden;
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.55)) drop-shadow(0 0 8px rgb(0 0 0 / 0.35));
  transition: opacity var(--dur-hover) var(--ease), visibility 0s linear var(--dur-hover);
}

.pc-yt svg {
  width: 68px;
  height: 16px;
}

.screen.pc-lg .pc-yt {
  top: 16px;
  right: 18px;
}

.screen.pc-lg .pc-yt svg {
  width: 80px;
  height: 19px;
}

.screen.pc-active.pc-show .pc-yt,
.screen.pc-active.pc-paused .pc-yt,
.screen.pc-active.pc-drag .pc-yt,
.screen.pc-active.pc-menu-open .pc-yt {
  opacity: 0.95;
  visibility: visible;
  transition: opacity var(--dur-hover) var(--ease), visibility 0s;
}

.screen.pc-ended .pc-yt {
  display: none;
}

/* ---- Settings menu ---- */
.pc-menu {
  position: absolute;
  right: var(--space-2);
  bottom: 56px;
  z-index: 6;
  min-width: 220px;
  max-width: calc(100% - 2 * var(--space-2));
  max-height: calc(100% - 68px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border-radius: var(--radius-lg);
  background: var(--pc-glass);
  box-shadow: var(--shadow-popover);
  color: var(--text-1);
  font-family: var(--font-sans);
  cursor: default;
}

.pc-menu[hidden] {
  display: none;
}

.pc-menu.pc-menu--sheet {
  position: static;
  max-width: none;
  max-height: none;
  min-width: 0;
  padding: 0;
  background: none;
  box-shadow: none;
}

.pc-menu__h {
  margin: var(--space-2) 10px 6px;
  color: var(--text-2);
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  line-height: 1;
}

.pc-menu__opts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: 0 6px 6px;
}

.pc-opt {
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-1);
  font-size: var(--fs-14);
  font-weight: var(--fw-medium);
  line-height: 1.2;
  cursor: pointer;
}

@media (hover: hover) {
  .pc-opt:hover {
    background: rgb(255 255 255 / 0.08);
  }
}

.pc-opt[aria-checked='true'] {
  background: var(--accent-soft);
  color: var(--accent);
}

.pc-menu__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 2px 10px 6px;
  font-size: var(--fs-14);
}

.pc-menu__row--hq {
  margin-top: var(--space-1);
  padding-top: 10px;
  padding-bottom: var(--space-2);
  border-top: 1px solid var(--hairline);
}

.pc-menu__lbl {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pc-menu__lbl small {
  color: var(--text-2);
  font-size: var(--fs-12);
  line-height: var(--lh-12);
}

.pc-menu__note {
  max-width: 300px;
  padding: 2px 10px var(--space-2);
  color: var(--text-2);
  font-size: var(--fs-12);
  line-height: var(--lh-12);
}

.pc-menu--sheet .pc-menu__note {
  max-width: none;
}

.pc-switch {
  --sw-w: 34px;
  --sw-h: 20px;
  --sw-k: 14px;
  position: relative;
  flex: none;
  width: 38px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  cursor: pointer;
}

.pc-switch::before,
.pc-switch::after {
  content: '';
  position: absolute;
  top: 50%;
  border-radius: var(--radius-full);
}

.pc-switch::before {
  left: 50%;
  width: var(--sw-w);
  height: var(--sw-h);
  transform: translate(-50%, -50%);
  background: rgb(255 255 255 / 0.24);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.08);
  transition: background-color var(--dur-hover) var(--ease);
}

.pc-switch::after {
  left: calc(50% - var(--sw-w) / 2 + 3px);
  width: var(--sw-k);
  height: var(--sw-k);
  margin-top: calc(var(--sw-k) / -2);
  background: var(--pc-fg);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  transition: transform var(--dur-hover) var(--ease);
}

.pc-switch[aria-checked='true']::before {
  background: var(--accent);
}

.pc-switch[aria-checked='true']::after {
  transform: translateX(calc(var(--sw-w) - var(--sw-k) - 6px));
}

/* ---- Fullscreen: roomier bar ---- */
.screen.pc-on:fullscreen .pc {
  padding: 60px var(--space-6) var(--space-3);
}

.screen.pc-on:fullscreen .pc-yt {
  top: 24px;
  right: 28px;
}

/* ---- Touch: bigger targets, the bar stays up longer (set in JS) ---- */
html.touch .pc-btn {
  width: 40px;
  height: 40px;
}

html.touch .pc-seek {
  height: 24px;
}

html.touch .pc-opt {
  min-height: 40px;
  padding: 10px 14px;
}

html.touch .pc-switch {
  --sw-w: 44px;
  --sw-h: 26px;
  --sw-k: 20px;
  width: 52px;
  height: 44px;
}

/* In the bottom sheet, option rows read as even segmented rows. */
.pc-menu--sheet .pc-menu__opts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
}

.pc-menu--sheet .pc-opt {
  padding-left: var(--space-1);
  padding-right: var(--space-1);
  text-align: center;
}

.pc-menu--sheet .pc-menu__h {
  margin-top: var(--space-3);
}

@media (max-width: 899px), (max-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  .pc {
    padding: 28px var(--space-1) 2px;
  }

  .pc-yt {
    top: 10px;
    right: 12px;
  }

  .pc-yt svg {
    width: 60px;
    height: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pc,
  .pc-yt,
  .pc-seek::-webkit-slider-thumb,
  .pc-seek::-webkit-slider-runnable-track,
  .pc-switch::after {
    transition: none;
  }

  .pc {
    transform: none;
  }

  .pc-bezel.is-on {
    animation-name: pc-bezel-still;
  }
}
