/* Floating study tutor: launcher, panel (floating card from 640px, full-screen sheet below),
   messages, composer and the conversations list. Colours, radii and shadows come from tokens.css. */

/* ---- Launcher ------------------------------------------------------------------- */
.tutor-fab {
  position: fixed;
  z-index: var(--z-fab);
  right: max(16px, calc(env(safe-area-inset-right, 0px) + 16px));
  bottom: calc(var(--fab-bottom, 0px) + max(16px, calc(env(safe-area-inset-bottom, 0px) + 16px)));
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--accent) 60%, transparent), var(--shadow-md);
  transition: transform var(--dur) var(--ease), background-color var(--dur-fast) var(--ease),
    box-shadow var(--dur) var(--ease), opacity var(--dur) var(--ease), bottom var(--dur-slow) var(--ease-out);
}
@media (hover: hover) {
  .tutor-fab:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 14px 30px -8px color-mix(in srgb, var(--accent) 65%, transparent), var(--shadow-md);
  }
  .tutor-fab:hover > .icon { transform: rotate(-8deg); }
}
.tutor-fab:active { transform: scale(.95); }
.tutor-fab:focus-visible { box-shadow: var(--focus), var(--shadow-md); }
.tutor-fab > .icon { transition: transform var(--dur) var(--ease); }

/* Hidden while the panel is open (the panel covers its corner). */
.tutor.is-open .tutor-fab {
  opacity: 0; transform: scale(.6);
  visibility: hidden; pointer-events: none;
  transition: transform var(--dur) var(--ease), opacity var(--dur-fast) var(--ease), visibility 0s linear var(--dur);
}

.tutor-fab-label {
  position: absolute; top: 50%; right: calc(100% + 12px);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--text); color: var(--bg);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.3; white-space: nowrap;
  box-shadow: var(--shadow-md);
  opacity: 0; transform: translate(6px, -50%);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .tutor-fab:hover .tutor-fab-label,
  .tutor-fab:focus-visible .tutor-fab-label { opacity: 1; transform: translate(0, -50%); transition-delay: 60ms; }
}

/* A reply finished while the panel was closed. */
.tutor-fab-dot {
  position: absolute; top: 2px; right: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2.5px var(--surface);
  animation: tutor-pop var(--dur-slow) var(--ease-out) both;
}
@keyframes tutor-pop { from { transform: scale(0); } }

/* One-time nudge on the first in-progress question of a session. */
.tutor-fab::after {
  content: ""; position: absolute; inset: 0;
  border-radius: inherit; pointer-events: none; opacity: 0;
}
.tutor-fab.is-pulsing::after { animation: tutor-pulse 1.5s var(--ease-out) 2; }
@keyframes tutor-pulse {
  0% { opacity: .6; box-shadow: 0 0 0 0 var(--accent); }
  100% { opacity: 0; box-shadow: 0 0 0 18px var(--accent); }
}

/* ---- Panel ---------------------------------------------------------------------- */
.tutor-panel {
  position: fixed;
  z-index: var(--z-panel);
  right: max(16px, calc(env(safe-area-inset-right, 0px) + 16px));
  /* Like the launcher, it sits above a page's sticky bottom bar (the quiz between 640 and 1024px). */
  bottom: calc(var(--fab-bottom, 0px) + max(16px, calc(env(safe-area-inset-bottom, 0px) + 16px)));
  width: min(400px, calc(100vw - 32px));
  /* Never reaches the sticky header: its top stays at least 16px below it. */
  height: min(640px, calc(100vh - var(--header-h) - env(safe-area-inset-top, 0px) - 32px - var(--fab-bottom, 0px)));
  height: min(640px, calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px) - 32px - var(--fab-bottom, 0px)));
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  /* Grows out of the launcher's centre. */
  transform-origin: calc(100% - 28px) calc(100% - 28px);
  opacity: 0;
  transform: translateY(8px) scale(.94);
  visibility: hidden;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur) var(--ease-out),
    width var(--dur-slow) var(--ease-out), height var(--dur-slow) var(--ease-out), visibility 0s linear var(--dur);
}
.tutor-panel.is-open { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; }
.tutor-panel.is-expanded {
  width: min(560px, calc(100vw - 32px));
  height: calc(100vh - var(--header-h) - env(safe-area-inset-top, 0px) - 32px - var(--fab-bottom, 0px));
  height: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px) - 32px - var(--fab-bottom, 0px));
}
.tutor-panel:focus-visible { box-shadow: var(--shadow-lg); }

