:root {
  --linen: #efe6d4;
  --linen-deep: #e4d8c0;
  --paper: #fbf7ee;
  --ink: #232a3d;
  --ink-soft: #5d6274;
  --red: #c5392f;
  --red-deep: #9f2a22;
  --wood: #c9965a;
  --wood-deep: #a87740;
  --line: #cfc2a6;
  --display: "Fraunces", Georgia, serif;
  --body: "Atkinson Hyperlegible", Verdana, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--linen);
  /* woven linen */
  background-image:
    repeating-linear-gradient(0deg, rgba(120, 98, 60, .055) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(120, 98, 60, .055) 0 1px, transparent 1px 3px),
    radial-gradient(1200px 600px at 80% -10%, rgba(255, 255, 255, .55), transparent 70%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.12; margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 6px; }

/* ------------------------------------------------------------ header */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 40px);
}
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-button {
  width: 34px; height: 34px; border-radius: 50%;
  background:
    radial-gradient(circle at 36% 36%, var(--paper) 0 2.6px, transparent 3px),
    radial-gradient(circle at 64% 36%, var(--paper) 0 2.6px, transparent 3px),
    radial-gradient(circle at 36% 64%, var(--paper) 0 2.6px, transparent 3px),
    radial-gradient(circle at 64% 64%, var(--paper) 0 2.6px, transparent 3px),
    var(--red);
  box-shadow: inset 0 0 0 3px var(--red), inset 0 0 0 4.5px rgba(255, 255, 255, .45), 0 2px 0 var(--red-deep);
}
.brand-name { font-family: var(--display); font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.brand-name i { font-style: normal; color: var(--red); padding: 0 .12em; }
.lang {
  border: 2px dashed var(--ink); background: transparent; border-radius: 999px;
  padding: 4px 14px; font-weight: 700; font-size: .95rem;
}
.top-tools { display: flex; align-items: center; gap: 12px; }
.units { display: inline-flex; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--paper); }
.units button { border: 0; background: transparent; padding: 4px 14px; font-weight: 700; font-size: .95rem; min-width: 46px; }
.units button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.units button:focus-visible { outline-offset: -3px; }
.lang:hover { background: var(--ink); color: var(--paper); border-style: solid; }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 48px; }

/* ------------------------------------------------------------- start */
.start { max-width: 720px; margin: clamp(8px, 4vh, 48px) auto 0; text-align: center; }
.start h1 { font-size: clamp(2.2rem, 6.2vw, 3.9rem); letter-spacing: -.02em; }
.lead { font-size: 1.2rem; color: var(--ink-soft); max-width: 30em; margin: 18px auto 32px; }

