/* Puzzle Maker. Look A "Craft Table" from the design canvas (Nick, 2026-10-10): a wooden table,
   cream stickers with ink outlines and hard shadows, Chewy + Sniglet. Same family as the sewing
   shop's Cozy Craft Room.

   The four screen corners belong to the shared buttons: 🏠 top-left, ⛶ top-right, 🔊 + 📮
   bottom-left, and the portal's 💬 bottom-right (it floats over this iframe). The bars keep
   76px clear at both ends for exactly that reason; the table between the bars is ours. */
:root {
	--ink: #3b2a2a;
	--cream: #fff6e5;
	--kraft: #ead3a8;
	--well: #d6b986;
	--coral: #ff8a65;
	--mint: #8fdcc0;
	--lemon: #ffd84d;
	--topH: 88px;
	--botH: 124px;
	--side: 76px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
	background-color: #c48f5a;
	background-image:
		repeating-linear-gradient(0deg, rgba(59, 42, 42, 0.12) 0 2px, transparent 2px 164px),
		repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 3px, transparent 3px 23px, rgba(59, 42, 42, 0.05) 23px 25px, transparent 25px 61px);
	font-family: 'Sniglet', 'Arial Rounded MT Bold', system-ui, sans-serif;
	color: var(--ink);
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
svg { display: block; }
.stk { background: var(--cream); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 4px 5px 0 var(--ink); }
button.stk:active { transform: translate(2px, 3px); box-shadow: 2px 2px 0 var(--ink); }
button svg { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top: the picture's name ---------- */
.top {
	position: fixed; left: 0; right: 0; top: 0; height: var(--topH); z-index: 20;
	display: flex; align-items: center; justify-content: center;
	padding: 0 220px;
}
.title { display: flex; align-items: center; gap: 16px; min-width: 0; }
#thumb {
	width: 96px; height: 64px; flex: none;
	border: 3px solid var(--ink); border-radius: 10px; background: var(--cream);
	box-shadow: 3px 3px 0 var(--ink); transform: rotate(-4deg);
}
.tt { min-width: 0; }
.tt h1 {
	margin: 0; font-family: 'Chewy', cursive; font-weight: 400; font-size: 40px; line-height: 1.05;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#count { font-weight: 800; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.2em; }
.pics-btn {
	position: absolute; right: 80px; top: 15px; height: 58px; padding: 0 20px;
	display: flex; align-items: center; gap: 10px;
	font-family: 'Chewy', cursive; font-size: 25px; border-radius: 18px; box-shadow: 3px 4px 0 var(--ink);
}
.pics-btn svg { width: 24px; height: 24px; }

/* ---------- the table ---------- */
#table { position: fixed; left: 0; right: 0; top: var(--topH); bottom: var(--botH); touch-action: none; }
#mat { position: absolute; background: var(--kraft); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 5px 6px 0 var(--ink); }
#board, #whole, #lines, #shine { position: absolute; left: 0; top: 0; }
#whole, #lines, #shine { pointer-events: none; }
#lines { transition: opacity 0.45s; }
#shine { overflow: hidden; }
#shine::after {
	content: ''; position: absolute; top: -10%; bottom: -10%; width: 34%; left: -40%;
	background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.55), transparent);
	transform: skewX(-12deg); opacity: 0;
}
#shine.go::after { animation: shine 0.9s ease-out; }
@keyframes shine { 0% { left: -40%; opacity: 1; } 100% { left: 110%; opacity: 1; } }
#pieces { position: absolute; inset: 0; pointer-events: none; }
.pc { position: absolute; left: 0; top: 0; transform-origin: 50% 50%; will-change: transform; }
.pc.fly { transition: transform 0.6s cubic-bezier(0.2, 1.25, 0.4, 1); }
.pc.lift { transition: transform 0.12s ease-out; }
.pc.snap { transition: transform 0.15s ease-out; }
.pc.held { filter: drop-shadow(8px 12px 0 rgba(59, 42, 42, 0.42)); }
#brush { position: absolute; left: 0; top: 0; width: 96px; height: 96px; z-index: 900; pointer-events: none; }
#stamp {
	position: absolute; z-index: 901; pointer-events: none;
	padding: 6px 26px 10px; background: var(--lemon); border: 4px solid var(--ink); border-radius: 22px;
	box-shadow: 5px 6px 0 var(--ink); font-family: 'Chewy', cursive; font-size: 58px; line-height: 1;
	transform: translate(-50%, -50%) rotate(-6deg); animation: stamp 1.6s ease-out forwards;
}
@keyframes stamp {
	0% { transform: translate(-50%, -50%) rotate(-6deg) scale(0.2); opacity: 0; }
	18% { transform: translate(-50%, -50%) rotate(-6deg) scale(1.12); opacity: 1; }
	30% { transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
	80% { opacity: 1; }
	100% { transform: translate(-50%, -50%) rotate(-6deg) scale(1); opacity: 0; }
}
#table.jolt { animation: jolt 0.4s; }
@keyframes jolt { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-7px, 2px); } 40% { transform: translate(6px, -2px); } 60% { transform: translate(-4px, 1px); } 80% { transform: translate(3px, 0); } }
.wiggle { animation: wiggle 0.42s; }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } 75% { transform: rotate(-2deg); } }

