:root {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3344;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --accent: #4f8ff7;
  --accent-hover: #3a7de6;
  --accent-glow: rgba(79, 143, 247, 0.15);
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  overflow-x: hidden;
}

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

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
header { padding: 56px 0 0; text-align: center; }

.name {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #f1f2f6 0%, #8b8fa3 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  margin-top: 12px;
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.tagline strong { color: var(--accent); font-weight: 500; }

/* Dashboard strip */
.dashboard {
  margin: 28px auto 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 32px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: border-color .2s, color .2s, background .2s;
}
.stat:hover { border-color: var(--accent); color: var(--text); background: var(--accent-glow); }

.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot.green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.amber { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.dot.red   { background: var(--red);   box-shadow: 0 0 6px var(--red); }

.stat .num {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.dash-note {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: .7;
  margin-top: 8px;
  min-height: 1em;
}

/* Featured */
.featured {
  display: block;
  margin: 28px auto 0;
  max-width: 520px;
  width: 100%;
  padding: 12px 18px;
  background: linear-gradient(135deg, rgba(79,143,247,0.08), rgba(79,143,247,0.03));
  border: 1px solid rgba(79,143,247,0.2);
  border-radius: 12px;
  text-align: center;
  transition: border-color .25s, background .25s;
}
.featured:hover { border-color: var(--accent); background: linear-gradient(135deg, rgba(79,143,247,0.14), rgba(79,143,247,0.06)); }
.featured-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
}
.featured-q { display: block; font-size: 0.92rem; color: var(--text); }

/* FAQ chips */
.faq-section { margin: 24px auto 0; max-width: 720px; }
.faq-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-align: center;
}
.faq-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.faq-chip {
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: color .2s, border-color .2s, background .2s, transform .2s;
}
.faq-chip:hover { color: var(--text); border-color: var(--accent); background: var(--accent-glow); transform: translateY(-1px); }

/* Chat */
.chat-container {
  margin: 28px auto 0;
  max-width: 720px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: min(640px, 70vh);
  min-height: 420px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.chat-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

.ai-indicator {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

.chat-title { font-size: 0.84rem; font-weight: 500; }
.chat-subtitle { font-size: 0.7rem; color: var(--text-muted); }

.reset-btn {
  font-size: 0.72rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  flex-shrink: 0;
}
.reset-btn:hover { color: var(--text); border-color: var(--accent); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.message { display: flex; gap: 10px; max-width: 95%; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.message.ai { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.66rem; font-weight: 600;
  flex-shrink: 0; margin-top: 2px;
}
.message.ai .msg-avatar { background: linear-gradient(135deg, var(--accent), #7c4dff); color: #fff; }
.message.user .msg-avatar { background: var(--surface2); border: 1px solid var(--border); color: var(--text-muted); }

.msg-content {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.65;
  min-width: 0;
  overflow-wrap: anywhere;
}
.message.ai .msg-content { background: var(--surface2); border: 1px solid var(--border); }
.message.user .msg-content { background: var(--accent); color: #fff; }
.message.error .msg-content { border-color: rgba(248,113,113,.4); color: #fca5a5; }

.msg-content p, .msg-content ul, .msg-content ol { margin-bottom: 10px; }
.msg-content > :last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { padding-left: 20px; }
.msg-content li { margin-bottom: 4px; }
.msg-content strong { color: #fff; font-weight: 600; }
.msg-content em { color: #c4c7d4; }
.msg-content code { font-family: var(--mono); font-size: .82em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.msg-content a { color: var(--accent); }

.cursor::after { content: '▍'; color: var(--accent); animation: pulse 1s infinite; margin-left: 1px; }

.typing { display: flex; gap: 4px; padding: 4px 0; align-items: center; }
.typing span { width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%; animation: typingDot 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typingDot { 0%,100% { opacity: .3; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }

.chat-input-area { padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface2); }
.chat-input-wrapper { display: flex; gap: 8px; align-items: center; }
.chat-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 16px; /* prevents iOS zoom */
  font-family: var(--font);
  outline: none;
  transition: border-color .2s;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

.send-btn {
  background: var(--accent);
  border-radius: 10px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .2s, opacity .2s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* About */
.about { margin: 48px auto 0; max-width: 640px; text-align: center; }
.about-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 600; margin-bottom: 12px; }
.about-text { font-size: 0.86rem; color: var(--text-muted); line-height: 1.7; margin-bottom: 10px; }
.about-links { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.about-links a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 14px;
  border: 1px solid rgba(79,143,247,0.3);
  border-radius: 20px;
  transition: background .2s, border-color .2s;
}
.about-links a:hover { background: var(--accent-glow); border-color: var(--accent); }

footer { text-align: center; padding: 36px 0 28px; font-size: 0.72rem; color: var(--text-muted); opacity: .6; }

@media (max-width: 640px) {
  header { padding: 32px 0 0; }
  .name { font-size: 1.9rem; }
  .tagline { font-size: 0.94rem; }
  .stat { padding: 5px 10px; font-size: 0.7rem; }
  .faq-chip { font-size: 0.78rem; padding: 7px 12px; }
  .chat-container { height: 78vh; border-radius: 12px; }
  .chat-messages { padding: 14px; }
  .chat-header { padding: 10px 14px; }
  .chat-subtitle { display: none; }
  .message { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.chat-title-sub { color: var(--text-muted); font-weight: 400; }
.model-tag {
  margin-top: 8px;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: var(--mono);
  opacity: .8;
}

.back-link { font-size: 0.72rem; color: var(--text-muted); text-decoration: none; margin-left: auto; margin-right: 8px; }
.back-link:hover { color: var(--text); }

/* ── App layout (v4): full-viewport chat, input always visible ── */
html, body.app { height: 100%; }
body.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.appbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.appbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.appbar .back-link { margin: 0 4px 0 0; }
.arix-mark { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--accent), #7c4dff); flex-shrink: 0; }
.appbar-title { font-size: .92rem; font-weight: 600; }
.appbar-sub { font-size: .7rem; color: var(--text-muted); }
.chat-main { flex: 1; min-height: 0; display: flex; justify-content: center; }
.chat-main .chat-messages { width: 100%; max-width: 760px; padding: 24px 20px; }
.intro { display: flex; flex-direction: column; gap: 14px; margin-left: 38px; }
.intro.hidden { display: none; }
.intro .featured { margin: 0; max-width: none; text-align: left; }
.intro .faq-grid { justify-content: flex-start; }
.composer { flex-shrink: 0; border-top: 1px solid var(--border); background: var(--surface); padding: 12px 20px 10px; }
.composer .chat-input-wrapper { max-width: 760px; margin: 0 auto; }
.composer-note { max-width: 760px; margin: 8px auto 0; font-size: .68rem; color: var(--text-muted); text-align: center; line-height: 1.5; }
@media (max-width: 640px) {
  .appbar { padding: 8px 12px; }
  .appbar-sub { display: none; }
  .appbar .back-link { display: none; }
  .chat-main .chat-messages { padding: 16px 12px; }
  .intro { margin-left: 0; }
  .composer { padding: 10px 12px 8px; }
  .composer-note { display: none; }
}
header.appbar { text-align: left; padding: 10px 20px; }
@media (max-width: 640px) { header.appbar { padding: 8px 12px; } }

/* ── v5: side panel trace + clearer composer ── */
.workspace { flex: 1; min-height: 0; display: flex; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.composer .chat-input {
  height: 50px; font-size: 16px; padding: 0 16px;
  background: #0b0d12; border: 1.5px solid #4a5270; border-radius: 12px;
  box-shadow: 0 0 0 4px rgba(79,143,247,.06);
}
.composer .chat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(79,143,247,.18); }
.composer .chat-input::placeholder { color: #a3a8bd; }
.composer .send-btn { width: 50px; height: 50px; border-radius: 12px; }
.composer { box-shadow: 0 -8px 24px rgba(0,0,0,.25); }

.trace-panel {
  width: 360px; flex-shrink: 0; border-left: 1px solid var(--border); background: #13161f;
  overflow-y: auto; padding: 18px 18px 24px;
}
.trace-head { display: flex; align-items: center; justify-content: space-between; }
.trace-head h2 { font-size: .95rem; font-weight: 600; }
.trace-close { display: none; font-size: 1.4rem; line-height: 1; color: var(--text-muted); background: none; border: 0; cursor: pointer; }
.trace-sub { font-size: .76rem; color: var(--text-muted); margin: 4px 0 16px; }
.trace-toggle { display: none; }

.pipeline { list-style: none; position: relative; }
.pipeline li { position: relative; display: flex; gap: 12px; padding: 0 0 18px; }
.pipeline li:last-child { padding-bottom: 6px; }
.pipeline li::before {
  content: ''; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px;
  background: var(--border); border-radius: 2px;
}
.pipeline li:last-child::before { display: none; }
.pipeline li.done::before { background: linear-gradient(var(--green), rgba(52,211,153,.35)); }
.pipeline li.done + li.active::before, .pipeline li.flow::before {
  background: linear-gradient(180deg, var(--accent) 0%, transparent 50%, var(--accent) 100%);
  background-size: 100% 200%; animation: flow 1s linear infinite;
}
@keyframes flow { from { background-position: 0 0; } to { background-position: 0 -200%; } }
.node { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); background: var(--bg); flex-shrink: 0; margin-top: 2px; position: relative; z-index: 1; transition: all .25s; }
.pipeline li strong { display: block; font-size: .84rem; font-weight: 600; color: var(--text-muted); transition: color .25s; }
.node-desc { display: block; font-size: .72rem; color: #6f7389; margin-top: 2px; line-height: 1.45; }
.pipeline li.done .node { background: var(--green); border-color: var(--green); }
.pipeline li.done strong, .pipeline li.active strong { color: var(--text); }
.pipeline li.done .node-desc { color: var(--text-muted); }
.pipeline li.active .node { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 0 rgba(79,143,247,.6); animation: ping 1.2s infinite; }
.pipeline li.error .node { background: var(--red); border-color: var(--red); }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(79,143,247,.55); } 100% { box-shadow: 0 0 0 10px rgba(79,143,247,0); } }

.trace-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 6px; }
.trace-stats > div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.ts-num { display: block; font-family: var(--mono); font-size: .9rem; font-weight: 600; color: #fff; }
.ts-label { display: block; font-size: .66rem; color: var(--text-muted); margin-top: 2px; }

.trace-log-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 600; margin: 18px 0 8px; }
.trace-log { list-style: none; font-family: var(--mono); font-size: .7rem; line-height: 1.55; background: #0b0d12; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; max-height: 260px; overflow-y: auto; }
.trace-log li { padding: 3px 0; border-bottom: 1px dashed rgba(46,51,68,.6); animation: fadeIn .25s ease; }
.trace-log li:last-child { border-bottom: 0; }
.trace-log .tl-ms { color: var(--accent); display: inline-block; min-width: 64px; }
.trace-log .tl-err { color: var(--red); }
.trace-log .tl-detail { display: block; color: #8b8fa3; padding-left: 64px; }
.trace-empty { color: #6f7389; }
.trace-note { font-size: .68rem; color: #6f7389; margin-top: 12px; line-height: 1.5; }

.view-trace { margin-left: 8px; font-family: var(--mono); font-size: .68rem; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }

@media (max-width: 1100px) {
  .trace-toggle { display: inline-block; }
  .trace-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); z-index: 30;
    transform: translateX(100%); transition: transform .25s ease; box-shadow: -12px 0 30px rgba(0,0,0,.4);
  }
  body.trace-open .trace-panel { transform: none; }
  .trace-close { display: block; }
}
@media (max-width: 640px) {
  .appbar .trace-toggle { padding: 5px 8px; }
}

/* ── v6: brand, framing, clearer New chat ── */
body.app { background: radial-gradient(1200px 500px at 30% -10%, rgba(91,155,255,.10), transparent 60%), radial-gradient(900px 500px at 100% 110%, rgba(139,92,246,.08), transparent 60%), var(--bg); }
.arix-logo { width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0; display: block; }
.msg-avatar img { width: 28px; height: 28px; border-radius: 8px; display: block; }
.message.ai .msg-avatar { background: none; }
.new-chat-btn {
  display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: #fff;
  background: var(--accent); border: 1px solid var(--accent); border-radius: 9px; padding: 7px 14px; cursor: pointer;
  transition: background .2s;
}
.new-chat-btn:hover { background: var(--accent-hover); }
.new-chat-btn svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 2.5; fill: none; stroke-linecap: round; }
.context-strip { border-bottom: 1px solid var(--border); background: rgba(26,29,39,.6); flex-shrink: 0; }
.context-inner { max-width: 760px; margin: 0 auto; padding: 10px 20px; display: flex; gap: 16px; justify-content: space-between; align-items: center; font-size: .78rem; color: var(--text-muted); }
.context-inner strong { color: var(--text); font-weight: 600; }
.context-links { display: flex; gap: 14px; flex-shrink: 0; }
.context-links a { color: var(--accent); text-decoration: none; }
.context-links a:hover { text-decoration: underline; }
.composer-tools { max-width: 760px; margin: 0 auto 8px; display: flex; justify-content: flex-end; }
.composer-tools[hidden] { display: none; }
.restart-link { background: none; border: 1px solid var(--border); color: var(--text-muted); font-size: .74rem; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.restart-link:hover { color: var(--text); border-color: var(--accent); }
.chat-col { position: relative; }
@media (max-width: 640px) {
  .context-inner { padding: 8px 12px; font-size: .72rem; }
  .context-links { display: none; }
  .new-chat-btn { padding: 6px 10px; }
}

.jd-hint { max-width: 760px; margin: 0 auto 8px; font-size: .8rem; color: var(--text-muted); background: rgba(79,143,247,.08); border: 1px solid rgba(79,143,247,.3); border-radius: 9px; padding: 7px 12px; }
.jd-hint[hidden] { display: none; }
.jd-hint a { color: var(--accent); }

/* ── v8: mobile — site nav row, composer always on screen, distinct featured card ── */
.appnav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.appnav .back-link { margin: 0 6px; }
.composer { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
.intro .featured {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 14px;
  background: transparent; border: 1px dashed rgba(79,143,247,.45); border-radius: 10px; padding: 10px 14px; text-align: left;
}
.intro .featured:hover { background: var(--accent-glow); border-style: solid; border-color: var(--accent); }
.intro .featured .featured-label, .intro .featured .featured-q { grid-column: 1; }
.intro .featured .featured-q { font-size: .88rem; color: var(--text); line-height: 1.45; }
.featured-go { grid-column: 2; grid-row: 1 / span 2; font-size: .78rem; font-weight: 600; color: var(--accent); white-space: nowrap; }
@media (max-width: 640px) {
  .appbar { flex-wrap: wrap; row-gap: 6px; }
  .appbar .chat-title-sub { display: none; }
  .appnav { order: 3; flex-basis: 100%; margin: 0; gap: 18px; padding: 2px 0 0 46px; overflow-x: auto; scrollbar-width: none; }
  .appnav::-webkit-scrollbar { display: none; }
  .appnav .back-link, .appbar .appnav .back-link { display: inline; margin: 0; font-size: .78rem; white-space: nowrap; }
  .intro { margin-left: 38px; }
  .composer { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}

/* v9: keyboard open on a phone: give the space to the conversation */
body.app.kb-open .context-strip, body.app.kb-open .appnav, body.app.kb-open .appbar-sub, body.app.kb-open .jd-hint { display: none; }
body.app.kb-open .composer { padding-bottom: 8px; box-shadow: none; }

/* v12: phones and small tablets: the page scrolls normally; header and message box stick to the visible screen.
   Lets every mobile browser (Safari, Chrome, in-app) handle its own toolbars and keyboard. */
@media (max-width: 900px) {
  html:has(body.app) { height: auto; }
  body.app { height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .appbar { position: sticky; top: 0; z-index: 20; }
  .workspace, .chat-col, .chat-main { min-height: auto; }
  .chat-main .chat-messages { overflow: visible; flex: 1 0 auto; }
  .composer { position: sticky; bottom: 0; z-index: 15; }
  .appbar { opacity: 1; }
}

/* the composer is a <footer>: undo the old page-footer dimming */
.composer { opacity: 1; text-align: left; }