.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 34px 24px 38px; cursor: pointer;
  background: var(--paper);
  border-radius: 28px;
  box-shadow: 0 1px 0 #fff inset, 0 18px 40px -22px rgba(60, 42, 12, .5);
  transition: transform .15s ease, box-shadow .15s ease;
}
.drop::before { /* stitched seam */
  content: ""; position: absolute; inset: 12px; border-radius: 18px;
  border: 2.5px dashed var(--red); opacity: .75; pointer-events: none;
}
.drop:hover, .drop:focus-within { transform: translateY(-3px); box-shadow: 0 1px 0 #fff inset, 0 26px 44px -22px rgba(60, 42, 12, .55); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-art { width: 132px; height: 132px; margin-bottom: 6px; }
.hoop-outer { fill: none; stroke: var(--wood); stroke-width: 7; }
.hoop-inner { fill: var(--linen); stroke: var(--wood-deep); stroke-width: 1.5; }
.needle-thread { fill: none; stroke: var(--red); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 7 5; animation: sew 1.6s linear infinite; }
.needle { fill: #8d939c; }
@keyframes sew { to { stroke-dashoffset: -24; } }
.drop-main {
  font-family: var(--display); font-weight: 700; font-size: 1.5rem;
  background: var(--red); color: #fff; padding: 12px 30px; border-radius: 999px;
  box-shadow: 0 4px 0 var(--red-deep);
}
.drop-sub { color: var(--ink-soft); margin-top: 12px; font-size: 1rem; }

.or { margin: 22px 0 0; }
.link {
  background: none; border: 0; padding: 4px 2px; color: var(--ink);
  text-decoration: underline; text-decoration-style: dashed; text-decoration-thickness: 2px;
  text-underline-offset: 5px; text-decoration-color: var(--red);
}
.link:hover { color: var(--red-deep); text-decoration-style: solid; }
.error { color: var(--red-deep); font-weight: 700; background: #fbe4df; border-radius: 12px; padding: 12px 16px; margin: 20px 0 0; }

.promises {
  list-style: none; padding: 0; margin: 40px 0 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 14px;
  color: var(--ink-soft); font-size: .98rem;
}
.promises li { padding: 6px 14px; border: 1.5px dashed var(--line); border-radius: 999px; background: rgba(251, 247, 238, .6); }

/* -------------------------------------------------------------- work */
.work { display: grid; gap: 28px; margin-top: 8px; animation: rise .45s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@media (min-width: 940px) {
  .work { grid-template-columns: minmax(0, 1.08fr) minmax(360px, .92fr); align-items: start; gap: 40px; }
  .stage { position: sticky; top: 18px; }
}

.hoop {
  position: relative; aspect-ratio: 1; width: 100%; max-width: min(620px, 78vh); margin: 0 auto;
  border-radius: 13%;
  padding: 3.4%;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .35), transparent 40%, rgba(80, 45, 5, .28)),
    repeating-linear-gradient(8deg, var(--wood) 0 7px, #c08c4f 7px 9px, var(--wood) 9px 17px);
  box-shadow: 0 30px 50px -28px rgba(60, 42, 12, .7), inset 0 0 0 1.5px rgba(80, 45, 5, .35);
}
.hoop canvas {
  display: block; width: 100%; height: 100%; border-radius: 10.5%;
  box-shadow: inset 0 0 0 1.5px rgba(80, 45, 5, .5), inset 0 6px 18px rgba(0, 0, 0, .2);
  background: #f4ecdc;
}
.thumb {
  position: absolute; left: -6px; top: -6px; width: 22%; max-width: 120px; aspect-ratio: 1; object-fit: contain;
  background: #fff; border: 5px solid #fff; border-radius: 6px; transform: rotate(-5deg);
  box-shadow: 0 8px 18px -8px rgba(0, 0, 0, .5);
}
.busy {
  position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
  background: var(--ink); color: var(--paper); padding: 8px 18px; border-radius: 999px; font-size: .95rem;
}
.spool { width: 16px; height: 16px; border-radius: 50%; border: 3px dashed var(--paper); animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.under-hoop { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; max-width: min(620px, 78vh); margin: 18px auto 0; }
.fabrics { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: .95rem; }
.fabric { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); background: var(--c); padding: 0; }
.fabric.on { box-shadow: 0 0 0 2px var(--linen), 0 0 0 4.5px var(--ink); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: min(620px, 78vh); margin: 18px auto 0; }
.stats div { background: rgba(251, 247, 238, .75); border: 1.5px dashed var(--line); border-radius: 14px; padding: 9px 6px; text-align: center; }
.stats dt { font-size: .8rem; color: var(--ink-soft); }
.stats dd { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.12rem; }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ------------------------------------------------------------- panel */
.panel { display: grid; gap: 22px; }
.card {
  position: relative; background: var(--paper); border-radius: 22px; padding: 26px clamp(18px, 3vw, 30px) 28px;
  box-shadow: 0 1px 0 #fff inset, 0 18px 36px -26px rgba(60, 42, 12, .55);
}
.card::before { content: ""; position: absolute; inset: 8px; border-radius: 15px; border: 2px dashed var(--line); pointer-events: none; }
.card > * { position: relative; }
.card h2 { display: flex; align-items: center; gap: 12px; font-size: 1.65rem; margin-bottom: 20px; }
.num {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 50%; background: var(--red); color: #fff; font-size: 1.2rem;
  box-shadow: inset 0 0 0 3px var(--red), inset 0 0 0 4.5px rgba(255, 255, 255, .6), 0 3px 0 var(--red-deep);
}
.card h3 { font-size: 1.15rem; margin-bottom: 4px; }

.field { margin-bottom: 22px; }
.field > label { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-weight: 700; margin-bottom: 8px; }
.field output { font-family: var(--display); font-size: 1.12rem; color: var(--red-deep); white-space: nowrap; }
.ends { display: flex; justify-content: space-between; font-size: .85rem; color: var(--ink-soft); margin-top: 2px; }
.hint { font-size: .9rem; color: var(--ink-soft); margin: 4px 0 10px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 36px; background: transparent; margin: 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 0; border-top: 4px dashed var(--ink); opacity: 1; }
input[type=range]::-moz-range-track { height: 0; border-top: 4px dashed var(--ink); background: transparent; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 32px; height: 32px; margin-top: -18px; border-radius: 50%; border: 0;
  background:
    radial-gradient(circle at 36% 36%, var(--paper) 0 2.4px, transparent 2.8px),
    radial-gradient(circle at 64% 36%, var(--paper) 0 2.4px, transparent 2.8px),
    radial-gradient(circle at 36% 64%, var(--paper) 0 2.4px, transparent 2.8px),
    radial-gradient(circle at 64% 64%, var(--paper) 0 2.4px, transparent 2.8px),
    var(--red);
  box-shadow: 0 3px 0 var(--red-deep), 0 6px 10px -4px rgba(0, 0, 0, .4);
}
input[type=range]::-moz-range-thumb {
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  background:
    radial-gradient(circle at 36% 36%, var(--paper) 0 2.4px, transparent 2.8px),
    radial-gradient(circle at 64% 36%, var(--paper) 0 2.4px, transparent 2.8px),
    radial-gradient(circle at 36% 64%, var(--paper) 0 2.4px, transparent 2.8px),
    radial-gradient(circle at 64% 64%, var(--paper) 0 2.4px, transparent 2.8px),
    var(--red);
  box-shadow: 0 3px 0 var(--red-deep);
}

select {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--ink); background: #fff;
}

.check { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 22px; cursor: pointer; }
.check input { width: 26px; height: 26px; margin: 2px 0 0; accent-color: var(--red); flex: none; }
.check small { display: block; color: var(--ink-soft); font-size: .9rem; }

.threads { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.threads label {
  display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 12px;
  padding: 7px 12px 7px 8px; border-radius: 12px; background: #fff; border: 1.5px solid var(--linen-deep); cursor: pointer;
}
.threads input { width: 22px; height: 22px; accent-color: var(--red); margin: 0; }
.threads .sw { width: 34px; height: 26px; border-radius: 5px; background:
  repeating-linear-gradient(100deg, rgba(255, 255, 255, .28) 0 1.5px, transparent 1.5px 4px), var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); }
.threads .nm small { color: var(--ink-soft); }
.threads .ct { color: var(--ink-soft); font-size: .88rem; white-space: nowrap; }
.threads li.off label { opacity: .55; background: transparent; border-style: dashed; }
.threads li.off .nm { text-decoration: line-through; }
.threads-box { margin-bottom: 8px; }

.advanced { margin-top: 20px; border-top: 2px dashed var(--line); padding-top: 14px; }
.advanced summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.advanced[open] summary { margin-bottom: 16px; }

.download {
  display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%;
  font-family: var(--display); font-weight: 700; font-size: 1.4rem; line-height: 1.15;
  padding: 18px 20px; border: 0; border-radius: 18px; background: var(--red); color: #fff;
  box-shadow: 0 6px 0 var(--red-deep), 0 18px 26px -14px rgba(159, 42, 34, .8);
  transition: transform .08s ease, box-shadow .08s ease;
}
.download svg { width: 30px; height: 30px; flex: none; }
.download:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 0 var(--red-deep), 0 22px 28px -14px rgba(159, 42, 34, .8); }
.download:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 var(--red-deep); }
.download:disabled { background: #b9ae9a; box-shadow: 0 6px 0 #9a8f7b; cursor: not-allowed; }
.file-name { text-align: center; color: var(--ink-soft); font-size: .92rem; margin: 16px 0 0; }
.file-name code { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--ink); }
.warn { background: #fff1c9; border-radius: 12px; padding: 12px 14px; margin: 0 0 16px; font-size: .95rem; }
.next { margin-top: 20px; border-top: 2px dashed var(--line); padding-top: 16px; animation: rise .4s ease both; }
.next ol { margin: 8px 0 0; padding-left: 1.3em; }
.next li { margin-bottom: 6px; }

footer { text-align: center; color: var(--ink-soft); font-size: .9rem; padding: 20px clamp(16px, 4vw, 40px) 30px; }
footer p { margin: 0 auto; max-width: 44em; }

.dragveil {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(35, 42, 61, .82); color: #fff; font-family: var(--display); font-size: clamp(1.6rem, 5vw, 3rem);
  outline: 4px dashed #fff; outline-offset: -22px;
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
