/* Video Player Component */

.cp-video-player:focus {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.cp-video-player {
  display: flex;
  flex-direction: column;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  max-width: var(--wide);
  margin-left: auto;
  margin-right: auto;
  box-shadow: var(--shadow);


  /* Video wrapper - contains video and overlays */
  & .video-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-top-right-radius: var(--radius);
    border-top-left-radius: var(--radius);
    overflow: hidden;
  }

  /* Video element */
  & .video {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  & .video:focus {
    outline: 2px dashed var(--text);
    outline-offset: -2px;
  }

  /* Hide native controls */
  & .video::-webkit-media-controls {
    display: none !important;
  }

  /* Disabled state */
  &.disabled .big-play-button,
  &.disabled .play-pause,
  &.disabled .thumb,
  &.disabled .cc,
  &.disabled .speaker,
  &.disabled .fullscreen {
    cursor: not-allowed;
  }

  /* Video heading overlay - always white on video content */
  & .video-heading {
    position: absolute;
    top: var(--md);
    left: var(--md);
    z-index: 2;
    color: var(--white);
    font-size: var(--h3);
    text-shadow:
      0 0 10px rgba(0, 0, 0, 0.9),
      0 0 20px rgba(0, 0, 0, 0.7),
      0 2px 4px rgba(0, 0, 0, 0.9);
    margin: 0;
    opacity: 1;
    transition: all var(--normal) ease;
    white-space: nowrap;
  }

  & .video-heading.hidden {
    opacity: 0;
    transform: translateY(-0.5rem);
  }

  @media (max-width: 480px) {
    & .video-heading {
      font-size: 1.1rem;
      top: var(--sm);
      left: 50%;
      transform: translateX(-50%);
    }

    & .video-heading.hidden {
      transform: translateX(-50%) translateY(-0.5rem);
    }
  }

  /* Big center play button */
  & .big-play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    width: 15%;
    min-width: 70px;
    max-width: 120px;
    aspect-ratio: 1;
    cursor: pointer;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--white);
    transition: transform var(--fast), opacity var(--fast);
  }

  & .big-play-button svg {
    width: 100%;
    height: 100%;
  }

  & .big-play-button:hover {
    outline: 0;
    transform: translate(-50%, -50%) scale(1.1);
  }

  & .big-play-button:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
    border-radius: 50%;
  }

  & .big-play-button.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(1.5);
  }

  @media (max-width: 480px) {
    & .big-play-button {
      top: 55%;
    }
  }

  /* Loading indicator */
  & .loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    background: rgba(0, 0, 0, 0.5);
    border: 3px solid currentColor;
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    pointer-events: none;
  }

  & .loading-text {
    color: var(--text);
    font-size: 1.25rem;
    font-weight: bold;
  }

  & .loading-dots span {
    animation: cp-video-player-dots 1.4s infinite;
    opacity: 0;
  }

  & .loading-dots span:nth-child(1) {
    animation-delay: 0s;
  }

  & .loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
  }

  & .loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
  }

  & .loading-indicator.hidden {
    display: none;
  }

  @media (max-width: 480px) {
    & .loading-indicator {
      top: 55%;
    }
  }

  /* Video controls bar - positioned below video */
  & .video-controls {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
  }

  /* Idle state - hide cursor over video area */
  &.idle .video-wrapper {
    cursor: none;
  }

  /* Control buttons */
  & .play-pause,
  & .speaker,
  & .cc,
  & .fullscreen,
  & .settings {
    background: transparent;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--text);
    transition: color var(--fast);
    flex-shrink: 0;
  }

  /* Play-pause has no padding - size increased to compensate */
  & .play-pause {
    padding: 0;
  }

  & .play-pause:hover,
  & .speaker:hover,
  & .cc:hover,
  & .fullscreen:hover,
  & .settings:hover {
    color: var(--accent);
  }

  & .play-pause:focus-visible,
  & .speaker:focus-visible,
  & .cc:focus-visible,
  & .fullscreen:focus-visible,
  & .settings:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
  }

  & .play-pause:active,
  & .speaker:active,
  & .cc:active,
  & .fullscreen:active,
  & .settings:active {
    opacity: 0.6;
  }

  & .play-pause svg {
    display: block;
    width: 32px;
    height: 32px;
  }

  & .speaker svg,
  & .cc svg,
  & .fullscreen svg {
    display: block;
    width: 24px;
    height: 24px;
  }

  & .settings svg {
    display: block;
    width: 20px;
    height: 20px;
  }

  /* Settings wrapper and panel */
  & .settings-wrapper {
    position: relative;
    display: flex;
    align-items: center;
  }

  & .settings-panel {
    position: absolute;
    bottom: 100%;
    right: 0;
    z-index: 20;
    margin-bottom: 0;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--sm);
    display: flex;
    gap: var(--sm);
    opacity: 0;
    visibility: hidden;
    box-shadow: var(--shadow);
    transform: translateY(10px);
    transition: all var(--fast) ease;
  }

  & .settings-section {
    min-width: 90px;
  }

  & .settings-wrapper.open .settings-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  & .settings-label {
    font-size: var(--small);
    color: var(--text-2);
    margin-bottom: var(--xs);
    font-weight: bold;
  }

  & .speed-options,
  & .quality-options {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  & .speed-option,
  & .quality-option {
    background: transparent;
    border: none;
    color: var(--text);
    padding: 0.4rem 0.6rem;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    font-size: var(--small);
    transition: background var(--fast);
  }

  & .speed-option:hover,
  & .quality-option:hover {
    background: var(--border);
  }

  & .speed-option.active,
  & .quality-option.active {
    background: var(--accent);
    color: var(--white);
  }

  & .quality-section.hidden {
    display: none;
  }

  & .quality-section {
    padding-right: var(--sm);
    border-right: 1px solid var(--border);
  }

  /* Hidden icon state - only for control button icons */
  & .play-pause .hidden,
  & .speaker .hidden,
  & .cc .hidden,
  & .fullscreen .hidden {
    display: none;
  }

  /* Seekbar container - subtle track, always visible */
  & .seekbar {
    position: relative;
    background: var(--border);
    border-radius: 4px;
    height: 10px;
    flex-grow: 1;
    margin: 0 0.5rem;
    cursor: pointer;
    touch-action: none; /* Prevent scroll on mobile when dragging */
  }

  /* Invisible expanded hit area for easier hover/click */
  & .seekbar::before {
    content: "";
    position: absolute;
    top: -1rem;
    bottom: -1.5rem;
    left: 0;
    right: 0;
  }

  /* Buffer bar - more visible than track */
  & .bufferbar {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--buffer);
    border-radius: 4px;
    height: 100%;
    width: 0;
    pointer-events: none;
  }

  /* Time/progress bar */
  & .timebar {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    background: var(--accent);
    border-radius: 4px;
    height: 100%;
    width: 0;
    pointer-events: none;
  }

  /* Draggable thumb with time display */
  & .thumb {
    position: absolute;
    cursor: grab;
    text-align: center;
    z-index: 2;
    top: -38px;
    left: 0;
    transform: translateX(-50%);
    border-radius: 4px;
    background: var(--accent);
    font-family: var(--mono);
    font-size: var(--body);
    color: var(--white);
    padding: 0.2rem 0.5rem;
    white-space: nowrap;
    transition: transform 0.05s;
  }

  /* Triangle pointer on thumb */
  & .thumb::after {
    content: "";
    position: absolute;
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--accent);
  }

  & .thumb:active {
    cursor: grabbing;
  }

  /* Total time display */
  & .total-time {
    color: var(--text);
    font-family: var(--mono);
    font-size: var(--body);
    white-space: nowrap;
    padding: 0 0.25rem;
    flex-shrink: 0;
  }

  /* Hover thumbnail preview (tooltip above seekbar) */
  & .hover-preview {
    position: absolute;
    bottom: 100%;
    left: 0;
    transform: translateX(-50%);
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 10;
  }

  & .hover-preview.hidden {
    display: none;
  }

  & .hover-thumbnail {
    width: 160px;
    height: 90px;
    background-color: var(--black);
    background-size: auto;
    background-repeat: no-repeat;
    border: 2px solid var(--accent);
    border-radius: 4px;
  }

  & .hover-time {
    margin-top: 4px;
    padding: 2px 8px;
    background: var(--accent);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--white);
  }

  /* Scrub sprite overlay (covers video during drag) */
  & .scrub-sprite {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--black);
    background-repeat: no-repeat;
    z-index: 3;
    pointer-events: none;
  }

  & .scrub-sprite.hidden {
    display: none;
  }

  /* On-screen notification for keyboard actions - always white over video */
  & .video-notification {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--white);
    opacity: 0.8;
    font-size: 2.5rem;
    font-weight: bold;
    text-shadow:
      0 0 10px rgba(0, 0, 0, 0.9),
      0 2px 8px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    z-index: 10;
    transition: opacity var(--normal);
  }

  /* Captions styling */
  & .video::cue {
    color: var(--text);
    background: rgba(0, 0, 0, 0.7);
    font-family: var(--sans);
  }
}

