/* Tutor chat: a panel under the worked solution. */

.tutor {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

.tutor__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.tutor__title {
  margin: 0;
  font-size: var(--t-l);
  font-weight: 600;
  line-height: 1.15;
}

.tutor__head .tutor__clear {
  flex-shrink: 0;
  padding-inline: 0;
}

.tutor__hint {
  margin: 0.25rem 0 0;
  font-size: var(--t-s);
  color: var(--graphite);
}

/* Conversation */

.tutor__log {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: min(65vh, 36rem);
  margin-top: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Room for focus rings on the error bubble's button. */
  padding: 4px;
  margin-inline: -4px;
}

.tutor__log:empty {
  margin-top: 0;
  padding: 0;
}

.tutor__msg {
  max-width: min(100%, 44rem);
  padding: 0.75rem 1rem;
  border-radius: var(--r-box);
}

.tutor__msg--user {
  align-self: flex-end;
  margin-left: 2.5rem;
  background: var(--wash);
}

.tutor__msg--assistant {
  align-self: flex-start;
  width: 100%;
  border-left: 3px solid var(--blue);
  padding-block: 0.35rem;
  border-radius: 0;
}

.tutor__msg--error {
  align-self: stretch;
  max-width: none;
  border: 1.5px solid var(--ink);
  border-left-width: 4px;
}

.tutor__who {
  margin: 0 0 0.2rem;
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--graphite);
}

.tutor__text {
  margin: 0;
  font-size: var(--t-m);
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: break-word;
}

.tutor__error-action {
  margin-top: 0.6rem;
}

/* Streaming: "Thinking…" until the first words arrive, then a blinking caret. */

.tutor__msg--streaming .tutor__text:empty::before {
  content: "Thinking\2026";
  color: var(--graphite);
  animation: tutor-pulse 1.2s ease-in-out infinite;
}

.tutor__msg--streaming .tutor__text:not(:empty)::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1.1em;
  margin-left: 0.1em;
  vertical-align: text-bottom;
  background: var(--blue);
  animation: tutor-caret 1s steps(1) infinite;
}

@keyframes tutor-pulse {
  50% {
    opacity: 0.4;
  }
}

@keyframes tutor-caret {
  50% {
    opacity: 0;
  }
}

/* Wide display equations scroll sideways rather than overflow. */
.tutor mjx-container[jax][display="true"] {
  margin: 0.6em 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-block: 0.1em;
}

/* Account states */

.tutor__notice {
  margin: 1rem 0 0;
  font-size: var(--t-s);
  color: var(--graphite);
}

.tutor__gate {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background: var(--wash);
  border-radius: var(--r-box);
}

.tutor__gate-text {
  margin: 0;
  font-size: var(--t-m);
  font-weight: 500;
}

/* Composer */

.tutor__form {
  margin-top: 1rem;
}

.tutor__attachment {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

.tutor__image {
  display: block;
  max-width: 100%;
  max-height: 24rem;
  margin-top: 0.5rem;
  object-fit: contain;
  border: 1px solid var(--rule);
  border-radius: var(--r-control);
}

.tutor__image--preview {
  width: 7rem;
  height: 7rem;
  margin: 0;
  background: var(--paper);
}

.tutor__upload-status {
  margin: 0.5rem 0 0;
  font-size: var(--t-xs);
  line-height: 1.45;
  color: var(--graphite);
}

.tutor [hidden] {
  display: none;
}

.tutor__input {
  display: block;
  width: 100%;
  min-height: 5.5rem;
  max-height: 16rem;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--r-control);
  background: var(--paper);
  /* At least 16px so iOS doesn't zoom in on focus. */
  font-size: var(--t-m);
  line-height: 1.45;
  resize: vertical;
  field-sizing: content;
}

.tutor__input::placeholder {
  color: var(--graphite);
}

.tutor__input:disabled,
.tutor__input:read-only {
  border-color: var(--rule);
  background: var(--wash);
  color: var(--graphite);
}

.tutor__input:disabled {
  cursor: not-allowed;
}

.tutor__bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.6rem;
}

.tutor__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin: 0;
  font-size: var(--t-xs);
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.tutor__count--limit {
  color: var(--ink);
  font-weight: 600;
}

.tutor__send {
  min-width: 6.5rem;
  margin-left: auto;
}

@media (max-width: 399.98px) {
  .tutor__msg--user {
    margin-left: 1rem;
  }

  .tutor__send {
    flex-basis: 100%;
  }
}

@media (forced-colors: active) {
  .tutor__msg {
    border: 1px solid CanvasText;
  }

  .tutor__msg--streaming .tutor__text:not(:empty)::after {
    background: CanvasText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tutor__msg--streaming .tutor__text:empty::before,
  .tutor__msg--streaming .tutor__text:not(:empty)::after {
    animation: none;
  }
}
