/* ==========================================================================
   Audio Player — "ฟังบทความนี้" (Listen to this article)
   Component for The Reader by Praphansarn — content.php
   ========================================================================== */

.apw {
  --apw-navy: #102150;
  --apw-navy-deep: #0b1638;
  --apw-wine: #b3395a;
  --apw-wine-deep: #8f2c47;
  --apw-line: rgba(255, 255, 255, 0.16);
  --apw-text: #ffffff;
  --apw-text-muted: rgba(255, 255, 255, 0.62);
  --apw-radius: 18px;
  --apw-fill: 0%;

  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 28px 0 34px;
  padding: 16px 22px 16px 16px;
  border-radius: var(--apw-radius);
  background: linear-gradient(155deg, var(--apw-navy) 0%, var(--apw-navy-deep) 100%);
  color: var(--apw-text);
  font-family: "Sarabun", "Noto Sans Thai", -apple-system, BlinkMacSystemFont, sans-serif;
  overflow: hidden;
}

/* faint decorative bars in the background, right side — purely visual, low-key */
.apw::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 100% 120%, rgba(179, 57, 90, 0.35), transparent 55%);
}

/* ---------- Play button ---------- */
.apw__play {
  position: relative;
  flex: none;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--apw-wine);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 1;
  transition: transform 0.15s ease, background 0.15s ease;
}

.apw__play:hover {
  background: var(--apw-wine-deep);
}

.apw__play:active {
  transform: scale(0.94);
}

.apw__play:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.apw__play .apw__icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.apw__icon--pause {
  display: none;
}

.apw.is-playing .apw__icon--play {
  display: none;
}

.apw.is-playing .apw__icon--pause {
  display: block;
}

/* pulsing ring while playing */
.apw__play::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid var(--apw-wine);
  opacity: 0;
}

.apw.is-playing .apw__play::before {
  animation: apw-pulse 1.8s ease-out infinite;
}

@keyframes apw-pulse {
  0% {
    opacity: 0.55;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

/* ---------- Main column ---------- */
.apw__main {
  flex: 1 1 auto;
  min-width: 0;
  z-index: 1;
}

.apw__row {
  display: flex;
  align-items: center;
}

.apw__row--top {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.apw__label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.apw__label::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--apw-wine);
  vertical-align: middle;
}

/* eq bars replace the dot while playing */
.apw__eq {
  display: none;
  align-items: flex-end;
  gap: 2px;
  width: 14px;
  height: 12px;
  margin-right: 8px;
  vertical-align: middle;
}

.apw.is-playing .apw__label::before {
  display: none;
}

.apw.is-playing .apw__eq {
  display: inline-flex;
}

.apw__eq span {
  display: block;
  width: 3px;
  background: var(--apw-wine);
  border-radius: 1px;
  animation: apw-eq 0.9s ease-in-out infinite;
}

.apw__eq span:nth-child(1) {
  height: 40%;
  animation-delay: -0.6s;
}
.apw__eq span:nth-child(2) {
  height: 100%;
  animation-delay: -0.2s;
}
.apw__eq span:nth-child(3) {
  height: 65%;
  animation-delay: -0.8s;
}
.apw__eq span:nth-child(4) {
  height: 85%;
  animation-delay: -0.35s;
}

@keyframes apw-eq {
  0%, 100% { transform: scaleY(0.35); }
  50% { transform: scaleY(1); }
}

.apw__speed {
  flex: none;
  border: 1px solid var(--apw-line);
  background: transparent;
  color: var(--apw-text);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.apw__speed:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.32);
}

.apw__speed:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ---------- Track row ---------- */
.apw__row--track {
  gap: 8px;
}

.apw__skip {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--apw-line);
  background: transparent;
  color: var(--apw-text-muted);
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.apw__skip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.apw__skip:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.apw__track {
  position: relative;
  flex: 1 1 auto;
  height: 28px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.apw__track-bg {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.apw__track-fill {
  position: absolute;
  left: 0;
  height: 4px;
  width: var(--apw-fill);
  border-radius: 999px;
  background: var(--apw-wine);
}

.apw__track-handle {
  position: absolute;
  left: var(--apw-fill);
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease;
}

.apw__track:hover .apw__track-handle,
.apw__track:focus-visible .apw__track-handle {
  transform: scale(1.15);
}

.apw__track:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 4px;
  border-radius: 999px;
}

/* ---------- Time row ---------- */
.apw__row--time {
  justify-content: space-between;
  margin-top: 4px;
  padding: 0 38px; /* align under track, inside the skip-button gutters */
}

.apw__row--time span {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--apw-text-muted);
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .apw__play::before,
  .apw__eq span {
    animation: none !important;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .apw {
    gap: 14px;
    padding: 14px 16px 14px 14px;
    margin: 22px 0 28px;
  }

  .apw__play {
    width: 46px;
    height: 46px;
  }

  .apw__play .apw__icon {
    width: 17px;
    height: 17px;
  }

  .apw__label {
    font-size: 13px;
  }

  .apw__row--time {
    padding: 0 36px;
  }
}

@media (max-width: 380px) {
  .apw__speed {
    padding: 5px 9px;
    font-size: 11.5px;
  }
}