.tutor-view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.tutor-view.is-entering { animation: tutor-view-in var(--dur) var(--ease-out) both; }
.tutor-convos.is-entering { animation-name: tutor-view-in-back; }
@keyframes tutor-view-in { from { opacity: 0; transform: translateX(12px); } }
@keyframes tutor-view-in-back { from { opacity: 0; transform: translateX(-12px); } }

/* ---- Header --------------------------------------------------------------------- */
.tutor-head {
  flex: none;
  display: flex; align-items: center; gap: 2px;
  min-height: 60px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.tutor-head-main {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  padding: 0 6px;
}
.tutor-title {
  max-width: 100%;
  font-size: 15px; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tutor-title:focus-visible { box-shadow: none; text-decoration: underline; text-underline-offset: 3px; }
/* Chat title: the text truncates rather than the heading, so the rename button's ring isn't clipped. */
.tutor-chat .tutor-title { display: flex; overflow: visible; }
.tutor-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tutor-title-btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 0; max-width: calc(100% + 12px);
  margin: -3px -6px; padding: 3px 6px;
  border-radius: var(--radius-sm);
  color: inherit; font: inherit; letter-spacing: inherit; text-align: left;
  transition: background-color var(--dur-fast) var(--ease);
}
/* An inset ring (like .list-item's): an outer one would spill onto the context pill just below. */
.tutor-title-btn:focus-visible { box-shadow: none; outline: 2px solid var(--accent); outline-offset: -2px; }
.tutor-chat .tutor-title + .tutor-ctx { margin-top: 2px; } /* keeps the ring off the pill; fits the 60px header */
.tutor-title-pencil {
  flex: none; display: inline-grid; place-items: center;
  color: var(--text-3);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tutor-title-btn:focus-visible .tutor-title-pencil { opacity: 1; color: var(--text-2); }
@media (hover: hover) {
  .tutor-title-btn:hover { background: var(--surface-2); }
  .tutor-title-btn:hover .tutor-title-pencil { opacity: 1; color: var(--text-2); }
}
/* No hover on touch screens: the pencil stays faintly visible so the title reads as tappable. */
@media (hover: none) {
  .tutor-title-pencil { opacity: .75; }
}
.tutor-ctx {
  display: inline-flex; align-items: center; gap: 4px;
  max-width: 100%;
  padding: 1px 8px 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 12px; font-weight: 550; line-height: 18px;
}
.tutor-ctx > .icon { flex: none; }
.tutor-ctx-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tutor-head > .btn { flex: none; }
.tutor-head > .btn-icon { color: var(--text-2); }
.tutor-head > .btn-icon:hover { color: var(--text); }
.tutor-new { flex: none; margin-right: 2px; }
.tutor-head > .btn-icon[aria-pressed="true"] { color: var(--accent-text); }

/* Renaming from the header: the editor gets the whole row (its Cancel would sit beside Close otherwise). */
.tutor-head.is-renaming > :not(.tutor-head-rename) { display: none; }
.tutor-head-rename { flex: 1 1 auto; min-width: 0; display: flex; padding-left: 2px; }
.tutor-head-rename .tutor-rename-input { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }

/* ---- Message log ---------------------------------------------------------------- */
.tutor-log-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.tutor-log {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 18px;
  padding: 16px 16px 24px;
  overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.tutor-log:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }

.tutor-intro {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 12px 4px;
  text-align: center;
}
.tutor-intro-mark {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  margin-bottom: 8px;
  border-radius: 14px;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}
.tutor-intro-title { font-size: var(--fs-base); font-weight: 650; letter-spacing: -0.01em; }
.tutor-intro-sub { max-width: 34ch; font-size: var(--fs-xs); color: var(--text-2); line-height: 1.45; }

.tutor-msg {
  position: relative;
  display: flex; gap: 8px;
  max-width: 100%; min-width: 0;
  animation: tutor-msg-in var(--dur) var(--ease-out) both;
}
@keyframes tutor-msg-in { from { opacity: 0; transform: translateY(6px); } }
.tutor-msg-user { flex-direction: column; align-items: flex-end; padding-left: 14%; }
.tutor-msg-bot { align-items: flex-start; padding-right: 2%; }
.tutor-msg-body { position: relative; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }

.tutor-avatar {
  flex: none;
  width: 28px; height: 28px; margin-top: 1px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-text);
}

.tutor-bubble {
  max-width: 100%; min-width: 0;
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 15px; line-height: 1.5;
  overflow-wrap: break-word;
}
.tutor-msg-user .tutor-bubble {
  background: var(--accent); color: var(--on-accent);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tutor-msg-user .tutor-bubble::selection { background: color-mix(in srgb, var(--on-accent) 32%, transparent); color: var(--on-accent); }
.tutor-msg-bot .tutor-bubble {
  background: var(--surface-2); color: var(--text);
  border-top-left-radius: 6px;
}
.tutor-msg.is-partial .tutor-bubble { opacity: .72; }

/* renderMarkdown output inside a bubble */
.tutor-bubble.prose { line-height: 1.55; }
.tutor-bubble.prose > * + * { margin-top: .6em; }
.tutor-bubble > .sr-only:first-child + * { margin-top: 0; }
.tutor-bubble.prose ul, .tutor-bubble.prose ol { padding-left: 1.25em; }
.tutor-bubble.prose li + li { margin-top: .25em; }
.tutor-bubble.prose * + .md-h { margin-top: .9em; }
.tutor-msg-bot .tutor-bubble code { background: color-mix(in srgb, var(--text) 8%, transparent); }
.tutor-msg-bot .tutor-bubble pre {
  max-width: 100%;
  margin-inline: -4px;
  background: var(--surface);
  border-color: var(--border);
}
.tutor-msg-bot .tutor-bubble pre code { background: none; }
.tutor-msg-bot .tutor-bubble .md-table { background: var(--surface); }
.tutor-msg-bot .tutor-bubble blockquote { border-left-color: var(--border-strong); }

/* Streaming: a soft caret after the last paragraph. */
.tutor-msg.is-streaming .tutor-bubble.has-text > p:last-child::after {
  content: "";
  display: inline-block;
  width: 7px; height: 1em; margin-left: 3px;
  vertical-align: -0.15em;
  border-radius: 2px;
  background: var(--accent);
  animation: tutor-caret 1s steps(2, jump-none) infinite;
}
@keyframes tutor-caret { 50% { opacity: 0; } }

.tutor-typing { display: inline-flex; align-items: center; gap: 4px; height: 1.5em; padding: 0 2px; }
.tutor-typing > span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
  animation: tutor-dot 1.2s ease-in-out infinite;
}
.tutor-typing > span:nth-child(2) { animation-delay: .15s; }
.tutor-typing > span:nth-child(3) { animation-delay: .3s; }
@keyframes tutor-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* Timestamps sit in the gap under a bubble: shown on hover, focus, or a tap on touch screens. */
.tutor-time {
  position: absolute; top: calc(100% + 2px);
  padding: 0 4px;
  font-size: 11px; line-height: 14px; color: var(--text-3);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
  pointer-events: none;
}
.tutor-msg-user .tutor-time { right: 2px; }
.tutor-msg-bot .tutor-time { left: 2px; }
.tutor-msg:hover .tutor-time,
.tutor-msg:focus-within .tutor-time,
.tutor-msg.show-time .tutor-time { opacity: 1; }

.tutor-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 2px 0 -6px;
  color: var(--text-3);
  font-size: 11.5px; font-weight: 550; line-height: 1.3;
}
.tutor-divider::before, .tutor-divider::after { content: ""; flex: 1 1 16px; height: 1px; background: var(--border); }
.tutor-divider-inner { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 80%; }
.tutor-divider-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Greeting extras (draft only) */
.tutor-note {
  display: flex; align-items: flex-start; gap: 6px;
  margin-top: 8px; padding: 0 4px;
  font-size: var(--fs-xs); line-height: 1.45; color: var(--text-2);
}
.tutor-note > .icon { margin-top: 1px; color: var(--accent-text); }

