:root {
  --rich-text-scale: 1;
  --rich-line-height: 1.78;
  --rich-card-opacity: 0.72;
  --rich-card-blur: 12px;
  --rich-accent-rust: #a85a45;
  --rich-accent-rose: #b86a76;
  --rich-accent-red: #b9544d;
  --rich-accent-gold: #a77a32;
  --rich-muted: rgba(30, 24, 22, 0.68);
}

.rich-message,
.rich-message * {
  box-sizing: border-box;
  max-width: 100%;
}

.rich-message {
  display: grid;
  gap: 0.78em;
  width: 100%;
  font-size: calc(1rem * var(--rich-text-scale));
  line-height: var(--rich-line-height);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.rich-message .rich-block {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.rich-message .rich-markdown {
  white-space: normal;
}

.rich-message code,
.rich-message pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.rich-aside {
  color: var(--rich-muted);
  font-size: 0.92em;
  line-height: 1.62;
  letter-spacing: 0;
}

.rich-emphasis {
  color: var(--rich-accent-rose);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: 0;
}

.rich-emphasis--rust { color: var(--rich-accent-rust); }
.rich-emphasis--rose { color: var(--rich-accent-rose); }
.rich-emphasis--red { color: var(--rich-accent-red); }
.rich-emphasis--gold { color: var(--rich-accent-gold); }
.rich-emphasis--muted { color: var(--rich-muted); }
.rich-emphasis--md { font-size: 1.08em; }
.rich-emphasis--lg { font-size: 1.24em; }
.rich-emphasis--xl { font-size: 1.46em; }
.rich-emphasis--xxl { font-size: 1.7em; }
.rich-weight--600 { font-weight: 600; }
.rich-weight--700 { font-weight: 700; }
.rich-weight--800 { font-weight: 800; }

.rich-heading {
  margin: 0.35em 0 0.16em;
  color: rgba(31, 37, 44, 0.88);
  font-weight: 760;
  line-height: 1.34;
}

.rich-heading--2 { font-size: 1.28em; }
.rich-heading--3 { font-size: 1.12em; }

.rich-card,
.rich-memory-card {
  width: 100%;
  border-radius: 24px;
  padding: 20px 22px;
  border: 1px solid rgba(255, 255, 255, 0.48);
  background: rgba(255, 242, 246, var(--rich-card-opacity));
  box-shadow: 0 14px 34px rgba(110, 78, 88, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.56);
  backdrop-filter: blur(var(--rich-card-blur)) saturate(130%);
  -webkit-backdrop-filter: blur(var(--rich-card-blur)) saturate(130%);
}

.rich-card--glass,
.rich-card--neutral {
  background: rgba(255, 255, 255, 0.62);
}

.rich-card--gold {
  background: rgba(255, 246, 224, 0.70);
  border-color: rgba(210, 171, 87, 0.22);
}

.rich-card--dark {
  color: rgba(255, 255, 255, 0.90);
  background: rgba(42, 46, 45, 0.55);
  border-color: rgba(255, 255, 255, 0.18);
}

.rich-card--compact {
  padding: 15px 17px;
  border-radius: 20px;
}

.rich-card-title,
.rich-memory-title {
  margin: 0 0 0.65em;
  color: var(--rich-accent-rose);
  font-weight: 760;
  line-height: 1.32;
}

.rich-card-icon {
  display: inline-block;
  margin: 0 0.38em 0.45em 0;
  color: var(--rich-accent-gold);
  font-weight: 700;
}

.rich-card-body,
.rich-memory-body {
  min-width: 0;
}

.rich-quote {
  margin: 0;
  padding: 0.25em 0 0.25em 1em;
  border-left: 3px solid rgba(184, 106, 118, 0.34);
  color: rgba(36, 35, 34, 0.78);
  background: linear-gradient(90deg, rgba(255, 232, 238, 0.36), transparent 72%);
}

.rich-quote-by {
  margin-top: 0.55em;
  font-size: 0.88em;
  color: var(--rich-muted);
}

.rich-quote-by::before {
  content: "— ";
}

.rich-memory-card {
  background: rgba(255, 250, 240, 0.72);
  border-color: rgba(180, 128, 82, 0.24);
}

.rich-memory-card--high {
  border-color: rgba(184, 106, 118, 0.42);
  box-shadow: 0 16px 36px rgba(143, 84, 92, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.58);
}

@media (max-width: 640px) {
  .rich-message {
    gap: 0.68em;
  }

  .rich-card,
  .rich-memory-card {
    padding: 16px 17px;
    border-radius: 20px;
    backdrop-filter: blur(8px) saturate(118%);
    -webkit-backdrop-filter: blur(8px) saturate(118%);
  }

  .rich-emphasis--xxl { font-size: 1.45em; }
  .rich-emphasis--xl { font-size: 1.32em; }
}


/* Safe markdown fallback inside assistant messages and rich blocks. */
.md-heading {
  margin: 0.18em 0 0.42em;
  color: rgba(34, 47, 45, 0.92);
  font-weight: 760;
  line-height: 1.24;
}
.md-heading-1 { font-size: 1.34em; }
.md-heading-2 { font-size: 1.22em; }
.md-heading-3 { font-size: 1.12em; }
.md-p {
  margin: 0.16em 0;
}
.md-list {
  margin: 0.2em 0 0.35em 1.25em;
  padding: 0;
}
.md-list li {
  margin: 0.16em 0;
  padding-left: 0.1em;
}
.md-quote {
  margin: 0.28em 0;
  padding: 0.28em 0 0.28em 0.85em;
  border-left: 3px solid rgba(103, 139, 108, 0.36);
  color: rgba(37, 53, 50, 0.78);
  background: linear-gradient(90deg, rgba(232, 246, 234, 0.42), transparent 75%);
}
.md-hr {
  border: 0;
  height: 1px;
  margin: 0.72em 0;
  background: linear-gradient(90deg, transparent, rgba(99, 127, 111, 0.28), transparent);
}
.rich-markdown > br:first-child,
.rich-markdown > br:last-child {
  display: none;
}

.rich-theme-css-applied { border-color: rgba(103,139,108,.28); color: rgba(42,83,61,.82); }
.rich-theme-css-rejected { border-color: rgba(184,106,118,.32); color: rgba(132,55,65,.86); }

/* v53: rich blocks should follow the assistant bubble width on mobile. */
.rich-message,
.rich-message .rich-block,
.rich-card,
.rich-quote,
.rich-aside,
.rich-emphasis,
.rich-memory-card {
  min-width: 0;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  .rich-message {
    width: 100%;
    max-width: 100%;
  }

  .rich-message .rich-block,
  .rich-card,
  .rich-quote,
  .rich-aside,
  .rich-emphasis,
  .rich-memory-card {
    width: var(--yan-rich-card-width, 100%);
    max-width: 100%;
  }
}

/* v54: never let rich blocks define a narrower mobile column than their bubble. */
@media (max-width: 768px) {
  .rich-message,
  .rich-message .rich-block,
  .rich-card,
  .rich-quote,
  .rich-aside,
  .rich-emphasis,
  .rich-memory-card {
    display: block;
    width: var(--yan-rich-card-width, 100%);
    max-width: 100%;
    min-width: 0;
    margin-left: 0;
    margin-right: 0;
    box-sizing: border-box;
  }
}
