:root {
  --paper: #ffffff;
  --surface: #eef3f6;
  --surface-deep: #dce5ea;
  --ink: #12202b;
  --muted: #536572;
  --rule: #b7c5ce;
  --registration: #087f96;
  --registration-dark: #075d70;
  --warning: #c94c2b;
  --focus: #007f99;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --body: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--surface);
  font-family: var(--body);
  line-height: 1.5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; }
body { margin: 0; min-height: 100vh; }
button, input, select { font: inherit; }
button, summary { cursor: pointer; }
a { color: var(--registration-dark); text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }
button {
  min-height: 44px;
  padding: 11px 16px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--ink);
  color: white;
  font-weight: 700;
  touch-action: manipulation;
}
button:hover { background: #223747; }
button:disabled { cursor: not-allowed; opacity: .42; }
.secondary { background: var(--paper); color: var(--ink); border-color: var(--rule); }
.secondary:hover { background: var(--surface); border-color: var(--ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: 1480px;
  margin: auto;
  padding: 18px 32px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 14px; color: var(--ink); text-decoration: none; }
.brand > span:last-child { display: grid; }
.brand strong { font: 800 20px/1.2 var(--mono); letter-spacing: -.7px; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.brand-mark {
  display: block;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
}
nav { display: flex; gap: 20px; font-size: 13px; }

main {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 28px;
  max-width: 1480px;
  margin: auto;
  padding: 28px 32px 48px;
}
aside { align-self: start; background: var(--paper); border: 1px solid var(--rule); }
.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: var(--ink);
  color: white;
}
h1, h2 { margin: 0; font: 750 17px/1.35 var(--mono); letter-spacing: -.3px; }
.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--registration);
  font: 700 10px/1.2 var(--mono);
  letter-spacing: 1.4px;
  text-transform: uppercase;
}
.settings-head .eyebrow { color: #66c9dc; }
.control-group { min-width: 0; margin: 0; padding: 18px 20px 21px; border: 0; border-bottom: 1px solid var(--rule); }
.control-group legend {
  float: left;
  width: 100%;
  margin-bottom: 9px;
  color: var(--muted);
  font: 700 10px/1.2 var(--mono);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}
.control-group legend + * { clear: both; }
label { display: block; margin: 13px 0 6px; font-size: 12px; font-weight: 700; }
select, input {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-weight: 550;
}
input { font: 18px var(--mono); font-variant-numeric: tabular-nums; }
p, details { color: var(--muted); font-size: 12px; line-height: 1.65; }
p { margin: 11px 0; }
.paper-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.number-stepper { display: grid; grid-template-columns: 44px minmax(44px, 1fr) 44px; gap: 0; }
.number-stepper button { padding: 0; font: 300 23px var(--mono); }
.number-stepper input { border-radius: 0; text-align: center; appearance: textfield; }
.number-stepper input::-webkit-inner-spin-button { appearance: none; }
.distance-presets { display: flex; gap: 4px; margin-top: 6px; }
.distance-presets button { flex: 1; min-width: 0; padding: 8px 2px; font: 11px var(--mono); }
.distance-presets button[aria-pressed="true"] { background: var(--registration-dark); color: white; }
.support { padding: 19px 20px 22px; }
.support h2 { margin-top: 3px; font-size: 13px; }
.warning { padding: 9px 12px; color: var(--ink); background: #fff4ef; border-left: 3px solid var(--warning); }
#settings-error { padding: 12px; color: var(--ink); border: 2px solid var(--warning); font-weight: 700; }

#preview { min-width: 0; align-self: start; position: sticky; top: 18px; }
.preview-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 13px; }
.preview-tools { display: flex; gap: 9px; }
.preview-tools button { font-size: 12px; }
.sheet-docket {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  margin-bottom: 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--registration);
}
.sheet-docket > div { min-width: 0; padding: 11px 14px; border-right: 1px solid var(--rule); }
.sheet-docket > div:last-child { border-right: 0; }
.sheet-docket span { display: block; color: var(--muted); font: 9px/1.4 var(--mono); letter-spacing: 1px; text-transform: uppercase; }
.sheet-docket strong { display: block; overflow: hidden; margin-top: 4px; font: 700 12px/1.4 var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.calibration { min-height: 20px; margin: 0 0 10px; }
.calibration output { font: 500 12px/1.5 var(--mono); }
.preview-bed { padding: 16px; background: var(--surface-deep); border: 1px solid var(--rule); }
.zoom-hint { margin: 0 0 5px; color: var(--muted); text-align: right; font: 10px/1.4 var(--mono); }
#zoom-level { color: var(--ink); font-weight: 700; }
#preview-progress { min-height: 22px; padding-bottom: 4px; color: var(--ink); font: 11px/1.6 var(--mono); }
#sheet-viewport { width: 100%; height: var(--preview-height); overflow: auto; overscroll-behavior: contain; touch-action: manipulation; }
#sheet {
  width: var(--preview-width);
  max-width: none;
  margin: auto;
  background: var(--paper);
  box-shadow: 0 3px 9px #12202b2b, 0 18px 35px #12202b1c;
}
#sheet svg { display: block; width: 100%; height: auto; }
#sheet:empty { min-height: 240px; }
#sheet:empty::before { display: block; padding: 30px; color: var(--muted); content: "Preparing your target…"; font: 12px/1.6 var(--mono); }
#sheet[data-render-state="error"]:empty::before { content: "Preview unavailable. Use the guidance below to retry."; }
.scale-note { margin-top: 14px; }
.scale-note strong { color: var(--ink); }
.scale-note::before { margin-right: 8px; color: var(--warning); content: "!"; font-weight: 900; }
#worker-status { min-height: 20px; }
#pdf-result, .readout { margin-top: 14px; padding: 14px 16px; background: var(--paper); border: 1px solid var(--rule); }
#pdf-result a { display: inline-block; min-height: 44px; padding: 10px 0; font-weight: 700; }
.readout summary { color: var(--ink); font: 700 11px var(--mono); }
pre { margin: 12px 0 0; color: var(--muted); font: 11px/1.8 var(--mono); white-space: pre-wrap; }
.mobile-only { display: none; }

