/* ==========================================================================
   Audio Modal
   Shared, callable audio player. See js/audio-modal.js for how to add one
   to a page, and for the logo/icon/artwork sources.

   ========================================================================
   CONFIGURE HERE
   Colors and every size that shapes the player live in this custom
   property block. Change a value here and it applies wherever the audio
   modal is used, no per-article CSS required.
   ========================================================================== */

.audio-modal {
  /* colors */
  --am-bg: #141414;
  --am-border: #2a2a2a;
  --am-accent: #F5A623;
  --am-text: #ffffff;
  --am-muted: #8a8a8a;
  --am-track: rgba(255, 255, 255, 0.85);
  --am-menu-bg: #1c1c1c;

  /* sizing */
  --am-radius: 6px;
  --am-padding: 28px 32px;
  --am-art-size: 148px;
  --am-play-size: 52px;
  --am-icon-size: 27px;

  /* the player is a wide banner; it steps outside the article's text
     column by this much on wide screens (see the breakpoints below) */
  --am-breakout-md: 100px;
  --am-breakout-lg: 180px;
}

/* ==========================================================================
   Structure. Shouldn't need to change for a logo/color/size update, only
   for a layout change.
   ========================================================================== */

.audio-modal {
  background: var(--am-bg);
  border: 1px solid var(--am-border);
  border-radius: var(--am-radius);
  padding: var(--am-padding);
  margin: 0 0 48px;
}

/* The three columns live on .audio-modal-ui, not on .audio-modal. The JS
   builds the UI inside that wrapper so the not-ready guard below can hide
   the whole thing in one rule, which means the wrapper is what has to carry
   the grid. Putting the grid on .audio-modal instead would make the wrapper
   its only child and the columns would stack. */
.audio-modal-ui {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 28px;
  align-items: center;
}

@media (min-width: 900px) {
  .audio-modal { margin-left: calc(-1 * var(--am-breakout-md)); margin-right: calc(-1 * var(--am-breakout-md)); }
}
@media (min-width: 1040px) {
  .audio-modal { margin-left: calc(-1 * var(--am-breakout-lg)); margin-right: calc(-1 * var(--am-breakout-lg)); }
}

/* Before JS runs, only the placeholder's native <audio> exists in the DOM.
   Once js/audio-modal.js builds the rest of the UI it marks the root
   data-audio-modal-ready and this swaps which one is visible. If the
   script fails to load, the native player stays up and stays usable. */
.audio-modal:not([data-audio-modal-ready]) .audio-modal-audio { display: block; width: 100%; }
.audio-modal[data-audio-modal-ready] .audio-modal-audio { display: none; }
/* Guards the case where build() throws partway through (e.g. an unexpected
   DOM shape) and .audio-modal-ui exists but wire() never ran to attach
   working handlers to it. Without this, a half-wired UI could be visible
   with dead buttons instead of falling back to the native controls. */
.audio-modal:not([data-audio-modal-ready]) .audio-modal-ui { display: none; }

/* ---------- artwork + play ---------- */

.audio-modal-art {
  position: relative;
  width: var(--am-art-size);
  height: var(--am-art-size);
  flex-shrink: 0;
}
.audio-modal-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

.audio-modal-play {
  position: absolute;
  right: -10px;
  bottom: -6px;
  width: var(--am-play-size);
  height: var(--am-play-size);
  border: 0;
  border-radius: 50%;
  background: var(--am-accent);
  color: #0a0a0a;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}
.audio-modal-play:hover { transform: scale(1.06); }
.audio-modal-play svg { width: 38%; height: 38%; display: block; }
/* Qualified with .audio-modal-play so this outweighs the generic
   ".audio-modal-play svg { display: block }" sizing rule above, which has
   equal specificity to an unqualified ".audio-modal-icon-pause" and would
   otherwise win regardless of source order. */
.audio-modal-play .audio-modal-icon-pause { display: none; }
.audio-modal[data-audio-modal-playing] .audio-modal-play .audio-modal-icon-play { display: none; }
.audio-modal[data-audio-modal-playing] .audio-modal-play .audio-modal-icon-pause { display: block; }

/* ---------- centre column ---------- */

.audio-modal-main { min-width: 0; }

.audio-modal-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--am-accent);
  margin-bottom: 10px;
}

