@font-face {
  font-family: 'Archivo';
  src: url('fonts/archivo.woff2') format('woff2');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  --stock: #efebe2;
  --stock-deep: #e4dfd3;
  --sheet: #fffefb;
  --ink: #17161b;
  --ink-2: #4e4b55;
  --rule: #cfc8b8;
  --cyan: #009fe3;
  --magenta: #e4007c;
  --yellow: #ffe500;
  --npb: #9fd6ef;
  --warn-bg: #fff6c2;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --hatch: repeating-linear-gradient(-45deg, var(--npb) 0 1.5px, transparent 1.5px 9px), var(--sheet);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 16px; }
body {
  margin: 0;
  background: var(--stock);
  color: var(--ink);
  font: 400 16px/1.5 'Archivo', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--yellow); color: var(--ink); }
input, select { caret-color: var(--magenta); }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--magenta); }
:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }
code { font: 500 0.95em ui-monospace, 'SF Mono', Menlo, monospace; background: var(--stock-deep); padding: 0.05em 0.3em; border-radius: 3px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
h2 { font-size: 1.6rem; font-weight: 700; font-stretch: 108%; letter-spacing: -0.015em; line-height: 1.15; }
h3 { font-size: 1rem; font-weight: 650; margin-bottom: 0.35rem; }
p { margin: 0; }

/* ---------- masthead ---------- */
.masthead {
  background: var(--ink);
  color: var(--sheet);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.85rem + env(safe-area-inset-top)) max(clamp(16px, 4vw, 40px), env(safe-area-inset-right)) 0.85rem max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
}
.wordmark {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-weight: 800; font-stretch: 118%; font-size: 1.15rem; letter-spacing: -0.01em;
  text-decoration: none;
}
.masthead nav { display: flex; gap: clamp(0.8rem, 2.5vw, 1.8rem); font-size: 0.9rem; }
.masthead nav a { text-decoration: none; color: #cfccd6; }
.masthead nav a:hover { color: var(--sheet); text-decoration: underline; text-decoration-color: var(--magenta); }
.colour-bar { display: grid; grid-template-columns: repeat(8, 1fr); height: 6px; }
.colour-bar i:nth-child(1) { background: var(--cyan); }
.colour-bar i:nth-child(2) { background: var(--magenta); }
.colour-bar i:nth-child(3) { background: var(--yellow); }
.colour-bar i:nth-child(4) { background: var(--ink); }
.colour-bar i:nth-child(5) { background: color-mix(in srgb, var(--cyan) 50%, white); }
.colour-bar i:nth-child(6) { background: color-mix(in srgb, var(--magenta) 50%, white); }
.colour-bar i:nth-child(7) { background: color-mix(in srgb, var(--yellow) 50%, white); }
.colour-bar i:nth-child(8) { background: color-mix(in srgb, var(--ink) 40%, white); }

/* ---------- registration target (signature) ---------- */
.reg { position: relative; display: inline-block; width: 26px; height: 26px; flex: none; }
.reg svg { position: absolute; inset: 0; width: 100%; height: 100%; mix-blend-mode: multiply; transition: transform 900ms var(--ease), color 900ms var(--ease); }
.reg .c { color: var(--cyan); transform: translate(-2.5px, 1.5px); }
.reg .m { color: var(--magenta); transform: translate(2.5px, -1px); }
.reg .y { color: var(--yellow); transform: translate(0.5px, 2.5px); }
.masthead .reg svg { mix-blend-mode: normal; opacity: 0.9; }
.masthead .reg .y { opacity: 1; }
.masthead .wordmark:hover .reg svg { transform: none; }

/* ---------- workbench ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px); }
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: start;
  padding: clamp(1.5rem, 4vw, 3rem) 0;
}
.stage { padding: 28px; }
.sheet {
  --ar: 1;
  position: relative;
  aspect-ratio: var(--ar);
  max-height: calc(100vh - 160px);
  margin: 0 auto;
  background: var(--sheet);
  box-shadow: 0 1px 1px rgb(40 30 10 / 0.06), 0 10px 28px -10px rgb(40 30 10 / 0.28);
  transition: box-shadow 300ms var(--ease);
}
.crop { position: absolute; width: 22px; height: 22px; border: 0 solid var(--ink); pointer-events: none; }
.crop.tl { top: -26px; left: -26px; border-right-width: 1px; border-bottom-width: 1px; transform: translate(-4px, -4px); }
.crop.tr { top: -26px; right: -26px; border-left-width: 1px; border-bottom-width: 1px; transform: translate(4px, -4px); }
.crop.bl { bottom: -26px; left: -26px; border-right-width: 1px; border-top-width: 1px; transform: translate(-4px, 4px); }
.crop.br { bottom: -26px; right: -26px; border-left-width: 1px; border-top-width: 1px; transform: translate(4px, 4px); }
.reg.side { position: absolute; width: 20px; height: 20px; pointer-events: none; }
.reg.side.t { top: -24px; left: calc(50% - 10px); }
.reg.side.b { bottom: -24px; left: calc(50% - 10px); }
.reg.side.l { left: -24px; top: calc(50% - 10px); }
.reg.side.r { right: -24px; top: calc(50% - 10px); }
.sheet[data-state='busy'] .reg.side svg { animation: drift 1.6s ease-in-out infinite alternate; }
.sheet[data-state='busy'] .reg.side .m { animation-delay: -0.5s; }
.sheet[data-state='busy'] .reg.side .y { animation-delay: -1.1s; }
.sheet[data-state='done'] .reg.side svg { transform: none; color: var(--ink); }
@keyframes drift {
  from { translate: -2px 1px; }
  to { translate: 2px -2px; }
}

.sheet > .drop, .sheet > .busy, .sheet > .result { position: absolute; inset: 0; display: none; }
.sheet[data-state='empty'] > .drop,
.sheet[data-state='busy'] > .busy,
.sheet[data-state='done'] > .result { display: flex; }

.drop {
  flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 0.9rem; padding: 2rem; cursor: pointer;
  background: var(--hatch);
  background-size: auto;
}
.drop::before {
  content: ''; position: absolute; inset: 14%;
  background: var(--sheet); border: 1.5px dashed var(--rule); border-radius: 2px;
  transition: border-color 200ms var(--ease), inset 400ms var(--ease);
}
.drop > * { position: relative; }
.drop h1 { font-size: clamp(1.3rem, 2.4vw, 1.75rem); font-weight: 700; font-stretch: 104%; letter-spacing: -0.015em; line-height: 1.15; max-width: 16em; }
.drop p { color: var(--ink-2); max-width: 30ch; font-size: 0.95rem; }
.drop-icon { width: 44px; height: 44px; color: var(--ink); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:hover::before, body.dragging .drop::before { border-color: var(--magenta); }
body.dragging .drop::before { inset: 8%; border-style: solid; border-width: 2px; }
.drop:focus-within::before { border-color: var(--magenta); border-style: solid; }

.busy { flex-direction: column; align-items: center; justify-content: center; gap: 1rem; overflow: hidden; }
.busy img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: grayscale(1) contrast(0.8) brightness(1.15); opacity: 0.35; }
.busy p {
  position: relative; background: var(--ink); color: var(--sheet);
  padding: 0.45rem 0.9rem; border-radius: 2px;
  font-weight: 600; font-stretch: 80%; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.85rem;
}
.busy p::after { content: '…'; }

.result { margin: 0; background: repeating-linear-gradient(-45deg, rgb(159 214 239 / 0.22) 0 1.5px, transparent 1.5px 9px), #26252b; }
.result canvas { width: 100%; height: 100%; display: block; }
.view3d { position: absolute; inset: 0; cursor: grab; touch-action: none; }
.view3d:active { cursor: grabbing; }
.load3d { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 0.8rem; pointer-events: none; }
.load3d .track { width: min(240px, 60vw); height: 4px; background: rgb(23 22 27 / 0.12); border-radius: 2px; overflow: hidden; }
.load3d p { font-weight: 600; font-stretch: 80%; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; color: var(--ink-2); }
.load3d span { display: block; height: 100%; width: 0; background: var(--magenta); transition: width 120ms linear; }
.load3d.indeterminate span { width: 100% !important; animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.2; } }
.sheet[data-view='3d'] .result { background: radial-gradient(circle at 50% 40%, #fffefb, #e4dfd3 75%); }
.sheet[data-view='3d'] #view { visibility: hidden; }
.sheet[data-view='check'] .result { background: var(--sheet); }

.slug {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-top: 36px;
  font-stretch: 72%; font-weight: 550; font-size: 0.78rem; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.slug span:first-child { color: var(--ink); }

/* ---------- panel ---------- */
.panel { position: sticky; top: 1.5rem; display: grid; gap: 1.5rem; padding-top: 28px; }
.panel-block { display: grid; gap: 1.25rem; }
.panel h2 { font-size: 1.25rem; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 0.85rem; }
.steps li { counter-increment: s; position: relative; padding-left: 2.1rem; color: var(--ink-2); }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 0.05rem; width: 1.4rem; height: 1.4rem; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.75rem; font-weight: 700; color: var(--sheet); background: var(--ink);
}
.steps li:nth-child(1)::before { background: var(--cyan); }
.steps li:nth-child(2)::before { background: var(--magenta); }
.steps li:nth-child(3)::before { background: var(--yellow); color: var(--ink); }
.steps strong { color: var(--ink); font-weight: 650; }

