/* ============================================================
   箱ボット（XXBase HP 用）
   サイトの --ink / --paper / --font をそのまま使います。
   ============================================================ */
.boxbot {
  --bb-ink: var(--ink, #1a1a1a);
  --bb-paper: var(--paper, #f3f3f2);
  --bb-soft: var(--ink-soft, #4a4a4a);
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  font-family: var(--font, "Tetsubin Gothic", sans-serif);
  color: var(--bb-ink);
}
.boxbot__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- 右下の箱 ---- */
.boxbot__launcher {
  position: relative; display: block; margin-left: auto;
  width: 72px; height: 72px; padding: 0; border: 0; background: none; cursor: pointer;
  transition: transform .25s ease, opacity .25s ease;
}
.boxbot__svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(3px 4px 0 rgba(0,0,0,.18)); }
.boxbot__launcher:hover { transform: translateY(-3px) rotate(-3deg); }
.boxbot__launcher:focus-visible { outline: 3px solid var(--bb-ink); outline-offset: 4px; border-radius: 6px; }
.boxbot__bubble {
  position: absolute; top: -6px; left: -10px;
  width: 26px; height: 26px; display: grid; place-items: center;
  font-size: 14px; font-weight: 900; background: var(--bb-paper);
  border: 2px solid var(--bb-ink); border-radius: 50% 50% 50% 8%;
  transition: opacity .2s ease, transform .2s ease;
}
.boxbot.is-open .boxbot__bubble { opacity: 0; transform: scale(.6); }

/* フタ：開くと左右のフラップが外へ倒れる */
.boxbot__flap { transform-box: fill-box; transition: transform .35s cubic-bezier(.3,1.4,.5,1); }
.boxbot__flap--l { transform-origin: 100% 100%; }
.boxbot__flap--r { transform-origin: 0% 100%; }
.boxbot.is-open .boxbot__flap--l { transform: rotate(-38deg); }
.boxbot.is-open .boxbot__flap--r { transform: rotate(38deg); }

/* 答えがあった：ぴょこっと跳ねる */
.boxbot.is-happy .boxbot__launcher { animation: bb-hop .45s ease; }
@keyframes bb-hop { 40% { transform: translateY(-8px); } }

/* 空っぽだった：フタが大きく開いて、箱がしょんぼり揺れる */
.boxbot.is-empty .boxbot__flap--l { transform: rotate(-110deg); }
.boxbot.is-empty .boxbot__flap--r { transform: rotate(110deg); }
.boxbot.is-empty .boxbot__inside { opacity: .45; }
.boxbot.is-empty .boxbot__mouth { d: path("M27 49 Q32 46 37 49"); }
.boxbot.is-empty .boxbot__launcher { animation: bb-shake .5s ease; }
@keyframes bb-shake { 20% { transform: rotate(-6deg); } 40% { transform: rotate(5deg); } 60% { transform: rotate(-3deg); } 80% { transform: rotate(2deg); } }

/* ---- 吹き出しパネル ---- */
.boxbot__panel {
  position: absolute; right: 0; bottom: 86px;
  width: min(360px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 140px));
  display: flex; flex-direction: column;
  background: var(--bb-paper);
  border: 2px solid var(--bb-ink); border-radius: 4px 7px 5px 6px;
  box-shadow: 6px 6px 0 rgba(0,0,0,.2);
  transform-origin: 90% 100%;
  animation: bb-pop .22s ease;
}
.boxbot__panel[hidden] { display: none; }
@keyframes bb-pop { from { opacity: 0; transform: translateY(8px) scale(.96); } }
.boxbot__panel::after { /* しっぽ */
  content: ""; position: absolute; right: 28px; bottom: -11px; width: 18px; height: 18px;
  background: var(--bb-paper); border-right: 2px solid var(--bb-ink); border-bottom: 2px solid var(--bb-ink);
  transform: rotate(45deg) skew(6deg, 6deg);
}
.boxbot__head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 8px 16px; border-bottom: 2px dashed rgba(0,0,0,.25); }
.boxbot__title { margin: 0; font-weight: 900; letter-spacing: .12em; font-size: 14px; }
.boxbot__close { width: 32px; height: 32px; font: inherit; font-size: 20px; line-height: 1; background: none; border: 2px solid transparent; border-radius: 4px; color: var(--bb-ink); cursor: pointer; }
.boxbot__close:hover, .boxbot__close:focus-visible { border-color: var(--bb-ink); outline: none; }

