/* ══════════════════════════════════════════════════════════════════
   engram — design system (from DESIGN.md)
   Dark, premium, alive. Violet = brand/AI · cyan = "the graph is alive".
   ══════════════════════════════════════════════════════════════════ */

:root {
  /* ── surfaces ── */
  --bg-0: #07080d;
  --bg-1: #0b0d15;
  --surface-1: #10131d;
  --surface-2: #161a27;
  --surface-3: #1e2433;
  --glass-bg: rgba(13, 15, 24, 0.72);
  --glass-bg-strong: rgba(16, 19, 29, 0.88);

  /* ── borders ── */
  --border-subtle: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.24);
  --border-accent: rgba(34, 211, 238, 0.45);

  /* ── text ── */
  --text-1: #e7eaf3;
  --text-2: #a6adc2;
  --text-3: #79819a;

  /* ── brand ── */
  --primary: #8b5cf6;
  --primary-strong: #7c3aed;
  --primary-soft: rgba(139, 92, 246, 0.14);
  --on-primary: #ffffff;
  --accent: #22d3ee;
  --accent-strong: #06b6d4;
  --accent-soft: rgba(34, 211, 238, 0.12);
  --on-accent: #04222b;
  --gradient-brand: linear-gradient(135deg, #8b5cf6 0%, #22d3ee 100%);
  --gradient-brand-soft: linear-gradient(135deg, rgba(139,92,246,.18), rgba(34,211,238,.18));

  /* ── semantic ── */
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);

  /* ── ambient glows ── */
  --glow-violet: radial-gradient(600px 480px at 18% -8%, rgba(124, 58, 237, 0.16), transparent 70%);
  --glow-cyan: radial-gradient(700px 520px at 88% 108%, rgba(34, 211, 238, 0.10), transparent 70%);

  /* ── graph canvas palette ── */
  --graph-node-person: #22d3ee;
  --graph-node-project: #a78bfa;
  --graph-node-place: #34d399;
  --graph-node-org: #fbbf24;
  --graph-node-topic: #f472b6;
  --graph-node-thing: #94a3b8;
  --graph-node-preference: #fb7185;
  --graph-edge: rgba(148, 163, 184, 0.26);
  --graph-edge-lit: rgba(34, 211, 238, 0.55);
  --graph-label: rgba(231, 234, 243, 0.82);
  --graph-label-dim: rgba(166, 173, 194, 0.55);
  --graph-dot-grid: rgba(148, 163, 184, 0.055);

  /* ── typography ── */
  --font-display: 'Space Grotesk', 'DM Sans', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3.5rem;
  --leading-tight: 1.15;
  --leading-body: 1.55;

  /* ── spacing (4px base) ── */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px; --sp-20: 80px; --sp-24: 96px;

  /* ── radii ── */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 999px;

  /* ── shadows & glows ── */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55), 0 4px 12px rgba(0,0,0,.4);
  --glow-accent: 0 0 24px rgba(34, 211, 238, 0.28), 0 0 4px rgba(34, 211, 238, 0.4);
  --glow-primary: 0 0 28px rgba(139, 92, 246, 0.30);
  --ring: 0 0 0 2px var(--bg-0), 0 0 0 4px var(--accent);

  /* ── motion ── */
  --dur-fast: 150ms;
  --dur-med: 250ms;
  --dur-slow: 500ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);

  /* ── metrics ── */
  --nav-h: 64px;
  --topbar-h: 56px;
  --content-max: 1120px;
  --chat-w: 400px;
  --sidebar-w: 264px;
}

/* ── base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(139, 92, 246, .35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--radius-full); }

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: var(--leading-tight); margin: 0; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
img, svg, canvas { display: block; }
[hidden] { display: none !important; }

.mono { font-family: var(--font-mono); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
}
.grad-text {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ambient page glows (fixed) */
.glow-page::before, .glow-page::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
}
.glow-page::before { background: var(--glow-violet); }
.glow-page::after  { background: var(--glow-cyan); }
.glow-page > * { position: relative; z-index: 1; }

