/* Design: AI-native, terminal look (ui-ux-pro-max "AI/Chatbot Platform"), neon accent on near-black.
   RTL-first: layout uses logical properties (inline-start = right in Persian). */

/* Self-hosted variable fonts (OFL), from @fontsource-variable. Google Fonts is unreliable from Iran. */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-arabic.woff2") format("woff2-variations"), url("fonts/vazirmatn-arabic.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn-latin.woff2") format("woff2-variations"), url("fonts/vazirmatn-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin.woff2") format("woff2-variations"), url("fonts/jetbrains-mono-latin.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}

:root {
  --font: "Vazirmatn", Tahoma, system-ui, sans-serif;
  /* Persian characters inside code fall back to Vazirmatn instead of a random system font. */
  --mono: "JetBrains Mono", "Vazirmatn", Consolas, monospace;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 20px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --sidebar: 288px;
  --content: 760px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fast: 150ms;
  --normal: 220ms;
}

/* Dark is the default theme. Text contrast on --bg: --text 15:1, --muted 7:1, --accent 6.5:1. */
:root,
[data-theme="dark"] {
  /* Terminal palette. Contrast on --bg: --text 15:1, --muted 7.2:1, --accent 14:1. */
  --bg: #05070a;
  --surface: #0a0e13;
  --surface-2: #0f151c;
  --surface-3: #17202a;
  --border: #1b2631;
  --text: #dce6f0;
  --muted: #8d9cae;
  --accent: #3dffa0;
  --accent-2: #4cc9ff;
  --accent-3: #c77dff;
  --accent-strong: #2bf08f;
  --on-accent: #03140b;
  --accent-soft: rgba(61, 255, 160, .1);
  --glow: 0 0 0 1px rgba(61, 255, 160, .35), 0 0 24px rgba(61, 255, 160, .18);
  --danger: #ff6b7d;
  --danger-soft: rgba(255, 107, 125, .1);
  --warning: #ffcc66;
  --success: #3dffa0;
  --user-bubble: #0f1a17;
  --code-bg: #030507;
  --grid: rgba(61, 255, 160, .045);
  --shadow: 0 12px 40px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --surface-3: #e2e8ee;
  --border: #d7dee6;
  --text: #0c1219;
  --muted: #4a5767;
  --accent: #067a4c;
  --accent-2: #0b6aa8;
  --accent-3: #7b3fc4;
  --accent-strong: #067a4c;
  --on-accent: #ffffff;
  --accent-soft: rgba(6, 122, 76, .09);
  --glow: 0 0 0 1px rgba(6, 122, 76, .35), 0 0 18px rgba(6, 122, 76, .12);
  --danger: #c8283a;
  --danger-soft: rgba(200, 40, 58, .08);
  --warning: #8a5a00;
  --success: #067a4c;
  --user-bubble: #e7f4ee;
  --code-bg: #f2f5f8;
  --grid: rgba(6, 122, 76, .05);
  --shadow: 0 12px 34px rgba(12, 18, 25, .1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.75 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.6; }
.sprite { position: absolute; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Brand */
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand h1 { margin: 0; font-size: 24px; font-weight: 800; }
.small-brand { font-weight: 700; font-size: 16px; gap: var(--space-2); }
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px; flex: none;
  background: conic-gradient(from var(--spin, 0deg), var(--accent), var(--accent-2), var(--accent-3), var(--accent));
  animation: mark-spin 6s linear infinite;
  box-shadow: inset 0 0 0 6px var(--bg);
}
.brand-mark.big { width: 56px; height: 56px; border-radius: 18px; box-shadow: inset 0 0 0 12px var(--bg); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius);
  font-weight: 600; transition: background var(--fast) var(--ease), border-color var(--fast), transform var(--fast);
}
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent-strong); color: var(--on-accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger); color: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted);
  transition: background var(--fast), color var(--fast);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* Boot + login */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100%; display: grid; place-items: center; padding: var(--space-5) var(--space-4);
  background: radial-gradient(60rem 30rem at 50% -10%, var(--accent-soft), transparent 70%); }
