:root {
  --aida: #f3f5f7;
  --weave: #e3e7ec;
  --ink: #1f2a37;
  --muted: #5d6b7a;
  --thread: #0e3f8c;   /* DMC 820 */
  --needle: #c72b3b;   /* DMC 321 */
  --paper: #ffffff;
  --line: #c9d1da;
}
* { box-sizing: border-box; }
body {
  margin: 0; color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-color: var(--aida);
  background-image:
    linear-gradient(var(--weave) 1px, transparent 1px),
    linear-gradient(90deg, var(--weave) 1px, transparent 1px);
  background-size: 9px 9px;
}
main {
  max-width: 1080px; margin: 0 auto; padding: 40px 20px 60px;
  display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 32px; align-items: start;
}
h1 {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-weight: 600; font-size: 2.1rem; line-height: 1.1; margin: 0 0 6px;
}
header { grid-column: 1 / -1; margin-bottom: -8px; }
.lead { color: var(--muted); margin: 0; max-width: 60ch; }
form { background: var(--paper); border: 1px solid var(--weave); border-radius: 6px; padding: 22px; }
.field, fieldset { margin: 0 0 18px; }
fieldset { border: 0; padding: 0; }
.field > label, legend { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; padding: 0; }
.field > label.check { font-weight: 400; }
input[type=text], input[type=number] {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: inherit;
}
input[type=file] { font: inherit; width: 100%; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: .82rem; color: var(--muted); margin: 4px 0 0; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.segmented label { flex: 1; text-align: center; padding: 7px 4px; cursor: pointer; font-size: .92rem; border-left: 1px solid var(--line); }
.segmented label:first-child { border-left: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--thread); color: #fff; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--needle); outline-offset: -2px; }
input[type=range] { width: 100%; accent-color: var(--thread); }
.range-out { font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; }
.check input { margin-top: 4px; accent-color: var(--thread); }
button {
  width: 100%; font: inherit; font-weight: 600; padding: 12px; border: 0; border-radius: 4px;
  background: var(--thread); color: #fff; cursor: pointer;
}
button:disabled { opacity: .55; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--needle); outline-offset: 2px; }
.status { min-height: 1.5em; margin-top: 10px; font-size: .92rem; }
.status.error { color: var(--needle); }

.stage { position: sticky; top: 20px; }
.hoop {
  background: var(--paper); border: 1px solid var(--weave); border-radius: 6px; padding: 18px;
  display: grid; place-items: center; min-height: 420px; position: relative;
}
.hoop.busy canvas { opacity: .45; transition: opacity .2s; }
canvas { max-width: 100%; max-height: 70vh; image-rendering: pixelated; display: none; }
.empty { color: var(--muted); text-align: center; max-width: 28ch; }
.measure { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; gap: 12px; flex-wrap: wrap; }
.size {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 1.9rem; font-variant-numeric: tabular-nums; line-height: 1;
}
.measure small { color: var(--muted); }
.threads { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.threads li {
  display: flex; align-items: center; gap: 6px; background: var(--paper); border: 1px solid var(--weave);
  border-radius: 3px; padding: 3px 8px 3px 3px; font-size: .8rem; font-variant-numeric: tabular-nums;
}
.threads i { width: 16px; height: 16px; border-radius: 2px; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; padding-top: 28px; }
  .stage { position: static; order: 1; }
  main > section:not(.stage) { order: 2; }
  .hoop { min-height: 220px; }
}
@media (prefers-reduced-motion: reduce) { .hoop.busy canvas { transition: none; } }
