:root {
  --paper: #eef2ef;
  --ink: #18211d;
  --muted: #5b6862;
  --rule: #cbd5cf;
  --link: #2b4acb;
  --wait: #a86a12;
  --error: #b3261e;
  --code-bg: #e2e8e4;
  --field: #ffffff;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.0625rem;
  --step-2: 1.375rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141917;
    --ink: #e4eae6;
    --muted: #94a39b;
    --rule: #2e3833;
    --link: #9db0ff;
    --wait: #e3a64b;
    --error: #ff8a80;
    --code-bg: #1f2622;
    --field: #1b211e;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.5;
}

a {
  color: var(--link);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Page frame ------------------------------------------------------ */

.page {
  max-width: 44rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
}

.masthead {
  padding: 3rem 0 2rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.new-chat {
  flex: none;
  margin-top: 0.125rem;
  font: inherit;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.375rem 0.75rem;
  cursor: pointer;
}

.new-chat:hover {
  border-color: var(--muted);
}

.masthead h1 {
  margin: 0 0 0.5rem;
  font-size: var(--step-2);
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.masthead p {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
}

.log {
  flex: 1;
  padding: 2rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 2.75rem;
}

.empty {
  margin: 0;
  color: var(--muted);
  max-width: 34rem;
}

/* ---- An exchange: question, status, answer, sources ------------------- */

.exchange {
  scroll-margin-top: 1.5rem;
}

.question {
  margin: 0;
  padding: 0.125rem 0 0.125rem 0.875rem;
  border-left: 3px solid var(--ink);
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.status {
  margin: 0.625rem 0 0;
  font-size: var(--step--1);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.answer + .status,
.sources + .status {
  margin-top: 0.75rem;
}

.status.waiting {
  color: var(--wait);
}

.status.waiting::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  vertical-align: 0.05em;
  animation: breathe 1.6s ease-in-out infinite;
}

.status.writing {
  display: none;
}

.status.error {
  color: var(--error);
}

.status.truncated {
  color: var(--wait);
}

@keyframes breathe {
  50% {
    opacity: 0.3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status.waiting::before {
    animation: none;
  }
}

.retry {
  margin-top: 0.5rem;
  font: inherit;
  font-size: var(--step--1);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.25rem 0.625rem;
  cursor: pointer;
}

.retry:hover {
  border-color: var(--muted);
}

/* Answers read like the blog's own prose. */
.answer {
  font-family: var(--serif);
  font-size: var(--step-1);
  line-height: 1.65;
  overflow-wrap: break-word;
}

.answer:not(:empty) {
  margin-top: 0.875rem;
}

.answer > :first-child {
  margin-top: 0;
}

.answer > :last-child {
  margin-bottom: 0;
}

.answer p,
.answer ul,
.answer ol {
  margin: 0 0 0.875em;
}

.answer ul,
.answer ol {
  padding-left: 1.25em;
}

.answer li + li {
  margin-top: 0.25em;
}

.answer h3,
.answer h4 {
  font-family: var(--sans);
  font-size: var(--step-0);
  font-weight: 650;
  margin: 1.25em 0 0.375em;
}

.answer code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

.answer pre {
  margin: 0 0 0.875em;
  padding: 0.75rem 0.875rem;
  background: var(--code-bg);
  border-radius: 4px;
  overflow-x: auto;
  line-height: 1.5;
}

.answer pre code {
  padding: 0;
  background: none;
  font-size: 0.8125rem;
}

.sources {
  margin-top: 1.125rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
}

.sources-label {
  margin: 0 0 0.25rem;
  font-size: var(--step--1);
  color: var(--muted);
}

.sources ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sources li {
  padding: 0.125rem 0;
}

.sources a {
  font-weight: 550;
}

/* ---- Composer -------------------------------------------------------- */

.composer {
  position: sticky;
  bottom: 0;
  background: var(--paper);
  padding: 0.75rem 0 max(0.75rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
}

.composer-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  font: inherit;
  font-size: 1rem; /* 16px avoids zoom-on-focus on iOS */
  line-height: 1.4;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.625rem 0.75rem;
  max-height: 200px;
}

.composer textarea:focus-visible {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 1px var(--link);
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer button[type="submit"] {
  flex: none;
  font: inherit;
  font-weight: 600;
  min-width: 4.5rem;
  min-height: 2.75rem;
  padding: 0 1rem;
  border-radius: 6px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}

.composer button[type="submit"].stop {
  background: transparent;
  color: var(--ink);
}

.hint {
  margin: 0.5rem 0 0;
  font-size: var(--step--1);
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.counter {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.counter.over {
  color: var(--error);
}

.hint a {
  color: inherit;
}

/* ---- Text pages (privacy) --------------------------------------------- */

.doc {
  padding: 1.5rem 0 4rem;
  max-width: 38rem;
  font-family: var(--serif);
  font-size: var(--step-1);
  line-height: 1.65;
}

.doc h2 {
  font-family: var(--sans);
  font-size: var(--step-0);
  font-weight: 650;
  margin: 2rem 0 0.5rem;
}

.doc h2:first-child {
  margin-top: 0;
}

.doc p,
.doc ul {
  margin: 0 0 0.875em;
}

.doc ul {
  padding-left: 1.25em;
}

.noscript {
  max-width: 44rem;
  margin: 1rem auto;
  padding: 0 16px;
}