/* ── interactive base ─────────────────────────────────────────────── */
button, a, input, textarea, [role="button"] {
  transition: all var(--dur-fast) var(--ease-in-out);
}
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* ── buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-2);
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  border: 0;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn[disabled] { opacity: .4; cursor: not-allowed; transform: none; }
.btn-lg { padding: 14px 24px; font-size: var(--text-base); }
.btn-block { width: 100%; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); box-shadow: var(--glow-primary); color: var(--on-primary); }

.btn-accent { background: var(--accent); color: var(--on-accent); }
.btn-accent:hover { background: var(--accent-strong); box-shadow: var(--glow-accent); color: var(--on-accent); }

.btn-ghost {
  background: transparent; color: var(--text-1);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-1); }
.btn-ghost:active { background: var(--surface-3); }

.btn-google {
  background: #ffffff; color: #1f1f1f;
  border: 1px solid #dadce0;
  font-family: var(--font-body); font-weight: 500;
}
.btn-google:hover { background: #f8f9fa; box-shadow: 0 2px 8px rgba(0,0,0,.35); color: #1f1f1f; }
.btn-google svg { width: 18px; height: 18px; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-md);
  background: transparent; border: 0; color: var(--text-3); padding: 0;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text-1); }
.btn-icon.sm { width: 32px; height: 32px; }

.link-quiet { color: var(--text-2); font-size: var(--text-sm); }
.link-quiet:hover { color: var(--text-1); }

/* ── inputs ───────────────────────────────────────────────────────── */
.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: var(--text-sm);
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--border-accent); box-shadow: var(--ring); }
.input.err { border-color: var(--danger); }
.field-err { color: var(--danger); font-size: var(--text-xs); margin-top: var(--sp-1); }

/* ── cards ────────────────────────────────────────────────────────── */
.card-panel {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.card-glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.grad-border {
  border: 1px solid transparent;
  background:
    linear-gradient(var(--surface-2), var(--surface-2)) padding-box,
    var(--gradient-brand) border-box;
}

/* ── chips / badges / meter ───────────────────────────────────────── */
.chip-type {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-2);
  padding: 3px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
}
.chip-type .dot { width: 6px; height: 6px; border-radius: 50%; }

.badge-plan {
  font-family: var(--font-mono); font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 3px 10px; border-radius: var(--radius-full);
}
.badge-plan.free { border: 1px solid var(--border-strong); color: var(--text-3); }
.badge-plan.pro {
  background: var(--gradient-brand); color: #04222b; font-weight: 500;
  border: 0;
}

.usage-meter { display: inline-flex; align-items: center; gap: var(--sp-2); }
.usage-meter .count { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3); }
.usage-meter .track {
  width: 64px; height: 4px; border-radius: var(--radius-full);
  background: var(--surface-3); overflow: hidden;
}
.usage-meter .fill {
  height: 100%; background: var(--accent); border-radius: var(--radius-full);
  transition: width 400ms var(--ease-out);
}
.usage-meter.warn .fill { background: var(--warning); }
.usage-meter.full .fill { background: var(--danger); }
.usage-meter.warn .count, .usage-meter.full .count { color: var(--text-2); }

/* ── spinner ──────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  background: conic-gradient(var(--accent), transparent 70%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  animation: spin 900ms linear infinite;
}
.spinner.lg { width: 40px; height: 40px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════ LANDING ══════════════════ */

.nav {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}
.nav-inner {
  max-width: var(--content-max); margin: 0 auto; height: 100%;
  padding: 0 var(--sp-6);
  display: flex; align-items: center; gap: var(--sp-8);
}
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); }
.brand .mark { width: 28px; height: 28px; }
.brand .word {
  font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg);
  color: var(--text-1);
}
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: var(--sp-6); margin: 0 auto; }
.nav-links a { font-size: var(--text-sm); color: var(--text-2); }
.nav-links a:hover { color: var(--text-1); text-decoration: none; }
.nav-right { display: flex; align-items: center; gap: var(--sp-3); margin-left: auto; }
.nav-links + .nav-right { margin-left: 0; }