footer { display: flex; gap: 20px; max-width: 1480px; margin: auto; padding: 22px 32px 30px; border-top: 1px solid var(--rule); font-size: 12px; }
footer span { margin-right: auto; font-family: var(--mono); font-weight: 700; }

.article-page main.article {
  display: block;
  max-width: 780px;
  margin: 0 auto;
  padding: 54px 32px 70px;
}
.article h1 { max-width: 700px; font-size: clamp(27px, 5vw, 46px); line-height: 1.08; letter-spacing: -1.8px; }
.article h2 { margin: 36px 0 10px; font-size: 18px; }
.article p, .article li { color: var(--ink); font-size: 16px; line-height: 1.75; }
.article .lede { margin: 22px 0 34px; color: var(--muted); font-size: 19px; }
.article li { padding-left: 5px; }
.article .notice { margin-top: 32px; padding: 16px 18px; background: #fff4ef; border-left: 4px solid var(--warning); line-height: 1.65; }
.article-action { display: inline-block; margin-top: 22px; font-weight: 750; }
.article .reveal-email {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--registration-dark);
  font: inherit;
  font-weight: inherit;
  text-decoration: underline;
  text-underline-offset: .2em;
}
.article .reveal-email:hover { background: none; text-decoration-thickness: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#code-dialog { width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 24px; color: var(--ink); border: 1px solid var(--rule); border-radius: 3px; }
#code-dialog::backdrop { background: #12202b99; }
#code-dialog input { font: 16px var(--mono); text-transform: uppercase; }
#code-error { padding-left: 10px; color: var(--ink); border-left: 3px solid var(--warning); }
.code-dialog-actions { display: flex; gap: 8px; margin-top: 18px; }
.code-dialog-actions button { flex: 1; }

@media (max-width: 1000px) {
  main { grid-template-columns: 280px minmax(0, 1fr); gap: 20px; padding: 22px; }
  .site-header { padding-inline: 22px; }
  .sheet-docket { grid-template-columns: 1fr 1fr; }
  .sheet-docket > div:last-child { grid-column: 1 / -1; border-top: 1px solid var(--rule); }
}

@media (max-width: 740px) {
  body:not(.article-page):not(.customising) { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  .site-header { padding: 14px 16px; }
  .brand small { display: none; }
  nav { gap: 12px; }
  main { display: block; padding: 17px 16px 28px; }
  aside { display: none; }
  #preview { position: static; }
  .preview-head { align-items: center; }
  .preview-head h2 { font-size: 14px; }
  .preview-tools { display: none; }
  .sheet-docket { grid-template-columns: 1fr 1fr; }
  .sheet-docket > div { padding: 9px 10px; }
  .preview-bed { padding: 11px; }
  .mobile-only { display: block; }
  .mobile-actions {
    position: fixed;
    z-index: 10;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: 1fr 1fr 1.2fr;
    gap: 6px;
    padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: var(--surface);
    border-top: 1px solid var(--rule);
    box-shadow: 0 -4px 12px #12202b22;
  }
  .mobile-actions button { min-width: 0; padding: 9px 5px; font-size: 12px; }
  body.customising aside { display: block; }
  body.customising #preview { display: none; }
  body.customising .settings-head { position: sticky; z-index: 5; top: 0; padding-top: max(18px, env(safe-area-inset-top)); box-shadow: 0 3px 8px #12202b33; }
  select, input { font-size: 16px; }
  footer { padding-inline: 16px; }
  .article-page main.article { padding: 38px 18px 52px; }
}

@media (prefers-reduced-motion: no-preference) {
  button, a { transition: background-color .12s ease, border-color .12s ease; }
}

@media print {
  body::before {
    display: block;
    margin: 20mm;
    content: "Direct webpage printing is unsupported. Return to PDF Targets and choose Download PDF.";
    color: black;
    font: 16pt/1.5 sans-serif;
  }
  body > * { display: none !important; }
}