.field { display: grid; gap: 0.4rem; border: 0; margin: 0; padding: 0; min-width: 0; }
.field-label { font-size: 0.8rem; font-weight: 650; font-stretch: 80%; letter-spacing: 0.08em; text-transform: uppercase; display: flex; align-items: center; gap: 0.5rem; padding: 0; }
.hint, .meta { font-size: 0.85rem; color: var(--ink-2); }
.meta { font-variant-numeric: tabular-nums; }
.badge { font-size: 0.7rem; letter-spacing: 0.06em; background: var(--yellow); color: var(--ink); padding: 0.1rem 0.4rem; border-radius: 2px; }

select, input[type='text'] {
  font: inherit; color: var(--ink);
  width: 100%; min-height: 44px; padding: 0.55rem 0.75rem;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 4px;
  transition: border-color 150ms;
}
select { appearance: none; padding-right: 2.2rem; background: var(--sheet) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2317161b' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 0.8rem center; }
select:hover, input[type='text']:hover { border-color: var(--ink-2); }
select:focus-visible, input[type='text']:focus-visible { outline: 2px solid var(--magenta); outline-offset: 0; border-color: var(--magenta); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--stock-deep); border-radius: 5px; padding: 3px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; text-align: center; padding: 0.5rem 0.4rem; border-radius: 3px; font-size: 0.9rem; font-weight: 550; color: var(--ink-2); transition: background 150ms, color 150ms; }
.segmented input:checked + span { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgb(40 30 10 / 0.18); }
.segmented input:focus-visible + span { outline: 2px solid var(--magenta); outline-offset: 1px; }