.login-card {
  width: min(400px, 100%); display: grid; gap: var(--space-4);
  padding: var(--space-6) var(--space-5); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.login-card p { margin: 0; }
.field { display: grid; gap: var(--space-2); font-weight: 600; font-size: 14px; }
.field input {
  min-height: 46px; padding: 0 var(--space-3); border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--border); font-size: 16px; text-align: left;
  transition: border-color var(--fast), box-shadow var(--fast);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { margin: 0; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: 14px; }

/* Shell */
.shell { display: flex; height: 100%; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar); flex: none; display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-3); background: var(--surface); border-inline-end: 1px solid var(--border);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding-inline: var(--space-2); }
.new-chat { justify-content: flex-start; }
.conv-list { flex: 1; overflow-y: auto; margin-inline: calc(var(--space-1) * -1); padding-inline: var(--space-1); }
.conv-list ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.conv-group { padding: var(--space-3) var(--space-3) var(--space-1); font-size: 12px; font-weight: 700; color: var(--muted); }
.conv { position: relative; display: flex; align-items: center; border-radius: var(--radius-sm); }
.conv a {
  flex: 1; min-width: 0; padding: 9px var(--space-3); color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; border-radius: var(--radius-sm);
}
.conv:hover, .conv.active { background: var(--surface-3); }
.conv.active a { font-weight: 600; }
.conv-actions { display: none; padding-inline-end: var(--space-1); }
.conv:hover .conv-actions, .conv.active .conv-actions, .conv:focus-within .conv-actions { display: flex; }
.conv-actions .icon-btn { width: 32px; height: 32px; }
.conv-actions svg { width: 16px; height: 16px; }
.conv-rename { flex: 1; margin: 4px; padding: 5px var(--space-2); border: 1px solid var(--accent); border-radius: 6px; background: var(--bg); font-size: 14px; }
.conv-empty { padding: var(--space-4) var(--space-3); font-size: 14px; color: var(--muted); }

.sidebar-bottom { display: grid; gap: var(--space-3); border-top: 1px solid var(--border); padding-top: var(--space-3); }
.usage { display: grid; gap: 6px; padding: var(--space-3); border-radius: var(--radius); background: var(--surface-2); }
.usage-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width var(--normal) var(--ease); }
.usage.warn .meter span { background: var(--warning); }
.usage.full .meter span { background: var(--danger); }
.account { display: flex; align-items: center; gap: var(--space-2); }
.avatar { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.account-text { flex: 1; min-width: 0; line-height: 1.4; }
.account-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: var(--space-2); min-height: 56px; padding: 0 var(--space-4); border-bottom: 1px solid var(--border); }
.chat-title { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode select {
  min-height: 36px; padding: 0 var(--space-3); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); font-size: 14px;
}

.scroller { flex: 1; overflow-y: auto; scroll-behavior: smooth; overscroll-behavior: contain; }
.empty { max-width: var(--content); margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); padding: var(--space-6) var(--space-4); text-align: center; }
.empty h3 { margin: 0; font-size: clamp(20px, 3vw, 28px); font-weight: 700; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-3); width: 100%; margin-top: var(--space-3); }
.suggestion {
  display: grid; gap: 2px; text-align: start; padding: var(--space-3) var(--space-4); min-height: 64px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); line-height: 1.5;
  transition: background var(--fast), border-color var(--fast), transform var(--fast);
}
.suggestion:hover { background: var(--surface-2); border-color: var(--surface-3); transform: translateY(-1px); }
.suggestion strong { font-size: 14px; }
.suggestion span { font-size: 13px; color: var(--muted); }

