/* Stetwell visitor widgets: the narration Listen pill and player (the Ask
 * chat will share these). Every look comes from variables set on the
 * widget root by Settings > Narration > appearance; unset ones fall back
 * to the page's own colours and font, so light and dark themes still work.
 *   --stw-nar-accent  pulse, icons, focus ring
 *   --stw-w-bg/-fg    button colours      --stw-w-pbg/-pfg  player colours
 *   --stw-w-font      font family         --stw-w-scale     size
 *   --stw-w-radius    corner roundness    --stw-w-shadow    shadow */
.stw-nar { font-family: var(--stw-w-font, inherit); color: inherit; box-sizing: border-box; }
.stw-nar *, .stw-nar *::before, .stw-nar *::after { box-sizing: inherit; }
/* The player opens ABOVE the Listen pill, which stays anchored at the bottom (as on Rathvane). */
.stw-nar--dock { position: fixed; display: flex; flex-direction: column-reverse; align-items: flex-end; gap: 10px; max-width: calc(100vw - 24px);
  transition: transform .25s ease, opacity .25s ease; }
.stw-nar--inline { margin: 1.5em 0; }
.stw-nar button { font-family: inherit; cursor: pointer; }

/* ---- the launcher (Listen) ---- */
.stw-nar-launch { position: relative; display: inline-flex; align-items: center; gap: calc(9px * var(--stw-w-scale, 1));
  min-height: calc(44px * var(--stw-w-scale, 1)); padding: 0 calc(18px * var(--stw-w-scale, 1)) 0 calc(16px * var(--stw-w-scale, 1));
  font-size: calc(15px * var(--stw-w-scale, 1)); font-weight: 700; line-height: 1; letter-spacing: .01em;
  border: 0; border-radius: var(--stw-w-radius, 999px); box-shadow: var(--stw-w-shadow, 0 2px 10px rgba(0,0,0,.18));
  background: var(--stw-w-bg, Canvas); color: var(--stw-w-fg, CanvasText); }
/* hover and press states are derived from the button's own colours */
.stw-nar-launch { transition: transform .12s ease, filter .12s ease; } /* no colour transition: colours change only from Settings, and a transitioned var() froze in testing */
.stw-nar-launch:hover { filter: brightness(.95); }
.stw-nar-launch:active { transform: translateY(1px) scale(.98); filter: brightness(.9); }
.stw-nar-play:hover, .stw-nar-play:active { filter: brightness(.92); }
.stw-nar-play:active { transform: scale(.95); }
.stw-w-iconwrap { position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: calc(20px * var(--stw-w-scale, 1)); height: calc(20px * var(--stw-w-scale, 1)); flex-shrink: 0; }
.stw-w-icon { position: relative; z-index: 1; width: calc(13px * var(--stw-w-scale, 1)); height: calc(13px * var(--stw-w-scale, 1));
  fill: var(--stw-nar-accent, currentColor); }
.stw-w-icon--play { margin-left: 2px; } /* optical centre of a triangle */
.stw-w-icon .stw-w-stroke { stroke: var(--stw-nar-accent, currentColor); fill: none; }
.stw-nar-halo, .stw-nar-ring { position: absolute; left: 50%; top: 50%; width: 100%; height: 100%; margin: -50% 0 0 -50%;
  border-radius: 50%; opacity: 0; pointer-events: none; }
