/* GitHub Flavored Markdown styling with custom refinements */
.markdown-body {
  line-height: 1.85;
  font-size: 18px;
  font-feature-settings: "liga" 1, "tnum" 1;
  color: var(--color-text);
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body > *:last-child {
  margin-bottom: 0;
}

/* Enhance spacing for better readability */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: clamp(2.8rem, 5vw, 3.8rem);
  margin-bottom: clamp(1.4rem, 2.8vw, 2rem);
}

.markdown-body h1 {
  font-size: clamp(2.4rem, 4.2vw, 3.1rem);
}

.markdown-body h2 {
  font-size: clamp(1.9rem, 3.4vw, 2.45rem);
  padding-bottom: 0.55rem;
}

.markdown-body h3 {
  font-size: clamp(1.55rem, 2.6vw, 1.95rem);
}

.markdown-body h4 {
  font-size: clamp(1.3rem, 2vw, 1.55rem);
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table,
.markdown-body figure,
.markdown-body details,
.markdown-body .callout,
.markdown-body .admonition {
  margin-bottom: clamp(1.8rem, 3.5vw, 2.4rem);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: clamp(1.2rem, 3vw, 1.85rem);
}

.markdown-body li {
  margin-bottom: 1rem;
}

.markdown-body table {
  overflow-x: auto;
  margin: 1.5rem auto;
  border-radius: 0.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.markdown-body table th,
.markdown-body table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.markdown-body table th:last-child,
.markdown-body table td:last-child {
  border-right: none;
}

.markdown-body table th {
  background: var(--color-surface-alt);
  font-weight: 600;
  color: var(--color-heading);
}

.markdown-body table tr:last-child th,
.markdown-body table tr:last-child td {
  border-bottom: none;
}

.markdown-body a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body blockquote {
  margin-left: clamp(-0.2rem, -1vw, -0.6rem);
  padding-left: clamp(1.1rem, 2.4vw, 1.6rem);
  border-left: 4px solid var(--color-accent);
  background: var(--color-surface-alt);
  padding: 1.5rem 2rem;
  border-radius: 0.5rem;
  font-style: italic;
  color: var(--color-muted);
  margin-bottom: clamp(2rem, 4vw, 2.8rem);
}

/* Custom elements that GFM doesn't handle */
.markdown-body figure {
  margin: calc(clamp(1.8rem, 3.5vw, 2.4rem) * 1.2) 0;
  text-align: center;
  border-radius: 1rem;
  overflow: hidden;
}

.markdown-body figure > img,
.markdown-body figure > video,
.markdown-body figure > canvas,
.markdown-body figure > svg {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 1rem;
}

/* Regular images (not in figures) */
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  background: transparent;
  border: none;
}

.markdown-body iframe,
.markdown-body .gfm-iframe-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  border-radius: 1rem;
}

.markdown-body .gfm-iframe-container > iframe {
  width: 100%;
  height: 100%;
}

.markdown-body .footnotes {
  font-size: 0.9rem;
  border-top: 1px solid var(--color-border-default);
  margin-top: 2.4rem;
  padding-top: 1.4rem;
}

.markdown-body .footnotes li {
  margin-bottom: 0.55rem;
}

@media (max-width: 768px) {
  .markdown-body {
    padding: 1.4rem 0;
  }

  .markdown-body figure,
  .markdown-body table,
  .markdown-body pre,
  .markdown-body iframe,
  .markdown-body .gfm-iframe-container,
  .markdown-body .callout {
    margin-left: 0;
    margin-right: 0;
  }
}

/* Syntax highlighting using Prism.js themes */
.markdown-body pre[class*="language-"] {
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 20px;
  overflow-x: auto;
  font-size: 15px;
  line-height: 1.6;
  margin: clamp(2rem, 4vw, 2.8rem) 0;
}

html[data-theme="dark"] .markdown-body pre[class*="language-"] {
  background: #0d1117;
  border: 1px solid #30363d;
}

/* Override Prism.js theme for dark mode */
html[data-theme="dark"] .token.comment,
html[data-theme="dark"] .token.prolog,
html[data-theme="dark"] .token.doctype,
html[data-theme="dark"] .token.cdata {
  color: #8b949e;
}

