/* Grace chat widget — scoped under #grace-root */

#grace-root {
  position: fixed;
  z-index: 9400;
  font-family: 'Montserrat', sans-serif;
  color: #f0f0f0;
}

/* ─── LAUNCHER (collapsed state) ──────────────────────────────── */

#grace-launcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9400;
  background: #7ab648;
  color: #000;
  border: none;
  border-radius: 999px;
  padding: 0 26px;
  height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 22px;
  letter-spacing: 0.08em;
  /* Bebas Neue sits low in its em-box; nudge text up 1px for true visual center. */
  padding-top: 1px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: background 0.2s, transform 0.15s;
}

#grace-launcher:hover {
  background: #8dd44e;
}

#grace-launcher:active {
  transform: scale(0.97);
}

#grace-launcher:focus-visible {
  outline: 2px solid #f0f0f0;
  outline-offset: 2px;
}

#grace-launcher.grace-hidden {
  display: none;
}

/* ─── PANEL (expanded state) ──────────────────────────────────── */

#grace-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 40px);
  background: #161616;
  border: 1px solid rgba(122, 182, 72, 0.25);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

#grace-panel.grace-open {
  display: flex;
}

/* ─── HEADER ──────────────────────────────────────────────────── */

#grace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}

.grace-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.grace-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: #f0f0f0;
  line-height: 1;
}

/* Which conversation this is: Code Essentials, Fly Essentials, FTW Code. Empty on
   the site conversation, where it takes no room. */
.grace-thread {
  font-family: 'Montserrat', sans-serif;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #7ab648;
  margin-bottom: 2px;
}

.grace-thread:empty {
  display: none;
}

.grace-subtitle {
  font-family: 'Montserrat', sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: rgba(240, 240, 240, 0.45);
  letter-spacing: 0.04em;
}

.grace-minimize {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: rgba(240, 240, 240, 0.85);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.grace-minimize:hover {
  color: #7ab648;
  border-color: rgba(122, 182, 72, 0.5);
  color: #f0f0f0;
  background: rgba(255, 255, 255, 0.06);
}

.grace-minimize:focus-visible {
  outline: 1px solid #7ab648;
  outline-offset: 1px;
}

/* ─── MESSAGES ────────────────────────────────────────────────── */

#grace-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#grace-messages::-webkit-scrollbar {
  width: 6px;
}

#grace-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.grace-msg {
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  line-height: 1.6;
  padding: 10px 13px;
  border-radius: 12px;
  max-width: 82%;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: graceFadeIn 0.25s ease;
}

.grace-msg-grace {
  background: #0e0e0e;
  color: #f0f0f0;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.grace-msg-visitor {
  background: #7ab648;
  color: #000;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.grace-msg-system {
  align-self: center;
  font-size: 11px;
  color: rgba(240, 240, 240, 0.45);
  font-style: italic;
  background: none;
  padding: 4px 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

.grace-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.grace-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(240, 240, 240, 0.5);
  animation: graceTyping 1.2s infinite;
}

.grace-typing span:nth-child(2) { animation-delay: 0.15s; }
.grace-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes graceTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

@keyframes graceFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── INPUT AREA ──────────────────────────────────────────────── */

#grace-input-area {
  flex-shrink: 0;
  padding: 12px 14px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.grace-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#grace-input {
  flex: 1;
  background: #0e0e0e;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #f0f0f0;
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  padding: 9px 11px;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 38px;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

#grace-input:focus {
  border-color: rgba(122, 182, 72, 0.5);
}

#grace-input::placeholder {
  color: rgba(240, 240, 240, 0.3);
}

#grace-send {
  background: #7ab648;
  color: #000;
  border: none;
  border-radius: 6px;
  font-family: 'Montserrat', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0 16px;
  height: 38px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

#grace-send:hover:not(:disabled) {
  background: #8dd44e;
}

#grace-send:disabled {
  background: #2a4018;
  color: #0f1a08;
  cursor: not-allowed;
}

#grace-send:focus-visible {
  outline: 1px solid #f0f0f0;
  outline-offset: 1px;
}

.grace-disclaimer {
  font-size: 10px;
  color: rgba(240, 240, 240, 0.35);
  text-align: center;
  letter-spacing: 0.02em;
  padding: 0 4px;
}

/* ─── RESPONSIVE ──────────────────────────────────────────────── */

@media (max-width: 599px) {
  #grace-panel {
    bottom: 8px;
    right: 8px;
    left: 8px;
    width: auto;
    height: min(80vh, 600px);
    max-height: calc(100vh - 16px);
  }

  #grace-launcher {
    bottom: 14px;
    right: 14px;
    padding: 0 22px;
    padding-top: 1px;
    height: 44px;
    font-size: 18px;
  }
}

