/* Minimal markdown editor + preview.
   Works with: <textarea id="input"> and <div id="output"> */

:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --text: #1a1c20;
  --muted: #6b7280;
  --line: #e4e5e8;
  --accent: #2f5fd0;

  --code-bg: #f6f7f9;
  --code-text: #23272e;
  --inline-bg: #eff0f3;

  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #16191e;
    --text: #e6e8eb;
    --muted: #8b929c;
    --line: #262a31;
    --accent: #7ba2ff;

    --code-bg: #171a20;
    --code-text: #d9dce1;
    --inline-bg: #1e222a;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 1.2fr);
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

/* ---------- editor ---------- */
#input {
  width: 100%;
  height: 100vh;
  padding: 2rem;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  outline: 0;
  resize: none;
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.7;
  tab-size: 2;
  caret-color: var(--accent);
}

#input::placeholder { color: var(--muted); }

/* ---------- preview ---------- */
#output {
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 2.5rem clamp(1.5rem, 5vw, 4.5rem) 4rem;
  font-size: 1rem;
  line-height: 1.7;
  overflow-wrap: break-word;
}

#output > * { max-width: 70ch; }
#output > :first-child { margin-top: 0; }

/* headings */
#output h1,
#output h2,
#output h3,
#output h4,
#output h5,
#output h6 {
  margin: 2em 0 0.6em;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.015em;
}
#output h1 { font-size: 2rem;    letter-spacing: -0.025em; }
#output h2 { font-size: 1.5rem;  padding-bottom: 0.35em; border-bottom: 1px solid var(--line); }
#output h3 { font-size: 1.2rem; }
#output h4 { font-size: 1rem; }
#output h5 { font-size: 0.95rem; }
#output h6 { font-size: 0.9rem; color: var(--muted); }

/* text */
#output p { margin: 0 0 1.1em; }
#output strong { font-weight: 650; }
#output a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
#output a:hover { text-decoration-thickness: 2px; }
#output del { color: var(--muted); }
#output img { max-width: 100%; border-radius: 4px; }
#output hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

/* lists */
#output ul,
#output ol { margin: 0 0 1.1em; padding-left: 1.4em; }
#output li + li { margin-top: 0.3em; }
#output li::marker { color: var(--muted); }
#output li > ul,
#output li > ol { margin: 0.3em 0 0; }
#output input[type="checkbox"] { margin-right: 0.5em; }

/* blockquote */
#output blockquote {
  margin: 1.5em 0;
  padding: 0 0 0 1.1rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
#output blockquote > :last-child { margin-bottom: 0; }

/* ---------- code ---------- */
#output :not(pre) > code {
  padding: 0.12em 0.35em;
  background: var(--inline-bg);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.875em;
}

#output pre {
  position: relative;
  margin: 1.5em 0;
  padding: 1rem 0;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  tab-size: 2;
}

#output pre code {
  display: block;
  width: max-content;
  min-width: 100%;
  padding: 0 1.25rem;
  background: none;
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.7;
  white-space: pre;
}

/* optional language tag: <pre data-lang="js"> */
#output pre[data-lang]:not([data-lang=""])::after {
  content: attr(data-lang);
  position: absolute;
  top: 0.4rem;
  right: 0.75rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
}

/* syntax colors (highlight.js class names) */
#output .hljs-comment,
#output .hljs-quote           { color: #8a919c; }
#output .hljs-keyword,
#output .hljs-selector-tag,
#output .hljs-literal         { color: #a3359b; }
#output .hljs-string,
#output .hljs-regexp,
#output .hljs-addition        { color: #1f7a46; }
#output .hljs-number,
#output .hljs-symbol          { color: #a85a12; }
#output .hljs-title,
#output .hljs-function        { color: #2f5fd0; }
#output .hljs-built_in,
#output .hljs-type            { color: #0e7490; }
#output .hljs-attr,
#output .hljs-attribute,
#output .hljs-variable,
#output .hljs-property        { color: #8a4b0f; }
#output .hljs-deletion        { color: #c0352b; }

@media (prefers-color-scheme: dark) {
  #output .hljs-comment,
  #output .hljs-quote         { color: #6c7480; }
  #output .hljs-keyword,
  #output .hljs-selector-tag,
  #output .hljs-literal       { color: #d791d0; }
  #output .hljs-string,
  #output .hljs-regexp,
  #output .hljs-addition      { color: #8fd1a4; }
  #output .hljs-number,
  #output .hljs-symbol        { color: #e8b073; }
  #output .hljs-title,
  #output .hljs-function      { color: #8db1ff; }
  #output .hljs-built_in,
  #output .hljs-type          { color: #6dd0e6; }
  #output .hljs-attr,
  #output .hljs-attribute,
  #output .hljs-variable,
  #output .hljs-property      { color: #e0b98a; }
  #output .hljs-deletion      { color: #ff8f86; }
}

/* ---------- tables ---------- */
#output table {
  display: block;
  max-width: 100%;
  margin: 1.5em 0;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.95em;
}
#output th,
#output td {
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
#output th { font-weight: 600; border-bottom-width: 2px; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  body { display: block; height: auto; }
  #input {
    height: 45vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  #output {
    height: auto;
    padding: 2rem 1.25rem 3rem;
  }
}