.tutor-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tutor-chip {
  display: inline-flex; align-items: center;
  min-height: 36px; max-width: 100%;
  padding: 7px 14px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-pill);
  background: var(--surface); color: var(--accent-text);
  font-size: var(--fs-sm); font-weight: 550; line-height: 1.3; text-align: left;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.tutor-chip:hover { background: var(--accent-soft); border-color: var(--accent); }
.tutor-chip:active { transform: scale(.97); }
.tutor-chip-quiet { border-color: var(--border-strong); color: var(--text-2); }
.tutor-chip-quiet:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }

.tutor-continue-slot { align-self: stretch; min-width: 0; }
.tutor-continue-slot:empty { display: none; }
.tutor-continue {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%; min-height: 32px;
  margin: 10px 0 0 -6px; padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: var(--fs-xs); font-weight: 550;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tutor-continue:hover { background: var(--surface-2); color: var(--text); }
.tutor-continue > .icon { color: var(--text-3); }
.tutor-continue-label { flex: none; }
.tutor-continue-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 600; }

/* "Picked up from …" (recall tool) */
.tutor-recalls { align-self: stretch; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; margin-bottom: 6px; }
.tutor-recalls:empty { display: none; }
.tutor-recall {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%; min-height: 30px;
  padding: 3px 3px 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 12.5px; font-weight: 550; line-height: 1.3;
  animation: tutor-msg-in var(--dur) var(--ease-out) both;
}
.tutor-recall > .icon { flex: none; }
.tutor-recall-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tutor-recall-open {
  position: relative;
  flex: none;
  min-height: 24px; padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface); color: var(--accent-text);
  font-size: 12px; font-weight: 650;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tutor-recall-open:hover { background: var(--accent); color: var(--on-accent); }
