/* ==========================================================================
   CMU Student Compass — Immersive design system · COMPANIONS  (workstream G)

   1 · พี่ทิศ      floating avatar + speech bubble               #sprite-portal subtree
   2 · Help        launcher, chat sheet, target ring, callout    .tid-help-*
   3 · Q&A tab     "ถามได้นะ!" — topic cards + chat thread        #qa-panel subtree

   Cascade notes
   · Everything here is unlayered, so it beats the legacy sheet (imported into `@layer legacy`).
   · Legacy `!important` declarations (launcher hiding, target ring) are beaten from `@layer imm-force`.
   · Unlayered `!important` is used only against inline styles written by compass.js / qa_engine.js;
     every use says why.
   · State hooks published by companions.js: #sprite.imm-tid-head / .imm-tid-rested,
     #bubble.imm-is-empty / .imm-is-data / .imm-is-rested / .imm-pop-b, html.imm-help-open /
     .imm-help-pointing / .imm-help-ring-on / .imm-qa-on, body > .imm-help-ring (overlay ring, --_r),
     .tid-help-panel.imm-is-loading, .tid-help-target-callout.imm-is-below,
     .qa-wrap[data-imm-qa="pick|compose|waiting|streaming|done|error"][data-imm-full].
     All of them are progressive: without that script every component still works.
   · Strict legacy contracts kept: #bubble.speech-bubble.speech-bubble-bottom-left > p, inline
     left/bottom/display on #sprite / #bubble, [hidden] on the help panel / launcher / callout, the
     z-index ladder (9999 · 10020 · 10030 · 10040), .qa-head / .q-row / .chk and every Q&A id.
   ========================================================================== */

/* The help-target ring animates through registered custom properties: the legacy sheet pins `box-shadow`
   with !important, and an animation cannot override an important declaration — but it can drive a
   variable that the important declaration reads. */
@property --imm-hl-spread { syntax: '<length>'; inherits: false; initial-value: 5px; }
@property --imm-hl-alpha { syntax: '<number>'; inherits: false; initial-value: 0.5; }

/* shared: three bouncing dots drawn by one box (typing / streaming indicators) */
@keyframes imm-co-dots {
  0%, 100% { background-position: 0% 50%, 50% 50%, 100% 50%; }
  20% { background-position: 0% 0%, 50% 50%, 100% 50%; }
  40% { background-position: 0% 100%, 50% 0%, 100% 50%; }
  60% { background-position: 0% 50%, 50% 100%, 100% 0%; }
  80% { background-position: 0% 50%, 50% 50%, 100% 100%; }
}

/* ==========================================================================
   1 · พี่ทิศ — avatar + speech bubble
   ========================================================================== */
#sprite {
  /* compass.js pins the sprite with inline `left:12px; bottom:12px` — !important is required to add the
     safe-area insets (notch / home indicator) on top of that inline value */
  left: max(12px, var(--imm-safe-l)) !important;
  bottom: max(12px, var(--imm-safe-b)) !important;
  -webkit-user-select: none; user-select: none;
  transition: left 0.6s var(--imm-ease-out), bottom 0.6s var(--imm-ease-out), opacity 0.45s ease, visibility 0s linear 0s;
}

/* soft contact shadow under the full-body artwork (breathes with the idle float) */
#sprite::before {
  content: ''; position: absolute; z-index: 0; left: 8%; right: 8%; bottom: -6px; height: 14px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(27, 24, 56, 0.36), rgba(27, 24, 56, 0));
  pointer-events: none;
  animation: imm-tid-shadow 6.5s ease-in-out 1s infinite;
}
#sprite.imm-tid-head::before { display: none; }

#avatar {
  position: relative; z-index: 1; display: block;
  width: clamp(64px, 11vmin, 140px); height: auto;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 8px 10px rgba(27, 24, 56, 0.24));
  /* the float uses the individual `translate` / `rotate` properties so it composes with `scale` (tucked state) */
  animation: imm-tid-enter 0.9s var(--imm-ease-spring) backwards, imm-tid-float 6.5s ease-in-out 1s infinite;
  transition: scale 0.6s var(--imm-ease-spring), opacity 0.4s ease;
}
/* head-only artwork: compass.js picks it at ≤768px and writes inline `width:60px` → a chat-head medallion */
#avatar[style*='width'] {
  box-sizing: border-box; height: 60px; padding: 2px; border-radius: 50%; object-fit: contain;
  background: radial-gradient(circle at 50% 32%, #fff 0%, var(--imm-cream) 78%);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--imm-line-gold), 0 10px 22px rgba(27, 24, 56, 0.3);
  filter: none;
  transform-origin: 0 100%;
}
#avatar.imm-emote-a { animation: imm-tid-emote-a 0.5s var(--imm-ease-out), imm-tid-float 6.5s ease-in-out 1s infinite; }
#avatar.imm-emote-b { animation: imm-tid-emote-b 0.5s var(--imm-ease-out), imm-tid-float 6.5s ease-in-out 1s infinite; }

@keyframes imm-tid-enter { from { opacity: 0; transform: translate3d(0, 34px, 0) scale(0.6); } }
@keyframes imm-tid-float { 0%, 100% { translate: 0 0; rotate: 0deg; } 50% { translate: 0 -7px; rotate: -1.2deg; } }
@keyframes imm-tid-shadow { 0%, 100% { transform: scaleX(1); opacity: 1; } 50% { transform: scaleX(0.84); opacity: 0.66; } }
@keyframes imm-tid-emote-a { 0% { transform: none; } 35% { transform: scale(1.09, 0.93); } 70% { transform: scale(0.97, 1.04); } 100% { transform: none; } }
@keyframes imm-tid-emote-b { 0% { transform: none; } 35% { transform: scale(1.09, 0.93); } 70% { transform: scale(0.97, 1.04); } 100% { transform: none; } }

/* ---- speech bubble: luminous glass with a tail ---------------------------------------------- */
#bubble {
  left: calc(100% - 20px); top: auto; bottom: calc(100% - 36px);
  width: max-content; min-width: 0; max-width: min(21.5rem, calc(100vw - 100% - 44px));
  margin: 0; padding: 0; overflow: visible; transform: none;
  color: var(--imm-ink); font-size: var(--imm-fs-sm); font-weight: 400; line-height: 1.5;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, var(--imm-glass-bg-strong) 100%);
  border: 1px solid var(--imm-glass-border);
  border-radius: 20px 20px 20px 6px;
  box-shadow: var(--imm-shadow-2), 0 0 0 1px rgba(104, 104, 172, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  transform-origin: 0 100%;
  /* fill `backwards` only: afterwards the folded state below may transition `transform` freely */
  animation: imm-tid-pop 0.55s var(--imm-ease-spring) backwards;
  transition: opacity 0.3s ease, transform 0.5s var(--imm-ease-spring), visibility 0s linear 0s;
}
#bubble.imm-pop-b { animation-name: imm-tid-pop-b; } /* same keyframes under another name → replays when the text changes */
@keyframes imm-tid-pop { from { opacity: 0; transform: translate3d(-8px, 12px, 0) scale(0.6); } }
@keyframes imm-tid-pop-b { from { opacity: 0; transform: translate3d(-8px, 12px, 0) scale(0.6); } }

/* the text inset is a margin, not padding: a line-clamped box paints its hidden lines into its own padding */
#bubble > p {
  margin: 10px 16px 11px; padding: 0;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4; overflow: hidden;
  overflow-wrap: anywhere;
}
#bubble > p b, #bubble > p strong { font-weight: 600; }
/* chart read-outs arrive as <span style="color:{series colour}">; keep the hue, deepen it so pale series colours
   (gold, sky blue) stay readable on the light glass */
#bubble > p [style*='color'] { filter: brightness(0.62) saturate(1.5); }
/* empty bubble: the <p> carries the padding, so it collapses; :has() / the script remove the shell too.
   !important beats the inline `display:block` that changeTooltip('') leaves for 4 s. */
#bubble > p:empty { display: none; }
#bubble.imm-is-empty { display: none !important; }
@supports selector(:has(*)) {
  #bubble:has(> p:empty) { display: none !important; }
}

/* tail — a clipped, rotated square that continues the glass edge (legacy ::after triangle retired) */
#bubble::after { content: none; }
#bubble::before {
  content: ''; position: absolute; left: 17px; bottom: -7px; width: 13px; height: 13px;
  background: var(--imm-glass-bg-strong);
  border: solid var(--imm-glass-border); border-width: 0 1px 1px 0; border-bottom-right-radius: 4px;
  transform: rotate(58deg) skewX(18deg);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}

/* ---- folded ("…") state ---------------------------------------------------------------------------
   companions.js folds chatter after a few seconds so it never buries content (chart read-outs never fold);
   พี่ทิศ then wears a small gold "…" chip and becomes tappable / hoverable to unfold it again. */
#bubble.imm-is-rested {
  opacity: 0; visibility: hidden; transform: translate3d(-10px, 6px, 0) scale(0.4);
  transition: opacity 0.3s ease, transform 0.45s var(--imm-ease-in-out), visibility 0s linear 0.45s;
}
#sprite::after {
  content: ''; position: absolute; z-index: 2; left: calc(100% - 22px); top: 4%; box-sizing: border-box; width: 30px; height: 18px;
  border-radius: var(--imm-r-pill); border: 1.5px solid #fff; color: #2b1d00;
  --_dot: no-repeat radial-gradient(circle closest-side, currentColor 88%, transparent);
  background: var(--_dot) 0% 50%, var(--_dot) 50% 50%, var(--_dot) 100% 50%, var(--imm-grad-gold);
  background-size: 5px 5px, 5px 5px, 5px 5px, 100% 100%;
  background-origin: content-box, content-box, content-box, border-box; padding: 0 5px;
  box-shadow: 0 4px 10px rgba(27, 24, 56, 0.28);
  opacity: 0; scale: 0.2; transform-origin: 0 100%; pointer-events: none;
  transition: opacity 0.3s ease, scale 0.5s var(--imm-ease-spring);
}
#sprite.imm-tid-rested::after { opacity: 1; scale: 1; }
/* the folded avatar becomes tappable (unfolds the bubble); legacy img / portal are click-through otherwise */
#sprite.imm-tid-rested #avatar { pointer-events: auto; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---- results / accessibility modal open: step back a little on mid-size screens ------------- */
@media (min-width: 769px) and (max-width: 1500px) and (min-height: 521px) {
  body.no-scroll #avatar { scale: 0.82; transform-origin: 0 100%; }
  body.no-scroll #bubble { left: calc(82% - 18px); bottom: calc(82% - 30px); }
  body.no-scroll #sprite::before { right: 26%; left: 2%; }
  body.no-scroll #sprite::after { left: calc(82% - 22px); top: calc(18% + 4%); }
}

