.mchat {
  --mc-brand: #2b4acb;
  --mc-on-brand: #ffffff;
  --mc-text-brand: #2b4acb;
  --mc-field-line: #94A3B8;
  --mc-off: #F1F5F9;
  --mc-off-ink: #4D5C70;
  --mc-full: 100vh;
  --mc-bg: #ffffff;
  --mc-fill: #F1F5F9;
  --mc-field: #ffffff;
  --mc-ink: #1E293B;
  --mc-sub: #4D5C70;
  --mc-line: #CBD5E1;
  --mc-glass: #fff;
  --mc-err: #c4291c;
  --mc-shadow: 0 0 0 .5px rgba(0, 0, 0, .1), 0 4px 12px rgba(0, 0, 0, .08), 0 24px 56px rgba(0, 0, 0, .18);
  --mc-curve: cubic-bezier(.32, .72, 0, 1);
  --mc-move: .32s;
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50;
  display: flex; flex-direction: column; align-items: flex-end;
  pointer-events: none; /* 開くボタンの余白で箱が伸び、下部タブの上に重なるため、箱では受けない */
  font: var(--fs-15)/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  color: var(--mc-ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
@supports (height: 100dvh) { .mchat { --mc-full: 100dvh; } }
html[data-role="duty"] .mchat, html[data-role="loading"] .mchat, html[data-ledger="1"] .mchat { display: none; }
@media print { .mchat { display: none; } }
.mchat *, .mchat *::before, .mchat *::after { box-sizing: border-box; }
.mchat [hidden] { display: none !important; }
.mchat.is-open { z-index: 1000; }
.mchat-open, .mchat-panel { pointer-events: auto; }
.mchat :where(button) { margin: 0; font: inherit; color: inherit; cursor: pointer; -webkit-appearance: none; appearance: none; }
.mchat p, .mchat h2, .mchat h3 { margin: 0; }
.mchat-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mchat-icon { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.mchat-icon.fill { fill: currentColor; stroke: none; }

/* 開くボタン */
.mchat-open {
  display: inline-flex; align-items: center; min-width: 52px; height: 52px; padding: 0 16px; border: 0; border-radius: 26px;
  background: var(--mc-brand); color: var(--mc-on-brand) !important; font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .16), 0 8px 24px rgba(0, 0, 0, .22);
  opacity: 0; transform: translateY(8px);
  transition: opacity .2s ease .16s, transform var(--mc-move) var(--mc-curve) .16s, margin-bottom var(--mc-move) var(--mc-curve), filter .15s ease;
}
.mchat.is-ready .mchat-open { opacity: 1; transform: none; }
.mchat.is-open .mchat-open { opacity: 0; transform: none; visibility: hidden; transition: opacity .12s ease, transform .2s ease, visibility 0s .12s; }
.mchat-open-label { max-width: 6em; padding: 0 4px; overflow: hidden; white-space: nowrap; transition: max-width var(--mc-move) var(--mc-curve), padding var(--mc-move) var(--mc-curve), opacity .2s ease; }
.mchat.is-compact .mchat-open-label { max-width: 0; padding: 0; opacity: 0; }
.mchat-open:active { background: var(--press-bg); transition-delay: 0s; }
@media (hover: hover) { .mchat-open:hover { filter: brightness(1.08); } }

/* 窓 */
.mchat-panel {
  position: absolute; right: 0; bottom: var(--mc-kb, 0px); display: flex; flex-direction: column; overflow: hidden;
  width: 400px; max-width: calc(100vw - 32px); height: min(640px, calc(var(--mc-vh, var(--mc-full)) - 32px - env(safe-area-inset-bottom)));
  background: var(--mc-bg); border-radius: 22px; box-shadow: var(--mc-shadow); outline: none;
  transform-origin: 100% 100%; opacity: 0; transform: translateY(12px);
  transition: opacity .18s ease, transform var(--mc-move) var(--mc-curve);
}
.mchat.is-open .mchat-panel { opacity: 1; transform: none; }
.mchat-scrim { display: none; }

.mchat-head {
  position: absolute; inset: 0 0 auto; z-index: 1; display: flex; align-items: center; justify-content: center; height: 52px;
  background: var(--mc-glass); -webkit-backdrop-filter: none; backdrop-filter: none;
  box-shadow: 0 .5px 0 transparent; transition: box-shadow .2s ease;
}
.mchat-head.is-scrolled { box-shadow: 0 .5px 0 var(--mc-line); }
.mchat-head h2 { font-size: var(--fs-15); font-weight: 600; letter-spacing: .01em; font-feature-settings: "palt"; opacity: 0; transition: opacity .2s ease; }
.mchat-head.is-scrolled h2 { opacity: 1; }
.mchat-grabber { display: none; }
.mchat-close {
  position: absolute; right: 4px; top: 4px; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: none; color: var(--mc-sub);
}
.mchat-close::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: none; transition: filter .15s ease; }
.mchat-close .mchat-icon { position: relative; width: 18px; height: 18px; stroke-width: 2.4; }
@media (hover: hover) { .mchat-close:hover::before { filter: brightness(.94); } }
.mchat-close:active::before { background: var(--press-bg); }

.mchat-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 8px; padding: 60px 16px 12px; outline: none;
  scrollbar-width: thin; scrollbar-gutter: stable;
}
.mchat-log > * { flex-shrink: 0; }
.mchat-intro { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding: 12px 4px 4px; }
.mchat-intro h3 { font-size: var(--fs-20); line-height: 1.35; font-weight: 600; letter-spacing: .01em; font-feature-settings: "palt"; word-break: auto-phrase; text-wrap: balance; }
.mchat-intro p { font-size: var(--fs-13); line-height: 1.6; color: var(--mc-sub); word-break: auto-phrase; text-wrap: pretty; }
.mchat-intro > a { display: inline-flex; align-items: center; align-self: flex-start; min-height: 44px; margin-top: -8px; font-size: var(--fs-13); color: var(--mc-text-brand); text-decoration: none; }
.mchat-suggest { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 4px; }
.mchat-suggest button {
  min-height: 44px; padding: 8px 16px; border: 0; border-radius: 22px; text-align: left; background: var(--mc-bg); box-shadow: inset 0 0 0 1px var(--mc-field-line, #CBD5E1); color: var(--mc-text-brand);
  font-weight: 400; transition: opacity .15s ease;
}
.mchat-suggest button:active { background: var(--press-bg); }
@media (hover: hover) { .mchat-suggest button:hover { filter: brightness(.96); } }

.mchat-msg { max-width: 86%; padding: 8px 16px; border-radius: 18px; overflow-wrap: anywhere; white-space: pre-wrap; word-break: auto-phrase; text-wrap: pretty; }
.mchat-msg p + p { margin-top: .6em; }
.mchat-msg.bot { align-self: flex-start; max-width: 100%; padding-inline: 0; background: none; border-bottom-left-radius: 6px; }
.mchat-msg.me { align-self: flex-end; margin-top: 8px; background: var(--mc-brand); color: var(--mc-on-brand); border-bottom-right-radius: 6px; }
.mchat-msg a { color: var(--mc-text-brand); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.mchat-msg.err { color: var(--mc-ink); }
.mchat-msg.err p::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--mc-err); vertical-align: .1em; }
.mchat-retry { display: block; min-height: 44px; margin: 4px 0 -8px; padding: 0; border: 0; background: none; color: var(--mc-text-brand) !important; font-weight: 600; }
.mchat-msg.is-new { animation: mchat-in .28s var(--mc-curve) both; }
.mchat-msg.me.is-new { transform-origin: 100% 100%; }
.mchat-msg.bot.is-new { transform-origin: 0 100%; }
@keyframes mchat-in { from { opacity: 0; transform: translateY(8px); } }
.mchat-msg.is-reveal > * { animation: mchat-reveal .18s ease both; }
@keyframes mchat-reveal { from { opacity: 0; } }
.mchat-msg.wait { display: inline-flex; gap: 4px; align-items: center; height: 40px; padding: 0 16px; }
.mchat-msg.wait i { width: 8px; height: 8px; border-radius: 50%; background: var(--mc-sub); animation: mchat-dot 1.2s ease-in-out infinite; }
.mchat-msg.wait i:nth-child(2) { animation-delay: .15s; }
.mchat-msg.wait i:nth-child(3) { animation-delay: .3s; }
@keyframes mchat-dot { 0%, 60%, 100% { opacity: .35; } 30% { opacity: 1; } }