.boxbot__log { flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.boxbot__msg { margin: 0; max-width: 88%; padding: 9px 12px; font-size: 14px; line-height: 1.75; border: 2px solid var(--bb-ink); border-radius: 3px 6px 4px 5px; word-break: break-word; }
.boxbot__msg--box { align-self: flex-start; background: #fff; }
.boxbot__msg--me { align-self: flex-end; background: var(--bb-ink); color: var(--bb-paper); }
.boxbot__msg--thinking { letter-spacing: .3em; color: var(--bb-soft); }
.boxbot__msg--empty { font-weight: 700; border-style: dashed; } /* ドラクエ風のメッセージ枠っぽく */
.boxbot__msg a { color: inherit; font-weight: 700; text-underline-offset: 3px; }

.boxbot__chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 10px; }
.boxbot__chip { font: inherit; font-size: 12px; padding: 5px 10px; background: var(--bb-paper); color: var(--bb-ink); border: 1.5px solid var(--bb-ink); border-radius: 999px; cursor: pointer; }
.boxbot__chip:hover, .boxbot__chip:focus-visible { background: var(--bb-ink); color: var(--bb-paper); outline: none; }

.boxbot__form { display: flex; gap: 8px; padding: 10px 12px; border-top: 2px solid var(--bb-ink); }
.boxbot__input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 8px 10px; color: var(--bb-ink); background: #fff; border: 2px solid var(--bb-ink); border-radius: 3px; }
.boxbot__input:focus { outline: none; box-shadow: 0 0 0 3px rgba(0,0,0,.18); }
.boxbot__send { font: inherit; font-weight: 900; font-size: 14px; padding: 0 14px; color: var(--bb-paper); background: var(--bb-ink); border: 2px solid var(--bb-ink); border-radius: 4px; cursor: pointer; }
.boxbot__send:active { transform: translate(1px, 1px); }
.boxbot__note { margin: 0; padding: 0 12px 10px; font-size: 10.5px; color: var(--bb-soft); }

/* ---- スマホ ---- */
@media (max-width: 720px) {
  .boxbot { right: 12px; bottom: 12px; }
  .boxbot__launcher { width: 58px; height: 58px; }
  .boxbot__panel { position: fixed; left: 10px; right: 10px; bottom: 82px; width: auto; max-height: calc(100dvh - 110px); }
  /* X アイコン・フォーム・フッターが見えている間は、箱を画面の外へ引っこめる */
  .boxbot.is-tucked:not(.is-open) .boxbot__launcher { transform: translateX(120%); opacity: 0; pointer-events: none; }
}

/* ---- 動きを減らしたい人向け ---- */
@media (prefers-reduced-motion: reduce) {
  .boxbot *, .boxbot *::before, .boxbot *::after { animation: none !important; transition: none !important; }
}

/* HP担当: 箱を大きく・ときどきゆらす */
.boxbot__launcher { width: 92px; height: 92px; }
@keyframes boxbot-nudge { 0%,86%,100% { transform: rotate(0); } 89% { transform: rotate(-7deg); } 92% { transform: rotate(6deg); } 95% { transform: rotate(-3deg); } }
.boxbot__launcher:not([aria-expanded="true"]) .boxbot__svg { animation: boxbot-nudge 7s ease-in-out 3s infinite; transform-origin: 50% 90%; }
@media (max-width: 720px) { .boxbot__launcher { width: 70px; height: 70px; } }
@media (prefers-reduced-motion: reduce) { .boxbot__launcher .boxbot__svg { animation: none !important; } }
