.ai-tutor-launcher,
.ai-tutor-panel {
  --ai-navy: #123b56;
  --ai-teal: #149584;
  --ai-line: #d5e4e6;
  --ai-muted: #60768a;
  --ai-surface: #f6f9fa;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

.ai-tutor-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 4200;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 52px;
  padding: 7px 17px 7px 8px;
  border: 1px solid rgba(255, 255, 255, .32);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--ai-navy), #0e6f73);
  color: #fff;
  box-shadow: 0 14px 34px rgba(15, 60, 78, .25);
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease;
}

.ai-tutor-launcher:hover { transform: translateY(-2px); box-shadow: 0 18px 38px rgba(15, 60, 78, .3); }
.ai-tutor-launcher:active { transform: translateY(1px); box-shadow: 0 8px 20px rgba(15, 60, 78, .22), inset 0 2px 5px rgba(0, 0, 0, .18); }
.ai-tutor-launcher:focus-visible,
.ai-tutor-panel button:focus-visible,
.ai-tutor-panel select:focus-visible,
.ai-tutor-panel textarea:focus-visible { outline: 3px solid rgba(20, 149, 132, .28); outline-offset: 2px; }
.ai-tutor-launcher-avatar { position: relative; display: grid; width: 40px; height: 40px; flex: 0 0 auto; place-items: center; overflow: visible; border: 2px solid rgba(255, 255, 255, .88); border-radius: 50%; background: linear-gradient(145deg, #fff, #e9f7f7); box-shadow: 0 4px 12px rgba(4, 42, 72, .2); }
.ai-tutor-launcher-avatar img { width: 42px; height: 42px; object-fit: contain; border-radius: 50%; }
.ai-tutor-launcher-avatar i { position: absolute; right: -1px; bottom: -1px; width: 9px; height: 9px; border: 2px solid #fff; border-radius: 50%; background: #31c49a; box-shadow: 0 0 0 2px rgba(49, 196, 154, .18); }
.ai-tutor-launcher > strong { font-size: 15px; letter-spacing: .02em; }
.ai-tutor-launcher[hidden] { display: none; }

.ai-tutor-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 4210;
  display: grid;
  grid-template-rows: auto auto minmax(210px, 1fr) auto;
  width: 440px;
  height: 600px;
  min-width: 360px;
  min-height: 460px;
  max-width: min(720px, calc(100vw - 32px));
  max-height: min(840px, calc(100vh - 32px));
  overflow: hidden;
  resize: none;
  border: 1px solid rgba(117, 151, 163, .42);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 24px 64px rgba(19, 55, 75, .24), 0 3px 12px rgba(19, 55, 75, .08);
}

.ai-tutor-panel[hidden] { display: none; }
.ai-tutor-panel.is-dragging { user-select: none; box-shadow: 0 30px 76px rgba(19, 55, 75, .32); }
.ai-tutor-panel.is-minimized { grid-template-rows: auto; width: 320px !important; height: auto !important; min-height: 0; }
.ai-tutor-panel.is-minimized .ai-tutor-toolbar,
.ai-tutor-panel.is-minimized .ai-tutor-chat-region,
.ai-tutor-panel.is-minimized .ai-tutor-body,
.ai-tutor-panel.is-minimized .ai-tutor-form,
.ai-tutor-panel.is-minimized .ai-tutor-resize-handle { display: none; }

.ai-tutor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  box-sizing: border-box;
  padding: 10px 12px;
  color: #fff;
  background: linear-gradient(125deg, var(--ai-navy), #0d696c);
  cursor: move;
  touch-action: none;
}

.ai-tutor-heading { display: flex; align-items: center; gap: 9px; min-width: 0; }
.ai-tutor-heading > div { display: grid; gap: 2px; }
.ai-tutor-heading strong { font-size: 15px; line-height: 1.25; }
.ai-tutor-heading small { color: rgba(255, 255, 255, .76); font-size: 11px; }
.ai-tutor-mark { display: grid; width: 38px; height: 38px; flex: 0 0 auto; place-items: center; overflow: hidden; border: 1px solid rgba(255, 255, 255, .72); border-radius: 10px; background: rgba(255, 255, 255, .96); box-shadow: 0 3px 10px rgba(0, 0, 0, .1); }
.ai-tutor-mark img { width: 40px; height: 40px; object-fit: contain; }
.ai-tutor-window-actions { display: flex; gap: 5px; }
.ai-tutor-window-actions button { display: grid; width: 30px; height: 30px; place-items: center; padding: 0; border: 0; border-radius: 8px; background: rgba(255, 255, 255, .12); color: #fff; font: inherit; font-size: 18px; cursor: pointer; }
.ai-tutor-window-actions button:hover { background: rgba(255, 255, 255, .23); }
.ai-tutor-window-actions button:active { transform: translateY(1px); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .2); }

.ai-tutor-toolbar {
  display: grid;
  grid-template-columns: auto minmax(116px, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  box-sizing: border-box;
  padding: 7px 12px;
  border-bottom: 1px solid var(--ai-line);
  background: #fff;
}
.ai-tutor-toolbar label { margin: 0; color: #476477; font-size: 11px; font-weight: 700; }
.ai-tutor-toolbar select { width: 100%; min-width: 0; height: 31px; margin: 0; border: 1px solid #cadbdf; border-radius: 8px; padding: 0 28px 0 9px; background: var(--ai-surface); color: #17384c; font: inherit; font-size: 12px; cursor: pointer; }
.ai-tutor-toolbar select:disabled { cursor: wait; color: #81919c; background: #f1f5f6; }
.ai-tutor-local-status { display: inline-flex; align-items: center; gap: 5px; color: #527082; font-size: 10px; white-space: nowrap; }
.ai-tutor-local-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--ai-teal); box-shadow: 0 0 0 3px rgba(20, 149, 132, .12); }
.ai-tutor-course-narration { grid-column: 1 / -1; display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; column-gap: 7px; min-height: 32px; padding: 4px 9px 4px 6px; border: 1px solid #a9d3ce; border-radius: 9px; background: linear-gradient(145deg, #f2fbf9, #fff); color: #184b59; font: inherit; text-align: left; cursor: pointer; box-shadow: 0 3px 9px rgba(18, 59, 86, .07); }
.ai-tutor-course-narration[hidden] { display: none; }
.ai-tutor-course-narration > b { display: grid; width: 22px; height: 22px; place-items: center; border-radius: 50%; background: var(--ai-teal); color: #fff; font-size: 9px; line-height: 1; }
.ai-tutor-course-narration > span { font-size: 11px; font-weight: 800; line-height: 1.2; white-space: nowrap; }
.ai-tutor-course-narration > small { justify-self: end; color: #607b86; font-size: 9px; line-height: 1.15; white-space: nowrap; }
.ai-tutor-course-narration:hover:not(:disabled) { border-color: var(--ai-teal); background: #eaf8f5; }
.ai-tutor-course-narration:active:not(:disabled) { transform: translateY(1px); box-shadow: inset 0 2px 4px rgba(18, 59, 86, .1); }
.ai-tutor-course-narration:disabled { border-style: dashed; background: #f5f7f8; color: #7d8d96; cursor: not-allowed; box-shadow: none; }
.ai-tutor-course-narration:disabled > b { background: #9dabb2; }

.ai-tutor-message.course-narration { width: 100%; max-width: 100%; }
.ai-tutor-message.course-narration > .ai-tutor-narration-choices { display: grid; gap: 7px; min-width: 0; padding: 10px; border: 1px solid #b9dcd7; border-radius: 4px 13px 13px 13px; background: linear-gradient(145deg, #f2fbf9, #fff); box-shadow: 0 4px 14px rgba(28, 78, 93, .055); }
.ai-tutor-narration-choices > p { margin: 0 0 2px; color: #335768; font-size: 12px; line-height: 1.55; }
.ai-tutor-narration-choice { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-width: 0; padding: 8px 9px; border: 1px solid #c7dedb; border-radius: 9px; background: #fff; color: #244758; font: inherit; text-align: left; cursor: pointer; }
.ai-tutor-narration-choice > b { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: var(--ai-teal); color: #fff; font-size: 10px; }
.ai-tutor-narration-choice > span { min-width: 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 700; line-height: 1.4; }
.ai-tutor-narration-choice > small { color: #667f8a; font-size: 10px; white-space: nowrap; }
.ai-tutor-narration-choice:hover { border-color: var(--ai-teal); background: #eef9f6; }
.ai-tutor-narration-choice:active { transform: translateY(1px); }

.ai-tutor-chat-region { position: relative; min-height: 0; overflow: hidden; }
.ai-tutor-body { width: 100%; height: 100%; min-height: 0; overflow: auto; overscroll-behavior: contain; background: linear-gradient(180deg, #f3f7f8 0, #f8fbfb 100%); scrollbar-color: #bfd0d5 transparent; scrollbar-width: thin; }
.ai-tutor-messages { display: grid; align-content: start; gap: 14px; min-height: 100%; box-sizing: border-box; padding: 18px 16px 24px; }
.ai-tutor-scroll-latest { position: absolute; left: 50%; bottom: 12px; z-index: 4; display: inline-flex; align-items: center; gap: 7px; min-height: 34px; transform: translateX(-50%); border: 1px solid #b9d7d4; border-radius: 999px; padding: 0 10px 0 13px; background: rgba(255, 255, 255, .96); color: #245668; font: inherit; font-size: 11px; font-weight: 700; white-space: nowrap; box-shadow: 0 7px 18px rgba(18, 59, 86, .16); cursor: pointer; backdrop-filter: blur(8px); }
.ai-tutor-scroll-latest b { display: grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; background: #e7f5f2; color: var(--ai-teal); font-size: 13px; line-height: 1; }
.ai-tutor-scroll-latest:hover { border-color: var(--ai-teal); background: #fff; }
.ai-tutor-scroll-latest:active { transform: translate(-50%, 1px); box-shadow: 0 4px 11px rgba(18, 59, 86, .13), inset 0 1px 3px rgba(18, 59, 86, .1); }
.ai-tutor-scroll-latest.has-new { border-color: #89cbc2; color: #116f66; }
.ai-tutor-scroll-latest[hidden] { display: none; }
.ai-tutor-message { display: grid; max-width: 86%; gap: 5px; }
.ai-tutor-message > span { color: var(--ai-muted); font-size: 11px; font-weight: 700; }
.ai-tutor-message > p { margin: 0; padding: 11px 13px; border: 1px solid var(--ai-line); border-radius: 4px 13px 13px 13px; background: #fff; color: #203d50; font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 4px 14px rgba(28, 78, 93, .055); }
.ai-tutor-message.assistant:not(.welcome) { grid-template-columns: 28px minmax(0, 1fr); column-gap: 7px; }
.ai-tutor-message.assistant:not(.welcome) > .ai-tutor-message-avatar { grid-row: 1 / 3; width: 28px; height: 28px; align-self: start; object-fit: contain; border: 1px solid #c7dfe2; border-radius: 9px; background: #fff; box-shadow: 0 3px 8px rgba(18, 59, 86, .08); }
.ai-tutor-message.assistant:not(.welcome) > span,
.ai-tutor-message.assistant:not(.welcome) > p { grid-column: 2; }
.ai-tutor-message.welcome { grid-template-columns: 104px minmax(0, 1fr); width: 100%; max-width: 100%; align-items: center; gap: 2px 12px; padding: 10px 12px 10px 8px; box-sizing: border-box; border: 1px solid #c8dfe0; border-radius: 14px; background: linear-gradient(135deg, #fff 0%, #f3fbfa 100%); box-shadow: 0 8px 22px rgba(28, 78, 93, .065); }
.ai-tutor-message.welcome > img { grid-row: 1 / 3; width: 104px; height: 104px; object-fit: contain; }
.ai-tutor-message.welcome > span { align-self: end; color: var(--ai-teal); font-size: 11px; letter-spacing: .08em; }
.ai-tutor-message.welcome > p { align-self: start; padding: 0; border: 0; background: transparent; box-shadow: none; line-height: 1.62; }
.ai-tutor-message.welcome > p strong { display: block; margin-bottom: 3px; color: var(--ai-navy); font-size: 15px; }
.ai-tutor-message.user { justify-self: end; }
.ai-tutor-message.user > span { text-align: right; }
.ai-tutor-message.user > p { border-color: #b5d8d4; border-radius: 13px 4px 13px 13px; background: #eaf6f4; }
.ai-tutor-message.status > p { border-style: dashed; color: var(--ai-muted); box-shadow: none; }
.ai-tutor-message.queued { position: relative; }
.ai-tutor-message.queued > p { min-height: 24px; padding-right: 64px; border-color: #c9dadd; background: #f4f8f8; color: #60768a; }
.ai-tutor-queue-remove { position: absolute; right: 8px; bottom: 8px; min-width: 46px; min-height: 27px; border: 1px solid #c6d6da; border-radius: 7px; padding: 0 8px; color: #526d7c; background: #fff; font: inherit; font-size: 10px; font-weight: 700; cursor: pointer; transition: border-color .15s ease, color .15s ease, background .15s ease, transform .08s ease; }
.ai-tutor-queue-remove:hover { border-color: #d49a91; color: #9a3f32; background: #fff8f5; }
.ai-tutor-queue-remove:active { transform: translateY(1px); }
.ai-tutor-queue-remove:focus-visible { outline: 2px solid rgba(20, 149, 132, .32); outline-offset: 2px; }
.ai-tutor-message.stopped > p { border-color: #e0c9bd; background: #fff9f5; color: #775246; }
.ai-tutor-message.truncated > p { border-color: #dbcfa9; background: #fffdf5; }
.ai-tutor-message.error > p { border-color: #f0c7c7; background: #fff5f5; color: #9b2c2c; }
.ai-tutor-message.system { justify-self: center; width: 100%; max-width: 100%; }
.ai-tutor-message.system > span { text-align: center; color: #527082; }
.ai-tutor-message.system > p { padding: 7px 11px; border-color: #c8dedc; border-radius: 999px; background: #eef7f5; color: #315b61; font-size: 12px; line-height: 1.5; text-align: center; box-shadow: none; }

.ai-tutor-form { display: grid; gap: 6px; padding: 10px 12px 9px; border-top: 1px solid var(--ai-line); background: #fff; }
.ai-tutor-composer { display: grid; gap: 7px; padding: 8px 9px 8px 11px; border: 1px solid #b9d0d5; border-radius: 12px; background: #fbfdfd; box-shadow: 0 3px 12px rgba(25, 70, 86, .05); transition: border-color .15s ease, box-shadow .15s ease; }
.ai-tutor-composer:focus-within { border-color: var(--ai-teal); box-shadow: 0 0 0 3px rgba(20, 149, 132, .11); }
.ai-tutor-composer > .sr-only { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.ai-tutor-form textarea { width: 100%; height: 46px; min-height: 46px; max-height: 108px; box-sizing: border-box; margin: 0; resize: none; overflow-y: auto; border: 0; padding: 4px 2px; background: transparent; color: #17384c; font: inherit; font-size: 14px; line-height: 1.55; outline: 0; }
.ai-tutor-form textarea:focus-visible { outline: 0; }
.ai-tutor-form textarea::placeholder { color: #8a9ba8; }
.ai-tutor-form-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ai-tutor-form-actions small { color: #788d99; font-size: 10px; }
.ai-tutor-form-actions #ai-tutor-queue-status { color: #527082; font-weight: 700; }
.ai-tutor-submit-actions { display: flex; align-items: center; gap: 7px; }
.ai-tutor-form-actions button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 82px; min-height: 34px; border: 0; border-radius: 8px; padding: 0 12px; background: var(--ai-navy); color: #fff; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 5px 13px rgba(18, 59, 86, .16); }
.ai-tutor-form-actions button b { display: grid; width: 19px; height: 19px; place-items: center; border-radius: 50%; background: rgba(255, 255, 255, .16); font-size: 13px; line-height: 1; }
.ai-tutor-form-actions button:hover { background: #0f4a6b; }
.ai-tutor-form-actions button:active { transform: translateY(1px); box-shadow: inset 0 2px 5px rgba(0, 0, 0, .2); }
.ai-tutor-form-actions button:disabled { cursor: not-allowed; opacity: .58; transform: none; box-shadow: none; }
.ai-tutor-form-actions .ai-tutor-stop { min-width: 72px; border: 1px solid #d8b9ae; background: #fff8f5; color: #9a3f32; box-shadow: none; }
.ai-tutor-form-actions .ai-tutor-stop:hover { background: #fff0eb; }
.ai-tutor-form-actions .ai-tutor-stop b { background: rgba(154, 63, 50, .1); }
.ai-tutor-form-actions .ai-tutor-stop[hidden] { display: none; }
.ai-tutor-notice { margin: 0; color: #7a8d98; font-size: 10px; line-height: 1.5; text-align: center; }

.ai-tutor-resize-handle { position: absolute; right: 3px; bottom: 3px; z-index: 3; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 5px; background: transparent; cursor: nwse-resize; opacity: .26; transition: opacity .15s ease, background .15s ease; }
.ai-tutor-resize-handle::before { content: ""; position: absolute; right: 3px; bottom: 3px; width: 9px; height: 9px; background: linear-gradient(135deg, transparent 0 44%, #6f8997 46% 53%, transparent 55% 68%, #6f8997 70% 77%, transparent 79%); }
.ai-tutor-panel:hover .ai-tutor-resize-handle,
.ai-tutor-resize-handle:focus-visible { opacity: .75; background: rgba(20, 149, 132, .08); }

@media (max-width: 700px) {
  .ai-tutor-launcher { right: 14px; bottom: 14px; }
  .ai-tutor-panel { inset: auto 8px 8px 8px !important; width: auto !important; height: min(78dvh, 620px) !important; min-width: 0; min-height: min(420px, calc(100dvh - 16px)); max-width: none; max-height: calc(100dvh - 16px); border-radius: 14px; }
  .ai-tutor-panel.is-minimized { left: auto !important; width: min(320px, calc(100vw - 16px)) !important; min-height: 0; }
  .ai-tutor-header { cursor: default; }
  .ai-tutor-toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .ai-tutor-toolbar label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .ai-tutor-messages { padding: 14px 12px 18px; }
  .ai-tutor-message { max-width: 92%; }
  .ai-tutor-message.system { max-width: 100%; }
  .ai-tutor-message.welcome { grid-template-columns: 78px minmax(0, 1fr); padding: 8px 9px 8px 5px; gap: 2px 9px; }
  .ai-tutor-message.welcome > img { width: 78px; height: 78px; }
  .ai-tutor-message.welcome > p { font-size: 12px; line-height: 1.55; }
  .ai-tutor-message.welcome > p strong { font-size: 14px; }
  .ai-tutor-form { padding: 9px 10px 8px; }
  .ai-tutor-form-actions small { max-width: 62%; }
  .ai-tutor-resize-handle { display: none; }
  .ai-tutor-course-narration { min-width: 0; padding-right: 7px; }
  .ai-tutor-course-narration > span { font-size: 10px; }
  .ai-tutor-course-narration > small { display: block; }
  .ai-tutor-narration-choice { grid-template-columns: 26px minmax(0, 1fr) auto; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-tutor-launcher,
  .ai-tutor-composer,
  .ai-tutor-resize-handle { transition: none; }
}