.mchat-form { flex: none; position: relative; padding: 8px 12px 12px; box-shadow: 0 -.5px 0 transparent; transition: box-shadow .2s ease; }
.mchat-form.is-more { box-shadow: 0 -.5px 0 var(--mc-line); }
.mchat-field {
  display: flex; align-items: flex-end; min-height: 44px; padding: 4px 4px 4px 16px; border-radius: 22px; background: var(--mc-field);
  box-shadow: inset 0 0 0 1px var(--mc-field-line); transition: box-shadow .15s ease;
}
.mchat-field:focus-within { box-shadow: inset 0 0 0 1.5px var(--mc-text-brand); }
.mchat-field textarea {
  display: block; flex: 1; min-width: 0; max-height: 120px; margin: 0; padding: 8px 8px 8px 0; resize: none; border: 0; outline: 0; background: none; box-shadow: none;
  color: inherit; font: inherit; font-size: var(--fs-15); line-height: 24px;
}
.mchat-field textarea::placeholder { color: var(--mc-sub); opacity: 1; }
.mchat-send {
  flex: none; position: relative; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  background: var(--mc-brand); color: var(--mc-on-brand) !important; transition: transform .15s ease, background-color .15s ease, color .15s ease;
}
.mchat-send::after { content: ""; position: absolute; inset: -4px; }
.mchat-send .mchat-icon { width: 20px; height: 20px; stroke-width: 2.6; }
.mchat-send:disabled { background: var(--mc-off); color: var(--mc-off-ink) !important; cursor: default; }
.mchat-send:not(:disabled):active { background: color-mix(in srgb, var(--mc-brand) 88%, var(--mc-ink)); }
.mchat-count { padding: 4px 16px 0; font-size: var(--fs-13); text-align: right; color: var(--mc-sub); }

