/* ============================================
   STUDENT TOOLS — Coach page (/coach)
   Built on the tokens in site.css, so themes and accent palettes apply.
   ============================================ */

.coach-page { display: flex; justify-content: center; padding-bottom: 0; }
.coach {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-h) - 32px);
}

/* ---- Top ---- */
.coach-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.coach-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; }
.coach-lede { margin: 0; color: var(--text-2); font-size: 15px; line-height: 1.55; max-width: 560px; }
.coach-top-actions { display: flex; gap: 8px; flex: none; padding-top: 4px; }
.coach-count:not(:empty) {
  margin-left: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

.coach-banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--border));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--warning) 8%, var(--surface));
  color: var(--text);
  font-size: 14px;
}

/* ---- Saved panel ---- */
.coach-saved {
  margin-bottom: 20px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
}
.coach-saved-head h2 { margin: 0 0 4px; font-size: 16px; }
.coach-saved-head p { margin: 0 0 12px; color: var(--text-2); font-size: 13px; line-height: 1.5; }
.coach-saved-head a { color: var(--accent-text); }
.coach-saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.coach-saved-item details {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 10px 12px;
}
.coach-saved-item summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.coach-saved-title { font-weight: 600; font-size: 14px; }
.coach-saved-meta { color: var(--text-3); font-size: 12px; }
.coach-saved-item .msg-text { margin-top: 10px; font-size: 14px; }
.coach-saved-empty { color: var(--text-3); font-size: 14px; }

/* ---- Empty state ---- */
.coach-empty { margin-bottom: 20px; }
.coach-empty-title { margin: 8px 0 14px; font-weight: 600; font-size: 15px; }
.coach-suggest { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.coach-suggest-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.coach-suggest-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.coach-suggest-head .cat-tile { width: 26px; height: 26px; border-radius: 6px; }
.coach-suggest-head .cat-tile .i { width: 15px; height: 15px; }
.coach-suggestion {
  text-align: left;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.coach-suggestion:hover { background: var(--surface-hover); border-color: var(--border); }

/* ---- Conversation ---- */
.coach-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; flex: 1; }
.msg { display: flex; flex-direction: column; min-width: 0; }
.msg-student { align-items: flex-end; }
.msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-coach { gap: 8px; }
.msg-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.msg-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  color: var(--cat-coach);
  background: color-mix(in srgb, var(--cat-coach) 12%, transparent);
}
.msg-avatar .i { width: 14px; height: 14px; }
.msg-label { font-weight: 600; }
.msg-via { color: var(--text-3); }
.msg-tryas { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 12px; }
.msg-tryas-select {
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
}
.msg-body { display: flex; flex-direction: column; gap: 10px; padding-left: 32px; min-width: 0; }
.msg-text { font-size: 15px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta { margin: 0; color: var(--text-3); font-size: 13px; }
.msg-meta-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.msg-note { margin: 0; color: var(--text-2); font-size: 13.5px; }
.msg-link {
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.msg-link:hover { text-decoration: underline; }
.msg-bullets { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 15px; line-height: 1.55; }
.msg-details summary { cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 500; }
.msg-details .msg-text { margin-top: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-sunken); font-size: 14px; }
.msg-error {
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--danger) 6%, var(--surface));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.msg-error p { margin: 0; font-size: 14px; }

.msg-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-left: 32px; }
.msg-actions .btn .i { width: 14px; height: 14px; }
.msg-name { width: auto; flex: 1 1 180px; max-width: 280px; min-height: 30px; padding: 4px 10px; font-size: 13px; }
.msg-saved { display: inline-flex; align-items: center; gap: 6px; color: var(--success); font-size: 13px; font-weight: 500; }
.msg-saved .i { width: 15px; height: 15px; }
.msg-saved .msg-link { margin-left: 4px; }
.msg-choices { display: flex; gap: 8px; flex-wrap: wrap; }
.msg-choices .btn .i { width: 14px; height: 14px; }

/* Waiting */
.msg-wait { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 14px; }
.msg-dots { width: 28px; height: 8px; background:
  radial-gradient(circle closest-side, currentColor 90%, transparent) 0 50% / 8px 8px no-repeat,
  radial-gradient(circle closest-side, currentColor 90%, transparent) 50% 50% / 8px 8px no-repeat,
  radial-gradient(circle closest-side, currentColor 90%, transparent) 100% 50% / 8px 8px no-repeat;
  animation: coach-dots 1.2s infinite ease-in-out; }
