/* MEditor preview — base layout & typography (theme-agnostic).
   Colors and code-block highlighting come from themes/*.css. */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Skip layout/paint for off-screen blocks — massive win for long docs.
   Browser only renders viewport + 200px margin, rest is deferred. */
#content > * {
  content-visibility: auto;
  contain-intrinsic-size: auto 80px;
}

html, body {
  background: var(--bg);
  color: var(--text);
}

html {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: var(--preview-font-size, 15px);
  line-height: 1.7;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 3rem 2rem 2.5rem;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--heading);
  margin-top: 32px;
  margin-bottom: 12px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 1.75em;
  font-weight: 700;
  margin-top: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
h2 {
  font-size: 1.3em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
h3 { font-size: 1.1em; }
h4 { font-size: 1em; }

p { margin-bottom: 16px; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { padding-left: 2em; margin-bottom: 16px; }
li { margin-bottom: 4px; }

blockquote {
  margin: 0 0 16px;
  padding: 0 16px;
  color: var(--blockquote-text);
  border-left: 4px solid var(--blockquote-border);
}

code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--text);
}

pre {
  margin-bottom: 16px;
  border-radius: 8px;
  overflow: hidden;
}
pre code {
  background: none;
  padding: 16px;
  display: block;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

hr {
  height: 1px;
  border: none;
  background: var(--border);
  margin: 28px 0;
  opacity: 0.6;
}

.table-wrapper { overflow-x: auto; margin-bottom: 16px; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--table-border); padding: 8px 12px; text-align: left; white-space: nowrap; }
th { background: var(--table-bg); font-weight: 600; }
tr:nth-child(even) { background: var(--table-bg); }

img { max-width: 100%; border-radius: 6px; }

.mermaid-container { margin: 16px 0; display: flex; justify-content: center; }
.mermaid-container svg { max-width: 100%; height: auto; }

.error-block {
  color: #d73a49;
  background: var(--code-bg);
  border: 1px solid #d73a49;
  border-radius: 8px;
  padding: 12px 16px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--blockquote-border); }

@media (max-width: 900px) {
  body {
    padding: 1.5rem 1.25rem;
  }
}

/* ===== Code-block copy button ===== */
.meditor-codeblock { position: relative; }
.meditor-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 9px;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', sans-serif;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  user-select: none;
}
.meditor-codeblock:hover .meditor-copy-btn { opacity: 1; }
.meditor-copy-btn:hover { opacity: 1 !important; background: rgba(255, 255, 255, 0.22); }
.meditor-copy-btn--copied { opacity: 1 !important; color: #7ee787; }
