/* ============================================================
   Markdown → PDF
   Two layers live in this file:
     1. the app chrome (toolbar, panes, status bar) — screen only;
     2. .markdown-body, the document typography, which is what
        actually ends up in the PDF.
   Keep them apart. Anything that styles .page must look right on
   paper first and on screen second.
   ============================================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Full-height app shell. dvh so mobile browser chrome does not cover the
   status bar when the URL bar collapses. */
.tool-body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.tool-name {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate-dim);
}

/* ── Toolbar ── */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.85rem 1.1rem;
  padding: 0.75rem 1.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate-dim);
}

.field input,
.field select {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.field input {
  width: 15ch;
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.banner {
  margin: 0;
  padding: 0.75rem 1.5rem;
  background: #fff3f0;
  border-bottom: 1px solid var(--surge);
  color: var(--surge-deep);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ── Workspace ── */

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
}

.editor-pane {
  position: relative;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--paper);
}

#editor {
  display: block;
  width: 100%;
  height: 100%;
  padding: 1.5rem;
  border: 0;
  resize: none;
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--ink);
  background: transparent;
  tab-size: 2;
}

#editor:focus {
  outline: none;
  box-shadow: inset 3px 0 0 var(--surge);
}

.drop-hint {
  position: absolute;
  inset: 0.75rem;
  display: grid;
  place-items: center;
  border: 2px dashed var(--surge);
  border-radius: var(--radius);
  background: #fff3f0f2;
  color: var(--surge-deep);
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 700;
  pointer-events: none;
}

.preview-pane {
  min-width: 0;
  overflow: auto;
  padding: 2rem 1.5rem;
  background: var(--mist);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* The paper. Width and padding mirror the chosen page size and margins so
   the preview's line breaks are the PDF's line breaks; app.js sets these.
   
   When the pane is narrower than the sheet, the sheet is SCALED (--page-zoom,
   set by app.js) rather than allowed to shrink. Letting it reflow narrower
   would give a preview that quietly disagrees with the printed result and a
   page count computed from the wrong line lengths. `zoom` is used instead of
   a transform because it keeps the element's scroll height honest, which is
   what the page estimate reads. */
.page {
  /* positioned so the children's offsetTop is measured against the sheet --
     that is what the page estimate reads. */
  position: relative;
  width: var(--page-w, 210mm);
  min-height: var(--page-h, 297mm);
  padding: var(--page-margin, 20mm);
  zoom: var(--page-zoom, 1);
  background: var(--paper);
  box-shadow: 0 1px 3px #1a20301a, 0 12px 32px #1a203014;
  border-radius: 2px;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  border-top: 1px solid var(--line);
  background: var(--paper);
  color: var(--slate-dim);
  font-size: 0.78rem;
}

#counts {
  font-family: var(--mono);
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 2fr) minmax(0, 3fr);
  }

  .editor-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar-actions {
    margin-left: 0;
    width: 100%;
  }

  .status-note,
  /* The page title already says which tool this is; on a phone the label only
     costs the header a second line. */
  .tool-name {
    display: none;
  }
}

/* ============================================================
   Document typography — this is the PDF.
   ============================================================ */

.markdown-body {
  --doc-font: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-family: var(--doc-font);
  font-size: 11.5pt;
  line-height: 1.55;
  color: #14181f;
  overflow-wrap: break-word;
}

.markdown-body[data-typeface="sans"] {
  --doc-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 11pt;
}

/* The placeholder shown when the editor is empty. */
.markdown-body .empty {
  color: var(--slate-dim);
  font-family: var(--body);
  font-style: italic;
}

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

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 0 0 0.85em;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-family: var(--doc-font);
  font-weight: 700;
  line-height: 1.25;
  margin: 1.6em 0 0.5em;
  /* A heading alone at the foot of a page is the classic ugly PDF. */
  break-after: avoid-page;
  break-inside: avoid-page;
}

.markdown-body h1 {
  font-size: 1.9em;
  letter-spacing: -0.015em;
  margin-top: 0;
  padding-bottom: 0.25em;
  border-bottom: 1px solid #d9dde5;
}

.markdown-body h2 {
  font-size: 1.45em;
  letter-spacing: -0.01em;
}

.markdown-body h3 { font-size: 1.2em; }
.markdown-body h4 { font-size: 1.05em; }

.markdown-body h5,
.markdown-body h6 {
  font-size: 1em;
  color: #444c5c;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.5em;
}

.markdown-body li {
  margin-bottom: 0.25em;
}

.markdown-body li > ul,
.markdown-body li > ol {
  margin: 0.25em 0 0.25em;
}

/* GitHub-style task lists. marked emits a disabled checkbox per item. */
.markdown-body li:has(> input[type="checkbox"]) {
  list-style: none;
  margin-left: -1.35em;
}

.markdown-body li > input[type="checkbox"] {
  margin-right: 0.5em;
  vertical-align: middle;
}

.markdown-body blockquote {
  padding: 0.1em 0 0.1em 1em;
  border-left: 3px solid #d9dde5;
  color: #444c5c;
  break-inside: avoid-page;
}

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

.markdown-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: #f2f4f8;
  border: 1px solid #e4e8ef;
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.markdown-body pre {
  font-family: var(--mono);
  font-size: 0.82em;
  line-height: 1.5;
  background: #f7f8fb;
  border: 1px solid #e4e8ef;
  border-radius: 6px;
  padding: 0.85em 1em;
  overflow-x: auto;
  /* Long code must wrap: a PDF page has no horizontal scrollbar. */
  white-space: pre-wrap;
  overflow-wrap: break-word;
  break-inside: avoid-page;
}

.markdown-body pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92em;
  break-inside: avoid-page;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid #d9dde5;
  padding: 0.45em 0.65em;
  text-align: left;
  vertical-align: top;
}

.markdown-body thead th {
  background: #f2f4f8;
  font-weight: 700;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  break-inside: avoid-page;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid #d9dde5;
  margin: 1.8em 0;
}

.markdown-body a {
  color: #0b4fd0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Written by app.js where the source had a page-break marker. */
.markdown-body .page-break {
  break-after: page;
  /* On screen, show it as a visible seam rather than nothing at all. */
  height: 0;
  border-top: 1px dashed var(--slate-dim);
  margin: 1.8em 0;
}

/* ============================================================
   Print — everything except .page is chrome and must disappear.
   Page size and margins come from #print-rules (@page).
   ============================================================ */

@media print {
  html,
  body.tool-body {
    height: auto;
    overflow: visible;
    background: #fff;
    display: block;
  }

  .site,
  .toolbar,
  .banner,
  .editor-pane,
  .status-bar,
  .skip,
  .drop-hint {
    display: none !important;
  }

  .workspace {
    display: block;
    height: auto;
    min-height: 0;
  }

  .preview-pane {
    display: block;
    overflow: visible;
    padding: 0;
    background: none;
  }

  /* @page owns the paper and the margins now, so the on-screen sheet
     metaphor has to be undone or the content gets padded twice. */
  .page {
    width: auto;
    min-height: 0;
    padding: 0;
    /* The screen-fit scale must not follow the document onto paper. */
    zoom: 1;
    box-shadow: none;
    border-radius: 0;
  }

  .markdown-body .page-break {
    border-top: 0;
    margin: 0;
  }

  .markdown-body p,
  .markdown-body li {
    orphans: 3;
    widows: 3;
  }
}