.msg-wait-secs { font-variant-numeric: tabular-nums; font-size: 12px; }
@keyframes coach-dots { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .msg-dots { animation: none; } }

/* Flashcards */
.fc-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.fc-item { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.fc-front { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.fc-back { color: var(--text-2); font-size: 13.5px; line-height: 1.45; }

/* Quiz */
.qz-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 14px; }
.qz-q { margin: 0 0 8px; font-weight: 500; font-size: 14.5px; line-height: 1.45; }
.qz-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.qz-opt {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  line-height: 1.4;
  cursor: pointer;
}
.qz-opt:hover:not(:disabled) { background: var(--surface-hover); }
.qz-opt:disabled { cursor: default; }
.qz-letter { flex: none; font-weight: 600; color: var(--text-3); }
.qz-item.is-answered .qz-opt.is-correct,
.qz-list.is-revealed .qz-opt.is-correct {
  border-color: color-mix(in srgb, var(--success) 60%, var(--border));
  background: color-mix(in srgb, var(--success) 10%, var(--surface));
}
.qz-item.is-answered .qz-opt.is-picked:not(.is-correct) {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
}

/* Grammar */
.gc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.gc-item { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.gc-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.gc-orig { color: var(--danger); text-decoration: line-through; }
.gc-fix { color: var(--success); text-decoration: none; font-weight: 600; }
.gc-arrow { color: var(--text-3); }
.gc-type { height: 20px; font-size: 11px; margin-left: auto; }
.gc-why { margin: 4px 0 0; color: var(--text-2); font-size: 13px; line-height: 1.45; }

/* Chords */
.chord-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chord-chip {
  min-width: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--cat-music) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--cat-music) 30%, var(--border));
  font-family: var(--font-mono);
  font-weight: 500;
  text-align: center;
}

/* Math */
.math-card {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.math-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 600; color: var(--text-2); }
.math-q { font-family: var(--font-mono); font-size: 14.5px; overflow-wrap: anywhere; }
.math-show { align-self: flex-start; }
.math-show .i { width: 14px; height: 14px; }
.math-result {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  overflow-wrap: anywhere;
}
.math-steps { margin: 6px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: 13.5px; line-height: 1.5; }

/* Inline form */
.msg-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
}
.msg-form .form-group { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.msg-form .form-group:has(textarea) { grid-column: 1 / -1; }
.msg-form .btn { justify-self: start; }

/* ---- Composer ---- */
.coach-composer {
  position: sticky;
  bottom: 0;
  margin-top: 20px;
  padding: 10px 0 14px;
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
  z-index: 5;
}
.coach-mode-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.coach-mode-wrap { position: relative; }
.coach-mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.coach-mode .i { width: 14px; height: 14px; color: var(--cat-coach); }
.coach-mode .i:last-child { color: var(--text-3); }
.coach-mode.is-set { border-color: var(--accent-text); background: var(--accent-soft); }
.coach-mode-hint { color: var(--text-3); font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coach-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  width: 260px;
  max-height: min(420px, 60vh);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 20;
}
.coach-menu-label { padding: 8px 8px 4px; color: var(--text-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.coach-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.coach-menu-item .i { width: 15px; height: 15px; color: var(--text-3); }
.coach-menu-item:hover, .coach-menu-item:focus-visible { background: var(--surface-hover); outline: none; }
.coach-menu-item[aria-checked="true"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 500; }
.coach-menu-item[aria-checked="true"] .i { color: currentColor; }

.coach-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.coach-input-wrap:focus-within { border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-ring); }
.coach-input {
  flex: 1;
  min-width: 0;
  min-height: 24px;
  max-height: 40vh;
  padding: 6px 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
}
.coach-input::placeholder { color: var(--text-3); }
.coach-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}
.coach-send .i { width: 18px; height: 18px; }
.coach-send:disabled { opacity: 0.45; cursor: not-allowed; }
.coach-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; color: var(--text-3); font-size: 12px; }
.coach-foot .is-warning { color: var(--warning); font-weight: 500; }

/* ---- Small screens ---- */
@media (max-width: 640px) {
  .coach-top { flex-direction: column; gap: 12px; }
  .coach-title { font-size: 24px; }
  .coach-suggest, .fc-list, .qz-opts, .msg-form { grid-template-columns: minmax(0, 1fr); }
  .msg-body, .msg-actions { padding-left: 0; }
  .msg-bubble { max-width: 92%; }
  .msg-tryas { margin-left: 0; }
  .coach-foot span:last-child { display: none; }
}