/* ---- small screens: a compact translucent strip between the avatar and the help launcher ----- */
@media (max-width: 768px), (max-height: 520px) {
  #bubble {
    left: calc(100% + 12px); bottom: 5px;
    /* viewport − avatar − gaps − the 52px help launcher on the right */
    max-width: calc(100vw - 100% - 2 * max(12px, var(--imm-safe-l)) - 12px - 62px);
    font-size: var(--imm-fs-xs); line-height: 1.42;
    background: rgba(255, 253, 248, 0.9);
    border-radius: 16px 16px 16px 5px;
    box-shadow: var(--imm-shadow-1), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  }
  #bubble > p { margin: 7px 12px 8px; -webkit-line-clamp: 2; line-clamp: 2; }
  /* chart read-outs (rich markup) are data, not chatter: never cut them at two lines */
  #bubble.imm-is-data > p { -webkit-line-clamp: 5; line-clamp: 5; }
  #bubble::before { left: -6px; bottom: 10px; transform: rotate(135deg); background: rgba(255, 253, 248, 0.9); }
  #sprite::after { left: calc(100% - 16px); top: -5px; }

  /* modal open: shrink and tuck into the corner so result content and the tab bar stay clear */
  body.no-scroll #sprite { left: max(8px, var(--imm-safe-l)) !important; bottom: max(8px, var(--imm-safe-b)) !important; } /* !important: inline left/bottom, see above */
  body.no-scroll #avatar { scale: 0.74; transform-origin: 0 100%; opacity: 0.96; }
  body.no-scroll #bubble { left: calc(74% + 10px); bottom: 2px; max-width: calc(100vw - 74% - 2 * max(8px, var(--imm-safe-l)) - 10px - 66px); }
  body.no-scroll #sprite::after { left: calc(74% - 14px); top: calc(26% - 6px); }
  body.no-scroll #sprite::before { display: none; }
}

/* Q&A tab: พี่ทิศ moves into the conversation heading, so the floating copy steps aside (no chart read-outs there) */
html.imm-qa-on #sprite { opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0s linear 0.3s; }

/* landscape phones keep the full-body artwork (viewport was wider than 768px at load): bubble beside the head */
@media (max-height: 520px) and (min-width: 769px) {
  #avatar:not([style*='width']) { width: 56px; }
  #sprite:not(.imm-tid-head) #bubble { bottom: 46%; }
  body.no-scroll #sprite:not(.imm-tid-head) #bubble { bottom: 34%; }
}
/* very narrow screens: no room beside the avatar → sit just above it */
@media (max-width: 340px) {
  #bubble, body.no-scroll #bubble { left: 0; bottom: calc(100% + 12px); max-width: calc(100vw - 2 * max(12px, var(--imm-safe-l))); border-radius: 16px 16px 16px 5px; }
  body.no-scroll #bubble { bottom: calc(74% + 12px); }
  #bubble::before { left: 18px; bottom: -6px; transform: rotate(45deg); clip-path: polygon(100% 0, 100% 100%, 0 100%); }
}

/* ==========================================================================
   2 · Help assistant
   ========================================================================== */
.tid-help-widget {
  --_r0: max(18px, var(--imm-safe-r));
  --_b0: max(18px, var(--imm-safe-b));
  right: var(--_r0); bottom: var(--_b0);
  display: block; /* legacy flex column let the (hidden) panel push the launcher; the panel is positioned now */
  font-family: inherit;
}

