:root {
  color-scheme: dark;
  --bg: #14171e;
  --panel: #1b1f28;
  --raised: #232834;
  --border: #303644;
  --text: #e6e8ee;
  --muted: #8d95a5;
  --accent: #c4a574;
  --accent-ink: #1a160f;
  --tool: #c4a574;
  --result: #7f9e8a;
  --error: #c97a74;
  --z-base: 0;
  --z-grain: 1;
  --z-ui: 2;
  --font: "Outfit", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-family: var(--font);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: flex-start;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.skip-link {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: calc(var(--z-ui) + 1);
  transform: translateY(-140%);
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  transform: none;
}

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

.sidebar {
  position: relative;
  z-index: var(--z-ui);
  flex: 0 0 260px;
  width: 260px;
  height: 100dvh;
  display: flex;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.sidebar-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 14px 16px;
}

.sidebar .rail {
  display: none;
  flex: 0 0 48px;
  width: 48px;
  align-items: flex-start;
  justify-content: center;
  padding-top: 16px;
}

.sidebar.is-collapsed {
  flex-basis: 48px;
  width: 48px;
}

.sidebar.is-collapsed .sidebar-main {
  display: none;
}

.sidebar.is-collapsed .rail {
  display: flex;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sidebar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.25;
  text-wrap: balance;
}

.menu-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.menu-toggle:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.sidebar-threads-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.sidebar-new {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

#sidebar-close,
#new-thread {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  border-radius: 6px;
}

#sidebar-close {
  margin-top: 2px;
}

.sidebar-new:hover:not(:disabled) {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.sidebar-new:disabled {
  opacity: 0.55;
  cursor: default;
}

.sidebar-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.thread-item {
  appearance: none;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.8125rem;
  line-height: 1.35;
  cursor: pointer;
}

.thread-item:hover {
  background: var(--raised);
}

.thread-item.is-active {
  background: var(--raised);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.chat {
  position: relative;
  z-index: var(--z-ui);
  flex: 1;
  width: auto;
  max-width: 840px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  margin-inline: auto;
  padding: 20px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  gap: 18px;
}

.chat-header {
  padding-bottom: 4px;
}

.chat-header-copy {
  min-width: min(100%, 220px);
}

.chat-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.15;
  text-wrap: balance;
}

.graph-toggle {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
  margin-right: 2px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.graph-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--border);
  position: relative;
  transition: background 180ms ease-out, border-color 180ms ease-out;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 180ms ease-out;
}

.graph-toggle input:checked + .switch {
  background: color-mix(in srgb, var(--accent) 35%, var(--raised));
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.graph-toggle input:checked + .switch::after {
  transform: translateX(14px);
}

.graph-toggle input:focus-visible + .switch {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.graph {
  width: 100%;
  color: var(--muted);
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px 2px;
  box-shadow: 0 12px 28px color-mix(in srgb, var(--bg) 70%, transparent);
}

.graph[hidden] {
  display: none;
}

.graph-svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
}

.graph-svg .node rect {
  fill: var(--raised);
  stroke: var(--border);
  stroke-width: 1.5;
  transition: fill 150ms ease-out, stroke 150ms ease-out;
}

.graph-svg .node.terminal rect {
  stroke-dasharray: 3 3;
}

.graph-svg .node text {
  fill: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  text-anchor: middle;
}

.graph-svg .node.active rect {
  fill: color-mix(in srgb, var(--accent) 28%, var(--raised));
  stroke: var(--accent);
}

.graph-svg .node.active[data-id="tools"] rect {
  fill: color-mix(in srgb, var(--tool) 28%, var(--raised));
  stroke: var(--tool);
}

.graph-svg .edge {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
  transition: stroke 150ms ease-out;
}

.graph-svg .edge.conditional {
  stroke-dasharray: 5 4;
}

.graph-svg .edge.active {
  stroke: var(--accent);
  stroke-width: 2.5;
}

.graph-svg marker path {
  fill: var(--muted);
}

.history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 2px 8px;
}

.empty {
  margin: auto;
  align-self: center;
  width: min(100%, 40rem);
  padding: 8px 4px 24px;
  text-align: center;
}

.empty-asks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.empty h2 {
  margin: 0 0 20px;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
}