/* Messages */
.messages { list-style: none; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-6); max-width: var(--content); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); }
.messages:empty { display: none; }
.msg { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); min-width: 0; animation: rise var(--normal) var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.user { justify-items: end; }
.msg.user .bubble {
  max-width: 85%; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  background: var(--user-bubble); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user .images { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; }
.msg.user .images img { width: 160px; max-height: 200px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }
.msg-actions { display: flex; gap: 2px; opacity: 0; transition: opacity var(--fast); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg.last .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 32px; height: 32px; }
.msg-actions svg { width: 16px; height: 16px; }
.msg-meta { font-size: 12px; color: var(--muted); padding-inline: var(--space-2); align-self: center; direction: ltr; }

.thinking { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.msg-error { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); font-size: 14px; }
.msg-error .btn { min-height: 36px; background: var(--surface); color: var(--text); border-color: var(--border); }

/* Markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md table { margin: 0 0 var(--space-3); }
.md h1, .md h2, .md h3, .md h4 { margin: var(--space-5) 0 var(--space-2); line-height: 1.4; font-weight: 700; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4 { font-size: 16px; }
.md ul, .md ol { padding-inline-start: var(--space-5); }
.md li { margin: 2px 0; }
.md li::marker { color: var(--muted); }
.md a { color: var(--accent); text-underline-offset: 3px; }
.md strong { font-weight: 700; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }
.md blockquote { padding: var(--space-1) var(--space-4); border-inline-start: 3px solid var(--accent); color: var(--muted); background: var(--surface); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.md code { font-family: var(--mono); font-size: .88em; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); direction: ltr; unicode-bidi: isolate; }
.md .table-wrap { overflow-x: auto; margin: 0 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 0; }
.md th, .md td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); text-align: start; vertical-align: top; }
.md th { background: var(--surface); font-weight: 700; }
.md tr:last-child td { border-bottom: 0; }
.codeblock { margin: 0 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); direction: ltr; }
.codeblock-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 4px var(--space-3); background: var(--surface); border-bottom: 1px solid var(--border); font: 12px/1.5 var(--mono); color: var(--muted); }
.codeblock-head .icon-btn { width: auto; height: 30px; padding: 0 var(--space-2); gap: 6px; display: inline-flex; font: 600 12px var(--font); }
.codeblock-head svg { width: 15px; height: 15px; }
.codeblock pre { margin: 0; padding: var(--space-3) var(--space-4); overflow-x: auto; font: 13.5px/1.65 var(--mono); tab-size: 4; }
.codeblock pre code { padding: 0; background: none; font-size: inherit; }
.tok-k { color: #c792ea; } .tok-s { color: #a5d6a7; } .tok-c { color: #7f8798; font-style: italic; } .tok-n { color: #f5b971; }
[data-theme="light"] .tok-k { color: #7c3aed; } [data-theme="light"] .tok-s { color: #0f7a3d; } [data-theme="light"] .tok-c { color: #6b7280; } [data-theme="light"] .tok-n { color: #b45309; }
.cursor::after { content: ""; display: inline-block; width: 8px; height: 1.1em; margin-inline-start: 2px; vertical-align: text-bottom; background: var(--accent); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Composer */
.composer-wrap { padding: 0 var(--space-4) max(var(--space-3), env(safe-area-inset-bottom)); }
.composer {
  max-width: var(--content); margin: 0 auto; display: grid; gap: var(--space-2);
  padding: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); transition: border-color var(--fast), box-shadow var(--fast);
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.composer.dragging { border-style: dashed; border-color: var(--accent); }
.composer textarea {
  width: 100%; min-height: 28px; max-height: 40vh; resize: none; border: 0; outline: 0; background: transparent;
  padding: var(--space-1) var(--space-2); font-size: 16px; line-height: 1.7;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; gap: var(--space-2); }
.hint { flex: 1; }
.send-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--accent-strong); color: var(--on-accent); transition: opacity var(--fast), transform var(--fast);
}
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.send-btn:not(:disabled):active { transform: scale(.94); }
.send-btn.stop { background: var(--text); color: var(--bg); }
.attachments { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.thumb { position: relative; width: 64px; height: 64px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; inset-block-start: 2px; inset-inline-end: 2px; width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .65); color: #fff; }
.thumb svg { width: 14px; height: 14px; }
.disclaimer { margin: var(--space-2) 0 0; text-align: center; }

.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .5); }
.toast {
  position: fixed; inset-inline: 0; bottom: 96px; margin: 0 auto; width: max-content; max-width: calc(100% - 32px); z-index: 50;
  padding: var(--space-2) var(--space-4); border-radius: 99px; background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
  animation: rise var(--normal) var(--ease);
}

.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; z-index: 30; inset-block: 0; inset-inline-start: 0; width: min(86vw, var(--sidebar));
    transform: translateX(100%); transition: transform var(--normal) var(--ease); box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .hint { visibility: hidden; }
  .topbar { padding: 0 var(--space-2); }
  .msg.user .bubble { max-width: 92%; }
}

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

