:root {
  --bg: #f6f6f4; --panel: #fff; --text: #1d1d1b; --muted: #6b6b66; --line: #e2e2dd;
  --accent: #e84142; --accent-text: #fff; --ok: #2f9e44; --warn: #e8a317; --bad: #c92a2a;
  --link: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141413; --panel: #1f1f1d; --text: #ececea; --muted: #9a9a94; --line: #33332f; --link: #fff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, sans-serif; }
/* Links: white on the dark theme, text colour on the light one, always underlined. */
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 18px; }
nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
nav a { color: var(--text); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
a.primary, button.primary { background: var(--accent); color: var(--accent-text); }
button { font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; }
button.primary { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }
h2 { margin: 24px 0 8px; font-size: 17px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.muted { color: var(--muted); }
.row { display: grid; grid-template-columns: 40px 72px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.pos { font-weight: 700; font-size: 18px; text-align: center; }
.thumb { width: 72px; height: 72px; object-fit: contain; image-rendering: pixelated;
  background: repeating-conic-gradient(#8881 0 25%, transparent 0 50%) 0 0/12px 12px; border-radius: 4px; }
.title { font-weight: 600; overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); }
.badge.queued { border-color: var(--warn); color: var(--warn); }
.badge.active { border-color: var(--accent); color: var(--accent); }
.badge.done { border-color: var(--ok); color: var(--ok); }
.badge.failed { border-color: var(--bad); color: var(--bad); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--ok); }
.job { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 720px) { .job { grid-template-columns: 1fr; } .row { grid-template-columns: 32px 56px 1fr; } .row .right { grid-column: 3; } .thumb { width: 56px; height: 56px; } }
.canvas { position: relative; width: 100%;
  background: repeating-conic-gradient(#8881 0 25%, transparent 0 50%) 0 0/16px 16px; border-radius: 6px; }
.canvas img, .canvas svg, .canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
label { display: block; margin: 12px 0 4px; font-weight: 600; }
input[type=text], input[type=number] { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); width: 100%; }
.dims { display: flex; gap: 8px; align-items: center; }
.dims input[type=number] { width: 100px; }
.dims input[type=number][step=any] { width: 160px; }
.status { margin-top: 10px; padding: 8px 10px; border-radius: 6px; background: var(--bg); white-space: pre-wrap; overflow-wrap: anywhere; }
.status.err { color: var(--bad); }
.status.ok { color: var(--ok); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
details { margin-top: 12px; }
code { font-size: 12px; overflow-wrap: anywhere; }

/* ---------- canvas area picker ---------- */
.cmap { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 70vh; overflow: hidden;
  background: #f4f1e8; border: 1px solid var(--line); border-radius: 10px; touch-action: none;
  user-select: none; -webkit-user-select: none; cursor: grab; outline: none; }
.cmap:focus-visible { border-color: #1c7ed6; }
.cmap.dragging { cursor: grabbing; }
.cmap-tiles { position: absolute; inset: 0; pointer-events: none; }
.cmap-tiles img { position: absolute; left: 0; top: 0; opacity: 0; transition: opacity .25s; transform-origin: 0 0; }
.cmap-tiles img.in { opacity: 1; }
.cmap-tiles img.failed { visibility: hidden; }
.cmap-tiles.stale img { opacity: 1; transition: none; }
.cmap-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.cmap-job { fill: rgba(232, 65, 66, .08); stroke: #e84142; stroke-width: 1.5; stroke-dasharray: 5 4; pointer-events: auto; }
.cmap-job.done { fill: rgba(47, 158, 68, .06); stroke: #2f9e44; }
.cmap-job.this { fill: none; stroke: #1c7ed6; stroke-width: 2.5; stroke-dasharray: none; }
.cmap-sel { position: absolute; left: 0; top: 0; box-sizing: border-box; border: 2px solid #1c7ed6;
  background: rgba(28, 126, 214, .12); cursor: move; box-shadow: 0 0 0 9999px rgba(20, 20, 19, .18); }
.cmap.readonly .cmap-sel { cursor: inherit; }
.cmap-sel.invalid { border-color: var(--bad); background: rgba(201, 42, 42, .14); }
.cmap-sel-fill { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.cmap-sel-fill > * { width: 100%; height: 100%; display: block; image-rendering: pixelated; opacity: .9; }
.cmap-sel-label { position: absolute; left: -2px; bottom: 100%; margin-bottom: 4px; white-space: nowrap;
  background: #1c7ed6; color: #fff; font-size: 12px; padding: 2px 6px; border-radius: 4px; pointer-events: none; }
.cmap-sel.invalid .cmap-sel-label { background: var(--bad); }
.cmap-sel.tiny .cmap-handle { width: 10px; height: 10px; }
/* a bigger invisible target than the visible handle, for fingers */
.cmap-handle::after { content: ""; position: absolute; inset: -12px; }
.cmap-handle { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid #1c7ed6; border-radius: 3px; }
.cmap-handle.nw { left: -8px; top: -8px; cursor: nwse-resize; }
.cmap-handle.se { right: -8px; bottom: -8px; cursor: nwse-resize; }
.cmap-handle.ne { right: -8px; top: -8px; cursor: nesw-resize; }
.cmap-handle.sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.cmap-bar { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.cmap-bar button { pointer-events: auto; background: rgba(255, 255, 255, .92); color: #1d1d1b; border-color: rgba(0, 0, 0, .15);
  min-width: 34px; padding: 4px 10px; font-size: 13px; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.cmap-bar button.on { background: #1c7ed6; color: #fff; border-color: #1c7ed6; }
.cmap-readout, .cmap-loading { position: absolute; bottom: 8px; font-size: 12px; padding: 2px 8px; border-radius: 4px;
  background: rgba(255, 255, 255, .85); color: #1d1d1b; pointer-events: none; }
.cmap-readout { right: 8px; font-variant-numeric: tabular-nums; }
.cmap-readout:empty { display: none; }
.cmap-loading { left: 8px; }
.picker-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.picker-fields label { margin: 0 0 2px; font-weight: 400; font-size: 13px; color: var(--muted); }
@media (max-width: 560px) { .picker-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.summary { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 12px 0; }
.summary b { font-variant-numeric: tabular-nums; }
.step { font-weight: 700; margin: 18px 0 6px; }
.step:first-child { margin-top: 0; }
.err-text { color: var(--bad); }

/* ---------- how it works ---------- */
.hero { padding: 24px 0 8px; }
.hero h1 { font-size: 30px; line-height: 1.2; margin: 0 0 10px; }
.hero p { max-width: 640px; font-size: 16px; }
a.button { display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); text-decoration: none; font-weight: 600; }
a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.cta { display: flex; flex-wrap: wrap; gap: 12px; margin: 20px 0 8px; }
a.button.big { padding: 16px 32px; font-size: 20px; border-radius: 10px; flex: 1 1 220px; max-width: 320px; text-align: center; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat span { color: var(--muted); font-size: 13px; }
.steps { padding-left: 20px; }
.steps li, main ul li { margin-bottom: 6px; }
table.prices { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.prices th, table.prices td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.prices tr:last-child td { border-bottom: 0; }
table.prices th { color: var(--muted); font-weight: 600; font-size: 13px; }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; text-align: center; }
.calc { margin-top: 12px; }
.calc-out p { margin: 8px 0 0; }
.banner { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-top: 16px; }

/* ---------- sizes to scale ---------- */
table.prices tr.pick { cursor: pointer; }
table.prices tr.pick:hover td { background: rgba(0, 0, 0, .03); }
table.prices tr.pick.on td { background: rgba(28, 126, 214, .08); }
.scale { margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.chip.on { background: #1c7ed6; border-color: #1c7ed6; color: #fff; }
.scale-map .cmap { aspect-ratio: 16 / 10; }
.cmap-job.ghost { fill: none; stroke: #1c7ed6; stroke-width: 1; stroke-dasharray: 3 3; opacity: .55; pointer-events: none; }
.scale-map .cmap-sel { background: transparent; }
table.prices td:first-child, table.prices td:nth-child(2) { white-space: normal; }
@media (max-width: 480px) { table.prices th, table.prices td { padding: 8px 10px; } }
.picker-tools { margin-top: 10px; margin-bottom: 0; }
.chip:disabled { opacity: .45; cursor: default; }
.status.err.big { background: rgba(201, 42, 42, .1); border: 1px solid var(--bad); font-weight: 600; padding: 12px 14px; }
.warn-text { color: #b35c00; }