/* ---------- bottom: break, how many, glue ---------- */
.bar {
	position: fixed; left: 0; right: 0; bottom: 0; height: var(--botH); z-index: 20;
	display: flex; align-items: center; justify-content: center; gap: 20px;
	padding: 0 var(--side) 6px;
}
.big {
	position: relative; height: 84px; padding: 0 28px;
	display: flex; align-items: center; gap: 12px;
	font-family: 'Chewy', cursive; font-size: 33px; border-radius: 26px; white-space: nowrap;
}
.big svg { width: 32px; height: 32px; flex: none; }
.coral { background: var(--coral); }
.mint { background: var(--mint); }
#glueBtn.wait { background: #cfe9de; }
#glueBtn.ready, #breakBtn.ready { animation: ready 1.3s ease-in-out infinite; }
#glueBtn.unglue { background: var(--cream); }
@keyframes ready { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.badge {
	position: absolute; right: -14px; top: -17px; padding: 3px 10px;
	background: var(--cream); border: 2px solid var(--ink); border-radius: 12px; transform: rotate(7deg);
	font-family: 'Sniglet', sans-serif; font-weight: 800; font-size: 15px; white-space: nowrap;
}
.chips { display: flex; align-items: center; gap: 9px; padding: 9px 14px; border-radius: 26px; }
.chips .lbl { font-family: 'Chewy', cursive; font-size: 22px; margin-right: 2px; }
.chips button {
	width: 56px; height: 56px; padding: 0; border-radius: 50%;
	background: var(--cream); border: 2px solid var(--ink); font-weight: 800; font-size: 21px;
}
.chips button[aria-pressed='true'] { background: var(--lemon); border-width: 3px; box-shadow: 2px 3px 0 var(--ink); }

/* ---------- coach + toast ---------- */
.coach {
	position: fixed; z-index: 30; pointer-events: none;
	padding: 10px 18px; background: #fff; border: 3px solid var(--ink); border-radius: 18px;
	box-shadow: 3px 4px 0 var(--ink); font-size: 22px; font-weight: 800; white-space: nowrap;
	transform: translate(-50%, -100%); animation: bob 1.2s ease-in-out infinite;
}
.coach b { font-family: 'Chewy', cursive; font-weight: 400; font-size: 26px; }
.coach::after {
	content: ''; position: absolute; left: 50%; bottom: -14px; width: 20px; height: 20px; margin-left: -10px;
	background: #fff; border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(45deg);
}
@keyframes bob { 0%, 100% { margin-top: 0; } 50% { margin-top: -8px; } }
.toast {
	position: fixed; left: 50%; top: calc(var(--topH) + 8px); z-index: 40; pointer-events: none;
	max-width: calc(100% - 160px); padding: 10px 20px; background: #fff;
	border: 3px solid var(--ink); border-radius: 16px; box-shadow: 3px 4px 0 var(--ink);
	font-size: 20px; font-weight: 800; text-align: center;
	opacity: 0; transform: translate(-50%, -16px); transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- the picture shelf ---------- */
.sheet {
	position: fixed; inset: 0; z-index: 100; overflow-y: auto; -webkit-overflow-scrolling: touch;
	background: rgba(59, 42, 42, 0.5); padding: 80px 16px 40px; touch-action: pan-y;
}
.sheet-card {
	position: relative; width: min(920px, 100%); margin: 0 auto;
	background: var(--cream); border: 3px solid var(--ink); border-radius: 26px; box-shadow: 6px 8px 0 var(--ink);
	padding: 22px 24px 28px;
}
.sheet h2 { font-family: 'Chewy', cursive; font-weight: 400; font-size: 40px; margin: 0 64px 16px 0; line-height: 1.1; }
.sheet h3 { font-family: 'Chewy', cursive; font-weight: 400; font-size: 28px; margin: 26px 0 12px; }
.x {
	position: absolute; right: 16px; top: 16px; width: 54px; height: 54px; padding: 0;
	display: flex; align-items: center; justify-content: center;
	border-radius: 50%; background: #fff; border: 3px solid var(--ink); box-shadow: 2px 3px 0 var(--ink);
}
.x svg { width: 26px; height: 26px; stroke-width: 3; }
.pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
.pic {
	position: relative; display: flex; flex-direction: column; gap: 8px; padding: 10px;
	background: #fff; border: 3px solid var(--ink); border-radius: 18px; box-shadow: 3px 4px 0 var(--ink);
	font-family: 'Chewy', cursive; font-size: 22px; text-align: center; cursor: pointer;
}
.pic:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.pic img, .pic canvas, .pic .cam {
	display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover;
	border: 2px solid var(--ink); border-radius: 11px; background: var(--well);
}
.pic[aria-current='true'] { background: var(--lemon); }
.photo-pick .cam { display: flex; align-items: center; justify-content: center; background: var(--mint); }
.photo-pick .cam svg { width: 64px; height: 64px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.photo-pick input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* ---------- smaller screens ---------- */
/* Under 960px the three controls no longer fit one row between the corners: chips go on top. */
@media (max-width: 960px) {
	:root { --botH: 178px; }
	.bar {
		display: grid; grid-template-columns: auto auto; grid-template-areas: 'chips chips' 'brk glue';
		align-content: center; justify-content: center; gap: 14px 16px;
	}
	.chips { grid-area: chips; justify-self: center; }
	#breakBtn { grid-area: brk; }
	#glueBtn { grid-area: glue; }
	.big { height: 66px; font-size: 27px; padding: 0 20px; }
	.big svg { width: 26px; height: 26px; }
}
/* Phones: 375px minus 68px a side leaves 239px. The chips lose their sticker panel (five 44px
   circles and four 4px gaps is 236px) and the big buttons lose their icons. */
@media (max-width: 640px) {
	:root { --topH: 78px; --side: 68px; --botH: 150px; }
	.top { justify-content: flex-start; padding: 0 140px 0 72px; }
	#thumb { display: none; }
	.tt h1 { font-size: 29px; }
	#count { font-size: 16px; }
	.pics-btn { right: 72px; top: 12px; width: 54px; height: 54px; padding: 0; justify-content: center; }
	.pics-btn span { display: none; }
	.bar { gap: 12px 10px; }
	.chips { gap: 4px; padding: 0; background: none; border: 0; box-shadow: none; }
	.chips .lbl { display: none; }
	.chips button { width: 44px; height: 44px; font-size: 17px; }
	.big { height: 58px; font-size: 21px; padding: 0 12px; gap: 0; border-radius: 20px; }
	.big svg { display: none; }
	.badge { font-size: 13px; top: -15px; right: -10px; }
	.sheet { padding-top: 76px; }
	.sheet h2 { font-size: 32px; }
	.pics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
	.pic { font-size: 18px; }
}
/* A phone on its side: one thin row of everything, or there is no table left. */
@media (max-height: 520px) and (min-width: 600px) {
	:root { --topH: 62px; --botH: 76px; --side: 68px; }
	.top { justify-content: flex-start; padding: 0 140px 0 72px; }
	#thumb { display: none; }
	.tt { display: flex; align-items: baseline; gap: 12px; }
	.tt h1 { font-size: 26px; }
	#count { font-size: 15px; }
	.pics-btn { right: 72px; top: 6px; width: 50px; height: 50px; padding: 0; justify-content: center; }
	.pics-btn span { display: none; }
	.bar { display: flex; gap: 10px; padding-bottom: 4px; }
	.chips { gap: 4px; padding: 0; background: none; border: 0; box-shadow: none; }
	.chips .lbl { display: none; }
	.chips button { width: 44px; height: 44px; font-size: 17px; }
	.big { height: 54px; font-size: 21px; padding: 0 12px; gap: 0; border-radius: 18px; }
	.big svg { display: none; }
	.badge { font-size: 13px; top: -14px; right: -10px; }
}
@media (prefers-reduced-motion: reduce) {
	.coach, #glueBtn.ready, #breakBtn.ready { animation: none; }
}