/* Dynamic title. Scales with the container and clamps to two lines so a
   long headline never pushes the card out of shape. */
.audio-modal-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(24px, 2.6vw, 38px);
  line-height: 1.04;
  letter-spacing: 0.02em;
  color: var(--am-text);
  margin: 0 0 18px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- scrubber ---------- */

.audio-modal-scrub {
  position: relative;
  height: 16px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}
.audio-modal-scrub-rail {
  position: relative;
  width: 100%;
  height: 3px;
  background: var(--am-track);
  border-radius: 2px;
  overflow: hidden;
}
.audio-modal-scrub-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--am-accent);
}
.audio-modal-scrub:focus-visible {
  outline: 2px solid var(--am-accent);
  outline-offset: 4px;
  border-radius: 2px;
}

/* ---------- right column ---------- */

.audio-modal-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  align-self: stretch;
}

.audio-modal-brandrow { display: flex; align-items: flex-start; gap: 14px; }

.audio-modal-brand { display: flex; align-items: center; gap: 9px; }
.audio-modal-brand-mark { width: 25px; height: auto; flex-shrink: 0; display: block; }
.audio-modal-brand-text { line-height: 1; }
.audio-modal-brand-name { display: block; height: 19px; width: auto; }
.audio-modal-brand-sub {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--am-accent);
  display: block;
  margin-top: 3px;
}

/* ---------- transport ---------- */

.audio-modal-controls { display: flex; align-items: center; gap: 16px; }

.audio-modal-btn {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--am-text);
  display: grid;
  place-items: center;
  transition: color 0.15s ease;
}
.audio-modal-btn:hover { color: var(--am-accent); }
.audio-modal-btn svg { width: var(--am-icon-size); height: var(--am-icon-size); display: block; }

.audio-modal-speed {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 21px;
  letter-spacing: 0.04em;
  min-width: 34px;
  text-align: center;
}

.audio-modal-metarow { display: flex; align-items: center; gap: 14px; }
.audio-modal-time {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 20px;
  letter-spacing: 0.05em;
  color: var(--am-accent);
  font-variant-numeric: tabular-nums;
}
/* Same specificity fix as the play/pause icons above. */
.audio-modal-vol .audio-modal-icon-muted { display: none; }
.audio-modal[data-audio-modal-muted] .audio-modal-vol .audio-modal-icon-loud { display: none; }
.audio-modal[data-audio-modal-muted] .audio-modal-vol .audio-modal-icon-muted { display: block; }

/* ---------- overflow menu ---------- */

.audio-modal-menu-wrap { position: relative; }
.audio-modal-menu-btn svg { width: 20px; height: 20px; }
.audio-modal-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 176px;
  background: var(--am-menu-bg);
  border: 1px solid var(--am-border);
  border-radius: 4px;
  padding: 6px;
  z-index: 20;
  display: none;
}
.audio-modal-menu[data-open] { display: block; }
.audio-modal-menu a {
  display: block;
  padding: 9px 12px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  border-radius: 3px;
}
.audio-modal-menu a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .audio-modal { padding: 20px; }
  .audio-modal-ui {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 20px;
    row-gap: 22px;
  }
  .audio-modal-art { width: 88px; height: 88px; }
  .audio-modal-play { width: 40px; height: 40px; right: -8px; }
  .audio-modal-side {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
  }
  .audio-modal-brandrow { order: 2; }
  .audio-modal-controls { order: 1; }
  .audio-modal-metarow { order: 3; }
}

@media (max-width: 520px) {
  .audio-modal-title { font-size: 22px; margin-bottom: 14px; }
  .audio-modal-eyebrow { font-size: 10px; margin-bottom: 8px; }
  .audio-modal-brand-name { height: 16px; }
  .audio-modal-brand-mark { width: 21px; }
  .audio-modal-controls { gap: 12px; }
  .audio-modal-btn svg { width: 24px; height: 24px; }
  .audio-modal-side { row-gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .audio-modal-play, .audio-modal-btn { transition: none; }
  .audio-modal-play:hover { transform: none; }
}
