/* ==========================================================================
   Dual-Source Synchronized Video Player - UI styles
   Dark, cinematic theme.  Everything is scoped under .ctp so the player can
   be dropped into any page without leaking styles.
   ========================================================================== */

:root {
  --ctp-bg: #05070a;
  --ctp-surface: #0d1117;
  --ctp-surface-2: #151b24;
  --ctp-border: rgba(255, 255, 255, 0.1);
  --ctp-border-strong: rgba(255, 255, 255, 0.18);
  --ctp-text: #f2f5f9;
  --ctp-text-dim: #9aa6b6;
  --ctp-accent: #4f8cff;
  --ctp-accent-2: #7c5cff;
  --ctp-danger: #ff5c6c;
  --ctp-radius: 14px;
  --ctp-radius-sm: 9px;
  --ctp-aspect: 16 / 9;
  --ctp-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --ctp-transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --ctp-ctl-h: 44px;
  --ctp-seek-fb-duration: 700ms;
  /* The subtitle area ends ABOVE the control bar, even while the bar is
     visible: the bar's lowest row sits "padding-bottom (8px) + --ctp-ctl-h"
     above the player's bottom edge, so the offset has to clear that stack
     (52px here) with a little room - a smaller value would let a cue that
     is anchored low (a position near 100 %) render behind the buttons. */
  --ctp-subs-offset: 54px;

  /* --- interaction states ---------------------------------------------
     Every theme has to define these five tokens: they are the colours of
     the hover, the pressed, the selected and the scrollbar states.  They
     are shared by every control of the player (the buttons, the menus and
     the dropdowns) so that a light theme stays readable as well. */
  --ctp-hover: rgba(255, 255, 255, 0.12);
  --ctp-hover-soft: rgba(255, 255, 255, 0.06);
  --ctp-selected: rgba(79, 140, 255, 0.18);
  --ctp-scrollbar: rgba(255, 255, 255, 0.22);
  --ctp-scrollbar-hover: rgba(255, 255, 255, 0.34);
  --ctp-input-bg: rgba(255, 255, 255, 0.06);
}

.ctp-host {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
}

/* The full-page mode fills the viewport - the host must not add a default
   body margin that would make the page scroll. */
.ctp-host--fullpage {
  margin: 0;
  padding: 0;
  max-width: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  /* The page itself must never scroll - the player is the whole page. */
  overflow: hidden;
}

.ctp {
  position: relative;
  display: block;
  width: 100%;
  /* The width comes from the parent - the player never exceeds it. */
  max-width: var(--ctp-max-w, 100%);
  /* A grid or flex item must be allowed to shrink below its content size. */
  min-width: 0;
  min-height: 0;
  /* The container owns the dimensions: the height comes from the parent (or
     from the viewport), never from the media element. */
  height: var(--ctp-h, 100%);
  margin: 0 auto;
  background: var(--ctp-bg);
  color: var(--ctp-text);
  /* No frame at all: the player blends into its container.  No border, no
     outline, no shadow, no rounded corners - not on the root and not on any
     of the wrappers inside it. */
  border: 0;
  border-radius: 0;
  outline: none;
  box-shadow: none;
  overflow: hidden;
  box-sizing: border-box;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  isolation: isolate;
}

/* The box model has to be predictable for the sizing rules below. */
.ctp *,
.ctp *::before,
.ctp *::after { box-sizing: inherit; }

/* The author rules below set `display`, which would otherwise win over the
   user-agent rule for the `hidden` attribute. */
.ctp [hidden] { display: none !important; }

/* The player root is a region, not a control: it must never draw a frame of
   its own.  The focus rings of the interactive controls stay untouched. */
.ctp:focus,
.ctp:focus-visible { outline: none; }
.ctp *:focus-visible {
  outline: 2px solid var(--ctp-accent);
  outline-offset: 2px;
}

.ctp-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.ctp-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ctp-icon {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  /* An icon never stretches and never shrinks - it keeps its size when the
     button around it changes. */
  flex: 0 0 auto;
}
.ctp-icon--sm { width: 18px; height: 18px; }
.ctp-icon--lg { width: 30px; height: 30px; stroke-width: 1.8; }
.ctp-icon--xl { width: 42px; height: 42px; stroke-width: 1.6; }

/* ------------------------------- stage ---------------------------------- */

/* The stage fills the player - it never derives its size from the media.
   The picture itself is rendered inside with "object-fit" (letterboxed by
   default), so the aspect ratio of the source cannot resize the container. */
