@font-face {
  font-family: 'Switzer';
  src: url('/fonts/Switzer-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/GeistMono-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #07080a;
  --bg-soft: #0b0d11;
  --surface: #101319;
  --surface-2: #161a23;
  --glass: rgba(13, 15, 20, 0.8);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.15);
  --ink: #f2f3f6;
  --ink-2: #9ba3b2;
  --ink-3: #636b7a;
  --accent: #c5b8ff;
  --accent-ink: #0a0910;
  --accent-soft: rgba(197, 184, 255, 0.12);
  --live: #7de2c4;
  --warn: #f0c27b;
  --danger: #f59c9c;
  --sans: 'Switzer', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --measure: 740px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --scrollbar-thumb: rgba(255, 255, 255, 0.22);
  --scrollbar-track: transparent;
  accent-color: var(--accent);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-width: 320px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.auth-body {
  overflow: auto;
}

::selection {
  background: rgba(197, 184, 255, 0.28);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.mono-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.mono-num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(64% 42% at 50% -10%, rgba(197, 184, 255, 0.065), transparent 72%),
    radial-gradient(40% 35% at 85% 15%, rgba(125, 226, 196, 0.025), transparent 70%);
}

/* Scrollbar theming with baseline fallback */
.scroller,
.scroll-stage,
.drawer-sheet,
.studio-body,
.studio-rail,
.studio-form,
.code-block pre {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

@supports not (scrollbar-color: auto) {
  .scroll-stage,
  .drawer-sheet,
  .studio-body,
  .studio-rail,
  .studio-form,
  .code-block pre {
    scrollbar-width: auto;
  }
  .scroll-stage::-webkit-scrollbar,
  .drawer-sheet::-webkit-scrollbar,
  .studio-body::-webkit-scrollbar,
  .code-block pre::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  .scroll-stage::-webkit-scrollbar-thumb,
  .drawer-sheet::-webkit-scrollbar-thumb,
  .studio-body::-webkit-scrollbar-thumb,
  .code-block pre::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 99px;
  }
  .scroll-stage::-webkit-scrollbar-track,
  .drawer-sheet::-webkit-scrollbar-track,
  .studio-body::-webkit-scrollbar-track,
  .code-block pre::-webkit-scrollbar-track {
    background: transparent;
  }
}

/* Top bar */
.topbar {
  position: relative;
  z-index: 10;
  flex: none;
  height: 56px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(7, 8, 10, 0.72);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.icon-btn:hover {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.persona-pill {
  height: 34px;
  max-width: min(52vw, 310px);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(16, 19, 25, 0.75);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.persona-pill:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.persona-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(197, 184, 255, 0.65);
}

.persona-pill-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.persona-pill-sep {
  color: var(--ink-3);
}

.persona-pill-tone {
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  height: 32px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(16, 19, 25, 0.65);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  transition: border-color 0.16s ease, color 0.16s ease;
}

.status-pill:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
}

.status-pill[data-state="ready"] .status-dot {
  background: var(--live);
  box-shadow: 0 0 8px rgba(125, 226, 196, 0.65);
}

.status-pill[data-state="busy"] .status-dot,
.status-pill[data-state="loading"] .status-dot {
  background: var(--warn);
}

.status-pill[data-state="offline"] .status-dot {
  background: var(--danger);
}

.ghost-btn {
  height: 32px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
  transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}

.ghost-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--surface);
}

