/* ImageReducer — the cut sheet. One stepped neutral ramp, one ink. */
@font-face {
  /* Barlow Semi Condensed 600, latin subset, Open Font License. Drafting lettering for the
     display tier only: title, drop heading, yield figure. */
  font-family: "Barlow Semi Condensed";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/barlow-semi-condensed-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  /* Drafting-paper ramp. Every neutral on the page comes from here. */
  --paper-0: #ffffff;
  --paper-1: #f5f4f0;
  --paper-2: #e9e7e1;
  --paper-3: #d5d2ca;
  --paper-4: #aaa69c;
  --paper-5: #7a766c;
  --paper-6: #4e4b44;
  --paper-7: #2a2823;
  --paper-8: #15140f;
  /* Blueprint ink: actions, selection, the saved figure. */
  --ink: #1f4e9c;
  --ink-deep: #173b78;
  --ink-soft: #e3ecf8;
  --on-ink: #ffffff;
  /* Pencil red: failures only. */
  --pencil: #b3261e;
  --pencil-soft: #f7e6e4;
  /* Drag-over state of the stock only: a wash of ink on the paper and its grid. */
  --ink-wash: #f4f8fd;
  --ink-grid: #cfdcf0;

  --grid: var(--paper-2);
  --radius: 4px;
  --pitch: 44px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", ui-monospace, monospace;
  --display: "Barlow Semi Condensed", "Segoe UI Semibold", system-ui, sans-serif;
}

* { box-sizing: border-box; }
/* Author display rules would otherwise beat the browser's [hidden] rule. */
[hidden] { display: none !important; }
html { font-size: 16px; scrollbar-color: var(--paper-3) transparent; scrollbar-width: thin; }
body {
  margin: 0;
  background: var(--paper-1);
  color: var(--paper-8);
  font: 1rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--ink-soft); color: var(--paper-8); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.sheet {
  max-width: 920px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 32px) 40px;
}

/* Credit line under the sheet. */
.credit {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px) 40px;
  text-align: center;
  font-size: 0.8125rem;
}
.credit a { color: var(--paper-6); text-decoration: none; }
@media (hover: hover) and (pointer: fine) {
  .credit a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
}

/* Title block: a drawing's title strip. */
.title-block {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--paper-7);
  margin-bottom: 20px;
}
h1 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font: 600 1.5rem/1.2 var(--display);
  letter-spacing: 0.005em;
}
/* The mark: Ryan's teal icon, the one second hue on the page. Sized to the title line. */
.logo { width: 44px; height: 44px; flex: none; }
.brand-link { display: inline-flex; align-items: center; gap: 8px; }
.brand-link .logo { width: 22px; height: 22px; }
.title-note { margin: 0; color: var(--paper-6); font-size: 0.9375rem; }

/* The stock: blank material waiting to be cut. */
.stock {
  min-height: 300px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 40px 24px;
  border: 1px solid var(--paper-3);
  border-radius: var(--radius);
  background-color: var(--paper-0);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out), background-color 160ms var(--ease-out);
}
.stock.is-over { --grid: var(--ink-grid); border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background-color: var(--ink-wash); }
.stock-icon { width: 44px; height: 44px; color: var(--ink); margin-bottom: 6px; }
h2 {
  margin: 0 0 4px;
  font: 600 1.625rem/1.2 var(--display);
  letter-spacing: 0.005em;
}
.stock-hint { margin: 0; color: var(--paper-6); }
.stock-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 20px; }

/* Buttons: one shape everywhere. */
.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--paper-4);
  border-radius: var(--radius);
  background: var(--paper-0);
  color: var(--paper-8);
  font: inherit;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), border-color 160ms var(--ease-out), background-color 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .button:hover { border-color: var(--paper-7); }
  .button-ink:hover { background: var(--ink-deep); border-color: var(--ink-deep); }
  .button-quiet:hover { color: var(--paper-8); border-color: var(--paper-4); }
}
.button:active { transform: scale(0.97); }
.button-ink { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.button-quiet { border-color: transparent; background: transparent; color: var(--paper-6); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }

/* The ticket: what to do with the stock. Shares its sheet with the ruled lines below. */
.ticket {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
  margin-top: 12px;
  padding: 10px 16px;
  border: 1px solid var(--paper-3);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--paper-0);
}
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; min-height: 32px; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.toggle-track {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  border-radius: 2px;
  background: var(--paper-4);
  transition: background-color 160ms var(--ease-out);
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  background: var(--paper-0);
  transition: transform 160ms var(--ease-out);
}
.toggle input:checked + .toggle-track { background: var(--ink); }
.toggle input:checked + .toggle-track::after { transform: translateX(14px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--ink); outline-offset: 2px; }
.toggle-label { font-weight: 500; }

