:root {
  color-scheme: light;
  --canvas: #f2f1ee;
  --surface: #fdfcf9;
  --field: #f3f2ef;
  --hover: #e9e7e3;
  --text: #292827;
  --muted: #79756f;
  --line: #e6e3dc;
  --accent: #71609b;
  --accent-soft: #eae6f3;
  --accent-text: #625085;
  --error: #a2463d;
  --shadow: 0 10px 36px #26221b12;
  --serif: 'Spectral', 'Noto Serif SC', Georgia, serif;
  --display: 'Instrument Serif', 'Noto Serif SC', Georgia, serif;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --canvas: #161615;
  --surface: #212120;
  --field: #2c2c2a;
  --hover: #30302e;
  --text: #e9e7e1;
  --muted: #a29f98;
  --line: #393936;
  --accent: #b3a1dc;
  --accent-soft: #3b344e;
  --accent-text: #d6c6f4;
  --error: #eba397;
  --shadow: 0 10px 36px #0003;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; width: 100%; height: 100%; }
body { background: var(--canvas); color: var(--text); font: 400 15px/1.5 var(--serif); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .45; }
button, a, input, textarea { outline-offset: 4px; }
:focus-visible { outline: 2px solid var(--accent); }
a { color: inherit; }
svg { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
::selection { background: var(--accent-soft); color: var(--text); }
::placeholder { color: var(--muted); opacity: 1; }
.icon-definitions, .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); height: 100dvh; padding: 7px 7px 7px 0; }
.sidebar { display: flex; flex-direction: column; min-height: 0; padding: 14px 16px 10px; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 2px 25px 8px; }
.brand { font: 34px/1 var(--display); text-decoration: none; letter-spacing: -.9px; }
.brand-dot { color: var(--accent); }
.icon-button { display: inline-flex; justify-content: center; align-items: center; width: 36px; height: 36px; border-radius: 9px; color: var(--muted); }
.icon-button:hover, .nav-button:hover { background: var(--hover); color: var(--text); }
.sidebar-nav { display: grid; gap: 4px; }
.nav-button { display: flex; align-items: center; gap: 13px; padding: 10px 12px; border-radius: 9px; text-align: left; width: 100%; }
.nav-button svg { width: 19px; height: 19px; }
.nav-button:first-child { background: var(--accent-soft); color: var(--accent-text); font-weight: 500; }
.history-search-wrap { margin: 12px 0 0; }
.history-search-wrap input { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; }
.history-heading { margin: 34px 12px 12px; color: var(--muted); font-size: 12px; }
.history { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.history-empty { margin: 8px 12px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.history-row { position: relative; display: flex; align-items: center; min-width: 0; border-radius: 8px; margin-bottom: 2px; }
.history-row:hover, .history-row.active { background: var(--hover); }
.history-item { min-width: 0; width: 100%; text-align: left; padding: 9px 34px 9px 12px; }
.history-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.history-delete { position: absolute; right: 3px; opacity: 0; width: 28px; height: 28px; }
.history-delete svg { width: 14px; height: 14px; }
.history-row:hover .history-delete, .history-row:focus-within .history-delete { opacity: 1; }
.sidebar-foot { padding: 18px 6px 2px; }
.theme-switch { display: flex; padding: 3px; background: var(--hover); border-radius: 10px; gap: 2px; }
.theme-switch button { display: flex; align-items: center; justify-content: center; gap: 7px; flex: 1; border-radius: 7px; padding: 7px 8px; font-size: 13px; color: var(--muted); }
.theme-switch svg { width: 15px; height: 15px; }
.theme-switch button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px #0000000a; }
.sidebar-foot p { font-size: 11px; text-align: center; margin: 13px 0 0; color: var(--muted); }
.workspace { display: flex; flex-direction: column; position: relative; min-width: 0; min-height: 0; border-radius: 14px; background: var(--surface); overflow: hidden; }
.topbar { height: 66px; flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 0 24px; z-index: 3; }
.open-sidebar { display: none; }
.model-picker { position: relative; min-width: 0; }
.model-toggle { display: flex; align-items: center; gap: 9px; padding: 8px 4px; min-width: 0; max-width: min(500px, 65vw); font-size: 19px; font-weight: 500; }
#model-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-toggle svg { width: 15px; height: 15px; color: var(--muted); }
.chat-title { margin-left: auto; color: var(--muted); font-size: 13px; max-width: 33%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-popover { position: absolute; top: calc(100% + 8px); left: 0; width: 330px; max-width: calc(100vw - 48px); padding: 8px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); border-radius: 16px; }
.model-search { display: flex; align-items: center; gap: 10px; margin: 2px 5px 9px; border-bottom: 1px solid var(--line); padding: 7px 2px 12px; color: var(--muted); }
.model-search svg { width: 17px; height: 17px; }
.model-search input { width: 100%; min-width: 0; background: transparent; border: 0; font-size: 15px; }
.model-options { max-height: min(350px, 50dvh); overflow-y: auto; scrollbar-width: thin; }
.model-option { width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px; overflow-wrap: anywhere; font-size: 14px; }
.model-option:hover { background: var(--hover); }
.model-option[aria-pressed='true'] { background: var(--accent-soft); color: var(--accent-text); }
.model-empty { margin: 12px; color: var(--muted); }
.reading-area { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.messages { width: min(100%, 790px); margin: 0 auto; padding: 26px 24px 16px; }
.message { margin: 0 0 30px; font-size: 17px; line-height: 1.85; overflow-wrap: anywhere; }
.message.user { width: fit-content; max-width: 86%; margin-left: auto; border-radius: 20px 20px 5px 20px; padding: 12px 20px; background: var(--field); white-space: pre-wrap; }
.message.assistant { padding: 0 3px; }
.message-label { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--accent-text); }
.message-actions { margin-top: 8px; }
.message-actions button { width: 30px; height: 30px; }
.message-actions svg { width: 15px; height: 15px; }
.markdown { white-space: normal; }
.markdown.streaming { white-space: pre-wrap; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 1em; }
.markdown h1, .markdown h2, .markdown h3 { line-height: 1.4; margin: 1.3em 0 .6em; font-weight: 600; }
.markdown h1 { font-size: 1.5em; }
.markdown h2 { font-size: 1.3em; }
.markdown h3 { font-size: 1.1em; }
.markdown a { color: var(--accent-text); text-underline-offset: 3px; }
.markdown blockquote { border-left: 2px solid var(--accent); color: var(--muted); margin: 1em 0; padding-left: 18px; }
.markdown pre { border: 1px solid var(--line); background: var(--field); border-radius: 12px; padding: 18px; overflow-x: auto; }
.markdown code { font-family: var(--serif); background: var(--field); border-radius: 4px; padding: 1px 4px; font-size: .92em; }
.markdown pre code { background: none; padding: 0; }
.markdown ul, .markdown ol { padding-left: 1.4em; }
.markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 1em 0; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 8px 14px; }
.markdown img { max-width: 100%; border-radius: 10px; }
.writing-area { width: min(100%, 816px); margin: 0 auto; padding: 12px 24px 20px; flex: 0 0 auto; }
.welcome { text-align: center; margin: 0 0 30px; }
.welcome h1 { font: 400 clamp(38px, 4.5vw, 54px)/1.16 var(--display); letter-spacing: -.7px; margin: 0; }
.composer { display: flex; gap: 16px; align-items: flex-end; border: 1px solid var(--line); border-radius: 28px; padding: 10px 11px 10px 23px; background: var(--field); transition: border-color .18s, box-shadow .18s; }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 8%, transparent); }
.composer textarea { flex: 1; min-width: 0; resize: none; min-height: 34px; max-height: 200px; background: transparent; border: 0; padding: 4px 0; line-height: 26px; font-size: 17px; outline: none; }
.send { width: 36px; height: 36px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--surface); transition: transform .15s, opacity .15s; }
.send:hover:not(:disabled) { transform: translateY(-1px); }
.send:disabled { background: var(--line); color: var(--muted); opacity: 1; }
.send svg { width: 22px; height: 22px; stroke-width: 1.9; }
.send.stopping::before { content: ''; width: 11px; height: 11px; background: currentColor; border-radius: 2px; }
.send.stopping svg { display: none; }
.status { margin: 10px 12px 0; min-height: 19px; font-size: 12px; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.status.error { color: var(--error); }
.workspace.empty .reading-area { display: none; }
.workspace.empty .writing-area { margin: auto; transform: translateY(-60px); }
.workspace:not(.empty) .welcome { display: none; }
.app.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); padding-left: 7px; }
.app.sidebar-collapsed .sidebar { display: none; }
.app.sidebar-collapsed .open-sidebar { display: inline-flex; }
.backdrop { display: none; }
.gate { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 24px; padding: 0; width: min(440px, calc(100vw - 36px)); box-shadow: var(--shadow); }
.gate::backdrop { background: color-mix(in srgb, var(--canvas) 85%, transparent); backdrop-filter: blur(9px); }
.gate-card { padding: 38px; }
.gate-brand { display: block; font: 32px/1 var(--display); color: var(--accent-text); }
.gate-card h2 { font: 38px/1.1 var(--display); margin: 30px 0 12px; }
.gate-card > p { color: var(--muted); font-size: 14px; }
.gate-card input { width: 100%; border: 1px solid var(--line); background: var(--field); padding: 12px 16px; border-radius: 10px; margin-top: 18px; }
.gate-card .gate-error { margin: 10px 0; color: var(--error); min-height: 20px; }
.gate-submit { display: flex; align-items: center; justify-content: space-between; background: var(--accent); color: var(--surface); width: 100%; padding: 12px 16px; border-radius: 10px; font-weight: 500; }
@media (max-width: 760px) {
  .app, .app.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); padding: 0; }
  .workspace { border-radius: 0; }
  .sidebar, .app.sidebar-collapsed .sidebar { display: flex; position: fixed; top: 0; left: 0; bottom: 0; width: 270px; max-width: 86vw; background: var(--canvas); z-index: 6; transform: translateX(-100%); transition: transform .22s ease; padding-top: max(20px, env(safe-area-inset-top)); }
  .sidebar.open { transform: translateX(0); }
  .open-sidebar { display: inline-flex; }
  .backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 5; background: #0005; }
  .topbar { height: calc(62px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 15px 0; }
  .model-toggle { font-size: 17px; }
  .model-popover { left: -48px; width: min(340px, calc(100vw - 30px)); }
  .chat-title { display: none; }
  .writing-area { padding: 10px 16px max(16px, env(safe-area-inset-bottom)); }
  .welcome { margin-bottom: 25px; }
  .welcome h1 { font-size: clamp(34px, 8.5vw, 46px); }
  .workspace.empty .writing-area { transform: translateY(-35px); }
  .composer { padding-left: 18px; gap: 10px; }
  .composer textarea { font-size: 16px; }
  .messages { padding: 22px 20px 10px; }
  .message { font-size: 16px; }
  .message.user { max-width: 92%; }
  .history-delete { opacity: .65; }
  .gate-card { padding: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
