/* Help-desk doll in the bottom-right corner (_includes/dollchat.html, assets/js/dollchat.js).
   Colors follow the site theme; html[data-theme="dark"] switches to the dark set. */

.dollchat {
  --dc-bg: #ffffff;
  --dc-fg: #3d4144;
  --dc-muted: #6f777d;
  --dc-line: #e2e4e6;
  --dc-bot: #f3f2ef;
  --dc-accent: #500000;
  --dc-accent-fg: #ffffff;
  --dc-link: #500000;
  --dc-ok: #3f8f5a;
  --dc-shadow: 0 10px 30px rgba(20, 20, 20, 0.16), 0 2px 6px rgba(20, 20, 20, 0.08);
  --dc-doll-w: 96px;   /* pose canvas 3:5; the slim doll stands in the middle, arms may reach the sides */
  --dc-doll-h: 160px;
  position: fixed;
  right: 16px;
  bottom: 12px;
  z-index: 40;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--dc-fg);
}
html[data-theme="dark"] .dollchat {
  --dc-bg: #333333;
  --dc-fg: #f1f1f1;
  --dc-muted: #b9b9b9;
  --dc-line: #555555;
  --dc-bot: #404040;
  --dc-accent: #8f3a3a;
  --dc-accent-fg: #ffffff;
  --dc-link: #e8a4a4;
  --dc-ok: #6cc28a;
  --dc-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
}
.dollchat [hidden] { display: none !important; }
.dollchat__sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- the doll ---------- */
.dollchat__doll {
  position: relative;
  display: block;
  width: var(--dc-doll-w);
  height: var(--dc-doll-h);
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  perspective: 500px;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.dollchat__doll:focus { outline: none; }
.dollchat__doll:focus-visible { outline: 2px solid var(--dc-link); outline-offset: 3px; border-radius: 18px; }
.dollchat__body {
  position: absolute;
  inset: 0;
  transform-origin: 50% 100%;
  transition: transform 0.25s ease;
}
.dollchat__body img {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  -webkit-user-select: none; user-select: none;
  transform-origin: 50% 100%;
  animation: dc-breathe 3.6s ease-in-out infinite;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.12));
}
.dollchat__shadow {
  position: absolute;
  left: 33%;
  right: 33%;
  bottom: -3px;
  height: 7px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
  filter: blur(2px);
  transform-origin: 50% 50%;
}
html[data-theme="dark"] .dollchat__shadow { background: rgba(0, 0, 0, 0.4); }
.dollchat__doll:hover .dollchat__body { transform: translateY(-3px) rotate(-4deg); }

/* actions (one class at a time on the button, set by dollchat.js) */
.dollchat__doll.dc-hop .dollchat__body     { animation: dc-hop 0.7s ease-out; }
.dollchat__doll.dc-hop .dollchat__shadow   { animation: dc-shadow 0.7s ease-out; }
.dollchat__doll.dc-wave .dollchat__body    { animation: dc-wave 1.3s ease-in-out; }
.dollchat__doll.dc-wiggle .dollchat__body  { animation: dc-wiggle 0.9s ease-in-out; }
.dollchat__doll.dc-look .dollchat__body    { animation: dc-look 2.4s ease-in-out; }
.dollchat__doll.dc-stretch .dollchat__body { animation: dc-stretch 1.4s ease-in-out; }
.dollchat__doll.dc-spin .dollchat__body    { animation: dc-spin 1.1s ease-in-out; }
.dollchat__doll.dc-nod .dollchat__body     { animation: dc-nod 1.2s ease-in-out; }
.dollchat__doll.dc-hum .dollchat__body     { animation: dc-sway 2.4s ease-in-out; }
.dollchat__doll.dc-talk .dollchat__body    { animation: dc-talk 0.42s ease-in-out infinite; }
.dollchat__doll.dc-sway .dollchat__body    { animation: dc-sway 1.8s ease-in-out; }
.dollchat__doll.dc-jump2 .dollchat__body   { animation: dc-jump2 1.2s ease-out; }
.dollchat__doll.dc-jump2 .dollchat__shadow { animation: dc-shadow 0.6s ease-out 2; }
.dollchat__doll.dc-lean .dollchat__body    { animation: dc-lean 1.4s ease-in-out; }
.dollchat__doll.dc-shake .dollchat__body   { animation: dc-shake 1.6s ease-in-out; }
.dollchat__doll.dc-tilt .dollchat__body    { animation: dc-tilt 2.2s ease-in-out; }
.dollchat__doll.is-sleep .dollchat__body   { transform: rotate(6deg) translateY(2px); transition: transform 1.2s ease; }
.dollchat__doll.is-sleep .dollchat__body img { animation-duration: 5.5s; }