.ctp__stage {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #131a24 0%, #05070a 70%);
  overflow: hidden;
  touch-action: manipulation;
  /* The stage contains absolutely positioned layers only - it may contain
     them without leaking into the document. */
  contain: layout paint;
}

.ctp__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;      /* never distort the picture */
  background: #000;
  display: block;
  z-index: 1;
}
.ctp--fit-cover .ctp__video { object-fit: cover; }

/* The standby element prepares the next quality in the background: it is
   invisible and behind the active picture until the handoff. */
.ctp__video--standby {
  opacity: 0;
  z-index: 0;
  pointer-events: none;
}

/* poster - shown until the first frame is rendered */
.ctp__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  pointer-events: none;     /* the poster must never block the controls */
  z-index: 1;
}
.ctp--fit-cover .ctp__poster { object-fit: cover; }
.ctp.has-poster-error .ctp__poster { display: none !important; }

.ctp__scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.28) 18%, rgba(0, 0, 0, 0) 42%);
  opacity: 1;
  transition: opacity var(--ctp-transition);
  pointer-events: none;
  z-index: 2;
}
.ctp.is-idle .ctp__scrim { opacity: 0; }

/* ---------------------------- center controls ---------------------------- */

.ctp__center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 20px;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ctp-transition), visibility var(--ctp-transition);
}
/* The centre controls appear while the pointer is over the picture.  The
   states of the player (idle, paused, error, end of the media) refine this
   rule - they are defined further down, in the order of their priority. */
.ctp.is-hover .ctp__center {
  opacity: 1;
  pointer-events: auto;
}

/* While the loading indicator is visible the centre controls would overlap
   it.  The player removes them from the layout (the "hidden" attribute), so
   they cannot be focused or clicked either - the rule that keeps the
   pointer away from them lives with the other state rules below. */

.ctp__center-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--ctp-border-strong);
  background: rgba(10, 14, 20, 0.55);
  backdrop-filter: blur(10px);
  color: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}
.ctp__center-btn:hover {
  transform: scale(1.07);
  background: rgba(79, 140, 255, 0.32);
}
.ctp__center-btn:active { transform: scale(0.96); }

/* big play button (the play/pause button of the centre group) */
.ctp__bigplay {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 1px solid var(--ctp-border-strong);
  background: rgba(10, 14, 20, 0.6);
  backdrop-filter: blur(10px);
  color: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  transition: transform var(--ctp-transition), background var(--ctp-transition), opacity var(--ctp-transition);
}
.ctp__bigplay .ctp-icon { margin-left: 4px; }
.ctp__bigplay[data-state="pause"] .ctp-icon { margin-left: 0; }
.ctp__bigplay:hover {
  transform: scale(1.06);
  background: rgba(79, 140, 255, 0.32);
}

/* ------------------------------ subtitles -------------------------------- */

.ctp__subs-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  /* The subtitle area ends above the control bar while the bar is visible.
     The offset is measured from the real control bar (--ctp-subs-offset is
     written by the player), so it follows small phones, embedded players and
     fullscreen instead of a hard-coded bar height. */
  bottom: var(--ctp-subs-offset, 54px);
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
  /* The bar fades out; the subtitles follow it down smoothly instead of
     jumping between the two positions. */
  transition: bottom var(--ctp-transition);
}
/* The controls are hidden: there is nothing below the picture any more, so
   the cues move down (slightly) into the freed space.  The idle state is the
   player's existing control-visibility state - no independent timer. */
.ctp.is-idle .ctp__subs-wrap {
  bottom: var(--ctp-subs-offset-idle, 12px);
}

