/* Rendered markdown (.md) and the teacher's editor for it. */

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.85em; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.3em 0 0.45em; line-height: 1.3; }
.md h1 { font-size: 1.3em; }
.md h2 { font-size: 1.15em; }
.md h3 { font-size: 1.05em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 0.85em; padding-left: 1.5rem; }
.md li { margin: 0.2em 0; padding-left: 0.2rem; }
.md li > ul, .md li > ol { margin: 0.2em 0 0; }
.md li > p { margin: 0; }
.md blockquote { margin: 0 0 0.85em; padding: 0.35rem 1rem; border-left: 3px solid var(--border); color: var(--text-muted); }
.md blockquote > :last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.md code { background: var(--surface-2); padding: 0.1em 0.35em; font-size: 0.92em; }
.md pre { background: var(--surface-2); padding: 0.75rem 1rem; overflow-x: auto; margin: 0 0 0.85em; line-height: 1.5; }
.md pre code { background: none; padding: 0; }
.md img { display: block; max-width: 100%; height: auto; margin: 1rem auto; }
.md p > img:only-child { margin: 0 auto; }
.md table { width: auto; max-width: 100%; margin: 0.2em 0 1em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 0.4rem 0.8rem; }
.md th { background: var(--surface-2); }
.md-inline { display: inline; }
.md-inline > * { display: inline; }

/* formulas: display maths gets its own line and scrolls sideways instead of overflowing */
.math-display { display: block; margin: 1em 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
.math-display .katex-display { margin: 0; }
.md > .math-display:first-child { margin-top: 0; }
.md > .math-display:last-child { margin-bottom: 0; }
.math .katex { font-size: 1.08em; }
.math-inline:not([data-done]), .math-display:not([data-done]) { color: var(--text-muted); font-family: ui-monospace, monospace; font-size: 0.9em; }

/* the editor */
.md-editor { border: 1px solid #8c8c8c; }
.md-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; padding: 0.4rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.md-status { margin-left: auto; color: var(--text-muted); font-size: 0.85em; }
.md-status.error { color: var(--bad); }
.md-panes { display: grid; grid-template-columns: 1fr 1fr; min-height: 14rem; }
.md-input { border: 0 !important; border-right: 1px solid var(--border) !important; min-height: 14rem; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace !important; font-size: 0.92rem !important; }
.md-preview { padding: 0.75rem 1rem; overflow: auto; max-height: 28rem; }
.md-line-preview { padding: 0.25rem 0.1rem 0; color: var(--text); font-size: 0.95em; }
.md-line-preview.is-empty { display: none; }
@media (max-width: 44rem) {
  .md-panes { grid-template-columns: 1fr; }
  .md-input { border-right: 0 !important; border-bottom: 1px solid var(--border) !important; }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 1.2em; height: 1.2em; vertical-align: -0.2em; }
dialog.wide { width: min(64rem, 96vw); }

/* ---- images dropped onto an editor ---- */
.drop-active { position: relative; outline: 2px dashed var(--brand); outline-offset: -4px; }
.drop-active::after {
  content: "solte a imagem aqui"; position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 82%, var(--brand)); color: var(--text); font-weight: 700; font-size: 1.1rem; pointer-events: none;
}
.md-line { display: flex; gap: 0.4rem; align-items: center; }
.md-line input[type="text"] { flex: 1; min-width: 0; }
.md-status.error { color: var(--bad); }

/* ---- the question editor takes (nearly) the whole screen ---- */
dialog.xwide { width: min(80rem, 96vw); max-width: none; height: min(58rem, 94vh); max-height: 94vh; } /* a window you can see around, not the whole screen */
dialog.xwide .dialog-body { display: flex; flex-direction: column; overflow: hidden; }
dialog.xwide .qe-grid { flex: 1 1 0; min-height: 0; align-items: stretch; }
dialog.xwide .qe-pane { overflow-y: auto; min-height: 0; padding-right: 0.5rem; }
dialog.xwide .qe-side { position: static; }
dialog.xwide .md-panes { grid-template-columns: 1fr; min-height: 0; }
dialog.xwide .md-input { min-height: 16rem; border-right: 0 !important; }
dialog.xwide .md-preview { display: none; } /* the right-hand pane already shows the whole question as students see it */

.md li > p + p { margin-top: 0.4em; }
