:root {
  color-scheme: light;
  --bg: #ffffff;
  --side-bg: #f6f6f7;
  --fg: #1a1a1a;
  --muted: #666666;
  --line: #d0d0d0;
  --error: #b00020;
  --user-bg: #eef1f5;
  --code-bg: #f3f4f6;
}
/* Dark, when the visitor chose it, or when they have chosen nothing and their device is dark. */
:root[data-appearance="dark"] {
  color-scheme: dark;
  --bg: #161616;
  --side-bg: #1e1e1f;
  --fg: #e8e8e8;
  --muted: #9a9a9a;
  --line: #3a3a3a;
  --error: #ff6b6b;
  --user-bg: #262a30;
  --code-bg: #22262b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-appearance]) {
    color-scheme: dark;
    --bg: #161616;
    --side-bg: #1e1e1f;
    --fg: #e8e8e8;
    --muted: #9a9a9a;
    --line: #3a3a3a;
    --error: #ff6b6b;
    --user-bg: #262a30;
    --code-bg: #22262b;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 system-ui, sans-serif;
}
#layout { display: flex; height: 100%; }
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 0 0 260px;
  min-width: 0;
  padding: 12px;
  background: var(--side-bg);
  border-right: 1px solid var(--line);
}
#sidebar-body { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
/* Closed, the sidebar folds down to a narrow rail that holds only the control to open it again. */
:root[data-sidebar="closed"] #sidebar { flex-basis: 52px; padding: 12px 8px; }
:root[data-sidebar="closed"] #sidebar-body,
:root[data-sidebar="closed"] .product { display: none; }
:root[data-sidebar="closed"] .sidebar-head { justify-content: center; }
#sidebar-toggle::before { content: "\2039"; }
:root[data-sidebar="closed"] #sidebar-toggle::before { content: "\203A"; }
#sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; overflow-y: auto; }
#sidebar h2 { margin: 16px 0 4px; padding: 0 10px; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
#no-conversations { margin: 0; padding: 0 10px; color: var(--muted); font-size: 0.85rem; }
.sidebar-foot { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
button.entry { width: 100%; border-color: transparent; text-align: left; }
button.entry:not(:disabled):hover { background: var(--user-bg); }
button.quiet { padding: 2px 10px; border-color: transparent; font-size: 1.2rem; line-height: 1.2; }
.product { margin: 0; font-size: 1.05rem; font-weight: 600; }
/* Light or dark: a sun, a sliding switch, a moon. The knob sits on the side that is on. */
button.switch { display: flex; align-items: center; gap: 8px; align-self: flex-start; border-color: transparent; color: var(--muted); }
.switch .track { position: relative; width: 40px; height: 22px; border-radius: 11px; background: var(--line); }
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.15s;
}
.switch[aria-pressed="true"] .track::after { transform: translateX(18px); }
/* Present for assistive technology, not shown. */
.unseen { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-width: 0;
  max-width: 920px;
  height: 100%;
  margin: 0 auto;
  padding: 16px 24px;
}
/* Before the first message everything sits together in the middle of the page. Once a Conversation
   has started, the messages take the room and the message box stays at the bottom. */
main[data-conversation="empty"] { justify-content: center; }
main[data-conversation="empty"] #messages { display: none; }
#start { display: flex; flex-direction: column; gap: 12px; }
main[data-conversation="started"] #start { order: -1; }
/* Load is offered only until the model is loaded. */
main[data-state="ready"] #loader, main[data-state="generating"] #loader { display: none; }
#load-note { color: var(--muted); font-size: 0.85rem; }
main[data-state="loading"] #load-note { display: none; }
#composer-area { display: flex; flex-direction: column; gap: 8px; }
h1 { margin: 0; font-size: 1.05rem; }
#composer textarea { border-radius: 18px; padding: 12px 16px; }
dialog {
  max-width: 520px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h2 { margin: 0 0 12px; font-size: 1.05rem; }
dialog ul { margin: 0 0 12px; padding-left: 18px; }
.row { display: flex; align-items: center; gap: 8px; }
#status, #hint { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
#hint { font-size: 0.8rem; }
#credits { margin: 0 0 16px; color: var(--muted); font-size: 0.85rem; }
#credits a { color: inherit; }
#system summary { cursor: pointer; }
#system textarea { display: block; width: 100%; margin-top: 8px; }
#system textarea[readonly] { color: var(--muted); }
#system-note { margin: 6px 0 0; color: var(--muted); font-size: 0.8rem; }
#status[data-state="unsupported"],
#status[data-state="load-failed"],
#status.failed { color: var(--error); }
progress { flex: 1; min-width: 0; }
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px;
}
.message {
  margin: 0 0 18px;
  overflow-wrap: anywhere;
}
.message .text { white-space: pre-wrap; }
/* A Reply rendered from Markdown lays itself out; only its code keeps its own spacing. */
.message .text.formatted { white-space: normal; }
.formatted > :first-child { margin-top: 0; }
.formatted > :last-child { margin-bottom: 0; }
.formatted p, .formatted ul, .formatted ol, .formatted pre,
.formatted table, .formatted blockquote { margin: 0 0 10px; }
.formatted h1, .formatted h2, .formatted h3,
.formatted h4, .formatted h5, .formatted h6 { margin: 14px 0 6px; font-size: 1rem; }
.formatted h1 { font-size: 1.2rem; }
.formatted h2 { font-size: 1.1rem; }
.formatted ul, .formatted ol { padding-left: 24px; }
.formatted code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  border-radius: 4px;
  padding: 1px 4px;
}
.formatted pre {
  overflow-x: auto;
  padding: 10px 12px;
  background: var(--code-bg);
  border-radius: 6px;
}
.formatted pre code { padding: 0; background: none; white-space: pre; }
.formatted table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.formatted th, .formatted td { padding: 4px 10px; border: 1px solid var(--line); }
.formatted th:not([align]) { text-align: left; }
.formatted blockquote { padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.formatted hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.formatted a { color: inherit; }
.message .readout {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
/* What the user said: a rounded block on the right, as wide as its text needs. */
.message.user { width: fit-content; max-width: 80%; margin-left: auto; padding: 8px 14px; border-radius: 16px; background: var(--user-bg); }
/* A Reply: plain text across the full width. */
textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
}
button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
button:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }
