/* Level Book: an engineer's computation pad. Pale green squared paper, charcoal ink, condensed bold labels like the
   stencilling on an instrument case, hi-vis yellow for the Enter key, and numbers in a monospace so columns line up.
   Paper output is black on white with ruled lines. */
:root {
  --bg: #e9eee4;
  --paper: #f8faf4;
  --ink: #18201a;
  --muted: #47524a;
  --grid: #d3dfcc;
  --line: #a6b8a0;
  --edge: #6f8169;
  --accent: #ffd21f;
  --accent-ink: #18201a;
  --accent-edge: #9c7c00;
  --bs: #1b5a36;
  --is: #36495d;
  --fs: #8a2b16;
  --good: #1b6438;
  --good-soft: #dcefdf;
  --warn: #6f4a00;
  --warn-soft: #f6ecd0;
  --bad: #a3231b;
  --bad-soft: #f7dedb;
  --info-soft: #e1e9f1;
  --focus: #0b57d0;
  --sel: #fff3b8;
  --head: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", "Liberation Sans Narrow", Arial, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --r: 4px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --paper: #1a1f1a;
    --ink: #e7ece4;
    --muted: #a9b6a7;
    --grid: #252d25;
    --line: #3d4b3d;
    --edge: #7b8f78;
    --accent: #ffd21f;
    --accent-ink: #121512;
    --accent-edge: #ffe26a;
    --bs: #86d6a3;
    --is: #b0c7e0;
    --fs: #ffa38e;
    --good: #86d6a3;
    --good-soft: #1d3424;
    --warn: #f1c453;
    --warn-soft: #3a3016;
    --bad: #ff8f86;
    --bad-soft: #3d1f1c;
    --info-soft: #1f2a35;
    --focus: #8ab4ff;
    --sel: #3a3416;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.5 var(--sans);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { font-family: var(--head); font-weight: 700; line-height: 1.15; letter-spacing: 0; }
h1 { font-size: clamp(26px, 6vw, 38px); margin: 18px 0 6px; font-stretch: condensed; }
h2 { font-size: 24px; margin: 0 0 10px; font-stretch: condensed; }
h3 { font-size: 19px; margin: 20px 0 4px; }
.hero { padding-top: 4px; }
.lede { margin: 0 0 14px; max-width: 64ch; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.lab { display: block; font-family: var(--head); font-weight: 700; font-size: 16px; color: var(--muted); }

/* tool */
.tool { padding-bottom: 24px; }
.tool:focus { outline: none; }
.note { padding: 10px 12px; border-radius: var(--r); margin: 0 0 10px; background: var(--info-soft); }
.note.warn { background: var(--warn-soft); color: var(--ink); }
.note .btn { margin: 6px 6px 0 0; }
.note .kept { margin: 6px 0 0; padding-left: 20px; }
.note .kept li { margin: 0 0 6px; }

input[type=text], select {
  font: inherit; font-size: 17px; color: var(--ink); background: var(--paper); border: 1px solid var(--edge); border-radius: var(--r);
  padding: 9px 10px; min-height: 46px; width: 100%; max-width: 100%;
}
input.num { font-family: var(--mono); }
input::placeholder { color: var(--muted); opacity: .8; }
select { padding-right: 28px; }
label { display: block; min-width: 0; }

.bookhead { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; margin-bottom: 10px; }
.namefield { flex: 1 1 220px; }
.startrow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-bottom: 10px; }
.startrow input { font-family: var(--mono); }
.startrow label:first-child input { font-family: var(--sans); }
.fieldmsg { color: var(--bad); margin: 4px 0 8px; min-height: 0; }
.fieldmsg:empty { margin: 0; }

.seg { display: inline-flex; border: 1px solid var(--edge); border-radius: var(--r); overflow: hidden; background: var(--paper); max-width: 100%; }
.seg button {
  font: 700 17px/1.1 var(--head); color: var(--ink); background: transparent; border: 0; border-left: 1px solid var(--line);
  min-height: 46px; padding: 0 14px; cursor: pointer; flex: 1 1 auto;
}
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed=true] { background: var(--ink); color: var(--paper); }

/* the book */
.book { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); margin: 0 0 12px; }
.book .empty { margin: 0; padding: 14px 12px; color: var(--muted); }
.bk { width: 100%; border-collapse: collapse; font-size: 16px; }
.bk th, .bk td { padding: 6px 6px; text-align: right; vertical-align: top; border-bottom: 1px solid var(--grid); }
.bk thead th { font: 700 16px/1.2 var(--head); color: var(--muted); border-bottom: 2px solid var(--line); position: sticky; top: 0; background: var(--paper); }
.bk thead th:first-child, .bk tbody th, .bk.wide thead th:last-child { text-align: left; }
.bk.wide tbody th { border-right: 2px solid var(--edge); }
.bk tbody tr.ln > * { padding-top: 9px; padding-bottom: 9px; }
.bk td.num, .bk .rds { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bk td.rl { font-weight: 700; }
.bk .rfl { display: block; font-weight: 400; }
.bk .remc { text-align: left; min-width: 10ch; overflow-wrap: anywhere; }
.bk .pt {
  font: 700 16px/1.25 var(--sans); color: var(--ink); background: none; border: 0; padding: 0; min-width: 44px;
  text-align: left; cursor: pointer; overflow-wrap: anywhere; max-width: 12ch;
}
.bk tr.ln { cursor: pointer; }
.bk tr.ln:hover, .bk tr.open { background: var(--sel); }
.bk tr.bad th .pt { color: var(--bad); }
.bk tr.ln:has(+ tr.sub) th, .bk tr.ln:has(+ tr.sub) td { border-bottom: 0; }
.bk tr.sub td { text-align: left; padding-top: 0; font-size: 16px; color: var(--muted); overflow-wrap: anywhere; }
.bk tr.sub td > span { margin-right: 10px; display: inline-block; max-width: 100%; }
.bk .rem { color: var(--ink); }
.wires-line { display: flex; flex-wrap: wrap; gap: 0 16px; }
.meta:has(> label[hidden]) { grid-template-columns: minmax(0, 1fr); }
.bk .wr { display: block; font-family: var(--mono); font-size: 16px; color: var(--muted); }
.bk.narrow .rds { text-align: left; }
.rd { display: block; }
.rd .t { display: inline-block; min-width: 2.2em; font: 700 16px var(--head); }
.rd.bs .t { color: var(--bs); } .rd.is .t { color: var(--is); } .rd.fs .t { color: var(--fs); }
.rise { color: var(--bs); } .fall { color: var(--fs); }
.flags { list-style: none; margin: 4px 0 0; padding: 0; }
.flag { font-size: 16px; color: var(--ink); margin: 2px 0; }
.flag .mk { display: inline-block; width: 1.3em; height: 1.3em; line-height: 1.3em; text-align: center; border-radius: 50%; font-weight: 700; font-size: 13px; margin-right: 4px; }
.flag.bad .mk { background: var(--bad); color: var(--paper); }
.flag.warn .mk { background: var(--warn); color: var(--paper); }
.flag.info .mk { background: var(--muted); color: var(--paper); }
.bk tr.acts td { text-align: left; background: var(--sel); padding: 8px 6px 10px; }
.act-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 2px 0; }
.act-what { font-family: var(--mono); font-weight: 700; min-width: 8.5ch; }

/* entry */
.entry { background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 12px; margin: 0 0 12px; }
.entry-mode { background: var(--sel); margin: -4px -4px 10px; padding: 8px 10px; border-radius: var(--r); font-weight: 600; }
.types { display: flex; width: 100%; margin-bottom: 10px; }
.types button { min-height: 52px; font-size: 21px; }
.readout { margin-bottom: 8px; }
.bigfield .lab { margin-bottom: 2px; }
input.big { font-size: 32px; min-height: 60px; padding: 6px 12px; font-weight: 600; }
.wires { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.wires input { font-size: 21px; min-height: 54px; padding: 6px 8px; }
.preview { margin: 6px 0 0; min-height: 1.5em; font-family: var(--mono); font-size: 16px; color: var(--muted); overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 8px; margin-bottom: 8px; }
.remfield { margin-bottom: 10px; }
.keypad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.keypad button {
  font: 600 25px/1 var(--mono); min-height: 56px; border: 1px solid var(--edge); border-radius: 6px; background: var(--bg); color: var(--ink);
  cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.keypad button:active { background: var(--grid); }
.keypad .enter { grid-column: span 3; background: var(--accent); color: var(--accent-ink); border: 2px solid var(--accent-edge); font: 700 23px/1 var(--head); }
.keypad .enter:active { filter: brightness(.94); }

.btn {
  font: 600 16px/1.2 var(--sans); color: var(--ink); background: var(--paper); border: 1px solid var(--edge); border-radius: var(--r);
  min-height: 44px; padding: 8px 14px; cursor: pointer; text-align: center;
}
.btn:hover { background: var(--grid); }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: 16px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
a.btn { display: inline-block; text-decoration: none; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; min-height: 44px; padding: 0 6px; }
.undo { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.undo .btn { max-width: 100%; overflow-wrap: anywhere; }
.undo:not(:has(.btn:not([hidden]))) { margin: 0; }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin: 0 0 12px; }
.ckrow { display: flex; flex-wrap: wrap; gap: 0 12px; padding: 4px 0; border-bottom: 1px solid var(--grid); }
.ckl { font-weight: 600; min-width: 11em; }
.ckrow .num { overflow-wrap: anywhere; }
.verdict { font-weight: 700; margin: 8px 0 0; }
.verdict .mk, .hi-check .mk { display: inline-block; width: 1.4em; height: 1.4em; line-height: 1.4em; text-align: center; border-radius: 50%; color: var(--paper); }
.verdict.good { color: var(--good); } .verdict.good .mk, .mk.good { background: var(--good); color: var(--paper); }
.verdict.bad { color: var(--bad); } .verdict.bad .mk, .mk.bad { background: var(--bad); color: var(--paper); }
.hi-check { margin: 10px 0 0; overflow-wrap: anywhere; }
.hi-check .lab { display: inline; }
#closing .seg { margin-bottom: 10px; display: flex; }
#close-more { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.result p { margin: 4px 0; overflow-wrap: anywhere; }
.result .mis strong { font-size: 21px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
details.more { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); margin: 0 0 10px; }
details.more > summary { cursor: pointer; padding: 12px 14px; font: 700 18px var(--head); min-height: 44px; }
details.more > :not(summary) { padding: 0 14px 12px; }
.settings { display: grid; gap: 12px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.check input { width: 22px; height: 22px; flex: none; }
.books { list-style: none; margin: 0; padding: 0; }
.books li { padding: 10px 0; border-bottom: 1px solid var(--grid); overflow-wrap: anywhere; }
.bname { font-weight: 700; }
.unbooked { display: block; font-weight: 700; }
.bacts { display: flex; gap: 8px; margin-top: 6px; }

/* desktop: the entry pad beside the book */
@media (min-width: 1000px) {
  .tool { display: grid; grid-template-columns: minmax(0, 1fr) 330px; column-gap: 22px; align-items: start; }
  .bk.wide { font-size: 16px; }
  .bk.wide th, .bk.wide td { padding-left: 5px; padding-right: 5px; }
  .tool > * { grid-column: 1; }
  .tool > .entry { grid-column: 2; grid-row: 1 / span 20; position: sticky; top: 12px; }
  .keypad button { min-height: 50px; }
}

/* content */
.content { padding-top: 18px; padding-bottom: 32px; }
.content > * { max-width: 760px; }
.content p, .content li { max-width: 70ch; }
.content ol { padding-left: 22px; }
.content h2 { margin-top: 28px; }
.ex-box { max-width: 520px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); }
.ex { border-collapse: collapse; font-family: var(--mono); font-size: 16px; width: 100%; }
.ex th, .ex td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--grid); }
.ex thead th { font-family: var(--head); color: var(--muted); }
.ex th:first-child { text-align: left; font-family: var(--sans); }
.sources { color: var(--muted); font-size: 16px; margin-top: 24px; }

.site-foot { border-top: 1px solid var(--line); background: var(--paper); padding: 18px 0 26px; }
.sb-footer { font-size: 16px; color: var(--muted); }
.sb-more { line-height: 1.7; overflow-wrap: anywhere; }
.sb-privacy, .sb-credit { margin: 6px 0; }

