/* Conversation partner mode — everything scoped under .talk-mode.
   Uses the app's theme variables from public/study/style.css :root. */

.talk-mode {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* --- Header row --- */
.talk-mode .talk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--surface-overlay);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.talk-mode .talk-header-left,
.talk-mode .talk-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.talk-mode .talk-deck {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.talk-mode .talk-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  white-space: nowrap;
}

.talk-mode .talk-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.talk-mode .talk-status.connecting::before {
  background: #fbbf24;
  animation: talk-blink 1s infinite;
}
.talk-mode .talk-status.connected::before,
.talk-mode .talk-status.listening::before {
  background: var(--success);
}
.talk-mode .talk-status.speaking::before {
  background: var(--primary);
  animation: talk-blink 0.8s infinite;
}
.talk-mode .talk-status.thinking::before {
  background: #a78bfa;
  animation: talk-blink 0.8s infinite;
}
.talk-mode .talk-status.error::before {
  background: var(--danger);
}

.talk-mode .talk-score {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.talk-mode .talk-end-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-color);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.talk-mode .talk-end-btn:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.5);
  color: #f87171;
}

/* --- Pinned question card --- */
.talk-mode .talk-question {
  margin: 12px 16px 0;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid var(--primary);
  background: var(--surface-color);
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.12);
  flex-shrink: 0;
  transition:
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

.talk-mode .talk-question.empty {
  border-color: var(--border-color);
  box-shadow: none;
}

.talk-mode .talk-question-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.talk-mode .talk-question-text {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.4;
}

.talk-mode .talk-question.empty .talk-question-text {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 1rem;
}

.talk-mode .talk-question-context {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* --- Transcript --- */
.talk-mode .talk-transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.talk-mode .talk-transcript::-webkit-scrollbar {
  width: 6px;
}
.talk-mode .talk-transcript::-webkit-scrollbar-thumb {
  background: var(--surface-hover);
  border-radius: 10px;
}

.talk-mode .talk-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 1rem;
  word-break: break-word;
  animation: talk-float-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.talk-mode .talk-msg.assistant {
  align-self: flex-start;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 6px;
}

.talk-mode .talk-msg.user {
  align-self: flex-end;
  background: var(--primary-gradient);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.talk-mode .talk-msg.system {
  align-self: center;
  max-width: 92%;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.talk-mode .talk-msg.streaming .talk-msg-text::after {
  content: "▍";
  margin-left: 2px;
  opacity: 0.6;
  animation: talk-blink 1s infinite;
}

.talk-mode .talk-msg.user.streaming {
  opacity: 0.85;
}

.talk-mode .talk-msg.interrupted {
  opacity: 0.75;
}

.talk-mode .talk-msg-text {
  white-space: pre-wrap;
}

.talk-mode .talk-msg-text:empty::before {
  content: "…";
  color: var(--text-muted);
}

.talk-mode .talk-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.talk-mode .talk-replay {
  display: block;
  width: 100%;
  max-width: 280px;
  height: 36px;
  margin-top: 10px;
  border-radius: 18px;
  outline: none;
}

.talk-mode .talk-retry-btn,
.talk-mode .talk-notice-btn {
  padding: 6px 14px;
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}

.talk-mode .talk-retry-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.talk-mode .talk-notice {
  align-self: center;
  margin: 32px auto;
  padding: 28px 32px;
  max-width: 380px;
  text-align: center;
  border-radius: 16px;
  border: 1px solid var(--border-color);
  background: var(--surface-color);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.talk-mode .talk-notice h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.talk-mode .talk-notice p {
  margin: 0 0 18px;
  color: var(--text-muted);
}

.talk-mode .talk-notice-btn {
  font-size: 0.95rem;
  padding: 10px 22px;
}

/* --- Bottom bar --- */
.talk-mode .talk-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border-color);
  background-color: var(--surface-overlay);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.talk-mode .talk-mic-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.talk-mode .talk-mic-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  background: #52525b;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition:
    transform 0.15s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.talk-mode .talk-mic-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.talk-mode .talk-mic-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.talk-mode .talk-mic-btn.is-idle {
  background: #52525b;
}

.talk-mode .talk-mic-btn.is-listening {
  background: var(--primary);
  box-shadow: 0 4px 18px rgba(37, 99, 235, 0.35);
}

.talk-mode .talk-mic-btn.is-talking {
  background: var(--danger);
  animation: talk-pulse-red 1.4s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

.talk-mode .talk-mic-btn.is-muted {
  background: #3f3f46;
  color: var(--text-muted);
  position: relative;
}

.talk-mode .talk-mic-btn.is-muted::after {
  content: "";
  position: absolute;
  width: 4px;
  height: 44px;
  background: var(--danger);
  border-radius: 2px;
  transform: rotate(45deg);
}

.talk-mode .talk-mic-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-height: 1em;
  text-align: center;
}

.talk-mode .talk-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.talk-mode .talk-input {
  flex: 1;
  min-width: 0;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-color);
  color: var(--text-color);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
}

.talk-mode .talk-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.talk-mode .talk-send-btn {
  padding: 12px 20px;
  border-radius: 999px;
  border: none;
  background-color: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.talk-mode .talk-send-btn:hover {
  background-color: var(--primary-hover);
}

.talk-mode .talk-send-btn:disabled,
.talk-mode .talk-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Animations --- */
@keyframes talk-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

@keyframes talk-float-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes talk-pulse-red {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45);
  }
  70% {
    box-shadow: 0 0 0 16px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

@media (max-width: 480px) {
  .talk-mode .talk-deck {
    display: none;
  }
  .talk-mode .talk-msg {
    max-width: 92%;
  }
  .talk-mode .talk-mic-btn {
    width: 68px;
    height: 68px;
  }
}


/* --- Embedded in the study session shell --- */
.talk-mode .talk-header.embedded {
  padding: 4px 16px 0;
  min-height: 0;
  border: none;
  background: transparent;
}
.talk-mode .talk-header.embedded .talk-score {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.talk-mode .talk-question {
  text-align: center;
}
.talk-mode .talk-question .talk-question-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 600;
}
.talk-mode .talk-question .talk-question-text {
  font-size: 1.35rem;
  line-height: 1.4;
  font-weight: 500;
}
.talk-mode .talk-header[hidden] {
  display: none;
}

/* --- Question cards in the timeline --- */
.talk-mode .talk-msg.question {
  align-self: stretch;
  max-width: none;
  text-align: center;
  background: var(--surface-color);
  border: 1px solid var(--primary);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 6px 0;
}
.talk-mode .talk-qcard-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 6px;
}
.talk-mode .talk-qcard-text {
  font-size: 1.25rem;
  line-height: 1.45;
  font-weight: 500;
  white-space: pre-wrap;
}
.talk-mode .talk-qcard-context {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* grade colours, matching the study grade bar */
.talk-mode .talk-grade {
  font-weight: 700;
}
.talk-mode .talk-grade-again {
  color: var(--danger, #ef4444);
}
.talk-mode .talk-grade-hard {
  color: var(--warning, #f59e0b);
}
.talk-mode .talk-grade-good {
  color: var(--success, #10b981);
}
.talk-mode .talk-grade-easy {
  color: var(--easy, #38bdf8);
}