/* hero */
.hero {
  max-width: var(--content-max); margin: 0 auto;
  padding: 0 var(--sp-6);
  min-height: min(calc(100vh - var(--nav-h)), 720px);
  display: grid; grid-template-columns: 1.05fr 0.95fr;
  gap: var(--sp-16); align-items: center;
}
.hero-copy .eyebrow { display: block; margin-bottom: var(--sp-5); }
.hero-copy h1 { font-size: var(--text-5xl); margin-bottom: var(--sp-5); }
.hero-copy .sub {
  font-size: var(--text-lg); color: var(--text-2);
  max-width: 46ch; margin-bottom: var(--sp-8);
}
.hero-ctas { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3); }
.hero-ctas .btn-google { min-width: 280px; }
.micro { font-size: var(--text-xs); color: var(--text-3); }

.preview-card {
  width: 480px; max-width: 100%; height: 420px;
  justify-self: end;
  position: relative; overflow: hidden;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}
.preview-card canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.preview-card .caption {
  position: absolute; left: var(--sp-4); bottom: var(--sp-4);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3);
}
.preview-card .caption .live-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-right: 6px;
  box-shadow: var(--glow-accent);
  animation: pulse-dot 3s var(--ease-in-out) infinite;
}
@keyframes pulse-dot { 50% { opacity: .35; } }

/* sections */
.section { padding: var(--sp-24) 0; }
.section-inner { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--sp-6); }
.section-head { text-align: center; margin-bottom: var(--sp-12); }
.section-head .eyebrow { display: block; margin-bottom: var(--sp-3); }
.section-head h2 { font-size: var(--text-3xl); }
.section-head .sub { color: var(--text-2); margin-top: var(--sp-3); }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-6); }
.step-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-8);
}
.step-card .num {
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent);
  display: block; margin-bottom: var(--sp-4);
}
.step-card h3 { font-size: var(--text-lg); margin-bottom: var(--sp-2); }
.step-card p { font-size: var(--text-sm); color: var(--text-2); }
.step-card.showpiece { border-color: var(--border-accent); box-shadow: var(--glow-accent); }

.pricing { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-6); max-width: 880px; margin: 0 auto; align-items: center; }
.price-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--sp-10);
  position: relative;
}
.price-card .plan-name { font-size: var(--text-sm); color: var(--text-2); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .1em; }
.price-card .amount { font-family: var(--font-display); font-size: var(--text-4xl); font-weight: 600; margin: var(--sp-4) 0 var(--sp-1); }
.price-card .amount small { font-size: var(--text-lg); color: var(--text-3); font-weight: 400; }
.price-card ul { list-style: none; margin: var(--sp-6) 0 var(--sp-8); padding: 0; display: grid; gap: var(--sp-3); }
.price-card li { display: flex; gap: var(--sp-3); align-items: center; font-size: var(--text-sm); color: var(--text-2); }
.price-card li svg { flex: none; }
.price-card.pro {
  background:
    linear-gradient(var(--surface-2), var(--surface-2)) padding-box,
    var(--gradient-brand) border-box;
  border: 1px solid transparent;
  box-shadow: var(--glow-primary);
  transform: scale(1.03);
}
.price-card .pro-badge {
  position: absolute; top: var(--sp-5); right: var(--sp-5);
  background: var(--gradient-brand); color: #04222b;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 500;
  letter-spacing: .1em; padding: 4px 10px; border-radius: var(--radius-full);
}

.final-cta { text-align: center; padding: var(--sp-20) 0; position: relative; }
.final-cta::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(480px 260px at 50% 60%, var(--primary-soft), transparent 70%);
  pointer-events: none;
}
.final-cta h2 { font-size: var(--text-3xl); margin-bottom: var(--sp-6); position: relative; }
.final-cta .btn-google { position: relative; }
.final-cta .micro { display: block; margin-top: var(--sp-4); position: relative; }

