:root {
  --berry: #a3123f;
  --berry-strong: #7d0b2f;
  --berry-soft: #f6dde5;
  --leaf: #4f8a52;
  --paper: #fdf9fa;
  --ink: #241319;
  --ink-muted: #6e5a61;
  --line: #ecdde2;
  --danger: #b3261e;
  --on-berry: #fff4f7;
  --topbar: #a3123f;
  --on-topbar: #fff4f7;

  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-3: 2.25rem;
  --step-4: clamp(2.5rem, 9vw, 4rem);
  --measure: 40rem;
  --gutter: 16px;
  --radius-small: 10px;
  --radius-large: 22px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --berry: #e2567f;
    --berry-strong: #f07b9c;
    --berry-soft: #3b1824;
    --leaf: #7dbb7f;
    --paper: #1b1014;
    --ink: #f6e9ee;
    --ink-muted: #b79fa8;
    --line: #3a242d;
    --danger: #ff8a80;
    --on-berry: #1b1014;
    --topbar: #5c0d27;
    --on-topbar: #fbe3ea;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --berry: #e2567f;
  --berry-strong: #f07b9c;
  --berry-soft: #3b1824;
  --leaf: #7dbb7f;
  --paper: #1b1014;
  --ink: #f6e9ee;
  --ink-muted: #b79fa8;
  --line: #3a242d;
  --danger: #ff8a80;
  --on-berry: #1b1014;
  --topbar: #5c0d27;
  --on-topbar: #fbe3ea;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--berry); outline-offset: 2px; }

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

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Buttons */
.button {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.4rem;
  font-weight: 650;
}
.button--primary { background: var(--berry); color: var(--on-berry); }
.button--primary:hover { background: var(--berry-strong); }
.button--quiet { align-self: flex-start; background: transparent; color: var(--ink-muted); padding-inline: 0; text-decoration: underline; text-underline-offset: 3px; }

.icon-button {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent; color: inherit;
}
.icon-button:hover { background: rgb(255 255 255 / 0.14); }

/* Login */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: var(--gutter);
}
.login__form {
  width: min(100%, 24rem);
  display: grid;
  gap: 1rem;
}
.login__title {
  margin: 0;
  font-size: var(--step-4);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--berry);
  font-variation-settings: "opsz" 96;
}
.login__lede { margin: 0 0 0.5rem; color: var(--ink-muted); }
.login__error { margin: 0; min-height: 1.5em; color: var(--danger); font-size: var(--step--1); }

.field { display: grid; gap: 0.35rem; }
.field__label { font-weight: 600; font-size: var(--step--1); }
.field input {
  padding: 0.75rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-small);
  background: transparent;
}
.field input:focus-visible { outline: none; border-color: var(--berry); }

/* App shell */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr auto 44px;
  align-items: center;
  gap: 0.25rem;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 10px;
  background: var(--topbar);
  color: var(--on-topbar);
}
.topbar__name {
  font-size: var(--step-1);
  font-weight: 800;
  letter-spacing: -0.02em;
  padding-left: 4px;
}
.topbar__status {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}
.topbar__temp { font-weight: 650; }

/* The thermometer: the Pi's real CPU temperature, 40–85 °C */
.thermo {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: rgb(0 0 0 / 0.18);
}
.thermo__fill {
  height: 100%;
  width: 0;
  background: var(--thermo-color, var(--leaf));
  transition: width 1.2s ease, background-color 1.2s ease;
}
.app[data-state="writing"] .thermo__fill { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.55; } }

/* Conversation */
.scroller {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.5rem var(--gutter) 1rem;
}

.empty {
  max-width: var(--measure);
  margin: 8vh auto 0;
}
.empty__title {
  margin: 0 0 0.75rem;
  font-size: var(--step-4);
  font-weight: 800;
  line-height: 0.98;
  letter-spacing: -0.035em;
  color: var(--berry);
  font-variation-settings: "opsz" 96;
}
.empty__body { margin: 0 0 1.75rem; color: var(--ink-muted); max-width: 34rem; }
.empty__ideas { display: grid; gap: 0.5rem; }
.idea {
  text-align: left;
  padding: 0.8rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-small);
  background: transparent;
}
.idea:hover { border-color: var(--berry); }

.messages {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: var(--measure);
  display: grid;
  gap: 1.5rem;
}