.empty button {
  appearance: none;
  background: var(--raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.empty button:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.empty button:active {
  transform: scale(0.98);
}

.empty button:focus-visible,
.composer input:focus-visible,
.composer button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.user-message {
  align-self: flex-end;
  max-width: 80%;
  background: var(--raised);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  border: 1px solid var(--border);
  border-right-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  white-space: pre-wrap;
  text-wrap: pretty;
}

.response {
  align-self: flex-start;
  width: min(100%, 40rem);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.response-tools,
.response-text,
.response-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.response-tools:empty,
.response-text:empty,
.response-results:empty {
  display: none;
}

.block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  white-space: pre-wrap;
  line-height: 1.55;
  text-wrap: pretty;
}

.block-text.draft {
  color: var(--muted);
}

.block-text.draft:empty::after {
  content: "…";
}

.block-tool-call {
  border-radius: 10px;
  border-color: color-mix(in srgb, var(--tool) 40%, var(--border));
}

.block-tool-call:not([open]) {
  padding-bottom: 6px;
}

.block-tool-call:not([open]) > summary {
  margin-bottom: 0;
}

.block-tool-call > summary {
  cursor: pointer;
  user-select: none;
  white-space: normal;
}

.block-tool-call[open] > .code {
  margin-top: 8px;
}

.block-tool-result {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 10px;
  border-radius: 10px;
  border-color: color-mix(in srgb, var(--result) 40%, var(--border));
}

.block-tool-result > .status {
  grid-column: 1;
  grid-row: 1;
  margin-bottom: 0;
}

.block-tool-result > .tool-json {
  display: contents;
}

.block-tool-result > .tool-json summary {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.block-tool-result > .weather {
  grid-column: 1 / -1;
  grid-row: 2;
  margin-bottom: 0;
}

.block-tool-result > .tool-json .code {
  grid-column: 1 / -1;
  grid-row: 3;
}

.block-error {
  border-color: var(--error);
  color: var(--error);
}

.block-tool-call.draft {
  color: var(--text);
  opacity: 0.78;
}

.weather {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 10px;
}

.weather-temp {
  font-size: 2.25rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.weather-temp sup {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
}

.weather-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.weather-cond {
  font-weight: 500;
}

.weather-city {
  color: var(--muted);
  font-size: 0.8125rem;
}

.tool-json summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  user-select: none;
  white-space: nowrap;
}

.tool-json .code {
  margin: 0;
}

.stream {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}

.stream-summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
  font-weight: 500;
}

.stream-list {
  margin: 8px 0 0;
  padding: 0 0 0 22px;
  max-height: 240px;
  overflow-y: auto;
  font-family: var(--mono);
}

.stream-item {
  display: grid;
  grid-template-columns: 170px 120px 1fr;
  gap: 8px;
  padding: 3px 0;
  color: var(--muted);
}

.stream-type,
.stream-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-item.is-model .stream-type {
  color: var(--accent);
}

.stream-item.is-tool .stream-type {
  color: var(--tool);
}

.stream-text {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.status {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

.block-tool-call .status {
  color: var(--tool);
}

.block-tool-result .status {
  color: var(--result);
}

.code {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: pre-wrap;
  word-break: break-word;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.composer input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9375rem;
}

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

.composer input:focus {
  outline: none;
}

.composer button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 10px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition-property: transform, filter;
  transition-duration: 150ms;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}

.send-icon {
  display: block;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}

.composer button:hover:not(:disabled) {
  filter: brightness(1.06);
}

.composer button:active:not(:disabled) {
  transform: scale(0.96);
}

.composer button:disabled,
.composer input:disabled {
  opacity: 0.55;
  cursor: default;
}

@media (max-width: 720px) {
  body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-basis: auto;
    height: auto;
    max-height: 36vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar.is-collapsed {
    width: 100%;
    flex-basis: 48px;
    max-height: 48px;
  }

  .sidebar .rail {
    width: 100%;
    justify-content: flex-start;
    padding: 10px 12px 0;
  }

  .chat {
    max-width: none;
    height: auto;
    min-height: 0;
    flex: 1;
  }
}

@media (max-width: 640px) {
  .stream-item {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
