/* ============================================================
   css/widgets.css  —  toast, lightbox, command palette, assistant
   (v2: system type, neat BrewedOps-like surfaces, light default,
   calm graphite dark mode)
   ------------------------------------------------------------
   Prefixes: .tst- toast · .lb- lightbox · .pal- palette ·
             .chat- assistant
   Every design token is used WITH a fallback (light values on
   the base rule, dark values under [data-theme="dark"]) so these
   widgets look right even if styles.css hasn't defined it yet.

   Theme-independent on purpose:
     • the lightbox is always dark (media viewer)
     • toasts are an inverse graphite surface in both themes

   Stacking (override the --z-* vars on :root if needed):
     chat 90  <  page modals (~100)  <  palette 110
     <  lightbox 120 (can sit over the service modal)  <  toast 130
   ============================================================ */

.tst-stack, .lb, .pal, .chat {
  --w-sans: var(--sans, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui,
    "Segoe UI Variable Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
  --w-mono: var(--mono, ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", Menlo, Consolas, monospace);
  --w-g1: var(--g1, #ff1b8d);
  --w-g2: var(--g2, #ff5a3c);
  --w-g3: var(--g3, #ffc23c);
  --w-grad: var(--grad, linear-gradient(90deg, #ff1b8d, #ff5a3c 55%, #ffc23c));
  --w-grad-diag: var(--grad-diag, linear-gradient(135deg, #ff1b8d, #ff5a3c 50%, #ffc23c));
  --w-ink: var(--ink, #151114);
  --w-err: var(--err, #e5484d);
  --w-ease: var(--ease, cubic-bezier(.22, 1, .36, 1));
  --w-ease-io: var(--ease-io, cubic-bezier(.65, 0, .35, 1));
  --w-spring: cubic-bezier(.34, 1.56, .64, 1);
  --w-focus: #ff1b8d;
  font-family: var(--w-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* themed surfaces (palette + assistant) — LIGHT fallbacks */
.pal, .chat {
  --w-bg: var(--bg, #fcfbf9);
  --w-panel: var(--panel, #ffffff);
  --w-panel-2: var(--panel-2, #f7f4f0);
  --w-line: var(--line, #e6e0d8);
  --w-line-soft: var(--line-soft, #efeae3);
  --w-text: var(--text, #151114);
  --w-muted: var(--muted, #5b545c);
  --w-muted-2: var(--muted-2, #76707a);
  --w-fg-rgb: var(--fg-rgb, 21 17 20);
  --w-sh-rgb: 21 17 20;                       /* shadow ink (always dark) */
  --w-ok: var(--ok, #119c63);
  --w-scrim: var(--scrim, rgb(20 16 20 / .38));
  --w-accent: #c40f68;                        /* small accent text: 5.5:1 on white */
  --w-accent-soft: rgb(255 27 141 / .1);
  --w-hover: rgb(var(--w-fg-rgb) / .045);
  --w-shadow: 0 1px 2px rgb(var(--w-fg-rgb) / .05), 0 12px 32px -18px rgb(var(--w-fg-rgb) / .18);
  --w-shadow-float: 0 1px 2px rgb(var(--w-fg-rgb) / .06), 0 2px 8px -2px rgb(var(--w-fg-rgb) / .06),
    0 32px 72px -28px rgb(var(--w-fg-rgb) / .32);
  color-scheme: light;
}
/* DARK fallbacks (calm graphite) */
:root[data-theme="dark"] :is(.pal, .chat) {
  --w-bg: var(--bg, #0e0f12);
  --w-panel: var(--panel, #16181c);
  --w-panel-2: var(--panel-2, #1c1e23);
  --w-line: var(--line, #272a31);
  --w-line-soft: var(--line-soft, #1d1f24);
  --w-text: var(--text, #ecedf0);
  --w-muted: var(--muted, #9ea2ab);
  --w-muted-2: var(--muted-2, #82868f);
  --w-fg-rgb: var(--fg-rgb, 236 237 240);
  --w-sh-rgb: 0 0 0;                          /* fg is near-white here: never tint shadows with it */
  --w-launch-glow: .22;                       /* calmer pink glow under the launcher */
  --w-ok: var(--ok, #3ddc97);
  --w-scrim: var(--scrim, rgb(0 0 0 / .6));
  --w-accent: #ff74a6;                        /* 6.9:1 on #16181c */
  --w-accent-soft: rgb(255 27 141 / .24);
  --w-hover: rgb(var(--w-fg-rgb) / .055);
  --w-shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 32px -18px rgb(0 0 0 / .7);
  --w-shadow-float: 0 0 0 1px rgb(255 255 255 / .02), 0 2px 8px -2px rgb(0 0 0 / .5),
    0 36px 80px -30px rgb(0 0 0 / .85);
  color-scheme: dark;
}

/* don't depend on the page's reset */
.tst-stack, .tst-stack *, .lb, .lb *, .pal, .pal *, .chat, .chat *,
.lb *::before, .lb *::after, .pal *::before, .pal *::after, .chat *::before, .chat *::after {
  box-sizing: border-box;
}
.lb button, .pal button, .chat button, .chat input { font-family: inherit; }

/* shared: visually hidden text + focus ring */
.lb-sr, .chat-sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.lb :focus-visible, .pal :focus-visible, .chat :focus-visible {
  outline: 2px solid var(--w-focus); outline-offset: 3px;
}

/* ============================================================
   TOAST  (inverse graphite pill in both themes)
   ============================================================ */
.tst-stack {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: var(--z-toast, 130);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.tst {
  pointer-events: auto; cursor: default;
  display: flex; align-items: center; gap: 10px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px 11px 14px;
  border-radius: 99px;
  background: #1b1d22;
  border: 1px solid rgb(255 255 255 / .08);
  box-shadow: 0 1px 2px rgb(0 0 0 / .18), 0 16px 36px -14px rgb(0 0 0 / .5);
  color: #ecedf0; font-size: 14px; font-weight: 500; line-height: 1.35; letter-spacing: -.005em;
  opacity: 0; transform: translateY(12px) scale(.97);
  transition: opacity .28s var(--w-ease), transform .45s var(--w-spring);
}
.tst.is-in { opacity: 1; transform: none; }
.tst.is-out { opacity: 0; transform: translateY(6px) scale(.98); transition: opacity .2s var(--w-ease), transform .2s var(--w-ease); }
.tst-dot {
  flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: #3ddc97; box-shadow: 0 0 0 3px rgb(61 220 151 / .16);
}
.tst-bad .tst-dot { background: #ff5c6c; box-shadow: 0 0 0 3px rgb(255 92 108 / .18); }
.tst-info .tst-dot { background: linear-gradient(135deg, #ff1b8d, #ff5a3c 50%, #ffc23c); box-shadow: 0 0 0 3px rgb(255 90 60 / .16); }
.tst-text { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .tst { border-radius: 16px; }   /* multi-line messages read better as a card */
}

/* 900–1199px: the centred stack could reach the soundtrack pill
   (bottom-left) — lift it clear */
@media (min-width: 900px) and (max-width: 1199px) {
  .tst-stack { bottom: calc(86px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 899px) {
  .tst-stack { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 640px) {
  /* narrow: the stack would run under the chat launcher / soundtrack
     button (both at bottom 92px) → sit above them */
  .tst-stack { bottom: calc(92px + 58px + 14px + env(safe-area-inset-bottom, 0px)); }
}

/* ============================================================
   LIGHTBOX  (always dark — it's a media viewer)
   ============================================================ */
.lb {
  --lb-text: #ecedf0;
  --lb-muted: #a3a7b0;
  --lb-line: rgb(255 255 255 / .1);
  --lb-chip: rgb(28 30 35 / .72);
  position: fixed; inset: 0;
  z-index: var(--z-lightbox, 120);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  color: var(--lb-text);
  color-scheme: dark;
  opacity: 0; transition: opacity .28s var(--w-ease);
  overscroll-behavior: contain;
}
.lb[hidden] { display: none; }
.lb.is-open { opacity: 1; }
.lb > * { position: relative; z-index: 1; }
.lb > .lb-backdrop {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 60% 50% at 50% 45%, rgb(255 27 141 / .035), transparent 70%),
    rgb(9 10 12 / .92);
  -webkit-backdrop-filter: blur(18px) saturate(110%); backdrop-filter: blur(18px) saturate(110%);
}

.lb-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 10px 20px;
  min-height: 72px;
}
.lb-count {
  font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--lb-muted);
  font-variant-numeric: tabular-nums;
  padding: 7px 12px; border-radius: 99px; border: 1px solid var(--lb-line);
  background: var(--lb-chip);
}
.lb-count[hidden] { display: inline-block; visibility: hidden; }

.lb-btn {
  display: inline-grid; place-items: center;
  width: 46px; height: 46px; padding: 0; border-radius: 50%;
  border: 1px solid var(--lb-line);
  background: var(--lb-chip);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  color: var(--lb-text); cursor: pointer;
  transition: border-color .2s, background-color .2s, transform .35s var(--w-ease);
}
.lb-btn:hover { border-color: rgb(255 255 255 / .22); background: rgb(44 47 54 / .85); }
.lb-btn:active { transform: scale(.96); }
.lb-btn[hidden] { display: none; }
.lb-close { margin-left: auto; }
.lb-close:hover svg { transform: rotate(90deg); }
.lb-close svg { transition: transform .35s var(--w-ease); }

.lb-nav {
  position: absolute; top: 50%; z-index: 2;
  transform: translateY(-50%);
}
.lb-prev { left: 20px; }
.lb-next { right: 20px; }
.lb-prev:hover { transform: translateY(-50%) translateX(-2px); }
.lb-next:hover { transform: translateY(-50%) translateX(2px); }
.lb-nav:active { transform: translateY(-50%) scale(.96); }

.lb-stage {
  display: grid; min-height: 0; min-width: 0;
  padding: 0 max(4vw, 12px);
  touch-action: pan-y pinch-zoom;
}
@media (min-width: 900px) { .lb-stage { padding: 0 92px; } }

.lb-slide {
  grid-area: 1 / 1;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; min-width: 0; min-height: 0;
  transition: opacity .38s var(--w-ease), transform .38s var(--w-ease);
}
.lb:not(.is-open) .lb-slide { transform: scale(.97); }
.lb-slide.from-right { opacity: 0; transform: translateX(40px) scale(.985); }
.lb-slide.from-left { opacity: 0; transform: translateX(-40px) scale(.985); }
.lb-slide.to-left { opacity: 0; transform: translateX(-40px) scale(.985); pointer-events: none; }
.lb-slide.to-right { opacity: 0; transform: translateX(40px) scale(.985); pointer-events: none; }

.lb-img, .lb-video {
  display: block;
  max-width: min(92vw, 100%); max-height: min(82vh, 100%);
  width: auto; height: auto; object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 0 0 1px rgb(255 255 255 / .05), 0 30px 80px -24px rgb(0 0 0 / .8);
  -webkit-user-select: none; user-select: none;
  transition: opacity .3s var(--w-ease);
}
.lb-video { background: #000; min-width: min(100%, 320px); }
.lb-slide.is-loading .lb-img { opacity: 0; }
.lb-slide.is-loading::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%;
  border: 2px solid rgb(255 255 255 / .12); border-top-color: #ff5a3c;
  animation: lb-spin .8s linear infinite;
}
@keyframes lb-spin { to { transform: rotate(360deg); } }

.lb-embed {
  width: min(100%, 92vw, calc(82vh * 16 / 9));
  width: min(100%, 92vw, calc(min(82vh, 100dvh - 190px) * 16 / 9));
  aspect-ratio: 16 / 9; max-height: 100%;
  border-radius: 14px; overflow: hidden; background: #000;
  box-shadow: 0 0 0 1px rgb(255 255 255 / .05), 0 30px 80px -24px rgb(0 0 0 / .8);
}
.lb-embed iframe { display: block; width: 100%; height: 100%; border: 0; pointer-events: auto !important; }
.lb-fallback {
  padding: 26px 30px; border-radius: 18px; max-width: 360px; text-align: center;
  background: #16181c; border: 1px solid var(--lb-line); color: var(--lb-muted);
  font-size: 15px; line-height: 1.5;
}

.lb-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: 100%; max-width: 900px; margin: 0 auto;
  padding: 14px 20px calc(18px + env(safe-area-inset-bottom, 0px));
}
.lb-bar[hidden] { display: none; }
.lb-cap { min-width: 0; flex: 1; }
.lb-title {
  display: block; font-weight: 600; font-size: 16px;
  letter-spacing: -.012em; line-height: 1.3;
}
.lb-caption {
  margin: 4px 0 0; color: var(--lb-muted); font-size: 14px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.lb-title[hidden], .lb-caption[hidden] { display: none; }
.lb-link {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 99px;
  background: var(--w-grad); color: #151114;
  font-weight: 600; font-size: 14px; letter-spacing: -.005em; text-decoration: none;
  transition: transform .3s var(--w-ease), box-shadow .3s;
}
.lb-link:hover { transform: translateY(-2px); box-shadow: 0 10px 24px -10px rgb(255 90 60 / .45); }
.lb-link[hidden] { display: none; }

@media (max-width: 640px) {
  .lb-top { min-height: 64px; padding-left: 14px; padding-right: 10px; }
  .lb-btn { width: 44px; height: 44px; }
  .lb-nav { background: rgb(22 24 28 / .55); }
  .lb-prev { left: 6px; }
  .lb-next { right: 6px; }
  .lb-bar { flex-direction: column; align-items: stretch; gap: 10px; padding-left: 16px; padding-right: 16px; }
  .lb-link { justify-content: center; }
  .lb-img, .lb-video { border-radius: 10px; }
}
@media (hover: none) and (pointer: coarse) {
  /* swiping is the main gesture on touch screens; keep the arrows subtle */
  .lb-nav { opacity: .75; }
}

/* ============================================================
   COMMAND PALETTE
   ============================================================ */
.pal {
  position: fixed; inset: 0;
  z-index: var(--z-palette, 110);
  display: flex; justify-content: center; align-items: flex-start;
  padding: 18vh 16px 16px;
  color: var(--w-text);
}
.pal[hidden] { display: none; }
.pal-backdrop {
  position: absolute; inset: 0;
  background: var(--w-scrim);
  -webkit-backdrop-filter: blur(6px) saturate(110%); backdrop-filter: blur(6px) saturate(110%);
  opacity: 0; transition: opacity .22s var(--w-ease);
}
.pal.is-open .pal-backdrop { opacity: 1; }
.pal-dialog {
  position: relative; width: 100%; max-width: 620px;
  max-height: min(560px, 74vh);
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: 20px;
  background: var(--w-panel);
  border: 1px solid var(--w-line);
  box-shadow: var(--w-shadow-float);
  opacity: 0; transform: translateY(-8px) scale(.98);
  transition: opacity .2s var(--w-ease), transform .32s var(--w-ease);
}
.pal.is-open .pal-dialog { opacity: 1; transform: none; }

.pal-search {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 14px 6px 18px; min-height: 60px;
  border-bottom: 1px solid var(--w-line-soft);
}
.pal-search-icon { display: grid; color: var(--w-muted); transition: color .2s; }
.pal-search:focus-within .pal-search-icon { color: var(--w-text); }
.pal-input {
  flex: 1; min-width: 0; min-height: 48px;
  background: transparent; border: 0; outline: none; box-shadow: none;
  color: var(--w-text); font: 500 17px/1.2 var(--w-sans); letter-spacing: -.012em;
}
.pal-input::placeholder { color: var(--w-muted); opacity: 1; }
.pal .pal-input:focus-visible { outline: none; }
.pal-kbd, .pal-foot kbd {
  font-family: var(--w-sans); font-size: 11px; font-weight: 600; line-height: 1;
  color: var(--w-muted); background: var(--w-panel-2);
  border: 1px solid var(--w-line); border-bottom-width: 2px; border-radius: 6px;
  padding: 4px 7px;
}

.pal-list {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 8px 10px;
  scrollbar-width: thin; scrollbar-color: var(--w-line) transparent;
}
.pal-list[hidden] { display: none; }
.pal-group-label {
  font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--w-muted-2); padding: 14px 12px 6px;
}
.pal-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 7px 10px; border-radius: 12px;
  cursor: pointer; color: var(--w-text);
  transition: background-color .14s;
}
.pal-item.is-active { background: var(--w-hover); box-shadow: inset 0 0 0 1px var(--w-line-soft); }
.pal-icon {
  flex: none; width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center; font-size: 15px;
  background: var(--w-panel); border: 1px solid var(--w-line); color: var(--w-muted);
  box-shadow: 0 1px 2px rgb(var(--w-sh-rgb) / .05);
  transition: background .2s, color .2s, border-color .2s, transform .35s var(--w-spring);
}
.pal-icon svg { width: 17px; height: 17px; }
.pal-item.is-active .pal-icon {
  background: var(--w-grad-diag); border-color: transparent; color: #151114;
  transform: scale(1.04);
}
.pal-label {
  flex: 1; min-width: 0; font-weight: 500; font-size: 15px; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pal-label mark {
  background: var(--w-accent-soft); color: inherit; font-weight: 650;
  border-radius: 3px; padding: 0 1px; margin: 0 -1px;
}
.pal-hint {
  flex: none; font-size: 12px; font-weight: 500;
  color: var(--w-muted); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pal-enter {
  flex: none; width: 22px; text-align: center; font-size: 13px;
  color: var(--w-muted); opacity: 0; transition: opacity .15s;
}
.pal-item.is-active .pal-enter { opacity: 1; }

.pal-empty { padding: 40px 20px 44px; text-align: center; color: var(--w-muted); font-size: 15px; }
.pal-empty[hidden] { display: none; }
.pal-empty strong { color: var(--w-text); font-weight: 600; }

.pal-foot {
  display: flex; gap: 18px; align-items: center;
  padding: 10px 16px; border-top: 1px solid var(--w-line-soft);
  background: var(--w-panel-2);
  font-size: 12px; color: var(--w-muted);
}
.pal-foot span { display: inline-flex; align-items: center; gap: 5px; }
.pal-foot kbd { padding: 3px 5px; font-size: 10.5px; background: var(--w-panel); }

@media (max-width: 640px) {
  .pal { padding-top: max(10vh, 56px); }
  .pal-dialog { max-height: 78vh; border-radius: 18px; }
  .pal-kbd { display: none; }
  .pal-input { font-size: 16px; }             /* ≥16px: no iOS zoom on focus */
  .pal-hint { display: none; }
}
@media (hover: none) and (pointer: coarse) {
  .pal-foot { display: none; }
}

/* ============================================================
   ASSISTANT (chat)
   ============================================================ */

/* hidden while the intro is up */
html.intro .chat { visibility: hidden; }

/* ---- launcher (bottom-right; the soundtrack player owns bottom-left) ---- */
.chat-launcher {
  position: fixed; right: 24px; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-chat, 90);
  width: 58px; height: 58px; padding: 0; border: 0; border-radius: 50%;
  background: var(--w-grad-diag);
  box-shadow: 0 1px 2px rgb(var(--w-sh-rgb) / .12), 0 12px 28px -12px rgb(255 27 141 / var(--w-launch-glow, .38)),
    0 8px 22px -10px rgb(var(--w-sh-rgb) / .28);
  cursor: pointer;
  transition: transform .45s var(--w-spring), box-shadow .3s, opacity .25s;
}
.chat-launcher::before {           /* soft halo: a few calm breaths, then still */
  content: ''; position: absolute; inset: -6px; border-radius: 50%;
  border: 1px solid rgb(255 90 60 / .35);
  opacity: 0;
  animation: chat-halo 3.2s var(--w-ease) 1.2s 4;
  pointer-events: none;
}
.chat-launcher:hover { transform: translateY(-3px); }
.chat-launcher:active { transform: scale(.96); }
.chat-launcher-av, .chat-launcher-x {
  position: absolute; inset: 2.5px; border-radius: 50%; overflow: hidden;
  transition: opacity .3s var(--w-ease), transform .45s var(--w-spring);
}
.chat-launcher-av { background: var(--w-panel-2); }
.chat-launcher-x {
  display: grid; place-items: center; color: var(--w-text);
  background: var(--w-panel);
  opacity: 0; transform: rotate(-90deg) scale(.6);
}
.chat-av {
  display: block; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 12%;
}
.chat-av-ph {
  display: grid; place-items: center;
  background: var(--w-grad-diag); color: #151114;
  font-weight: 800; font-size: 15px; letter-spacing: -.02em;
}
.chat-online {
  position: absolute; right: 1px; bottom: 3px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--w-ok); border: 2.5px solid var(--w-panel);
  transition: opacity .2s;
}
.chat-online::after {
  content: ''; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--w-ok); opacity: 0;
  animation: chat-ping 3s ease-out infinite;
}
.chat.is-open .chat-launcher::before { animation: none; opacity: 0; }
.chat.is-open .chat-launcher-av { opacity: 0; transform: scale(.6); }
.chat.is-open .chat-launcher-x { opacity: 1; transform: none; }
.chat.is-open .chat-launcher > .chat-online { opacity: 0; }

@keyframes chat-halo {
  0% { transform: scale(.94); opacity: 0; }
  40% { opacity: .8; }
  100% { transform: scale(1.18); opacity: 0; }
}
@keyframes chat-ping {
  0% { transform: scale(.8); opacity: .55; }
  70%, 100% { transform: scale(1.8); opacity: 0; }
}
/* WCAG 2.2.2 — the footer "Pause animations" toggle. Stop the loops
   outright (not animation-play-state): a paused halo/ping would freeze
   as a stray half-faded ring around the launcher. */
html.motion-paused .chat-launcher::before,
html.motion-paused .chat-online::after { animation: none; opacity: 0; }
html.motion-paused .chat-typing i { animation: none; opacity: .7; }

/* ---- nudge bubble ---- */
.chat-nudge {
  position: fixed; right: 24px; bottom: calc(24px + 58px + 14px + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-chat, 90);
  display: flex; align-items: center; gap: 2px;
  padding: 4px 4px 4px 8px;
  border-radius: 18px 18px 6px 18px;
  background: var(--w-panel); color: var(--w-text);
  border: 1px solid var(--w-line);
  box-shadow: var(--w-shadow-float);
  transform-origin: bottom right;
  opacity: 0; transform: translateY(8px) scale(.9);
  transition: opacity .3s var(--w-ease), transform .5s var(--w-spring);
}
.chat-nudge[hidden] { display: none; }
.chat-nudge.is-in { opacity: 1; transform: none; }
.chat-nudge::after {               /* tail toward the launcher */
  content: ''; position: absolute; right: 18px; bottom: -6px;
  width: 11px; height: 11px; background: inherit; transform: rotate(45deg); border-radius: 2px;
  border-right: 1px solid var(--w-line); border-bottom: 1px solid var(--w-line);
}
.chat-nudge-text {
  min-height: 40px; padding: 0 8px;
  background: none; border: 0; cursor: pointer;
  font: 600 14px/1 var(--w-sans); color: inherit; letter-spacing: -.01em;
}
.chat-nudge-text::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--w-ok); margin-right: 8px; vertical-align: 1px;
}
.chat-nudge-x {
  position: relative; display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--w-muted); cursor: pointer;
  transition: background-color .2s, color .2s;
}
.chat-nudge-x::before { content: ''; position: absolute; inset: -6px; }   /* 44px hit area */
.chat-nudge-x:hover { background: var(--w-hover); color: var(--w-text); }
.chat-nudge-x svg { width: 15px; height: 15px; }

/* ---- scrim (phones) ---- */
.chat-scrim {
  position: fixed; inset: 0; z-index: var(--z-chat, 90);
  background: var(--w-scrim);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .3s var(--w-ease);
  touch-action: none;
}
.chat-scrim[hidden] { display: none; }
.chat-scrim.is-open { opacity: 1; }

/* ---- panel ---- */
.chat-panel {
  position: fixed; right: 24px;
  bottom: calc(24px + 58px + 14px + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-chat, 90);
  width: 380px; max-width: calc(100vw - 32px);
  height: min(560px, calc(100dvh - 130px));
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: 22px;
  background: var(--w-panel);
  border: 1px solid var(--w-line);
  box-shadow: var(--w-shadow-float);
  color: var(--w-text);
  transform-origin: bottom right;
  opacity: 0; transform: translateY(12px) scale(.97);
  transition: opacity .26s var(--w-ease), transform .42s var(--w-ease);
  outline: none;
}
.chat-panel[hidden] { display: none; }
/* the panel itself only takes focus programmatically (touch open) —
   never ring the whole dialog */
.chat .chat-panel:focus, .chat .chat-panel:focus-visible { outline: none; }
.chat-panel.is-open { opacity: 1; transform: none; }
.chat-panel::before {              /* hairline brand accent along the top */
  content: ''; position: absolute; left: 22px; right: 22px; top: 0; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgb(255 27 141 / .45), rgb(255 194 60 / .4), transparent);
}
.chat-panel > * { position: relative; }

.chat-handle { display: none; }

.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 10px 14px 16px;
  border-bottom: 1px solid var(--w-line-soft);
}
.chat-head-av {
  position: relative; flex: none; width: 40px; height: 40px; border-radius: 50%;
  padding: 2px; background: var(--w-grad-diag);
}
.chat-head-av .chat-av, .chat-head-av .chat-av-ph {
  width: 100%; height: 100%; border-radius: 50%;
  background: var(--w-panel-2);
  box-shadow: 0 0 0 1.5px var(--w-panel);
}
.chat-head-av .chat-av-ph { color: var(--w-text); font-size: 12.5px; }
.chat-head-av .chat-online { width: 12px; height: 12px; right: -1px; bottom: 0; border-width: 2px; }
.chat-head-text { flex: 1; min-width: 0; }
.chat-title {
  margin: 0; font-weight: 600; font-size: 15.5px;
  letter-spacing: -.012em; line-height: 1.2; color: var(--w-text);
}
.chat-sub {
  margin: 3px 0 0; font-size: 12px; font-weight: 500; letter-spacing: 0;
  color: var(--w-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-icon-btn {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; padding: 0; border-radius: 50%;
  border: 1px solid transparent; background: transparent; color: var(--w-muted); cursor: pointer;
  transition: background-color .2s, color .2s, border-color .2s;
}
.chat-icon-btn:hover { background: var(--w-hover); color: var(--w-text); border-color: var(--w-line-soft); }
.chat-icon-btn svg { transition: transform .4s var(--w-ease); }
.chat-close:hover svg { transform: rotate(90deg); }
.chat-restart:hover svg { transform: rotate(-120deg); }

/* ---- log ---- */
.chat-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px 14px 10px;
  background: var(--w-bg);
  scrollbar-width: thin; scrollbar-color: var(--w-line) transparent;
}
.chat-log:focus-visible { outline-offset: -3px; }
.chat-msg {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  max-width: 90%;
}
.chat-user { align-self: flex-end; align-items: flex-end; max-width: 82%; }
.chat-msg.is-new { animation: chat-in .42s var(--w-ease) both; }
@keyframes chat-in { from { opacity: 0; transform: translateY(8px); } }

.chat-bubble {
  padding: 11px 14px;
  border-radius: 18px 18px 18px 6px;
  background: var(--w-panel);
  border: 1px solid var(--w-line);
  box-shadow: 0 1px 2px rgb(var(--w-sh-rgb) / .04);
  font-size: 14.5px; line-height: 1.5; color: var(--w-text);
  overflow-wrap: anywhere;
}
.chat-user .chat-bubble {
  background: var(--w-text); color: var(--w-bg); border-color: transparent;
  border-radius: 18px 18px 6px 18px; font-weight: 500; box-shadow: none;
}
.chat-kicker {
  margin: 0 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--w-accent);
}
.chat-text { margin: 0; }
.chat-list { list-style: none; margin: 10px 0 0; padding: 0; }
.chat-list li {
  position: relative; padding-left: 16px; margin-top: 6px;
  font-size: 14px; line-height: 1.45; color: var(--w-text);
}
.chat-list li::before {
  content: ''; position: absolute; left: 1px; top: .55em;
  width: 6px; height: 6px; border-radius: 2px; background: var(--w-grad-diag);
}
.chat-note {
  display: grid; gap: 4px; margin-top: 12px; padding: 10px 12px; border-radius: 12px;
  background: var(--w-panel-2); border: 1px solid var(--w-line-soft);
  font-size: 13.5px; line-height: 1.45;
}
.chat-note-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--w-muted);
}

.chat-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-act {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 40px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--w-line); background: var(--w-panel);
  color: var(--w-text); font: 600 13.5px/1 var(--w-sans); letter-spacing: -.005em;
  text-decoration: none; cursor: pointer;
  box-shadow: 0 1px 2px rgb(var(--w-sh-rgb) / .04);
  transition: border-color .2s, background-color .2s, transform .3s var(--w-ease), box-shadow .3s;
}
.chat-act:hover { border-color: rgb(var(--w-fg-rgb) / .22); transform: translateY(-1px); box-shadow: var(--w-shadow); }
.chat-act.is-primary { background: var(--w-grad); color: #151114; border-color: transparent; }
.chat-act.is-primary:hover { box-shadow: 0 10px 22px -12px rgb(255 90 60 / .55); }
.chat-act-ic { display: grid; }

/* typing indicator */
.chat-typing .chat-bubble { display: inline-flex; gap: 5px; align-items: center; padding: 14px 16px; }
.chat-typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--w-muted);
  animation: chat-dot 1.1s var(--w-ease-io) infinite;
}
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- quick replies ---- */
.chat-chips {
  display: flex; gap: 6px; flex: none;
  overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  padding: 8px 14px 8px;
  background: var(--w-bg);
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
          mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}
.chat-chips::-webkit-scrollbar { display: none; }
.chat-chips[hidden] { display: none; }
.chat-chips::after { content: ''; flex: none; width: 18px; }   /* room past the fade */
.chat-chip {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--w-line); background: var(--w-panel);
  color: var(--w-text); font: 500 13.5px/1 var(--w-sans); letter-spacing: -.005em;
  white-space: nowrap; cursor: pointer;
  transition: background .2s, color .2s, border-color .2s, transform .3s var(--w-spring);
}
.chat-chip:hover { border-color: rgb(var(--w-fg-rgb) / .24); background: var(--w-panel-2); transform: translateY(-1px); }

/* ---- input ---- */
.chat-form {
  display: flex; gap: 8px; align-items: center; flex: none;
  padding: 10px 12px 8px;
  border-top: 1px solid var(--w-line-soft);
}
.chat-input {
  flex: 1; min-width: 0; min-height: 46px; padding: 0 16px;
  border-radius: 99px; border: 1px solid var(--w-line);
  background: var(--w-panel-2); color: var(--w-text);
  font: 400 15px/1.2 var(--w-sans);
  transition: border-color .2s, box-shadow .2s, background-color .2s;
}
.chat-input::placeholder { color: var(--w-muted); opacity: 1; }
.chat-input:focus {
  outline: none; background: var(--w-panel);
  border-color: rgb(255 27 141 / .55); box-shadow: 0 0 0 3px rgb(255 27 141 / .14);
}
.chat .chat-input:focus-visible { outline: none; }
.chat-send {
  flex: none; display: grid; place-items: center;
  width: 46px; height: 46px; padding: 0; border: 0; border-radius: 50%;
  background: var(--w-text); color: var(--w-panel); cursor: pointer;
  transition: transform .35s var(--w-spring), background .25s, color .25s;
}
.chat-send:hover { background: var(--w-grad-diag); color: #151114; transform: translateX(2px); }
.chat-foot {
  margin: 0; padding: 0 14px 10px; text-align: center;
  font-size: 11.5px; font-weight: 500; color: var(--w-muted);
}

/* touch screens: full 44px targets, 16px input (no iOS zoom) */
@media (pointer: coarse) {
  .chat-act, .chat-chip { min-height: 44px; }
  .chat-input { font-size: 16px; }
}

/* ---- tablets & phones: lift above the bottom tab bar ----
   (the soundtrack's round button sits at left:16px on the same
   line — the assistant stays on the right) */
@media (max-width: 899px) {
  .chat-launcher { right: 16px; bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }
  .chat-nudge { right: 16px; bottom: calc(92px + 58px + 12px + env(safe-area-inset-bottom, 0px)); }
  .chat-panel {
    right: 16px;
    bottom: calc(92px + 58px + 12px + env(safe-area-inset-bottom, 0px));
    height: min(560px, calc(100dvh - 190px));
  }
}

/* ---- parked over the hero (chat.js sets .is-parked below 900px) ---- */
.chat.is-parked:not(.is-open) .chat-launcher,
.chat.is-parked .chat-nudge { opacity: 0; pointer-events: none; transform: translateY(14px) scale(.85); }

/* ---- bottom sheet (phones + landscape phones; chat.js sets .is-sheet) ---- */
.chat.is-sheet-open .chat-launcher { opacity: 0; pointer-events: none; transform: scale(.8); }
.chat-panel.is-sheet {
  left: 0; right: 0; bottom: var(--chat-kb, 0px);
  width: 100%; max-width: none;
  height: min(86svh, calc(var(--chat-vh, 100svh) - 10px));
  border-radius: 22px 22px 0 0; border-bottom: 0;
  transform-origin: bottom center;
  opacity: 1; transform: translateY(102%);
  transition: transform .45s var(--w-ease);
}
.chat-panel.is-sheet.is-open { transform: none; }
.chat-panel.is-sheet.is-dragging { transition: none; }
.chat-panel.is-sheet .chat-handle {
  display: flex; justify-content: center; align-items: center; height: 22px; flex: none;
  cursor: grab; touch-action: none;
}
.chat-panel.is-sheet .chat-handle::before {
  content: ''; width: 40px; height: 4px; border-radius: 4px; background: rgb(var(--w-fg-rgb) / .18);
}
.chat-panel.is-sheet .chat-head { padding-top: 4px; touch-action: none; }
.chat-panel.is-sheet .chat-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
@media (max-height: 520px) {
  /* landscape phones: every pixel of height goes to the log */
  .chat-panel.is-sheet .chat-foot { display: none; }
  .chat-panel.is-sheet .chat-head { padding-bottom: 8px; }
}

@media (max-width: 640px) {
  .chat-msg { max-width: 94%; }
  .chat-head { gap: 10px; }
}

/* ============================================================
   Reduced motion: no slides, scales, bobbing or pulsing
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .tst, .tst.is-in, .tst.is-out,
  .pal-dialog, .pal.is-open .pal-dialog,
  .lb-slide, .lb:not(.is-open) .lb-slide,
  .lb-slide.from-left, .lb-slide.from-right, .lb-slide.to-left, .lb-slide.to-right,
  .chat-panel, .chat-panel.is-open, .chat-nudge, .chat-nudge.is-in {
    transform: none !important;
  }
  .tst, .lb, .lb-slide, .pal-backdrop, .pal-dialog, .chat-panel, .chat-nudge, .chat-scrim,
  .chat-launcher, .chat-launcher-av, .chat-launcher-x {
    transition-duration: .01ms !important;
  }
  .pal-item.is-active .pal-icon { transform: none; }
  .chat-launcher::before, .chat-online::after { animation: none; display: none; }
  .chat-msg.is-new { animation: none; }
  .chat-typing i { animation: none; opacity: .7; }
  .lb-slide.is-loading::after { animation-duration: 2.4s; }
  /* the sheet has no slide-in, so keep it hidden until opened */
  .chat-panel.is-sheet { opacity: 0; }
  .chat-panel.is-sheet.is-open { opacity: 1; }
}
