:root {
  --bg: #090d16;
  --bg-elevated: #0f1520;
  --bg-composer: rgba(18, 24, 38, 0.92);
  --bg-msg-user: linear-gradient(145deg, #1a2740 0%, #152033 100%);
  --bg-msg-ai: rgba(15, 21, 32, 0.55);
  --bg-sidebar: rgba(8, 11, 18, 0.96);
  --ink: #f8fafc;
  --muted: #94a3b8;
  --faint: #64748b;
  --line: rgba(248, 250, 252, 0.09);
  --line-strong: rgba(248, 250, 252, 0.16);
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --accent-glow: rgba(56, 189, 248, 0.35);
  --violet: #a855f7;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 0 1px rgba(56, 189, 248, 0.28), 0 0 40px rgba(56, 189, 248, 0.12), 0 20px 60px rgba(0, 0, 0, 0.4);
  --font-display: "Syne", "Plus Jakarta Sans", system-ui, sans-serif;
  --font-body: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sidebar-w: 280px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

::selection {
  background: rgba(56, 189, 248, 0.35);
  color: #fff;
}

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

.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: var(--accent);
  color: #041018;
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus { top: 0.75rem; }

[hidden] { display: none !important; }

/* Ambient background */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(1000px 560px at 10% -10%, rgba(56, 189, 248, 0.18), transparent 55%),
    radial-gradient(800px 480px at 95% 5%, rgba(168, 85, 247, 0.12), transparent 50%),
    radial-gradient(600px 400px at 50% 110%, rgba(14, 165, 233, 0.08), transparent 55%),
    linear-gradient(180deg, #0b101a 0%, var(--bg) 40%, #070a12 100%);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: drift 18s var(--ease) infinite alternate;
}
.orb-a {
  width: 380px; height: 380px;
  top: -8%; left: -6%;
  background: rgba(56, 189, 248, 0.22);
}
.orb-b {
  width: 320px; height: 320px;
  top: 8%; right: -8%;
  background: rgba(168, 85, 247, 0.16);
  animation-delay: -6s;
  animation-duration: 22s;
}
.orb-c {
  width: 280px; height: 280px;
  bottom: 5%; left: 35%;
  background: rgba(14, 165, 233, 0.1);
  animation-delay: -12s;
  animation-duration: 26s;
}
.grain {
  position: absolute;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(30px, 40px) scale(1.08); }
}

/* Shell + sidebar */
.shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(var(--sidebar-w), 88vw);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem 0.75rem;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35);
  transform: translateX(-105%);
  transition: transform 0.28s var(--ease);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
}
.shell.sidebar-open .sidebar { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(2, 6, 14, 0.55);
  backdrop-filter: blur(2px);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.15rem 0.35rem 0.35rem;
}
.sidebar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-display);
  font-weight: 750;
  font-size: 0.92rem;
  letter-spacing: -0.02em;
}
.brand-mark.sm {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.35rem;
}

.sidebar-new {
  width: 100%;
  justify-content: flex-start;
  background: var(--accent-soft);
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: var(--ink);
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font: 650 0.84rem/1 var(--font-body);
}
.sidebar-new:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.45);
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.15rem;
  min-height: 0;
  overscroll-behavior: contain;
}

.thread-empty {
  padding: 1rem 0.75rem;
  color: var(--faint);
  font-size: 0.78rem;
  line-height: 1.45;
}

.thread-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  gap: 0.15rem;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.thread-item:hover {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--line);
}
.thread-item.active {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.28);
}