.notice { background: var(--warn-bg); border: 1px solid #e8d77a; padding: 0.75rem 0.9rem; border-radius: 4px; font-size: 0.9rem; }
.notice.error { background: #fde7ef; border-color: #f2a9c6; }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 46px; padding: 0.6rem 1.15rem;
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
  color: var(--ink); background: var(--sheet); border: 1px solid var(--ink); border-radius: 4px;
  transition: background 150ms, color 150ms, transform 150ms var(--ease), box-shadow 150ms;
}
.button:hover { background: var(--stock-deep); }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--ink); color: var(--sheet); }
.button.wide { flex-basis: 100%; }
.button svg { width: 20px; height: 20px; flex: none; }
.button[aria-pressed='true'] { background: var(--stock-deep); }
.button.primary:hover { background: #000; box-shadow: 0 0 0 0 transparent, inset 0 -3px 0 var(--magenta); }
.button.quiet { border-color: transparent; background: transparent; text-decoration: underline; text-decoration-color: var(--rule); padding-inline: 0.5rem; }
.button.quiet:hover { text-decoration-color: var(--magenta); background: transparent; }
.actions .button.primary { flex: 1 1 100%; }
.drop .button.primary { min-width: 11rem; }

/* ---------- print section ---------- */
.print-section {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: clamp(1.5rem, 5vw, 4rem); align-items: center;
  border-top: 1px solid var(--rule); padding: clamp(2.5rem, 6vw, 4.5rem) 0;
}
.print-copy { display: grid; gap: 1.25rem; max-width: 30rem; }
.print-copy > p:first-of-type { color: var(--ink-2); }
.print-copy .actions .button.primary { flex: 0 1 auto; }
.print-preview { background: var(--stock-deep); padding: clamp(1rem, 3vw, 2rem); border-radius: 2px; }
.print-preview img { display: block; width: 100%; max-width: 760px; margin: 0 auto; background: #fff; box-shadow: 0 10px 24px -12px rgb(40 30 10 / 0.35); }

/* ---------- send ---------- */
.send { border-top: 1px solid var(--rule); padding: clamp(2.5rem, 6vw, 4.5rem) 0; display: grid; gap: 1.75rem; }
.send-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(1.25rem, 4vw, 3rem); }
.send-grid > div { border-top: 3px solid var(--ink); padding-top: 0.9rem; }
.send-grid > div:nth-child(1) { border-color: var(--cyan); }
.send-grid > div:nth-child(2) { border-color: var(--magenta); }
.send-grid > div:nth-child(3) { border-color: var(--yellow); }
.send-grid p { color: var(--ink-2); max-width: 40ch; }
.send-grid b { color: var(--ink); font-weight: 650; }

.footer {
  max-width: 1280px; margin: 0 auto; padding: 1.5rem clamp(16px, 4vw, 40px) 2.5rem;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem 2rem;
  font-size: 0.85rem; color: var(--ink-2); border-top: 1px solid var(--rule);
}

#printable { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; padding-top: 0; }
  .print-section { grid-template-columns: minmax(0, 1fr); }
  .send-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .masthead nav a:not(:first-child) { display: none; }
  .stage { padding: 20px 18px; }
  .crop { width: 14px; height: 14px; }
  .crop.tl, .crop.tr { top: -17px; } .crop.bl, .crop.br { bottom: -17px; }
  .crop.tl, .crop.bl { left: -17px; } .crop.tr, .crop.br { right: -17px; }
  .reg.side { width: 14px; height: 14px; }
  .reg.side.t { top: -17px; left: calc(50% - 7px); } .reg.side.b { bottom: -17px; left: calc(50% - 7px); }
  .reg.side.l { left: -17px; top: calc(50% - 7px); } .reg.side.r { right: -17px; top: calc(50% - 7px); }
  .drop::before { inset: 6%; }
  .drop p { display: none; }
  .slug { margin-top: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation: none !important; }
}

