/* Patchwork: Grandma's Sewing Table. Wood, linen, a green cutting mat, a yellow ruler. No purple. */
:root {
	--wood: #cd9b6b; --wood2: #c4905f; --wood3: #d4a578; --seam: #7a4d2a;
	--linen: #efe3c9; --linen2: #e4d4b0; --dash: #bfa573;
	--mat: #4f8a6a; --red: #d1473a; --ink: #3b2a1e; --ruler: #f2c63e; --cream: #fbf3df;
	--hand: 'Patrick Hand', 'Comic Sans MS', cursive; --ui: 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
	font-family: var(--ui); color: var(--ink); background-color: var(--wood);
	background-image:
		radial-gradient(ellipse 60% 55% at 50% 42%, rgba(255, 238, 196, .42), rgba(255, 238, 196, 0) 70%),
		repeating-linear-gradient(180deg, rgba(0, 0, 0, 0) 0 84px, rgba(110, 66, 32, .5) 84px 86px),
		repeating-linear-gradient(90deg, rgba(120, 70, 30, .05) 0 3px, rgba(0, 0, 0, 0) 3px 13px),
		repeating-linear-gradient(180deg, #cd9b6b 0 86px, #c58f5d 86px 172px, #d4a577 172px 258px, #c9975f 258px 344px, #d09f70 344px 430px, #c28c5b 430px 516px);
	user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #1d6fb8; outline-offset: 2px; }

#app {
	position: fixed; inset: 0; display: grid; gap: 10px 14px; padding: 12px 14px;
	grid-template-columns: 212px minmax(0, 1fr) 212px; grid-template-rows: 48px minmax(0, 1fr) 54px; padding-right: 72px;
	grid-template-areas: "ruler ruler ruler" "tray mat side" "tray strip side";
}

/* the ruler carries the one step line; the shared home and fullscreen buttons sit at its two ends */
#ruler { grid-area: ruler; margin: 0 56px; display: flex; align-items: stretch; }
#step {
	flex: 1; display: flex; align-items: center; gap: 12px; padding: 0 16px; min-width: 0; border-radius: 6px;
	background: var(--ruler); border: 2px solid #b8901d; box-shadow: 0 3px 0 rgba(90, 52, 24, .4);
	background-image: repeating-linear-gradient(90deg, rgba(60, 40, 0, .55) 0 2px, rgba(0, 0, 0, 0) 2px 20px), repeating-linear-gradient(90deg, rgba(60, 40, 0, .5) 0 1.5px, rgba(0, 0, 0, 0) 1.5px 100px);
	background-size: 100% 9px, 100% 15px; background-repeat: no-repeat; background-position: 0 0, 0 0;
}
#stepN { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--red); color: var(--cream); font: 700 22px/34px var(--hand); text-align: center; border: 2px solid #9c2f25; margin-top: 4px; }
#stepT { font: 400 clamp(17px, 2.3vw, 25px)/1.05 var(--hand); color: var(--ink); margin-top: 4px; }
#step.nudge { animation: wob .5s; }
@keyframes wob { 20% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 80% { transform: translateX(-3px); } }

.card {
	background: var(--linen); border: 3px dashed var(--dash); border-radius: 22px; padding: 10px 12px 12px;
	box-shadow: 0 4px 0 rgba(90, 52, 24, .35), 0 10px 18px rgba(60, 30, 10, .18); min-height: 0;
}
.card h2, .card h3 { margin: 0 0 6px; font: 400 22px/1 var(--hand); text-align: center; color: var(--ink); }
.card h3 { font-size: 18px; margin-top: 8px; }
.card h2 small { display: block; font: 700 11.5px/1.3 var(--ui); color: #7a6648; letter-spacing: .02em; margin-top: 2px; min-height: 15px; }

/* fabrics */
#tray { grid-area: tray; align-self: start; max-height: calc(100% - 114px); display: flex; flex-direction: column; overflow: hidden; }
#fabsWrap { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: none; }
#fabsWrap::-webkit-scrollbar { display: none; }
#fabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 2px; }
.fab { aspect-ratio: 1; min-width: 44px; min-height: 44px; border-radius: 6px; position: relative; }
.fab svg { width: 100%; height: 100%; display: block; overflow: visible; }
.fab[aria-pressed="true"], .opt[aria-pressed="true"] { outline: 3px solid var(--red); outline-offset: 1px; border-radius: 8px; }
#colsRow { flex: none; }
#cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; justify-items: center; }
.col { width: 46px; height: 46px; border-radius: 50%; border: 3px solid rgba(40, 20, 5, .55); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), inset 0 3px 0 rgba(255, 255, 255, .35); }
.col[aria-pressed="true"] { outline: 3px solid var(--red); outline-offset: 2px; }