/* ─── DOCKED BESIDE THE WORKBENCH (hopper-code, ftwcode) ──────── */
/* The page gives up the column's width, so Grace sits next to the workbench,
   never on top of it. --grace-dock-w is set on <html> by the widget: the
   panel width when open, the rail width when minimized. */

html.grace-docked body {
  /* No transition. Pages that size in script measure on the resize event, and an
     animating margin handed them a width that was still moving. */
  margin-right: var(--grace-dock-w, 0) !important;
}

/* ftwcode.ai sizes its text editor pane to 100vw, which would run under the
   column. Let it take the width it is given instead. */
html.grace-docked .code-editor-pane {
  width: auto !important;
}

#grace-root.grace-docked #grace-panel {
  top: var(--grace-dock-top, 0px);
  bottom: 0;
  right: 0;
  width: 320px;
  height: auto;
  max-height: none;
  border: none;
  border-left: 1px solid rgba(122, 182, 72, 0.35);
  border-radius: 0;
  box-shadow: none;
}

/* Minimized: a narrow dark rail. Available, never louder than the workbench. */
#grace-root.grace-docked #grace-launcher {
  top: var(--grace-dock-top, 0px);
  bottom: 0;
  right: 0;
  width: 28px;
  height: auto;
  padding: 0;
  background: #121212;
  color: rgba(122, 182, 72, 0.85);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0;
  box-shadow: none;
  writing-mode: vertical-rl;
  font-size: 15px;
  letter-spacing: 0.16em;
}

#grace-root.grace-docked #grace-launcher:hover {
  background: #1a1d17;
  color: #8dd44e;
  border-left-color: rgba(122, 182, 72, 0.6);
}

#grace-root.grace-docked #grace-launcher:active {
  transform: none;
}

/* ─── LISTEN (student pages) ──────────────────────────────────── */

.grace-listen {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 3px 9px 3px 7px;
  background: transparent;
  color: #7ab648;
  border: 1px solid rgba(122, 182, 72, 0.45);
  border-radius: 999px;
  font-family: 'Montserrat', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
}

.grace-listen:hover,
.grace-listen:focus-visible {
  background: rgba(122, 182, 72, 0.12);
  outline: none;
}

.grace-listen[data-state="loading"] {
  opacity: 0.6;
}

.grace-listen[data-state="playing"] {
  background: #7ab648;
  color: #000;
  border-color: #7ab648;
}

/* ─── RAISED HAND (Rob, 2026-11-03) ─────────────────────────────
   Grace noticed something. A slow heartbeat on her button, never louder than that. */
@keyframes grace-heartbeat {
  0%, 100% { box-shadow: 0 0 0 0 rgba(122, 182, 72, 0.0); }
  12% { box-shadow: 0 0 0 4px rgba(122, 182, 72, 0.55), 0 0 18px 2px rgba(122, 182, 72, 0.35); }
  24% { box-shadow: 0 0 0 1px rgba(122, 182, 72, 0.25); }
  36% { box-shadow: 0 0 0 5px rgba(122, 182, 72, 0.5), 0 0 22px 4px rgba(122, 182, 72, 0.3); }
  60% { box-shadow: 0 0 0 0 rgba(122, 182, 72, 0.0); }
}
#grace-root.grace-hand #grace-launcher { animation: grace-heartbeat 2.4s ease-in-out infinite; }
#grace-root.grace-hand #grace-launcher::after {
  content: ''; position: absolute; top: 6px; right: 6px; width: 9px; height: 9px; border-radius: 50%;
  background: #8dd44e; box-shadow: 0 0 8px #8dd44e;
}
#grace-root.grace-docked.grace-hand #grace-launcher { color: #b6f07e; background: #16200f; border-left-color: rgba(122, 182, 72, 0.8); }
#grace-root.grace-docked.grace-hand #grace-launcher::after { top: 10px; right: 9px; }
#grace-hand-chip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 12px 8px; padding: 10px 12px;
  border: 1px solid rgba(122, 182, 72, 0.55); border-radius: 12px; background: rgba(122, 182, 72, 0.08);
  font-family: 'Montserrat', sans-serif; font-size: 13px; color: #e9f1e2; animation: grace-heartbeat 2.4s ease-in-out 2;
}
#grace-hand-chip span { flex: 1 1 180px; }
#grace-hand-chip button { border-radius: 999px; padding: 5px 12px; font-weight: 700; font-size: 12px; cursor: pointer; }
#grace-hand-chip .grace-hand-yes { background: #7ab648; color: #0b0b0b; border: 0; }
#grace-hand-chip .grace-hand-no { background: transparent; color: #aaa; border: 1px solid #444; }