.ctp__subs-group {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ctp__subs {
  position: absolute;
  left: 0;
  right: 0;
  padding: 0 4%;
  /* Every layer is anchored by its own vertical position (a percentage
     measured from the top of the stage: 0 % = at the top, 100 % = at the
     bottom).  The anchor is the effective position - the layout moves it
     down when a cue would not fit above it. */
  bottom: calc(100% - var(--ctp-sub-anchor, var(--ctp-sub-position, 90%)));
  display: flex;
  justify-content: var(--ctp-sub-align, center);
  opacity: 0;
  transition: opacity 120ms ease;
  /* The collision avoidance moves the secondary layer up when the two
     layers would cover each other. */
  transform: translateY(var(--ctp-sub-shift, 0px));
}
.ctp__subs.is-visible { opacity: 1; }

.ctp__sub {
  display: inline-block;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--ctp-sub-background, rgba(0, 0, 0, 0.55));
  color: var(--ctp-sub-color, #ffffff);
  opacity: var(--ctp-sub-opacity, 1);
  font-family: var(--ctp-sub-font-family, Arial, sans-serif);
  /* The scale is 1 as long as the cue fits - a cue that is too tall for
     the space above its position is scaled down instead of losing a line. */
  font-size: calc(var(--ctp-sub-font-size, 24px) * var(--ctp-sub-scale, 1));
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  white-space: pre-line;          /* multi line cues keep their breaks */
  overflow-wrap: anywhere;
  -webkit-text-stroke: calc(var(--ctp-sub-outline-width, 2px) * var(--ctp-sub-scale, 1)) var(--ctp-sub-outline-color, #000000);
  paint-order: stroke fill;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  /* The direction is not forced here: the layer and the cue carry the "dir"
     attribute of their own language (a Persian track is right-to-left). */
}

/* ----------------------------- seek feedback ----------------------------- */

.ctp__seek-fb {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 14px 16px;
  border-radius: 50%;
  background: rgba(8, 11, 16, 0.72);
  border: 1px solid var(--ctp-border);
  backdrop-filter: blur(8px);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}
.ctp__seek-fb--back { left: 10%; }
.ctp__seek-fb--fwd { right: 10%; }
.ctp__seek-fb.is-active {
  animation: ctp-seek-fb var(--ctp-seek-fb-duration) ease-out;
}
.ctp__seek-fb-text {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
@keyframes ctp-seek-fb {
  0%   { opacity: 0; transform: translateY(-50%) scale(0.72); }
  22%  { opacity: 1; transform: translateY(-50%) scale(1.06); }
  70%  { opacity: 1; transform: translateY(-50%) scale(1); }
  100% { opacity: 0; transform: translateY(-50%) scale(0.94); }
}

/* ---------------------------- replay overlay ----------------------------- */

/* Icon only: the accessible name carries the meaning ("Replay video"). */
.ctp__replay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 92px;
  height: 92px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--ctp-border-strong);
  background: rgba(8, 11, 16, 0.74);
  backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  line-height: 0;
  z-index: 5;
  transition: opacity 220ms ease, transform 220ms ease;
}
.ctp__replay.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.ctp__replay:hover { background: rgba(79, 140, 255, 0.34); }
.ctp__replay .ctp-icon {
  width: 40px;
  height: 40px;
  margin: 0;
  display: block;
  flex: 0 0 auto;
}

/* At the end of the media only the replay button is shown - the centre
   controls (back / play / forward) are hidden.  The rule lives with the
   other state rules of the transient controls (see below), because it has
   to win over the paused and the hover state. */

/* spinner */
.ctp__spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  color: #fff;
  pointer-events: none;
  z-index: 4;
}
.ctp__spinner[hidden] { display: none; }
.ctp-spin { animation: ctp-spin 900ms linear infinite; }
@keyframes ctp-spin {
  to { transform: rotate(360deg); }
}

/* error overlay */
.ctp__error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: clamp(10px, 4vw, 24px);
  text-align: center;
  overflow: auto;
  background: rgba(5, 7, 10, 0.9);
  backdrop-filter: blur(4px);
  z-index: 6;
}
.ctp__error[hidden] { display: none; }
.ctp__error-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 92, 108, 0.14);
  color: var(--ctp-danger);
}
.ctp__error-title {
  margin: 0;
  max-width: 100%;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.ctp__error-msg {
  margin: 0;
  max-width: min(46ch, 100%);
  color: var(--ctp-text-dim);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* toast (non blocking messages) */
.ctp__toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 82%;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(8, 11, 16, 0.92);
  border: 1px solid var(--ctp-border-strong);
  color: var(--ctp-text);
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  transition: opacity 200ms ease;
  z-index: 7;
  pointer-events: none;
}
.ctp__toast.is-visible { opacity: 1; }

/* ------------------------------ controls --------------------------------- */

.ctp__controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 10px 8px;
  background: linear-gradient(to top, rgba(4, 6, 9, 0.94) 12%, rgba(4, 6, 9, 0.6) 55%, rgba(4, 6, 9, 0) 100%);
  /* "visibility" is part of the transition: a hidden control bar must not
     stay in the tab order. */
  transition: opacity var(--ctp-transition), transform var(--ctp-transition), visibility var(--ctp-transition);
  z-index: 3;
}
/* The idle state hides the transient controls.  It comes after the hover
   state, therefore the centre controls disappear as well - the pointer may
   stay inside the player without moving. */