@keyframes dc-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(0.992, 1.022); } }
@keyframes dc-hop {
  0% { transform: translateY(0) scale(1, 1); }
  15% { transform: translateY(0) scale(1.08, 0.9); }
  45% { transform: translateY(-16px) scale(0.95, 1.06); }
  70% { transform: translateY(0) scale(1.06, 0.93); }
  85% { transform: translateY(-3px) scale(0.99, 1.01); }
  100% { transform: translateY(0) scale(1, 1); }
}
@keyframes dc-shadow { 0%, 100% { transform: scale(1); opacity: 1; } 45% { transform: scale(0.6); opacity: 0.5; } }
@keyframes dc-wave {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-9deg) translateY(-4px); }
  30% { transform: rotate(7deg); }
  45% { transform: rotate(-7deg) translateY(-3px); }
  60% { transform: rotate(5deg); }
  75% { transform: rotate(-3deg); }
}
@keyframes dc-wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(6deg); }
  40% { transform: rotate(-6deg); }
  60% { transform: rotate(4deg); }
  80% { transform: rotate(-2deg); }
}
@keyframes dc-look {
  0%, 100% { transform: scaleX(1); }
  20%, 45% { transform: scaleX(1) rotate(-5deg) translateX(-2px); }
  55%, 85% { transform: scaleX(-1) rotate(-5deg) translateX(-2px); }
}
@keyframes dc-stretch {
  0%, 100% { transform: scale(1, 1); }
  30% { transform: scale(0.93, 1.12) translateY(-2px); }
  55% { transform: scale(0.95, 1.1) rotate(3deg); }
  75% { transform: scale(1.06, 0.94); }
}
@keyframes dc-spin { 0% { transform: rotateY(0); } 100% { transform: rotateY(360deg); } }
@keyframes dc-nod {
  0%, 100% { transform: rotate(0); }
  25%, 65% { transform: rotate(0) translateY(3px) scale(1.02, 0.97); }
  45%, 85% { transform: rotate(0) translateY(0); }
}
@keyframes dc-sway { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@keyframes dc-jump2 {
  0%, 50%, 100% { transform: translateY(0) scale(1, 1); }
  8%, 58% { transform: translateY(0) scale(1.06, 0.92); }
  25%, 75% { transform: translateY(-14px) scale(0.96, 1.05); }
  40%, 90% { transform: translateY(0) scale(1.04, 0.96); }
}
@keyframes dc-lean { 0%, 100% { transform: rotate(0); } 30%, 70% { transform: rotate(-6deg) translateX(-3px); } 45% { transform: rotate(-8deg) translateX(-5px); } }
@keyframes dc-shake {
  0%, 100% { transform: rotate(0); }
  10%, 30%, 50%, 70% { transform: rotate(2.5deg) translateY(-1px); }
  20%, 40%, 60%, 80% { transform: rotate(-2.5deg); }
}
@keyframes dc-tilt { 0%, 100% { transform: rotate(0); } 25%, 75% { transform: rotate(3deg); } }
@keyframes dc-talk { 0%, 100% { transform: translateY(0) scale(1, 1); } 50% { transform: translateY(-2px) scale(1.01, 0.985); } }

/* little things that float up over the doll: z (sleeping), notes (humming), ? (thinking) */
.dollchat__fx { position: absolute; left: 0; right: 0; top: -6px; height: 0; pointer-events: none; }
.dollchat__fx > span {
  position: absolute;
  left: 56%;
  top: 0;
  font-weight: 700;
  color: var(--dc-muted);
  animation: dc-float 2.2s ease-out forwards;
}
.dollchat__fx svg { width: 14px; height: 14px; fill: currentColor; display: block; }
@keyframes dc-float {
  0% { opacity: 0; transform: translate(0, 6px) scale(0.7); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx, 14px), -34px) scale(1.15); }
}