.checks { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; transition: opacity 160ms var(--ease-out); }
.checks.is-disabled { opacity: 0.45; }
.check-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.check {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 10px 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--paper-8);
  font: inherit;
  font-weight: 550;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: background-color 120ms var(--ease-out), transform 120ms var(--ease-out);
}
.check:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) {
  .check:not(:disabled):hover { background: var(--paper-1); }
}
.check:disabled { cursor: not-allowed; }
.check-box {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--paper-6);
  border-radius: 2px;
  background: var(--paper-0);
  position: relative;
  transition: background-color 120ms var(--ease-out), border-color 120ms var(--ease-out);
}
.check-box::after {
  /* The ink tick, drawn as two strokes of a rotated box. */
  content: "";
  position: absolute;
  left: 4px;
  top: 0.5px;
  width: 5px;
  height: 9px;
  border: solid var(--on-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0.6);
  opacity: 0;
  transition: opacity 120ms var(--ease-out), transform 160ms var(--ease-out);
}
.check[aria-pressed="true"] .check-box { background: var(--ink); border-color: var(--ink); }
.check[aria-pressed="true"] .check-box::after { opacity: 1; transform: rotate(45deg) scale(1); }
.check-all { color: var(--ink); font-weight: 500; margin-left: 6px; padding-left: 10px; border-left: 1px solid var(--paper-3); border-radius: 0 var(--radius) var(--radius) 0; }

/* The ruled sheet: one line per file. */
.lines {
  border: 1px solid var(--paper-3);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--paper-0);
  overflow: clip; /* clip, not hidden: hidden would stop the yield stamp sticking */
}
.notice {
  margin: 0;
  padding: 0 16px;
  min-height: 36px;
  display: flex;
  align-items: center;
  border-top: 1px solid var(--paper-3);
  color: var(--paper-6);
  font-size: 0.9375rem;
}
.lines-head, .line {
  display: grid;
  /* Fixed widths everywhere but the name, so the heads and the lines share one grid. */
  grid-template-columns: minmax(0, 1fr) 5.25rem 9rem 5.25rem 4rem 15rem;
  gap: 16px;
  align-items: center;
  padding: 0 16px;
  min-height: var(--pitch);
}
.lines-head {
  min-height: 36px;
  border-top: 1px solid var(--paper-3);
  border-bottom: 1px solid var(--paper-7);
}
.lines-head > span { color: var(--paper-6); font-size: 0.8125rem; font-weight: 550; }
.lines-head .num { font-family: var(--sans); text-align: right; }
.line .num { text-align: right; }
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  /* Faint rules keep the sheet ruled even where no line has been written yet. */
  background-image: linear-gradient(var(--paper-2) 1px, transparent 1px);
  background-size: 100% var(--pitch);
  background-position: 0 calc(var(--pitch) - 1px);
  min-height: calc(var(--pitch) * 3);
}
.rows-empty {
  display: flex;
  align-items: center;
  min-height: var(--pitch);
  padding: 0 16px;
  color: var(--paper-5);
  font-size: 0.9375rem;
}
.line { border-bottom: 1px solid var(--paper-2); background: var(--paper-0); }
.line-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line .num { font-size: 0.875rem; color: var(--paper-6); white-space: nowrap; }
.line .after { color: var(--paper-8); }
.line .saved { color: var(--ink); font-weight: 600; }
.line.is-working .after { color: var(--paper-5); }

/* The dimension line: a witness line whose length is the file's size. */
.dim {
  position: relative;
  height: 14px;
  display: flex;
  align-items: center;
}
.dim::before {
  /* The full "before" length, faint. */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--paper-3);
}
/* --r is the after/before ratio. Registered so it interpolates, which lets the line
   shrink with a transform (no layout) while the right tick counter-scales to stay 1.5px. */