.ctp.is-idle .ctp__controls {
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
}
/* The controls in the centre of the picture are transient as well - they
   disappear together with the control bar when the user is idle. */
.ctp.is-idle .ctp__center {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
/* A persistent state wins over the idle state: a paused playback, a visible
   error and an open menu always keep their controls on the screen. */
.ctp.is-paused .ctp__controls,
.ctp.has-error .ctp__controls,
.ctp.is-menu-open .ctp__controls {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}
.ctp.is-paused .ctp__center,
.ctp.has-error .ctp__center,
.ctp.is-menu-open .ctp__center {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
/* At the end of the media only the replay button is shown - the centre
   controls (back / play / forward) are hidden.  This state wins over the
   paused state and over the hover state. */
.ctp.is-ended .ctp__center {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
/* While the loading indicator is visible the centre controls would overlap
   it - they must not catch the pointer either. */
.ctp.is-loading .ctp__center,
.ctp.is-loading .ctp__replay {
  pointer-events: none;
}

/* timeline */
.ctp__timeline {
  position: relative;
  height: 22px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}
.ctp__track {
  position: relative;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: visible;
  transition: height 120ms ease;
}
.ctp__timeline:hover .ctp__track,
.ctp__timeline:focus-visible .ctp__track,
.ctp__timeline.is-dragging .ctp__track { height: 6px; }

.ctp__buffer,
.ctp__played,
.ctp__hover {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 999px;
  pointer-events: none;
}
.ctp__buffer { background: rgba(255, 255, 255, 0.32); width: 0; }
.ctp__played {
  background: linear-gradient(90deg, var(--ctp-accent) 0%, var(--ctp-accent-2) 100%);
  width: 0;
}
/* A viewer behind the live edge gets a warmer bar; at the edge the normal
   accent is used.  It is the same timeline, only the state is different. */
.ctp__timeline.is-behind-live .ctp__played {
  background: linear-gradient(90deg, #f59e0b 0%, #ef4444 100%);
}
.ctp__timeline.is-behind-live .ctp__thumb { background: #fbbf24; }
.ctp__hover {
  background: rgba(255, 255, 255, 0.35);
  width: 0;
  opacity: 0;
  transition: opacity 120ms ease;
}
.ctp__hover[data-visible="true"] { opacity: 1; }
.ctp__thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  border-radius: 50%;
  background: #fff;
  transform: translateY(-50%) scale(0.6);
  opacity: 0;
  transition: transform 140ms ease, opacity 140ms ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.ctp__timeline:hover .ctp__thumb,
.ctp__timeline:focus-visible .ctp__thumb,
.ctp__timeline.is-dragging .ctp__thumb {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* chapter markers - they must never block the scrubbing */
.ctp__chapters {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ctp__chapter-marker {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 12px;
  margin-left: -1.5px;
  transform: translateY(-50%);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  transition: background 120ms ease;
}
.ctp__chapter-marker.is-active { background: var(--ctp-accent); }

/* hover tooltip (time + chapter title) */
.ctp__tip {
  position: absolute;
  bottom: 100%;
  left: 0;
  transform: translateX(-50%);
  margin-bottom: 6px;
  padding: 4px 9px;
  border-radius: 7px;
  background: rgba(8, 11, 16, 0.94);
  border: 1px solid var(--ctp-border);
  color: var(--ctp-text);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
}

/* button row */
.ctp__bar {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: var(--ctp-ctl-h);
}
.ctp__spacer { flex: 1 1 auto; }

.ctp-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  /* Icon buttons carry no padding - the default padding of a button would
     make the content box narrower than the icon. */
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ctp-text);
  cursor: pointer;
  transition: background var(--ctp-transition), color var(--ctp-transition), transform 120ms ease;
  flex: 0 0 auto;
}
.ctp-btn:hover { background: var(--ctp-hover); }
.ctp-btn:active { transform: scale(0.94); }
.ctp-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* live badge / "Go live" button */
.ctp-btn--live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background var(--ctp-transition), color var(--ctp-transition),
    border-color var(--ctp-transition), transform 120ms ease;
}
.ctp-btn--live[hidden] { display: none; }
.ctp__live-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}
.ctp__live-label { line-height: 1; }
.ctp-btn--live.is-live {
  color: #ff6b6b;
  border-color: rgba(255, 77, 79, 0.55);
  background: rgba(229, 62, 62, 0.16);
  cursor: default;
}
.ctp-btn--live.is-live .ctp__live-dot {
  background: #ff4d4f;
  animation: ctp-live-pulse 1.8s ease-in-out infinite;
}
.ctp-btn--live.is-behind {
  color: #171207;
  border-color: #fbbf24;
  background: #fbbf24;
  cursor: pointer;
}
.ctp-btn--live.is-behind:hover {
  background: #fcd34d;
  transform: translateY(-1px);
}
.ctp-btn--live.is-behind:active { transform: scale(0.96); }
@keyframes ctp-live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.55); }
  50% { box-shadow: 0 0 0 5px rgba(255, 77, 79, 0); }
}
.ctp.is-behind-live .ctp__time-current { color: #fbbf24; }

/* Reduced motion: the dot keeps its colour, the pulse is not needed. */
@media (prefers-reduced-motion: reduce) {
  .ctp-btn--live.is-live .ctp__live-dot { animation: none; }
}
.ctp-btn--primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  padding: 0 16px;
  height: 38px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  background: var(--ctp-accent);
  color: #fff;
}
.ctp-btn--primary:hover { background: #6ba0ff; }
.ctp-btn--sm {
  height: 30px;
  width: auto;
  padding: 0 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
}
.ctp-btn--repeat.is-on {
  color: var(--ctp-accent);
  background: var(--ctp-selected);
}

.ctp__time {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ctp-text);
  white-space: nowrap;
  /* The time is always read from left to right - the interface language
     never changes the order of the values or their separator. */
  direction: ltr;
  unicode-bidi: isolate;
}
.ctp__time-sep { color: var(--ctp-text-dim); }
.ctp__time-dur { color: var(--ctp-text-dim); }

