@layer content {
.rich-content-host {
  min-width: 0;
  max-width: 100%;
  overflow: visible;
  container-type: inline-size;
}

.rich-content {
  min-width: 0;
  color: var(--text-primary);
  font-size: .94rem;
  line-height: 1.75;
  overflow-wrap: anywhere;
  white-space: normal;
}

.rich-content > :first-child { margin-top: 0; }
.rich-content > :last-child { margin-bottom: 0; }

.rich-content :where(h2, h3, h4, h5, h6) {
  max-width: 38ch;
  margin: 1.5em 0 .55em;
  color: var(--text-primary);
  letter-spacing: -.025em;
  line-height: 1.25;
}

.rich-content h2 { font-size: clamp(1.22rem, 1.05rem + .5vw, 1.56rem); }
.rich-content h3 { font-size: clamp(1.08rem, 1rem + .3vw, 1.3rem); }
.rich-content :where(h4, h5, h6) { font-size: 1rem; }

.rich-content :where(p, ul, ol, blockquote, pre, table, figure, .rich-math) {
  margin: .82em 0;
}

.rich-content :where(ul, ol) {
  padding-inline-start: 1.45rem;
}

.rich-content li + li { margin-top: .28rem; }

.rich-content blockquote {
  padding: .08rem 0 .08rem 1rem;
  border-inline-start: 2px solid color-mix(in srgb, var(--accent-fg) 58%, transparent);
  color: var(--text-secondary);
}

.rich-content a {
  color: var(--accent-fg);
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset: .18em;
}

.rich-content a:hover { text-decoration-color: currentColor; }

.rich-content :not(pre) > code,
.rich-content .rich-math-source {
  padding: .12em .38em;
  border-radius: var(--radius-xs);
  background: var(--surface-field);
  font: .88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.rich-content .rich-code,
.rich-content table,
.rich-content .rich-math-block {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

.rich-content .rich-code {
  padding: clamp(.8rem, 2vw, 1.05rem);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  background: var(--surface-field);
  color: var(--text-primary);
  white-space: pre;
  overflow-wrap: normal;
  tab-size: 2;
}

.rich-content .rich-code code {
  font: .84rem/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.rich-content table {
  display: block;
  width: max-content;
  min-width: min(100%, 32rem);
  max-width: 100%;
  border-collapse: collapse;
}

.rich-table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}

.rich-part-plain {
  margin: .75rem 0;
  white-space: pre-wrap;
  font: inherit;
}

.rich-content-compact,
.rich-content-message { line-height: 1.62; }
.rich-content-message { font-size: .9rem; }

.rich-content :where(th, td) {
  min-width: 7rem;
  padding: .6rem .7rem;
  border-bottom: 1px solid var(--divider);
  text-align: start;
  vertical-align: top;
}

.rich-content th {
  color: var(--text-secondary);
  font-size: .78rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.rich-task-marker {
  display: inline-grid;
  width: 1.15em;
  place-items: center;
  margin-inline-end: .35em;
  color: var(--accent-fg);
}

.rich-media {
  width: min(100%, 62rem);
}

.rich-media :where(img, video),
.rich-pdf-frame {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--surface-field);
}

.rich-media img {
  height: auto;
  max-height: min(68vh, 50rem);
  object-fit: contain;
}

.rich-media video { max-height: min(68vh, 44rem); }
.rich-media audio { width: min(100%, 36rem); }
.rich-pdf-frame { min-height: min(66vh, 46rem); }

.rich-media figcaption {
  margin-top: .45rem;
  color: var(--text-secondary);
  font-size: .8rem;
}

.rich-media-placeholder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  min-height: 4.25rem;
  padding: .75rem 0;
  border-block: 1px solid var(--divider);
}

.rich-media-placeholder button {
  min-height: 2.75rem;
  padding: .55rem .9rem;
  border: 1px solid color-mix(in srgb, var(--accent-fg) 30%, transparent);
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.rich-media-placeholder button:disabled { cursor: progress; opacity: .7; }

.rich-math {
  max-width: 100%;
  color: inherit;
}

.rich-math-inline { display: inline-flex; vertical-align: -.12em; }
.rich-math-block { padding-block: .35rem; text-align: center; }
.rich-math math { font-size: 1.08em; }

.rich-content-note,
.rich-media-unavailable {
  color: var(--text-secondary);
  font-size: .8rem;
}

.rich-content-fallback pre,
.rich-content-plain pre {
  max-width: 100%;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
}

@media (max-width: 600px) {
  .rich-content { font-size: .92rem; line-height: 1.68; }
  .rich-content :where(th, td) { min-width: 6.5rem; padding: .52rem .6rem; }
  .rich-media-placeholder { align-items: stretch; flex-direction: column; }
  .rich-media-placeholder button { width: 100%; min-height: 44px; }
  .rich-pdf-frame { min-height: 58vh; }
}

@container (max-width: 420px) {
  .rich-content { font-size: .9rem; line-height: 1.62; }
  .rich-content :where(th, td) { min-width: 6rem; padding: .5rem .55rem; }
  .rich-media-placeholder { align-items: stretch; flex-direction: column; }
  .rich-media-placeholder button { width: 100%; min-height: 44px; }
  .rich-pdf-frame { min-height: min(58vh, 28rem); }
}

@media (forced-colors: active) {
  .rich-content .rich-code,
  .rich-media-placeholder,
  .rich-content :where(th, td) { border-color: CanvasText; }
}
}
