:root {
  font: 16px/1.5 var(--grotesk);
  color: var(--ink);
  background: var(--paper);
  --surface: #f0f0f0;
  --line: #c8c8c8;
  --muted: #505050;
  --accent: #9c3150;
  --active: #f9dce4;
  --content: 46rem;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 16.25rem minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.65rem 1rem 1.15rem;
  background: #f4f4f4;
  border-right: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  align-self: flex-start;
  margin: 0 0 1.8rem .35rem;
  color: inherit;
  font-size: 1.2rem;
  font-weight: 650;
  text-decoration: none;
}

.brand-mark { display: inline-flex; align-items: center; gap: .19rem; color: currentColor; }
.brand-mark i { width: .3rem; height: .85rem; background: currentColor; border-radius: 2rem; transform: rotate(25deg); }
.brand-mark i:nth-child(2) { height: 1.2rem; }
.brand-mark i:nth-child(3) { height: .6rem; }

.new-chat, .icon-button, .composer-actions button, .suggestions button, .dialog-actions button {
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.new-chat { padding: .62rem .8rem; text-align: left; font-weight: 600; }
.new-chat span { margin-right: .25rem; color: var(--accent); font-size: 1.15rem; }
.new-chat:hover:enabled, .suggestions button:hover:enabled, .icon-button:hover:enabled { background: var(--active); border-color: var(--ink); }
.history { flex: 1; min-height: 0; overflow-y: auto; margin: 1.75rem 0 1rem; }
.history h2 { margin: 0 .45rem .45rem; color: var(--muted); font-size: .86rem; font-weight: 600; }
.empty-history { margin: .52rem .45rem; color: var(--muted); font-size: .85rem; }
.history ul { margin: 0; padding: 0; list-style: none; }
.history button {
  display: block;
  width: 100%;
  margin: .1rem 0;
  padding: .55rem .65rem;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history button:hover:enabled, .history button[aria-current] { background: var(--active); }

.main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: .8rem;
  min-height: 4.55rem;
  padding: .6rem 1.6rem;
  border-bottom: 1px solid var(--line);
}
.heading { display: grid; flex: 1; min-width: 0; }
#chat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 620; }
.chat-status { color: var(--muted); font-size: .83rem; }
.icon-button { min-width: 2.45rem; min-height: 2.45rem; color: var(--muted); font-size: 1.15rem; line-height: 1; }
.menu { display: none; }
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.3rem;
  padding: .36rem .62rem;
  border-radius: 0;
  color: var(--muted);
  font-size: .875rem;
  text-decoration: none;
}
.site-nav a:hover, .site-nav a[aria-current='page'] { background: var(--active); color: var(--ink); }
.site-nav .chat-link { background: var(--ink); color: var(--paper); border: 1px solid var(--ink); margin-left: .3rem; }
.site-nav .chat-link:hover { background: var(--pink); color: var(--ink); }

.reference-header { justify-content: space-between; flex-wrap: wrap; }
.reference-header .brand { margin: 0; align-self: center; }
.reference-page { width: min(100% - 2rem, var(--content)); margin: 0 auto; padding: 3.8rem 0 4rem; }
.reference-page h1 { margin: 0; font-size: clamp(2.5rem, 6vw, 5rem); line-height: .9; font-weight: 500; letter-spacing: -.035em; }
.reference-intro { max-width: 40rem; margin: 1rem 0 2.4rem; color: var(--muted); font-size: 1.1rem; }
.reference-page h2 { margin: 0; font-size: 1.28rem; line-height: 1.25; }
.reference-page section p { margin: .7rem 0 0; }
.reference-page a { color: var(--accent); text-underline-offset: .15em; }
.reference-section { padding-top: 1.35rem; margin-top: 1.65rem; border-top: 1px solid var(--line); }
.mode-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.mode-cards section {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
}
.mode-cards p, .protocol-steps li { color: var(--muted); }
.protocol-steps { padding-left: 1.35rem; margin: 1rem 0; }
.protocol-steps li { padding-left: .2rem; margin: .6rem 0; }
.protocol-steps strong { color: var(--ink); }
.protocol-steps li::marker { color: var(--accent); }
.docs-contents { margin-bottom: 1.65rem; padding: 1rem; border: 1px solid var(--line); background: var(--surface); }
.docs-contents h2 { font-size: .94rem; }
.docs-contents ul { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .3rem .6rem; padding: 0; margin: .55rem 0 0; list-style: none; }
.docs-contents a { display: block; padding-block: .2rem; color: var(--muted); font-size: .9rem; text-decoration: none; }
.docs-contents a:hover { color: var(--accent); text-decoration: underline; }
.docs-body { min-width: 0; }
.docs-body .reference-section { scroll-margin-top: 1.5rem; }
.docs-body .reference-section + .reference-section { margin-top: 2rem; }
.docs-body .reference-section:first-child { margin-top: 0; }
.docs-body .mode-cards { margin-top: .9rem; }
.docs-body .mode-cards h3 { margin: 0; font-size: 1.04rem; }
.docs-issues { margin: .85rem 0 0; }
.docs-issues dt { font-weight: 600; }
.docs-issues dt:not(:first-child) { margin-top: .85rem; }
.docs-issues dd { margin: .22rem 0 0; color: var(--muted); }

@media (min-width: 1000px) {
  .docs-page { display: grid; grid-template-columns: 12rem minmax(0, var(--content)); align-items: start; gap: 0 3rem; width: min(100% - 3rem, 61rem); }
  .docs-header, .docs-body { grid-column: 2; }
  .docs-contents { grid-column: 1; position: sticky; top: 1.5rem; margin-bottom: 0; }
  .docs-contents ul { grid-template-columns: 1fr; }
}