.mchat button:focus-visible, .mchat a:focus-visible, .mchat-log:focus-visible { outline: 2px solid var(--mc-text-brand); outline-offset: 2px; }
.mchat-log:focus-visible { outline-offset: -2px; }

/* スマホ：下から出るシート */
@media (max-width: 640px), (max-height: 500px) {
  .mchat-scrim {
    display: block; position: fixed; inset: 0; background: #E2E8F0; opacity: 0; pointer-events: none; transition: opacity var(--mc-move) ease;
  }
  .mchat.is-open .mchat-scrim { opacity: 1; pointer-events: auto; }
  .mchat-panel {
    position: fixed; right: 0; left: 0; bottom: var(--mc-kb, 0px); width: 100%; max-width: none;
    height: calc(var(--mc-vh, var(--mc-full)) - max(12px, env(safe-area-inset-top)));
    border-radius: 20px 20px 0 0; opacity: 1; transform: translateY(100%); transform-origin: 50% 100%;
    transition: transform var(--mc-move) var(--mc-curve);
  }
  .mchat.is-open .mchat-panel { transform: none; }
  .mchat.is-grow .mchat-panel { transition: transform var(--mc-move) var(--mc-curve), height var(--mc-move) var(--mc-curve); }
  .mchat.is-drag .mchat-panel, .mchat.is-drag .mchat-scrim { transition: none; }
  .mchat-head { height: 56px; padding-top: 8px; touch-action: none; cursor: grab; }
  .mchat-grabber { display: block; position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 3px; background: var(--mc-line); }
  .mchat-close { top: 8px; }
  .mchat-log { padding-top: 64px; }
  .mchat-form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .mchat.is-kb .mchat-form { padding-bottom: 8px; }
  html.mchat-lock { overflow: hidden; }
  html.mchat-lock body { overflow: visible; }
}
/* 質問の前は、親指の届く高さで開く。 */
@media (max-width: 640px) and (min-height: 501px) {
  .mchat:not(.is-talk):not(.is-kb) .mchat-panel { height: min(72vh, 600px); }
}
/* 横向きでキーボードが出たら、入力欄が切れないように詰める。 */
@media (max-height: 500px) {
  .mchat.is-kb .mchat-head { height: 44px; padding-top: 0; }
  .mchat.is-kb .mchat-grabber { display: none; }
  .mchat.is-kb .mchat-close { top: 0; }
  .mchat.is-kb .mchat-log { padding: 48px 16px 4px; }
  .mchat.is-kb .mchat-form { padding-top: 4px; padding-bottom: 4px; }
  .mchat.is-kb .mchat-field textarea { max-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .mchat *, .mchat *::before, .mchat *::after { transition-duration: 0s !important; transition-delay: 0s !important; }
  .mchat-msg.is-new, .mchat-msg.is-reveal > * { animation: none; }
  .mchat-msg.wait i { animation-duration: 2.4s; transform: none !important; }
}

/* 下のタブに重ねない */
@media (max-width: 699px) {
  html:has(.tabbar) .mchat { bottom: calc(68px + env(safe-area-inset-bottom)); }
}

.mchat-panel, .mchat-msg, .mchat-msg.bot, .mchat-msg.me { border-radius: 0; }
.mchat-suggest button { border-radius: 6px; }
.mchat-field { border-radius: 4px; }
.mchat-field:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (max-width: 699px) {
  html:has(.tabbar) .mchat, html:has(.select-bar):has(.shell) .mchat { bottom: calc(64px + 16px); }
  .mchat-open { width: 48px; min-width: 48px; height: 48px; padding: 12px; border-radius: 50%; }
  .mchat-open-label { display: none; }
  html:has(input:focus, textarea:focus, select:focus) .mchat:not(.is-open) { display: none; }
}

html[data-ledger="1"] .chat-launch { display: none; }

.mchat-head { background: #fff; backdrop-filter: none; -webkit-backdrop-filter: none; }
.mchat-panel { box-shadow: none; border: 1px solid #E2E8F0; }
@media (max-width: 699px) {
  html .mchat-field textarea { font-size: 17px; }
  html:has(.tabbar) .mchat-open, html[data-role="duty"] .mchat-open { display: none; }
  html:not(:has(.tabbar)):not([data-role="duty"]) .mchat:not(.is-open) { position: fixed; margin: 0; }
  html:not(:has(.tabbar)) .mchat-open { width: auto; padding: 0 16px; border-radius: 6px; box-shadow: none; }
  html:not(:has(.tabbar)) .mchat-open-label { display: inline; }
}

@media (max-width: 699px) {
  html:not(:has(.tabbar)) .mchat.is-compact .mchat-open-label { max-width: 6em; padding: 0 4px; opacity: 1; }
}

/* 生徒の質問は本文と重ならない下部の二次操作。 */
@media (max-width: 767px) {
  html[data-role="student"] .solo { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  html[data-role="student"] .mchat-open { background: var(--mc-bg); color: var(--mc-ink) !important; border: 1px solid var(--mc-field-line); border-radius: 6px; box-shadow: none; }
  .mchat-field textarea { min-height: 44px; }
}

.mchat-field { border-radius: 6px; }

/* 生徒：希望の送信バーが出ているときは、質問ボタンをバーの上に上げる */
@media (max-width: 767px) {
  html[data-role="student"]:has(.wish-send-bar) .mchat:not(.is-open) { bottom: calc(88px + env(safe-area-inset-bottom)); }
  html[data-role="student"]:has(.wish-send-bar) .solo { padding-bottom: calc(180px + env(safe-area-inset-bottom)); }
}

.mchat-send { width: 44px; height: 44px; border-radius: 6px; }
html[data-role="student"] .mchat-open { min-height: 44px; height: 44px; border-radius: 6px; }

/* 案内ページ・紹介ページでも、アプリ内と同じ二次ボタンの型にそろえる（角丸6px・影なし） */
.mchat-open { background: var(--mc-bg); color: var(--mc-ink) !important; border: 1px solid var(--mc-field-line); border-radius: 6px; box-shadow: none; min-height: 44px; }

/* LPの案内ページはbodyをスクロールする。質問ボタンが出る面だけ余白を確保。 */
html:not(:has(.tabbar)):not([data-role="duty"]):not([data-role="loading"]):not([data-ledger="1"]):has(.mchat:not([hidden])) body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

/* 生徒の質問は本文に重ならない固定タブ。 */
@media (max-width: 767px) {
  html[data-role="student"] .mchat:not(.is-open), html[data-role="student"]:has(.wish-send-bar) .mchat:not(.is-open) { left: 0; right: 0; bottom: 0; align-items: stretch; background: var(--mc-bg); border-top: 1px solid var(--mc-line); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
  html[data-role="student"] .mchat-open { justify-content: center; }
  html[data-role="student"] .wish-send-bar { bottom: calc(60px + env(safe-area-inset-bottom)); padding-bottom: 8px; }
  html[data-role="student"] .mchat-open-label { display: inline; max-width: none; opacity: 1; }
}

/* 生徒PC：質問ボタンは本文の列の右外に置く。列の外に余白が無い幅では、本文の下にボタン分の余白を取る。 */
@media (min-width: 1100px) {
  html[data-role="student"] .mchat:not(.is-open) { right: auto; left: calc(50% + 328px + 24px); bottom: 24px; }
}
@media (max-width: 1099px) {
  html[data-role="student"] .solo { padding-bottom: calc(96px + var(--safe-b, 0px)); }
}

/* 案内ページのフォーム（お知らせ登録・掲載の申込・問い合わせ）：スマホでは同意欄と送信ボタンに重ならないよう、絵だけの小さいボタンにする。 */
@media (max-width: 699px) {
  html:not([data-role]):has(form:not(.mchat form)) .mchat-open { width: 44px; min-width: 44px; padding: 0; justify-content: center; }
  html:not([data-role]):has(form:not(.mchat form)) .mchat-open-label { display: none; }
}

/* 学校・企業の「操作の案内」（スマホの帯から移した） */
.mchat-intro .mchat-help { display: block; margin-top: 8px; }
.mchat-intro .mchat-help[hidden] { display: none; }