html[data-theme="dark"] .token.punctuation {
  color: #c9d1d9;
}

html[data-theme="dark"] .token.property,
html[data-theme="dark"] .token.tag,
html[data-theme="dark"] .token.boolean,
html[data-theme="dark"] .token.number,
html[data-theme="dark"] .token.constant,
html[data-theme="dark"] .token.symbol,
html[data-theme="dark"] .token.deleted {
  color: #79c0ff;
}

html[data-theme="dark"] .token.selector,
html[data-theme="dark"] .token.attr-name,
html[data-theme="dark"] .token.string,
html[data-theme="dark"] .token.char,
html[data-theme="dark"] .token.builtin,
html[data-theme="dark"] .token.inserted {
  color: #a5c9ea;
}

html[data-theme="dark"] .token.operator,
html[data-theme="dark"] .token.entity,
html[data-theme="dark"] .token.url,
html[data-theme="dark"] .token.keyword,
html[data-theme="dark"] .token.atrule,
html[data-theme="dark"] .token.attr-value {
  color: #ff7b72;
}

html[data-theme="dark"] .token.function,
html[data-theme="dark"] .token.class-name {
  color: #d2a8ff;
}

html[data-theme="dark"] .token.regex,
html[data-theme="dark"] .token.important,
html[data-theme="dark"] .token.variable {
  color: #ffa657;
}

/* Inline code styling */
.markdown-body code {
  background: rgba(175, 184, 193, 0.2);
  color: #24292f;
  padding: 0.2em 0.4em;
  border-radius: 6px;
  font-family:
    "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", "Consolas",
    "Courier New", monospace;
  font-size: 0.85em;
  border: 1px solid rgba(175, 184, 193, 0.3);
}

html[data-theme="dark"] .markdown-body code {
  background: rgba(177, 186, 196, 0.2);
  color: #c9d1d9;
  border: 1px solid rgba(177, 186, 196, 0.3);
}

/* Ensure code in pre blocks doesn't get extra styling */
.markdown-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

/* Inline code styling - GitHub theme */
.markdown-body code {
  background: rgba(175, 184, 193, 0.2);
  color: #24292f;
  padding: 0.2em 0.4em;
  border-radius: 6px;
  font-family:
    "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", "Consolas",
    "Courier New", monospace;
  font-size: 0.85em;
  border: 1px solid rgba(175, 184, 193, 0.3);
}

html[data-theme="dark"] .markdown-body code {
  background: rgba(177, 186, 196, 0.2);
  color: #c9d1d9;
  border: 1px solid rgba(177, 186, 196, 0.3);
}

/* Ensure code in pre blocks doesn't get extra styling */
.markdown-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

/* Ensure code in pre blocks doesn't get extra styling */
.markdown-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
}