.thread { display: flex; flex-direction: column; min-height: 0; overflow: auto; padding: 1.75rem 1.4rem; }
.welcome { align-self: center; width: min(100%, var(--content)); margin: auto; padding: 2rem 0; text-align: center; }
.welcome-mark {
  display: grid;
  width: 3.8rem;
  height: 3.8rem;
  margin: 0 auto 1.25rem;
  place-items: center;
  border: 1px solid var(--ink);
  background: var(--pink);
}
.welcome-mark .brand-mark { transform: scale(1.45); }
.welcome h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.05rem); line-height: 1.15; font-weight: 620; letter-spacing: -.045em; }
.suggestions { display: flex; justify-content: center; flex-wrap: wrap; gap: .55rem; margin-top: 1.3rem; }
.suggestions button { padding: .53rem .73rem; font-size: .875rem; color: var(--ink); }
.messages { display: grid; gap: 1.4rem; width: min(100%, var(--content)); margin: 0 auto; }
.messages:empty { display: none; }
.message { min-width: 0; max-width: 90%; }
.message-user { justify-self: end; padding: .7rem .95rem; border: 1px solid var(--line); background: var(--surface); }
.message-assistant { justify-self: start; }
.message-label { margin: 0 0 .23rem; color: var(--muted); font-size: .84rem; font-weight: 600; }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.thinking {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: min(100%, var(--content));
  margin: 1.15rem auto 0;
  color: var(--muted);
  font-size: .875rem;
}
.thinking-dots { display: inline-flex; gap: .24rem; color: var(--accent); }
.thinking-dots i { width: .3rem; height: .3rem; border-radius: 50%; background: currentColor; animation: thinking-pulse 1.05s ease-in-out infinite; }
.thinking-dots i:nth-child(2) { animation-delay: .14s; }
.thinking-dots i:nth-child(3) { animation-delay: .28s; }

@keyframes thinking-pulse {
  0%, 60%, 100% { opacity: .4; }
  30% { opacity: 1; transform: translateY(-.1rem); }
}

@media (prefers-reduced-motion: reduce) {
  .thinking-dots i { animation: none; }
}

.composer { width: min(100%, calc(var(--content) + 2.8rem)); margin: 0 auto; padding: 0 1.4rem 1rem; }
.composer-box { padding: .85rem; border: 1px solid var(--line); background: var(--surface); }
.composer-box:focus-within { border-color: var(--ink); }
textarea { display: block; width: 100%; min-height: 3.25rem; max-height: 8rem; padding: .15rem .3rem; resize: vertical; outline: none; border: 0; background: transparent; }
textarea:focus-visible { outline: none; }
textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: .55rem; margin-top: .52rem; }
.mode-switches { display: flex; flex-wrap: wrap; gap: .45rem; }
.mode-switches button { display: inline-flex; align-items: center; gap: .38rem; min-height: 2.24rem; padding: .34rem .58rem; font-size: .875rem; color: var(--muted); }
.mode-switches button:hover:enabled { background: var(--active); }
.mode-switches button[aria-checked='true'] { border-color: var(--ink); background: var(--pink); color: var(--ink); }
.mode-switches button:disabled { opacity: .7; }
.toggle-track { position: relative; width: 1.15rem; height: .7rem; border: 1px solid currentColor; border-radius: 1rem; }
.toggle-track::before { position: absolute; top: .1rem; left: .1rem; width: .37rem; height: .37rem; border-radius: 50%; background: currentColor; content: ''; }
[aria-checked='true'] .toggle-track::before { left: .52rem; }
.composer-actions .send { min-height: 2.35rem; padding: .42rem .85rem; border-color: var(--ink); background: var(--ink); color: var(--paper); font-size: .875rem; font-weight: 500; }
.composer-actions .send:hover:enabled { background: #444; }
.composer-actions .send:disabled { border-color: var(--line); background: #dedede; color: var(--muted); }
.composer-note { margin: .65rem .15rem 0; color: var(--muted); font-size: .82rem; text-align: center; }
.notice { margin: 0 0 .55rem; padding: .42rem .65rem; border: 1px solid #9c3150; color: #74223b; background: var(--active); font-size: .875rem; }

dialog { max-width: min(25rem, calc(100vw - 2rem)); padding: 1.25rem; border: 1px solid var(--ink); color: inherit; background: var(--surface); }
dialog::backdrop { background: #1e1e1e99; }
dialog h2 { margin: 0; font-size: 1.2rem; }
dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .55rem; }
.dialog-actions button { padding: .35rem .7rem; }
.dialog-actions .delete-confirm { border-color: #9c3150; color: #74223b; }

@media (max-width: 720px) {
  :root { --mobile-chat-header: 6.25rem; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; position: absolute; z-index: 1; inset: var(--mobile-chat-header) auto 0 0; width: min(19rem, 85vw); box-shadow: .75rem 0 2.75rem #1e1e1e40; }
  .menu-open .sidebar { display: flex; }
  .menu { display: inline-block; }
  .topbar { min-height: 3.85rem; padding-inline: .85rem; }
  .main .topbar { flex-wrap: wrap; row-gap: .15rem; min-height: var(--mobile-chat-header); padding-block: .4rem; }
  .main .site-nav { flex-basis: 100%; }
  .thread { padding: 1.2rem .85rem; }
  .composer { padding: 0 .85rem .75rem; }
  .composer-box { padding: .65rem; }
  .reference-page { padding-top: 2.25rem; }
}

@media (max-width: 520px) {
  .mode-cards { grid-template-columns: minmax(0, 1fr); }
  .reference-header .chat-link { margin-left: 0; }
}

@media (max-width: 354px) {
  .composer-actions { align-items: flex-end; }
  .mode-switches { gap: .3rem; }
  .mode-switches button { padding-inline: .42rem; }
}