/* Status popover */
.status-popover {
  inset: auto;
  top: 62px;
  right: 18px;
  margin: 0;
  width: min(300px, calc(100vw - 24px));
  padding: 15px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(14, 17, 23, 0.94);
  backdrop-filter: blur(22px);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.status-popover:not(:popover-open) {
  display: none;
}

@supports not selector(:popover-open) {
  [popover]:not(.\:popover-open) {
    display: none;
  }
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.status-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin: 0;
}

.status-meta dt {
  font-size: 11px;
  color: var(--ink-3);
}

.status-meta dd {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.popover-note {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-2);
}

/* Main stage */
.chat-stage {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.scroll-stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px 20px 190px;
}

/* Empty state */
.empty-state {
  max-width: var(--measure);
  min-height: calc(100dvh - 280px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 28px;
  padding: 20px 0;
}

.eyebrow {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  color: var(--ink-3);
  margin-bottom: 10px;
}

.empty-title {
  margin: 0;
  font-size: clamp(32px, 5vw, 46px);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1.05;
  background: linear-gradient(180deg, #ffffff 30%, rgba(242, 243, 246, 0.62) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.empty-sub {
  margin: 10px 0 0;
  color: var(--ink-2);
  font-size: 15px;
}

.empty-greeting {
  margin: 14px auto 0;
  max-width: 52ch;
  color: var(--ink);
  font-size: 14px;
  opacity: 0.85;
}

.persona-rail-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.persona-rail {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  max-width: 660px;
}

.rail-pill {
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(16, 19, 25, 0.55);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}

.rail-pill:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.rail-pill[aria-checked="true"] {
  border-color: rgba(197, 184, 255, 0.45);
  background: var(--accent-soft);
  color: var(--ink);
}

.rail-pill-new {
  border-style: dashed;
  color: var(--ink-3);
}

.studio-link {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: 12px;
  padding: 4px 8px;
  transition: color 0.16s ease;
}

.studio-link:hover {
  color: var(--accent);
}

.starter-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 620px;
}

.starter-chip {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(16, 19, 25, 0.4);
  color: var(--ink-2);
  font-size: 12.5px;
  transition: border-color 0.16s ease, color 0.16s ease, background-color 0.16s ease;
}

.starter-chip:hover {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

/* Message stream */
.message-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: var(--measure);
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (prefers-reduced-motion: no-preference) {
  .msg {
    animation: msg-in 0.24s var(--ease-out) both;
  }
  @keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

.msg-user {
  align-items: flex-end;
}

.msg-user .msg-bubble {
  max-width: min(82%, 560px);
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 20px 20px 6px 20px;
  background: linear-gradient(180deg, #161a23 0%, #11141c 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.msg-assistant {
  align-items: stretch;
}

.msg-assistant-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}

.msg-assistant-head .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.8;
}

.msg-body {
  color: #ebedf2;
  font-size: 15px;
  line-height: 1.68;
  overflow-wrap: anywhere;
}

.msg-body.is-streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -0.14em;
  background: var(--accent);
  animation: caret-blink 0.9s steps(2, start) infinite;
}

@keyframes caret-blink {
  50% { opacity: 0; }
}

.thinking-box {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(16, 19, 25, 0.55);
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--ink-2);
}

.thinking-box summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  user-select: none;
}

.thinking-box pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-2);
}

/* Markdown inside assistant prose */
.md-p {
  margin: 0 0 12px;
}

.md-p:last-child {
  margin-bottom: 0;
}

.md-h {
  margin: 18px 0 8px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: #fff;
}

.md-h1 { font-size: 21px; }
.md-h2 { font-size: 18px; }
.md-h3 { font-size: 15.5px; }
.md-h4 { font-size: 14px; color: var(--ink-2); }
.md-h:first-child { margin-top: 0; }

.md-list {
  margin: 0 0 12px;
  padding-left: 20px;
}

.md-list li + li {
  margin-top: 4px;
}

.md-quote {
  margin: 10px 0 12px;
  padding: 2px 0 2px 14px;
  border-left: 2px solid rgba(197, 184, 255, 0.45);
  color: var(--ink-2);
  white-space: pre-wrap;
}

.md-hr {
  margin: 16px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.md-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.inline-code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: #e4ddff;
}

.code-block {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0a0c10;
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.code-lang {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}

.code-copy {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 5px;
}

.code-copy:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.code-copy[data-copied="true"] {
  color: var(--live);
}

.code-block pre {
  margin: 0;
  padding: 13px 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  color: #e6e9f0;
}

.md-table-wrap {
  margin: 12px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.md-table th,
.md-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.md-table th {
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
}

.md-table tr:last-child td {
  border-bottom: 0;
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 22px;
  opacity: 0;
  transition: opacity 0.16s ease;
}

.msg:hover .msg-actions,
.msg:focus-within .msg-actions,
.msg-actions[data-visible="true"] {
  opacity: 1;
}

.msg-action-btn {
  border: 0;
  background: transparent;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--ink-3);
  font-size: 11.5px;
}

.msg-action-btn:hover {
  color: var(--ink);
  background: var(--surface);
}

.msg-telemetry {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}

.msg-error {
  padding: 10px 14px;
  border: 1px solid rgba(245, 156, 156, 0.25);
  border-radius: 12px;
  background: rgba(245, 156, 156, 0.06);
  color: var(--danger);
  font-size: 13.5px;
}

/* Jump to bottom */
.jump-bottom {
  position: absolute;
  left: 50%;
  bottom: 138px;
  transform: translateX(-50%);
  z-index: 6;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: rgba(16, 19, 25, 0.92);
  backdrop-filter: blur(14px);
  color: var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* Composer dock */
.composer-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  padding: 28px 18px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 58%, rgba(7, 8, 10, 0.82) 82%, transparent 100%);
  pointer-events: none;
}

