:root {
  --rail: #f5f5f5;
  --bg: #fff;
  --bg-mobile: #fcfcfc;
  --border: rgba(0, 0, 0, 0.1);
  --text: #0d0d0d;
  --text-user: #0d0d0d;
  --text-2: #5d5d5d;
  --text-3: #8f8f8f;
  --bubble: rgba(233, 233, 233, 0.5);
  --composer: #fff;
  --composer-ring: 0 0 0 1px rgba(0, 0, 0, 0.1), 0 4px 16px rgba(0, 0, 0, 0.05);
  --primary: #0d0d0d;
  --on-primary: #fff;
  --hover: rgba(0, 0, 0, 0.05);
  --rail-active: rgba(0, 0, 0, 0.06);
  --seg-track: #ececec;
  --seg-on: #fff;
  --seg-on-ring: 0 0 0 0.5px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.08);
  --popover: #fff;
  --popover-ring: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 10px 30px rgba(0, 0, 0, 0.12);
  --round-btn: rgba(243, 243, 243, 0.9);
  --code-bg: #f9f9f9;
  --code-head: #f1f1f1;
  --soft-btn: rgba(0, 0, 0, 0.05);
  --tap: rgba(0, 0, 0, 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --rail: #000;
    --bg: #0e0e0e;
    --bg-mobile: #000;
    --border: rgba(255, 255, 255, 0.15);
    --text: #ededed;
    --text-user: #fff;
    --text-2: #cdcdcd;
    --text-3: #afafaf;
    --bubble: rgba(50, 50, 50, 0.85);
    --composer: #212121;
    --composer-ring: inset 0 0 1px rgba(255, 255, 255, 0.2);
    --primary: #fff;
    --on-primary: #0d0d0d;
    --hover: rgba(255, 255, 255, 0.07);
    --rail-active: #1b1b1b;
    --seg-track: #1b1b1b;
    --seg-on: #212121;
    --seg-on-ring: 0 0 0 0.5px rgba(255, 255, 255, 0.1);
    --popover: #2a2a2a;
    --popover-ring: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 10px 30px rgba(0, 0, 0, 0.45);
    --round-btn: rgba(24, 24, 24, 0.98);
    --code-bg: #171717;
    --code-head: #202020;
    --soft-btn: rgba(255, 255, 255, 0.06);
    --tap: rgba(255, 255, 255, 0.28);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system-body, ui-sans-serif, -apple-system, system-ui, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 16px;
  line-height: 24px;
  color: var(--text);
  background: var(--rail);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 20px; height: 20px; flex: none; display: block; }
[hidden] { display: none !important; }

.app { display: flex; height: 100vh; height: 100dvh; }

/* ---- rail ---------------------------------------------------------------- */
.rail {
  width: 52px;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}
.rail-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.rail-btn:hover { background: var(--hover); color: var(--text); }
.rail-btn.active { background: var(--rail-active); color: var(--text); }
.rail-sep { width: 32px; height: 1px; background: var(--border); margin: -2px 0; }
.rail-fill { flex: 1; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-bottom: 2px;
  background: linear-gradient(135deg, #9a9a9a, #5f5f5f);
}

/* ---- panel: sidebar + main --------------------------------------------- */
.panel {
  flex: 1;
  min-width: 0;
  display: flex;
  background: var(--bg);
  border-left: 0.5px solid var(--border);
  border-radius: 14px 0 0 14px;
  overflow: hidden;
  position: relative;
}

.sidebar {
  width: 288px;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 0 6px;
  border-right: 0.5px solid var(--border);
  overflow-y: auto;
  transition: margin-left 0.22s ease;
}
.app.collapsed .sidebar { margin-left: -288px; }
.side-head {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 10px;
  flex: none;
}
.brand { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; white-space: nowrap; }
.side-head-tools { display: flex; gap: 4px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.side-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  min-height: 36px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 20px;
}
.side-item:hover { background: var(--hover); }
.side-item.current { background: var(--hover); }
.side-item.project span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lizard-mark { width: 22px; height: 22px; margin: -1px; color: #10b981; }
.initial {
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
}
.side-group { margin-top: 12px; }
.side-label {
  padding: 9px 10px;
  font-size: 14px;
  line-height: 18px;
  font-weight: 500;
  color: var(--text-3);
}
.side-empty { padding: 8px 10px; font-size: 14px; line-height: 20px; color: var(--text-3); opacity: 0.5; }
.recents .side-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recents .side-item.fresh { animation: fade-in 0.4s ease; }

.scrim { display: none; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 8px;
  position: relative;
  z-index: 3;
}
.topbar-center {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.mobile-only, .mobile-title { display: none; }
.desktop-collapsed-only { display: none; }
.app.collapsed .desktop-collapsed-only { display: grid; }

.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 112px 112px;
  height: 36px;
  border-radius: 999px;
}
.seg-track { position: absolute; inset: 1px 1px; border-radius: 999px; background: var(--seg-track); }
.seg {
  position: relative;
  z-index: 1;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  color: var(--text-2);
  border-radius: 999px;
}
.seg.on { color: var(--text); background: var(--seg-on); box-shadow: var(--seg-on-ring); }
body.chat .segmented { display: none; }

.pill-top {
  height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  white-space: nowrap;
}
.pill-top:hover { opacity: 0.85; }
.pill-top .short { display: none; }

/* ---- thread ---------------------------------------------------------------- */
.scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.thread {
  width: 100%;
  max-width: calc(768px + 48px);
  margin: 0 auto;
  padding: 0 24px;
}
body.empty .thread { display: none; }
body.chat .hero { display: none; }

.hero {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 24px 22px;
}
.hero h1 {
  margin: 0;
  font-size: 24px;
  line-height: 28.8px;
  font-weight: 400;
  text-align: center;
  text-wrap: balance;
}

.turn { animation: fade-in 0.25s ease; }
.turn.instant, .turn.instant .actions { animation: none; }
.turn.user { display: flex; justify-content: flex-end; padding-top: 32px; }
.turn.user + .turn.assistant { padding-top: 40px; }
.turn.assistant { padding-bottom: 8px; }
.bubble {
  max-width: 70%;
  padding: 10px 16px;
  border-radius: 22px;
  background: var(--bubble);
  color: var(--text-user);
  font-size: 16px;
  line-height: 26px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.md { font-size: 16px; line-height: 26px; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 16px; }
.md ol, .md ul { margin: 0 0 16px; padding-left: 32px; }
.md li { margin: 0; }
.md li > p { margin: 0; }
.md li > ul, .md li > ol { margin: 8px 0 0; }
.md ol > li::marker { font-weight: 600; }
.md strong { font-weight: 600; }
.md a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--text-3); }
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--soft-btn);
}
.md pre {
  margin: 0 0 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--code-bg);
  overflow-x: auto;
}
.md pre code { padding: 0; background: none; }
.md h1, .md h2, .md h3 { font-size: 18px; line-height: 28px; font-weight: 600; margin: 20px 0 8px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.md table { border-collapse: collapse; margin: 0 0 16px; font-size: 14px; }
.md th, .md td { border-bottom: 1px solid var(--border); padding: 6px 12px 6px 0; text-align: left; }

.thinking {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin: 7px 0;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.25s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.75); opacity: 0.55; }
  50% { transform: scale(1); opacity: 1; }
}