/* volume */
.ctp__volume {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ctp__volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 0;
  opacity: 0;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ctp-accent) 0%, var(--ctp-accent) var(--ctp-vol, 100%), rgba(255, 255, 255, 0.25) var(--ctp-vol, 100%));
  cursor: pointer;
  transition: width var(--ctp-transition), opacity var(--ctp-transition);
}
.ctp__volume:hover .ctp__volume-slider,
.ctp__volume:focus-within .ctp__volume-slider {
  width: 84px;
  opacity: 1;
}
.ctp__volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
.ctp__volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #fff;
}

/* menus */
.ctp-menu { position: relative; flex: 0 0 auto; }
.ctp-menu__toggle {
  width: auto;
  min-width: 38px;
  padding: 0 8px;
  gap: 4px;
  grid-auto-flow: column;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ctp-text);
}
.ctp-menu__label { white-space: nowrap; }
.ctp-menu__toggle .ctp-icon { opacity: 0.75; }
.ctp-menu.is-open .ctp-menu__toggle { background: rgba(255, 255, 255, 0.14); }

.ctp-menu__panel {
  position: absolute;
  bottom: calc(100% + 10px);
  /* The player layout is always left-to-right, therefore the panel is
     anchored with a physical offset. */
  right: 0;
  min-width: 250px;
  /* The maximum height is computed by the layout script (it depends on the
     space between the player edge and the button).  The panel itself never
     scrolls - the list inside does, so the header stays visible. */
  max-height: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 6px;
  border-radius: var(--ctp-radius-sm);
  background: rgba(14, 18, 24, 0.97);
  border: 1px solid var(--ctp-border-strong);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(14px);
  z-index: 20;
  animation: ctp-menu-in 140ms ease-out;
}
.ctp-menu__panel[hidden] { display: none; }
@keyframes ctp-menu-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
/* The scrollable area: long lists (e.g. many subtitle tracks) scroll here
   instead of growing the panel beyond the player. */
.ctp-menu__list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}
.ctp-menu__list::-webkit-scrollbar { width: 8px; }
.ctp-menu__list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
}
.ctp-menu__list::-webkit-scrollbar-track { background: transparent; }

.ctp-menu__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 8px;
  margin-bottom: 5px;
  border-bottom: 1px solid var(--ctp-border);
  flex: 0 0 auto;      /* the header never scrolls away */
}
.ctp-menu__header-title {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  /* A long title must never overlap the navigation icons - it is shortened
     with an ellipsis instead. */
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ctp-menu__back,
.ctp-menu__close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  /* The default padding of a button would make the content box narrower
     than the icon - the icon would be shifted to the right. */
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ctp-text);
  cursor: pointer;
  flex: 0 0 auto;
}
.ctp-menu__back:hover,
.ctp-menu__close:hover { background: rgba(255, 255, 255, 0.18); }
.ctp-menu__back[hidden],
.ctp-menu__close[hidden] { display: none !important; }
/* The close button belongs to the trailing edge of the header. */
.ctp-menu__close { margin-inline-start: auto; }