/* small speech bubble that always sits next to the doll while the chat is closed */
.dollchat__bubble {
  position: absolute;
  right: calc(var(--dc-doll-w) * 0.72);
  bottom: calc(var(--dc-doll-h) * 0.56);
  width: max-content;
  max-width: 178px;
  padding: 7px 11px;
  border: 1px solid var(--dc-line);
  border-radius: 12px;
  background: var(--dc-bg);
  color: var(--dc-fg);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: var(--dc-shadow);
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
  animation: dc-pop 0.25s ease-out;
  transition: opacity 0.3s ease, transform 0.3s ease, border-color 0.2s ease;
}
.dollchat__bubble::after {          /* the little tail pointing at the doll */
  content: "";
  position: absolute;
  right: -6px;
  bottom: 13px;
  width: 10px;
  height: 10px;
  background: var(--dc-bg);
  border-top: 1px solid var(--dc-line);
  border-right: 1px solid var(--dc-line);
  transform: rotate(45deg);
  transition: border-color 0.2s ease;
}
.dollchat__bubble:hover, .dollchat__bubble:hover::after { border-color: var(--dc-link); }
html[data-theme="dark"] .dollchat__bubble { --dc-bg: #3a3a3a; --dc-line: #6a6a6a; }
.dollchat__bubble.is-hint, .dollchat__bubble.is-hint::after { border-color: var(--dc-link); }
.dollchat__bubble.is-hint { max-width: 230px; }
/* the part of the page the doll is offering to explain */
.dc-hint-target { outline: 1.5px dashed rgba(80, 0, 0, 0.5); outline-offset: 3px; border-radius: 3px; }
html[data-theme="dark"] .dc-hint-target { outline-color: rgba(232, 164, 164, 0.7); }
.dollchat.is-tucked .dollchat__bubble { opacity: 0; transform: translateX(24px); pointer-events: none; }
@keyframes dc-pop { from { opacity: 0; transform: translateY(6px) scale(0.96); } to { opacity: 1; transform: none; } }

/* ---------- the chat panel ---------- */
.dollchat__panel {
  position: fixed;
  right: calc(16px + var(--dc-doll-w) * 0.72 + 6px);
  bottom: 12px;
  width: 360px;
  height: min(580px, calc(100vh - 96px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--dc-line);
  border-radius: 14px;
  background: var(--dc-bg);
  color: var(--dc-fg);
  box-shadow: var(--dc-shadow);
  animation: dc-pop 0.2s ease-out;
}
.dollchat__head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border-bottom: 1px solid var(--dc-line);
}
.dollchat__avatar {
  width: 40px;
  height: 40px;
  margin: 0;
  border-radius: 50%;
  background: var(--dc-bot);
  border: 1px solid var(--dc-line);
  object-fit: cover;
}
.dollchat__who { flex: 1; min-width: 0; }
.dollchat__title { margin: 0; padding: 0; border: 0; font-size: 15px; font-weight: 700; line-height: 1.25; color: var(--dc-fg); }
.dollchat__status { margin: 1px 0 0; font-size: 12.5px; color: var(--dc-muted); display: flex; align-items: center; gap: 6px; }
.dollchat__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dc-ok); flex: none; }
.dollchat__close, .dollchat__send {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
  width: 34px; height: 34px;
  margin: 0; padding: 0;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--dc-muted);
  cursor: pointer;
}
.dollchat__close:hover { background: var(--dc-bot); color: var(--dc-fg); }
.dollchat__close svg, .dollchat__send svg {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.dollchat__close:focus-visible, .dollchat__send:focus-visible, .dc-chip:focus-visible, .dc-link:focus-visible, .dollchat__log:focus-visible {
  outline: 2px solid var(--dc-link); outline-offset: 2px;
}

.dollchat__log {
  flex: 1 1 auto;
  min-height: 0; /* lets the conversation shrink and scroll, so the input box always stays in view */
  overflow-y: auto;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.dc-row { display: flex; align-items: flex-end; gap: 8px; }
.dc-row--user { justify-content: flex-end; }
.dc-row__avatar { width: 26px; height: 26px; margin: 0; border-radius: 50%; flex: none; background: var(--dc-bot); object-fit: cover; }
.dc-msg {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14.5px;
  overflow-wrap: anywhere;
}
.dc-msg p { margin: 0; font-size: inherit; line-height: 1.45; }
.dc-msg p + p { margin-top: 0.5em; }
.dc-row--bot .dc-msg { background: var(--dc-bot); color: var(--dc-fg); border-bottom-left-radius: 4px; }
.dc-row--user .dc-msg { background: var(--dc-accent); color: var(--dc-accent-fg); border-bottom-right-radius: 4px; }
.dc-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dc-link {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--dc-line);
  border-radius: 999px;
  background: var(--dc-bg);
  color: var(--dc-link) !important;
  font-size: 13px;
  text-decoration: none !important;
}
.dc-link:hover { border-color: var(--dc-link); }
.dc-typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.dc-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--dc-muted); animation: dc-dot 1.1s ease-in-out infinite; }
.dc-typing i:nth-child(2) { animation-delay: 0.15s; }
.dc-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dc-dot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }
.dc-caret::after { content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 1px; vertical-align: -2px; background: currentColor; animation: dc-blink 0.8s steps(1) infinite; }
@keyframes dc-blink { 50% { opacity: 0; } }

