/* ครูผู้ช่วย AI */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.tl-avatar {
  width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: var(--gold); box-shadow: inset 0 0 0 2px rgb(255 190 26 / 0.55);
}
.tl-avatar i { font-size: 1.25rem; }
.tl-avatar.sm { width: 32px; height: 32px; }
.tl-avatar.sm i { font-size: 1rem; }

.tutor-launch {
  position: fixed; right: var(--s-300); bottom: var(--s-300); z-index: 55;
  display: flex; align-items: center; gap: var(--s-100); cursor: pointer;
  padding: var(--s-75) var(--s-300) var(--s-75) var(--s-75);
  background: var(--ink); color: #fff; border: 0; border-radius: var(--r-full);
  box-shadow: 0 12px 32px rgb(30 24 40 / 0.28);
  transition: transform .5s var(--ease), opacity .3s var(--ease), background-color .3s var(--ease);
}
.tutor-launch:hover { transform: translateY(-2px); background: #2e2540; }
.tutor-launch:active { transform: scale(0.98); }
.tl-text { display: grid; text-align: left; line-height: 1.35; }
.tl-text strong { font-size: 0.875rem; font-weight: 600; }
.tl-text small { font-size: 0.75rem; color: rgb(255 255 255 / 0.65); }
.is-reader .tutor-launch { bottom: 104px; }
.tutor-open .tutor-launch { opacity: 0; pointer-events: none; transform: translateY(16px); }
@media (max-width: 640px) {
  .tutor-launch { right: var(--s-200); bottom: var(--s-200); padding: var(--s-50); }
  .tl-text { display: none; }
  .is-reader .tutor-launch { bottom: 136px; }
}

.tutor {
  position: fixed; right: var(--s-200); top: var(--s-200); bottom: var(--s-200); z-index: 80;
  width: min(440px, calc(100vw - 32px));
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-3xl);
  box-shadow: 0 24px 64px rgb(30 24 40 / 0.22);
  opacity: 0; transform: translateX(24px);
  transition: opacity .4s var(--ease), transform .5s var(--ease);
}
.tutor[hidden] { display: none; }
.tutor.show { opacity: 1; transform: none; }
@media (max-width: 640px) {
  .tutor { inset: 0; width: 100%; border-radius: 0; border: 0; transform: translateY(24px); }
}