/* ---- launcher: glass pill with the compass ----------------------------------------------------- */
.tid-help-toggle {
  position: relative; z-index: 2; isolation: isolate;
  display: inline-grid; grid-template-columns: 36px 1fr; align-items: center; column-gap: 10px;
  min-height: 52px; padding: 7px 18px 7px 7px;
  border: 1px solid var(--imm-glass-border); border-radius: var(--imm-r-pill);
  color: var(--imm-violet-800);
  background: var(--imm-glass-bg-strong);
  -webkit-backdrop-filter: blur(var(--imm-blur)) saturate(1.35); backdrop-filter: blur(var(--imm-blur)) saturate(1.35);
  box-shadow: var(--imm-shadow-2), 0 0 0 1px rgba(250, 172, 30, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transform-origin: 100% 100%;
  animation: none; /* legacy tidHelpBounce retired */
  /* no spring easing anywhere in the guide (owner request 2026-11-17: no bouncing) */
  transition: transform 0.5s var(--imm-ease-out), grid-template-columns 0.6s var(--imm-ease-out), column-gap 0.6s var(--imm-ease-out),
    padding 0.6s var(--imm-ease-out), color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease, background-color 0.4s ease;
}
@layer imm-force {
  /* legacy: `.tid-help-toggle[hidden], .is-hidden { display:none !important }`. In the new design the launcher
     stays on screen as the active pill (and close control) while its panel is open. */
  .tid-help-toggle[hidden], .tid-help-toggle.is-hidden { display: inline-grid !important; }
}
.tid-help-toggle::before { /* active wash (gradients cannot transition, so it cross-fades) */
  content: ''; position: absolute; inset: -1px; z-index: -1; border-radius: inherit;
  background: var(--imm-grad-brand); opacity: 0; transition: opacity 0.4s ease;
}
.tid-help-toggle::after { /* slow sonar ping around the compass */
  content: ''; position: absolute; left: 7px; top: 50%; box-sizing: border-box; width: 36px; height: 36px; margin-top: -18px; border-radius: 50%;
  border: 1.5px solid var(--imm-gold-400); opacity: 0; pointer-events: none;
  animation: imm-help-ping 5.2s var(--imm-ease-out) 2s infinite;
}
@keyframes imm-help-ping { 0%, 62% { transform: scale(0.9); opacity: 0; } 66% { opacity: 0.75; } 100% { transform: scale(2); opacity: 0; } }
.tid-help-toggle img {
  width: 36px; height: 36px; padding: 3px; border-radius: 50%; object-fit: contain;
  background: radial-gradient(circle at 50% 35%, #fff, var(--imm-cream));
  box-shadow: 0 0 0 1px var(--imm-line-gold), 0 2px 6px rgba(27, 24, 56, 0.16);
  transition: rotate 0.9s var(--imm-ease-out);
}
.tid-help-toggle span {
  min-width: 0; overflow: hidden; white-space: nowrap;
  font-size: var(--imm-fs-sm); font-weight: 500; line-height: 1.3;
  transition: opacity 0.4s ease;
}
@media (hover: hover) {
  .tid-help-toggle:hover { transform: translate3d(0, -2px, 0); color: var(--imm-violet-900); background: #fff; box-shadow: var(--imm-shadow-3), 0 0 0 1px rgba(250, 172, 30, 0.55); }
  .tid-help-toggle:hover img { rotate: 45deg; }
}
.tid-help-toggle:focus-visible { outline: 2px solid var(--imm-gold-400); outline-offset: 3px; border-radius: var(--imm-r-pill); color: var(--imm-violet-900); background: #fff; }
.tid-help-toggle[aria-expanded='true'] { color: #fff; border-color: rgba(255, 255, 255, 0.4); box-shadow: var(--imm-shadow-violet), inset 0 1px 0 rgba(255, 255, 255, 0.28); }
.tid-help-toggle[aria-expanded='true']::before { opacity: 1; }
.tid-help-toggle[aria-expanded='true']::after { animation: none; }
.tid-help-toggle[aria-expanded='true'] img { rotate: 360deg; }

/* ---- panel: paper sheet with a dawn header ------------------------------------------------------ */
.tid-help-panel {
  position: absolute; z-index: 1; right: 0; bottom: calc(100% + 12px);
  display: flex; flex-direction: column;
  width: min(25rem, calc(100vw - 2 * var(--_r0)));
  height: min(38.5rem, calc(var(--imm-vh) - var(--_b0) - 52px - 12px - 14px)); max-height: none;
  overflow: visible; /* children carry the corner radii, so nothing needs clipping */
  color: var(--imm-ink);
  background: var(--imm-surface);
  border: 1px solid var(--imm-glass-border); border-radius: var(--imm-r-lg);
  box-shadow: var(--imm-shadow-3), 0 0 0 1px rgba(104, 104, 172, 0.12);
  -webkit-backdrop-filter: none; backdrop-filter: none;
  transform-origin: calc(100% - 28px) calc(100% + 30px);
  /* negative insets keep the shadow; the "pointing" state folds the sheet by animating the bottom inset */
  clip-path: inset(-80px -80px -100px -80px round var(--imm-r-lg));
  transition: opacity 0.35s ease, transform 0.6s var(--imm-ease-out), clip-path 0.7s var(--imm-ease-out), visibility 0s linear 0s;
}
/* Closed: stays in the layout (so open AND close animate) but is `visibility:hidden` — the focus order and the
   assistant's own "is this target visible" test both rely on that. Open is immediate (input is focused at 0 ms). */
.tid-help-panel[hidden] {
  display: flex; visibility: hidden; opacity: 0; pointer-events: none;
  transform: translate3d(0, 22px, 0) scale(0.86);
  transition: opacity 0.22s ease, transform 0.32s var(--imm-ease-in-out), visibility 0s linear 0.32s;
}

.tid-help-header {
  position: relative; flex: none; isolation: isolate; overflow: hidden;
  min-height: 68px; padding: 12px 12px 12px 16px; gap: 12px;
  color: var(--imm-ink-inv);
  background:
    radial-gradient(130% 150% at 100% -10%, rgba(250, 172, 30, 0.42) 0%, rgba(240, 163, 180, 0.2) 34%, rgba(240, 163, 180, 0) 62%),
    linear-gradient(118deg, var(--imm-violet-950) 0%, var(--imm-violet-800) 48%, var(--imm-violet-600) 100%);
  border-bottom: 1px solid var(--imm-line-gold);
  border-radius: calc(var(--imm-r-lg) - 1px) calc(var(--imm-r-lg) - 1px) 0 0;
}
.tid-help-header::before { /* compass rings, half off the right edge */
  content: ''; position: absolute; z-index: -1; right: -34px; top: 50%; width: 170px; height: 170px; margin-top: -85px; border-radius: 50%;
  background:
    repeating-radial-gradient(circle, rgba(255, 255, 255, 0) 0 21px, rgba(255, 255, 255, 0.16) 21px 22px),
    repeating-conic-gradient(from 0deg, rgba(255, 223, 148, 0.5) 0 1deg, transparent 1deg 15deg);
  -webkit-mask: radial-gradient(circle, transparent 0 34%, #000 35% 70%, transparent 71%); mask: radial-gradient(circle, transparent 0 34%, #000 35% 70%, transparent 71%);
  opacity: 0.55;
}
.tid-help-title { gap: 12px; }
.tid-help-title img {
  width: 44px; height: 44px; padding: 4px; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #fff, var(--imm-cream));
  box-shadow: 0 0 0 1px var(--imm-line-gold), 0 0 22px rgba(250, 172, 30, 0.45);
}
.tid-help-title strong { color: #fff; font-size: var(--imm-fs-md); font-weight: 600; line-height: 1.3; }
.tid-help-title span { margin-top: 1px; color: var(--imm-gold-200); font-size: var(--imm-fs-xs); font-weight: 300; line-height: 1.4; }
.tid-help-close {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  color: #fff; background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.26);
  transition: background-color 0.3s ease, rotate 0.5s var(--imm-ease-out), border-color 0.3s ease;
}
.tid-help-close:hover, .tid-help-close:focus-visible { background: rgba(255, 255, 255, 0.24); border-color: var(--imm-gold-300); rotate: 90deg; }
.tid-help-close:focus-visible { outline: 2px solid var(--imm-gold-400); outline-offset: 2px; border-radius: 50%; }
.tid-help-icon { width: 20px; height: 20px; }

.tid-help-messages {
  flex: 1 1 auto; min-height: 0; max-height: none; padding: 16px 14px 6px;
  /* a faint compass dial sits in the empty part of the conversation (background of a scroller stays put) */
  --_wm: 50% 62%;
  background:
    radial-gradient(circle at var(--_wm), rgba(250, 172, 30, 0.4) 0 2.5px, transparent 3px 61px, rgba(104, 104, 172, 0.07) 61.5px 62.5px, transparent 63px 95px, rgba(250, 172, 30, 0.14) 95.5px 96.5px, transparent 97px),
    radial-gradient(circle at var(--_wm), var(--imm-surface) 0 74px, transparent 74.5px 86px, var(--imm-surface) 86.5px),
    repeating-conic-gradient(from -0.5deg at var(--_wm), rgba(104, 104, 172, 0.1) 0 1deg, transparent 1deg 10deg),
    var(--imm-surface);
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: var(--imm-violet-200) transparent;
}
.tid-help-message { align-items: flex-end; gap: 8px; margin: 0 0 12px; animation: imm-fade-up 0.5s var(--imm-ease-out) backwards; }
.tid-help-message--assistant::before { /* the compass speaks */
  content: ''; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--imm-cream) url('../../images/top-sm.webp') center / 80% no-repeat;
  box-shadow: 0 0 0 1px var(--imm-line-gold);
}
.tid-help-message-bubble {
  max-width: min(100% - 40px, 22rem); padding: 10px 14px;
  color: var(--imm-ink); font-size: var(--imm-fs-sm); line-height: 1.62;
  background: #fff; border: 1px solid var(--imm-line); border-radius: 18px 18px 18px 6px;
  box-shadow: var(--imm-shadow-1);
}
.tid-help-message--user .tid-help-message-bubble {
  max-width: 84%; color: #fff; background: var(--imm-grad-brand); border-color: transparent; border-radius: 18px 18px 6px 18px;
  box-shadow: 0 8px 20px rgba(104, 104, 172, 0.3);
}
.tid-help-message-bubble p { margin: 0 0 0.6em; }
.tid-help-message-bubble p:last-child { margin-bottom: 0; }
.tid-help-message-bubble ul, .tid-help-message-bubble ol { margin: 0.4em 0 0.5em 1.25em; padding: 0; }
.tid-help-message-bubble li { margin: 0.25em 0; }
.tid-help-message-bubble li::marker { color: var(--imm-gold-500); }
.tid-help-message-bubble strong, .tid-help-message-bubble b { font-weight: 600; color: var(--imm-violet-800); }
.tid-help-message-bubble code { padding: 0.08em 0.4em; border-radius: 6px; background: var(--imm-violet-50); font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 0.9em; }
.tid-help-message-bubble pre { margin: 0.5em 0; padding: 0.7em 0.9em; overflow-x: auto; border-radius: var(--imm-r-sm); background: var(--imm-violet-50); }
.tid-help-message-bubble pre code { padding: 0; background: none; }
/* typing dots after the answer while the request is running (class from companions.js) */
.tid-help-panel.imm-is-loading .tid-help-message--assistant:last-child .tid-help-message-bubble::after {
  content: ''; display: block; width: 30px; height: 12px; margin-top: 6px; color: var(--imm-violet-400);
  --_dot: no-repeat radial-gradient(circle closest-side, currentColor 90%, transparent);
  background: var(--_dot) 0% 50%, var(--_dot) 50% 50%, var(--_dot) 100% 50%; background-size: 10px 6px;
  animation: imm-co-dots 1.15s linear infinite;
}

.tid-help-chips {
  flex: none; gap: 8px; padding: 8px 14px 4px; background: var(--imm-surface);
  scroll-snap-type: x proximity; scroll-padding-inline: 14px; overscroll-behavior-x: contain; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 26px), transparent 100%);
}
.tid-help-chips::-webkit-scrollbar { display: none; }
.tid-help-chip {
  min-height: 40px; padding: 0 14px; scroll-snap-align: start;
  border: 1px solid var(--imm-line-strong); border-radius: var(--imm-r-pill);
  color: var(--imm-violet-700); background: rgba(104, 104, 172, 0.07);
  font-family: inherit; font-size: var(--imm-fs-xs); font-weight: 500; line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease, transform 0.4s var(--imm-ease-out);
}
.tid-help-chip:hover, .tid-help-chip:focus-visible { border-color: var(--imm-gold-400); background: var(--imm-gold-50); color: var(--imm-gold-700); transform: translate3d(0, -1px, 0); }
.tid-help-chip:focus-visible { outline: 2px solid var(--imm-gold-400); outline-offset: 2px; border-radius: var(--imm-r-pill); }

.tid-help-form {
  flex: none; gap: 8px; padding: 10px 12px 12px;
  background: var(--imm-surface); border-top: 0;
  border-radius: 0 0 calc(var(--imm-r-lg) - 1px) calc(var(--imm-r-lg) - 1px);
}
.tid-help-input {
  min-height: 46px; max-height: 120px; /* 120px is hard-coded in help_assistant.js autoResizeInput */
  padding: 11px 16px; border: 1px solid var(--imm-line-strong); border-radius: 23px;
  color: var(--imm-ink); background: #fff;
  font-family: inherit; font-size: 1rem; line-height: 1.45; /* ≥16px: no focus zoom on iOS */
  box-shadow: inset 0 1px 2px rgba(27, 24, 56, 0.05);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.tid-help-input::placeholder { color: var(--imm-ink-3); opacity: 0.85; }
.tid-help-input:focus { border-color: var(--imm-gold-400); box-shadow: 0 0 0 4px rgba(250, 172, 30, 0.22); }
/* the gold border + halo is the focus indicator; drop the global outline so it does not draw a third ring
   (the in-app "focus highlight" setting is more specific and still adds its strong outline) */
.tid-help-input:focus-visible { outline: none; }
.tid-help-input:disabled { background: var(--imm-violet-50); color: var(--imm-ink-3); }
.tid-help-submit {
  position: relative; flex: 0 0 46px; width: 46px; height: 46px; border-radius: 50%;
  color: #2b1d00; background: var(--imm-grad-gold);
  box-shadow: 0 8px 20px rgba(250, 172, 30, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.4s var(--imm-ease-out), box-shadow 0.4s ease, filter 0.3s ease;
}
.tid-help-submit:hover, .tid-help-submit:focus-visible { background: var(--imm-grad-gold); transform: translate3d(0, -2px, 0); filter: saturate(1.15); }
.tid-help-submit:focus-visible { outline: 2px solid var(--imm-violet-500); outline-offset: 2px; border-radius: 50%; }
.tid-help-submit:active { transform: scale(0.94); }
.tid-help-form.is-loading .tid-help-submit { opacity: 1; cursor: progress; transform: none; }
.tid-help-form.is-loading .tid-help-submit .tid-help-icon { opacity: 0; }
.tid-help-form.is-loading .tid-help-submit::after { /* compass-ring spinner replaces the paper plane */
  content: ''; position: absolute; inset: 12px; border-radius: 50%; border: 2.5px solid rgba(43, 29, 0, 0.25); border-top-color: #2b1d00;
  animation: imm-spin 0.9s linear infinite;
}

/* open choreography — children rise one after another (runs only while the panel is open) */
.tid-help-panel:not([hidden]) .tid-help-title,
.tid-help-panel:not([hidden]) .tid-help-chip,
.tid-help-panel:not([hidden]) .tid-help-form > * { animation: imm-help-rise 0.7s var(--imm-ease-out) backwards; }
.tid-help-panel:not([hidden]) .tid-help-title { animation-delay: 0.1s; }
.tid-help-panel:not([hidden]) .tid-help-chip:nth-child(1) { animation-delay: 0.22s; }
.tid-help-panel:not([hidden]) .tid-help-chip:nth-child(2) { animation-delay: 0.29s; }
.tid-help-panel:not([hidden]) .tid-help-chip:nth-child(3) { animation-delay: 0.36s; }
.tid-help-panel:not([hidden]) .tid-help-chip:nth-child(n + 4) { animation-delay: 0.42s; }
.tid-help-panel:not([hidden]) .tid-help-form > * { animation-delay: 0.4s; }
@keyframes imm-help-rise { from { opacity: 0; transform: translate3d(0, 16px, 0); } }

/* pointing at something on the page: the sheet folds down to its header so the gold ring is visible
   (html.imm-help-pointing is set by companions.js only while the sheet would cover the target) */
html.imm-help-pointing .tid-help-panel:not([hidden]) {
  transform: translate3d(0, calc(100% - 68px), 0);
  clip-path: inset(-80px -80px calc(100% - 68px) -80px round var(--imm-r-lg));
  transition: opacity 0.35s ease, transform 0.7s var(--imm-ease-out), clip-path 0.7s var(--imm-ease-out), visibility 0s linear 0s;
}
html.imm-help-pointing .tid-help-header { cursor: pointer; }

/* ---- target ring: gold pulse --------------------------------------------------------------------- */
@layer imm-force {
  /* legacy declares outline + box-shadow with !important on whatever element the assistant points at */
  .tid-help-target-highlight {
    outline: 2px solid var(--imm-gold-400) !important;
    box-shadow:
      0 0 0 var(--imm-hl-spread) rgba(250, 172, 30, var(--imm-hl-alpha)),
      0 0 0 calc(var(--imm-hl-spread) * 2.4) rgba(250, 172, 30, calc(var(--imm-hl-alpha) * 0.32)),
      0 0 46px rgba(250, 172, 30, 0.42) !important;
  }
}
.tid-help-target-highlight { outline-offset: 4px; animation: imm-help-target 1.5s var(--imm-ease-out) infinite; }
@keyframes imm-help-target { 0% { --imm-hl-spread: 0px; --imm-hl-alpha: 0.7; } 100% { --imm-hl-spread: 16px; --imm-hl-alpha: 0; } }

/* With companions.js the ring is drawn by a fixed overlay (body > .imm-help-ring) that follows the target and
   takes the shape of its card; the class then only keeps the legacy lift (position / z-index). */
@layer imm-force {
  html.imm-help-ring-on .tid-help-target-highlight { outline-color: transparent !important; box-shadow: none !important; }
}
html.imm-help-ring-on .tid-help-target-highlight { animation: none; }

.imm-help-ring {
  --_r: 18px;
  position: fixed; left: 0; top: 0; z-index: 10020; /* help-highlight rung of the ladder: above พี่ทิศ, below the help widget */
  box-sizing: border-box; width: 0; height: 0; pointer-events: none;
  border-radius: calc(var(--_r) + 5px);
  outline: 2px solid var(--imm-gold-400); outline-offset: 5px;
  box-shadow:
    0 0 0 calc(5px + var(--imm-hl-spread)) rgba(250, 172, 30, var(--imm-hl-alpha)),
    0 0 44px 6px rgba(250, 172, 30, 0.3);
  opacity: 0; visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  animation: imm-help-target 1.6s var(--imm-ease-out) 0.5s infinite;
}
.imm-help-ring.is-on { opacity: 1; visibility: visible; transition: opacity 0.35s ease, visibility 0s linear 0s; }
.imm-help-ring::after { /* viewfinder brackets that lock on to the target */
  content: ''; position: absolute; inset: -15px;
  --_c: var(--imm-gold-300); --_l: 16px; --_w: 2px;
  background:
    linear-gradient(var(--_c), var(--_c)) 0 0 / var(--_l) var(--_w), linear-gradient(var(--_c), var(--_c)) 0 0 / var(--_w) var(--_l),
    linear-gradient(var(--_c), var(--_c)) 100% 0 / var(--_l) var(--_w), linear-gradient(var(--_c), var(--_c)) 100% 0 / var(--_w) var(--_l),
    linear-gradient(var(--_c), var(--_c)) 0 100% / var(--_l) var(--_w), linear-gradient(var(--_c), var(--_c)) 0 100% / var(--_w) var(--_l),
    linear-gradient(var(--_c), var(--_c)) 100% 100% / var(--_l) var(--_w), linear-gradient(var(--_c), var(--_c)) 100% 100% / var(--_w) var(--_l);
  background-repeat: no-repeat;
  filter: drop-shadow(0 0 6px rgba(250, 172, 30, 0.6));
}
.imm-help-ring.is-locked::after { animation: imm-help-lock 0.75s var(--imm-ease-out) backwards; }
@keyframes imm-help-lock { from { opacity: 0; inset: -46px; } 60% { opacity: 1; } }

/* ---- callout: dark glass with an arrow ----------------------------------------------------------- */
.tid-help-target-callout {
  max-width: min(19rem, calc(100vw - 24px)); padding: 9px 15px 9px 36px;
  color: var(--imm-ink-inv); font-family: inherit; font-size: var(--imm-fs-sm); font-weight: 500; line-height: 1.4;
  background: rgba(19, 16, 52, 0.84); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 14px;
  box-shadow: 0 18px 44px rgba(5, 4, 20, 0.46), 0 0 0 1px rgba(250, 172, 30, 0.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3); backdrop-filter: blur(14px) saturate(1.3);
}
/* translate only: help_assistant.js measures the callout's width/height while it appears */
.tid-help-target-callout:not([hidden]) { animation: imm-help-callout 0.45s var(--imm-ease-out) backwards; }
@keyframes imm-help-callout { from { opacity: 0; transform: translate3d(0, 8px, 0); } }
.tid-help-target-callout::before { /* gold bearing dot */
  content: ''; position: absolute; left: 14px; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 50%;
  background: var(--imm-grad-gold); box-shadow: 0 0 0 4px rgba(250, 172, 30, 0.28), 0 0 12px rgba(250, 172, 30, 0.7);
}
.tid-help-target-callout::after { /* arrow: follows the target horizontally; flips when the callout sits below it */
  left: var(--imm-arrow-x, 50%); bottom: -6.5px; width: 12px; height: 12px;
  background: rgba(19, 16, 52, 0.92); border: solid rgba(255, 255, 255, 0.2); border-width: 0 1px 1px 0;
  transform: translateX(-50%) rotate(45deg);
}
.tid-help-target-callout.imm-is-below::after { bottom: auto; top: -6.5px; border-width: 1px 0 0 1px; }

/* ---- tablets / landscape phones: compact chrome ------------------------------------------------ */
@media (max-height: 520px) and (min-width: 769px) {
  .tid-help-widget { --_r0: max(12px, var(--imm-safe-r)); --_b0: max(10px, var(--imm-safe-b)); }
  .tid-help-panel { width: min(27rem, 58vw); bottom: calc(100% + 8px); height: calc(var(--imm-vh) - var(--_b0) - 52px - 8px - 8px); }
  .tid-help-header { min-height: 52px; padding-block: 6px; }
  .tid-help-title img { width: 36px; height: 36px; }
  .tid-help-title span { display: none; }
  .tid-help-close { width: 40px; height: 40px; }
  .tid-help-messages { padding-top: 10px; }
  .tid-help-chips { padding-top: 4px; }
  .tid-help-form { padding: 6px 10px 8px; }
  html.imm-help-pointing .tid-help-panel:not([hidden]) { transform: translate3d(0, calc(100% - 52px), 0); clip-path: inset(-80px -80px calc(100% - 52px) -80px round var(--imm-r-lg)); }
  /* a phone on its side is still a phone: the launcher folds to the 52px compass and unfolds while open */
  .tid-help-toggle { grid-template-columns: 36px 0fr; column-gap: 0; padding: 7px; }
  .tid-help-toggle span { opacity: 0; }
  .tid-help-toggle[aria-expanded='true'] { grid-template-columns: 36px 1fr; column-gap: 10px; padding: 7px 18px 7px 7px; }
  .tid-help-toggle[aria-expanded='true'] span { opacity: 1; }
}

/* ---- phones: 52px compass button ⇄ bottom sheet -------------------------------------------------- */
@media (max-width: 768px) {
  .tid-help-widget {
    --_r0: max(12px, var(--imm-safe-r)); --_b0: max(12px, var(--imm-safe-b)); --_l0: max(12px, var(--imm-safe-l));
    /* sheet height: tall, but always inside the visible viewport (companions.js publishes the visual viewport
       height and the keyboard inset while the sheet is open) */
    --_sheet-h: min(38rem, 82vh, calc(var(--imm-vvh, 100vh) - 56px));
    --_head-h: 64px;
    left: 0; right: 0; bottom: var(--imm-kb, 0px);
  }
  @supports (height: 1dvh) {
    .tid-help-widget { --_sheet-h: min(38rem, 82dvh, calc(var(--imm-vvh, 100dvh) - 56px)); }
  }

  /* launcher: the 52px compass icon. It no longer flies up to become the sheet's title (owner report 2026-11-17:
     the springy flight overshot the sheet's top edge, so the icon and label left the frame, and a drag-to-close left
     them behind — "no bouncing"). It fades out where it is while the sheet rises with its own title, and fades back
     in as the sheet goes down. */
  .tid-help-toggle {
    position: absolute; left: calc(100% - 52px - var(--_r0)); bottom: var(--_b0); width: max-content;
    grid-template-columns: 36px 0fr; column-gap: 0; padding: 7px;
    transform-origin: 50% 50%;
    transition: opacity 0.3s ease 0.2s, visibility 0s linear 0s, transform 0.4s var(--imm-ease-out);
  }
  .tid-help-toggle span { opacity: 0; }
  .tid-help-toggle img { transition: none; }
  .tid-help-toggle[aria-expanded='true'] {
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity 0.18s ease, visibility 0s linear 0.18s;
  }
  .tid-help-toggle[aria-expanded='true']::before { opacity: 0; }

  .tid-help-panel {
    left: 0; right: 0; bottom: 0; width: 100%; height: var(--_sheet-h);
    border-width: 1px 0 0; border-radius: var(--imm-r-lg) var(--imm-r-lg) 0 0;
    box-shadow: 0 -18px 60px rgba(5, 4, 20, 0.38);
    transform-origin: 50% 100%; clip-path: none;
    transition: transform 0.7s var(--imm-ease-out), opacity 0.3s ease, visibility 0s linear 0s;
  }
  .tid-help-panel[hidden] {
    opacity: 1; transform: translate3d(0, 104%, 0);
    transition: transform 0.4s var(--imm-ease-in-out), visibility 0s linear 0.4s;
  }
  /* night scrim above the sheet (travels with it; click-through so the page stays usable, as before). It also fills
     the two wedges outside the sheet's rounded top corners (owner report 2026-11-17: the undimmed page showed through
     them as light notches) — masked to exactly those wedges, so the sheet's own top edge stays crisp. */
  .tid-help-panel::before {
    --_r: var(--imm-r-lg);
    content: ''; position: absolute; left: 0; right: 0; bottom: calc(100% + 1px - var(--_r)); height: 100vh; pointer-events: none;
    background: linear-gradient(0deg, rgba(10, 9, 32, 0.62) 0%, rgba(10, 9, 32, 0.34) 46%, rgba(10, 9, 32, 0) 100%);
    -webkit-mask:
      linear-gradient(#000, #000) top / 100% calc(100% - var(--_r)) no-repeat,
      radial-gradient(circle at 100% 100%, transparent calc(var(--_r) - 0.5px), #000 var(--_r)) left bottom / var(--_r) var(--_r) no-repeat,
      radial-gradient(circle at 0 100%, transparent calc(var(--_r) - 0.5px), #000 var(--_r)) right bottom / var(--_r) var(--_r) no-repeat;
    mask:
      linear-gradient(#000, #000) top / 100% calc(100% - var(--_r)) no-repeat,
      radial-gradient(circle at 100% 100%, transparent calc(var(--_r) - 0.5px), #000 var(--_r)) left bottom / var(--_r) var(--_r) no-repeat,
      radial-gradient(circle at 0 100%, transparent calc(var(--_r) - 0.5px), #000 var(--_r)) right bottom / var(--_r) var(--_r) no-repeat;
    opacity: 1; transition: opacity 0.5s ease;
  }
  .tid-help-panel[hidden]::before { opacity: 0; }
  .tid-help-header {
    min-height: var(--_head-h); padding: 10px max(10px, var(--imm-safe-r)) 10px max(16px, var(--imm-safe-l));
    border-radius: calc(var(--imm-r-lg) - 1px) calc(var(--imm-r-lg) - 1px) 0 0;
    touch-action: none; /* the header is the drag handle (companions.js: pull down to close) */
  }
  .tid-help-header::after { /* grabber */
    content: ''; position: absolute; left: 50%; top: 6px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(255, 255, 255, 0.34);
  }
  /* the sheet carries its own title, so it rises, folds and drags with the sheet and never leaves its frame */
  .tid-help-title { min-width: 0; }
  .tid-help-messages { padding-inline: max(14px, var(--imm-safe-l)) max(14px, var(--imm-safe-r)); }
  .tid-help-message-bubble { max-width: min(100% - 40px, 30rem); }
  .tid-help-chips { padding-inline: max(14px, var(--imm-safe-l)) max(14px, var(--imm-safe-r)); }
  .tid-help-form { padding: 8px max(12px, var(--imm-safe-r)) calc(10px + var(--imm-safe-b)) max(12px, var(--imm-safe-l)); border-radius: 0; }

  /* pointing: fold to the header strip at the bottom edge (the title is part of it) */
  html.imm-help-pointing .tid-help-panel:not([hidden]) {
    transform: translate3d(0, calc(100% - var(--_head-h) - var(--imm-safe-b)), 0); clip-path: none;
    transition: transform 0.7s var(--imm-ease-out), visibility 0s linear 0s;
  }
  html.imm-help-pointing .tid-help-panel:not([hidden])::before { opacity: 0; }
}

/* ==========================================================================
   3 · Q&A tab — "ถามได้นะ!"
   ========================================================================== */
.qa-wrap {
  position: relative; box-sizing: border-box;
  width: 100%; max-width: 58rem; margin-inline: auto; padding: clamp(6px, 1.4vw, 18px) 0 0;
  color: var(--imm-ink); font-family: inherit; line-height: 1.6;
}
.qa-wrap .row { margin: 0; }

/* ---- heading: พี่ทิศ asks ----------------------------------------------------------------------- */
.qa-wrap .qa-head {
  position: relative; flex-direction: row; align-items: flex-end; justify-content: flex-start;
  gap: clamp(8px, 1.4vw, 16px); margin: 0 0 clamp(12px, 1.6vw, 18px);
}
.qa-wrap .qa-head::before { /* พี่ทิศ's head (decorative) */
  content: ''; flex: none; width: clamp(58px, 8.4vw, 96px); aspect-ratio: 1;
  background: url('../../images/tid-head/webp/t-greeting.webp') center / contain no-repeat; /* a polite wai: พี่ทิศ is asking */
  filter: drop-shadow(0 8px 10px rgba(27, 24, 56, 0.22));
  transform-origin: 50% 100%;
  animation: imm-qa-head 0.85s var(--imm-ease-spring) 0.05s backwards, imm-tid-float 6.5s ease-in-out 1.2s infinite;
}
@keyframes imm-qa-head { from { opacity: 0; transform: translate3d(-18px, 14px, 0) scale(0.5) rotate(-14deg); } }
.qa-wrap .qa-head h1 {
  position: relative; flex: 1 1 auto; min-width: 0; width: auto; margin: 0 0 clamp(8px, 1.2vw, 16px);
  padding: clamp(14px, 1.7vw, 22px) clamp(16px, 2.2vw, 28px) clamp(15px, 1.8vw, 24px);
  color: var(--imm-ink); font-size: clamp(1.1rem, 0.96rem + 0.95vw, 1.72rem); font-weight: 600; line-height: 1.4; text-wrap: balance;
  background: linear-gradient(140deg, #fff 0%, var(--imm-gold-50) 130%);
  border: 1px solid var(--imm-line); border-radius: 26px 26px 26px 8px;
  box-shadow: var(--imm-shadow-2);
  transform-origin: 0 100%;
  animation: imm-qa-say 0.7s var(--imm-ease-spring) 0.22s backwards;
}
@keyframes imm-qa-say { from { opacity: 0; transform: translate3d(-10px, 8px, 0) scale(0.86); } }
.qa-wrap .qa-head h1::before { /* Latin eyebrow (ornament; empty alt text keeps it out of the spoken heading) */
  content: 'ASK P’TID'; content: 'ASK P’TID' / ''; display: block; margin: 0 0 0.5em;
  color: var(--imm-gold-600); font-size: var(--imm-fs-2xs); font-weight: 500; letter-spacing: var(--imm-track-eyebrow); line-height: 1.2;
}
.qa-wrap .qa-head h1::after { /* tail towards the head */
  content: ''; position: absolute; left: -6px; bottom: 16px; width: 12px; height: 12px;
  background: #fff; border: solid var(--imm-line); border-width: 0 0 1px 1px; border-bottom-left-radius: 3px;
  transform: rotate(45deg);
}
/* counter — a gold chip riding the bubble's corner. #countPill's className is overwritten by JS: style by id/.pill only */
.qa-wrap .pill {
  position: absolute; right: 14px; top: -11px; z-index: 1;
  display: inline-flex; align-items: center; gap: 0.45em; padding: 0.28em 0.95em 0.28em 0.8em;
  color: var(--imm-gold-700); font-size: var(--imm-fs-xs); font-weight: 600; line-height: 1.5; font-variant-numeric: tabular-nums; white-space: nowrap;
  background: var(--imm-gold-50); border: 1px solid rgba(250, 172, 30, 0.55); border-radius: var(--imm-r-pill);
  box-shadow: 0 4px 12px rgba(250, 172, 30, 0.22);
  transition: color 0.3s ease, background-color 0.3s ease, box-shadow 0.4s ease, transform 0.5s var(--imm-ease-spring);
}
.qa-wrap .pill::before { content: 'เลือกแล้ว'; font-weight: 400; }
.qa-wrap[data-imm-full] .pill { color: #2b1d00; background: var(--imm-gold-300); border-color: var(--imm-gold-500); box-shadow: 0 6px 18px rgba(250, 172, 30, 0.45); transform: scale(1.06); }
.qa-wrap .pill.error { color: #fff; background: var(--imm-danger); border-color: var(--imm-danger); }

/* ---- consent: a quiet, always-visible line (PDPA copy is never folded) ------------------------- */
.qa-wrap .warning-text {
  position: relative; width: auto; max-width: none; margin: 0 0 clamp(12px, 1.8vw, 20px); padding: 0 0 0 1.9em;
  color: var(--imm-ink-3); font-size: var(--imm-fs-xs); font-weight: 400; line-height: 1.65;
}
.qa-wrap .warning-text::before { /* shield glyph */
  content: ''; position: absolute; left: 0; top: 0.18em; width: 1.3em; height: 1.3em; background: var(--imm-gold-500);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l7 3v5c0 4.6-3 8.6-7 10-4-1.4-7-5.4-7-10V6l7-3z'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l7 3v5c0 4.6-3 8.6-7 10-4-1.4-7-5.4-7-10V6l7-3z'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---- topics: selectable cards ------------------------------------------------------------------- */
/* JS shows / hides #topicList with inline display (grid / none): only the tracks are declared here */
.qa-wrap .topic-box {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 10px;
  max-height: none; padding: 0; overflow: visible; border: 0; border-radius: 0;
}
.qa-wrap .chk {
  position: relative; isolation: isolate; gap: 12px; min-height: 54px; padding: 10px 16px 10px 14px;
  background: none; border: 0; border-radius: var(--imm-r-md);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  animation: imm-qa-card 0.6s var(--imm-ease-out) calc(min(var(--imm-i, 0), 16) * 26ms) backwards;
  transition: transform 0.45s var(--imm-ease-out);
}
@keyframes imm-qa-card { from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.97); } }
/* a result without any topic (e.g. no academic records yet): say so instead of showing an empty frame */
.qa-wrap .topic-box:empty::before {
  content: 'ยังไม่มีหัวข้อข้อมูลให้เลือกในผลลัพธ์นี้'; grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 14px 18px;
  color: var(--imm-ink-3); font-size: var(--imm-fs-sm); line-height: 1.5;
  background: var(--imm-surface); border: 1px dashed var(--imm-line-strong); border-radius: var(--imm-r-md);
}
/* the card face is drawn by the label text's ::before so `input:checked + .k` can restyle it without :has() */
.qa-wrap .chk .k {
  flex: 1 1 auto; min-width: 0; color: var(--imm-ink-2); font-family: inherit; font-size: var(--imm-fs-sm); font-weight: 400; line-height: 1.45;
  overflow-wrap: anywhere; transition: color 0.3s ease, opacity 0.3s ease;
}
.qa-wrap .chk .k::before {
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: var(--imm-r-md);
  background: #fff; border: 1px solid var(--imm-line); box-shadow: var(--imm-shadow-1);
  transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.4s ease;
}
.qa-wrap .chk input[type='checkbox'] {
  -webkit-appearance: none; appearance: none; position: relative; flex: none; width: 24px; height: 24px; margin: 0;
  border: 1.5px solid var(--imm-line-strong); border-radius: 50%; background-color: #fff; cursor: pointer;
  transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.4s ease;
}
.qa-wrap .chk input[type='checkbox']::after { /* check mark */
  content: ''; position: absolute; inset: 0; background: #2b1d00;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 12.6l4.3 4.3L18.6 7.6'/%3E%3C/svg%3E") center / 14px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 12.6l4.3 4.3L18.6 7.6'/%3E%3C/svg%3E") center / 14px no-repeat;
  transform: scale(0) rotate(-30deg); transition: transform 0.5s var(--imm-ease-spring);
}
.qa-wrap .chk input[type='checkbox']:checked { border-color: var(--imm-gold-500); background-color: var(--imm-gold-400); background-image: var(--imm-grad-gold); box-shadow: 0 4px 12px rgba(250, 172, 30, 0.45); }
.qa-wrap .chk input[type='checkbox']:checked::after { transform: none; }
.qa-wrap .chk input:checked + .k { color: var(--imm-ink); font-weight: 500; }
.qa-wrap .chk input:checked + .k::before { background-color: var(--imm-gold-50); border-color: var(--imm-gold-400); box-shadow: 0 0 0 1px rgba(250, 172, 30, 0.45), 0 10px 26px rgba(250, 172, 30, 0.2); }
@media (hover: hover) {
  .qa-wrap .chk:hover { transform: translate3d(0, -2px, 0); }
  .qa-wrap .chk:hover .k::before { border-color: var(--imm-violet-400); box-shadow: var(--imm-shadow-2); }
  .qa-wrap .chk:hover input:checked + .k::before { border-color: var(--imm-gold-500); box-shadow: 0 0 0 1px rgba(250, 172, 30, 0.55), 0 14px 30px rgba(250, 172, 30, 0.26); }
}
.qa-wrap .chk:active { transform: scale(0.985); }
.qa-wrap .chk input[type='checkbox']:focus-visible { outline: none; }
.qa-wrap .chk input:focus-visible + .k::before { outline: 2px solid var(--imm-gold-400); outline-offset: 2px; }
html.a11y-focus-highlight .qa-wrap .chk input:focus-visible + .k::before { outline: 3px solid #ff9900; outline-offset: 3px; }
/* fourth pick is refused by JS (class is removed after 250 ms): quick shake + a red glint.
   The entrance animation stays first in the list so removing `shake` does not replay it. */
.qa-wrap .chk.shake { animation: imm-qa-card 0.6s var(--imm-ease-out) backwards, imm-qa-shake 0.24s linear 1; }
.qa-wrap .chk.shake .k::before { border-color: var(--imm-danger); box-shadow: 0 0 0 3px rgba(201, 58, 85, 0.16); }
@keyframes imm-qa-shake { 0%, 100% { transform: none; } 20% { transform: translate3d(-5px, 0, 0); } 45% { transform: translate3d(5px, 0, 0); } 70% { transform: translate3d(-3px, 0, 0); } 88% { transform: translate3d(2px, 0, 0); } }
/* limit reached: the rest steps back (still clickable — JS answers with the shake) */
.qa-wrap[data-imm-full] .chk input:not(:checked) + .k { opacity: 0.58; }
.qa-wrap[data-imm-full] .chk input:not(:checked) + .k::before { box-shadow: none; }

.qa-wrap .note { /* #limitNote — className is overwritten by JS, style by .note only */
  position: relative; margin: 12px 0 0; padding-left: 1.6em;
  color: var(--imm-ink-3); font-size: var(--imm-fs-xs); line-height: 1.6; transition: color 0.3s ease;
}
.qa-wrap .note::before { content: ''; position: absolute; left: 0.25em; top: 0.52em; width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--imm-gold-400); box-shadow: 0 0 0 3px rgba(250, 172, 30, 0.22); }
.qa-wrap[data-imm-full] .note { color: var(--imm-gold-700); font-weight: 500; }
.qa-wrap .note.error { color: var(--imm-danger); }

/* large screens: the list scrolls inside a soft-edged window so the composer stays in reach */
@media (min-width: 769px) and (min-height: 600px) {
  .qa-wrap .topic-box {
    max-height: min(27rem, 50vh); overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
    margin: -14px -12px 0; padding: 14px 12px 24px;
    -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 14px, #000 calc(100% - 24px), transparent 100%);
    mask-image: linear-gradient(180deg, transparent 0, #000 14px, #000 calc(100% - 24px), transparent 100%);
    scrollbar-width: thin; scrollbar-color: var(--imm-violet-300) transparent;
  }
  .qa-wrap .note { margin-top: 0; }
}

/* ---- composer: chat input ------------------------------------------------------------------------ */
/* JS shows / hides .q-row with inline display (flex / none) */
.qa-wrap .q-row {
  position: relative; z-index: 4; align-items: center; gap: 8px;
  margin: clamp(14px, 2vw, 22px) 0 0; padding: 6px 6px 6px 8px;
  animation: imm-qa-rise 0.65s var(--imm-ease-spring) backwards;
}
@keyframes imm-qa-rise { from { opacity: 0; transform: translate3d(0, 26px, 0) scale(0.96); } }
.qa-wrap .q-row::after { /* the capsule itself (kept on a pseudo so the phone fade below can sit behind it) */
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: var(--imm-r-pill);
  background: #fff; border: 1px solid var(--imm-line-strong); box-shadow: var(--imm-shadow-2);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.qa-wrap .q-row:focus-within::after { border-color: var(--imm-gold-400); box-shadow: 0 0 0 4px rgba(250, 172, 30, 0.22), var(--imm-shadow-2); }
.qa-wrap .q-input {
  flex: 1 1 auto; min-width: 0; min-height: 46px; padding: 0 8px 0 14px;
  color: var(--imm-ink); background: transparent; border: 0; border-radius: var(--imm-r-pill); outline: none; box-shadow: none;
  font-family: inherit; font-size: 1rem; line-height: 1.4; /* ≥16px: no focus zoom on iOS */
}
.qa-wrap .q-input:focus { border: 0; box-shadow: none; }
/* the capsule's gold ring (:focus-within above) is the indicator; zero-specificity scope so the in-app
   "focus highlight" setting (html.a11y-focus-highlight :focus-visible) still wins */
:where(.qa-wrap) .q-input:focus-visible { outline: none; }
.qa-wrap .q-input::placeholder { color: var(--imm-ink-3); opacity: 0.85; }
.qa-wrap .q-row .btn {
  position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  min-height: 46px; padding: 0 1.15em 0 1.3em; border: 0; border-radius: var(--imm-r-pill);
  color: #fff; background: var(--imm-grad-brand); box-shadow: var(--imm-shadow-violet), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  font-family: inherit; font-size: var(--imm-fs-md); font-weight: 500; line-height: 1.2; white-space: nowrap; cursor: pointer;
  transition: transform 0.4s var(--imm-ease-out), box-shadow 0.4s ease, filter 0.3s ease, opacity 0.3s ease;
}
.qa-wrap .q-row .btn::after { /* paper plane */
  content: ''; width: 1.05em; height: 1.05em; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m22 2-7 20-4-9-9-4 20-7Z'/%3E%3Cpath d='M22 2 11 13'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m22 2-7 20-4-9-9-4 20-7Z'/%3E%3Cpath d='M22 2 11 13'/%3E%3C/svg%3E") center / contain no-repeat;
}
@media (hover: hover) {
  .qa-wrap .q-row .btn:not(:disabled):hover { transform: translate3d(0, -2px, 0); filter: saturate(1.12); }
}
.qa-wrap .q-row .btn:not(:disabled):active { transform: scale(0.96); }
.qa-wrap .q-row .btn:focus-visible { outline: 2px solid var(--imm-gold-400); outline-offset: 2px; border-radius: var(--imm-r-pill); }
.qa-wrap .q-row .btn:disabled { color: var(--imm-violet-400); background: var(--imm-violet-100); box-shadow: none; opacity: 1; cursor: not-allowed; }

/* ---- thread: question → typing → answer ---------------------------------------------------------- */
/* .questionQA / .answerQA / .askAgain stay `display:none` by default (legacy rule); JS switches them to block */
.qa-wrap .questionQA {
  width: fit-content; max-width: min(88%, 40rem); margin: clamp(6px, 1.2vw, 14px) 0 0 auto; padding: 12px 18px 13px;
  color: #fff; font-size: var(--imm-fs-md); font-weight: 400; line-height: 1.6; overflow-wrap: anywhere;
  background: var(--imm-grad-brand); border: 0; border-radius: 22px 22px 6px 22px;
  box-shadow: 0 10px 26px rgba(104, 104, 172, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transform-origin: 100% 100%;
  animation: imm-qa-out 0.55s var(--imm-ease-spring) backwards;
}
@keyframes imm-qa-out { from { opacity: 0; transform: translate3d(16px, 10px, 0) scale(0.9); } }
@keyframes imm-qa-in { from { opacity: 0; transform: translate3d(-14px, 10px, 0) scale(0.94); } }

/* typing bubble (before the first chunk). `#resultsModal .hidden` (modal.css) keeps the hidden state. */
#loadingQA:not(.hidden) {
  position: relative; inset: auto; isolation: auto;
  display: flex; flex: none; flex-direction: row; align-items: center; justify-content: flex-start; gap: 10px;
  width: fit-content; max-width: 100%; min-height: 0; margin: 14px 0 0; padding: 9px 18px 9px 9px;
  color: var(--imm-ink-3); font-size: var(--imm-fs-sm); text-align: left;
  background: #fff; border: 1px solid var(--imm-line); border-radius: 22px 22px 22px 6px;
  box-shadow: var(--imm-shadow-1);
  transform-origin: 0 100%;
  animation: imm-qa-in 0.5s var(--imm-ease-out) backwards;
}
#loadingQA::before { /* พี่ทิศ thinking */
  content: ''; flex: none; width: 36px; height: 36px; border-radius: 50%;
  background: var(--imm-cream) url('../../images/tid-head/webp/t-think.webp') center / 92% no-repeat;
  box-shadow: 0 0 0 1px var(--imm-line-gold);
}
#loadingQA .spinner { /* legacy ring → three dots */
  flex: none; width: 30px; height: 12px; margin: 0; border: 0; border-radius: 0; color: var(--imm-violet-400);
  --_dot: no-repeat radial-gradient(circle closest-side, currentColor 90%, transparent);
  background: var(--_dot) 0% 50%, var(--_dot) 50% 50%, var(--_dot) 100% 50%; background-size: 10px 6px;
  animation: imm-co-dots 1.15s linear infinite;
}
#loadingQA p { width: auto; margin: 0; color: inherit; font-size: inherit; line-height: 1.5; }

/* answer bubble + markdown */
.qa-wrap .answerQA {
  position: relative; box-sizing: border-box; width: fit-content; max-width: min(100%, 46rem);
  margin: 14px 0 0; padding: clamp(14px, 2vw, 24px) clamp(16px, 2.4vw, 30px) clamp(16px, 2.2vw, 26px);
  color: var(--imm-ink-2); font-size: var(--imm-fs-md); line-height: 1.75; overflow-wrap: anywhere;
  background: #fff; border: 1px solid var(--imm-line); border-radius: 24px 24px 24px 8px;
  box-shadow: var(--imm-shadow-2);
  transform-origin: 0 0;
  animation: imm-qa-in 0.5s var(--imm-ease-out) backwards; /* the container animates once; chunks re-render inside */
}
.qa-wrap .answerQA::before { /* author row (phones): พี่ทิศ's medallion + name */
  content: 'พี่ทิศ'; display: flex; align-items: center; min-height: 36px; margin: 0 0 12px; padding: 0 0 12px 46px;
  color: var(--imm-violet-700); font-size: var(--imm-fs-sm); font-weight: 500; line-height: 1.2;
  background:
    url('../../images/tid-head/webp/t-advice.webp') 3px 3px / 30px 30px no-repeat,
    radial-gradient(circle at 18px 18px, var(--imm-cream) 0 16.5px, transparent 17px) 0 0 / 36px 36px no-repeat,
    radial-gradient(circle at 18px 18px, var(--imm-gold-300) 0 18px, transparent 18.5px) 0 0 / 36px 36px no-repeat;
  border-bottom: 1px solid var(--imm-line);
}
.qa-wrap .answerQA > * { width: auto; max-width: 100%; }
.qa-wrap .answerQA > :first-child { margin-top: 0; }
.qa-wrap .answerQA > :last-child { margin-bottom: 0; }
.qa-wrap .answerQA p { margin: 0 0 0.85em; }
.qa-wrap .answerQA h1, .qa-wrap .answerQA h2, .qa-wrap .answerQA h3, .qa-wrap .answerQA h4, .qa-wrap .answerQA h5, .qa-wrap .answerQA h6 {
  margin: 1.25em 0 0.45em; color: var(--imm-violet-800); font-weight: 600; line-height: 1.4; text-wrap: balance;
}
.qa-wrap .answerQA h1 { font-size: var(--imm-fs-lg); }
.qa-wrap .answerQA h2 { font-size: var(--imm-fs-lg); }
.qa-wrap .answerQA h3, .qa-wrap .answerQA h4, .qa-wrap .answerQA h5, .qa-wrap .answerQA h6 { font-size: var(--imm-fs-md); }
.qa-wrap .answerQA h1::after, .qa-wrap .answerQA h2::after { content: ''; display: block; width: 2.4em; height: 2px; margin-top: 0.4em; border-radius: 2px; background: var(--imm-grad-gold); }
.qa-wrap .answerQA ul, .qa-wrap .answerQA ol { margin: 0 0 0.9em; padding-left: 1.45em; }
.qa-wrap .answerQA ul ul, .qa-wrap .answerQA ol ol, .qa-wrap .answerQA ul ol, .qa-wrap .answerQA ol ul { margin: 0.3em 0 0.2em; }
.qa-wrap .answerQA li { margin: 0.3em 0; padding-left: 0.2em; }
.qa-wrap .answerQA ul > li::marker { color: var(--imm-gold-500); }
.qa-wrap .answerQA ol > li::marker { color: var(--imm-violet-500); font-weight: 600; }
.qa-wrap .answerQA strong, .qa-wrap .answerQA b { color: var(--imm-ink); font-weight: 600; }
.qa-wrap .answerQA em { font-style: italic; }
.qa-wrap .answerQA a { color: var(--imm-violet-600); text-decoration: underline; text-decoration-color: var(--imm-gold-400); text-decoration-thickness: 1.5px; text-underline-offset: 0.22em; }
.qa-wrap .answerQA code { padding: 0.08em 0.42em; border-radius: 6px; background: var(--imm-violet-50); color: var(--imm-violet-800); font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 0.9em; }
.qa-wrap .answerQA pre { margin: 0 0 0.9em; padding: 0.9em 1.1em; overflow-x: auto; border-radius: var(--imm-r-sm); background: var(--imm-violet-950); color: var(--imm-ink-inv); line-height: 1.6; }
.qa-wrap .answerQA pre code { padding: 0; background: none; color: inherit; }
.qa-wrap .answerQA blockquote { margin: 0 0 0.9em; padding: 0.7em 1em; border-left: 3px solid var(--imm-gold-400); border-radius: 0 var(--imm-r-sm) var(--imm-r-sm) 0; background: var(--imm-gold-50); color: var(--imm-ink-2); font-weight: 300; }
.qa-wrap .answerQA blockquote > :last-child { margin-bottom: 0; }
.qa-wrap .answerQA hr { height: 1px; margin: 1.3em 0; border: 0; background: linear-gradient(90deg, var(--imm-line-strong), transparent); }
.qa-wrap .answerQA img { max-width: 100%; height: auto; border-radius: var(--imm-r-sm); }
.qa-wrap .answerQA table { display: block; width: 100%; max-width: 100%; margin: 0 0 0.9em; overflow-x: auto; border-collapse: separate; border-spacing: 0; font-size: var(--imm-fs-sm); line-height: 1.5; }
.qa-wrap .answerQA th { padding: 0.6em 0.9em; text-align: left; font-weight: 500; color: var(--imm-violet-800); background: var(--imm-violet-50); border-bottom: 1px solid var(--imm-line-strong); white-space: nowrap; }
.qa-wrap .answerQA th:first-child { border-top-left-radius: 10px; }
.qa-wrap .answerQA th:last-child { border-top-right-radius: 10px; }
.qa-wrap .answerQA td { padding: 0.55em 0.9em; border-bottom: 1px solid var(--imm-line); vertical-align: top; }
/* streaming: dots at the end of the answer until the stream closes (state from companions.js) */
.qa-wrap[data-imm-qa='streaming'] .answerQA::after {
  content: ''; display: block; width: 30px; height: 12px; margin-top: 0.7em; color: var(--imm-violet-400);
  --_dot: no-repeat radial-gradient(circle closest-side, currentColor 90%, transparent);
  background: var(--_dot) 0% 50%, var(--_dot) 50% 50%, var(--_dot) 100% 50%; background-size: 10px 6px;
  animation: imm-co-dots 1.15s linear infinite;
}

.qa-wrap .askAgain { margin: 16px 0 0; text-align: center; animation: imm-fade-up 0.55s var(--imm-ease-out) 0.1s backwards; }
.qa-wrap .askAgain .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.55em;
  min-height: 48px; padding: 0 1.5em 0 1.25em; border-radius: var(--imm-r-pill);
  color: var(--imm-violet-700); background: rgba(104, 104, 172, 0.1); border: 1px solid var(--imm-line-strong);
  font-family: inherit; font-size: var(--imm-fs-md); font-weight: 500; line-height: 1.2; cursor: pointer;
  transition: transform 0.4s var(--imm-ease-out), background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}
.qa-wrap .askAgain .btn::before { /* loop arrow */
  content: ''; width: 1.1em; height: 1.1em; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: rotate 0.7s var(--imm-ease-spring);
}
.qa-wrap .askAgain .btn:hover, .qa-wrap .askAgain .btn:focus-visible { color: var(--imm-violet-900); background: var(--imm-gold-50); border-color: var(--imm-gold-400); transform: translate3d(0, -2px, 0); }
.qa-wrap .askAgain .btn:hover::before, .qa-wrap .askAgain .btn:focus-visible::before { rotate: -180deg; }
.qa-wrap .askAgain .btn:focus-visible { outline: 2px solid var(--imm-gold-400); outline-offset: 2px; border-radius: var(--imm-r-pill); }

/* error — a friendly card. qa_engine.js ships it with inline `margin-top:10px; color:#dc3545`: !important re-tokens both */
#qaErrorState {
  position: relative; box-sizing: border-box; width: fit-content; max-width: min(100%, 40rem);
  margin: 14px 0 0 !important; padding: 14px 18px 16px 70px; min-height: 68px;
  color: var(--imm-ink-2) !important; font-size: var(--imm-fs-sm); line-height: 1.6;
  background: linear-gradient(140deg, #fff 0%, #fff4f5 100%); border: 1px solid rgba(201, 58, 85, 0.3); border-radius: 22px 22px 22px 6px;
  box-shadow: var(--imm-shadow-1);
  animation: imm-qa-in 0.5s var(--imm-ease-out) backwards;
}
#qaErrorState::before { /* พี่ทิศ apologising */
  content: ''; position: absolute; left: 14px; top: 14px; width: 42px; height: 42px; border-radius: 50%;
  background: var(--imm-cream) url('../../images/tid-head/webp/t-sorry-hand.webp') center / 92% no-repeat;
  box-shadow: 0 0 0 1px rgba(201, 58, 85, 0.3);
}
#qaErrorMessage { width: auto; margin: 0 0 10px; color: var(--imm-danger); font-weight: 500; overflow-wrap: anywhere; }
.qa-wrap .btn-retry { /* JS toggles inline display (inline-block / none) */
  min-height: 44px; margin: 0 8px 0 0; padding: 0 1.3em; border: 0; border-radius: var(--imm-r-pill);
  color: #fff; background: var(--imm-grad-brand); box-shadow: 0 8px 20px rgba(104, 104, 172, 0.3);
  font-family: inherit; font-size: var(--imm-fs-sm); font-weight: 500; line-height: 1.2; cursor: pointer;
  transition: transform 0.4s var(--imm-ease-out), filter 0.3s ease;
}
.qa-wrap .btn-retry:hover, .qa-wrap .btn-retry:focus-visible { transform: translate3d(0, -2px, 0); filter: saturate(1.12); }
.qa-wrap .btn-retry:focus-visible { outline: 2px solid var(--imm-gold-400); outline-offset: 2px; border-radius: var(--imm-r-pill); }

/* ---- wide layout: พี่ทิศ's head moves outside the bubbles, like a chat thread ------------------- */
@media (min-width: 640px) {
  #loadingQA:not(.hidden), .qa-wrap .answerQA, #qaErrorState { margin-left: 58px; }
  .qa-wrap .askAgain { padding-left: 58px; text-align: left; }
  #loadingQA:not(.hidden) { padding-left: 18px; }
  #loadingQA::before { position: absolute; left: -58px; bottom: 0; width: 44px; height: 44px; box-shadow: 0 0 0 1px var(--imm-line-gold), var(--imm-shadow-1); }
  .qa-wrap .answerQA::before {
    content: ''; position: absolute; left: -58px; top: 0; width: 44px; height: 44px; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: 50%;
    background: var(--imm-cream) url('../../images/tid-head/webp/t-advice.webp') center / 86% no-repeat;
    box-shadow: 0 0 0 1px var(--imm-line-gold), var(--imm-shadow-1);
  }
  #qaErrorState { padding-left: 18px; min-height: 0; }
  #qaErrorState::before { left: -58px; top: 0; width: 44px; height: 44px; box-shadow: 0 0 0 1px rgba(201, 58, 85, 0.3), var(--imm-shadow-1); }
}

/* ---- phones: compact cards, room for the 52px help launcher in the bottom-right corner ------------ */
@media (max-width: 768px), (max-height: 520px) {
  .qa-wrap { padding-bottom: 72px; } /* the end of the thread can always scroll clear of the launcher */
  .qa-wrap .topic-box { gap: 8px; }
  .qa-wrap .chk { min-height: 50px; padding: 8px 14px 8px 12px; gap: 11px; }
  .qa-wrap .chk input[type='checkbox'] { width: 22px; height: 22px; }
}

/* ---- phones: the composer docks to the bottom of the sheet, beside the help launcher ------------- */
@media (max-width: 768px) and (min-height: 521px) {
  .qa-wrap .qa-head h1 { text-wrap: wrap; }
  .qa-wrap .q-row {
    position: sticky; bottom: calc(10px + var(--imm-safe-b));
    margin-right: 62px; /* the 52px help launcher lives in that corner */
    padding: 4px 4px 4px 6px;
  }
  .qa-wrap .q-row::before { /* paper fade so the list dissolves under the dock (also behind the launcher) */
    content: ''; position: absolute; z-index: -2; left: -16px; right: -78px; top: -22px; bottom: calc(-10px - var(--imm-safe-b)); pointer-events: none;
    background: linear-gradient(180deg, rgba(255, 253, 248, 0) 0, var(--imm-surface) 22px, var(--imm-surface) 100%);
  }
  .qa-wrap .q-input { min-height: 44px; padding-left: 12px; }
  .qa-wrap .q-row .btn { min-height: 44px; padding: 0 0.95em 0 1.05em; }
}
@media (max-width: 340px) {
  /* fold-width screens: the ask button keeps only its paper plane (the text stays as the accessible name) */
  .qa-wrap .q-row .btn { width: 44px; padding: 0; gap: 0; font-size: 0; }
  .qa-wrap .q-row .btn::after { width: 18px; height: 18px; }
  .qa-wrap .pill::before { content: none; }
}

/* ==========================================================================
   Reduced motion — static, still composed (html.imm-reduced = OS setting or in-app switch)
   ========================================================================== */
html.imm-reduced #avatar,
html.imm-reduced #sprite::before,
html.imm-reduced #bubble,
html.imm-reduced .tid-help-toggle::after,
html.imm-reduced .tid-help-message,
html.imm-reduced .tid-help-panel:not([hidden]) .tid-help-title,
html.imm-reduced .tid-help-panel:not([hidden]) .tid-help-chip,
html.imm-reduced .tid-help-panel:not([hidden]) .tid-help-form > *,
html.imm-reduced .tid-help-target-callout:not([hidden]),
html.imm-reduced .qa-wrap .qa-head::before,
html.imm-reduced .qa-wrap .qa-head h1,
html.imm-reduced .qa-wrap .chk,
html.imm-reduced .qa-wrap .q-row,
html.imm-reduced .qa-wrap .questionQA,
html.imm-reduced .qa-wrap .answerQA,
html.imm-reduced .qa-wrap .askAgain,
html.imm-reduced #loadingQA:not(.hidden),
html.imm-reduced #qaErrorState { animation: none; }
html.imm-reduced .tid-help-target-highlight { animation: none; --imm-hl-spread: 6px; --imm-hl-alpha: 0.45; }
html.imm-reduced .imm-help-ring { animation: none; --imm-hl-spread: 4px; --imm-hl-alpha: 0.3; transition-duration: 0.01s; }
html.imm-reduced .imm-help-ring.is-locked::after { animation: none; }
html.imm-reduced #sprite::after { transition-duration: 0.01s; }
html.imm-reduced .tid-help-toggle, html.imm-reduced .tid-help-toggle img,
html.imm-reduced #bubble, html.imm-reduced #sprite, html.imm-reduced #avatar, html.imm-reduced .qa-wrap .chk { transition-duration: 0.01s; }
@layer imm-force {
  /* The sheet must be visible in the very frame it opens: help_assistant.js focuses its input 0 ms later and a
     running visibility transition starts at "hidden", which makes that focus() a no-op. The legacy
     `body.a11y-reduce-motion * { transition-duration: .01ms !important }` turns the default `transition: all`
     of every descendant into such a transition, so the whole subtree opts out. !important beats that rule. */
  html.imm-reduced .tid-help-panel, html.imm-reduced .tid-help-panel * { transition: none !important; }
}
/* indicators keep a calm three-dot row instead of bouncing */
html.imm-reduced #loadingQA .spinner,
html.imm-reduced .qa-wrap[data-imm-qa='streaming'] .answerQA::after,
html.imm-reduced .tid-help-panel.imm-is-loading .tid-help-message--assistant:last-child .tid-help-message-bubble::after { animation: none; }
html.imm-reduced .tid-help-form.is-loading .tid-help-submit::after { animation-duration: 2.4s; }

/* ==========================================================================
   High contrast — solid plates, dark text, 2px borders
   ========================================================================== */
html.a11y-high-contrast #bubble { background: var(--imm-surface); border: 2px solid var(--imm-ink); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; color: var(--imm-ink); }
html.a11y-high-contrast #bubble::before { background: var(--imm-surface); border-color: var(--imm-ink); border-width: 0 2px 2px 0; -webkit-backdrop-filter: none; backdrop-filter: none; }
html.a11y-high-contrast #bubble > p [style*='color'] { filter: brightness(0.45) saturate(1.6); }
html.a11y-high-contrast #avatar[style*='width'] { border-color: var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .tid-help-toggle { color: var(--imm-ink); background: var(--imm-surface); border: 2px solid var(--imm-ink); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
html.a11y-high-contrast .tid-help-toggle[aria-expanded='true'] { color: #fff; background: #05050c; border-color: #fff; }
html.a11y-high-contrast .tid-help-toggle::after { display: none; }
html.a11y-high-contrast .tid-help-panel { border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .tid-help-header { background: #05050c; border-bottom: 2px solid #fff; }
html.a11y-high-contrast .tid-help-header::before { display: none; }
html.a11y-high-contrast .tid-help-title span { color: #fff; font-weight: 400; }
html.a11y-high-contrast .tid-help-close { background: #05050c; border: 2px solid #fff; }
html.a11y-high-contrast .tid-help-messages { background: var(--imm-surface); }
html.a11y-high-contrast .tid-help-message-bubble { border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .tid-help-message-bubble li::marker { color: var(--imm-ink); }
html.a11y-high-contrast .tid-help-message--user .tid-help-message-bubble { background: var(--imm-accent-strong); border-color: var(--imm-accent-strong); }
html.a11y-high-contrast .tid-help-message-bubble strong { color: var(--imm-ink); }
html.a11y-high-contrast .tid-help-chip { color: var(--imm-ink); background: var(--imm-surface); border: 2px solid var(--imm-ink); }
html.a11y-high-contrast .tid-help-chips { -webkit-mask-image: none; mask-image: none; }
html.a11y-high-contrast .tid-help-input { border: 2px solid var(--imm-ink); }
html.a11y-high-contrast .tid-help-submit { color: #fff; background: var(--imm-accent-strong); border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .tid-help-form.is-loading .tid-help-submit::after { border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }
html.a11y-high-contrast .tid-help-target-callout { background: #05050c; border: 2px solid #fff; -webkit-backdrop-filter: none; backdrop-filter: none; }
html.a11y-high-contrast .tid-help-target-callout::after { background: #05050c; border-color: #fff; }
@layer imm-force {
  html.a11y-high-contrast:not(.imm-help-ring-on) .tid-help-target-highlight { outline: 4px solid #b05f00 !important; box-shadow: 0 0 0 8px #fffef5, 0 0 0 11px #0b0b12 !important; }
}
html.a11y-high-contrast .tid-help-target-highlight { animation: none; }
html.a11y-high-contrast .imm-help-ring {
  animation: none; outline: 4px solid #b05f00; outline-offset: 5px;
  box-shadow: 0 0 0 9px #fffef5, 0 0 0 12px #0b0b12;
}
html.a11y-high-contrast .imm-help-ring::after { --_c: #0b0b12; filter: none; }
html.a11y-high-contrast #sprite::after { border-color: var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .qa-head h1 { background: var(--imm-surface); border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .qa-head h1::before { color: var(--imm-ink-2); }
html.a11y-high-contrast .qa-wrap .qa-head h1::after { background: var(--imm-surface); border-color: var(--imm-ink); border-width: 0 0 2px 2px; left: -7px; }
html.a11y-high-contrast .qa-wrap .pill { color: var(--imm-ink); background: var(--imm-surface); border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .qa-wrap[data-imm-full] .pill { color: #fff; background: var(--imm-highlight); }
html.a11y-high-contrast .qa-wrap .warning-text, html.a11y-high-contrast .qa-wrap .note { color: var(--imm-ink-2); }
html.a11y-high-contrast .qa-wrap .warning-text::before { background: var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .chk .k { color: var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .chk .k::before { background: var(--imm-surface); border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .chk input[type='checkbox'] { border: 2px solid var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .chk input[type='checkbox']:checked { background: var(--imm-accent-strong); border-color: var(--imm-accent-strong); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .chk input[type='checkbox']::after { background: #fff; }
html.a11y-high-contrast .qa-wrap .chk input:checked + .k::before { background: #fff; border: 3px solid var(--imm-accent-strong); box-shadow: none; }
html.a11y-high-contrast .qa-wrap[data-imm-full] .chk input:not(:checked) + .k { opacity: 1; }
html.a11y-high-contrast .qa-wrap .q-row::after { border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .q-row .btn { background: var(--imm-accent-strong); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .q-row .btn:disabled { color: var(--imm-ink-3); background: var(--imm-surface); border: 2px dashed var(--imm-ink-3); }
html.a11y-high-contrast .qa-wrap .questionQA { background: var(--imm-accent-strong); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .answerQA, html.a11y-high-contrast #loadingQA:not(.hidden), html.a11y-high-contrast #qaErrorState { color: var(--imm-ink); background: var(--imm-surface); border: 2px solid var(--imm-ink); box-shadow: none; }
html.a11y-high-contrast .qa-wrap .answerQA h1, html.a11y-high-contrast .qa-wrap .answerQA h2, html.a11y-high-contrast .qa-wrap .answerQA h3,
html.a11y-high-contrast .qa-wrap .answerQA th, html.a11y-high-contrast .qa-wrap .answerQA code, html.a11y-high-contrast .qa-wrap .answerQA::before { color: var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .answerQA blockquote { background: var(--imm-surface); border: 2px solid var(--imm-ink); border-left-width: 6px; font-weight: 400; }
html.a11y-high-contrast .qa-wrap .answerQA li::marker { color: var(--imm-ink); }
html.a11y-high-contrast #loadingQA .spinner,
html.a11y-high-contrast .qa-wrap[data-imm-qa='streaming'] .answerQA::after,
html.a11y-high-contrast .tid-help-panel.imm-is-loading .tid-help-message--assistant:last-child .tid-help-message-bubble::after { color: var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .answerQA th { background: var(--imm-surface); border-bottom: 2px solid var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .answerQA code { background: var(--imm-surface); outline: 1px solid var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .askAgain .btn { color: var(--imm-ink); background: var(--imm-surface); border: 2px solid var(--imm-ink); }
html.a11y-high-contrast .qa-wrap .btn-retry { background: var(--imm-accent-strong); box-shadow: none; }

/* ------------------------------------------------------------------ print: companions never print */
@media print {
  #sprite-portal, .tid-help-widget, .tid-help-target-callout { display: none !important; }
}