/* dialog and toast */
.dialog { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.dialog-box { background: var(--paper); color: var(--ink); border-radius: 8px; padding: 18px; max-width: 420px; width: 100%; border: 2px solid var(--ink); }
.dialog-box p { margin: 0 0 14px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 16px; margin: 0 auto; max-width: 520px; transform: translateY(8px); opacity: 0;
  pointer-events: none; background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 6px; z-index: 30;
  transition: opacity .2s, transform .2s; overflow-wrap: anywhere;
}
.jump {
  position: fixed; right: 16px; bottom: 16px; z-index: 25; min-height: 48px; padding: 0 18px; border-radius: 24px;
  border: 2px solid var(--ink); background: var(--accent); color: #111; font: 700 17px var(--head); cursor: pointer;
}
.jump[hidden] { display: none; }
body.has-jump { padding-bottom: 80px; }
/* above the Book next reading button, never over the notes at the top */
body.has-jump .toast { bottom: 76px; }
@media print { .jump { display: none !important; } }
.toast.show { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } * { scroll-behavior: auto !important; } }

@media (max-width: 380px) {
  .bk th, .bk td { padding: 5px 4px; }
  .bk { font-size: 16px; }
  .seg button { padding: 0 10px; }
}

/* ---------- paper ---------- */
.print-root { display: none; }
@page { margin: 12mm; }
@media print {
  body { background: #fff; color: #000; font: 10pt/1.3 var(--sans); }
  body > :not(.print-root) { display: none !important; }
  .print-root { display: block; }
  .sheet { break-after: page; page-break-after: always; }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .ph { display: grid; grid-template-columns: 1fr auto; gap: 1mm 6mm; border-bottom: 1.5pt solid #000; padding-bottom: 2mm; margin-bottom: 2mm; }
  .ph-title { font: 700 14pt/1.2 var(--head); overflow-wrap: anywhere; }
  .ph-page { font: 700 11pt var(--head); text-align: right; }
  .ph-meta { grid-column: 1 / -1; font-size: 10pt; overflow-wrap: anywhere; }
  .ph-fields { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 3mm 8mm; font-size: 10.5pt; padding-top: 3mm; }
  table.pt { width: 100%; border-collapse: collapse; table-layout: fixed; }
  table.pt th, table.pt td { border: 0.6pt solid #555; padding: 0.8mm 1.2mm; font: 10pt/1.25 var(--mono); text-align: right; vertical-align: top; overflow-wrap: anywhere; }
  table.pt thead th { font: 700 10pt/1.2 var(--head); text-align: center; border-bottom: 1.2pt solid #000; background: none; }
  table.pt tbody th { text-align: left; font-family: var(--sans); font-weight: 600; }
  table.pt td.rem { text-align: left; font-family: var(--sans); }
  table.pt td.rl { font-weight: 700; }
  table.pt tbody tr { height: 6.6mm; break-inside: avoid; }
  table.pt tr.bf td, table.pt tr.bf th { border-top: 1pt solid #000; }
  table.pt tr.bf td.rem { font-style: italic; }
  table.pt tr.out th, table.pt tr.out td { color: #444; }
  table.pt tfoot { display: table-row-group; }
  table.pt tfoot th { font: 700 9pt var(--head); text-align: left; white-space: nowrap; }
  table.pt tfoot tr.page td, table.pt tfoot tr.page th { border-top: 1.4pt solid #000; }
  table.pt tfoot tr.cfwd td, table.pt tfoot tr.cfwd th { border-bottom: 1.4pt double #000; }
  table.pt tr.pwr td { text-align: left; border-top: 0; padding-top: 0; }
  table.pt tbody tr.pwr { height: auto; break-before: avoid; }
  table.pt tbody tr:has(+ tr.pwr) > * { border-bottom: 0; }
  .pw { font: 10pt/1.3 var(--mono); color: #222; margin-right: 2em; white-space: nowrap; }
  .pcheck { margin: 2mm 0 0; font: 10pt/1.35 var(--mono); }
  .pfinal { margin-top: 3mm; border-top: 0.8pt solid #000; padding-top: 2mm; break-inside: avoid; }
  .pfinal p { margin: 0 0 1.5mm; overflow-wrap: anywhere; }
  .pfinal .sign { margin-top: 5mm; }
  .blank table.pt tbody tr { height: 7.4mm; }
}