.dc-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -2px 0 2px 34px;
}
.dc-chip {
  margin: 0;
  padding: 5px 11px;
  border: 1px solid var(--dc-line);
  border-radius: 999px;
  background: var(--dc-bg);
  color: var(--dc-fg);
  font: inherit;
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}
.dc-chip:hover { border-color: var(--dc-link); color: var(--dc-link); }
.dc-chip:disabled { opacity: 0.55; cursor: default; }
.dc-chip--more { border-style: dashed; color: var(--dc-muted); }

.dollchat__form {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 8px 8px 8px 12px;
  border-top: 1px solid var(--dc-line);
}
.dollchat__input {
  flex: 1;
  min-width: 0;
  width: auto;
  height: 38px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid var(--dc-line);
  border-radius: 999px;
  background: var(--dc-bg);
  color: var(--dc-fg);
  font: inherit;
  font-size: 15px;
  box-shadow: none;
}
.dollchat__input::placeholder { color: var(--dc-muted); }
.dollchat__input:focus { outline: none; border-color: var(--dc-link); box-shadow: 0 0 0 2px color-mix(in srgb, var(--dc-link) 20%, transparent); }
.dollchat__send { background: var(--dc-accent); color: var(--dc-accent-fg); border-radius: 50%; width: 38px; height: 38px; }
.dollchat__send:hover { filter: brightness(1.1); }
.dollchat__send:disabled { opacity: 0.5; cursor: default; }
.dollchat__foot { flex: none; margin: 0; padding: 0 12px 8px; font-size: 11.5px; color: var(--dc-muted); }