/* the mat */
#matwrap { grid-area: mat; position: relative; display: grid; place-items: center; min-height: 0; min-width: 0; }
#mat { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; overflow: visible; filter: drop-shadow(0 8px 10px rgba(50, 25, 8, .35)); }
#mat .cell { fill: rgba(255, 255, 255, .06); stroke: rgba(255, 255, 255, .6); stroke-width: 2.4; stroke-dasharray: 9 8; stroke-linecap: round; }
#mat .cell.glow { stroke: #ffe066; stroke-width: 4; fill: rgba(255, 224, 102, .2); animation: pulse .9s ease-in-out infinite alternate; }
#mat .sel { fill: none; stroke: var(--red); stroke-width: 4; stroke-dasharray: 10 7; stroke-linecap: round; animation: march 1s linear infinite; }
#mat .ring { fill: none; stroke: #ffe066; stroke-width: 5; animation: pulse .9s ease-in-out infinite alternate; }
#mat .patch { pointer-events: none; }
@keyframes pulse { from { opacity: .45; } to { opacity: 1; } }
@keyframes march { to { stroke-dashoffset: -34; } }

#pickup {
	position: absolute; width: 48px; height: 48px; border-radius: 50%; background: var(--cream); color: var(--red);
	font: 900 24px/44px var(--ui); border: 3px solid var(--red); box-shadow: 0 3px 0 rgba(90, 20, 10, .35); z-index: 3;
}
#pickup[hidden] { display: none; }

/* buttons under the mat and in the side panel */
#strip { grid-area: strip; display: flex; align-items: center; justify-content: center; gap: 14px; min-width: 0; }
#tools, #helpers { display: flex; gap: 8px; }
.tool {
	height: 48px; min-width: 48px; padding: 0 16px; border-radius: 14px; background: var(--linen); border: 3px solid #a67c4a;
	box-shadow: 0 3px 0 rgba(90, 52, 24, .45); font: 800 15px/1 var(--ui); display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap; position: relative;
}
.tool:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(90, 52, 24, .45); }
.tool i { width: 22px; height: 22px; display: block; }
.tool i svg { width: 100%; height: 100%; display: block; }
.tool[aria-disabled="true"] { opacity: .5; }
#helpBtn { background: var(--red); color: var(--cream); border-color: #9c2f25; }
#shelfN { font: 900 12px/20px var(--ui); font-style: normal; background: var(--red); color: var(--cream); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; }
#shelfN:empty { display: none; }

#side { grid-area: side; margin-bottom: 76px; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; scrollbar-width: none; }
#side::-webkit-scrollbar { display: none; }
#stitches { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.opt { height: 48px; border-radius: 12px; background: var(--cream); border: 2px solid #d3c19a; display: block; }
.opt svg { width: 100%; height: 100%; display: block; }
#stitches .opt { height: 50px; }
#threads { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#threads .opt { height: 56px; background: var(--cream); }
#threads .opt svg { width: 100%; height: 100%; padding: 2px; }
#makeBtns { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.mk { min-height: 70px; border-radius: 14px; background: var(--cream); border: 3px solid #d3c19a; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font: 800 12.5px/1.1 var(--ui); padding: 3px 2px; box-shadow: 0 3px 0 rgba(90, 52, 24, .3); }
.mk svg { width: 38px; height: 38px; display: block; }
.mk[aria-disabled="true"] { opacity: .55; }
.mk.glow, .glow-box { animation: boxglow .9s ease-in-out infinite alternate; }
.fab.glow, .opt.glow { animation: boxglow .9s ease-in-out infinite alternate; }
@keyframes boxglow { from { box-shadow: 0 0 0 3px rgba(255, 224, 102, .5), 0 3px 0 rgba(90, 52, 24, .3); } to { box-shadow: 0 0 0 7px rgba(255, 224, 102, 1), 0 3px 0 rgba(90, 52, 24, .3); } }

