/* The chat: a conversation with the reading list, on the same stage as the rest
 * of the site. The composer stays at the foot of the viewport like any chat. */
.chat { isolation: isolate; padding: clamp(2rem, 5vw, 3.5rem) var(--gutter) 2.5rem; }
.chat__inner { max-width: 800px; margin-inline: auto; }

/* Intro, in the stage voice; it steps back once the conversation starts. */
.chat__intro { padding-bottom: 2rem; }
.chat__kicker { margin-bottom: 1rem; font-weight: 700; font-size: 1rem; color: var(--cyan); }
.chat__title { display: flex; flex-direction: column; line-height: 1.02; letter-spacing: -0.02em; }
.chat__title-line { font-size: clamp(1.8rem, 4vw, 2.6rem); font-style: italic; font-weight: 400; color: var(--ink-3); }
.chat__title-big { font-size: clamp(2.6rem, 7vw, 4.4rem); font-weight: 800; color: var(--ink); }
.chat__punct { color: var(--amber); }
.chat__lede { max-width: 54ch; margin-top: 1.2rem; font-size: 1.0625rem; color: var(--ink-2); }
.chat[data-active] .chat__intro { padding-bottom: 1.25rem; }
.chat[data-active] .chat__kicker,
.chat[data-active] .chat__lede { display: none; }
.chat[data-active] .chat__title { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 0.3em; }
.chat[data-active] .chat__title-line,
.chat[data-active] .chat__title-big { font-size: clamp(1.5rem, 3.5vw, 1.9rem); }

/* Scope and new chat, one quiet row. */
.chat__toolbar { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem 1rem; padding-block: 1rem; border-block: 1px solid var(--border-strong); }
.chat__scope { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.75rem; min-width: 0; }
.chat__scope label { font-size: 0.92rem; color: var(--ink-3); }
.chat__scope select {
  min-width: 0;
  max-width: 100%;
  min-height: 40px;
  padding: 0.4rem 2.2rem 0.4rem 0.95rem;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-pill);
  background: var(--input-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.8rem center / 14px;
  font-size: 1rem;
  font-weight: 500;
  appearance: none;
  cursor: pointer;
}
.chat__scope-note { flex-basis: 100%; font-size: 0.85rem; color: var(--ink-4); }
.chat:not([data-active]) .chat__scope-note { display: none; }

.chat__button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex-shrink: 0;
  min-height: 40px;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-pill);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--dur-micro), color var(--dur-micro), border-color var(--dur-micro);
}
.chat__button svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.chat__button--quiet { border: 1px solid var(--border-strong); background: transparent; color: var(--ink-2); }
@media (hover: hover) {
  .chat__button--quiet:hover { border-color: var(--ink-4); color: var(--ink); }
}
.chat__button:disabled, .chat__starters button:disabled { cursor: default; opacity: 0.55; }

/* Starters: cards to tap. */
.chat__welcome { padding-block: 2.25rem 1rem; }
.chat__welcome h2 { font-size: clamp(1.5rem, 3.5vw, 1.9rem); font-weight: 700; letter-spacing: -0.015em; }
.chat__starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.75rem; margin-top: 1.25rem; }
.chat__starters button {
  width: 100%;
  height: 100%;
  min-height: 4.5rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 1rem;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur-micro), color var(--dur-micro), background-color var(--dur-micro);
}
@media (hover: hover) {
  .chat__starters button:hover:not(:disabled) { border-color: var(--cyan); color: var(--ink); background: var(--surface-2); }
}

/* Messages */
.chat__transcript { display: grid; gap: 2rem; padding-top: 2rem; }
.chat__transcript:empty { display: none; }
.chat__message { min-width: 0; overflow-wrap: anywhere; }
.chat__message--user { justify-self: end; max-width: min(85%, 36rem); padding: 0.8rem 1.1rem; border-radius: 18px 18px 4px 18px; background: var(--surface-3); }
.chat__message--user .chat__text { color: var(--ink); white-space: pre-wrap; line-height: 1.55; }
.chat__speaker { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; font-size: 0.85rem; font-weight: 700; color: var(--ink-3); }
.chat__speaker img { width: 20px; height: 20px; }
.chat__text { font-size: 1.0625rem; line-height: 1.75; color: var(--ink-2); }
.chat__text > * + * { margin-top: 0.9em; }
.chat__text p { white-space: pre-line; }
.chat__text ol, .chat__text ul { display: grid; gap: 0.5em; padding-left: 1.4em; }
.chat__text ol { list-style: decimal; }
.chat__text ul { list-style: disc; }
.chat__text li::marker { color: var(--ink-4); font-variant-numeric: tabular-nums; }
.chat__citation {
  display: inline-grid;
  place-items: center;
  min-width: 1.35rem;
  height: 1.35rem;
  margin-inline: 0.15rem;
  padding: 0 0.3rem;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--cyan) 16%, transparent);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  vertical-align: 0.15em;
}
@media (hover: hover) {
  .chat__citation:hover { background: var(--cyan); color: var(--bg); }
}

