:root {
  --teal-50: #f2faf8;
  --teal-100: #dbe9e7;
  --teal-300: #62aba3;
  --teal-500: #2a827b;
  --teal-600: #136b65;
  --teal-800: #054946;
  --ink: #2c3439;
  --gray-25: #f9fafb;
  --gray-50: #f4f5f7;
  --gray-200: #d9e2e8;
  --gray-600: #5a6872;
  --gold: #f79a3e;
  --gold-50: #fff5eb;
  --red: #c2413b;
  --red-50: #fdf0ef;
  --white: #ffffff;
  --radius: 1rem;
  --radius-sm: 0.625rem;
  --shadow-soft: 0 1px 2px rgba(44, 52, 57, 0.06), 0 4px 16px rgba(44, 52, 57, 0.06);
  --shadow-lift: 0 2px 6px rgba(44, 52, 57, 0.08), 0 12px 32px rgba(44, 52, 57, 0.1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --sidebar: 16.5rem;
  --column: 47rem;
  --font: "Figtree", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.icon { display: inline-flex; width: 1.125rem; height: 1.125rem; flex: none; }
.icon svg { width: 100%; height: 100%; }

.brand { display: flex; align-items: center; gap: 0.625rem; padding: 0.25rem 0.5rem 1rem; }
.brand-mark {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.5rem;
  background: var(--teal-500);
  position: relative;
  flex: none;
  box-shadow: inset 0 -2px 0 rgba(5, 73, 70, 0.35);
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 0.42rem;
  background: var(--white);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}
.brand-mark.large { width: 3rem; height: 3rem; border-radius: 0.875rem; }
.brand-mark.large::after { inset: 0.75rem; }
.brand-name { font-weight: 700; font-size: 1.0625rem; letter-spacing: -0.01em; color: var(--teal-800); }

.app { display: flex; height: 100dvh; overflow: hidden; background: var(--white); }

.sidebar {
  width: var(--sidebar);
  flex: none;
  background: var(--gray-25);
  border-right: 1px solid var(--gray-200);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
  background: var(--white);
  font-weight: 600;
  color: var(--teal-800);
  transition: background 160ms ease, border-color 160ms ease, transform 160ms var(--ease-out), box-shadow 160ms ease;
}
.new-chat:hover { border-color: var(--teal-300); box-shadow: var(--shadow-soft); }
.new-chat:active { transform: scale(0.98); }
.new-chat .icon { color: var(--teal-500); }

.side-list { margin-top: 1.25rem; display: flex; flex-direction: column; gap: 0.125rem; }
.side-label { font-size: 0.75rem; font-weight: 600; color: var(--gray-600); padding: 0 0.75rem 0.375rem; letter-spacing: 0.02em; }
.side-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  color: var(--ink);
  border: 0;
  background: transparent;
  text-align: left;
  width: 100%;
}
#sideChat { background: var(--teal-50); color: var(--teal-800); }
.side-item .icon { color: var(--gray-600); width: 1rem; height: 1rem; }
#sideChat .icon { color: var(--teal-500); }
.side-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-preview { transition: background 160ms ease; animation: rise 320ms var(--ease-out) both; }
.side-preview:hover { background: var(--gray-50); }
.chat-list { display: flex; flex-direction: column; gap: 0.125rem; overflow-y: auto; min-height: 0; margin: 0 -0.25rem; padding: 0 0.25rem; }
.chat-empty { margin: 0; padding: 0.25rem 0.75rem; font-size: 0.8125rem; color: var(--gray-600); }
.chat-item { position: relative; border-radius: var(--radius-sm); animation: rise 280ms var(--ease-out) both; transition: background 160ms ease; }
.chat-item:hover { background: var(--gray-50); }
.chat-item.current { background: var(--teal-50); }
.chat-open { display: flex; align-items: center; gap: 0.625rem; width: 100%; border: 0; background: transparent; padding: 0.5rem 2.25rem 0.5rem 0.75rem; text-align: left; border-radius: var(--radius-sm); }
.chat-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; flex: none; background: var(--gray-200); transition: background 200ms ease; }
.chat-dot.running { background: var(--teal-300); }
.chat-dot.running.busy, .chat-dot.starting { background: var(--teal-500); animation: breathe 1.6s ease-in-out infinite; }
.chat-dot.paused { background: var(--gold); }
.chat-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.chat-title { font-size: 0.875rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.current .chat-title { color: var(--teal-800); font-weight: 600; }
.chat-meta { font-size: 0.75rem; color: var(--gray-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-remove { position: absolute; top: 0.4375rem; right: 0.25rem; width: 1.75rem; height: 1.75rem; opacity: 0; transition: opacity 160ms ease, background 160ms ease; }
.chat-remove .icon { width: 0.9375rem; height: 0.9375rem; }
.chat-item:hover .chat-remove, .chat-remove:focus-visible, .chat-item.current .chat-remove { opacity: 1; }
.chat-confirm { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 240ms var(--ease-in-out); }
.chat-item.confirming .chat-confirm { grid-template-rows: 1fr; }
.chat-confirm > div { min-height: 0; overflow: hidden; }
.chat-confirm p { margin: 0; padding: 0.125rem 0.75rem 0.5rem; font-size: 0.8125rem; color: var(--gray-600); }
.chat-confirm .row { display: flex; gap: 0.375rem; padding: 0 0.75rem 0.625rem; }
.chat-confirm button { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; }
.danger-solid { border: 0; background: var(--red); color: var(--white); border-radius: 999px; font-weight: 600; }
.danger-solid:hover { background: #a63630; }
.side-list { min-height: 0; flex: 1; }
.topbar .menu-toggle { display: none; margin-left: -0.5rem; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(23, 29, 32, 0.32); z-index: 39; animation: fade 200ms ease both; }

.side-foot { margin-top: auto; font-size: 0.8125rem; color: var(--gray-600); padding: 0.75rem; line-height: 1.45; }

.code-chip {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 0.125rem 0.4375rem;
  border-radius: 0.375rem;
  background: var(--teal-100);
  color: var(--teal-800);
  border: 0;
}
.code-chip.copyable { cursor: pointer; transition: background 160ms ease; }
.code-chip.copyable:hover { background: #cde0dd; }

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

.topbar {
  height: 3.5rem;
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem 0 1.25rem;
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease;
}
.app.scrolled .topbar { border-color: var(--gray-200); }
.topbar-brand { display: none; align-items: center; gap: 0.5rem; }
.topbar-brand .brand-mark { width: 1.5rem; height: 1.5rem; }
.topbar-brand .brand-mark::after { inset: 0.36rem; }
.topbar-title { flex: 1; min-width: 0; font-weight: 600; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transform: translateY(-2px); transition: opacity 240ms ease, transform 240ms var(--ease-out); }
.topbar-title.visible { opacity: 1; transform: none; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }

.status-chip { display: inline-flex; align-items: center; gap: 0.375rem; font-size: 0.8125rem; color: var(--gray-600); padding: 0.25rem 0.625rem; border-radius: 999px; background: var(--gray-50); animation: fade 240ms ease both; }
.status-chip .dot { width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: var(--teal-300); }
.status-chip.starting .dot { background: var(--gold); animation: breathe 1.4s ease-in-out infinite; }
.status-chip.ended .dot, .status-chip.failed .dot { background: var(--gray-600); }

.ghost-button, .primary-button, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.875rem;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms var(--ease-out), opacity 160ms ease;
  text-decoration: none;
}
.ghost-button { border: 1px solid var(--gray-200); background: var(--white); padding: 0.4375rem 0.875rem; color: var(--ink); }
.ghost-button:hover { border-color: var(--teal-300); color: var(--teal-800); }
.primary-button { border: 0; background: var(--teal-500); color: var(--white); padding: 0.625rem 1.125rem; }
.primary-button:hover { background: var(--teal-600); }
.primary-button:disabled { opacity: 0.5; cursor: default; }
.ghost-button:active, .primary-button:active, .icon-button:active { transform: scale(0.97); }
.icon-button { width: 2.25rem; height: 2.25rem; border: 0; background: transparent; color: var(--gray-600); }
.icon-button:hover { background: var(--gray-50); color: var(--ink); }
.mobile-new { display: none; }

.panel-toggle { position: relative; animation: pop 360ms var(--ease-out) both; }
.panel-toggle.active { background: var(--teal-50); border-color: var(--teal-300); color: var(--teal-800); }
.panel-toggle .icon { width: 1rem; height: 1rem; color: var(--teal-500); }
.panel-toggle .badge, .side-tab .badge { position: absolute; top: -0.125rem; right: -0.125rem; width: 0.625rem; height: 0.625rem; border-radius: 50%; background: var(--gold); border: 2px solid var(--white); animation: pop 300ms var(--ease-out) both; }

.gate { flex: 1; display: grid; place-items: center; padding: 1.5rem 1rem; }
.gate-card {
  width: min(24rem, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
  animation: rise 480ms var(--ease-out) both;
}
.gate-card h1 { font-size: 1.625rem; line-height: 1.25; margin: 0.75rem 0 0; letter-spacing: -0.02em; }
.gate-card p { margin: 0; color: var(--gray-600); }
.gate-card input {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.8125rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--gray-200);
  font-size: 1.125rem;
  text-align: center;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.gate-card input:focus { outline: none; border-color: var(--teal-500); box-shadow: 0 0 0 4px rgba(42, 130, 123, 0.14); }
.gate-card .primary-button { width: 100%; padding: 0.8125rem; font-size: 1rem; border-radius: 0.75rem; }
.form-error { min-height: 1.25rem; font-size: 0.875rem; color: var(--red) !important; }
.gate-card.shake { animation: shake 360ms ease both; }

.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; overscroll-behavior: contain; }
.scroller { transition: opacity 180ms ease; }
.scroller.switching { opacity: 0; }
.thread { width: min(var(--column), 100%); margin: 0 auto; padding: 1.5rem 1.25rem 0; display: flex; flex-direction: column; }
.thread-end { height: 1.5rem; }

.hero {
  width: min(var(--column), 100%);
  margin: 0 auto;
  padding: 0 1.25rem 1.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hero h1 { font-size: 2rem; line-height: 1.2; letter-spacing: -0.025em; margin: 1.25rem 0 0.5rem; font-weight: 600; }
.hero p { margin: 0; color: var(--gray-600); font-size: 1.0625rem; }
.hero-mark { width: 3.25rem; height: 3.25rem; border-radius: 1rem; background: var(--teal-50); position: relative; animation: float 6s ease-in-out infinite; }
.hero-mark::after { content: ""; position: absolute; inset: 0.85rem; background: var(--teal-500); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); }
.app[data-state="empty"] .hero > * { animation: rise 560ms var(--ease-out) both; }
.app[data-state="empty"] .hero > :nth-child(2) { animation-delay: 60ms; }
.app[data-state="empty"] .hero > :nth-child(3) { animation-delay: 120ms; }
.app[data-state="empty"] .hero > .hero-mark { animation: rise 560ms var(--ease-out) both, float 6s ease-in-out 600ms infinite; }
.app:not([data-state="empty"]) .hero { display: none; }
.app[data-state="empty"] .chat { justify-content: center; padding-bottom: 14dvh; }
.app[data-state="empty"] .scroller { flex: 0 0 auto; overflow: visible; }
.app[data-state="empty"] .thread, .app[data-state="empty"] .thread-end { display: none; }
.app[data-state="loading"] .chat, .app[data-state="loading"] .topbar-actions { visibility: hidden; }
.app[data-state="gate"] .sidebar, .app[data-state="gate"] .topbar-actions { display: none; }
.hero-ghost { position: fixed; margin: 0; pointer-events: none; z-index: 2; }

.composer-wrap {
  flex: none;
  width: min(var(--column), 100%);
  margin: 0 auto;
  padding: 0.5rem 1.25rem calc(0.75rem + env(safe-area-inset-bottom));
  position: relative;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 1.125rem;
  border-radius: 1.5rem;
  border: 1px solid var(--gray-200);
  background: var(--white);
  box-shadow: var(--shadow-soft);
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.composer:focus-within { border-color: var(--teal-300); box-shadow: 0 0 0 4px rgba(42, 130, 123, 0.1), var(--shadow-soft); }
.composer textarea {
  flex: 1;
  border: 0;
  resize: none;
  outline: none;
  background: transparent;
  padding: 0.5rem 0;
  max-height: 14rem;
  min-height: 2.5rem;
  line-height: 1.5;
  font-size: 1rem;
}
.composer textarea::placeholder { color: #8a96a0; }
.send {
  width: 2.375rem;
  height: 2.375rem;
  border-radius: 50%;
  border: 0;
  background: var(--teal-500);
  color: var(--white);
  display: grid;
  place-items: center;
  flex: none;
  margin-bottom: 0.0625rem;
  transition: background 200ms ease, transform 200ms var(--ease-out), opacity 200ms ease;
}
.send:hover:not(:disabled) { background: var(--teal-600); }
.send:active:not(:disabled) { transform: scale(0.92); }
.send:disabled { opacity: 0.35; cursor: default; }
.send .icon { grid-area: 1 / 1; width: 1.125rem; height: 1.125rem; transition: opacity 200ms ease, transform 260ms var(--ease-out); }
.send .stop-icon { opacity: 0; transform: scale(0.5) rotate(-45deg); }
.app.busy .send { background: var(--ink); opacity: 1; cursor: pointer; }
.app.busy .send:hover { background: #1d2427; }
.app.busy .send .send-icon { opacity: 0; transform: scale(0.5) translateY(4px); }
.app.busy .send .stop-icon { opacity: 1; transform: none; }
.composer-note { margin: 0.5rem 0 0; text-align: center; font-size: 0.75rem; color: var(--gray-600); transition: opacity 200ms ease; }
.jump {
  position: absolute;
  top: -2.75rem;
  left: 50%;
  translate: -50% 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--gray-200);
  background: var(--white);
  box-shadow: var(--shadow-soft);
  display: grid;
  place-items: center;
  color: var(--gray-600);
  animation: pop 260ms var(--ease-out) both;
}
.jump .icon { width: 1rem; height: 1rem; }

.msg-user {
  align-self: flex-end;
  max-width: min(85%, 36rem);
  background: var(--gray-50);
  border-radius: 1.25rem 1.25rem 0.375rem 1.25rem;
  padding: 0.625rem 1rem;
  margin: 0.5rem 0 1.25rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.scheduled {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 100%;
  margin: 1rem 0 1.25rem;
  padding: 0.3125rem 0.875rem 0.3125rem 0.625rem;
  border-radius: 999px;
  background: var(--gold-50);
  color: #8a4b0f;
  font-size: 0.8125rem;
  font-weight: 500;
}
.scheduled .icon { width: 0.9375rem; height: 0.9375rem; color: var(--gold); }
.scheduled span.text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scheduled time { color: #b0702f; font-weight: 400; white-space: nowrap; flex: none; }

.turn { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.25rem; position: relative; }
.turn > .segment:first-child { margin-top: 0; }
.animate .enter { animation: rise 340ms var(--ease-out) both; }

.prose { overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 0.75rem; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.3; margin: 1.25rem 0 0.5rem; letter-spacing: -0.01em; }
.prose h1 { font-size: 1.375rem; }
.prose h2 { font-size: 1.1875rem; }
.prose h3, .prose h4 { font-size: 1.0625rem; }
.prose ul, .prose ol { margin: 0 0 0.75rem; padding-left: 1.375rem; }
.prose li { margin: 0.1875rem 0; }
.prose li::marker { color: var(--teal-500); }
.prose a { color: var(--teal-600); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.prose code { font-family: var(--mono); font-size: 0.875em; background: var(--gray-50); border-radius: 0.3125rem; padding: 0.0625rem 0.3125rem; }
.prose pre { background: var(--gray-25); border: 1px solid var(--gray-200); border-radius: 0.75rem; padding: 0.75rem 1rem; overflow-x: auto; margin: 0 0 0.75rem; }
.prose pre code { background: none; padding: 0; font-size: 0.8125rem; line-height: 1.55; }
.prose blockquote { margin: 0 0 0.75rem; padding: 0.125rem 0 0.125rem 0.875rem; border-left: 3px solid var(--teal-100); color: var(--gray-600); }
.prose table { border-collapse: collapse; margin: 0 0 0.75rem; font-size: 0.9375rem; display: block; overflow-x: auto; max-width: 100%; }
.prose th, .prose td { border: 1px solid var(--gray-200); padding: 0.375rem 0.625rem; text-align: left; vertical-align: top; }
.prose th { background: var(--gray-25); font-weight: 600; }
.prose hr { border: 0; border-top: 1px solid var(--gray-200); margin: 1rem 0; }
.prose img { max-width: 100%; border-radius: 0.5rem; }
.prose.streaming > :last-child::after {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-left: 0.25rem;
  border-radius: 50%;
  background: var(--teal-300);
  vertical-align: 0.0625rem;
  animation: breathe 1.2s ease-in-out infinite;
}

.steps {
  border: 1px solid var(--gray-200);
  border-radius: 0.875rem;
  background: var(--white);
  overflow: hidden;
  transition: border-color 200ms ease, background 200ms ease;
}
.steps.collapsed { background: var(--gray-25); }
.steps-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--gray-600);
  text-align: left;
}
.steps-summary:hover { color: var(--ink); }
.steps-summary .chev { width: 0.875rem; height: 0.875rem; transition: transform 280ms var(--ease-out); }
.steps:not(.collapsed) .steps-summary .chev { transform: rotate(90deg); }
.steps-summary .summary-text { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.steps-summary .count { font-variant-numeric: tabular-nums; }
.steps-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 320ms var(--ease-in-out); }
.steps.collapsed .steps-body { grid-template-rows: 0fr; }
.steps-inner { min-height: 0; overflow: hidden; }
.steps:not(.has-summary) .steps-summary { display: none; }
.steps.has-summary .steps-inner { border-top: 1px solid var(--gray-200); }
.steps.collapsed .steps-inner { border-top-color: transparent; }

.step { border-top: 1px solid var(--gray-50); }
.step:first-child { border-top: 0; }
.step-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0.4375rem 0.75rem;
  font-size: 0.875rem;
  text-align: left;
  color: var(--ink);
  transition: background 140ms ease;
}
.step-row:hover { background: var(--gray-25); }
.step-icon { width: 1.5rem; height: 1.5rem; border-radius: 0.4375rem; display: grid; place-items: center; background: var(--teal-50); color: var(--teal-600); flex: none; }
.step-icon .icon { width: 0.875rem; height: 0.875rem; }
.step-label { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.step-state { width: 1rem; height: 1rem; flex: none; display: grid; place-items: center; }
.step-state .icon { width: 0.875rem; height: 0.875rem; }
.step.running .step-state::before { content: ""; width: 0.75rem; height: 0.75rem; border-radius: 50%; border: 2px solid var(--teal-100); border-top-color: var(--teal-500); animation: spin 800ms linear infinite; }
.step.done .step-state { color: var(--teal-500); animation: pop 260ms var(--ease-out) both; }
.step.error .step-state { color: var(--red); }
.step.error .step-icon { background: var(--red-50); color: var(--red); }
.step-detail { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 280ms var(--ease-in-out); }
.step.open .step-detail { grid-template-rows: 1fr; }
.step-detail > div { min-height: 0; overflow: hidden; }
.step-detail pre {
  margin: 0 0.75rem 0.625rem 2.875rem;
  max-height: 16rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  background: var(--gray-25);
  border: 1px solid var(--gray-200);
  border-radius: 0.5rem;
  padding: 0.5rem 0.625rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.shots { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0 0.75rem 0.625rem 2.875rem; }
.steps.collapsed + .shots-strip, .shots-strip { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.shot {
  border: 1px solid var(--gray-200);
  padding: 0;
  border-radius: 0.5rem;
  overflow: hidden;
  background: var(--gray-25);
  width: 10.5rem;
  aspect-ratio: 16 / 10;
  transition: transform 200ms var(--ease-out), box-shadow 200ms ease;
  animation: rise 360ms var(--ease-out) both;
}
.shot:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); }
.shot img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }

.working {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  color: var(--gray-600);
  font-size: 0.875rem;
  padding: 0.25rem 0;
  animation: fade 260ms ease both;
}
.working .pulse { position: relative; width: 0.625rem; height: 0.625rem; flex: none; }
.working .pulse::before, .working .pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--teal-500); }
.working .pulse::after { animation: ripple 1.8s var(--ease-out) infinite; }
.working .pulse::before { animation: breathe 1.8s ease-in-out infinite; }
.working .label { transition: opacity 180ms ease, transform 180ms ease; }
.working .label.swap { opacity: 0; transform: translateY(3px); }
.working .shimmer {
  background: linear-gradient(90deg, var(--gray-600) 0%, var(--gray-600) 40%, var(--teal-300) 50%, var(--gray-600) 60%, var(--gray-600) 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 2.4s linear infinite;
}

.turn-note { font-size: 0.8125rem; color: var(--gray-600); display: inline-flex; align-items: center; gap: 0.375rem; }
.turn-note .icon { width: 0.875rem; height: 0.875rem; }
.notice {
  align-self: stretch;
  font-size: 0.875rem;
  border-radius: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: var(--gray-25);
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  margin: 0.25rem 0 1rem;
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
}
.notice .icon { margin-top: 0.125rem; width: 1rem; height: 1rem; }
.notice.warn { background: var(--gold-50); border-color: #fbd5ad; color: #7a4510; }
.notice.warn .icon { color: var(--gold); }
.notice.error { background: var(--red-50); border-color: #f2c9c6; color: #8f2f2a; }
.notice.error .icon { color: var(--red); }
.notice .notice-action { margin-left: auto; flex: none; }

.ended-card {
  margin: 0.5rem 0 1.5rem;
  padding: 1.25rem;
  border-radius: 1rem;
  background: var(--teal-50);
  border: 1px solid var(--teal-100);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
}
.ended-card h2 { margin: 0; font-size: 1.0625rem; color: var(--teal-800); }
.ended-card p { margin: 0; color: var(--gray-600); font-size: 0.9375rem; }

.side {
  width: min(46vw, 52rem);
  flex: none;
  border-left: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  background: var(--gray-25);
  animation: slide-in 420ms var(--ease-out) both;
}
.side.closing { animation: slide-out 280ms var(--ease-in-out) both; }
.side-bar { height: 3.5rem; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0 0.5rem 0 0.75rem; border-bottom: 1px solid var(--gray-200); background: var(--white); }
.side-tabs { display: flex; gap: 0.25rem; padding: 0.1875rem; border-radius: 999px; background: var(--gray-50); }
.side-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 0.375rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-600);
  transition: background 200ms ease, color 200ms ease, box-shadow 200ms ease;
  animation: pop 320ms var(--ease-out) both;
}
.side-tab .icon { width: 0.9375rem; height: 0.9375rem; }
.side-tab:hover { color: var(--ink); }
.side-tab[aria-selected="true"] { background: var(--white); color: var(--teal-800); box-shadow: 0 1px 2px rgba(44, 52, 57, 0.08); }
.side-tab[aria-selected="true"] .icon { color: var(--teal-500); }
.tab-live { width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: var(--teal-500); animation: breathe 1.8s ease-in-out infinite; }
.side-actions { display: flex; align-items: center; gap: 0.125rem; }
.preview-actions { display: flex; align-items: center; gap: 0.125rem; margin-right: 0.25rem; animation: fade 200ms ease both; }
.preview-actions .code-chip { margin-right: 0.25rem; }
.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-view { flex: 1; min-height: 0; display: flex; flex-direction: column; animation: fade 240ms ease both; }
.preview-links { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.75rem 0.75rem 0; }
.preview-links .ghost-button { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.preview-links .icon { width: 0.9375rem; height: 0.9375rem; color: var(--teal-500); }
.preview-links .ghost-button[aria-expanded="true"] { background: var(--teal-50); border-color: var(--teal-300); color: var(--teal-800); }
.qr-pop { display: flex; align-items: center; gap: 1rem; margin: 0.75rem 0.75rem 0; padding: 0.875rem 1rem; border-radius: 0.875rem; background: var(--white); border: 1px solid var(--teal-100); box-shadow: var(--shadow-soft); animation: rise 300ms var(--ease-out) both; }
.qr-box { width: 8.5rem; height: 8.5rem; flex: none; padding: 0.375rem; border-radius: 0.75rem; background: var(--white); border: 1px solid var(--gray-200); }
.qr-box svg { width: 100%; height: 100%; display: block; }
.qr-copy { min-width: 0; }
.qr-title { margin: 0 0 0.25rem; font-weight: 600; color: var(--teal-800); }
.qr-text { margin: 0; font-size: 0.8125rem; color: var(--gray-600); }
.preview-body { flex: 1; min-height: 0; padding: 0.75rem; }
.preview-body iframe { width: 100%; height: 100%; border: 1px solid var(--gray-200); border-radius: 0.75rem; background: var(--white); box-shadow: var(--shadow-soft); transition: opacity 240ms ease; }
.preview-body iframe.reloading { opacity: 0.55; }
.side-note { margin: 0; padding: 0 1rem 0.75rem; font-size: 0.75rem; color: var(--gray-600); }
.side-note strong { font-family: var(--mono); letter-spacing: 0.06em; color: var(--teal-800); }

.address {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin: 0.75rem 0.75rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: 0.75rem;
  background: var(--white);
  min-width: 0;
}
.address-icon { width: 1rem; height: 1rem; color: var(--teal-500); }
.address-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.address-title { font-size: 0.8125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.address-url { font-size: 0.75rem; color: var(--gray-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }
.live-pill { display: inline-flex; align-items: center; gap: 0.375rem; font-size: 0.75rem; font-weight: 600; color: var(--teal-600); background: var(--teal-50); border-radius: 999px; padding: 0.125rem 0.5rem; flex: none; animation: fade 240ms ease both; }
.live-pill .dot { width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: var(--teal-500); animation: breathe 1.8s ease-in-out infinite; }
.screen { flex: 1; min-height: 0; margin: 0.75rem; border: 1px solid var(--gray-200); border-radius: 0.75rem; background: var(--white); box-shadow: var(--shadow-soft); overflow: hidden; display: grid; place-items: center; position: relative; }
.screen img { width: 100%; height: 100%; object-fit: contain; object-position: top center; display: block; background: var(--white); animation: fade 320ms ease both; }
.screen-state { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; padding: 2rem; text-align: center; color: var(--gray-600); font-size: 0.9375rem; max-width: 22rem; animation: rise 360ms var(--ease-out) both; }
.screen-state p { margin: 0; }
.screen-icon { width: 3rem; height: 3rem; border-radius: 1rem; background: var(--teal-50); color: var(--teal-500); display: grid; place-items: center; animation: float 6s ease-in-out infinite; }
.screen-icon .icon { width: 1.375rem; height: 1.375rem; }
.screen.closed img { opacity: 0.35; filter: grayscale(0.6); transition: opacity 400ms ease, filter 400ms ease; }
.screen.closed .screen-state { position: absolute; inset: auto 0 1.5rem; margin: 0 auto; background: var(--white); border: 1px solid var(--gray-200); border-radius: 1rem; box-shadow: var(--shadow-soft); padding: 1rem 1.25rem; }

.lightbox { position: fixed; inset: 0; background: rgba(23, 29, 32, 0.72); display: grid; place-items: center; padding: 1.5rem; z-index: 50; animation: fade 200ms ease both; cursor: zoom-out; }
.lightbox img { max-width: min(100%, 90rem); max-height: 100%; border-radius: 0.75rem; box-shadow: var(--shadow-lift); animation: zoom-in 280ms var(--ease-out) both; background: var(--white); }

.toast { position: fixed; left: 50%; bottom: 6.5rem; translate: -50% 0; background: var(--ink); color: var(--white); padding: 0.5rem 1rem; border-radius: 999px; font-size: 0.875rem; box-shadow: var(--shadow-lift); z-index: 60; animation: rise 260ms var(--ease-out) both; }

.dialog { border: 0; border-radius: 1.25rem; padding: 1.5rem; width: min(26rem, calc(100vw - 2rem)); box-shadow: var(--shadow-lift); color: var(--ink); }
.dialog[open] { animation: zoom-in 260ms var(--ease-out) both; }
.dialog::backdrop { background: rgba(23, 29, 32, 0.4); animation: fade 200ms ease both; }
.dialog h2 { margin: 0 0 0.5rem; font-size: 1.1875rem; }
.dialog p { margin: 0 0 1.25rem; color: var(--gray-600); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }

.plain-page { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; background: var(--gray-25); }
.plain-card { background: var(--white); border: 1px solid var(--gray-200); border-radius: 1rem; padding: 1.5rem 1.75rem; max-width: 28rem; box-shadow: var(--shadow-soft); }
.plain-card h1 { font-size: 1.25rem; margin: 0 0 0.5rem; }
.plain-card p { margin: 0; color: var(--gray-600); }

.app.replaying *, .app.replaying *::before, .app.replaying *::after { transition: none !important; animation: none !important; }

@keyframes rise { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { opacity: 0; transform: scale(0.6); } 70% { transform: scale(1.06); } 100% { opacity: 1; transform: scale(1); } }
@keyframes zoom-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes breathe { 0%, 100% { opacity: 0.45; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1); } }
@keyframes ripple { 0% { opacity: 0.45; transform: scale(1); } 100% { opacity: 0; transform: scale(2.6); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(2rem); } to { opacity: 1; transform: none; } }
@keyframes slide-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(2rem); } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-out { from { transform: none; } to { transform: translateY(100%); } }

@media (max-width: 1400px) {
  .app.side-open .sidebar { position: fixed; inset: 0 auto 0 0; width: min(20rem, 86vw); z-index: 40; transform: translateX(-102%); transition: transform 320ms var(--ease-out); box-shadow: var(--shadow-lift); }
  .app.side-open.drawer-open .sidebar { transform: none; }
  .app.side-open .topbar .menu-toggle, .app.side-open .topbar .mobile-new { display: inline-flex; }
  .app.side-open .topbar-brand { display: flex; }
  .app.side-open .topbar-title { display: none; }
}

@media (max-width: 1100px) {
  .side { position: fixed; inset: 0 0 0 auto; width: min(100vw, 44rem); z-index: 30; box-shadow: var(--shadow-lift); }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(20rem, 86vw); z-index: 40; transform: translateX(-102%); transition: transform 320ms var(--ease-out); box-shadow: var(--shadow-lift); }
  .app.drawer-open .sidebar { transform: none; }
  .app.side-open .sidebar { display: flex; }
  .topbar .menu-toggle { display: inline-flex; }
  .chat-remove { opacity: 1; }
  .topbar { padding: 0 0.5rem 0 1rem; }
  .topbar-brand { display: flex; }
  .topbar-title { display: none; }
  .mobile-new { display: inline-flex; }
  .topbar-actions { margin-left: auto; }
}

@media (max-width: 640px) {
  .thread { padding: 1rem 1rem 0; }
  .hero { padding-left: 1rem; padding-right: 1rem; }
  .app[data-state="empty"] .chat { padding-bottom: 6dvh; }
  .hero h1 { font-size: 1.5rem; }
  .hero p { font-size: 1rem; }
  .composer-wrap { padding-left: 0.75rem; padding-right: 0.75rem; }
  .msg-user { max-width: 92%; }
  .status-chip { display: none; }
  .panel-toggle .label { display: none; }
  .panel-toggle { padding: 0.4375rem 0.625rem; }
  .side { inset: 0; width: 100vw; border-left: 0; animation: sheet-in 380ms var(--ease-out) both; }
  .side.closing { animation: sheet-out 260ms var(--ease-in-out) both; }
  .side-note { display: none; }
  .preview-body { padding: 0.5rem; }
  .screen { margin: 0.5rem; }
  .address { margin: 0.5rem 0.5rem 0; }
  .side-tab { padding: 0.375rem 0.75rem; }
  .shot { width: 8.5rem; }
  .step-detail pre, .shots { margin-left: 0.75rem; padding-left: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .working .pulse::after { display: none; }
  .working .shimmer { color: var(--gray-600); background: none; }
}