/* Fullscreen states */
.cp-video-player:fullscreen {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  outline: none;
  background: var(--black);
}

.cp-video-player:-webkit-full-screen {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  outline: none;
  background: var(--black);
}

.cp-video-player:-moz-full-screen {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  outline: none;
  background: var(--black);
}

.cp-video-player:-ms-fullscreen {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  outline: none;
  background: var(--black);
}

/* Fullscreen - video fills entire area */
.cp-video-player:fullscreen .video-wrapper {
  flex: 1;
}

.cp-video-player:-webkit-full-screen .video-wrapper {
  flex: 1;
}

.cp-video-player:fullscreen .video {
  aspect-ratio: unset;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cp-video-player:-webkit-full-screen .video {
  aspect-ratio: unset;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Fullscreen - controls overlay at bottom */
.cp-video-player:fullscreen .video-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 0.75rem 2rem;
  border-top: none;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  transition: opacity var(--normal) ease;
}

.cp-video-player:-webkit-full-screen .video-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 0.75rem 2rem;
  border-top: none;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  transition: opacity var(--normal) ease;
}

/* Fullscreen - force white controls over dark video */
.cp-video-player:fullscreen .play-pause,
.cp-video-player:fullscreen .speaker,
.cp-video-player:fullscreen .cc,
.cp-video-player:fullscreen .fullscreen,
.cp-video-player:fullscreen .settings,
.cp-video-player:fullscreen .total-time {
  color: var(--white);
}