/* Image styling for dark mode */
html[data-theme="dark"] .markdown-body img {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* Ensure figures don't have unwanted backgrounds in dark mode */
html[data-theme="dark"] .markdown-body figure {
  background: transparent;
}

/* Table styling for dark mode */
html[data-theme="dark"] .markdown-body {
  border-color: var(--color-border);
  background: var(--color-surface);
}

html[data-theme="dark"] .markdown-body table {
  background: var(--color-surface);
  border-color: var(--color-border);
}

html[data-theme="dark"] .markdown-body table th,
html[data-theme="dark"] .markdown-body table td {
  border-color: var(--color-border);
}

/* Syntax highlighting using GitHub's Prism theme colors */
html[data-theme="light"] .markdown-body .token.comment,
html[data-theme="light"] .markdown-body .token.prolog,
html[data-theme="light"] .markdown-body .token.doctype,
html[data-theme="light"] .markdown-body .token.cdata {
  color: #6a737d;
}

html[data-theme="light"] .markdown-body .token.punctuation {
  color: #24292f;
}

html[data-theme="light"] .markdown-body .token.property,
html[data-theme="light"] .markdown-body .token.tag,
html[data-theme="light"] .markdown-body .token.boolean,
html[data-theme="light"] .markdown-body .token.number,
html[data-theme="light"] .markdown-body .token.constant,
html[data-theme="light"] .markdown-body .token.symbol,
html[data-theme="light"] .markdown-body .token.deleted {
  color: #0550ae;
}

html[data-theme="light"] .markdown-body .token.selector,
html[data-theme="light"] .markdown-body .token.attr-name,
html[data-theme="light"] .markdown-body .token.string,
html[data-theme="light"] .markdown-body .token.char,
html[data-theme="light"] .markdown-body .token.builtin,
html[data-theme="light"] .markdown-body .token.inserted {
  color: #0a3069;
}

html[data-theme="light"] .markdown-body .token.operator,
html[data-theme="light"] .markdown-body .token.entity,
html[data-theme="light"] .markdown-body .token.url {
  color: #cf222e;
}

html[data-theme="light"] .markdown-body .token.atrule,
html[data-theme="light"] .markdown-body .token.attr-value,
html[data-theme="light"] .markdown-body .token.keyword,
html[data-theme="light"] .markdown-body .token.function,
html[data-theme="light"] .markdown-body .token.class-name {
  color: #cf222e;
}

html[data-theme="light"] .markdown-body .token.regex,
html[data-theme="light"] .markdown-body .token.important {
  color: #953800;
}

html[data-theme="light"] .markdown-body .token.variable {
  color: #953800;
}

/* Prism.js token colors for dark mode - GitHub dark theme */
html[data-theme="dark"] .markdown-body .token.comment,
html[data-theme="dark"] .markdown-body .token.prolog,
html[data-theme="dark"] .markdown-body .token.doctype,
html[data-theme="dark"] .markdown-body .token.cdata {
  color: #8b949e;
}

html[data-theme="dark"] .markdown-body .token.punctuation {
  color: #c9d1d9;
}

html[data-theme="dark"] .markdown-body .token.property,
html[data-theme="dark"] .markdown-body .token.tag,
html[data-theme="dark"] .markdown-body .token.boolean,
html[data-theme="dark"] .markdown-body .token.number,
html[data-theme="dark"] .markdown-body .token.constant,
html[data-theme="dark"] .markdown-body .token.symbol,
html[data-theme="dark"] .markdown-body .token.deleted {
  color: #79c0ff;
}

html[data-theme="dark"] .markdown-body .token.selector,
html[data-theme="dark"] .markdown-body .token.attr-name,
html[data-theme="dark"] .markdown-body .token.string,
html[data-theme="dark"] .markdown-body .token.char,
html[data-theme="dark"] .markdown-body .token.builtin,
html[data-theme="dark"] .markdown-body .token.inserted {
  color: #a5c9ea;
}

html[data-theme="dark"] .markdown-body .token.operator,
html[data-theme="dark"] .markdown-body .token.entity,
html[data-theme="dark"] .markdown-body .token.url {
  color: #ff7b72;
}

html[data-theme="dark"] .markdown-body .token.atrule,
html[data-theme="dark"] .markdown-body .token.attr-value,
html[data-theme="dark"] .markdown-body .token.keyword,
html[data-theme="dark"] .markdown-body .token.function,
html[data-theme="dark"] .markdown-body .token.class-name {
  color: #d2a8ff;
}

html[data-theme="dark"] .markdown-body .token.regex,
html[data-theme="dark"] .markdown-body .token.important {
  color: #f85149;
}

html[data-theme="dark"] .markdown-body .token.variable {
  color: #ffa657;
}

/* Copy to clipboard button styling */
.markdown-body pre[class*="language-"] {
  position: relative;
}

.copy-to-clipboard-button {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  color: #24292f;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.markdown-body pre[class*="language-"]:hover .copy-to-clipboard-button {
  opacity: 1;
}

html[data-theme="dark"] .copy-to-clipboard-button {
  background: #0d1117;
  border: 1px solid #30363d;
  color: #c9d1d9;
}

.copy-to-clipboard-button:hover {
  background: #f3f4f6;
}

html[data-theme="dark"] .copy-to-clipboard-button:hover {
  background: #161b22;
}
