/*
 * Community audio: the feed player and the composer's recorder panel
 * (static/js/community-audio.js). Desktop and phone share it.
 *
 * Colours come from whatever surface the player sits on: the phone room's
 * --room-*, the desktop chat's --chat-*, the page colours, then the theme.
 * The phone's light theme paints every leaf black with !important
 * ([data-theme=light] * * *), so the text rules carry an id through :is()
 * to outrank it, and icons draw with fill/stroke, which that sweep leaves be.
 */

.ca-player, .ca-rec {
  --ca-ink: var(--room-fg, var(--chat-ink, var(--pc-ink, #0e0e0e)));
  --ca-on: var(--room-bg, var(--chat, var(--pc-page, #ffffff)));
  --ca-track: color-mix(in srgb, var(--ca-ink) 22%, transparent);
  --ca-fill: color-mix(in srgb, var(--ca-ink) 5%, transparent);
  --ca-rim: color-mix(in srgb, var(--ca-ink) 12%, transparent);
  --ca-quiet: color-mix(in srgb, var(--ca-ink) 58%, transparent);
  --ca-rec: #e5484d;
}
:root[data-theme="dark"] .ca-player, :root[data-theme="dark"] .ca-rec {
  --ca-ink: var(--room-fg, var(--chat-ink, var(--pc-ink, #f4f4f4)));
  --ca-on: var(--room-bg, var(--chat, var(--pc-page, #0e0e0e)));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ca-player, :root:not([data-theme="light"]) .ca-rec {
    --ca-ink: var(--room-fg, var(--chat-ink, var(--pc-ink, #f4f4f4)));
    --ca-on: var(--room-bg, var(--chat, var(--pc-page, #0e0e0e)));
  }
}

/* ------------------------------------------------------------- player */

.ca-wrap { margin: 10px 0 2px; max-width: 460px; }
.ca-player {
  --p: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 460px;
  box-sizing: border-box;
  padding: 10px 14px 10px 10px;
  border-radius: 999px;
  background: var(--ca-fill);
  box-shadow: inset 0 0 0 1px var(--ca-rim);
  font-family: var(--mono, ui-monospace, "SF Mono", Menlo, monospace);
  -webkit-user-select: none;
  user-select: none;
  touch-action: pan-y;
  cursor: default;
}
.ca-player.is-file { border-radius: 18px; }
.ca-player .ca-play {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 0 !important;
  border-radius: 50% !important;
  background: var(--ca-ink) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  cursor: pointer;
  transition: transform .15s ease;
}
.ca-player .ca-play:active { transform: scale(.92); }
.ca-player .ca-play:focus-visible, .ca-player .ca-wave:focus-visible { outline: 2px solid var(--ca-ink); outline-offset: 3px; }
.ca-player .ca-i { width: 18px; height: 18px; fill: var(--ca-on) !important; stroke: none !important; }
.ca-player .ca-i--play { margin-left: 2px; }
.ca-player .ca-i--pause, .ca-player.is-playing .ca-i--play { display: none; }
.ca-player.is-playing .ca-i--pause { display: block; }
.ca-player.is-loading .ca-play { animation: ca-pulse 1s ease-in-out infinite; }
@keyframes ca-pulse { 50% { opacity: .55; } }

.ca-player .ca-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ca-player .ca-name { display: flex; align-items: center; gap: 6px; min-width: 0; font: 600 12px/1.2 var(--read, system-ui, sans-serif); }
.ca-player .ca-name svg { flex: 0 0 auto; width: 13px; height: 13px; fill: none !important; stroke: var(--ca-quiet) !important; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ca-player .ca-name span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.ca-player .ca-wave { position: relative; height: 30px; cursor: pointer; touch-action: none; border-radius: 6px; }
.ca-player .ca-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  pointer-events: none;
}
.ca-player .ca-bars i {
  flex: 1 1 0;
  min-width: 2px;
  max-width: 5px;
  height: calc(var(--h, .5) * 100%);
  border-radius: 3px;
  background: var(--ca-track) !important;
  font-style: normal;
}
.ca-player .ca-bars--on { clip-path: inset(0 calc(100% - var(--p) * 100%) 0 0); }
.ca-player .ca-bars--on i { background: var(--ca-ink) !important; }
.ca-player.is-scrubbing .ca-bars--on { transition: none; }

.ca-player .ca-time { flex: 0 0 auto; display: flex; gap: 6px; font-size: 12px; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.ca-player .ca-cur { display: none; }
.ca-player.is-active .ca-cur { display: inline; }
.ca-player.is-active .ca-cur::after { content: " /"; opacity: .5; }

/* Text colours, above the phone's light-theme leaf sweep. */
html :is(#ca-scope, body) .ca-player .ca-time,
html :is(#ca-scope, body) .ca-player .ca-time *,
html :is(#ca-scope, body) .ca-player .ca-name,
html :is(#ca-scope, body) .ca-player .ca-name * {
  color: var(--ca-ink) !important;
  -webkit-text-fill-color: var(--ca-ink) !important;
}
html :is(#ca-scope, body) .ca-player .ca-dur { color: var(--ca-quiet) !important; -webkit-text-fill-color: var(--ca-quiet) !important; }
html :is(#ca-scope, body) .ca-player.is-active .ca-dur { color: var(--ca-quiet) !important; -webkit-text-fill-color: var(--ca-quiet) !important; }

/* Phone room cards and timeline rows */
.crc .ca-wrap, .fp-tl .ca-wrap { margin: 8px 0 4px; }

/* ------------------------------------------------------------- recorder */

.ca-rec {
  box-sizing: border-box;
  margin: 10px 0;
  padding: 14px;
  border-radius: 18px;
  background: var(--ca-fill);
  box-shadow: inset 0 0 0 1px var(--ca-rim);
  font-family: var(--read, system-ui, -apple-system, sans-serif);
  animation: ca-rise .18s ease-out;
}
.ca-rec[hidden] { display: none !important; }
@keyframes ca-rise { from { opacity: 0; transform: translateY(4px); } }
.ca-rec__head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.ca-rec__title { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.ca-rec__sub { font: 12px var(--mono, ui-monospace, monospace); }
.ca-rec__x {
  margin-left: auto; align-self: center;
  display: grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  border: 0 !important; border-radius: 50% !important;
  background: transparent !important; box-shadow: none !important;
  backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
  cursor: pointer;
}
.ca-rec__x svg { width: 16px; height: 16px; fill: none !important; stroke: var(--ca-ink) !important; stroke-width: 2; stroke-linecap: round; }
.ca-rec__x:hover { background: var(--ca-rim) !important; }

.ca-rec__choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .ca-rec__choices { grid-template-columns: 1fr; } }
.ca-rec__choice {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 12px 14px; margin: 0;
  border: 0 !important; border-radius: 14px !important;
  background: var(--ca-on) !important;
  box-shadow: inset 0 0 0 1px var(--ca-rim) !important;
  backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
  text-align: left; cursor: pointer;
  transition: box-shadow .15s ease, transform .15s ease;
}
.ca-rec__choice:hover { box-shadow: inset 0 0 0 1.5px var(--ca-ink) !important; }
.ca-rec__choice:active { transform: scale(.98); }
.ca-rec__choice > svg { flex: 0 0 auto; width: 22px; height: 22px; fill: none !important; stroke: var(--ca-ink) !important; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ca-rec__choice span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ca-rec__choice b { font-size: 14px; font-weight: 700; }
.ca-rec__choice small { font-size: 12px; }

.ca-rec__dot { flex: 0 0 auto; width: 14px; height: 14px; border-radius: 50%; background: var(--ca-rec) !important; box-shadow: 0 0 0 4px color-mix(in srgb, var(--ca-rec) 22%, transparent); }
.ca-rec__dot.is-idle { opacity: .45; box-shadow: none; }
.ca-rec__dot.is-live { animation: ca-beat 1.1s ease-in-out infinite; }
@keyframes ca-beat { 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--ca-rec) 0%, transparent); } }

.ca-rec__live { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.ca-rec__clock { font: 700 20px var(--mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; min-width: 3.2em; }
.ca-rec__meter { flex: 1 1 auto; min-width: 0; width: 100%; height: 32px; color: var(--ca-rec); }
.ca-rec__max { font: 12px var(--mono, ui-monospace, monospace); }

.ca-rec__preview .ca-player { max-width: none; }
.ca-rec__row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.ca-rec__btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 18px; margin: 0;
  border: 0 !important; border-radius: 999px !important;
  background: transparent !important;
  box-shadow: inset 0 0 0 1px var(--ca-rim) !important;
  backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
  font: 700 13px var(--read, system-ui, sans-serif);
  cursor: pointer;
}
.ca-rec__btn--main { background: var(--ca-ink) !important; box-shadow: none !important; }
.ca-rec__btn--stop { background: var(--ca-rec) !important; }
.ca-rec__sq { width: 10px; height: 10px; border-radius: 2px; background: #ffffff !important; }
.ca-rec__err { margin: 0 0 12px; font-size: 13px; line-height: 1.4; }
.ca-rec__preview + .ca-rec__err { margin: 10px 0 0; }
.ca-rec__progress { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.ca-rec__bar { flex: 1 1 auto; height: 6px; border-radius: 3px; background: var(--ca-track) !important; overflow: hidden; }
.ca-rec__bar i { display: block; width: 4%; height: 100%; border-radius: 3px; background: var(--ca-ink) !important; transition: width .2s ease; }
.ca-rec__pct { font: 12px var(--mono, ui-monospace, monospace); min-width: 9em; text-align: right; }

html :is(#ca-scope, body) .ca-rec .ca-rec__title,
html :is(#ca-scope, body) .ca-rec .ca-rec__clock,
html :is(#ca-scope, body) .ca-rec .ca-rec__choice b,
html :is(#ca-scope, body) .ca-rec .ca-rec__btn,
html :is(#ca-scope, body) .ca-rec .ca-rec__err,
html :is(#ca-scope, body) .ca-rec .ca-rec__pct {
  color: var(--ca-ink) !important;
  -webkit-text-fill-color: var(--ca-ink) !important;
}
html :is(#ca-scope, body) .ca-rec .ca-rec__sub,
html :is(#ca-scope, body) .ca-rec .ca-rec__choice small,
html :is(#ca-scope, body) .ca-rec .ca-rec__max {
  color: var(--ca-quiet) !important;
  -webkit-text-fill-color: var(--ca-quiet) !important;
}
html :is(#ca-scope, body) .ca-rec .ca-rec__btn--main {
  color: var(--ca-on) !important;
  -webkit-text-fill-color: var(--ca-on) !important;
}
html :is(#ca-scope, body) .ca-rec .ca-rec__btn--stop { color: #ffffff !important; -webkit-text-fill-color: #ffffff !important; }

/* The composer's mic button */
#cm-compose-audio { border: 0; padding: 0; margin: 0; font: inherit; flex: 0 0 auto; }
#cm-compose-audio:not(:hover):not(.is-on) { background: transparent; }
#cm-compose-audio, #community-quick-compose-audio, .crs-dock__btn[data-dock="audio"] { cursor: pointer; }
#cm-compose-audio svg, #community-quick-compose-audio svg, .crs-dock__btn[data-dock="audio"] svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#cm-compose-audio.is-on svg, #community-quick-compose-audio.is-on svg { stroke: var(--ca-rec, #e5484d); }

@media (prefers-reduced-motion: reduce) {
  .ca-rec, .ca-rec__dot.is-live, .ca-player.is-loading .ca-play { animation: none; }
}

/* The recorder follows its composer out of view. */
#cm-compose[hidden] + .ca-rec,
.community-room-screen__composer[hidden] .ca-rec,
.community-room-screen__composer-shell[hidden] + .ca-rec { display: none !important; }

/* Desktop composer: one more column for the mic. */
.cm-composer:has(#cm-compose-audio) { grid-template-columns: 44px minmax(0, 1fr) 44px 44px 48px; gap: 6px; }
.cm-composer.is-home:has(#cm-compose-audio) { grid-template-columns: 44px minmax(0, 1fr) auto 44px 44px auto; }
@media (max-width: 860px) {
  .cm-composer.is-home:has(#cm-compose-audio) { grid-template-columns: 40px minmax(0, 1fr) 44px 44px auto; }
}

/* Phone room composer: room for the mic when it shows. */
html body #mobile-community-room .community-room-screen__composer-shell:has(#community-quick-compose-audio:not([hidden])) {
  grid-template-columns: 40px minmax(0, 1fr) 38px 38px 44px !important;
  gap: 4px !important;
}
html body #mobile-community-room #community-quick-compose-audio { width: 38px !important; }

/* Icon fills, above the phone's svg and leaf sweeps. */
html :is(#ca-scope, body) .ca-player .ca-play .ca-i,
html :is(#ca-scope, body) .ca-player .ca-play .ca-i * { fill: var(--ca-on) !important; stroke: none !important; color: var(--ca-on) !important; }
html :is(#ca-scope, body) .ca-player .ca-name svg,
html :is(#ca-scope, body) .ca-player .ca-name svg * { fill: none !important; stroke: var(--ca-quiet) !important; }
html :is(#ca-scope, body) .ca-rec .ca-rec__choice > svg,
html :is(#ca-scope, body) .ca-rec .ca-rec__choice > svg *,
html :is(#ca-scope, body) .ca-rec .ca-rec__x svg,
html :is(#ca-scope, body) .ca-rec .ca-rec__x svg * { fill: none !important; stroke: var(--ca-ink) !important; }

/* ------------------------------------------------------ the post's page */

/* The phone's thread view (mobile-community/index.js renderPostDetailMedia):
   an audio post fills the media slot with a dark stage and the player drawn
   large -- label, a big waveform, then time, play and length. The stage is
   always dark, whatever the theme, so the player inks white on it. The
   post-page rules paint the media slot #000 and force every stage child's
   size; these carry the modal's id plus .is-audio to outrank them. */
html body #enter-modal .enter-post-body.is-media:has(> .enter-detail-media-stage.is-audio),
html body #enter-modal.post-detail-page.media-detail-active .post-detail-thread-grid > .enter-post-body.is-media:has(> .enter-detail-media-stage.is-audio) {
  background: #0c0c10 !important;
  background-color: #0c0c10 !important;
  overflow: visible !important;
}
html body #enter-modal .enter-detail-media-stage.is-audio,
html body #enter-modal.post-detail-page .enter-post-body .enter-detail-media-stage.is-audio,
html body #enter-modal.post-detail-page.media-detail-active .enter-detail-media-stage.is-audio {
  position: relative !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-sizing: border-box !important;
  width: 100% !important;
  min-height: 300px !important;
  margin: 0 !important;
  padding: 64px 24px 30px !important;
  border-radius: 0 !important;
  overflow: hidden !important;
  background:
    radial-gradient(120% 85% at 50% 0%, color-mix(in srgb, var(--accent-color, #7c5cff) 30%, transparent), transparent 72%),
    linear-gradient(180deg, #15151b, #0c0c10) !important;
  background-color: #0c0c10 !important;
}

.ca-player.is-detail {
  --ca-ink: #ffffff !important;
  --ca-on: #0c0c10 !important;
  --ca-track: rgba(255, 255, 255, 0.22) !important;
  --ca-quiet: rgba(255, 255, 255, 0.6) !important;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  max-width: 520px;
  padding: 0;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none !important;
}
.ca-player.is-detail .ca-label {
  justify-content: center;
  gap: 8px;
  font: 600 12px/1.2 var(--mono, ui-monospace, "SF Mono", Menlo, monospace);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.ca-player.is-detail .ca-label svg { width: 15px; height: 15px; }
.ca-player.is-detail .ca-wave { height: 96px; border-radius: 10px; }
.ca-player.is-detail .ca-bars { gap: 3px; }
.ca-player.is-detail .ca-bars i { min-width: 2px; max-width: 6px; border-radius: 4px; }
.ca-player.is-detail .ca-foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}
.ca-player.is-detail .ca-time { font-size: 13px; }
.ca-player.is-detail .ca-time--dur { justify-content: flex-end; }
.ca-player.is-detail .ca-cur,
.ca-player.is-detail.is-active .ca-cur { display: inline; }
.ca-player.is-detail.is-active .ca-cur::after { content: none; }
.ca-player.is-detail .ca-play { width: 64px; height: 64px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45) !important; }
.ca-player.is-detail .ca-i { width: 26px; height: 26px; }
html :is(#ca-scope, body) .ca-player.is-detail .ca-cur,
html :is(#ca-scope, body) .ca-player.is-detail.is-active .ca-cur { color: var(--ca-ink) !important; -webkit-text-fill-color: var(--ca-ink) !important; }

/* The older arena feed's plain media stage centres its child. */
.mobile-community-raw-media > .ca-wrap { width: 100%; margin: 0; }