.footer {
  border-top: 1px solid var(--border-subtle);
  min-height: 72px;
}
.footer-inner {
  max-width: var(--content-max); margin: 0 auto; padding: var(--sp-5) var(--sp-6);
  display: flex; align-items: center; gap: var(--sp-6);
}
.footer .brand .mark { width: 20px; height: 20px; }
.footer .brand .word { font-size: var(--text-sm); }
.footer .privacy-note { font-size: var(--text-xs); color: var(--text-3); margin: 0 auto; }
.footer .links { display: flex; gap: var(--sp-5); }
.footer .links a { font-size: var(--text-sm); color: var(--text-3); }
.footer .links a:hover { color: var(--text-1); text-decoration: none; }

/* reveal animation */
.reveal { opacity: 0; transform: translateY(16px); transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out); }
.reveal.in { opacity: 1; transform: none; }

/* auth modal (landing email fallback) */
.modal-scrim {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(7,8,13,.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6);
}
.modal-scrim .auth-card { position: relative; }
.modal-scrim .modal-close { position: absolute; top: var(--sp-3); right: var(--sp-3); }

/* ── auth card ────────────────────────────────────────────────────── */
.auth-card {
  width: 380px; max-width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-8);
}
.auth-card .mark { width: 32px; height: 32px; margin-bottom: var(--sp-5); }
.auth-card h2 { font-size: var(--text-xl); margin-bottom: var(--sp-1); }
.auth-card .sub { font-size: var(--text-sm); color: var(--text-2); margin-bottom: var(--sp-6); }
.auth-card .btn-google { margin-bottom: var(--sp-5); }
.auth-card .divider {
  display: flex; align-items: center; gap: var(--sp-3);
  font-size: var(--text-xs); color: var(--text-3);
  margin-bottom: var(--sp-5);
}
.auth-card .divider::before, .auth-card .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border-subtle);
}
.auth-card form { display: grid; gap: var(--sp-3); }
.auth-card .swap { margin-top: var(--sp-5); text-align: center; font-size: var(--text-sm); color: var(--text-3); }
.auth-card .swap button { background: none; border: 0; color: var(--accent); font-size: inherit; padding: 0; }
.auth-card .swap button:hover { text-decoration: underline; }
.auth-err { color: var(--danger); font-size: var(--text-xs); min-height: 1em; }
.auth-note { color: var(--success); font-size: var(--text-xs); min-height: 1em; }

/* ══════════════════ APP SHELL ══════════════════ */

body.app { height: 100dvh; overflow: hidden; background: var(--bg-1); display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: none;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center;
  padding: 0 var(--sp-4); gap: var(--sp-3);
  position: relative; z-index: 40;
}
.topbar .brand .mark { width: 24px; height: 24px; }
.topbar .brand .word { font-size: var(--text-base); }
.topbar .cluster { margin-left: auto; display: flex; align-items: center; gap: var(--sp-3); }

.avatar-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 0; padding: 0; overflow: hidden;
  background: var(--primary-soft); color: var(--primary);
  font-family: var(--font-display); font-weight: 600; font-size: var(--text-xs);
  display: inline-flex; align-items: center; justify-content: center;
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }
.avatar-menu {
  position: absolute; top: calc(var(--topbar-h) - 6px); right: var(--sp-4);
  min-width: 200px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-2);
  z-index: 60;
}
.avatar-menu .email {
  font-size: var(--text-xs); color: var(--text-3);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--sp-1);
  word-break: break-all;
}
.avatar-menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; color: var(--text-2);
  font-size: var(--text-sm); padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
}
.avatar-menu button:hover { background: var(--surface-2); color: var(--text-1); }

.usage-banner {
  flex: none;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border-accent);
  font-size: var(--text-xs); color: var(--text-2);
  padding: var(--sp-2) var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-3);
}
.usage-banner a { color: var(--accent); font-weight: 500; }