.tutor-recall-open:focus-visible { box-shadow: var(--focus); }

/* Failed or stopped exchange */
.tutor-status {
  display: flex; align-items: center; gap: 8px;
  margin: -6px 0 0 36px;
  padding: 7px 7px 7px 12px;
  border-radius: var(--radius);
  font-size: var(--fs-xs); line-height: 1.4;
  animation: tutor-msg-in var(--dur) var(--ease-out) both;
}
.tutor-status > .icon { flex: none; }
.tutor-status.is-error { background: var(--danger-soft); color: var(--danger); }
.tutor-status.is-stopped { background: var(--surface-2); color: var(--text-2); }
.tutor-status-text { flex: 1 1 auto; min-width: 0; }
.tutor-status-retry {
  position: relative;
  flex: none;
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 30px; padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--surface); color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--border-strong);
  transition: background-color var(--dur-fast) var(--ease);
}
.tutor-status-retry:hover { background: var(--surface-2); }
.tutor-status-retry:focus-visible { box-shadow: var(--focus); }

/* Loading / error inside the log */
.tutor-skel { display: flex; flex-direction: column; gap: 18px; }
.tutor-skel-row { display: flex; gap: 8px; align-items: flex-start; }
.tutor-skel-avatar { flex: none; width: 28px; height: 28px; }
.tutor-skel-bubble { height: 38px; border-radius: 18px; }
.tutor-skel-bubble.is-user { align-self: flex-end; border-bottom-right-radius: 6px; }
.tutor-skel-row .tutor-skel-bubble { border-top-left-radius: 6px; }

.tutor-load-error {
  margin: auto 0; padding: 24px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center;
}
.tutor-load-error-icon {
  width: 44px; height: 44px; margin-bottom: 4px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--danger-soft); color: var(--danger);
}
.tutor-load-error-title { font-weight: 650; font-size: var(--fs-base); }
.tutor-load-error-body { color: var(--text-2); font-size: var(--fs-sm); max-width: 36ch; }
.tutor-load-error-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }

.tutor-jump {
  position: absolute; left: 50%; bottom: 12px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface); color: var(--text-2);
  box-shadow: var(--shadow-md);
  transform: translateX(-50%);
  animation: tutor-msg-in var(--dur) var(--ease-out) both;
}
.tutor-jump:hover { color: var(--text); background: var(--surface-2); }
.tutor-jump:focus-visible { box-shadow: var(--focus), var(--shadow-md); }

