:root {
  --chat-space-xs: 0.5rem;
  --chat-space-sm: 0.75rem;
  --chat-space-md: 1rem;
  --chat-space-lg: 1.5rem;
  --chat-space-xl: 2rem;
  --chat-space-2xl: 3rem;
}

.chat-nav .is-current {
  color: var(--moss-dark);
  font-weight: 700;
}

.chat-conversation {
  min-width: 0;
  padding-top: 1.5rem;
}

.chat-intro {
  max-width: 44rem;
}

.chat-intro h1 {
  margin: 0.55rem 0 0.75rem;
  font-family: var(--serif);
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.chat-intro > p:last-child,
.chat-avatar-note {
  max-width: 42rem;
  margin: 0;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.7;
  text-wrap: pretty;
}

.chat-avatar-caption h2 {
  font-size: 1.75rem;
}

.chat-mode-picker {
  margin: 2rem 0 0;
  padding: 0 0 1.5rem;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.chat-mode-picker legend,
.chat-preferences legend {
  padding: 0;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink);
}

.chat-mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chat-mode-options label {
  position: relative;
  cursor: pointer;
}

.chat-mode-options input,
.chat-preferences-content fieldset input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.chat-mode-options span {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 650;
  transition: background 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out;
}

.chat-mode-options label:hover span {
  border-color: #9aaca1;
  color: var(--moss-dark);
}

.chat-mode-options input:checked + span {
  border-color: var(--moss-dark);
  color: white;
  background: var(--moss-dark);
}

.chat-mode-options input:focus-visible + span,
.chat-preferences-content fieldset input:focus-visible + span {
  outline: 3px solid rgba(82, 108, 93, 0.32);
  outline-offset: 3px;
}

.chat-mode-help {
  margin: 0.65rem 0 0;
  color: var(--ink-soft);
  font-size: 0.8125rem;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 13rem;
  max-height: min(48rem, 62vh);
  overflow-y: auto;
  margin-top: 1.5rem;
  padding: 0.25rem 0.25rem 1rem;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-turn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  width: min(100%, 42rem);
}

.chat-turn.is-user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-speaker {
  padding: 0 0.2rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 700;
}

.chat-bubble {
  max-width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(82, 98, 91, 0.18);
  border-radius: 1rem;
  background: var(--surface-strong);
}

.chat-turn.is-user .chat-bubble {
  border-color: rgba(82, 108, 93, 0.2);
  background: var(--moss-pale);
}

.chat-bubble p {
  max-width: 68ch;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.7;
}

.chat-follow-up {
  margin-top: 0.65rem !important;
  color: var(--moss-dark);
  font-weight: 650;
}

.chat-reflection,
.chat-practice,
.chat-sources,
.chat-memory-proposals {
  width: 100%;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.chat-reflection strong,
.chat-practice strong,
.chat-sources > strong,
.chat-memory-proposals > strong {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.875rem;
}

.chat-reflection ul,
.chat-practice ol,
.chat-sources ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.chat-reflection li + li,
.chat-practice li + li,
.chat-sources li + li {
  margin-top: 0.35rem;
}

.chat-sources a {
  color: var(--moss-dark);
  font-weight: 650;
  text-underline-offset: 0.18em;
}

.chat-source-meta {
  display: block;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.chat-memory-proposal-note {
  margin-bottom: 0.65rem !important;
  color: var(--ink-soft);
  font-size: 0.78rem !important;
}

.chat-memory-proposal-list {
  display: grid;
  gap: 0.5rem;
}

.chat-memory-proposal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--surface);
}

.chat-memory-proposal strong {
  display: block;
  font-size: 0.82rem;
}

.chat-memory-proposal p {
  margin-top: 0.15rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
  line-height: 1.45;
}

.chat-memory-save {
  min-width: 4.5rem;
  min-height: 2.4rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--moss-dark);
  border-radius: 999px;
  color: var(--moss-dark);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.chat-memory-save:hover:not(:disabled) {
  color: white;
  background: var(--moss-dark);
}

.chat-memory-save:disabled {
  cursor: default;
  opacity: 0.7;
}

.chat-turn.is-pending .chat-bubble {
  min-width: 7.5rem;
  color: var(--ink-soft);
}

.chat-thinking-dots {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  height: 1.5rem;
}

.chat-thinking-dots span {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: currentColor;
  animation: chat-thinking 900ms ease-in-out infinite alternate;
}

.chat-thinking-dots span:nth-child(2) { animation-delay: 120ms; }
.chat-thinking-dots span:nth-child(3) { animation-delay: 240ms; }

@keyframes chat-thinking {
  from { opacity: 0.35; transform: translateY(0); }
  to { opacity: 0.9; transform: translateY(-0.2rem); }
}

.chat-composer {
  margin-top: 1rem;
  border-radius: 1rem;
  box-shadow: none;
}

.chat-composer textarea {
  min-height: 8.5rem;
}

.chat-quick-starts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chat-quick-starts button {
  min-height: 2.75rem;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-soft);
  background: var(--surface);
  font-size: 0.8125rem;
  font-weight: 650;
}