.cp-video-player:-webkit-full-screen .play-pause,
.cp-video-player:-webkit-full-screen .speaker,
.cp-video-player:-webkit-full-screen .cc,
.cp-video-player:-webkit-full-screen .fullscreen,
.cp-video-player:-webkit-full-screen .settings,
.cp-video-player:-webkit-full-screen .total-time {
  color: var(--white);
}

/* Fullscreen - seekbar track visible on dark background */
.cp-video-player:fullscreen .seekbar {
  background: rgba(255, 255, 255, 0.3);
}

.cp-video-player:-webkit-full-screen .seekbar {
  background: rgba(255, 255, 255, 0.3);
}

/* Fullscreen idle - hide controls, heading, cursor */
.cp-video-player.idle:fullscreen .video-controls {
  opacity: 0;
  pointer-events: none;
}

.cp-video-player.idle:-webkit-full-screen .video-controls {
  opacity: 0;
  pointer-events: none;
}

.cp-video-player.idle:fullscreen .video-heading {
  opacity: 0;
}

.cp-video-player.idle:-webkit-full-screen .video-heading {
  opacity: 0;
}

.cp-video-player.idle:fullscreen {
  cursor: none;
}

.cp-video-player.idle:-webkit-full-screen {
  cursor: none;
}

/* Prevent body scroll while dragging thumb */
body.dragging {
  user-select: none;
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .cp-video-player {
    & .video-controls {
      gap: 0.125rem;
      padding: 0.375rem;
    }

    & .play-pause svg {
      width: 28px;
      height: 28px;
    }

    & .speaker svg,
    & .cc svg,
    & .fullscreen svg {
      width: 20px;
      height: 20px;
    }

    & .thumb {
      font-size: 0.65rem;
      padding: 0.15rem 0.4rem;
      top: -28px;
    }

    & .total-time {
      font-size: 0.65rem;
    }

    & .seekbar {
      margin: 0 0.25rem;
    }
  }
}

/* Override grid width-full margins - needs high specificity to beat standard.css */
body#ly-standard .grid-container > .cp-video-player.width-full {
  width: min(var(--wide), calc(100% - var(--md) * 2));
  margin-left: auto;
  margin-right: auto;
}

/* Mobile: edge-to-edge, no border radius */
@media (max-width: 600px) {
  body#ly-standard .grid-container > .cp-video-player.width-full {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  .cp-video-player {
    border-radius: 0;
  }

  .cp-video-player .video-wrapper {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  .cp-video-player .video-controls {
    border-radius: 0;
  }
}

/* Loading dots animation */
@keyframes cp-video-player-dots {
  0%, 80%, 100% {
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
}

/* A portrait clip (a phone video, `portrait` on the player): 9:16 in a column
   no wider than a phone, centered, so a story column never becomes a tower */
.cp-video-player.portrait { max-width: 24rem; }
.cp-video-player.portrait .video { aspect-ratio: 9 / 16; }