.stw-nar-halo { background: var(--stw-nar-accent, currentColor); }
.stw-nar-ring { border: 2px solid var(--stw-nar-accent, currentColor); }
.stw-w--icon-only .stw-nar-launch { padding: 0; width: calc(48px * var(--stw-w-scale, 1)); justify-content: center; }
.stw-w--icon-only .stw-nar-launch-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* presets */
.stw-w--preset-solid .stw-nar-launch { background: var(--stw-w-bg, var(--stw-nar-accent, CanvasText)); color: var(--stw-w-fg, #fff); }
.stw-w--preset-solid .stw-w-icon { fill: currentColor; }
.stw-w--preset-solid .stw-w-icon .stw-w-stroke { stroke: currentColor; }
.stw-w--preset-solid .stw-nar-halo { background: currentColor; }
.stw-w--preset-solid .stw-nar-ring { border-color: currentColor; }
.stw-w--preset-minimal .stw-nar-launch { background: var(--stw-w-bg, transparent); box-shadow: none; padding: 0 calc(8px * var(--stw-w-scale, 1)); }

/* pulse (data-pulse="on" set by the script per the pulse setting) */
.stw-nar-launch[data-pulse="on"] .stw-nar-halo { animation: stw-nar-halo 1.8s ease-out infinite; }
.stw-nar-launch[data-pulse="on"] .stw-nar-ring { animation: stw-nar-ring 1.8s ease-out .45s infinite; }
.stw-nar-launch[data-pulse="on"] { animation: stw-nar-glow 1.8s ease-in-out infinite; }
.stw-nar-launch[data-pulse="on"] .stw-w-icon { animation: stw-nar-beat 1.8s ease-in-out infinite; }
@keyframes stw-nar-halo { 0% { transform: scale(.6); opacity: .6; } 70% { transform: scale(2.8); opacity: 0; } 100% { transform: scale(2.8); opacity: 0; } }
@keyframes stw-nar-ring { 0% { transform: scale(.8); opacity: .7; } 80% { transform: scale(3.4); opacity: 0; } 100% { transform: scale(3.4); opacity: 0; } }
@keyframes stw-nar-glow { 0%, 100% { box-shadow: var(--stw-w-shadow, 0 2px 10px rgba(0,0,0,.18)), 0 0 0 0 color-mix(in srgb, var(--stw-nar-accent, #888) 0%, transparent); }
  50% { box-shadow: var(--stw-w-shadow, 0 2px 10px rgba(0,0,0,.18)), 0 0 0 6px color-mix(in srgb, var(--stw-nar-accent, #888) 28%, transparent); } }
@keyframes stw-nar-beat { 0%, 100% { transform: scale(1); } 10% { transform: scale(1.35); } 20% { transform: scale(1); } 30% { transform: scale(1.2); } 40% { transform: scale(1); } }

/* ---- the player ---- */
.stw-nar-panel { width: min(calc(360px * var(--stw-w-scale, 1)), calc(100vw - 24px)); padding: 12px 14px; font-size: calc(15px * var(--stw-w-scale, 1));
  border: 1px solid rgba(127,127,127,.35); border-radius: min(var(--stw-w-radius, 12px), 14px);
  background: var(--stw-w-pbg, Canvas); color: var(--stw-w-pfg, CanvasText); }
.stw-nar--dock .stw-nar-panel { box-shadow: var(--stw-w-shadow, 0 6px 24px rgba(0,0,0,.2)); }
.stw-nar--inline .stw-nar-panel { width: 100%; max-width: 640px; }
.stw-nar-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.stw-nar-label { display: inline-flex; align-items: center; gap: 7px; font-size: .78em; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--stw-nar-accent, inherit); }
.stw-nar-label .stw-w-icon { width: 13px; height: 13px; }
/* close: a circle with an x */
.stw-nar-close { width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent); background: transparent; color: inherit; opacity: .8; }
.stw-nar-close svg { width: 10px; height: 10px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; fill: none; }
.stw-nar-close:hover { opacity: 1; border-color: var(--stw-nar-accent, currentColor); }
.stw-nar-row { display: flex; align-items: center; gap: 10px; }
/* play: a filled accent circle (as on Rathvane) */
.stw-nar-play { flex-shrink: 0; width: calc(40px * var(--stw-w-scale, 1)); height: calc(40px * var(--stw-w-scale, 1)); padding: 0; border: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--stw-nar-accent, CanvasText); color: var(--stw-w-pbg, Canvas); }
.stw-nar-play svg { width: 13px; height: 15px; fill: currentColor; }
.stw-nar-play .stw-nar-i-play { margin-left: 2px; }
.stw-nar-play .stw-nar-i-pause, .stw-nar-play[data-state="playing"] .stw-nar-i-play { display: none; }
.stw-nar-play[data-state="playing"] .stw-nar-i-pause { display: block; }
.stw-nar-time { font-size: .8em; font-variant-numeric: tabular-nums; white-space: nowrap; opacity: .8; }
/* seek and volume: a light track filled in the accent up to --p (set by the script), an accent thumb */
.stw-nar-seek, .stw-nar-volume { flex: 1; min-width: 60px; height: 20px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.stw-nar-seek::-webkit-slider-runnable-track, .stw-nar-volume::-webkit-slider-runnable-track { height: 4px; border-radius: 4px;
  background: linear-gradient(to right, var(--stw-nar-accent, currentColor) var(--p, 0%), color-mix(in srgb, currentColor 18%, transparent) var(--p, 0%)); }
.stw-nar-seek::-moz-range-track, .stw-nar-volume::-moz-range-track { height: 4px; border-radius: 4px; background: color-mix(in srgb, currentColor 18%, transparent); }
.stw-nar-seek::-moz-range-progress, .stw-nar-volume::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--stw-nar-accent, currentColor); }
.stw-nar-seek::-webkit-slider-thumb, .stw-nar-volume::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px;
  border-radius: 50%; border: 0; background: var(--stw-nar-accent, currentColor); }
.stw-nar-seek::-moz-range-thumb, .stw-nar-volume::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; border: 0; background: var(--stw-nar-accent, currentColor); }
/* second row: speed stepper and volume */
.stw-nar-row2 { justify-content: center; gap: 8px; margin-top: 8px; }
.stw-nar-slower, .stw-nar-faster, .stw-nar-vol { width: calc(30px * var(--stw-w-scale, 1)); height: calc(30px * var(--stw-w-scale, 1)); padding: 0;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent); background: transparent; color: inherit; font-size: 1em; line-height: 1; }
.stw-nar-slower:hover, .stw-nar-faster:hover, .stw-nar-vol:hover { border-color: var(--stw-nar-accent, currentColor); }
.stw-nar-rate { min-width: 3.2em; text-align: center; font-weight: 700; font-size: .9em; font-variant-numeric: tabular-nums; }
.stw-nar-vol .stw-w-icon { width: 14px; height: 14px; fill: currentColor; }
.stw-nar-vol .stw-w-icon .stw-w-stroke { stroke: currentColor; }
.stw-nar-vol[data-vol="0"] .stw-w-stroke { display: none; }
.stw-nar-vol[data-vol="0"] { opacity: .55; }
.stw-nar-volume { flex: 0 1 110px; }
.stw-nar-links { margin-top: 10px; font-size: .85em; }
.stw-nar-links span { display: block; opacity: .75; margin-bottom: 4px; }
.stw-nar-links ul { margin: 0; padding-left: 1.1em; }
.stw-nar-links a { color: inherit; }
.stw-nar-transcript { margin-top: 10px; font-size: .9em; }
.stw-nar-transcript summary { cursor: pointer; min-height: 32px; }
.stw-nar--dock .stw-nar-transcript > div { max-height: 40vh; overflow: auto; }
.stw-nar :focus-visible { outline: 2px solid var(--stw-nar-accent, currentColor); outline-offset: 2px; }

/* ---- behaviour states (set by the script) ---- */
.stw-nar.stw-w--waiting { opacity: 0; visibility: hidden; }
.stw-nar.stw-w--away { transform: translateY(calc(100% + 40px)); opacity: 0; }

/* ---- phones ---- */
@media (max-width: 600px) {
  .stw-nar--dock.stw-w--mobile-hide { display: none; }
  .stw-nar--dock.stw-w--mobile-bar { left: 0 !important; right: 0 !important; bottom: 0 !important; max-width: none; align-items: stretch; gap: 0; }
  .stw-w--mobile-bar .stw-dock-bar { width: 100%; border-radius: 0; }
  .stw-w--mobile-bar .stw-dock-bar > * { flex: 1; }
  .stw-w--mobile-bar .stw-dock-sep { flex: 0 0 1px; }
  .stw-w--mobile-bar .stw-nar-launch { width: 100%; justify-content: center; border-radius: 0; min-height: 48px; }
  .stw-w--mobile-bar .stw-nar-panel { width: 100%; border-radius: 14px 14px 0 0; border-bottom: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .stw-nar-launch[data-pulse="on"], .stw-nar-launch[data-pulse="on"] .stw-w-icon, .stw-nar-launch[data-pulse="on"] .stw-nar-halo,
  .stw-nar-launch[data-pulse="on"] .stw-nar-ring { animation: none; }
  .stw-nar-launch[data-pulse="on"] { box-shadow: var(--stw-w-shadow, 0 2px 10px rgba(0,0,0,.18)), 0 0 0 3px color-mix(in srgb, var(--stw-nar-accent, #888) 35%, transparent); }
  .stw-nar--dock { transition: none; }
}
/* ---- the shared dock bar: Listen and Ask in one pill (as on Rathvane) ---- */
.stw-dock-bar { display: inline-flex; align-items: center; }
.stw-dock-bar--multi { gap: 2px; padding: 3px; border-radius: var(--stw-w-radius, 999px); box-shadow: var(--stw-w-shadow, 0 2px 10px rgba(0,0,0,.18));
  background: var(--stw-w-bg, Canvas); color: var(--stw-w-fg, CanvasText); }
.stw-dock-bar--multi .stw-nar-launch { box-shadow: none; background: transparent; color: inherit;
  min-height: calc(38px * var(--stw-w-scale, 1)); padding: 0 calc(12px * var(--stw-w-scale, 1)); }
.stw-dock-bar--multi .stw-nar-launch[data-pulse="on"] { animation: none; } /* the icon still beats; the glow belongs to a lone button */
.stw-w--preset-minimal .stw-dock-bar--multi { background: var(--stw-w-bg, transparent); box-shadow: none; }
.stw-dock-sep { width: 1px; align-self: stretch; margin: 8px 2px; background: currentColor; opacity: .2; }

@media print { .stw-nar { display: none; } }