/* ===== Code look & motion (shared by the landing page and the chat app) ===== */
@property --spin { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes mark-spin { to { --spin: 360deg; } }
@keyframes grid-drift { to { background-position: 0 48px, 48px 0; } }
@keyframes scan { from { transform: translateY(-100%); } to { transform: translateY(100vh); } }
@keyframes glitch {
  0%, 92%, 100% { transform: none; text-shadow: none; }
  93% { transform: translateX(-2px); text-shadow: 2px 0 var(--accent-2), -2px 0 var(--accent-3); }
  95% { transform: translateX(2px); text-shadow: -2px 0 var(--accent-2), 2px 0 var(--accent-3); }
  97% { transform: none; text-shadow: 1px 0 var(--accent); }
}
@keyframes border-flow { to { background-position: 200% 0; } }

body {
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 48px 48px;
  background-attachment: fixed;
}
.mono, code, kbd { font-family: var(--mono); }
.prompt { font-family: var(--mono); color: var(--accent); direction: ltr; unicode-bidi: isolate; }
.glitch { animation: glitch 6s infinite; }
.gradient-text {
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3), var(--accent));
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: border-flow 6s linear infinite;
}
.caret::after { content: "▋"; margin-inline-start: 2px; color: var(--accent); animation: blink 1s steps(2) infinite; }
.tag { font: 600 12px/1 var(--mono); color: var(--accent); letter-spacing: .04em; direction: ltr; unicode-bidi: isolate; }

/* Scroll reveal: elements start hidden only when JS is running (html.js) and motion is allowed. */
html.js .reveal { opacity: 0; transform: translateY(18px); transition: opacity .6s var(--ease), transform .6s var(--ease); transition-delay: var(--d, 0ms); }
html.js .reveal.in { opacity: 1; transform: none; }

/* Animated gradient border used on focused/featured surfaces */
.flow-border { position: relative; }
.flow-border::before {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3), var(--accent)); background-size: 200% 100%;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
  animation: border-flow 4s linear infinite; opacity: 0; transition: opacity var(--normal);
}
.flow-border:focus-within::before, .flow-border.on::before { opacity: 1; }

/* Chat app touches */
.btn-primary { box-shadow: var(--glow); }
.btn-primary:hover { filter: brightness(1.05); box-shadow: 0 0 0 1px var(--accent), 0 0 32px rgba(61, 255, 160, .3); }
.sidebar { background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); }
.topbar { background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(10px); }
.chat-title::before { content: "~/chat $ "; font-family: var(--mono); color: var(--accent); font-size: 13px; direction: ltr; unicode-bidi: isolate; }
.conv a::before { content: ">"; font-family: var(--mono); color: var(--accent); margin-inline-end: 8px; opacity: 0; transition: opacity var(--fast); }
.conv:hover a::before, .conv.active a::before { opacity: 1; }
.conv.active { box-shadow: inset -2px 0 0 var(--accent); }
.composer { border-radius: var(--radius); }
.composer:focus-within { border-color: transparent; box-shadow: var(--shadow); }
.composer textarea { caret-color: var(--accent); }
.send-btn { box-shadow: var(--glow); }
.msg.assistant .who, .msg.user .who { font: 600 12px/1 var(--mono); color: var(--muted); direction: ltr; unicode-bidi: isolate; }
.msg.assistant .who b { color: var(--accent); font-weight: 600; }
.msg.user .bubble { border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border)); }
.codeblock { box-shadow: 0 0 0 1px rgba(255, 255, 255, .02), var(--shadow); }
.codeblock-head::before { content: ""; width: 42px; height: 10px; margin-inline-end: auto; order: -1; display: none; }
.dots3 { display: inline-flex; gap: 6px; direction: ltr; }
.dots3 i { width: 10px; height: 10px; border-radius: 50%; background: #ff5f57; }
.dots3 i:nth-child(2) { background: #febc2e; } .dots3 i:nth-child(3) { background: #28c840; }
.guest-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-2) var(--space-3);
  max-width: var(--content); margin: 0 auto var(--space-2); font-size: 13px; color: var(--muted);
}
.guest-bar a, .guest-bar button.link { color: var(--accent); background: none; border: 0; padding: 0; font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; min-height: 0; }
.login-modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--space-4); background: rgba(0, 0, 0, .6); backdrop-filter: blur(6px); }
.login-modal .login-card { position: relative; animation: rise var(--normal) var(--ease); }
.login-modal .close-modal { position: absolute; inset-block-start: 10px; inset-inline-end: 10px; }
.top-link { font-size: 13px; color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: var(--radius-sm); }
.top-link:hover { color: var(--text); background: var(--surface-3); }
.brand-link { color: inherit; text-decoration: none; }
.md .al-center { text-align: center; } .md .al-left { text-align: left; }
.conv-list { overflow-x: hidden; }
.msg.assistant .who { justify-self: start; }
.msg.user .who { justify-self: end; }
.conv-list ul { grid-template-columns: minmax(0, 1fr); }