@property --r {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}
.dim i {
  --r: 1;
  position: relative;
  display: block;
  height: 2px;
  width: 100%;
  background: var(--ink);
  transform: scaleX(var(--r));
  transform-origin: left center;
  transition: --r 600ms var(--ease-out), background-color 200ms var(--ease-out);
}
.dim i::before, .dim i::after {
  /* End ticks. */
  content: "";
  position: absolute;
  top: -5px;
  width: 1.5px;
  height: 12px;
  background: currentColor;
  color: var(--ink);
}
.dim i::before { left: 0; transform: scaleX(calc(1 / var(--r))); transform-origin: left center; }
.dim i::after { right: 0; transform: scaleX(calc(1 / var(--r))); transform-origin: right center; }
.line.is-working .dim i {
  /* Hatching means work in progress. */
  height: 8px;
  color: var(--paper-4);
  background: repeating-linear-gradient(135deg, var(--paper-3) 0 3px, transparent 3px 7px);
  background-size: 200% 100%;
  animation: hatch 1.2s linear infinite;
}
.line.is-working .dim i::before, .line.is-working .dim i::after { top: -2px; }
@keyframes hatch { from { background-position: 0 0; } to { background-position: 28px 0; } }
.line.is-failed .dim i { background: var(--pencil-soft); color: var(--pencil); height: 8px; }
.line.is-failed .dim i::before, .line.is-failed .dim i::after { top: -2px; }
.line.is-failed .after { color: var(--pencil); font-family: var(--sans); font-size: 0.875rem; white-space: normal; text-align: left; grid-column: 4 / 7; }
.line.is-failed .saved, .line.is-failed .line-links { display: none; }
.line .after .note { display: block; font-size: 0.6875rem; line-height: 1.2; color: var(--paper-5); }

