/* ════════════════════════════════════════════════════════════════
   coach.css — the in-app help assistant (js/coach.js)

   A launcher that sits out of the way until it is wanted, and a panel that
   behaves like the app it is docked into: a card in the bottom-right corner
   on desktop, a bottom sheet on a phone, because that is where a thumb is.

   Nothing here is a new colour. The launcher borrows the mic's accent
   gradient so it reads as the same family of control, and the two command
   verdicts reuse --good and --warn: a coach should be able to tell a
   confirmed command from an unsure one without reading either.
   ════════════════════════════════════════════════════════════════ */

/* ── Launcher ────────────────────────────────────────────────── */

.coach-fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 480;              /* over the tab bar (200), under a modal (900+) */
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 26px -10px var(--accent), 0 2px 6px rgba(20,23,31,.18);
  transition: transform .14s ease, box-shadow .14s ease;
  -webkit-tap-highlight-color: transparent;
}

.coach-fab:hover  { transform: translateY(-2px); box-shadow: 0 14px 30px -10px var(--accent), 0 2px 6px rgba(20,23,31,.18); }
.coach-fab:active { transform: scale(.94); }
.coach-fab svg    { width: 23px; height: 23px; }

/* The panel covers the launcher on a phone, and sitting on top of its own
   sheet makes it look like a stray control. */
body.coach-open .coach-fab { opacity: 0; pointer-events: none; }

/* The Feedback pill (style.css) owns the same corner on the dashboard, which
   is the one page where both are visible. Ask is the one a stuck coach needs,
   so it keeps the thumb position and Feedback steps up above it. Loaded after
   style.css, same specificity — this wins. */
body.on-dashboard .fb-widget { bottom: 88px; }

/* ── Panel ───────────────────────────────────────────────────── */

.coach-panel {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 490;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-family: var(--font);
}

.coach-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding: 14px 14px 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.coach-head-txt   { min-width: 0; }
.coach-title      { margin: 0; font-size: 14px; font-weight: 800; color: var(--ink); letter-spacing: -.01em; }
.coach-sub        { margin: 1px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.35; }

.coach-close {
  margin-left: auto;
  flex: none;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.coach-close:hover { color: var(--ink); border-color: var(--line-strong); }

/* ── Log ─────────────────────────────────────────────────────── */

.coach-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.coach-msg { display: flex; }
.coach-msg.is-you { justify-content: flex-end; }
/* An answer and its "Report" link stack, the link small and out of the way. */
.coach-msg.has-report { flex-direction: column; align-items: flex-start; }
.coach-report {
  margin: 3px 0 0 4px;
  padding: 2px 0;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
button.coach-report:hover { color: var(--bad); text-decoration: underline; }
button.coach-report:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.coach-report.is-done { cursor: default; color: var(--good); }

.coach-bubble {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.coach-bubble p { margin: 0; }
.coach-bubble p + p { margin-top: 7px; }

.is-you .coach-bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.is-bot .coach-bubble { border-bottom-left-radius: 5px; }

.coach-bubble.is-error {
  background: var(--bad-soft);
  border-color: rgba(211,65,58,.25);
  color: var(--bad);
}

/* ── A command the model proposed ────────────────────────────── */
/* The border colour is the parser's verdict, not the model's confidence:
   is-ok parsed, is-unsure did not. See js/coach.js. */

.coach-cmd {
  margin: 8px 0;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.coach-cmd:first-child { margin-top: 2px; }
.coach-cmd:last-child  { margin-bottom: 2px; }

.coach-cmd code {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  word-break: break-word;
}

.coach-cmd-note {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: lowercase;
}

.coach-cmd.is-ok     { background: var(--good-soft); border-color: rgba(13,117,57,.22); }
.coach-cmd.is-ok     .coach-cmd-note { color: var(--good); }
.coach-cmd.is-unsure { background: var(--warn-soft); border-color: rgba(194,129,28,.28); }
.coach-cmd.is-unsure .coach-cmd-note { color: var(--warn); text-transform: none; font-weight: 600; }

/* ── Empty state ─────────────────────────────────────────────── */

.coach-empty { margin: auto 0; }
.coach-empty-lede {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

.coach-sugs { display: flex; flex-direction: column; gap: 7px; }

.coach-sug {
  text-align: left;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.coach-sug:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }

/* ── Thinking ────────────────────────────────────────────────── */

.coach-bubble.is-thinking { display: flex; gap: 4px; align-items: center; padding: 13px 14px; }
.coach-bubble.is-thinking span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted-2);
  animation: coach-blink 1.1s infinite;
}
.coach-bubble.is-thinking span:nth-child(2) { animation-delay: .18s; }
.coach-bubble.is-thinking span:nth-child(3) { animation-delay: .36s; }

@keyframes coach-blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .coach-bubble.is-thinking span { animation: none; opacity: .5; }
  .coach-fab { transition: none; }
}

/* ── Composer ────────────────────────────────────────────────── */

.coach-form {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 11px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.coach-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: inherit;
  font-size: 16px;            /* under 16px, iOS Safari zooms the whole page */
  color: var(--ink);
}
.coach-input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.coach-send {
  flex: none;
  width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.coach-send:hover  { background: var(--accent-strong); }
.coach-send:active { transform: scale(.95); }
.coach-send svg    { width: 17px; height: 17px; }

/* ── Phone ───────────────────────────────────────────────────── */

@media (max-width: 700px) {
  /* Clear of the bottom tab bar, which is 56px plus the home indicator.
     Coding and Setup hide that bar, so the launcher drops back down. */
  .coach-fab {
    right: 16px;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    width: 48px;
    height: 48px;
  }
  body.coding .coach-fab,
  body.in-setup .coach-fab,
  body.viewing-match-stats .coach-fab {
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }

  /* Same stacking as on desktop, over the phone's own tab-bar offset. */
  body.on-dashboard .fb-widget { bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 76px); }

  /* A sheet, not a floating card: on a 360px screen a card with margins is
     mostly margin, and the answer is what the coach came for. */
  .coach-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    height: 82vh;
    height: 82dvh;
    max-height: none;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}