/* ===== Custom cursor (fx.js), only with a mouse ===== */
html.has-cursor, html.has-cursor * { cursor: none !important; }
.cursor-dot, .cursor-ring { position: fixed; top: 0; left: 0; z-index: 1000; pointer-events: none; transition: opacity var(--normal); }
.cursor-dot { width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.cursor-ring {
  width: 38px; height: 38px; margin: -19px 0 0 -19px; display: grid; place-items: center;
  border: 1.5px solid color-mix(in srgb, var(--accent) 65%, transparent); border-radius: 50%;
  transition: width .25s var(--ease), height .25s var(--ease), margin .25s var(--ease), background .25s, border-radius .25s, border-color .25s, scale .15s, opacity var(--normal);
}
.cursor-ring span { font: 800 10px/1 var(--mono); color: var(--on-accent); opacity: 0; transition: opacity .2s; }
.cursor-ring.is-hover { width: 64px; height: 64px; margin: -32px 0 0 -32px; border-color: var(--accent); background: rgba(61, 255, 160, .1); backdrop-filter: blur(1px); }
.cursor-ring.has-label { width: 74px; height: 74px; margin: -37px 0 0 -37px; background: var(--accent); border-color: var(--accent); }
.cursor-ring.has-label span { opacity: 1; }
.cursor-ring.is-text { width: 3px; height: 26px; margin: -13px 0 0 -1.5px; border-radius: 2px; border-color: transparent; background: var(--accent); }
.cursor-ring.is-down { scale: .82; }
html.cursor-out .cursor-dot, html.cursor-out .cursor-ring { opacity: 0; }
.cursor-glyph { position: fixed; z-index: 998; pointer-events: none; translate: -50% -50%; font: 12px var(--mono); color: var(--accent); text-shadow: 0 0 8px var(--accent); animation: glyph-fade .7s var(--ease) forwards; }
@keyframes glyph-fade { to { opacity: 0; transform: translateY(20px) scale(.5); } }

/* Click ripple (fx.js) */
.btn, .send-btn, .suggestion { position: relative; overflow: hidden; }
.ripple { position: absolute; border-radius: 50%; background: currentColor; opacity: .28; transform: scale(0); pointer-events: none; animation: ripple .65s ease-out forwards; }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

/* Chat empty state: living orb */
.ai-orb { position: relative; width: 92px; height: 92px; display: grid; place-items: center; }
.ai-orb i { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(from var(--spin, 0deg), var(--accent), var(--accent-2), var(--accent-3), var(--accent)); animation: mark-spin 4s linear infinite; filter: blur(14px); opacity: .7; }
.ai-orb i + i { inset: 10px; filter: none; opacity: 1; -webkit-mask: radial-gradient(circle, transparent 54%, #000 56%); mask: radial-gradient(circle, transparent 54%, #000 56%); animation-duration: 2.6s; animation-direction: reverse; }
.ai-orb b { position: relative; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 30px var(--accent), 0 0 60px var(--accent); animation: core 2.4s ease-in-out infinite; }
@keyframes core { 50% { transform: scale(.7); opacity: .7; } }
.empty h3 { font-size: clamp(24px, 4vw, 36px); font-weight: 900; }
.empty .tag { margin: 0; }
.suggestion { animation: rise .5s var(--ease) both; }
.suggestion:nth-child(2) { animation-delay: .06s; } .suggestion:nth-child(3) { animation-delay: .12s; } .suggestion:nth-child(4) { animation-delay: .18s; }
.suggestion::after { content: "←"; position: absolute; inset-inline-end: 14px; top: 50%; translate: 0 -50%; font-family: var(--mono); color: var(--accent); opacity: 0; transition: opacity var(--fast), transform var(--normal) var(--ease); }
.suggestion:hover::after { opacity: 1; transform: translateX(-4px); }
.suggestion:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: 0 0 0 1px rgba(61, 255, 160, .08), var(--shadow); }
.msg { animation: msg-in .45s var(--ease) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(10px); filter: blur(4px); } }
.conv { transition: background var(--fast), transform var(--fast); }
.conv:hover { transform: translateX(-3px); }
.msg-meta { color: var(--accent); opacity: .8; font-family: var(--mono); }

/* ===== Account button + settings panel ===== */
.account-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-2); padding: 4px; margin: -4px; border: 0; border-radius: 12px; background: none; text-align: start; transition: background var(--fast); }
.account-btn:not(:disabled):hover { background: var(--surface-3); }
.account-btn:disabled { cursor: default; }
.account-btn .account-text { display: grid; }
.settings-card { position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; display: grid; gap: var(--space-4); align-content: start;
  padding: var(--space-5); border: 1px solid var(--border); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow), 0 40px 120px rgba(61, 255, 160, .06); animation: rise .3s var(--ease); }