.thread-open {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  width: 100%;
  padding: 0.65rem 0.7rem;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
  font: inherit;
  min-width: 0;
}
.thread-open:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.thread-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.thread-meta {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.thread-del {
  align-self: center;
  width: 1.7rem;
  height: 1.7rem;
  margin-right: 0.25rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.thread-item:hover .thread-del,
.thread-item:focus-within .thread-del { opacity: 1; }
.thread-del:hover {
  color: var(--err);
  background: rgba(248, 113, 113, 0.12);
}

.sidebar-foot {
  padding: 0.45rem 0.55rem 0.2rem;
  border-top: 1px solid var(--line);
}
.sidebar-foot p {
  margin: 0;
  font-size: 0.68rem;
  color: var(--faint);
  line-height: 1.4;
}

.app {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.8rem clamp(0.85rem, 3vw, 1.75rem);
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 22, 0.72);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
}

.btn-menu {
  flex-shrink: 0;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(15, 21, 32, 0.6);
  color: var(--muted);
}
.btn-menu:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.08rem;
  letter-spacing: -0.02em;
  transition: opacity 0.2s var(--ease);
}
.brand:hover { opacity: 0.85; }
.brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 0.45rem;
  color: #041018;
  background: linear-gradient(135deg, var(--accent) 0%, var(--violet) 100%);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.4), 0 4px 14px rgba(56, 189, 248, 0.25);
}

.topnav {
  display: none;
  gap: 1.15rem;
  margin-left: 0.35rem;
}
.topnav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  transition: color 0.15s ease;
}
.topnav a:hover { color: var(--ink); }
.topnav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 4px;
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 21, 32, 0.85);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
  white-space: nowrap;
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color 0.2s ease, color 0.2s ease;
}
.status-pill::before {
  content: "";
  flex-shrink: 0;
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 0 transparent;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.status-pill.ok::before {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.55);
}
.status-pill.warn::before { background: var(--warn); }
.status-pill.err::before { background: var(--err); box-shadow: 0 0 8px rgba(248, 113, 113, 0.45); }

.export-wrap { position: relative; }
.export-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 30;
  min-width: 11.5rem;
  padding: 0.35rem;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(12, 17, 28, 0.98);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.export-menu button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  font: 600 0.8rem/1.2 var(--font-body);
  cursor: pointer;
}
.export-menu button:hover {
  background: var(--accent-soft);
  color: #e0f2fe;
}

/* Main */
.main {
  flex: 1;
  width: min(760px, calc(100% - 1.5rem));
  margin-inline: auto;
  padding: 1.25rem 0 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Landing */
.landing {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1rem, 4vh, 2.5rem) 0 1.5rem;
  animation: fadeUp 0.55s var(--ease) both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.hero { max-width: 40rem; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.85rem;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.eyebrow-dot {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

.landing h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.15rem, 6.5vw, 3.5rem);
  font-weight: 800;
  letter-spacing: -0.038em;
  line-height: 1.06;
}
.hero-accent {
  background: linear-gradient(105deg, var(--ink) 20%, var(--accent) 55%, var(--violet) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  max-width: 34rem;
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: clamp(0.98rem, 2.2vw, 1.08rem);
  line-height: 1.6;
}

/* Composer */
.composer {
  margin-top: 1.85rem;
  background: var(--bg-composer);
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: var(--shadow);
  padding: 0.9rem 0.95rem 0.8rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease), transform 0.25s var(--ease);
}
.composer:focus-within {
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: var(--shadow-glow);
}
.landing-composer:hover:not(:focus-within) {
  border-color: rgba(248, 250, 252, 0.22);
}

.composer textarea {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: 500 1.05rem/1.5 var(--font-body);
  min-height: 3.2rem;
  max-height: 220px;
  overflow-y: auto;
  field-sizing: content;
}
.landing-composer textarea { min-height: 4.6rem; }
.composer textarea::placeholder { color: var(--faint); }
.composer textarea:disabled { opacity: 0.7; }

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-top: 0.5rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}

.composer-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1;
}