.ctp-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ctp-text);
  font: inherit;
  font-size: 13px;
  text-align: start;
  cursor: pointer;
  transition: background var(--ctp-transition);
}
.ctp-menu__item:hover { background: rgba(255, 255, 255, 0.1); }
.ctp-menu__item.is-active { color: #fff; font-weight: 600; }
.ctp-menu__item.is-active .ctp-menu__check { opacity: 1; }
.ctp-menu__item:disabled { opacity: 0.45; cursor: not-allowed; }
.ctp-menu__check { margin-inline-start: auto; opacity: 0; color: var(--ctp-accent); }
.ctp-menu__icon { flex: 0 0 auto; opacity: 0.8; }
.ctp-menu__chevron { flex: 0 0 auto; opacity: 0.5; }
.ctp-menu__body { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ctp-menu__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctp-menu__value {
  color: var(--ctp-text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A settings row: the label sits on the leading edge, the current value on
   the trailing edge - the two are pushed apart. */
.ctp-menu__item--nav,
.ctp-menu__item--role {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 9px 12px;
}
.ctp-menu__item--nav .ctp-menu__main,
.ctp-menu__item--role .ctp-menu__main {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 0 1 auto;
}
.ctp-menu__item--nav .ctp-menu__aside,
.ctp-menu__item--role .ctp-menu__aside {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 0;
}

/* The role of a subtitle track (primary / secondary / none) */
.ctp-menu__role {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--ctp-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ctp-text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.ctp-menu__role--primary {
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.18);
  color: #cfe0ff;
}
.ctp-menu__role--secondary {
  border-color: rgba(255, 224, 138, 0.45);
  background: rgba(255, 224, 138, 0.14);
  color: #ffe08a;
}
.ctp-menu__sub {
  font-size: 11px;
  color: var(--ctp-text-dim);
  font-variant-numeric: tabular-nums;
}
.ctp-menu__group {
  padding: 7px 10px 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ctp-text-dim);
}
.ctp-menu__sep {
  height: 1px;
  margin: 5px 8px;
  background: var(--ctp-border);
}

/* -------------------------- appearance form ------------------------------ */

.ctp__form {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 3px;
  min-width: 250px;
}
.ctp__form__tabs { display: flex; gap: 4px; }
.ctp__form__tab {
  flex: 1 1 0;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--ctp-border);
  background: transparent;
  color: var(--ctp-text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.ctp__form__tab:hover { color: var(--ctp-text); }
.ctp__form__tab.is-active {
  background: rgba(79, 140, 255, 0.18);
  border-color: rgba(79, 140, 255, 0.45);
  color: #fff;
}
.ctp__form__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--ctp-text-dim);
}
.ctp__form__control { display: flex; align-items: center; gap: 6px; }
/* The dropdown of the settings form shares the row with the other controls. */
.ctp__form__control .ctp-select { max-width: 170px; }
.ctp__form__range { width: 88px; }
.ctp__form__color {
  width: 30px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--ctp-border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.ctp__form__value {
  min-width: 40px;
  text-align: end;
  color: var(--ctp-text);
  font-variant-numeric: tabular-nums;
}
.ctp__form__actions { display: flex; justify-content: flex-end; margin-top: 3px; }

/* ------------------------------ dropdown ---------------------------------
   The native <select> draws its popup with the colors of the operating
   system: it ignores the theme of the player and it is unreadable in the
   dark theme.  The dropdown below is rendered by the player itself, it lives
   inside the player (so that it is visible in the fullscreen mode and not
   clipped by the settings panel) and it inherits the theme variables. */

.ctp-select {
  position: relative;
  display: inline-flex;
  max-width: 100%;
}
.ctp-select__button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--ctp-border);
  border-radius: 6px;
  background: var(--ctp-input-bg);
  color: var(--ctp-text);
  font: inherit;
  font-size: 12px;
  text-align: start;
  cursor: pointer;
  transition: background var(--ctp-transition), border-color var(--ctp-transition);
}
.ctp-select__button:hover { background: var(--ctp-hover); }
.ctp-select__button:focus-visible { outline: 2px solid var(--ctp-accent); outline-offset: 2px; }
.ctp-select__value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctp-select__chevron { flex: 0 0 auto; opacity: 0.6; }
.ctp-select__button[aria-expanded="true"] .ctp-select__chevron { transform: rotate(180deg); }

/* The popup: a fixed box next to its button.  It is a child of the player,
   therefore it is not clipped by the settings panel and it inherits the
   theme variables of the player. */
.ctp-select__menu {
  position: fixed;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 4px;
  border: 1px solid var(--ctp-border-strong);
  border-radius: 8px;
  background: var(--ctp-surface-2);
  color: var(--ctp-text);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
  scrollbar-width: thin;
  scrollbar-color: var(--ctp-scrollbar) transparent;
}
.ctp-select__menu::-webkit-scrollbar { width: 8px; }
.ctp-select__menu::-webkit-scrollbar-thumb {
  background: var(--ctp-scrollbar);
  border-radius: 999px;
}
.ctp-select__menu::-webkit-scrollbar-thumb:hover { background: var(--ctp-scrollbar-hover); }
.ctp-select__menu::-webkit-scrollbar-track { background: transparent; }
.ctp-select__option {
  display: block;
  width: 100%;
  padding: 6px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ctp-text);
  font: inherit;
  font-size: 12px;
  text-align: start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background var(--ctp-transition);
}
.ctp-select__option:hover,
.ctp-select__option.is-active { background: var(--ctp-hover); }
.ctp-select__option[aria-selected="true"] {
  color: var(--ctp-accent);
  font-weight: 600;
  background: var(--ctp-selected);
}
.ctp-select__option:focus-visible { outline: 2px solid var(--ctp-accent); outline-offset: -2px; }

