/*
 * MedexPrep — Audio Lectures player styles
 * Scoped under .medexp-scope so it cannot leak. Uses CSS variables for tint,
 * which are set inline on the .medexp-audio-section element by the PHP render.
 */

.medexp-scope .medexp-audio-section {
  --mxp-player-tint-from: #0b4a6f;
  --mxp-player-tint-to:   #0891b2;
  --mxp-player-ink:       #0f172a;
  --mxp-player-muted:     #64748b;
  --mxp-player-border:    #e5e7eb;
  --mxp-player-bg:        #ffffff;
  --mxp-player-bg-soft:   #f8fafc;

  margin: 0 0 24px 0;
  padding: 0;
}

.medexp-scope .medexp-audio-wrap {
  background: var(--mxp-player-bg);
  border: 1px solid var(--mxp-player-border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 6px 20px rgba(15,23,42,.06);
  position: relative;
}

/* Head row */
.medexp-scope .mxp-audio-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.medexp-scope .mxp-audio-icon {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, var(--mxp-player-tint-from) 0%, var(--mxp-player-tint-to) 100%);
}
.medexp-scope .mxp-audio-head-text {
  flex: 1 1 auto;
  min-width: 0;
}
.medexp-scope .mxp-audio-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--mxp-player-tint-from);
  margin-bottom: 2px;
}
.medexp-scope .mxp-audio-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--mxp-player-ink);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.medexp-scope .mxp-audio-sub {
  font-size: 12px;
  color: var(--mxp-player-muted);
  margin-top: 2px;
}
.medexp-scope .mxp-audio-sep {
  opacity: .5;
  margin: 0 6px;
}

/* Progress */
.medexp-scope .mxp-audio-progress {
  position: relative;
  height: 8px;
  border-radius: 99px;
  background: #eef2f7;
  margin: 10px 0;
  cursor: pointer;
  outline: none;
}
.medexp-scope .mxp-audio-progress-buf {
  position: absolute;
  inset: 0;
  width: 0%;
  background: #d5dbe3;
  border-radius: 99px;
}
.medexp-scope .mxp-audio-progress-fill {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--mxp-player-tint-from), var(--mxp-player-tint-to));
  transition: width .08s linear;
}
.medexp-scope .mxp-audio-progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 14px; height: 14px;
  border-radius: 99px;
  background: #fff;
  border: 2px solid var(--mxp-player-tint-from);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
  pointer-events: none;
}

/* Controls row */
.medexp-scope .mxp-audio-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.medexp-scope .mxp-audio-times {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--mxp-player-muted);
  min-width: 84px;
}
.medexp-scope .mxp-audio-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}
.medexp-scope .mxp-audio-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--mxp-player-border);
  background: var(--mxp-player-bg-soft);
  color: var(--mxp-player-ink);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, border-color .15s ease, transform .08s ease;
  min-height: 36px;
  min-width: 36px;
  font-size: 13px;
  font-weight: 600;
}
.medexp-scope .mxp-audio-btn:hover { background: #eef2f7; }
.medexp-scope .mxp-audio-btn:active { transform: translateY(1px); }
.medexp-scope .mxp-audio-btn:focus-visible { outline: 2px solid var(--mxp-player-tint-to); outline-offset: 2px; }

.medexp-scope .mxp-audio-btn--play {
  width: 48px; height: 48px;
  border-radius: 99px;
  background: linear-gradient(135deg, var(--mxp-player-tint-from) 0%, var(--mxp-player-tint-to) 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px rgba(8, 145, 178, .35);
}
.medexp-scope .mxp-audio-btn--play:hover { filter: brightness(1.05); }

.medexp-scope .mxp-audio-btn--speed {
  font-variant-numeric: tabular-nums;
  min-width: 52px;
}

.medexp-scope .mxp-audio-btn--icon {
  padding: 6px 8px;
  min-height: 32px;
  min-width: 32px;
  background: transparent;
  border-color: transparent;
  color: var(--mxp-player-muted);
}
.medexp-scope .mxp-audio-btn--icon:hover {
  background: var(--mxp-player-bg-soft);
  color: var(--mxp-player-ink);
  border-color: var(--mxp-player-border);
}

/* Overall progress (tiny bar under controls) */
.medexp-scope .mxp-audio-overall {
  margin-top: 12px;
  height: 4px;
  border-radius: 99px;
  background: #eef2f7;
  overflow: hidden;
}
.medexp-scope .mxp-audio-overall-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--mxp-player-tint-from), var(--mxp-player-tint-to));
  opacity: .8;
  transition: width .2s ease;
}