.model-picker select,
.model-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  font: 600 0.74rem/1.15 var(--font-body);
  letter-spacing: -0.01em;
  max-width: min(52vw, 280px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.model-picker select {
  cursor: pointer;
  padding-right: 1.65rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    linear-gradient(var(--bg-elevated), var(--bg-elevated));
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%, 0 0;
  background-size: 5px 5px, 5px 5px, auto;
  background-repeat: no-repeat;
}
.model-picker select:hover,
.model-picker select:focus-visible {
  border-color: rgba(56, 189, 248, 0.4);
  outline: none;
}
.model-picker select:disabled { opacity: 0.5; cursor: not-allowed; }

.model-chip {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-family: var(--font-body);
}

.kbd-hint {
  display: none;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 500;
  white-space: nowrap;
}
.kbd-hint kbd {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  font: 500 0.62rem/1.3 var(--font-mono);
  color: var(--muted);
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1.05rem;
  font: 700 0.86rem/1 var(--font-body);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.15s var(--ease), filter 0.15s ease;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn.send {
  width: 2.55rem;
  height: 2.55rem;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #041018;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.35);
}
.btn.send:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.btn.send:active:not(:disabled) { transform: translateY(0); }
.btn.send.busy {
  background: #1e293b;
  color: var(--ink);
  border-color: var(--line-strong);
  box-shadow: none;
}
.btn.send.busy:hover:not(:disabled) {
  background: #243044;
  filter: none;
}
.btn.send svg[hidden] { display: none !important; }
.btn.send .icon-send,
.btn.send .icon-stop {
  display: block;
  pointer-events: none;
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
}
.btn.ghost:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
}
.btn-new svg, .btn-export svg { flex-shrink: 0; }

.btn.icon-sm {
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  border-color: transparent;
  color: var(--faint);
}
.btn.icon-sm:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

/* Suggestions */
.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 1.15rem;
}

.chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  border: 1px solid var(--line);
  background: rgba(15, 21, 32, 0.55);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), transform 0.2s var(--ease);
}
.chip:hover {
  border-color: rgba(56, 189, 248, 0.4);
  background: var(--accent-soft);
  transform: translateY(-1px);
}
.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chip-title {
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.3;
  color: var(--ink);
}
.chip-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--faint);
  line-height: 1.35;
}

.pillars {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1.25rem;
  margin: 1.85rem 0 0;
  padding: 0;
  color: var(--faint);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.pillar-icon {
  color: var(--accent);
  opacity: 0.75;
  margin-right: 0.15rem;
}

/* Chat */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  animation: fadeUp 0.35s var(--ease) both;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.15rem 0 0.75rem;
  min-width: 0;
}
.chat-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.chat-toolbar .model-chip {
  flex-shrink: 0;
  max-width: min(42vw, 200px);
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  padding: 0.15rem 0 1.25rem;
  overflow-y: auto;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.msg {
  display: grid;
  gap: 0.4rem;
  max-width: 100%;
  animation: msgIn 0.3s var(--ease) both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.4rem;
}

.msg-role {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}
.msg.user .msg-role { color: var(--accent); }

.msg-model {
  font: 600 0.65rem/1.1 var(--font-body);
  color: var(--faint);
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 21, 32, 0.6);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-actions {
  margin-left: auto;
  display: flex;
  gap: 0.15rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions { opacity: 1; }

.msg-body {
  padding: 0.95rem 1.05rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-msg-user);
  word-break: break-word;
  line-height: 1.6;
  font-size: 0.97rem;
  position: relative;
}
.msg.user .msg-body { white-space: pre-wrap; }
.msg.assistant .msg-body {
  background: var(--bg-msg-ai);
  border-color: var(--line);
}

.msg.error .msg-body {
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
  background: rgba(248, 113, 113, 0.08);
}

.msg.pending .msg-body::after {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--accent);
  border-radius: 1px;
  animation: blink 1s steps(1) infinite;
  box-shadow: 0 0 8px var(--accent-glow);
}
@keyframes blink { 50% { opacity: 0; } }