.actions { display: flex; gap: 0; margin: 12px 0 0 -6px; animation: fade-in 0.3s ease; }
.act {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-3);
}
.act svg.small { width: 16px; height: 16px; }
.act:hover { background: var(--hover); color: var(--text); }
.act.on { color: var(--text); }

.cta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; animation: fade-in 0.35s ease; }
.btn {
  height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--soft-btn);
  color: var(--text);
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: none; opacity: 0.88; }
.btn svg { width: 18px; height: 18px; }

.linkcard {
  margin-top: 4px;
  border-radius: 16px;
  background: var(--code-bg);
  overflow: hidden;
  animation: fade-in 0.3s ease;
}
.linkcard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 6px 14px;
  background: var(--code-head);
  font-size: 12px;
  line-height: 16px;
  color: var(--text-3);
}
.linkcard-head span { display: inline-flex; align-items: center; gap: 6px; }
.linkcard-head svg { width: 16px; height: 16px; }
.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-3);
}
.mini-btn:hover { background: var(--hover); color: var(--text); }
.linkcard-body {
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  line-height: 22px;
  overflow-wrap: anywhere;
}

/* ---- composer ------------------------------------------------------------- */
.dock {
  flex: none;
  width: 100%;
  max-width: calc(768px + 48px);
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
  z-index: 2;
}
body.chat .dock { padding-bottom: 16px; }
body.meme .composer { display: none; }
.disclaimer {
  min-height: 24px;
  padding: 0 16px 8px;
  text-align: center;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-3);
}
body.empty .chat-only { display: none; }
body.chat .empty-only { display: none; }

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "lead input trail";
  align-items: center;
  column-gap: 4px;
  min-height: 52px;
  padding: 8px;
  border-radius: 26px;
  background: var(--composer);
  box-shadow: var(--composer-ring);
  cursor: text;
}
.composer.multi {
  grid-template-areas: "input input input" "lead . trail";
  row-gap: 4px;
  border-radius: 28px;
  padding: 12px 8px 8px;
}
.composer.multi .c-input { padding: 0 8px; }
.c-plus { grid-area: lead; }
.c-input { grid-area: input; position: relative; min-width: 0; padding: 0 4px; }
.c-trail { grid-area: trail; display: flex; align-items: center; gap: 4px; }
.c-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--text);
}
.c-mic { color: var(--text-3); }
.c-btn:hover { background: var(--hover); }
.c-model {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px 0 12px;
  border-radius: 999px;
  font-size: 16px;
  line-height: 26px;
  color: var(--text-3);
}
.c-model svg { width: 16px; height: 16px; }
.c-model:hover { background: var(--hover); }
.c-send {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: var(--on-primary);
  transition: opacity 0.15s;
}
.c-send svg { grid-area: 1 / 1; }
.c-send .s-up, .c-send .s-stop { display: none; }
.composer.has-text .c-send .s-up { display: block; }
.composer.has-text .c-send .s-wave { display: none; }
.composer.streaming .c-send .s-wave, .composer.streaming .c-send .s-up { display: none; }
.composer.streaming .c-send .s-stop { display: block; }
.c-send:active { transform: scale(0.96); }