.composer-card {
  pointer-events: auto;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 12px 12px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(135%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.055), 0 24px 60px rgba(0, 0, 0, 0.65);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer-card:focus-within {
  border-color: rgba(197, 184, 255, 0.36);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 24px 64px rgba(0, 0, 0, 0.72), 0 0 0 3px rgba(197, 184, 255, 0.08);
}

.composer-grow > textarea {
  display: block;
  width: 100%;
  height: auto;
  field-sizing: content;
  min-block-size: 1.5lh;
  max-block-size: 9lh;
  resize: none;
  border: 0;
  padding: 2px 4px 6px 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  outline: none;
}

.composer-grow > textarea::placeholder {
  color: var(--ink-3);
}

@supports not (field-sizing: content) {
  .composer-grow {
    display: grid;
  }
  .composer-grow::after,
  .composer-grow > textarea {
    grid-area: 1 / 1 / 2 / 2;
    font: inherit;
    line-height: 1.5;
    padding: 2px 4px 6px 0;
  }
  .composer-grow::after {
    content: attr(data-replicated-value) " ";
    white-space: pre-wrap;
    visibility: hidden;
    max-height: 200px;
    overflow: hidden;
  }
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
}

.composer-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex-wrap: wrap;
}

.micro-pill {
  height: 26px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-2);
  font-size: 11.5px;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.micro-pill:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.micro-toggle[aria-pressed="true"] {
  border-color: rgba(197, 184, 255, 0.42);
  background: var(--accent-soft);
  color: var(--accent);
}

.ctx-meter {
  font-size: 11px;
  color: var(--ink-3);
  padding-left: 2px;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.send-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #08090c;
  transition: opacity 0.16s ease, transform 0.14s ease, background-color 0.16s ease;
}

.send-btn:hover:not(:disabled) {
  background: #ffffff;
  transform: translateY(-1px);
}

.send-btn:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.35);
  cursor: default;
}

.stop-btn {
  background: rgba(255, 255, 255, 0.14);
  color: var(--ink);
}

.stop-btn:hover {
  background: rgba(245, 156, 156, 0.24);
  color: var(--danger);
}

/* Modal dialog scroll containment */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

/* Threads drawer (scroll-snap native drawer) */
.drawer {
  --drawer-width: min(310px, 82dvw, calc(100dvw - 24px));
  --drawer-backdrop: 0;
  inset: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  color: var(--ink);
}

.drawer::backdrop {
  background: #000;
  opacity: calc(var(--drawer-backdrop) * 0.68);
}

.drawer-scroller {
  position: relative;
  display: grid;
  grid-template-columns: var(--drawer-width) 100%;
  overflow-x: scroll;
  overscroll-behavior: none;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}

@media (prefers-reduced-motion: no-preference) {
  .drawer-scroller {
    scroll-behavior: smooth;
  }
}

.drawer-scroller::after {
  content: '';
  scroll-snap-align: end;
  scroll-initial-target: nearest;
}

.drawer-sheet {
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 12px;
  background: rgba(11, 13, 18, 0.96);
  backdrop-filter: blur(22px);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  scroll-snap-align: start;
}

@supports (animation-timeline: scroll()) {
  .drawer {
    timeline-scope: --drawer-fade;
    animation: fade-drawer-backdrop linear both;
    animation-timeline: --drawer-fade;
  }
  .drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }
  @property --drawer-backdrop {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
  }
  @keyframes fade-drawer-backdrop {
    0% { --drawer-backdrop: 1; }
    100% { --drawer-backdrop: 0; }
  }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 4px;
}

.drawer-tools {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.drawer-search {
  height: 34px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  font-size: 13px;
}

.drawer-search::placeholder {
  color: var(--ink-3);
}

.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.thread-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 10px;
  padding: 3px;
}

.thread-item:hover,
.thread-item[data-active="true"] {
  background: var(--surface);
}

.thread-select {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 7px 8px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-3);
}

.thread-del {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-3);
  display: grid;
  place-items: center;
  opacity: 0;
}

.thread-item:hover .thread-del,
.thread-item:focus-within .thread-del {
  opacity: 1;
}

.thread-del:hover {
  color: var(--danger);
  background: rgba(245, 156, 156, 0.1);
}

.thread-empty {
  padding: 28px 10px;
  text-align: center;
  color: var(--ink-3);
  font-size: 12.5px;
}

