/* klikkies.ai, waitlist landing page.
   Colours and shapes follow the hub's own canvas (integration-hub/frontend/src/index.css). */

:root {
  --background: #0b1120;
  --surface: #111a2e;
  --surface-2: #17223a;
  --border: #243049;
  --foreground: #f8fafc;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent: #22c55e;
  --accent-foreground: #052e16;
  --accent-soft: #16361f;
  --warn: #f59e0b;
  --danger: #f43f5e;
  --dot: #26324a;
  --sans: "Fira Sans", system-ui, "Segoe UI", sans-serif;
  --mono: "Fira Code", ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e2e8f0;
    --foreground: #0f172a;
    --muted: #475569;
    --faint: #64748b;
    --accent: #16a34a;
    --accent-foreground: #ffffff;
    --accent-soft: #dcfce7;
    --warn: #d97706;
    --danger: #e11d48;
    --dot: #cbd5e1;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── The board ─────────────────────────────────────────────── */

.board {
  position: fixed; top: 0; left: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--background);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}

.brand {
  position: absolute; top: 20px; left: 24px; z-index: 5;
  display: flex; align-items: center; gap: 10px;
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.brand-pill {
  font-family: var(--mono); font-size: 11px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}

.wire { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.wire path {
  fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 6;
  opacity: 0; transition: opacity .3s;
  animation: wire-flow 1s linear infinite;
}
.wire.is-on path { opacity: 1; }
@keyframes wire-flow { to { stroke-dashoffset: -12; } }

/* ── The Klikkie node ──────────────────────────────────────── */

.node {
  position: absolute; z-index: 3;
  width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  touch-action: none;
  user-select: none;
}
.node-avatar {
  position: relative;
  width: 92px; height: 92px; padding: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  box-shadow: 0 6px 20px rgb(0 0 0 / .25);
  cursor: grab;
  transition: border-color .2s, box-shadow .2s;
}
.node-avatar:active { cursor: grabbing; }
.node-avatar img {
  width: 100%; height: 100%; border-radius: 50%;
  transition: filter .3s, opacity .3s;
}
.node.is-online .node-avatar,
.node.is-typing .node-avatar { border-color: var(--accent); }
.node.is-typing .node-avatar { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 45%, transparent); }
.node-avatar:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.node.is-starting .node-avatar img { opacity: .6; filter: grayscale(1); }
.node-spinner {
  position: absolute; inset: 0; margin: auto;
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--accent); border-right-color: transparent;
  animation: spin .8s linear infinite;
  display: none;
}
.node.is-starting .node-spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.node-dot {
  position: absolute; right: 2px; bottom: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--background);
}
.node-dot::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--warn);
}
.node.is-online .node-dot::after,
.node.is-typing .node-dot::after { background: var(--accent); }
.node.is-starting .node-dot::after,
.node.is-typing .node-dot::after { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.node-name { margin: 4px 0 0; font-weight: 600; font-size: 15px; }
.node-role {
  font-size: 11px; font-weight: 500; line-height: 1;
  padding: 4px 8px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
}
.node-status { margin: 2px 0 0; font-size: 12px; font-weight: 500; color: var(--warn); }
.node.is-online .node-status,
.node.is-typing .node-status { color: var(--accent); }

.node-panel {
  margin: 8px 0 0; width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 8px 24px rgb(0 0 0 / .2);
  font-size: 11px; line-height: 1.35;
}
.node.panel-hidden .node-panel { display: none; }
.node-panel div { display: flex; justify-content: space-between; gap: 10px; }
.node-panel div + div { margin-top: 3px; }
.node-panel dt { color: var(--faint); }
.node-panel dd { margin: 0; text-align: right; color: var(--muted); }

/* ── The chat window ───────────────────────────────────────── */

.chat {
  position: absolute; z-index: 4;
  display: flex; flex-direction: column;
  width: min(420px, calc(100vw - 32px));
  height: min(520px, calc(100dvh - 140px));
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 20px 50px rgb(0 0 0 / .35);
  overflow: hidden;
  animation: chat-in .35s cubic-bezier(.2, .8, .2, 1);
}
.chat[hidden] { display: none; }
.chat.is-moving { user-select: none; }
.chat.is-moving .chat-head { cursor: grabbing; }
.chat-resize {
  position: absolute; right: 0; bottom: 0; width: 18px; height: 18px;
  cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 50%, var(--faint) 50%, var(--faint) 58%, transparent 58%, transparent 70%, var(--faint) 70%, var(--faint) 78%, transparent 78%);
  opacity: .6;
}
.chat-resize:hover { opacity: 1; }