/* the audio element must not be visible but must stay in the DOM - it is
   hidden with the clip technique, so that it never enlarges the document
   (a negative offset would create an overflow in a right-to-left page) */
.ctp__audio {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* fullscreen */
.ctp:fullscreen,
.ctp:-webkit-full-screen {
  max-width: none;
  /* "100vw" contains the scrollbar and would create a horizontal
     scrollbar - the fullscreen box is exactly the screen. */
  width: 100%;
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  --ctp-subs-offset: 70px;
}
.ctp:fullscreen .ctp__stage,
.ctp:-webkit-full-screen .ctp__stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  background: #000;
}
.ctp:fullscreen .ctp__video {
  /* Both video elements stay absolutely positioned - they share the same
     place and only the active one is visible. */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.ctp:fullscreen .ctp__poster { position: absolute; }
.ctp:fullscreen .ctp__controls { position: absolute; }

/* ----------------------------- full page -------------------------------- */

/* The player occupies the whole viewport (container === body).
   "100dvh" follows the dynamic viewport (the mobile browser bars), the
   "100vh" is the fallback for older engines.  The safe-area insets are
   padding, and "box-sizing: border-box" keeps the total size inside the
   viewport - the page itself never has to scroll. */
.ctp--fullpage {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: 100vw;
  max-width: 100dvw;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  /* No frame - not here either. */
  border: 0;
  border-radius: 0;
  outline: none;
  box-shadow: none;
  overflow: hidden;
  /* The player swallows the gestures - the page behind it does not scroll. */
  overscroll-behavior: none;
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}
.ctp--fullpage .ctp__stage {
  height: 100%;
  width: 100%;
  min-height: 0;
}

/* A container without a meaningful size: the player uses the space that is
   left in the viewport and keeps its width - the picture is letterboxed
   inside, the page never has to scroll because of it. */
.ctp--fit-viewport {
  width: 100%;
  max-width: 100vw;
  max-width: 100dvw;
  max-height: 100vh;
  max-height: 100dvh;
  height: var(--ctp-h, 100vh);
  height: var(--ctp-h, 100dvh);
}

/* Fatal error (invalid configuration) - the player refuses to start, but the
   reason has to be visible instead of an empty black box. */
.ctp-fatal {
  padding: 22px 24px;
  border: 1px solid rgba(255, 92, 108, 0.35);
  border-radius: var(--ctp-radius);
  background: linear-gradient(180deg, rgba(255, 92, 108, 0.1), rgba(10, 13, 18, 0.9));
  color: var(--ctp-text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
.ctp-fatal h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
  color: #ff8f99;
}
.ctp-fatal p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ctp-text-dim);
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ------------------------------ info panel ------------------------------- */

.ctp-info {
  margin-top: 14px;
  padding: 16px 18px;
  border: 1px solid var(--ctp-border);
  border-radius: var(--ctp-radius);
  background: linear-gradient(180deg, rgba(21, 27, 36, 0.85), rgba(10, 13, 18, 0.9));
  color: var(--ctp-text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
.ctp-info__title {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.ctp-info__desc {
  margin: 0 0 12px;
  color: var(--ctp-text-dim);
  font-size: 13.5px;
  max-width: 80ch;
}
.ctp-info__meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.ctp-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--ctp-border);
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  color: var(--ctp-text-dim);
  font-variant-numeric: tabular-nums;
}
.ctp-info__toggle {
  border: 0;
  background: none;
  color: var(--ctp-text-dim);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ctp-info__toggle:hover { color: var(--ctp-text); }
.ctp-info__debug {
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--ctp-border);
  color: #9fe8c0;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-x: auto;
}
.ctp-info__debug[hidden] { display: none; }

/* ------------------------------- RTL -------------------------------------
   The main player layout always stays left-to-right: the controls, the icons,
   the progress bar and the volume are never mirrored.  Only the settings
   menu follows the direction of the interface language - inside it the label
   and the current value swap their edges.
   ------------------------------------------------------------------------ */

.ctp-menu__panel[dir="rtl"] {
  text-align: right;
}
/* The navigation icons follow the reading direction: in a right-to-left menu
   the back button points to the right and the submenu chevrons to the left.
   Only these navigation icons are mirrored - the playback controls stay
   untouched. */
.ctp-menu__panel[dir="rtl"] .ctp-menu__back .ctp-icon,
.ctp-menu__panel[dir="rtl"] .ctp-menu__chevron {
  transform: scaleX(-1);
}
/* The header follows the reading direction: the back button ends up on the
   right (it points to the right as well), the close button on the left and
   the title is aligned to the right edge of the panel. */
.ctp-menu__panel[dir="rtl"] .ctp-menu__header {
  flex-direction: row;
  justify-content: flex-start;
}
.ctp-menu__panel[dir="rtl"] .ctp-menu__header-title {
  flex: 1 1 auto;
  text-align: right;
}
.ctp-menu__panel[dir="rtl"] .ctp-menu__item {
  text-align: right;
}
.ctp-menu__panel[dir="rtl"] .ctp-menu__item--nav,
.ctp-menu__panel[dir="rtl"] .ctp-menu__item--role {
  /* The label moves to the right edge, the value to the left one. */
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.ctp-menu__panel[dir="rtl"] .ctp-menu__check {
  margin-inline-start: auto;
  margin-inline-end: 0;
}
.ctp-menu__panel[dir="rtl"] .ctp-menu__form__row {
  flex-direction: row-reverse;
  justify-content: space-between;
}

/* ------------------------------ responsive ------------------------------- */

@media (max-width: 720px) {
  /* The subtitle offset follows the smaller control row (see the :root
     definition): padding-bottom 8px + 40px bar = 48px to clear. */
  :root { --ctp-radius: 10px; --ctp-ctl-h: 40px; --ctp-subs-offset: 50px; }
  .ctp__time { font-size: 11.5px; padding: 0 4px; }
  .ctp-btn { width: 40px; height: 40px; }
  .ctp-menu__toggle { padding: 0 6px; font-size: 12px; }
  .ctp__volume-slider { width: 64px; }
  .ctp__bigplay { width: 62px; height: 62px; }
  .ctp__center-btn { width: 44px; height: 44px; }
  .ctp__center { gap: 14px; }
  .ctp__replay { width: 76px; height: 76px; }
  .ctp__replay .ctp-icon { width: 34px; height: 34px; }
  .ctp__sub { font-size: calc(var(--ctp-sub-font-size, 24px) * 0.8); }
  .ctp-btn--live { height: 24px; padding: 0 8px; font-size: 10px; }
}

@media (max-width: 560px) {
  .ctp__time-dur,
  .ctp__time-sep { display: none; }
  .ctp-btn--seek { display: none; }
  .ctp-menu__label { display: none; }
  .ctp__volume:hover .ctp__volume-slider,
  .ctp__volume:focus-within .ctp__volume-slider { width: 56px; }
  .ctp-btn--live { height: 23px; padding: 0 7px; font-size: 9.5px; gap: 5px; }
}

/* Very narrow screens: the secondary controls move into the settings menu
   so that the bar never overflows. */
@media (max-width: 440px) {
  .ctp__volume-slider { display: none; }
  .ctp-menu--speed,
  .ctp-btn--pip { display: none; }
  .ctp-btn { width: 38px; height: 38px; }
  .ctp__center { gap: 10px; }
  .ctp__center-btn { width: 40px; height: 40px; }
}

/* --------------------------- reduced motion ------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .ctp *,
  .ctp *::before,
  .ctp *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .ctp__spinner .ctp-icon { animation: none; }
  .ctp__seek-fb.is-active { animation: none; opacity: 1; }
}