@media print {
  @page { size: landscape; margin: 0; }
  body { background: white; }
  body > :not(#printable) { display: none !important; }
  #printable { display: flex; align-items: center; justify-content: center; height: 100vh; }
  #printable img { max-width: 100%; max-height: 100%; }
}

.install {
  position: fixed; z-index: 10; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.8rem 0.6rem 0.8rem 0.8rem; border-radius: 10px;
  background: var(--ink); color: var(--sheet); font-size: 0.9rem; line-height: 1.35;
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.12), 0 14px 36px -8px rgb(0 0 0 / 0.45);
  animation: rise 500ms var(--ease) both 600ms;
}
.install img { border-radius: 12px; flex: none; box-shadow: 0 0 0 1px rgb(255 255 255 / 0.14); }
.install-copy { flex: 1; min-width: 0; }
.install-title { font-weight: 750; font-stretch: 110%; font-size: 1rem; }
.install #install-text { color: #cfccd6; }
.share-icon { width: 1.15em; height: 1.15em; vertical-align: -0.2em; color: var(--sheet); }
.install .button { min-height: 40px; padding: 0.45rem 0.9rem; background: var(--sheet); color: var(--ink); border-color: var(--sheet); }
.install-close { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%; background: none; color: #cfccd6; cursor: pointer; }
.install-close svg { width: 18px; height: 18px; }
@keyframes rise { from { transform: translateY(calc(100% + 24px)); } }
.rotate { display: none; }
@media (display-mode: standalone) and (orientation: landscape) and (max-height: 500px) {
  .rotate { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 1rem; background: var(--ink); color: var(--sheet); font-weight: 650; }
  .rotate svg { width: 56px; height: 56px; transform: rotate(-90deg); }
}
@media print { .install, .rotate { display: none !important; } }
