@use '../abstracts' as *;

// ============================================================
// MediaElement players — [audio], [video], [playlist] and the Audio/Video
// widgets (core's wp-mediaelement + mediaelementplayer-legacy)
//
// Core prints its skin late, after this sheet, so every rule here starts
// with :root — one class more than core's rule (toolkit unit-test-findings,
// "Post formats"). Colours are custom properties on the container: the
// audio bar takes the theme's glass; a video's controls sit on the picture
// and stay light-on-dark; [playlist style="dark"] keeps the author's choice.
// The control icons are core's white SVG sprite, darkened by a filter.
// ============================================================

:root {
  .mejs-container {
    --mejs-bar: var(--glass-strong);
    --mejs-ring: var(--hairline);
    --mejs-ink: var(--ink-soft);
    --mejs-icon: brightness(0) opacity(0.58);
    --mejs-track: var(--rule-strong);
    --mejs-loaded: var(--rule-strong);
    --mejs-fill: var(--accent-deep);
  }

  // Controls on a picture, and the author's dark playlist
  .mejs-video,
  .wp-playlist-dark .mejs-container {
    --mejs-ink: rgba(255, 255, 255, 0.9);
    --mejs-icon: none;
    --mejs-track: rgba(255, 255, 255, 0.22);
    --mejs-loaded: rgba(255, 255, 255, 0.4);
    --mejs-fill: #fff;
  }

  .mejs-video { --mejs-bar: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.55)); }

  .wp-playlist-dark .mejs-container {
    --mejs-bar: rgba(255, 255, 255, 0.08);
    --mejs-ring: rgba(255, 255, 255, 0.1);
  }

  &[data-theme="dark"] .mejs-container {
    --mejs-icon: brightness(0) invert(1) opacity(0.78);
  }

  // ---- The container and its bar ----
  .mejs-container * { font-family: var(--font-sans); }

  .mejs-container,
  .mejs-container .mejs-controls { background: var(--mejs-bar); }

  .mejs-audio {
    border-radius: $pill-radius;
    box-shadow: inset 0 0 0 1px var(--mejs-ring);

    .mejs-controls {
      padding: 0 12px;
      border-radius: $pill-radius;
    }
  }

  // A video keeps its black letterbox; the corners follow the theme's media
  .mejs-video {
    background: #000;
    border-radius: var(--radius-md);
    overflow: hidden;

    &.mejs-container-fullscreen { border-radius: 0; }
  }

  // [video] at the file's own width is centred, as a small image is (D16)
  .wp-video { margin-inline: auto; }

  // ---- Buttons ----
  .mejs-button > button {
    filter: var(--mejs-icon);
    outline: none;
  }

  // The filter would darken a ring on the button too: ring its wrapper
  .mejs-button:has(> button:focus-visible) {
    outline: 2px solid var(--accent-deep);
    outline-offset: -4px;
    border-radius: var(--radius-sm);
  }

  .mejs-video .mejs-button:has(> button:focus-visible) { outline-color: #fff; }

  // The player itself takes focus (tabindex 0) and drew nothing
  .mejs-container:focus-visible {
    outline: 2px solid var(--accent-deep);
    outline-offset: 3px;
  }

  // ---- Time ----
  .mejs-time {
    color: var(--mejs-ink);
    font-size: 12px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
  }

  // ---- The progress rail: a 4px line, its centre where core's 10px bar sat ----
  .mejs-controls .mejs-time-rail .mejs-time-total {
    height: 4px;
    margin-top: 8px;
    border-radius: 2px;
    background: var(--mejs-track);
  }

  .mejs-controls .mejs-time-rail :is(.mejs-time-loaded, .mejs-time-current, .mejs-time-hovered, .mejs-time-buffering) {
    height: 4px;
    border-radius: 2px;
  }

  .mejs-controls .mejs-time-rail .mejs-time-loaded { background: var(--mejs-loaded); }
  .mejs-controls .mejs-time-rail .mejs-time-current { background: var(--mejs-fill); }
  .mejs-controls .mejs-time-rail .mejs-time-hovered { background: var(--mejs-loaded); }

  .mejs-time-handle-content {
    top: -7px;
    border-color: var(--mejs-fill);
    background: var(--mejs-fill);
  }

  // The time shown above the rail on hover
  .mejs-time-float {
    border: 0;
    border-radius: 6px;
    background: var(--code-bg);
    color: var(--code-ink);
  }

  .mejs-time-float-corner { border-color: var(--code-bg) transparent transparent; }

  // ---- Volume (audio: horizontal) ----
  .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-total {
    top: 18px;
    height: 4px;
    border-radius: 2px;
    background: var(--mejs-track);
  }

  .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-current {
    height: 100%;
    border-radius: 2px;
    background: var(--mejs-fill);
  }

  // ---- [playlist]: a card, like the theme's other panels ----
  .wp-playlist {
    margin: 0;
    padding: 18px 20px;
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    background: var(--glass);
    box-shadow: var(--shadow-soft);
    color: var(--ink-soft);
    font-size: 14.5px;
  }

  .wp-playlist-dark {
    border-color: transparent;
    background: var(--code-bg);
    color: var(--code-ink);
  }

  .wp-playlist-current-item {
    display: flex;
    align-items: center;
    gap: 14px;
    height: auto;
    min-height: 60px;
    margin-bottom: 14px;

    img {
      float: none;
      flex-shrink: 0;
      margin: 0;
      border-radius: var(--radius-sm);
    }

    > div { min-width: 0; }
  }

  // Core colours every caption #333 / #ddd; the card's colour instead
  .wp-playlist .wp-playlist-caption { color: inherit; }

  .wp-playlist .wp-playlist-current-item :is(.wp-playlist-item-title, .wp-playlist-item-album, .wp-playlist-item-artist) {
    line-height: 1.5;
  }

  .wp-playlist-current-item .wp-playlist-item-title {
    font-size: 15.5px;
    font-weight: 500;
    color: var(--ink);
  }

  .wp-playlist-current-item .wp-playlist-item-album { font-size: 14px; }

  .wp-playlist-current-item .wp-playlist-item-artist {
    font-size: 11.5px;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
  }

  .wp-playlist-dark .wp-playlist-current-item :is(.wp-playlist-item-title, .wp-playlist-item-artist) { color: inherit; }

  .wp-playlist-tracks { margin-top: 12px; }

  .wp-playlist-item {
    padding: 9px 4px;
    border-bottom: 1px solid var(--rule);

    &:last-child { border-bottom: 0; }
  }

  .wp-playlist-dark .wp-playlist-item { border-color: rgba(255, 255, 255, 0.1); }

  .wp-playlist .wp-playlist-item .wp-playlist-caption {
    color: inherit;
    font-size: 14.5px;
    text-decoration: none;
  }

  .wp-playlist .wp-playlist-item .wp-playlist-caption:hover { color: var(--accent-deep); }
  .wp-playlist-dark .wp-playlist-item .wp-playlist-caption:hover { color: #fff; }

  .wp-playlist-item-length {
    top: 9px;
    right: 4px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    color: var(--ink-faint);
  }

  .wp-playlist-dark .wp-playlist-item-length { color: inherit; opacity: 0.7; }

  // The playing track: the theme's weight, not core's bold + white band
  .wp-playlist .wp-playlist-playing {
    background: none;
    color: var(--ink);
    font-weight: 500;
  }

  .wp-playlist-dark .wp-playlist-playing { color: #fff; }
}