/* ---- Composer ------------------------------------------------------------------- */
.tutor-composer {
  flex: none;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.tutor-input {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 5px 5px 5px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.tutor-input:hover { border-color: color-mix(in srgb, var(--text-3) 60%, var(--border-strong)); }
.tutor-input:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.tutor-input textarea {
  flex: 1 1 auto; min-width: 0;
  min-height: 36px;
  max-height: calc(6 * 1.45em + 14px);
  padding: 7px 0;
  border: 0; border-radius: 0;
  background: transparent; color: var(--text);
  font-size: 15px; line-height: 1.45;
  resize: none;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.tutor-input textarea:focus, .tutor-input textarea:focus-visible { outline: none; box-shadow: none; }
.tutor-input textarea::placeholder { color: var(--text-3); opacity: 1; }
/* The placeholder is longer than a narrow composer: one line that fades out at the edge. */
.tutor-input textarea:placeholder-shown {
  white-space: nowrap; overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent);
}

.tutor-send, .tutor-stop {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.tutor-send { background: var(--accent); color: var(--on-accent); }
.tutor-send:hover:not(:disabled) { background: var(--accent-hover); }
.tutor-send:active:not(:disabled), .tutor-stop:active { transform: scale(.92); }
.tutor-send:disabled { background: var(--surface-3); color: var(--text-3); }
.tutor-stop { background: var(--text); color: var(--surface); }
.tutor-stop:hover { background: color-mix(in srgb, var(--text) 85%, var(--surface)); }

.tutor-count {
  margin-top: 6px; padding: 0 8px;
  text-align: right;
  font-size: 11.5px; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.tutor-count.is-max { color: var(--danger); font-weight: 600; }

/* ---- Conversations view --------------------------------------------------------- */
.tutor-filter { flex: none; padding: 12px 12px 4px; }
.tutor-filter .input { min-height: 40px; font-size: var(--fs-sm); }
.tutor-convos-body {
  flex: 1 1 auto; min-height: 0;
  padding: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.tutor-list { display: flex; flex-direction: column; gap: 2px; list-style: none; padding: 0; }
.tutor-convo {
  position: relative;
  display: flex; align-items: center; gap: 2px;
  border-radius: var(--radius);
  transition: background-color var(--dur-fast) var(--ease);
}
.tutor-list.is-fresh > .tutor-convo { animation: tutor-msg-in var(--dur) var(--ease-out) both; }
.tutor-convo:hover { background: var(--surface-2); }
.tutor-convo.is-active { background: var(--accent-soft); }
.tutor-convo.is-active::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px;
  width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.tutor-convo-open {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 3px;
  padding: 11px 4px 11px 14px;
  border-radius: var(--radius);
  text-align: left;
}
.tutor-convo-top { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.tutor-convo-title {
  flex: 1 1 auto; min-width: 0;
  font-size: var(--fs-sm); font-weight: 600; line-height: 1.35; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tutor-convo-time { flex: none; font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tutor-convo-ctx {
  display: inline-flex; align-items: center; gap: 4px;
  min-width: 0; max-width: 100%;
  font-size: 12px; font-weight: 550; line-height: 1.35; color: var(--accent-text);
}
.tutor-convo-ctx > .icon { flex: none; }
.tutor-convo-ctx > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tutor-convo-preview {
  font-size: 13px; line-height: 1.4; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tutor-convo-act { flex: none; color: var(--text-3); }
.tutor-convo-del { margin-right: 6px; }
.tutor-convo-ren:hover { color: var(--text); background: color-mix(in srgb, var(--text) 8%, transparent); }
.tutor-convo-del:hover { color: var(--danger); background: var(--danger-soft); }
@media (hover: hover) and (pointer: fine) {
  .tutor-convo-act { opacity: 0; transition: opacity var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
  .tutor-convo:hover .tutor-convo-act, .tutor-convo:focus-within .tutor-convo-act { opacity: 1; }
}

/* Inline name editor: a list row, or the chat header (above). */
.tutor-convo.is-renaming { padding: 8px 8px 8px 10px; background: var(--surface-2); }
.tutor-rename { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; }
.tutor-rename-input.input {
  flex: 1 1 auto; min-width: 0;
  min-height: 36px; padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm); font-weight: 550;
}
.tutor-rename.is-busy .tutor-rename-input { color: var(--text-2); }
.tutor-rename > .btn { flex: none; }

.tutor-convo.is-confirming {
  flex-wrap: wrap; justify-content: space-between; gap: 8px 12px;
  padding: 10px 10px 10px 14px;
  background: var(--danger-soft);
}
.tutor-confirm-text { font-size: var(--fs-sm); font-weight: 600; color: var(--danger); }
.tutor-confirm-actions { display: flex; gap: 6px; margin-left: auto; }

.tutor-list-none { padding: 24px 12px; text-align: center; color: var(--text-2); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.tutor-list-error { padding-top: 8px; }
.tutor-convos-body .empty-state { padding-top: var(--sp-10); }

.tutor-list-skel { display: flex; flex-direction: column; gap: 2px; }
.tutor-skel-convo { padding: 8px 14px 10px; }
.tutor-skel-convo .skeleton-text { margin: 6px 0; height: 10px; }

/* ---- Touch ---------------------------------------------------------------------- */
@media (pointer: coarse) {
  .tutor-chip { min-height: var(--tap); }
  .tutor-continue { min-height: var(--tap); }
  .tutor-send, .tutor-stop { width: 40px; height: 40px; }
  .tutor-recall-open { min-height: 32px; padding: 4px 12px; }
  /* 44px tall hit area; -6px meets the next chip exactly (.tutor-recalls gap). */
  .tutor-recall-open::before { content: ""; position: absolute; inset: -6px -4px; }
  .tutor-status-retry { min-height: 36px; }
  .tutor-status-retry::before { content: ""; position: absolute; inset: -4px -2px; }
  .tutor-input textarea { font-size: 16px; } /* iOS zooms into smaller inputs */
  .tutor-filter .input { font-size: 16px; }
  .tutor-rename-input.input, .tutor-head-rename .tutor-rename-input { min-height: var(--tap); font-size: 16px; }
  /* A 44px tall target for the title, reaching into the header's padding and over the context pill. */
  .tutor-title-btn::before { content: ""; position: absolute; inset: -10px 0; }
}

/* ---- Wide screens: docked --------------------------------------------------------- */
/* The open card docks as a right rail and the page reflows beside it, so the question or explanation
   being discussed stays readable. No margin transition: it would re-lay out long pages every frame. */
@media screen and (min-width: 1280px) {
  html.tutor-docked { --tutor-dock: 432px; } /* 400 panel + 2 x 16 */
  html.tutor-docked-wide { --tutor-dock: 592px; } /* 560 expanded panel + 2 x 16 */
  html.tutor-docked .app-main { margin-right: var(--tutor-dock); }
  html.tutor-docked .tutor-panel { top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 16px); bottom: 16px; height: auto; }
}
/* 1024-1279 stays floating: a slightly narrower card keeps clear of the quiz stem. */
@media (min-width: 1024px) and (max-width: 1279.98px) {
  .tutor-panel:not(.is-expanded) { width: 360px; }
}

/* ---- Phones: full-screen sheet --------------------------------------------------- */
@media (max-width: 639.98px) {
  .tutor-panel, .tutor-panel.is-expanded {
    top: var(--tutor-vv-top, 0px); right: 0; bottom: auto; left: 0;
    width: 100%;
    height: var(--tutor-vh, 100dvh);
    border: 0; border-radius: 0; box-shadow: none;
    opacity: 1;
    transform: translateY(100%);
    transition: transform var(--dur-slow) var(--ease-out), visibility 0s linear var(--dur-slow);
  }
  .tutor-panel.is-open { transform: none; transition-delay: 0s; }
  .tutor-head {
    min-height: calc(60px + env(safe-area-inset-top, 0px));
    padding-top: max(7px, env(safe-area-inset-top, 0px));
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
  }
  .tutor-log {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .tutor-composer {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  /* The on-screen keyboard covers the home indicator, so its inset isn't needed then. */
  .tutor-panel.is-kb .tutor-composer { padding-bottom: 10px; }
  .tutor-convos-body { padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
  .tutor-expand { display: none; }
  .tutor-input textarea { font-size: 16px; }
  .tutor-msg-user { padding-left: 10%; }
}

/* ---- Preferences ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .tutor-fab, .tutor-panel, .tutor-panel.is-open, .tutor.is-open .tutor-fab { transition: none; }
  .tutor-panel, .tutor-panel.is-expanded { transform: none; }
  .tutor-fab:hover, .tutor-fab:hover > .icon { transform: none; }
  .tutor-fab.is-pulsing::after,
  .tutor-view.is-entering, .tutor-msg, .tutor-recall, .tutor-status, .tutor-list.is-fresh > .tutor-convo, .tutor-jump, .tutor-fab-dot { animation: none; }
  .tutor-typing > span { animation: none; opacity: .6; }
  .tutor-msg.is-streaming .tutor-bubble.has-text > p:last-child::after { animation: none; }
}

@media (forced-colors: active) {
  .tutor-fab { border: 2px solid ButtonText; }
  .tutor-panel { border: 1px solid CanvasText; }
  .tutor-bubble, .tutor-chip, .tutor-input, .tutor-recall, .tutor-status { border: 1px solid CanvasText; }
  .tutor-convo.is-active { outline: 2px solid Highlight; }
  .tutor-title-pencil { opacity: 1; }
}

@media print {
  .tutor-fab, .tutor-panel { display: none !important; }
}