/* Chapters drawer */
.medexp-scope .mxp-audio-chapters {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--mxp-player-border);
}
.medexp-scope .mxp-audio-chapters[hidden] { display: none; }
.medexp-scope .mxp-audio-chapters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--mxp-player-ink);
  margin-bottom: 8px;
}
.medexp-scope .mxp-audio-muted { color: var(--mxp-player-muted); font-weight: 500; }

.medexp-scope .mxp-audio-chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}
.medexp-scope .mxp-audio-chapter {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--mxp-player-border);
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
  transition: background .12s ease, border-color .12s ease;
}
.medexp-scope .mxp-audio-chapter:hover { background: var(--mxp-player-bg-soft); }
.medexp-scope .mxp-audio-chapter.is-active {
  border-color: var(--mxp-player-tint-to);
  background: linear-gradient(90deg, rgba(8,145,178,.06), rgba(8,145,178,0));
}
.medexp-scope .mxp-audio-chapter.is-done .mxp-audio-chapter__num {
  background: #10b981;
  color: #fff;
  border-color: #10b981;
}
.medexp-scope .mxp-audio-chapter__num {
  width: 26px; height: 26px;
  border-radius: 99px;
  border: 1px solid var(--mxp-player-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: var(--mxp-player-tint-from);
  background: var(--mxp-player-bg-soft);
}
.medexp-scope .mxp-audio-chapter.is-active .mxp-audio-chapter__num {
  background: linear-gradient(135deg, var(--mxp-player-tint-from), var(--mxp-player-tint-to));
  color: #fff;
  border-color: transparent;
}
.medexp-scope .mxp-audio-chapter__label {
  font-size: 13px;
  color: var(--mxp-player-ink);
  line-height: 1.35;
}
.medexp-scope .mxp-audio-chapter__meta {
  font-size: 11px;
  color: var(--mxp-player-muted);
}

/* Responsive */
@media (max-width: 560px) {
  .medexp-scope .mxp-audio-wrap { padding: 12px 14px; }
  .medexp-scope .mxp-audio-times { order: 3; width: 100%; text-align: center; }
  .medexp-scope .mxp-audio-controls { justify-content: center; }
}

/* -----------------------------------------------------------------------
 * Mini floating player (CAIDRA-style sticky bar)
 * Lives OUTSIDE .medexp-scope (appended to <body>), so selectors are
 * un-scoped. Tint variables are injected inline via JS from the main
 * player's computed style, with sane fallbacks.
 * ---------------------------------------------------------------------*/
.mxp-mini-player {
  --mxp-player-tint-from: #0b4a6f;
  --mxp-player-tint-to:   #0891b2;

  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  transform: translate(-50%, calc(100% + 40px));
  width: min(860px, calc(100vw - 24px));
  z-index: 9998;

  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.22), 0 2px 8px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #0f172a;
}
.mxp-mini-player.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}
.mxp-mini-player__progress {
  height: 4px;
  background: rgba(15, 23, 42, 0.08);
  cursor: pointer;
  position: relative;
  outline: none;
}
.mxp-mini-player__progress:focus-visible {
  outline: 2px solid var(--mxp-player-tint-to);
  outline-offset: -2px;
}
.mxp-mini-player__progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg,
    var(--mxp-player-tint-from),
    var(--mxp-player-tint-to));
  transition: width 120ms linear;
}
.mxp-mini-player__inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.mxp-mini-player__play {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg,
    var(--mxp-player-tint-from),
    var(--mxp-player-tint-to));
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(11, 74, 111, 0.28);
  transition: transform 140ms ease, box-shadow 140ms ease;
}
.mxp-mini-player__play:hover  { transform: scale(1.06); }
.mxp-mini-player__play:active { transform: scale(0.97); }
.mxp-mini-player__text {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font: inherit;
  color: inherit;
}
.mxp-mini-player__title {
  font-weight: 600;
  font-size: 14px;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.mxp-mini-player__meta {
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mxp-mini-player__actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
}
.mxp-mini-player__btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: #334155;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, color 150ms ease;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 0;
}
.mxp-mini-player__btn:hover { background: rgba(15, 23, 42, 0.06); }
.mxp-mini-player__speed {
  min-width: 44px;
  color: var(--mxp-player-tint-to);
}
.mxp-mini-player__close { color: #94a3b8; }
.mxp-mini-player__close:hover { color: #0f172a; background: rgba(15, 23, 42, 0.08); }

@media (max-width: 640px) {
  .mxp-mini-player {
    width: calc(100vw - 16px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    border-radius: 12px;
  }
  .mxp-mini-player__inner { padding: 8px 10px; gap: 10px; }
  .mxp-mini-player__play { width: 38px; height: 38px; }
  .mxp-mini-player__btn { width: 34px; height: 34px; }
  .mxp-mini-player__speed { min-width: 40px; }
  /* Hide prev on very small — keep play, next, speed, close */
  .mxp-mini-player__btn[data-role="mini-prev"] { display: none; }
}
@media (max-width: 420px) {
  .mxp-mini-player__btn[data-role="mini-speed"] { display: none; }
  .mxp-mini-player__meta { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .mxp-mini-player { transition: opacity 200ms ease; }
  .mxp-mini-player__progress-fill { transition: none; }
}

/* -----------------------------------------------------------------------
 * NOW PLAYING section highlighting
 * When the audio player is narrating a section, the JS adds
 * .mxp-now-playing to the matching section.medexp-card element.
 * This gives it a glowing outline, gradient pill, and bobbing arrow —
 * the same visual language as the edu-core tutor player.
 * ---------------------------------------------------------------------*/
.mxp-now-playing {
  --mxp-narr-color: var(--mxp-player-tint-from, #0b4a6f);
  outline: 3px solid var(--mxp-narr-color) !important;
  outline-offset: 8px;
  border-radius: 14px !important;
  position: relative;
  scroll-margin-top: 120px;
  animation: mxp-section-pulse 2.2s ease-in-out infinite;
  overflow: visible !important;
  z-index: 1;
}
/* ▶ NOW PLAYING pill */
.mxp-now-playing::before {
  content: "\25B6  NOW PLAYING";
  position: absolute;
  top: -14px;
  left: 18px;
  background: linear-gradient(135deg, var(--mxp-narr-color), var(--mxp-player-tint-to, #0891b2));
  color: #fff !important;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .10em;
  padding: 5px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(8, 145, 178, .42);
  z-index: 5;
  pointer-events: none;
  white-space: nowrap;
  line-height: 1;
  animation: mxp-pill-glow 2.2s ease-in-out infinite;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-transform: none;
  display: inline-block;
}
/* Bobbing arrow indicator */
.mxp-now-playing::after {
  content: "";
  position: absolute;
  left: -30px;
  top: 50%;
  width: 18px;
  height: 18px;
  background: var(--mxp-narr-color);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  transform: translateY(-50%);
  animation: mxp-arrow-bob 1.1s ease-in-out infinite;
  z-index: 3;
}

@keyframes mxp-section-pulse {
  0%, 100% {
    outline-color: var(--mxp-narr-color);
    box-shadow: 0 0 0 0 rgba(8, 145, 178, .45);
  }
  50% {
    outline-color: var(--mxp-player-tint-to, #0891b2);
    box-shadow: 0 0 0 12px rgba(8, 145, 178, 0);
  }
}
@keyframes mxp-pill-glow {
  0%, 100% { box-shadow: 0 4px 12px rgba(8, 145, 178, .42); }
  50%      { box-shadow: 0 4px 24px rgba(8, 145, 178, .85); }
}
@keyframes mxp-arrow-bob {
  0%, 100% { transform: translateY(-50%) translateX(0); }
  50%      { transform: translateY(-50%) translateX(4px); }
}

/* -----------------------------------------------------------------------
 * Per-section mini play pills ("▶ 0:33")
 * Injected by JS into each .medexp-card header area. Click jumps the
 * main player to the matching part and starts playback.
 * Matches the edu-core "▶ 0:33" pill button style.
 * ---------------------------------------------------------------------*/
.mxp-play-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #fff;
  border: 1px solid var(--mxp-player-tint-from, #0b4a6f);
  border-radius: 999px;
  padding: 4px 12px 4px 10px;
  cursor: pointer;
  transition: all .15s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--mxp-player-tint-from, #0b4a6f);
  white-space: nowrap;
  line-height: 1;
  vertical-align: middle;
  position: relative;
  z-index: 2;
  text-decoration: none !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.mxp-play-pill:hover {
  background: var(--mxp-player-tint-from, #0b4a6f);
  color: #fff;
  box-shadow: 0 2px 8px rgba(8,145,178,.25);
  transform: translateY(-1px);
}
.mxp-play-pill:active {
  transform: translateY(0);
}
.mxp-play-pill svg {
  width: 10px;
  height: 10px;
  fill: currentColor;
  flex-shrink: 0;
}
/* Active state — currently playing this part */
.mxp-play-pill.is-active {
  background: linear-gradient(135deg, var(--mxp-player-tint-from, #0b4a6f), var(--mxp-player-tint-to, #0891b2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(8,145,178,.35);
  animation: mxp-pill-glow 2.2s ease-in-out infinite;
}
/* Equalizer bars for active playing state */
.mxp-play-pill__eq {
  display: none;
  gap: 2px;
  align-items: flex-end;
  height: 10px;
  flex-shrink: 0;
}
.mxp-play-pill.is-active .mxp-play-pill__eq {
  display: inline-flex;
}
.mxp-play-pill.is-active svg {
  display: none;
}
.mxp-play-pill__eq span {
  display: block;
  width: 2px;
  border-radius: 1px;
  background: rgba(255,255,255,.8);
}
.mxp-play-pill__eq span:nth-child(1) { height: 60%; animation: mxp-eq .85s ease-in-out infinite; animation-delay: 0s; }
.mxp-play-pill__eq span:nth-child(2) { height: 100%; animation: mxp-eq .85s ease-in-out infinite; animation-delay: .2s; }
.mxp-play-pill__eq span:nth-child(3) { height: 80%; animation: mxp-eq .85s ease-in-out infinite; animation-delay: .4s; }
@keyframes mxp-eq {
  0%, 100% { transform: scaleY(.4); }
  50%      { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .mxp-now-playing,
  .mxp-now-playing::before,
  .mxp-now-playing::after,
  .mxp-section-listen__eq span {
    animation: none !important;
  }
}

@media (prefers-color-scheme: dark) {
  .mxp-mini-player {
    background: #0f172a;
    color: #e2e8f0;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.25);
  }
  .mxp-mini-player__title { color: #f1f5f9; }
  .mxp-mini-player__meta  { color: #94a3b8; }
  .mxp-mini-player__btn   { color: #cbd5e1; }
  .mxp-mini-player__btn:hover { background: rgba(255, 255, 255, 0.08); }
  .mxp-mini-player__close { color: #64748b; }
  .mxp-mini-player__progress { background: rgba(255, 255, 255, 0.12); }
}
