/* "Ask Rachel" — the corner chat. Loaded only by workshop-claude-code.html.
 *
 * LAYERING. Everything Play Mode puts on screen is fixed and numbered:
 * the canvas sits at 999990, the Insert-coin / Exit-Play-Mode buttons at
 * 999995 (both bottom-right, 24px in), toasts at 999996, the narration at
 * 999997, and the door fade at 1000000. This widget sits at 999998: above
 * the game's own chrome, below the fade that covers the page on a
 * navigation. The fixed nav is only 1000/1001, so the panel clears it too.
 *
 * NOT COVERING ANYTHING. The "Exit Play Mode" badge lands in exactly this
 * corner while the game runs, so body.emd-play-on lifts the launcher clear
 * of it. Below 640px Play Mode does not render at all, so on a phone the
 * corner is ours alone — but the safe-area inset still applies, because an
 * iPhone's home indicator is not Play Mode's problem or ours.
 */

.askr {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 999998;
  font-family: var(--font-body, 'Figtree', system-ui, sans-serif);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* Play Mode's exit badge owns bottom:24px right:24px. Step over it. */
body.emd-play-on .askr { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }

/* ── Launcher ─────────────────────────────────────────────────────────── */
/* On brand: coral is emphasis only, never a button (see the site rule in
   CLAUDE.md). This button now matches the page's primary .btn — near-black
   fill, white text, the same 4px darker pressable bottom edge as
   .btn-download in workshop-claude-code.html's own styles (box-shadow
   0 4px 0 <darker>, collapsing to 0 on :active as the button travels down
   4px). Coral survives only as a small dot ahead of the label — the accent,
   not the surface — which is what actually makes the button findable
   without being read. */
.askr-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 56px;
  padding: 0 24px;
  background: var(--accent, #0c0e13);
  color: var(--accent-fg, #fff);
  border: 1px solid var(--accent, #0c0e13);
  border-radius: var(--radius, 10px);
  box-shadow: 0 4px 0 var(--accent-strong, #000), 0 10px 26px rgba(12, 14, 19, 0.22);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.12s, transform 0.06s, box-shadow 0.06s;
}
.askr-launcher:hover { background: var(--accent-strong, #000); border-color: var(--accent-strong, #000); }
.askr-launcher:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--accent-strong, #000), 0 4px 14px rgba(12, 14, 19, 0.2);
}
.askr-launcher:focus-visible { outline: 3px solid var(--text-primary, #191b1f); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  .askr-launcher, .askr-launcher:active { transition: none; transform: none; }
}
.askr-launcher-glyph {
  width: 8px; height: 8px; flex: none;
  border-radius: 50%;
  background: #ff7366;
  font-size: 0; line-height: 1;
}
/* The panel replaces the button rather than sitting above it: on a short
   phone screen a 70vh panel plus a 56px button is most of the viewport. */
.askr.open .askr-launcher { display: none; }

/* ── Panel ────────────────────────────────────────────────────────────── */
.askr-panel {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 24px);
  max-height: 70vh;
  background: var(--bg-surface, #fff);
  color: var(--text-primary, #191b1f);
  border: 1px solid var(--border-strong, #d6d4d0);
  border-radius: var(--radius, 10px);
  box-shadow: 0 18px 54px rgba(12, 14, 19, 0.26);
  overflow: hidden;
}
.askr.open .askr-panel { display: flex; }

.askr-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 16px 14px 14px 18px;
  border-bottom: 1px solid var(--border, #e7e5e1);
}
.askr-head-text { flex: 1; min-width: 0; }
.askr-head h2 {
  font-family: var(--font-display, 'Figtree', system-ui, sans-serif);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 4px;
}
.askr-head p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-secondary, #5b5954);
}
.askr-close {
  flex: none;
  background: none;
  border: 0;
  padding: 4px 6px;
  margin: -2px -2px 0 0;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted, #8a8781);
  border-radius: 6px;
  cursor: pointer;
}
.askr-close:hover { color: var(--text-primary, #191b1f); background: rgba(0, 0, 0, 0.05); }

/* ── Thread ───────────────────────────────────────────────────────────── */
.askr-thread {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-base, #faf9f7);
}
.askr-bubble {
  max-width: 90%;
  padding: 10px 13px;
  border-radius: var(--radius, 10px);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.askr-bubble.bot {
  align-self: flex-start;
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border, #e7e5e1);
}
.askr-bubble.me {
  align-self: flex-end;
  background: var(--accent, #0c0e13);
  color: var(--accent-fg, #fff);
  border: 1px solid var(--accent, #0c0e13);
}
.askr-bubble.err {
  align-self: flex-start;
  background: hsl(5 100% 96%);
  border: 1px solid #ff7366;
}
.askr-bubble a { color: inherit; }

.askr-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 12px 14px; }
.askr-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted, #8a8781);
  animation: askrBlink 1.1s infinite ease-in-out;
}
.askr-typing span:nth-child(2) { animation-delay: 0.16s; }
.askr-typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes askrBlink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .askr-typing span { animation: none; opacity: 0.6; }
}

/* ── Composer ─────────────────────────────────────────────────────────── */
.askr-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border, #e7e5e1);
  background: var(--bg-surface, #fff);
}
.askr-compose textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  padding: 10px 12px;
  height: 42px;
  max-height: 110px;
  border: 1px solid var(--border-strong, #d6d4d0);
  border-radius: var(--radius, 10px);
  background: var(--bg-base, #faf9f7);
  color: var(--text-primary, #191b1f);
}
.askr-compose textarea:focus {
  outline: none;
  border-color: #ff7366;
  background: var(--bg-surface, #fff);
}
.askr-send {
  flex: none;
  height: 42px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent-fg, #fff);
  background: var(--accent, #0c0e13);
  border: 1px solid var(--accent, #0c0e13);
  border-radius: var(--radius, 10px);
  cursor: pointer;
}
.askr-send:hover { background: #ff7366; border-color: #ff7366; color: var(--text-primary, #191b1f); }
.askr-send[disabled] { opacity: 0.5; cursor: default; }
.askr-send[disabled]:hover { background: var(--accent, #0c0e13); border-color: var(--accent, #0c0e13); color: var(--accent-fg, #fff); }

/* ── Footer / mode switch ─────────────────────────────────────────────── */
.askr-foot {
  padding: 10px 18px 12px;
  border-top: 1px solid var(--border, #e7e5e1);
  background: var(--bg-surface, #fff);
  font-size: 12.5px;
  color: var(--text-secondary, #5b5954);
}
.askr-switch {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text-primary, #191b1f);
  text-decoration: underline;
  text-decoration-color: #ff7366;
  text-underline-offset: 3px;
  cursor: pointer;
}
.askr-switch:hover { color: #b34a41; }
.askr-foot-form { display: none; }
.askr.form .askr-foot-form { display: inline; }
.askr.form .askr-foot-chat { display: none; }

.askr-sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* ── Message form ─────────────────────────────────────────────────────── */
.askr-form { display: none; flex-direction: column; gap: 10px; padding: 16px 18px; overflow-y: auto; }
.askr.form .askr-form { display: flex; }
.askr-form-fields { display: flex; flex-direction: column; gap: 5px; }
.askr-form-fields label + input,
.askr-form-fields label + textarea { margin-bottom: 6px; }
.askr.form .askr-thread,
.askr.form .askr-compose { display: none; }
.askr-form label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-secondary, #5b5954);
}
.askr-form input,
.askr-form textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong, #d6d4d0);
  border-radius: var(--radius, 10px);
  background: var(--bg-base, #faf9f7);
  color: var(--text-primary, #191b1f);
  width: 100%;
  box-sizing: border-box;
}
.askr-form textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
.askr-form input:focus,
.askr-form textarea:focus { outline: none; border-color: #ff7366; background: var(--bg-surface, #fff); }
.askr-form button[type="submit"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  height: 44px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-fg, #fff);
  background: var(--accent, #0c0e13);
  border: 1px solid var(--accent, #0c0e13);
  border-radius: var(--radius, 10px);
  cursor: pointer;
}
.askr-form button[type="submit"]:hover { background: #ff7366; border-color: #ff7366; color: var(--text-primary, #191b1f); }
.askr-form button[type="submit"][disabled] { opacity: 0.5; cursor: default; }
.askr-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.askr-status { margin: 0; font-size: 13px; line-height: 1.5; color: var(--text-primary, #191b1f); }
.askr-status a { color: var(--text-primary, #191b1f); }

@media (max-width: 480px) {
  .askr { right: 12px; left: 12px; align-items: stretch; }
  .askr-panel { width: auto; max-width: none; max-height: 70vh; }
  .askr-launcher { align-self: flex-end; }
}