.drawer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* Personality Studio modal */
.studio-dialog {
  width: min(860px, calc(100vw - 24px));
  max-height: min(90dvh, 740px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: rgba(12, 14, 19, 0.96);
  backdrop-filter: blur(26px);
  color: var(--ink);
  box-shadow: 0 36px 100px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.studio-dialog::backdrop {
  background: rgba(2, 3, 5, 0.72);
  backdrop-filter: blur(5px);
}

.studio-shell {
  display: flex;
  flex-direction: column;
  max-height: min(90dvh, 740px);
}

.studio-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.studio-title {
  margin: 3px 0 0;
  font-size: 20px;
  font-weight: 550;
  letter-spacing: -0.025em;
}

.studio-body {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.studio-rail {
  border-right: 1px solid var(--line);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  background: rgba(8, 9, 12, 0.45);
}

.studio-new-btn {
  width: 100%;
  justify-content: center;
}

.studio-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.studio-item-btn {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  background: transparent;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.studio-item-btn:hover {
  background: var(--surface);
}

.studio-item-btn[aria-current="true"] {
  background: var(--accent-soft);
  border-color: rgba(197, 184, 255, 0.34);
}

.studio-item-name {
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.studio-item-badge {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--accent);
}

.studio-item-tag {
  font-size: 11.5px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.studio-reset-btn {
  align-self: flex-start;
  padding-top: 6px;
}

.studio-form {
  padding: 16px 20px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span,
.field-caption,
.field-label-row label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.muted-count {
  font-size: 11px;
  color: var(--ink-3);
}

.studio-form input[type="text"],
.studio-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 13.5px;
  transition: border-color 0.15s ease;
}

.studio-form input[type="text"]:focus,
.studio-textarea:focus {
  border-color: rgba(197, 184, 255, 0.45);
  outline: none;
}

.studio-textarea {
  resize: vertical;
  min-height: 92px;
  line-height: 1.55;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-chip {
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 11px;
}

.mini-chip:hover,
.mini-chip[aria-pressed="true"] {
  border-color: rgba(197, 184, 255, 0.4);
  background: var(--accent-soft);
  color: var(--ink);
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  width: fit-content;
}

.segmented button {
  border: 0;
  border-radius: 7px;
  padding: 6px 14px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface-2);
  color: var(--ink);
}

.slider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}

.slider-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slider-field > span {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-2);
}

.slider-field output {
  color: var(--ink);
  font-size: 11.5px;
}

.slider-field input[type="range"] {
  width: 100%;
  margin: 0;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-soft);
  cursor: pointer;
}

.switch-row strong {
  display: block;
  font-size: 13px;
  font-weight: 550;
}

.switch-row small {
  display: block;
  font-size: 11.5px;
  color: var(--ink-3);
}

.switch-row input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.studio-actions {
  position: sticky;
  bottom: -18px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding: 12px 0 18px;
  background: linear-gradient(to top, rgba(12, 14, 19, 0.98) 76%, rgba(12, 14, 19, 0));
  border-top: 1px solid var(--line);
}

.studio-actions-left,
.studio-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.studio-feedback {
  font-size: 12px;
  color: var(--live);
}

.studio-feedback[data-error="true"] {
  color: var(--danger);
}

/* Shared button styles */
.btn-primary {
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #08090c;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.btn-primary:hover {
  background: #ffffff;
}

.btn-subtle {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-subtle:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.btn-subtle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.text-btn {
  border: 0;
  background: transparent;
  padding: 4px 6px;
  color: var(--ink-2);
  font-size: 12px;
}

.text-btn:hover {
  color: var(--ink);
}

.danger-text {
  color: var(--danger);
}

/* Auth page */
.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.auth-card {
  width: min(100%, 380px);
  padding: 28px 26px 26px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: rgba(13, 15, 20, 0.88);
  backdrop-filter: blur(22px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.72), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(197, 184, 255, 0.75);
}

.auth-card h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 550;
  letter-spacing: -0.03em;
}

.auth-sub {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--ink-2);
}

.auth-error {
  margin: 14px 0 0;
  padding: 9px 12px;
  border: 1px solid rgba(245, 156, 156, 0.3);
  border-radius: 10px;
  background: rgba(245, 156, 156, 0.08);
  color: var(--danger);
  font-size: 13px;
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-2);
}

.auth-form input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 15px;
}

.auth-form input:focus {
  border-color: rgba(197, 184, 255, 0.45);
  outline: none;
}

.auth-submit {
  margin-top: 4px;
  height: 40px;
  width: 100%;
}

/* Responsive */
@media (max-width: 720px) {
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .persona-pill {
    max-width: min(44vw, 180px);
    padding: 0 10px;
    gap: 6px;
  }
  .status-pill {
    padding: 0 9px;
    gap: 6px;
  }
  .persona-pill-sep,
  .persona-pill-tone {
    display: none;
  }
  .ghost-btn span {
    display: none;
  }
  .ghost-btn {
    width: 32px;
    padding: 0;
    justify-content: center;
  }
  .scroll-stage {
    padding: 20px 14px 180px;
  }
  .composer-dock {
    padding: 18px 12px max(12px, env(safe-area-inset-bottom));
  }
  .composer-grow > textarea {
    font-size: 16px;
  }
  .studio-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .studio-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 14px;
  }
  .studio-list {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
  }
  .studio-item-btn {
    width: auto;
    min-width: 132px;
  }
  .studio-reset-btn {
    display: none;
  }
  .field-row,
  .slider-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