/* Markdown prose */
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0.55em 0; }
.prose h1, .prose h2, .prose h3 {
  font-family: var(--font-display);
  font-weight: 750;
  letter-spacing: -0.02em;
  margin: 1em 0 0.4em;
  line-height: 1.25;
}
.prose h1 { font-size: 1.35rem; }
.prose h2 { font-size: 1.18rem; }
.prose h3 { font-size: 1.05rem; }
.prose ul, .prose ol {
  margin: 0.5em 0;
  padding-left: 1.35em;
}
.prose li { margin: 0.25em 0; }
.prose li::marker { color: var(--accent); }
.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.prose a:hover { color: #7dd3fc; }
.prose strong { font-weight: 700; color: #fff; }
.prose em { font-style: italic; }
.prose blockquote {
  margin: 0.7em 0;
  padding: 0.35em 0 0.35em 0.9em;
  border-left: 3px solid rgba(56, 189, 248, 0.45);
  color: var(--muted);
}
.prose hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1em 0;
}
.prose code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: rgba(56, 189, 248, 0.1);
  color: #bae6fd;
  padding: 0.12em 0.4em;
  border-radius: 5px;
  border: 1px solid rgba(56, 189, 248, 0.15);
}
.prose pre {
  margin: 0;
  padding: 0;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  border: 0;
  background: transparent;
  overflow: hidden;
}
.prose pre code {
  display: block;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  background: transparent;
  border: 0;
  color: #e2e8f0;
  font-size: 0.82rem;
  line-height: 1.55;
  border-radius: 0;
}

.code-block {
  position: relative;
  margin: 0.75em 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #0a0e16;
  overflow: hidden;
}
.code-block-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}
.code-lang {
  font: 600 0.65rem/1 var(--font-mono);
  color: #7dd3fc;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.code-copy {
  font: 600 0.68rem/1 var(--font-body);
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.28rem 0.5rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.code-copy:hover {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
}
.code-copy.copied { color: var(--ok); }

/* Lean highlight tokens */
.tok-kw { color: #c4b5fd; font-weight: 500; }
.tok-str { color: #86efac; }
.tok-cmt { color: #64748b; font-style: italic; }
.tok-num { color: #fcd34d; }

.chat-composer {
  position: sticky;
  bottom: calc(0.5rem + var(--safe-bottom));
  margin-top: auto;
  z-index: 5;
}
.chat-composer textarea { min-height: 2.6rem; }

.site-footer {
  width: min(760px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 0.35rem 0 calc(1.25rem + var(--safe-bottom));
  color: var(--faint);
  font-size: 0.75rem;
  text-align: center;
}
.site-footer p { margin: 0; }

.app[data-view="chat"] .site-footer { display: none; }

.msg.thinking-label .msg-body {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(1.25rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(12, 17, 28, 0.96);
  color: var(--ink);
  font: 650 0.8rem/1.2 var(--font-body);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.app[data-view="landing"] .main { justify-content: center; }
.app[data-view="landing"] .landing { max-width: 100%; }

/* Desktop: persistent sidebar rail */
@media (min-width: 1100px) {
  .sidebar {
    position: sticky;
    transform: none;
    height: 100dvh;
    flex-shrink: 0;
    box-shadow: none;
  }
  .shell.sidebar-open .sidebar,
  .shell .sidebar { transform: none; }
  .sidebar-backdrop { display: none !important; }
  #btn-sidebar-close { display: none; }
  .btn-menu { display: none; }
  .shell {
    /* keep sidebar always visible on wide screens */
  }
  .sidebar {
    /* always shown */
    transform: none !important;
  }
}

@media (min-width: 800px) {
  .topnav { display: flex; }
  .kbd-hint { display: inline; }
}

@media (max-width: 640px) {
  .suggestions { grid-template-columns: 1fr; }
  .landing h1 { font-size: 2.05rem; }
  .status-pill { max-width: 28vw; font-size: 0.62rem; }
  .msg-actions { opacity: 1; }
  .kbd-hint { display: none; }
  .main { width: min(100%, calc(100% - 1rem)); }
  .composer { padding: 0.8rem 0.8rem 0.7rem; }
  .chip { padding: 0.7rem 0.8rem; }
  .btn-export span, .btn-new { font-size: 0.75rem; }
  .thread-del { opacity: 1; }
}

@media (max-width: 420px) {
  .topnav { display: none; }
  .btn-export { padding: 0.45rem 0.65rem; }
  .btn-new { padding: 0.45rem 0.65rem; }
  .brand-name { font-size: 1rem; }
  .status-pill { display: none; }
}

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