/* shelf, reveal, big view */
#veil { position: fixed; inset: 0; z-index: 50; background: rgba(42, 22, 8, .6); display: grid; place-items: center; padding: 14px; }
#veil[hidden] { display: none; }
#sheet { width: min(760px, 100%); max-height: 100%; overflow: auto; background: var(--linen); border: 4px solid #a67c4a; border-radius: 26px; padding: 18px 20px 20px; box-shadow: 0 10px 0 rgba(60, 30, 10, .4), 0 24px 50px rgba(0, 0, 0, .35); text-align: center; }
#sheet h2 { margin: 0 0 6px; font: 400 clamp(26px, 4vw, 36px)/1.05 var(--hand); }
#sheet p { margin: 0 0 10px; font: 400 19px/1.2 var(--hand); color: #6b5738; }
.bigmake { width: min(420px, 100%); margin: 4px auto 6px; display: block; background: radial-gradient(ellipse at 50% 55%, #fff6dc, #f1e3c4 75%); border-radius: 20px; border: 3px dashed var(--dash); }
.bigmake svg { width: 100%; height: auto; display: block; }
.reveal .bigmake svg { animation: pop .8s cubic-bezier(.2, 1.5, .4, 1) both; transform-origin: 50% 70%; }
@keyframes pop { 0% { transform: scale(.55) rotate(-4deg); opacity: 0; } 70% { opacity: 1; } 100% { transform: none; } }
.twk { position: absolute; font-size: 26px; color: #ffd24a; animation: twk 1.6s ease-in-out infinite; pointer-events: none; text-shadow: 0 0 6px #fff; }
@keyframes twk { 0%, 100% { transform: scale(0) rotate(0); opacity: 0; } 50% { transform: scale(1) rotate(25deg); opacity: 1; } }
.bigwrap { position: relative; }
.btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
.btn { height: 52px; padding: 0 22px; border-radius: 16px; font: 900 17px/1 var(--ui); background: var(--cream); border: 3px solid #a67c4a; box-shadow: 0 3px 0 rgba(90, 52, 24, .45); }
.btn.pri { background: var(--red); color: var(--cream); border-color: #9c2f25; }
.btn:active { transform: translateY(2px); }
.shelfgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; margin: 10px 0 6px; }
.shelfgrid .tile { isolation: isolate; display: block; position: relative; padding: 4px 4px 14px; background: none; text-align: center; }
.shelfgrid .tile svg { width: 100%; height: auto; display: block; }
.shelfgrid .tile::after { content: ''; position: absolute; left: -8px; right: -8px; bottom: 4px; height: 12px; border-radius: 4px; background: linear-gradient(#c58f5d, #a67044); box-shadow: 0 3px 0 rgba(60, 30, 10, .35); z-index: -1; }
.shelfgrid .tile span { font: 400 17px/1 var(--hand); display: block; margin-top: -2px; }
.empty { font: 400 22px/1.2 var(--hand); color: #7a6648; margin: 26px 0; }

#toast { position: fixed; left: 50%; bottom: 74px; transform: translate(-50%, 20px); background: rgba(40, 22, 8, .9); color: var(--cream); font: 800 16px/1.2 var(--ui); padding: 10px 18px; border-radius: 22px; opacity: 0; transition: .25s; pointer-events: none; z-index: 60; max-width: 80vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* tall and narrow: phone upright. mat on top, trays below */
@media (max-width: 760px) and (min-height: 560px), (max-aspect-ratio: 4/5) {
	#app { padding-right: 10px; grid-template-columns: minmax(0, 1fr); grid-template-rows: 54px auto minmax(220px, 1fr) auto auto auto auto auto; gap: 7px; padding: 10px 10px 8px;
		grid-template-areas: "ruler" "tools" "mat" "tray" "stitch" "thread" "make" "helpers"; }
	#ruler { margin: 0 52px; }
	#stepT { font-size: 17px; }
	#side, #strip { display: contents; }
	#tools { grid-area: tools; padding-right: 50px; } #tools .tool { flex: 1; padding: 0 6px; }
	#makeCard { padding-left: 62px; }
	#helpers { grid-area: helpers; padding-left: 62px; justify-content: flex-start; }
	#stitchCard { grid-area: stitch; } #threadCard { grid-area: thread; } #makeCard { grid-area: make; }
	.card { padding: 6px 8px; border-radius: 16px; }
	.card h2 { display: none; }
	#tray { margin: 0; align-self: stretch; max-height: none; flex-direction: column; gap: 4px; overflow: visible; }
	#tray h2 { display: block; font-size: 15px; margin: 0; text-align: left; }
	#tray h2 small { display: inline; margin-left: 6px; }
	#fabsWrap { overflow-x: auto; overflow-y: hidden; flex: none; min-height: 66px; }
	#fabs { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 54px; gap: 6px; padding: 3px 2px; width: max-content; }
	.fab { width: 54px; height: 54px; }
	#colsRow { display: flex; align-items: center; gap: 8px; } #colsRow h3 { display: none; }
	#cols { display: flex; gap: 8px; flex: 1; justify-content: space-between; }
	.col { width: 44px; height: 44px; }
	#stitches { grid-template-columns: repeat(4, 1fr); } #stitches .opt { height: 46px; }
	#threads { grid-template-columns: repeat(6, 1fr); } #threads .opt { height: 50px; }
	#makeBtns { grid-template-columns: repeat(4, 1fr); } .mk { min-height: 62px; } .mk svg { width: 30px; height: 30px; }
	#toast { bottom: 120px; }
	#tray, #stitchCard, #threadCard, #makeCard, #tools, #helpers { width: 100%; max-width: 640px; justify-self: center; }
	#tray h2 { display: none; }
	#fabsWrap { min-height: 60px; }
	.card { padding: 4px 8px; }
	#tools .tool { height: 46px; }
}
/* short and wide: phone on its side */
@media (max-height: 559px) and (min-aspect-ratio: 5/4) {
	#side .card { flex: none; }
	#side, #tray { -webkit-mask-image: none; }
	#app { grid-template-columns: 166px minmax(0, 1fr) 160px; grid-template-rows: 44px minmax(0, 1fr) 50px; gap: 6px 10px; padding: 8px 66px 8px 66px; }
	#ruler { margin: 0 54px; } #stepN { width: 28px; height: 28px; font-size: 18px; line-height: 28px; margin-top: 2px; } #stepT { font-size: 17px; margin-top: 2px; }
	.card { padding: 6px 8px; border-radius: 16px; } .card h2 { font-size: 16px; margin-bottom: 3px; } .card h2 small { display: none; }
	#tray { max-height: none; align-self: stretch; } #fabs { grid-template-columns: repeat(3, 1fr); gap: 4px; } .fab { min-width: 44px; min-height: 44px; }
	#colsRow h3 { display: none; } #cols { grid-template-columns: repeat(3, 1fr); gap: 4px; } .col { width: 44px; height: 44px; }
	#tray { overflow-y: auto; } #fabsWrap { flex: none; overflow: visible; }
	#side { margin-bottom: 0; gap: 6px; }
	/* the right column fits one screen with no scrolling: it runs the full height (the step ruler stops at the mat), the Stitch and Thread headings are gone (the pictures say it, as on a phone upright) */
	#app { grid-template-areas: "ruler ruler side" "tray mat side" "tray strip side"; } #ruler { margin: 0 0 0 54px; }
	#stitchCard h2, #threadCard h2 { display: none; } #stitches, #threads, #makeBtns { gap: 5px; }
	#stitches .opt { height: 44px; } #threads .opt { height: 44px; } .mk { min-height: 48px; } .mk svg { width: 24px; height: 24px; }
	.tool { height: 46px; padding: 0 10px; font-size: 13px; } #strip { gap: 8px; } #tools .tool span { display: none; } #tools .tool { padding: 0 12px; }
	#toast { bottom: 62px; }
	#sheet { padding: 10px 14px; } .bigmake { width: min(300px, 60vw); }
}
/* short laptop windows: keep the whole right column on screen */
@media (min-width: 761px) and (min-aspect-ratio: 4/5) and (max-height: 700px) and (min-height: 560px) {
	#side { gap: 7px; } #side .card { padding: 6px 10px 8px; } .card h2 { font-size: 19px; margin-bottom: 3px; }
	#stitches .opt { height: 42px; } #threads .opt { height: 46px; } .mk { min-height: 56px; } .mk svg { width: 30px; height: 30px; }
	#side { margin-bottom: 66px; }
}
/* the smallest phones on their side (375px tall): the Make buttons name themselves, so their heading steps aside and the cards tighten */
@media (max-height: 400px) and (min-aspect-ratio: 5/4) {
	#makeCard h2 { display: none; } #side .card { padding: 4px 8px; } #side { gap: 5px; } .mk { min-height: 46px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
