.chat-launch {
  display:flex; align-items:center; gap:10px; width:100%; min-height:46px;
  padding:13px 14px; margin:0 0 18px; border:1px solid #d7caf6; border-radius:9px;
  background:#f6f2ff; color:#7150ce; font-size:12px; font-weight:650; text-align:left;
}
.chat-launch:hover { background:#eee7ff; border-color:#aa91e8; }
.chat-launch>span:last-child { margin-left:auto; font-size:19px; }
.chat-launch svg {
  width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.6;
  stroke-linecap:round; stroke-linejoin:round; flex-shrink:0;
}
.chat-options-toggle {
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  width:100%; min-height:40px; padding:3px 0; color:#53604d; font-size:12px; text-align:left;
}
#chat-options-label { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-options-action { color:#7252b9; white-space:nowrap; }
.composer-toolbar {
  display:flex; align-items:center; gap:12px; margin-bottom:8px;
}
.composer-picker { flex:none; min-width:0; }
.composer-picker:last-of-type { flex-shrink:1; }
.composer-picker select {
  display:block; width:auto; min-width:0; max-width:100%; min-height:40px;
  appearance:none; field-sizing:content; padding:6px 0; border:0;
  background:transparent; color:#68508f; font-size:12px; font-weight:400;
  text-decoration:underline dotted #9c82be; text-underline-offset:3px;
  white-space:nowrap; text-overflow:ellipsis; cursor:pointer;
}
.composer-picker select:hover { color:#4e3291; }
.composer-picker select:focus-visible { outline:2px solid #aa91e8; outline-offset:2px; }
.chat-collapse-input { display:none; }
.chat-collapse-input svg { display:none; width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.6; stroke-linecap:round; stroke-linejoin:round; }
.chat-header-actions { display:flex; align-items:center; gap:6px; flex-shrink:0; }
.chat-restore-input {
  min-height:42px; padding:7px 10px; border:1px solid #ded7ee; border-radius:9px;
  color:#5a4195; background:#f8f5ff; font-size:12px;
}
.chat-restore-input:hover { background:#eee7ff; }
#question-form:not(.chat-options-open) .composer-settings { display:none; }
.composer-settings .form-row { margin:8px 0 12px; }
.composer-settings .answer-options { margin:0 0 12px; }
.composer-settings .mode-grid label>span {
  min-height:40px; display:grid; place-items:center; padding:7px 5px;
  font-size:11px; line-height:1.2; text-align:center;
}
.question-reply {
  display:flex; justify-content:space-between; align-items:baseline;
  flex-wrap:wrap; gap:3px 10px; padding:8px 12px 0; color:#514172; font-size:12px;
}
.question-reply label { font-weight:700; }
.question-reply span { color:#65715c; }
.solve-number,.solve-reply { display:none; }
#question-form[data-reply] .solve-default { display:none; }
#question-form[data-reply=number] .solve-number,
#question-form[data-reply=detail] .solve-reply { display:inline; }
#question-form[data-reply=number] textarea { min-height:52px; height:52px; resize:none; }
body.chat-is-open { overflow:hidden; }
.chat-screen {
  position:fixed; top:var(--chat-viewport-top,0px); right:0; bottom:auto; left:0;
  width:100%; height:100vh; height:var(--chat-viewport-height,100dvh);
  margin:0; padding:0; border:0; max-width:none; max-height:none; overflow:hidden;
  background:#f8f9f5; color:#25322b; overscroll-behavior:none;
}
.chat-screen[open] { display:flex; flex-direction:column; }
.chat-screen::backdrop { background:#f8f9f5; }
.chat-header {
  display:flex; align-items:center; justify-content:space-between; flex-shrink:0; gap:16px;
  padding:12px max(16px,calc((100% - 960px)/2));
  padding-top:max(12px,env(safe-area-inset-top));
  border-bottom:1px solid #e5ddec; background:#fff;
}
.chat-identity { display:flex; align-items:center; gap:10px; min-width:0; }
.chat-avatar {
  display:grid; place-items:center; width:36px; height:36px; flex-shrink:0;
  border-radius:10px; background:#eae2fc; color:#7957d5; font-size:22px;
}
.chat-header :is(h1,h2) { font-size:16px; letter-spacing:-.3px; margin:0 0 3px; }
.chat-header p { font-size:11px; color:#65715c; margin:0; }
.chat-close {
  display:flex; align-items:center; justify-content:center; gap:8px; flex-shrink:0;
  min-width:42px; min-height:42px; border:1px solid #dfe5d7; border-radius:9px;
  padding:8px 11px; font-size:12px; background:#fff;
}
.chat-close:hover { background:#f0f3e9; }
.chat-close svg { width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.5; stroke-linecap:round; }
.chat-thread {
  flex:1; min-height:0; overflow-y:auto; overscroll-behavior:contain;
  scrollbar-gutter:stable; padding:23px 20px 16px;
}
.chat-welcome {
  max-width:620px; min-height:100%; margin:auto; display:flex; flex-direction:column;
  align-items:center; justify-content:center; text-align:center; padding:14px 0 22px;
}
.chat-welcome-mark {
  display:grid; place-items:center; height:56px; width:56px; font-size:35px;
  border-radius:16px; background:#e8edda; color:#8da755; margin-bottom:16px; transform:rotate(-8deg);
}
.chat-welcome h2 { font-size:clamp(28px,3.3vw,43px); line-height:1.15; margin-bottom:12px; }
.chat-welcome p { font-size:14px; line-height:1.65; color:#65715c; margin:0 0 16px; }
.chat-example {
  display:flex; align-items:center; gap:15px; border:1px solid #ded7ee; background:#fff;
  border-radius:10px; padding:10px 14px; font-size:12px; color:#7756c9; min-height:42px;
}
.chat-example:hover { background:#f0eafa; }
.chat-messages { max-width:800px; margin:auto; }
.chat-exchange { margin:0 0 24px; min-width:0; }
.chat-question { display:flex; flex-direction:column; align-items:flex-end; margin-bottom:17px; gap:6px; }
.chat-question-label { font-size:11px; color:#65715c; }
.chat-question-bubble {
  max-width:90%; border:1px solid #ddd3f3; background:#eee7fb; padding:10px 15px;
  border-radius:15px 15px 4px 15px; color:#52406e;
  white-space:pre-wrap; overflow-wrap:anywhere; font-size:15px; line-height:1.6;
}
.chat-question-image {
  max-width:min(300px,85%); max-height:160px; object-fit:contain;
  border:1px solid #d9dfcf; border-radius:10px; background:#fff;
}
.chat-answer { display:grid; grid-template-columns:28px minmax(0,1fr); gap:11px; }
.chat-answer > div {
  min-width:0; padding:11px 14px; background:#fff; border:1px solid #e6dfee;
  border-radius:5px 14px 14px;
}
.chat-answer-avatar {
  display:grid; place-items:center; height:28px; width:28px; border-radius:8px;
  background:#e6edd8; color:#789448; font-size:18px;
}
.chat-answer-title { font-size:13px; letter-spacing:0; margin:0 0 8px; font-weight:650; color:#5b4387; }
.chat-answer .prose { font-size:15px; line-height:1.7; }
.chat-answer .prose :is(strong,h2,h3,h4) { color:#513a73; }
.chat-answer-meta { font-size:11px; color:#65715c; margin:8px 0 4px; }
.chat-answer-copy { font-size:12px; color:#7252b9; min-height:34px; padding:5px 0; text-decoration:underline; text-underline-offset:3px; }
.chat-answer-reply { margin-top:5px; min-height:38px; }
.chat-answer-error { color:#a63e39; font-size:13px; line-height:1.6; }
.chat-dock {
  flex-shrink:0; padding:4px 18px max(10px,env(safe-area-inset-bottom));
  background:#f6f3fa; border-top:1px solid #e9e2ef;
}
.chat-dock .solver-card {
  position:relative; max-width:800px; margin:auto; padding:8px 13px;
  border-radius:15px; box-shadow:0 6px 25px #2e41200a;
}
.chat-dock .solver-top,.chat-dock #solver-title,.chat-dock .solver-card>.muted,.chat-dock .chat-launch { display:none; }
.chat-dock #question-form {
  display:grid; grid-template-columns:minmax(0,1fr) auto; column-gap:10px; row-gap:6px;
}
.chat-dock #question-form>* { grid-column:1/-1; }
.chat-dock .composer-toolbar { margin:0; }
.chat-dock .chat-collapse-input {
  display:block; flex:none; min-height:40px; margin-left:auto; padding:0 4px; color:#7252b9;
  font-size:12px; white-space:nowrap;
}
.chat-dock .chat-collapse-input:hover { color:#4e3291; }
.chat-dock .chat-options-toggle { min-height:34px; }
.chat-dock .composer-settings {
  position:absolute; inset:auto 0 calc(100% + 6px); z-index:2; overflow:auto;
  max-height:260px; max-height:min(260px,calc(var(--chat-viewport-height,100dvh)*0.42));
  padding:8px 14px; background:#fff; border:1px solid #dfd9e9;
  border-radius:13px; box-shadow:0 7px 25px #3e295f23;
}
.chat-dock #question-form:not(.chat-options-open)>.form-row,
.chat-dock #question-form:not(.chat-options-open)>.answer-options { display:none; }
.chat-dock .task-input { margin:0; border-color:#ddd4e9; background:#fdfcff; }
.chat-dock .task-input:focus-within { border-color:#b7a4da; }
.chat-dock .task-input textarea {
  display:block; height:54px; min-height:48px; max-height:100px; resize:none;
  padding:8px 11px; font-size:16px; line-height:1.45;
}
.chat-dock #question-form[data-reply=number] textarea { height:39px; min-height:39px; }
.chat-dock .attach-row { padding:1px 10px; justify-content:flex-start; gap:13px; background:#f6f1fb; }
.chat-dock .attach-button { font-size:12px; min-height:34px; color:#654c95; }
.chat-dock .camera-button { padding-left:13px; }
.chat-dock .upload-hint,.chat-dock #question-form.photo-reply .attach-row { display:none; }
.chat-dock #question-form>.ai-check {
  grid-column:1; align-self:center; font-size:11px; margin:0; line-height:1.35; color:#59664f;
}
.chat-dock #question-form>.solve-button {
  grid-column:2; align-self:end; min-height:42px; width:auto; margin:0;
  padding:9px 12px; font-size:12px; gap:7px;
}
.chat-dock .solve-button>span:last-child { font-size:inherit; }
.chat-dock .solver-note { margin:0; font-size:11px; }
.chat-dock .image-preview { padding:4px 10px; }
.chat-dock .image-preview img { height:32px; width:42px; }
.chat-dock .image-preview .icon-button { min-width:36px; min-height:36px; }
.chat-dock #question-form.photo-reply .image-preview img { height:27px; width:36px; }
.chat-dock .form-error { margin:0; }
@media(max-width:700px) {
  .chat-header { padding:7px 13px; padding-top:max(7px,env(safe-area-inset-top)); gap:8px; }
  .chat-header :is(h1,h2) { font-size:15px; }
  .chat-header p { font-size:10px; }
  .chat-close>span { display:none; }
  .chat-thread { padding:14px 12px 10px; }
  .chat-welcome h2 { font-size:28px; }
  .chat-welcome p { font-size:13px; margin-bottom:13px; }
  .chat-dock { padding:2px 8px max(6px,env(safe-area-inset-bottom)); }
  .chat-dock .solver-card { padding:6px 9px; border-radius:13px; }
  .chat-dock #question-form { column-gap:6px; }
  .chat-dock .solve-button .solve-default { max-width:112px; line-height:1.2; }
  .chat-question-bubble { font-size:14px; }
  .chat-answer { grid-template-columns:25px minmax(0,1fr); gap:8px; }
  .chat-answer > div { padding:9px 10px; }
  .chat-answer-avatar { height:25px; width:25px; font-size:16px; }
  .chat-answer .prose { font-size:14px; }
}
@media(max-width:370px) {
  .composer-toolbar { gap:6px; }
  .composer-picker select { font-size:11px; }
  .chat-dock .chat-collapse-input {
    display:grid; flex-basis:38px; place-items:center; padding:0;
    border:1px solid #ded7ee; border-radius:8px; background:#f8f5ff;
  }
  .chat-collapse-input span { display:none; }
  .chat-collapse-input svg { display:block; }
  .composer-settings .form-row { flex-wrap:wrap; }
  .composer-settings .form-row>label { flex-basis:100%; }
  .composer-settings .form-row .grade-field { flex-basis:100%; }
}
@media(max-height:440px) {
  .chat-header p,.chat-welcome-mark { display:none; }
  .chat-thread { padding-top:9px; }
}
@media(prefers-reduced-motion:reduce) { .chat-thread { scroll-behavior:auto; } }