/* ── Language switch ──────────────────────────────────────── */

.lang-switch {
  position: absolute; top: 16px; right: 20px; z-index: 6;
  display: flex; padding: 3px; gap: 2px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
.lang-switch button {
  min-width: 40px; height: 32px; padding: 0 8px;
  border: 0; border-radius: 7px; background: none;
  font-family: var(--mono); font-size: 12px; font-weight: 500; color: var(--muted);
  cursor: pointer;
}
.lang-switch button:hover { color: var(--foreground); }
.lang-switch button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.lang-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@keyframes chat-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }

.chat-head {
  display: flex; align-items: center; gap: 10px;
  cursor: grab; user-select: none; touch-action: none;
  padding: 12px 14px 12px 16px;
  border-bottom: 1px solid var(--border);
}
.chat-head img { border-radius: 50%; background: var(--surface-2); }
.chat-title { flex: 1; min-width: 0; }
.chat-title p { margin: 0; font-weight: 600; font-size: 14px; line-height: 1.2; }
.chat-title .chat-sub { font-weight: 400; font-size: 11px; color: var(--faint); }
.chat-close {
  width: 40px; height: 40px; margin: -4px -6px -4px 0; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
}
.chat-close:hover { color: var(--accent); }
.chat-close svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; fill: none; }

.chat-log {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  font-size: 14px; line-height: 1.5;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 16px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  animation: msg-in .25s ease-out;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } }
.msg.bot {
  align-self: flex-start;
  background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.me {
  align-self: flex-end;
  background: var(--accent-soft);
  border-bottom-right-radius: 4px;
}
.msg.tool {
  align-self: flex-start; max-width: 100%;
  padding: 0 2px; border-radius: 0;
  font-family: var(--mono); font-size: 11.5px; color: var(--faint);
}
.msg.tool::before { content: "⚙ "; }

.typing {
  align-self: flex-start;
  display: inline-flex; gap: 4px;
  padding: 12px 14px; border-radius: 16px; border-bottom-left-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--faint);
  animation: bounce 1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.chat-form {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
}
.chat-input {
  flex: 1; min-width: 0; height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--background); color: var(--foreground);
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
}
.chat-input::placeholder { color: var(--faint); }
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-input:disabled { opacity: .6; }
.chat-input.is-invalid { border-color: var(--danger); }
.chat-send {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-foreground);
  cursor: pointer; transition: opacity .2s;
}
.chat-send:disabled { opacity: .4; cursor: default; }
.chat-send:focus-visible { outline: 2px solid var(--foreground); outline-offset: 2px; }
.chat-send svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; fill: none; }
.turnstile:not(:empty) { display: flex; justify-content: center; padding: 8px 12px 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* ── Phones ─────────────────────────────────────────────── */

@media (max-width: 759px) {
  .brand { top: 14px; left: 16px; }
  .lang-switch { top: 10px; right: 12px; }
  .chat-head { cursor: default; }
  .chat-resize { display: none; }
  .brand-name { font-size: 14px; }
  .node { width: 180px; gap: 3px; touch-action: auto; }
  .node-avatar { width: 76px; height: 76px; cursor: pointer; }
  .node-name { margin-top: 2px; font-size: 14px; }
  .chat { border-radius: 14px; }
  .chat-log { padding: 12px; }
  .chat-form { padding: 8px 10px 10px; }
  .msg { max-width: 88%; }
  .board.chat-full .chat { box-shadow: 0 0 0 100vmax color-mix(in srgb, var(--background) 70%, transparent); }
}

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