.line-links { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.line-compare {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 550;
  color: var(--paper-6);
  cursor: pointer;
  border-radius: 2px;
}
@media (hover: hover) and (pointer: fine) { .line-compare:hover { color: var(--paper-8); text-decoration: underline; text-underline-offset: 3px; } }
.line-compare[aria-expanded="true"] { color: var(--paper-8); text-decoration: underline; text-underline-offset: 3px; }

/* Compare view: the original beside every output, zooming together at the cursor. */
.compare {
  padding: 12px 16px 16px;
  background: var(--paper-1);
  border-bottom: 1px solid var(--paper-2);
}
.compare-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.compare-zooms { display: flex; gap: 4px; }
.compare-hint { margin: 0; color: var(--paper-6); font-size: 0.8125rem; flex: 1; }
.compare-head .button-quiet { margin-left: auto; }
.button-small { min-height: 32px; padding: 0 10px; font-size: 0.875rem; }
.button-small[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.compare-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.compare figure { margin: 0; min-width: 0; }
.compare figcaption { margin-bottom: 6px; font-size: 0.8125rem; font-weight: 550; color: var(--paper-6); }
.compare figcaption .num { font-weight: 400; color: var(--paper-8); font-size: 0.75rem; }
.zoom {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border: 1px solid var(--paper-3);
  border-radius: var(--radius);
  /* Checkerboard so transparent areas read as transparent, not as white. */
  background: repeating-conic-gradient(var(--paper-2) 0 25%, var(--paper-0) 0 50%) 0 0 / 16px 16px;
  cursor: zoom-in;
}
.zoom img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: var(--ox, 50%) var(--oy, 50%);
  transition: transform 80ms linear;
}
.compare.is-linked .zoom img { transform: scale(var(--z, 4)); }
.compare.is-linked .zoom { cursor: zoom-out; }
.zoom-note { position: absolute; inset: 0; display: grid; place-content: center; margin: 0; padding: 16px; text-align: center; color: var(--paper-6); font-size: 0.875rem; background: var(--paper-1); }
.line-links a { font-size: 0.8125rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.line-links a small { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 400; font-size: 0.75rem; color: var(--paper-6); margin-left: 4px; }
@media (hover: hover) and (pointer: fine) { .line-links a:hover { text-decoration: underline; } }

/* The yield stamp heads the sheet and stays pinned while the lines scroll. */
.yield {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-top: 1px solid var(--paper-3);
  border-bottom: 1px solid var(--paper-7);
  background: var(--paper-1);
}
.yield-stamp {
  display: inline-block;
  padding: 8px 14px 10px;
  border: 2px solid var(--ink);
  border-radius: 2px;
}
.yield-pct {
  margin: 0;
  font: 600 2rem/1 var(--display);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.yield-pct .num { font-family: var(--mono); font-size: 1.75rem; font-weight: 600; }
.yield-detail { margin: 4px 0 0; color: var(--paper-6); font-size: 0.875rem; }
.yield-actions { display: flex; gap: 10px; margin-left: auto; }

@media (max-width: 680px) {
  .title-block { flex-direction: column; gap: 2px; }
  .button, .check, .toggle { min-height: 44px; }
  .check { padding: 0 4px; gap: 5px; font-size: 0.8125rem; }
  .check-group { gap: 4px 2px; }
  .check-all { flex-basis: 100%; margin-left: 0; padding-left: 6px; border-left: 0; justify-content: flex-start; border-radius: var(--radius); }
  .lines-head { display: none; }
  .line {
    /* Size columns fit their figures; the last track takes the rest so nothing overlaps. */
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-areas:
      "name name name"
      "dim dim dim"
      "before after saved"
      "links links links";
    column-gap: 14px;
    row-gap: 6px;
    padding: 10px 14px;
  }
  .line-name { grid-area: name; }
  .line-links { grid-area: links; justify-content: flex-end; gap: 4px 12px; }
  .line-links a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; }
  .dim { grid-area: dim; }
  .line .before { grid-area: before; text-align: left; }
  .line .after { grid-area: after; }
  .line .saved { grid-area: saved; }
  .line.is-failed .after { grid-area: auto; grid-column: 2 / 4; grid-row: 3; text-align: right; }
  .line .after .note { display: inline; margin-left: 6px; }
  .yield-detail span { white-space: nowrap; }
  .rows { background-image: none; min-height: var(--pitch); }
  .yield-actions { width: 100%; margin-left: 0; }
  .yield-actions .button { flex: 1; }
}

/* General notes: the drawing's notes block under the sheet. Reading measure, drafting headings,
   light rules between notes. */
.notes { max-width: 68ch; margin: 48px 0 0; }
.notes h2 {
  margin: 40px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--paper-3);
  font: 600 1.25rem/1.25 var(--display);
  letter-spacing: 0.005em;
}
.notes h2:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.notes p { margin: 0 0 12px; }
.notes .note { color: var(--paper-6); font-size: 0.8125rem; }
.steps { margin: 0 0 12px; padding-left: 1.5em; }
.steps li { margin: 0 0 10px; padding-left: 4px; }
.steps li::marker { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--paper-6); }
.formats-wrap { overflow-x: auto; }
.formats { width: 100%; border-collapse: collapse; margin: 4px 0 8px; font-size: 0.9375rem; }
.formats th {
  text-align: left;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--paper-7);
  color: var(--paper-6);
  font-size: 0.8125rem;
  font-weight: 550;
}
.formats td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--paper-2); vertical-align: top; }
.formats td:first-child { font-weight: 600; white-space: nowrap; }
.faq { margin: 0 0 12px; }
.faq dt { margin: 16px 0 4px; font-weight: 600; }
.faq dd { margin: 0; }
.credit-sep { margin: 0 8px; color: var(--paper-4); }

@media (max-width: 680px) {
  .notes { margin-top: 36px; }
  .credit a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; }
  .formats thead { display: none; }
  .formats, .formats tbody, .formats tr, .formats td { display: block; }
  .formats tr { padding: 10px 0; border-bottom: 1px solid var(--paper-2); }
  .formats td { padding: 2px 0; border: 0; }
  .formats td:first-child { padding-bottom: 4px; }
  .formats td[data-th]::before { content: attr(data-th) ": "; color: var(--paper-6); font-size: 0.8125rem; font-weight: 550; }
}

@media (prefers-reduced-motion: reduce) {
  /* Keep colour and opacity feedback; remove movement. */
  .line.is-working .dim i { animation: none; }
  .zoom img { transition: none; }
  .dim i { transition: background-color 200ms var(--ease-out); }
  .button:active, .check:active { transform: none; }
  .toggle-track::after, .check-box::after { transition-property: opacity; }
  .stock { transition-property: border-color, background-color; }
}
