/* One Sheet. Desk on screen, the sheet in pt and mm, the page in print. */

:root { --wordmark: #530E36; }
[data-theme="dark"] { --wordmark: var(--ink); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --wordmark: var(--ink); }
}

html, body { margin: 0; height: 100%; background: var(--bg); }
body { overflow: hidden; }

.desk { position: fixed; inset: 0; overflow: auto; display: flex; }
.stack { position: relative; margin: auto; display: flex; flex-direction: column; align-items: center; }
.stage { position: relative; z-index: 1; flex: none; }

/* The paper. Everything inside takes its colour from these four. */
.sheet {
  --sheet-ink: #1A1A1A;
  --sheet-soft: #5B5B5B;
  --sheet-error: #BE3B27;
  --sheet-carry: #808080;
  position: relative;
  width: 210mm;
  height: calc(36pt + 14pt + 644pt + 40pt + 10mm);
  background: #FFFFFF;
  outline: 1px solid var(--sheet-ink);
  outline-offset: -1px;
  transform-origin: 0 0;
  color: var(--sheet-ink);
  font-family: "Courier New", Courier, "Liberation Mono", "Nimbus Mono PS", monospace;
}
.letter .sheet { width: 215.9mm; }

.col { position: absolute; top: 36pt; left: 0; right: 0; width: 468pt; margin: 0 auto; }

.carry {
  height: 14pt; font-size: 8pt; line-height: 14pt;
  color: var(--sheet-carry); white-space: pre; overflow: hidden;
}

.body { position: relative; height: 644pt; }
.body textarea, .body pre {
  display: block; box-sizing: content-box;
  width: 67ch; height: 644pt; margin: 0; padding: 0; border: 0;
  font: 12pt/14pt "Courier New", Courier, "Liberation Mono", "Nimbus Mono PS", monospace;
  color: var(--sheet-ink); background: transparent;
  white-space: pre; overflow: hidden; tab-size: 4;
}
.body textarea { resize: none; outline: none; caret-color: var(--sheet-ink); }
.body pre { display: none; }

.foot { height: 40pt; position: relative; }
.foot .line { position: relative; height: 20pt; text-align: center; }
.sheetno { font-size: 10pt; line-height: 20pt; color: var(--sheet-ink); }
.order { position: absolute; left: 0; top: 0; font-size: 7pt; line-height: 20pt; color: var(--sheet-soft); }
.rule {
  position: absolute; left: 0; bottom: 0; width: 100mm; height: 2mm;
  box-sizing: border-box; border-bottom: 0.75pt solid var(--sheet-ink);
}
.rule::before, .rule::after {
  content: ""; position: absolute; bottom: 0; width: 0.75pt; height: 2mm; background: var(--sheet-ink);
}
.rule::before { left: 0; }
.rule::after { right: 0; }
.rule span { position: absolute; left: calc(100% + 2mm); bottom: -2pt; font-size: 7pt; line-height: 7pt; white-space: nowrap; }

/* Screen-only margin furniture: ruler and figure on the left. */
.ruler {
  position: absolute; left: 6mm; top: 50pt; width: 2mm; height: 644pt;
}
.ruler svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ruler line { stroke: var(--sheet-ink); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.ruler i { display: block; height: calc(var(--used, 1) * 14pt); background: var(--sheet-ink); opacity: 0.16; }
.figure {
  position: absolute; left: 10mm; top: calc(50pt + var(--line, 0) * 14pt);
  font-size: 8pt; line-height: 14pt; color: var(--sheet-soft);
}
.figure.low { color: var(--sheet-error); }

/* Right margin: the collation mark and nothing else. */
.collate {
  position: absolute; right: 12mm; top: calc(50pt + var(--k, 0) * 10mm);
  width: 3mm; height: 10mm; background: #000;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
[hidden] { display: none !important; }

/* Desk lines: to the right on a wide window, under the paper otherwise. */
.desklines {
  box-sizing: border-box; width: var(--stage-w, 100%); padding: 14px 16px 24px;
  font: 11px/14px var(--font-body); color: var(--ink-soft);
}
.desklines p { margin: 0 0 6px; }
.desklines button {
  position: relative; z-index: 1;
  font: inherit; color: var(--ink); background: none; border: 0; border-radius: 0;
  padding: 15px 0; margin: -15px 0.9em -15px 0; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
@media (min-width: 1280px) {
  .desklines { position: absolute; top: calc(50pt * var(--s, 1)); left: calc(100% + 24px); width: calc((100vw - 100%) / 2 - 40px); padding: 0; }
}

.wordmark { position: fixed; left: 16px; bottom: 16px; width: 84px; z-index: 0; pointer-events: none; }
.wordmark svg { display: block; width: 100%; height: auto; }

@page { margin: 0; }
@media print {
  html, body { height: auto; overflow: visible; background: #FFFFFF; }
  .desk { position: static; display: block; overflow: visible; }
  .stack { display: block; margin: 0; }
  .stage { width: auto !important; height: auto !important; }
  .sheet { width: 100% !important; transform: none !important; outline: 0; --sheet-ink: #000; break-inside: avoid; }
  .desklines, .ruler, .figure, .wordmark, .body textarea { display: none !important; }
  .body pre { display: block; }
}
