/* MDK AI Assist, module 4: the corner swiftlet helper and its bottom sheet.
   Colours and type follow the live header (.mdkhdr): #1e1b17 text, #e8a33d / #c9861f amber, #fbfaf8 background.
   Everything is position:fixed, so nothing in the page moves when it appears (no layout shift).
   The art is assets/mascot.svg; the animations below only need these ids in it:
   #mdk-bird (wrapper, for the hop), #mdk-bird-eye, #mdk-bird-wing-left, #mdk-bird-wing-right.
   Wing pivots come from the SVG itself (style="transform-origin:..."), so a new drawing brings its own. */

.mdk-helper, .mdk-helper-sheet {
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #1e1b17; box-sizing: border-box;
}
.mdk-helper *, .mdk-helper-sheet * { box-sizing: border-box; }

/* Corner button. Bottom-right, 16px from the edges, above the iOS home bar.
   --mdk-helper-lift is set by helper.js if another fixed bar sits in that corner. */
.mdk-helper {
  position: fixed; right: 16px; z-index: 9990;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--mdk-helper-lift, 0px));
  width: 60px; height: 60px;
}
.mdk-helper__btn {
  display: block; width: 60px; height: 60px; padding: 0; margin: 0; border: 0; border-radius: 50%;
  background: #fbfaf8; cursor: pointer; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 18px rgba(30,27,23,.18), 0 1px 3px rgba(30,27,23,.12);
  transition: transform .18s ease;
}
.mdk-helper__btn:active { transform: scale(.95); }
.mdk-helper__btn:focus-visible { outline: 3px solid #c9861f; outline-offset: 3px; }
.mdk-helper__btn svg { display: block; width: 100%; height: 100%; overflow: visible; }
.mdk-helper__fallback { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: 26px; font-weight: 900; color: #1e1b17; }
.mdk-helper.is-open .mdk-helper__btn { visibility: hidden; }

/* Speech bubble, shown once per visitor */
.mdk-helper__bubble {
  position: absolute; right: 0; bottom: 74px; width: max-content; max-width: min(300px, calc(100vw - 32px));
  background: #fff; border: 1px solid rgba(30,27,23,.12); border-radius: 14px;
  box-shadow: 0 10px 28px rgba(30,27,23,.16);
  padding: 10px 44px 10px 14px; font-size: 15.5px; line-height: 1.45; font-weight: 700;
  opacity: 0; transform: translateY(6px); transition: opacity .25s ease, transform .25s ease;
}
.mdk-helper__bubble.is-in { opacity: 1; transform: none; }
.mdk-helper__bubble[hidden] { display: none; }
.mdk-helper__bubble::after {
  content: ""; position: absolute; right: 22px; bottom: -7px; width: 12px; height: 12px;
  background: #fff; border-right: 1px solid rgba(30,27,23,.12); border-bottom: 1px solid rgba(30,27,23,.12);
  transform: rotate(45deg);
}
.mdk-helper__bubble-text { margin: 0; cursor: pointer; text-wrap: balance; } /* 0.2.8: longer AI 小燕子 line, no lonely last word */
.mdk-helper__bubble-x {
  position: absolute; top: 0; right: 0; width: 44px; height: 44px; border: 0; background: none; padding: 0;
  font-size: 22px; line-height: 1; color: #6d675e; cursor: pointer; border-radius: 0 14px 0 14px;
}
.mdk-helper__bubble-x:focus-visible { outline: 3px solid #c9861f; outline-offset: -3px; }

/* Bottom sheet */
.mdk-helper-backdrop {
  position: fixed; inset: 0; z-index: 9994; background: rgba(30,27,23,.38);
  opacity: 0; transition: opacity .2s ease;
}
.mdk-helper-backdrop.is-in { opacity: 1; }
.mdk-helper-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9995; margin: 0 auto; max-width: 560px;
  max-height: 80vh; max-height: 80dvh; display: flex; flex-direction: column;
  background: #fbfaf8; border-radius: 18px 18px 0 0; box-shadow: 0 -12px 40px rgba(30,27,23,.22);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
}
.mdk-helper-sheet.is-in { transform: none; }
.mdk-helper-sheet[hidden], .mdk-helper-backdrop[hidden] { display: none; }
.mdk-helper-sheet__head {
  display: flex; align-items: center; gap: 10px; padding: 10px 6px 8px 14px;
  border-bottom: 1px solid rgba(30,27,23,.08); flex: none;
}
.mdk-helper-sheet__face { width: 36px; height: 36px; flex: none; }
.mdk-helper-sheet__face svg { width: 100%; height: 100%; display: block; }
.mdk-helper-sheet__title { margin: 0; font-size: 17px; font-weight: 800; line-height: 1.3; flex: 1; min-width: 0; }
.mdk-helper-sheet__sub { display: block; font-size: 13px; font-weight: 500; color: #6d675e; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdk-helper-sheet__x {
  width: 44px; height: 44px; flex: none; border: 0; background: none; padding: 0; border-radius: 50%;
  font-size: 28px; line-height: 1; color: #6d675e; cursor: pointer;
}
.mdk-helper-sheet__x:focus-visible, .mdk-helper-sheet__send:focus-visible, .mdk-helper-sheet__wa:focus-visible { outline: 3px solid #c9861f; outline-offset: 2px; }
.mdk-helper-sheet__log {
  flex: 1 1 auto; min-height: 96px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 12px 14px 4px; display: flex; flex-direction: column; gap: 10px;
}
.mdk-helper-sheet__intro { margin: 0; font-size: 14.5px; line-height: 1.55; color: #3d3831; background: #f4f1ea; border-radius: 12px; padding: 10px 12px; }
.mdk-helper-rate { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 13px; color: #6b645a; }
.mdk-helper-rate__btn {
  min-width: 44px; min-height: 44px; border: 1px solid rgba(30,27,23,.15); border-radius: 22px; background: #fff;
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 10px;
}
.mdk-helper-rate__btn:focus-visible { outline: 2px solid #1f8f4e; outline-offset: 2px; }
.mdk-helper-q {
  align-self: flex-end; max-width: 85%; margin: 0; background: #fff1d6; border-radius: 14px 14px 4px 14px;
  padding: 9px 12px; font-size: 15.5px; line-height: 1.5; word-break: break-word;
}
.mdk-helper-a {
  align-self: flex-start; max-width: 92%; background: #fff; border: 1px solid rgba(30,27,23,.08);
  border-radius: 14px 14px 14px 4px; padding: 10px 12px;
}
.mdk-helper-a__text { margin: 0; font-size: 15.5px; line-height: 1.65; word-break: break-word; }
.mdk-helper-a__wait { margin: 0; font-size: 15px; color: #6d675e; }
.mdk-helper-a .mdk-ai-wa { margin-top: 10px; }
.mdk-helper-sheet .mdk-ai-wa {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px;
  border-radius: 999px; background: #1f8f4e; color: #fff !important; font-weight: 800; font-size: 15.5px; text-decoration: none !important;
}
.mdk-helper-sheet .mdk-ai-wa svg { flex: none; }
.mdk-helper-sheet__form { display: flex; gap: 8px; padding: 10px 14px 6px; flex: none; }
.mdk-helper-sheet__input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; margin: 0;
  border: 1.5px solid rgba(30,27,23,.18); border-radius: 12px; background: #fff; color: #1e1b17;
  font: inherit; font-size: 16px; /* 16px: iOS does not zoom in on focus */
}
.mdk-helper-sheet__input:focus { outline: none; border-color: #c9861f; box-shadow: 0 0 0 3px rgba(232,163,61,.25); }
.mdk-helper-sheet__send {
  flex: none; min-height: 48px; min-width: 72px; padding: 0 16px; border: 0; border-radius: 999px; cursor: pointer;
  background: linear-gradient(180deg, #e8a33d, #c9861f); color: #231d13; font: inherit; font-weight: 800; font-size: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 6px 14px rgba(201,134,31,.25);
}
.mdk-helper-sheet__send:disabled { opacity: .6; cursor: default; }
.mdk-helper-sheet__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 14px 10px; flex: none; }
.mdk-helper-sheet__wa {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: 14.5px; font-weight: 700;
  color: #1f8f4e !important; text-decoration: underline !important;
}

/* Animations: transform and opacity only. */
#mdk-bird-eye { transform-box: fill-box; transform-origin: center; animation: mdk-helper-blink 5s infinite; }
#mdk-bird-wing-left { animation: mdk-helper-flap-l 8s ease-in-out infinite; }
#mdk-bird-wing-right { animation: mdk-helper-flap-r 8s ease-in-out infinite; }
.mdk-helper.is-hop #mdk-bird { animation: mdk-helper-hop .75s ease-out 1; }
.mdk-helper.is-hop svg:not(:has(#mdk-bird)) { animation: mdk-helper-hop .75s ease-out 1; }
.mdk-helper-sheet__face #mdk-bird-eye, .mdk-helper-sheet__face #mdk-bird-wing-left, .mdk-helper-sheet__face #mdk-bird-wing-right { animation: none; }

@keyframes mdk-helper-blink {
  0%, 93%, 100% { transform: scaleY(1); }
  95.5% { transform: scaleY(.08); }
}
@keyframes mdk-helper-flap-l {
  0%, 82%, 100% { transform: rotate(0deg); }
  86% { transform: rotate(-9deg); }
  90% { transform: rotate(0deg); }
  94% { transform: rotate(-6deg); }
}
@keyframes mdk-helper-flap-r {
  0%, 82%, 100% { transform: rotate(0deg); }
  86% { transform: rotate(9deg); }
  90% { transform: rotate(0deg); }
  94% { transform: rotate(6deg); }
}
@keyframes mdk-helper-hop {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
  55% { transform: translateY(0); }
  72% { transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .mdk-helper *, .mdk-helper-sheet *, .mdk-helper, .mdk-helper-sheet, .mdk-helper-backdrop, .mdk-helper__bubble {
    animation: none !important; transition: none !important;
  }
}
@media (max-width: 359px) {
  .mdk-helper__bubble { max-width: calc(100vw - 32px); }
  .mdk-helper-sheet__send { min-width: 64px; padding: 0 12px; }
}

/* 2026-10-14 owner: slightly bigger on computers */
@media (min-width: 1024px) {
  .mdk-helper, .mdk-helper__btn { width: 76px; height: 76px; }
  .mdk-helper__bubble { bottom: 90px; }
}

/* 2026-10-14: glide up and down when another floating button appears in the corner */
.mdk-helper { transition: bottom .25s ease; }
@media (prefers-reduced-motion: reduce) { .mdk-helper { transition: none; } }