.message--user {
  justify-self: end;
  max-width: 85%;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-large) var(--radius-large) 6px var(--radius-large);
  background: var(--berry-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message--assistant { overflow-wrap: anywhere; }
.message__body > :first-child { margin-top: 0; }
.message__body > :last-child { margin-bottom: 0; }
.message__body p, .message__body ul, .message__body ol { margin: 0 0 0.8em; }
.message__body ul, .message__body ol { padding-left: 1.3em; }
.message__body h1, .message__body h2, .message__body h3 { font-size: var(--step-1); line-height: 1.25; margin: 1.2em 0 0.4em; }
.message__body a { color: var(--berry); }
.message__body code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--berry-soft);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
.message__body pre {
  overflow-x: auto;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-small);
  background: var(--berry-soft);
}
.message__body pre code { background: none; padding: 0; }
.message__body table { border-collapse: collapse; display: block; overflow-x: auto; }
.message__body th, .message__body td { border: 1px solid var(--line); padding: 0.35em 0.6em; }

/* The writing cursor sits at the end of the text while tokens arrive */
.message--writing .message__body > :last-child::after {
  content: "";
  display: inline-block;
  width: 0.5em; height: 1em;
  margin-left: 2px;
  vertical-align: -0.12em;
  background: var(--berry);
  border-radius: 2px;
}

/* Pages the model looked at, folded away under the answer */
.sources {
  margin-top: 0.75rem;
  font-size: var(--step--1);
}
.sources summary {
  cursor: pointer;
  color: var(--berry);
  font-weight: 650;
  width: fit-content;
}
.sources ul {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}
.sources a {
  display: grid;
  color: inherit;
  text-decoration: none;
  padding-left: 0.75rem;
  border-left: 2px solid var(--line);
  overflow-wrap: anywhere;
}
.sources a:hover { border-left-color: var(--berry); }
.sources__site { color: var(--ink-muted); font-size: 0.85em; }

.message__meta {
  margin: 0.5rem 0 0;
  font-size: var(--step--1);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.message__meta--error { color: var(--danger); }
.message__retry {
  margin-left: 0.5rem;
  border: 0; background: none; padding: 0;
  color: var(--berry); font-weight: 650;
  text-decoration: underline; text-underline-offset: 3px;
}

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0.5rem var(--gutter) calc(env(safe-area-inset-bottom) + 0.75rem);
}
.composer textarea {
  flex: 1;
  min-height: 48px;
  max-height: 40vh;
  resize: none;
  padding: 0.7rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  line-height: 1.4;
  /* 16px+ stops iOS zooming in on focus */
  font-size: max(16px, var(--step-0));
}
.composer textarea:focus-visible { outline: none; border-color: var(--berry); }
.send {
  flex: none;
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border: 0; border-radius: 50%;
  background: var(--berry);
  color: var(--on-berry);
}
.send:disabled { opacity: 0.4; cursor: default; }
.send--stop { background: var(--ink); color: var(--paper); }

/* Chats drawer */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgb(20 6 11 / 0.45);
}
.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(86vw, 22rem);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: calc(env(safe-area-inset-top) + 8px) var(--gutter) calc(env(safe-area-inset-bottom) + 16px);
  background: var(--paper);
  border-right: 1px solid var(--line);
  animation: slide-in 0.22s ease-out;
}
@keyframes slide-in { from { transform: translateX(-100%); } }
.drawer__head { display: flex; align-items: center; justify-content: space-between; }
.drawer__head .icon-button:hover { background: var(--berry-soft); }
.drawer__title { margin: 0; font-size: var(--step-1); font-weight: 800; letter-spacing: -0.02em; }
.drawer__note { margin: 0 0 0.5rem; font-size: var(--step--1); color: var(--ink-muted); }

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list__item { display: flex; align-items: center; border-radius: var(--radius-small); }
.chat-list__item[aria-current="true"] { background: var(--berry-soft); }
.chat-list__open {
  flex: 1; min-width: 0;
  text-align: left;
  border: 0; background: none;
  padding: 0.7rem 0.6rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-list__delete { color: var(--ink-muted); }
.chat-list__delete:hover { color: var(--danger); background: transparent; }
.chat-list__empty { color: var(--ink-muted); font-size: var(--step--1); padding: 0.6rem; }

@media (min-width: 720px) {
  .scroller { padding-top: 2.5rem; }
  .empty__ideas { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .app[data-state="writing"] .thermo__fill { animation: none; }
  .drawer { animation: none; }
  .thermo__fill { transition: none; }
}
