/*
 * intake.keffals.gg. Visual design ported from the testing.keffals.gg portal
 * (Surrentum-Org/KGG-Testing index.css tokens + its Tailwind component classes),
 * as plain static CSS: no build step, no external fonts, no inline styles.
 * Light and dark follow prefers-color-scheme.
 */
:root {
  color-scheme: light;
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #efeff3;
  --line: #dcdce2;
  --line-strong: #85858f;
  --fg: #18181b;
  --fg-2: #3a3a42;
  --muted: #5a5a64;
  --accent: #a21caf;
  --accent-hover: #86198f;
  --on-accent: #ffffff;
  --accent-fg: #a21caf;
  --accent-soft: #fbeefd;
  --accent-line: rgba(162, 28, 175, 0.38);
  --user-bubble: #fbeefd;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-line: #f3a7a7;
  --success: #166534;
  --success-bg: #effcf3;
  --focus: #a21caf;
  --code-bg: #efeff3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #141414;
    --surface-2: #1b1b1d;
    --line: #2a2a2d;
    --line-strong: #6e6e78;
    --fg: #f2f2f3;
    --fg-2: #d2d2d6;
    --muted: #a3a3ad;
    --accent: #e879f9;
    --accent-hover: #f0abfc;
    --on-accent: #0d0d0d;
    --accent-fg: #ec8cfa;
    --accent-soft: #221b27;
    --accent-line: rgba(232, 121, 249, 0.42);
    --user-bubble: #241c2a;
    --danger: #f87171;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --danger-line: rgba(239, 68, 68, 0.5);
    --success: #4ade80;
    --success-bg: rgba(34, 197, 94, 0.12);
    --focus: #f0abfc;
    --code-bg: #232326;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
textarea::placeholder { color: var(--muted); opacity: 1; }

h1, h2, p { margin: 0; }
h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.3; }
h2 { font-size: 1rem; font-weight: 700; line-height: 1.35; }
strong { font-weight: 600; color: var(--fg); }

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

/* Header: same shape as the testing portal's (h-14, surface, bottom rule,
   accent dot + uppercase tracked accent name). */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 4px; }
.brand-dot { width: 8px; height: 8px; border-radius: 9999px; background: var(--accent); flex-shrink: 0; }
.brand-name {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-note { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 0.875rem; color: var(--fg-2); min-width: 0; }
.header-sub { font-weight: 600; white-space: nowrap; }
.age-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 9999px;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-fg);
}

main { width: 100%; max-width: 760px; margin: 0 auto; padding: 20px 16px 0; }
#gate, #done { padding-bottom: 32px; }

/* Cards and buttons: the portal's `card`, `btnPrimary`, `btnSecondary`. */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color 150ms, color 150ms, border-color 150ms;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); border: 1px solid transparent; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: var(--fg); border: 1px solid var(--line-strong); padding: 8px 14px; font-weight: 400; }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-link {
  font: inherit;
  font-size: 0.75rem;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0 4px;
  min-height: 32px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.btn-link:hover { color: var(--fg); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.icon { flex-shrink: 0; }

/* Gate */
.gate-card { display: flex; flex-direction: column; gap: 16px; padding: 20px; box-shadow: var(--shadow); }
.gate-head { display: flex; flex-direction: column; gap: 6px; }
.lede { font-size: 0.92rem; color: var(--muted); line-height: 1.625; }
.lede strong { color: var(--fg-2); }
.notes { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 0.875rem; color: var(--fg-2); line-height: 1.625; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color 150ms, background-color 150ms;
}
.check:hover { border-color: var(--accent-line); }
.check:has(input:checked) { border-color: var(--accent-line); background: var(--accent-soft); }
.check input { margin: 3px 0 0; width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
#turnstile:empty { display: none; }

/* Errors: the portal's ErrorNote. Empty alerts take no space. */
.error {
  font-size: 0.875rem;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-line);
  border-radius: 8px;
  padding: 12px;
  overflow-wrap: anywhere;
}
.error:empty { display: none; }

/* Conversation */
#messages { list-style: none; margin: 0; padding: 0 0 20px; display: flex; flex-direction: column; gap: 20px; }
#messages li { scroll-margin-bottom: 240px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
#messages li.customer { align-items: flex-end; }
.speaker { display: flex; align-items: center; gap: 6px; padding: 0 4px; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
#messages li.assistant > .speaker::before { content: ""; width: 6px; height: 6px; border-radius: 9999px; background: var(--accent); }
.bubble {
  max-width: 92%;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.625;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.assistant .bubble { background: var(--surface); border: 1px solid var(--line); color: var(--fg); border-bottom-left-radius: 6px; }
.customer .bubble { background: var(--user-bubble); border: 1px solid var(--accent-line); color: var(--fg); border-bottom-right-radius: 6px; }

.typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  border-bottom-left-radius: 6px;
}
.typing-dot { display: inline-block; width: 6px; height: 6px; border-radius: 9999px; background: var(--accent); animation: pulseDot 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-label { font-size: 0.75rem; color: var(--muted); margin-left: 4px; }
@keyframes pulseDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.35; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* Summary: the portal's "draft is ready" banner plus a code block. */
#summary { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; padding: 14px; background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 12px; }
.summary-banner { display: flex; gap: 12px; align-items: flex-start; color: var(--accent-fg); }
.summary-copy { display: flex; flex-direction: column; gap: 4px; color: var(--fg); }
.summary-copy p { font-size: 0.875rem; color: var(--fg-2); line-height: 1.5; }
#summary pre {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 0.85rem/1.5 var(--mono);
  color: var(--fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Composer: pinned to the bottom like the portal's, same rounded box. */
#dock {
  position: sticky;
  bottom: 0;
  margin: 0 -16px;
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  /* Full-bleed background and top rule, like the portal's composer bar. */
  box-shadow: 0 0 0 100vmax var(--bg);
  clip-path: inset(0 -100vmax);
}
#dock::before { content: ""; position: absolute; top: 0; left: -100vmax; right: -100vmax; height: 1px; background: var(--line); }
.dock-inner { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px 8px; }
#composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  transition: border-color 150ms, box-shadow 150ms;
}
#composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--focus); }
#composer textarea {
  width: 100%;
  min-height: 48px;
  max-height: 200px;
  padding: 2px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.625;
  resize: none;
}
#composer textarea:disabled { cursor: not-allowed; opacity: 0.6; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-end { display: flex; align-items: center; gap: 12px; }
#counter, .hint { font-size: 0.75rem; color: var(--muted); }
#restart { align-self: flex-start; }

/* Done */
.done-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 20px; }
.done-card p { font-size: 0.875rem; color: var(--fg-2); max-width: 28rem; line-height: 1.625; }
.done-icon { color: var(--success); }
.ref { font-family: var(--mono); font-size: 0.9em; overflow-wrap: anywhere; }
.done-card .actions { padding-top: 8px; }

@media (min-width: 640px) {
  .site-header { padding: 0 16px; }
  .bubble { max-width: 85%; padding: 12px 16px; }
  .gate-card { padding: 24px; }
}
@media (max-width: 639px) {
  .hint { display: none; }
  .header-sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