.app-body {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: var(--chat-w) 1fr var(--sidebar-w);
}

/* ── chat panel ── */
.chat-panel {
  background: var(--surface-1);
  border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
}
.chat-head {
  height: 48px; flex: none;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; padding: 0 var(--sp-4);
}
.chat-head h2 { font-size: var(--text-base); }
.chat-head .tag {
  margin-left: auto; font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--primary); letter-spacing: .08em;
}
.msg-list {
  flex: 1; overflow-y: auto;
  padding: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-4);
}
.msg-user {
  align-self: flex-end;
  background: var(--surface-3);
  border-radius: var(--radius-lg);
  border-bottom-right-radius: 6px;
  padding: 10px 14px;
  max-width: 85%;
  font-size: var(--text-sm);
  white-space: pre-wrap; word-break: break-word;
}
.msg-ai { max-width: 100%; font-size: var(--text-sm); }
.msg-ai .ai-label {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--primary);
  margin-bottom: var(--sp-1);
}
.msg-ai .ai-label::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}
.msg-ai .ai-body { white-space: pre-wrap; word-break: break-word; }
.msg-learned {
  margin-top: var(--sp-2);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent);
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
}
.msg-learned:hover { text-decoration: underline; }
.msg-warn {
  margin-top: var(--sp-2);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--warn, #f59e0b);
}
.chat-empty {
  margin: auto; text-align: center; color: var(--text-3);
  font-size: var(--text-sm); max-width: 30ch; padding: var(--sp-6);
}
.chat-empty .mark { width: 40px; height: 40px; margin: 0 auto var(--sp-4); opacity: .8; }

.typing { display: inline-flex; gap: 5px; padding: var(--sp-2) 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-3);
  animation: tp 1.2s var(--ease-in-out) infinite;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes tp { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.composer { flex: none; padding: var(--sp-3); border-top: 1px solid var(--border-subtle); }
.composer .box { position: relative; }
.composer textarea {
  width: 100%; resize: none;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 52px 12px 14px;
  color: var(--text-1); font-family: var(--font-body); font-size: var(--text-sm);
  line-height: 1.45;
  min-height: 44px; max-height: 120px;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer textarea:focus { outline: none; border-color: var(--border-accent); box-shadow: var(--ring); }
.composer .send {
  position: absolute; right: 8px; bottom: 8px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  border: 0; display: inline-flex; align-items: center; justify-content: center;
}
.composer .send:hover { background: var(--primary-strong); box-shadow: var(--glow-primary); }
.composer .send:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.composer .hint {
  font-size: var(--text-xs); color: var(--text-3);
  margin-top: var(--sp-2); text-align: right;
}

.upgrade-card {
  flex: none; margin: var(--sp-3);
  background: var(--accent-soft);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
}
.upgrade-card p { font-size: var(--text-sm); margin-bottom: var(--sp-3); }
.upgrade-card .btn { width: 100%; }

/* ── graph panel ── */
.graph-panel { position: relative; min-width: 0; min-height: 0; background: var(--bg-1); }
.graph-panel canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.graph-overlay {
  position: absolute; top: var(--sp-4); left: var(--sp-4);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
}
.graph-overlay .counts { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3); margin-left: var(--sp-2); }
.graph-legend {
  position: absolute; top: var(--sp-4); right: var(--sp-4);
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  display: grid; gap: 6px;
  font-size: var(--text-xs); color: var(--text-2);
}
.graph-legend .li { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-mono); }
.graph-legend .dot { width: 8px; height: 8px; border-radius: 50%; }
.graph-legend-btn {
  position: absolute; top: var(--sp-4); right: var(--sp-4);
  width: 32px; height: 32px; border-radius: var(--radius-md);
  background: var(--glass-bg); border: 1px solid var(--border-subtle);
  color: var(--text-3); font-family: var(--font-mono); font-size: var(--text-sm);
  backdrop-filter: blur(16px);
}
.graph-legend-btn:hover { color: var(--text-1); background: var(--surface-2); }