.tu-head { display: flex; align-items: center; gap: var(--s-100); padding: var(--s-200); border-bottom: 1px solid var(--line); }
.tu-who { flex: 1; min-width: 0; display: grid; line-height: 1.4; }
.tu-who strong { font-size: 1rem; font-weight: 600; }
.tu-who small { font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tu-body { flex: 1; overflow-y: auto; padding: var(--s-200); display: flex; flex-direction: column; gap: var(--s-200); scrollbar-width: thin; }
.tu-welcome { display: flex; gap: var(--s-100); }
.tu-welcome p { font-size: 0.875rem; line-height: 1.7; color: var(--ink-2); }
.tu-welcome p + p { margin-top: var(--s-75); }
.tu-suggest { display: flex; flex-wrap: wrap; gap: var(--s-75); padding-left: 44px; }
.tu-suggest button {
  display: inline-flex; align-items: center; gap: var(--s-50); cursor: pointer;
  padding: var(--s-75) var(--s-100); border-radius: var(--r-full); border: 1px solid var(--line);
  background: var(--paper); font-size: 0.875rem; color: var(--ink);
  transition: border-color .3s var(--ease), background-color .3s var(--ease);
}
.tu-suggest button:hover { border-color: var(--brand); background: var(--brand-50); }
.tu-suggest i { color: var(--brand); }

.tu-msg { display: flex; gap: var(--s-100); align-items: flex-start; }
.tu-msg.me { flex-direction: column; align-items: flex-end; gap: var(--s-75); }
.tu-msg.me img { max-width: 70%; border-radius: var(--r-xl); border: 1px solid var(--line); }
.bubble { font-size: 0.875rem; line-height: 1.75; max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
.tu-msg.me .bubble { background: var(--brand); color: #fff; padding: var(--s-75) var(--s-200); border-radius: var(--r-2xl) var(--r-2xl) var(--r-md) var(--r-2xl); max-width: 85%; }
.tu-msg.ai .bubble { padding-top: var(--s-50); flex: 1; }
.bubble.md p + p, .bubble.md p + ul, .bubble.md p + ol, .bubble.md ul + p, .bubble.md ol + p { margin-top: var(--s-100); }
.bubble.md ul, .bubble.md ol { padding-left: var(--s-300); margin: var(--s-75) 0; display: grid; gap: var(--s-50); }
.bubble.md ul { list-style: disc; }
.bubble.md h4 { font-size: 1rem; font-weight: 600; margin: var(--s-200) 0 var(--s-50); }
.bubble.md h4:first-child { margin-top: 0; }
.bubble.md code { font-family: var(--mono); font-size: 0.75rem; background: var(--paper); padding: 1px var(--s-50); border-radius: 4px; }
.bubble.err { background: #fdf1ef; color: var(--err); padding: var(--s-100) var(--s-200); border-radius: var(--r-xl); }
.bubble.err .btn { margin-top: var(--s-75); }
.caret { display: inline-block; width: 6px; height: 14px; margin-left: 2px; background: var(--brand); vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.tu-skel { display: grid; gap: var(--s-75); padding-top: var(--s-50); }
.tu-skel span { height: 10px; border-radius: var(--r-full); background: var(--paper); animation: shimmer 1.2s var(--ease) infinite alternate; }
.tu-skel span:nth-child(1) { width: 80%; } .tu-skel span:nth-child(2) { width: 92%; } .tu-skel span:nth-child(3) { width: 55%; }
@keyframes shimmer { from { opacity: 1; } to { opacity: .4; } }

.tu-compose { padding: var(--s-100) var(--s-200) var(--s-200); border-top: 1px solid var(--line); }
.tu-attach { display: flex; align-items: center; gap: var(--s-100); padding: var(--s-75); margin-bottom: var(--s-75); background: var(--paper); border-radius: var(--r-xl); font-size: 0.75rem; color: var(--ink-2); }
.tu-attach[hidden] { display: none; }
.tu-attach img { width: 48px; height: 48px; object-fit: cover; border-radius: var(--r-lg); }
.tu-attach span { flex: 1; }
.tu-row { display: flex; align-items: flex-end; gap: var(--s-75); padding: var(--s-50); border: 1px solid var(--line-strong); border-radius: var(--r-2xl); background: #fff; transition: border-color .3s var(--ease), box-shadow .3s var(--ease); }
.tu-row:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgb(127 70 184 / 0.12); }
.tu-row .icon-btn { border: 0; background: var(--paper); width: 40px; height: 40px; }
.tu-row textarea { flex: 1; border: 0; outline: none; resize: none; font: inherit; font-size: 1rem; line-height: 1.5; padding: var(--s-75) var(--s-50); min-height: 40px; max-height: 160px; background: transparent; }
.tu-send { width: 40px; height: 40px; flex: none; border: 0; border-radius: var(--r-xl); background: var(--brand); color: #fff; display: grid; place-items: center; cursor: pointer; transition: background-color .3s var(--ease), transform .3s var(--ease); }
.tu-send:hover { background: var(--brand-700); }
.tu-send:active { transform: scale(0.96); }
.tu-send:disabled { background: var(--line-strong); cursor: wait; }
.tu-send i { font-size: 1.125rem; }
.tu-note { margin-top: var(--s-75); font-size: 0.75rem; color: var(--muted); text-align: center; }

/* quiz */
.bubble.wide { width: 100%; }
.quiz { border: 1px solid var(--line); border-radius: var(--r-xl); overflow: hidden; }
.quiz-head { display: flex; justify-content: space-between; padding: var(--s-100) var(--s-200); background: var(--paper); font-size: 0.875rem; }
.quiz-head span { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; }
.qz { padding: var(--s-200); border-top: 1px solid var(--line); }
.qz-q { font-weight: 500; }
.qz-q b { color: var(--brand); }
.qz-c { display: grid; gap: var(--s-50); margin-top: var(--s-100); }
.qz-opt {
  display: flex; align-items: flex-start; gap: var(--s-100); text-align: left; cursor: pointer;
  padding: var(--s-75) var(--s-100); border-radius: var(--r-lg); border: 1px solid var(--line); background: #fff; font-size: 0.875rem; line-height: 1.6;
  transition: border-color .3s var(--ease), background-color .3s var(--ease);
}
.qz-opt span { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--paper); font-size: 0.75rem; font-weight: 600; }
.qz-opt:hover:not([disabled]) { border-color: var(--brand); }
.qz-opt[disabled] { cursor: default; }
.qz-opt.ok { border-color: var(--ok); background: var(--ok-50); }
.qz-opt.ok span { background: var(--ok); color: #fff; }
.qz-opt.no { border-color: var(--err); background: #fdf1ef; }
.qz-opt.no span { background: var(--err); color: #fff; }
.qz-opt.dim { opacity: .55; }
.qz-x { margin-top: var(--s-100); font-size: 0.875rem; color: var(--ink-2); padding: var(--s-75) var(--s-100); background: var(--paper); border-radius: var(--r-lg); }
.quiz-score { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-75) var(--s-200); padding: var(--s-200); background: var(--gold-50); border-top: 1px solid var(--line); }
.quiz-score span { flex: 1; font-size: 0.875rem; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) { .caret, .tu-skel span { animation: none; } }