.chat__typing { display: inline-flex; gap: 0.3rem; padding-block: 0.6rem; animation: chatFade 200ms var(--ease) 150ms both; }
.chat__typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-4); animation: chatTyping 1.2s ease-in-out infinite; }
.chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.chat__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTyping {
  0%, 60%, 100% { opacity: 0.35; transform: none; }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* A cited bookmark: a card in the digest's own voice (serif title, italic note,
 * the topic on top), so the finds stand apart from the answer's prose. */
.chat-cards { display: grid; gap: 0.6rem; }
.chat-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.85rem;
  padding: 0.95rem 1.1rem;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--cyan);
  border-radius: var(--radius);
  background: var(--surface);
  line-height: 1.45;
}
.chat-card__number { padding-top: 0.15rem; font-family: var(--font-mono); font-size: 0.75rem; color: var(--cyan); font-variant-numeric: tabular-nums; }
.chat-card__body { min-width: 0; }
.chat-card__topic { margin-bottom: 0.2rem; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--cyan); }
.chat-card__title { font-family: var(--font-serif); font-size: 1.12rem; font-weight: 700; line-height: 1.3; }
.chat-card__title a { color: var(--ink); text-decoration: none; }
.chat-card__title a::after { content: ' ↗'; font-family: var(--font-sans); font-size: 0.8em; font-weight: 400; color: var(--ink-4); }
@media (hover: hover) {
  .chat-card__title a:hover { color: var(--cyan); text-decoration: underline; text-decoration-thickness: 1px; }
}
.chat-card__note { margin-top: 0.4rem; font-family: var(--font-serif); font-style: italic; font-size: 0.98rem; line-height: 1.5; color: var(--ink-2); }
.chat-card__meta { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-top: 0.55rem; font-size: 0.8rem; color: var(--ink-4); }
.chat-card__meta a { color: var(--ink-3); }
@media (hover: hover) {
  .chat-card__meta a:hover { color: var(--ink); }
}
.chat__message-note { margin-top: 0.75rem; font-size: 0.9rem; color: var(--amber); }
.chat__message-note:empty { display: none; }
.chat__context-note { margin-top: 1.5rem; font-size: 0.9rem; color: var(--ink-3); }

/* Composer, sticky at the foot of the viewport. */
.chat__composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-top: 2rem;
  padding: 1.25rem 0 0.75rem;
  background: linear-gradient(to bottom, transparent, var(--bg) 1.25rem);
}
.chat__box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.45rem 0.45rem 0.45rem 1.1rem;
  border: 1px solid var(--input-border);
  border-radius: 26px;
  background: var(--input-bg);
  transition: border-color var(--dur-micro), box-shadow var(--dur-micro);
}
.chat__box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.chat__box textarea {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  max-height: 40vh;
  padding: 0.55rem 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.0625rem;
  line-height: 1.45;
  resize: none;
  outline: none;
}
.chat__box textarea::placeholder { color: var(--ink-4); }
.chat__controls { display: flex; align-items: center; gap: 0.4rem; }
.chat__icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color var(--dur-micro), opacity var(--dur-micro);
}
.chat__icon-button svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chat__icon-button--send { background: var(--burgundy); color: var(--on-accent); }
@media (hover: hover) {
  .chat__icon-button--send:hover:not(:disabled) { background: var(--burgundy-hover); }
}
.chat__icon-button--stop { background: var(--ink); color: var(--bg); }
.chat__icon-button--stop svg { fill: currentColor; stroke: none; }
.chat__icon-button:disabled { cursor: default; opacity: 0.45; }
.chat__composer-foot { display: flex; justify-content: space-between; gap: 1rem; padding: 0.5rem 1.1rem 0; font-size: 0.82rem; color: var(--ink-4); }
.chat__status { flex: 1; min-width: 0; min-height: 1.4em; color: var(--ink-3); }
.chat__keyboard { flex-shrink: 0; }
@media (hover: none), (max-width: 600px) {
  .chat__keyboard { display: none; }
}

.chat__privacy { max-width: 72ch; margin-top: 1rem; font-size: 0.85rem; color: var(--ink-4); }
.chat__noscript { margin-top: 1rem; color: var(--amber); }
.chat__back { padding-top: 1.75rem; font-size: 0.95rem; }
.chat__back a { text-decoration: none; }
@media (hover: hover) {
  .chat__back a:hover { text-decoration: underline; }
}

/* The site footer sits under the chat; keep it close. */
main:has(> .chat) + .foot { margin-top: 2rem; }

@media (max-width: 600px) {
  .chat { padding-top: 1.75rem; }
  .chat__intro { padding-bottom: 1.5rem; }
  .chat__lede { font-size: 1rem; }
  .chat__scope { flex: 1 1 100%; }
  .chat__scope select { flex: 1; }
  .chat__starters { grid-template-columns: minmax(0, 1fr); gap: 0.6rem; margin-top: 1rem; }
  .chat__starters button { min-height: 0; }
  .chat__welcome { padding-top: 1.75rem; }
  .chat__composer-foot { padding-inline: 0.5rem; }
  .chat__message--user { max-width: 90%; }
}
@media (pointer: coarse) {
  .chat__button { min-height: 44px; }
  .chat__icon-button::after { content: ''; position: absolute; inset: -3px; }
}