.detail-card {
  position: absolute; top: var(--sp-16); right: var(--sp-4);
  width: 288px; max-height: calc(100% - var(--sp-20));
  overflow-y: auto;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-5);
  z-index: 10;
}
.detail-card .close { position: absolute; top: var(--sp-3); right: var(--sp-3); }
.detail-card h3 { font-size: var(--text-lg); margin-bottom: var(--sp-2); padding-right: var(--sp-8); word-break: break-word; }
.detail-card .chip-type { margin-bottom: var(--sp-3); }
.detail-card .summary { font-size: var(--text-sm); color: var(--text-2); margin-bottom: var(--sp-4); }
.detail-card .facts-label {
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3);
  text-transform: uppercase; letter-spacing: .1em; margin-bottom: var(--sp-2);
}
.detail-card ul { margin: 0 0 var(--sp-4); padding-left: var(--sp-5); }
.detail-card li { font-size: var(--text-sm); color: var(--text-2); margin-bottom: var(--sp-1); }
.detail-card .meta { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3); }

/* ── entities sidebar ── */
.entities-panel {
  background: var(--surface-1);
  border-left: 1px solid var(--border-subtle);
  display: flex; flex-direction: column;
  min-height: 0;
}
.entities-head {
  height: 48px; flex: none;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; padding: 0 var(--sp-4);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3);
  letter-spacing: .1em;
}
.entities-head .count { margin-left: auto; letter-spacing: 0; }
.entities-list { flex: 1; overflow-y: auto; padding: var(--sp-3) var(--sp-2); }
.entities-group { margin-bottom: var(--sp-4); }
.entities-group .g-label {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3);
  padding: var(--sp-1) var(--sp-2); text-transform: lowercase;
}
.entities-group .g-label .dot { width: 6px; height: 6px; border-radius: 50%; }
.entity-row {
  display: flex; align-items: center; gap: var(--sp-2);
  width: 100%; min-height: 40px;
  padding: var(--sp-2);
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: var(--text-sm); text-align: left;
  border-left: 2px solid transparent;
}
.entity-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-row .n { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3); }
.entity-row:hover { background: var(--surface-2); }
.entity-row.sel { background: var(--surface-3); color: var(--text-1); }
.entities-empty { padding: var(--sp-6); color: var(--text-3); font-size: var(--text-sm); text-align: center; }

/* ── tabs (mobile) ── */
.tabs {
  flex: none; display: none;
  margin: var(--sp-2) var(--sp-4);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 4px;
  position: relative;
  height: 40px;
}
.tabs button {
  flex: 1; position: relative; z-index: 1;
  background: none; border: 0; border-radius: var(--radius-full);
  color: var(--text-3); font-size: var(--text-sm); font-family: var(--font-display); font-weight: 600;
}
.tabs button.active { color: var(--text-1); }
.tabs .slide {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px);
  background: var(--surface-3); border-radius: var(--radius-full);
  transition: transform var(--dur-med) var(--ease-in-out);
}
.tabs.graph-active .slide { transform: translateX(100%); }

.drawer-scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(7,8,13,.6);
}
.graph-entities-btn {
  position: absolute; bottom: var(--sp-4); right: var(--sp-4);
  z-index: 5;
}

/* ── sign-in gate on /app ── */
.auth-gate {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6); background: var(--bg-1);
}

/* ══════════════════ PAY PAGES ══════════════════ */