#input, .ghost {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 26px;
  max-height: 208px;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#input::placeholder { color: var(--text-3); opacity: 1; }
.ghost { display: none; min-height: 26px; }
body.playback .ghost { display: block; }
body.playback #input { display: none; }
.ghost.placeholder #ghost-text::before { content: attr(data-placeholder); color: var(--text-3); }
.caret {
  display: none;
  width: 1.5px;
  height: 20px;
  margin-left: 1px;
  vertical-align: -4px;
  background: var(--text);
  animation: blink 1.05s steps(1) infinite;
}
.ghost.focused .caret { display: inline-block; }
.ghost.focused.placeholder #ghost-text::before { margin-left: 2px; }
.ghost.focused.placeholder { display: flex; flex-direction: row-reverse; justify-content: flex-end; }
@keyframes blink { 50% { opacity: 0; } }

.below {
  flex: 1.6 1 0;
  min-height: 0;
  padding: 0 24px;
}
body.chat .below { display: none; }
.hint { margin: 18px auto 0; max-width: 520px; text-align: center; color: var(--text-3); font-size: 14px; line-height: 20px; }
.hint:empty { display: none; }
.foot {
  flex: none;
  padding: 0 16px 12px;
  text-align: center;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-3);
}

/* ---- playback overlays --------------------------------------------------- */
.caption {
  position: fixed;
  left: 50%;
  top: 64px;
  z-index: 40;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 16px;
  background: var(--popover);
  box-shadow: var(--popover-ring);
  color: var(--text);
  font-size: 16px;
  line-height: 22px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -6px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}
.caption.show { opacity: 1; transform: translate(-50%, 0); }
.caption.big { font-size: 20px; line-height: 28px; padding: 14px 22px; }

.cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  width: 24px;
  height: 24px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.35));
  will-change: transform;
}
.cursor svg { width: 24px; height: 24px; transform-origin: 5px 3px; transition: transform 0.09s ease; }
.cursor.show { opacity: 1; }
.cursor.press svg { transform: scale(0.86); }

.tap {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: var(--tap);
  pointer-events: none;
  opacity: 0;
}

@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- desktop sidebar desktop > tablet ------------------------------------ */
@media (max-width: 1023px) and (min-width: 768px) {
  .rail { display: none; }
  .panel { border-left: 0; border-radius: 0; }
}

/* ---- mobile ------------------------------------------------------------- */
@media (max-width: 767px) {
  body { background: var(--bg-mobile); }
  .rail { display: none; }
  .panel { border: 0; border-radius: 0; background: var(--bg-mobile); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(320px, 86vw);
    padding: env(safe-area-inset-top) 6px env(safe-area-inset-bottom);
    background: var(--bg);
    border-right: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    margin-left: 0 !important;
  }
  .app.drawer .sidebar { transform: none; }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
  }
  .app.drawer .scrim { opacity: 1; pointer-events: auto; }

  .topbar {
    height: calc(60px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 8px;
  }
  .mobile-only { display: grid; }
  .desktop-collapsed-only, .app.collapsed .desktop-collapsed-only { display: none; }
  .topbar-right { min-width: 44px; justify-content: flex-end; }
  .pill-top .long { display: none; }
  .pill-top .short { display: inline; }
  .round-btn {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    place-items: center;
    background: var(--round-btn);
    box-shadow: 0 0 0 1px var(--border), 0 4px 16px rgba(0, 0, 0, 0.05);
    color: var(--text);
  }
  .topbar-center { position: static; transform: none; min-width: 0; height: 44px; display: flex; align-items: center; justify-content: center; }
  .segmented { display: none; }
  .mobile-title {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
  }
  .pill-top { height: 44px; padding: 0 16px; }

  .thread, .dock { padding: 0 12px; }
  .thread { padding: 0 16px; }
  .turn.user { padding-top: 16px; }
  .bubble { max-width: 85%; }
  .hero h1 { font-size: 24px; line-height: 28px; }
  .composer { min-height: 48px; padding: 2px 4px; border-radius: 28px; column-gap: 0; }
  .composer.multi { padding: 10px 4px 2px; border-radius: 26px; }
  .c-btn, .c-send { width: 44px; height: 44px; }
  .c-send { width: 36px; height: 36px; margin: 4px; }
  .c-model { display: none; }
  .c-input { padding: 0 6px; }
  body.chat .dock { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .disclaimer { font-size: 11px; line-height: 15px; padding-bottom: 6px; }
  .foot { font-size: 11px; line-height: 15px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .caption { top: calc(72px + env(safe-area-inset-top)); font-size: 15px; }
  .caption.big { font-size: 18px; }
  .below { padding: 0 16px; }
}

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