/* --------------------------------------------------------------------------
   The side panel on a week's page
   -------------------------------------------------------------------------- */
.chat-panel {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 60;
  width: min(440px, 100vw);
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--ink);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.35);
}
.chat-panel[open] { display: block; }

/* The panel slides in from the edge and back out. It opens a little slower than it
 * closes, both on a decelerating sheet curve; allow-discrete keeps it rendered (and in
 * the top layer, on phones) until the exit finishes. Browsers without it skip the exit. */
.chat-panel {
  --drawer-ease: cubic-bezier(0.32, 0.72, 0, 1);
  translate: 100% 0;
  transition: translate 220ms var(--drawer-ease), display 220ms allow-discrete, overlay 220ms allow-discrete;
}
.chat-panel[open] { translate: 0 0; transition-duration: 320ms; }
@starting-style {
  .chat-panel[open] { translate: 100% 0; }
}
.chat-panel::backdrop {
  background: rgba(0, 0, 0, 0);
  transition: background-color 220ms var(--drawer-ease), display 220ms allow-discrete, overlay 220ms allow-discrete;
}
.chat-panel[open]::backdrop { background: rgba(0, 0, 0, 0.55); transition-duration: 320ms; }
@starting-style {
  .chat-panel[open]::backdrop { background: rgba(0, 0, 0, 0); }
}
/* Wide screens keep the digest readable beside the open panel, easing room open with it. */
@media (min-width: 1100px) {
  body { transition: padding-right 280ms cubic-bezier(0.32, 0.72, 0, 1); }
  html[data-chat-open] body { padding-right: 440px; }
}
@media (max-width: 899px) {
  .chat-panel { width: 100vw; border-left: 0; box-shadow: none; }
}

.chat--panel { display: flex; flex-direction: column; height: 100%; padding: 0; }
.chat-panel__head { display: flex; align-items: center; gap: 0.5rem; padding: 0.85rem 0.9rem 0.85rem 1.25rem; border-bottom: 1px solid var(--border); }
.chat-panel__heading { flex: 1; min-width: 0; }
.chat-panel__kicker { font-size: 0.8rem; font-weight: 700; color: var(--cyan); }
.chat-panel__title { font-size: 1.2rem; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.chat-panel__close { border: 1px solid var(--border-strong); background: transparent; color: var(--ink-2); }
@media (hover: hover) {
  .chat-panel__close:hover { border-color: var(--ink-4); color: var(--ink); }
}
.chat-panel__scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 1.25rem 1.25rem; }
.chat--panel .chat__welcome { padding-top: 1.5rem; }
.chat--panel .chat__welcome h2 { font-size: 1.35rem; }
.chat--panel .chat__starters { grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
.chat--panel .chat__starters button { min-height: 0; }
.chat--panel .chat__transcript { gap: 1.5rem; padding-top: 1.5rem; }
.chat--panel .chat__message--user { max-width: 90%; }
.chat--panel .chat__text { font-size: 1rem; }
.chat--panel .chat__composer { position: static; margin: 0; padding: 0.75rem 0.9rem 0.4rem; border-top: 1px solid var(--border); background: var(--bg); }
.chat--panel .chat__keyboard { display: none; }
.chat--panel .chat__composer-foot { padding-inline: 0.5rem; }
.chat-panel__privacy { margin: 0; padding: 0 1.4rem max(0.8rem, env(safe-area-inset-bottom)); font-size: 0.75rem; }

/* --------------------------------------------------------------------------
   Motion: each thing enters once, quickly, decelerating. base.css cuts all of
   it under reduced motion, and chat.js then shows text as it arrives.
   -------------------------------------------------------------------------- */
.chat__message--user { transform-origin: 100% 100%; animation: chatBubble 220ms var(--ease) both; }
.chat__message--assistant .chat__speaker { animation: chatFade 200ms var(--ease) both; }
.chat-card { animation: chatRise 280ms var(--ease) both; }
@keyframes chatFade { from { opacity: 0; } }
@keyframes chatBubble { from { opacity: 0; transform: translateY(6px) scale(0.96); } }
@keyframes chatRise { from { opacity: 0; transform: translateY(8px); } }

/* Where the text is still arriving. */
.chat__caret {
  display: inline-block;
  width: 0.45em;
  height: 1.05em;
  margin-left: 0.15em;
  border-radius: 2px;
  background: var(--cyan);
  opacity: 0.65;
  vertical-align: -0.17em;
}

/* Press feedback. */
.chat__starters button,
.chat__icon-button,
.chat__button { transition-property: background-color, color, border-color, opacity, transform; transition-duration: 120ms; transition-timing-function: var(--ease); }
.chat__starters button:active:not(:disabled) { transform: scale(0.98); }
.chat__icon-button:active:not(:disabled) { transform: scale(0.92); }
.chat__button:active:not(:disabled) { transform: scale(0.97); }