.pay-shell {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6);
  position: relative;
}
.pay-card {
  width: 440px; max-width: 100%;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-10);
  background:
    linear-gradient(var(--surface-1), var(--surface-1)) padding-box,
    var(--gradient-brand) border-box;
  border: 1px solid transparent;
  position: relative;
}
.pay-card.plain { border: 1px solid var(--border-subtle); background: var(--surface-1); width: 400px; }
.pay-card .pro-badge {
  display: inline-block;
  background: var(--gradient-brand); color: #04222b;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 500;
  letter-spacing: .1em; padding: 4px 10px; border-radius: var(--radius-full);
  margin-bottom: var(--sp-4);
}
.pay-card h1 { font-size: var(--text-3xl); margin-bottom: var(--sp-4); }
.pay-card .price { font-family: var(--font-display); font-size: var(--text-5xl); font-weight: 600; }
.pay-card .price small { font-size: var(--text-lg); color: var(--text-3); font-weight: 400; }
.pay-card ul { list-style: none; margin: var(--sp-6) 0 var(--sp-8); padding: 0; display: grid; gap: var(--sp-3); }
.pay-card li { display: flex; gap: var(--sp-3); align-items: center; font-size: var(--text-sm); color: var(--text-2); }
.pay-card .back { display: inline-block; margin-top: var(--sp-5); font-size: var(--text-sm); color: var(--text-3); }
.pay-card .back:hover { color: var(--text-1); }
.pay-card .note { margin-top: var(--sp-4); font-size: var(--text-xs); color: var(--text-3); text-align: center; }
.pay-card .err { color: var(--danger); font-size: var(--text-xs); margin-top: var(--sp-3); min-height: 1em; }

.pay-state { text-align: center; }
.pay-state .icon-circle {
  width: 56px; height: 56px; border-radius: 50%;
  margin: 0 auto var(--sp-5);
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
}
.pay-state .icon-circle.danger { background: var(--danger-soft); }
.pay-state .icon-circle.muted { background: var(--surface-3); }
.pay-state h1 { font-size: var(--text-2xl); margin-bottom: var(--sp-2); }
.pay-state .sub { font-size: var(--text-sm); color: var(--text-2); margin-bottom: var(--sp-8); }
.pay-state .actions { display: grid; gap: var(--sp-3); }
.pay-state .spinner.lg { margin: var(--sp-6) auto var(--sp-5); }

/* ── responsive ───────────────────────────────────────────────────── */

@media (max-width: 1399px) {
  .graph-legend { display: none; }
  .graph-legend.open { display: grid; }
  .graph-legend-btn { display: inline-flex; align-items: center; justify-content: center; }
}
@media (min-width: 1400px) {
  .graph-legend-btn { display: none; }
}

@media (max-width: 1023px) {
  .app-body { grid-template-columns: 360px 1fr; }
  .entities-panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 71;
    width: var(--sidebar-w); max-width: 85vw;
    transform: translateX(100%);
    transition: transform var(--dur-med) var(--ease-in-out);
    box-shadow: var(--shadow-lg);
  }
  .entities-panel.open { transform: none; }
  .graph-entities-btn { display: inline-flex; }
}
@media (min-width: 1024px) {
  .graph-entities-btn { display: none; }
}

@media (max-width: 767px) {
  .hero { grid-template-columns: 1fr; gap: var(--sp-10); padding-top: var(--sp-10); padding-bottom: var(--sp-10); min-height: 0; }
  .hero-copy h1 { font-size: var(--text-4xl); }
  .preview-card { justify-self: stretch; width: 100%; height: 340px; }
  .steps { grid-template-columns: 1fr; }
  .pricing { grid-template-columns: 1fr; }
  .price-card.pro { transform: none; }
  .nav-links { display: none; }
  .section { padding: var(--sp-16) 0; }
  .section-head h2 { font-size: var(--text-2xl); }

  .app-body { display: flex; flex-direction: column; }
  .app-body > .chat-panel, .app-body > .graph-panel { display: none; }
  .app-body.tab-chat > .chat-panel { display: flex; flex: 1; min-height: 0; }
  .app-body.tab-graph > .graph-panel { display: block; flex: 1; min-height: 0; position: relative; }
  .tabs { display: flex; }
  .composer .hint { display: none; }
  .usage-meter .track { display: none; }
  .detail-card {
    top: auto; right: 0; left: 0; bottom: 0;
    width: 100%; max-height: 55%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }
  .topbar .brand { margin-right: auto; }
}

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