.chat-quick-starts button:hover {
  border-color: #9aaca1;
  color: var(--moss-dark);
  background: var(--moss-pale);
}

.chat-preferences {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
}

.chat-preferences summary {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  cursor: pointer;
  color: var(--moss-dark);
  font-size: 0.875rem;
  font-weight: 700;
}

.chat-preferences-content {
  display: grid;
  gap: 1rem;
  padding: 0.25rem 0 0.75rem;
}

.chat-preferences-content fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.chat-preferences-content fieldset legend {
  grid-column: 1 / -1;
  margin-bottom: 0.25rem;
}

.chat-preferences-content fieldset label {
  position: relative;
  cursor: pointer;
}

.chat-preferences-content fieldset label > span {
  display: flex;
  min-height: 4.3rem;
  flex-direction: column;
  justify-content: center;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--surface);
  transition: border-color 180ms ease-out, background 180ms ease-out;
}

.chat-preferences-content fieldset input:checked + span {
  border-color: var(--moss-dark);
  background: var(--moss-pale);
}

.chat-preferences-content strong {
  font-size: 0.875rem;
}

.chat-preferences-content small {
  margin-top: 0.15rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
  line-height: 1.45;
}

.chat-memory-choice {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  cursor: pointer;
}

.chat-memory-choice input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0.15rem 0 0;
  accent-color: var(--moss-dark);
}

.chat-memory-choice span {
  display: flex;
  flex-direction: column;
}

.chat-account-memory-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8125rem;
}

.chat-account-memory-note a {
  color: var(--moss-dark);
  font-weight: 700;
  text-underline-offset: 0.16em;
}

.chat-composer-actions {
  align-items: flex-end;
}

.chat-composer-actions .privacy-note {
  max-width: 34rem;
}

.chat-boundary {
  margin-top: 1.5rem;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
}

.chat-boundary strong {
  color: var(--ink);
  font-size: 0.875rem;
}

.chat-boundary p {
  max-width: 65ch;
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
}

.chat-empty-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

@media (max-width: 1080px) {
  .chat-shell {
    grid-template-columns: minmax(15rem, 0.72fr) minmax(0, 1.28fr);
    gap: 2rem;
  }

  .chat-secondary-link {
    display: none;
  }
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
  }

  .chat-nav {
    max-width: 65%;
    overflow-x: auto;
    justify-content: flex-end;
    padding-bottom: 0.25rem;
    white-space: nowrap;
    scrollbar-width: none;
  }

  .chat-nav::-webkit-scrollbar { display: none; }

  .chat-nav .text-button {
    min-height: 2.75rem;
    flex: 0 0 auto;
  }

  .chat-shell {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1rem;
  }

  .chat-shell .avatar-stage {
    position: static;
    width: min(100%, 28rem);
    margin-inline: auto;
  }

  .chat-shell .avatar-frame {
    aspect-ratio: 16 / 10;
  }

  .chat-shell .avatar-frame img,
  .chat-shell .avatar-frame video {
    object-position: center 18%;
  }

  .chat-avatar-caption {
    padding: 1rem 0.25rem 0;
  }

  .chat-avatar-caption h2 {
    font-size: 1.45rem;
  }

  .chat-intro h1 {
    font-size: 2rem;
  }

  .chat-conversation {
    padding-top: 0;
  }

  .chat-thread {
    max-height: none;
    min-height: 11rem;
  }
}

@media (max-width: 560px) {
  .brand-copy small { display: none; }
  .brand-seal { width: 2.5rem; height: 2.5rem; }
  .chat-nav { max-width: calc(100% - 3.25rem); }
  .chat-nav .text-button { padding-inline: 0.45rem; font-size: 0.8125rem; }

  .chat-shell .avatar-frame {
    aspect-ratio: 16 / 9;
    border-radius: 1rem;
  }

  .chat-shell .avatar-caption {
    display: none;
  }

  .chat-mode-picker {
    margin-top: 1.5rem;
  }

  .chat-mode-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-mode-options span {
    width: 100%;
    justify-content: center;
  }

  .chat-mode-options label:first-child {
    grid-column: 1 / -1;
  }

  .chat-composer {
    margin-inline: -0.25rem;
    padding: 1rem;
  }

  .chat-composer textarea {
    min-height: 7.5rem;
    padding-right: 4.5rem;
  }

  .chat-preferences-content fieldset {
    grid-template-columns: 1fr;
  }

  .chat-composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-composer-actions .primary-button {
    width: 100%;
  }

  .chat-quick-starts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-quick-starts button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .chat-mode-options span,
  .chat-preferences-content fieldset label > span { transition: none; }
  .chat-thinking-dots span { animation: none; opacity: 0.7; transform: none; }
}