.set-head { display: flex; align-items: center; gap: var(--space-3); padding-inline-end: 40px; }
.set-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.set-head p { margin: 0; }
.avatar.big { width: 52px; height: 52px; font-size: 22px; background: conic-gradient(from var(--spin, 0deg), var(--accent), var(--accent-2), var(--accent-3), var(--accent)); color: var(--on-accent); animation: mark-spin 6s linear infinite; }
.set-tabs { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); overflow-x: auto; }
.set-tabs button { flex: 1; min-height: 38px; padding: 0 12px; border: 0; border-radius: 10px; background: none; color: var(--muted); font-weight: 700; font-size: 14px; white-space: nowrap; transition: background var(--fast), color var(--fast); }
.set-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.set-panel { display: grid; gap: var(--space-4); animation: rise .3s var(--ease); }
.set-form { display: grid; gap: var(--space-3); }
.set-form .field input { min-height: 46px; padding: 0 var(--space-3); border-radius: 12px; background: var(--bg); border: 1px solid var(--border); font-size: 16px; }
.set-form .field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.set-form .btn { justify-self: start; }
.set-form p { margin: 0; }
.plan-card { display: grid; gap: 8px; padding: var(--space-4); border-radius: 18px; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  background: radial-gradient(400px circle at 100% 0%, rgba(61, 255, 160, .12), transparent 60%), var(--surface-2); }
.plan-top { display: flex; align-items: center; justify-content: space-between; }
.plan-name { font: 800 20px var(--mono); }
.plan-meter { display: flex; justify-content: space-between; font-size: 13px; margin-top: 4px; }
.plan-card p { margin: 4px 0 0; }
.meter .grow { width: 0; animation: grow-w 1s var(--ease) forwards; }
@keyframes grow-w { to { width: var(--w); } }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4); border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); border-radius: 16px; }
.danger-zone p { margin: 2px 0 0; }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger-soft:hover { background: var(--danger); color: #fff; }
.upsell { display: grid; gap: var(--space-2); justify-items: center; text-align: center; padding: var(--space-5) var(--space-3); border-radius: 18px; background: var(--surface-2); }
.upsell h3, .upsell p { margin: 0; }
.ai-orb.small { width: 64px; height: 64px; }
.ai-orb.small b { width: 18px; height: 18px; }
.api-guide { display: grid; gap: var(--space-2); padding: var(--space-4); border-radius: 18px; background: var(--surface-2); }
.api-guide h3, .keys-head h3 { margin: 0; font-size: 16px; }
.api-guide ol { margin: 0; padding-inline-start: 20px; display: grid; gap: 4px; font-size: 14px; }
.api-guide p { margin: 0; }
.kv { display: grid; grid-template-columns: 80px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--code-bg); font-size: 13px; }
.kv span { color: var(--muted); }
.kv code { color: var(--accent); overflow-wrap: anywhere; }
.keys-head { display: flex; align-items: center; justify-content: space-between; }
.keys-head .btn { min-height: 38px; }
.keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.keys li { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 12px; font-size: 14px; animation: rise .3s var(--ease) both; }
.new-key { display: grid; gap: 8px; padding: var(--space-3); border-radius: 14px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.new-key p { margin: 0; font-size: 14px; }
.guest-bar .link + .link { margin-inline-start: 4px; }
@media (max-width: 520px) {
  .keys li { grid-template-columns: 1fr auto; }
  .keys li > span:nth-child(2), .keys li > span:nth-child(3) { grid-column: 1; }
  .danger-zone { flex-direction: column; align-items: stretch; }
}