/* ---------- phones ---------- */
@media (max-width: 600px) {
  .dollchat { right: 4px; bottom: 10px; --dc-doll-w: 66px; --dc-doll-h: 110px; }
  .dollchat.is-tucked .dollchat__doll { transform: translateX(52%); opacity: 0.85; }
  .dollchat__bubble { max-width: 162px; padding: 5px 9px; font-size: 12px; line-height: 1.3; right: calc(var(--dc-doll-w) * 0.72); bottom: calc(var(--dc-doll-h) * 0.55); }
  .dollchat__bubble::after { bottom: 10px; }
  .dollchat__panel {
    left: 8px; right: 8px; bottom: 8px;
    width: auto;
    height: min(560px, calc(100vh - 72px));
    height: min(560px, calc(100dvh - 72px));
  }
  .dollchat.is-open .dollchat__doll { opacity: 0; pointer-events: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dollchat *, .dollchat *::before, .dollchat *::after { animation: none !important; transition: none !important; }
}

@media print { .dollchat { display: none !important; } }

/* ---------- idle scenes along the bottom of the window (dollchat.js: runScene, dragonScene) ---------- */
.dollchat.is-away .dollchat__doll,
.dollchat.is-away .dollchat__bubble { opacity: 0 !important; pointer-events: none; transition: opacity 0.2s ease; }
.dollstage { position: fixed; left: 0; right: 0; bottom: 0; height: 280px; z-index: 39; pointer-events: none; overflow: hidden; }
.dollstage__actor { position: absolute; left: 0; bottom: 12px; will-change: transform; }
.dollstage__actor.is-clickable { pointer-events: auto; cursor: pointer; }
.dollstage__flip, .dollstage__bob { width: 100%; height: 100%; }
.dollstage__actor.is-left .dollstage__flip { transform: scaleX(-1); }
.dollstage__actor img { display: block; width: 100%; height: 100%; margin: 0; -webkit-user-select: none; user-select: none; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.12)); }
.dollstage__actor.is-running .dollstage__bob { animation: dc-runbob 0.3s ease-in-out infinite; }
.dollstage__actor.is-resting .dollstage__bob { animation: dc-breathe 3.6s ease-in-out infinite; transform-origin: 50% 100%; }
.dollstage__actor.is-flying { bottom: 40px; }
.dollstage__actor.is-flying .dollstage__bob { animation: dc-fly 1.3s ease-in-out infinite; }
.dollstage__actor.is-firing .dollstage__bob { animation: dc-fire 0.18s linear infinite; }
.dollstage__actor.is-landing { transition: opacity 0.35s ease; opacity: 0; }
.dollstage__actor.is-walking .dollstage__bob { animation: dc-walk 0.5s ease-in-out infinite; }
.dollstage__actor.is-hit .dollstage__bob { animation: dc-hit 0.12s linear 6; }
.dollstage__actor.is-down .dollstage__bob { transform-origin: 30% 100%; transform: rotate(-82deg) translateY(10px); opacity: 0; transition: transform 0.7s ease-in, opacity 0.6s ease-in 0.3s; }
@keyframes dc-runbob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes dc-fly { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-12px) rotate(-2deg); } }
@keyframes dc-fire { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-1px, 1px); } }
@keyframes dc-walk { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-3px) rotate(3deg); } }
@keyframes dc-hit { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(4px); } }
.dollstage__puff {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(110, 110, 110, 0.5);
  animation: dc-puff 1.6s ease-out forwards;
}
@keyframes dc-puff { from { opacity: 0.85; transform: translate(0, 0) scale(0.5); } to { opacity: 0; transform: translate(var(--dx, 0), -70px) scale(2); } }
.dollstage__z { position: absolute; font-weight: 700; font-size: 16px; color: var(--global-text-color-light, #888); animation: dc-float 1.8s ease-out forwards; }
@media (prefers-reduced-motion: reduce) { .dollstage { display: none !important; } }
@media print { .dollstage { display: none !important; } }
