/* Product page: "pack your box" (views/pages/product.php, js/product-pack.js).
   Kraft crates for the quantity tiles, a stamped stepper, and a box meter with
   the spend ladder as ticks. Brand tokens from app.css. */

.pk {
	--kraft: #c9965f;
	--kraft-deep: #a8743f;
	--kraft-dark: #7d5229;
	--kraft-pale: #f6ead9;
	--hot: #ff3b70;
	--hot-deep: #c81f50;
	--sun: #ffcf33;
	--mint: #0b7a44;
	margin: 0.25rem 0 0.5rem;
}

.pk-label { font-family: var(--ui); font-weight: 700; font-size: 1rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); margin-bottom: 0.6rem; }
.pk-label span { font-family: var(--body); font-weight: 400; font-size: 0.78rem; letter-spacing: 0; text-transform: none; color: var(--grey); margin-left: 0.35rem; }

/* ── Tiles ─────────────────────────────────────────────────────────── */
.pk-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 0.6rem; margin-bottom: 1rem; }
.pk-tile {
	position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
	padding: 0.7rem 0.4rem 0.65rem; border: 2px solid #e6e1d8; border-radius: 14px; background: #fff;
	cursor: pointer; font: inherit; color: var(--ink); text-align: center;
	transition: border-color .15s, transform .15s, box-shadow .15s;
}
.pk-tile:hover:not(:disabled) { border-color: var(--kraft); transform: translateY(-2px); }
.pk-tile:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; }
.pk-tile.is-on, .pk-tile.is-on:hover:not(:disabled) { border-color: var(--hot); background: #fff5f8; box-shadow: 0 4px 0 var(--hot); transform: translateY(-2px); }
.pk-tile.is-on::after {
	content: '✓'; position: absolute; top: -9px; right: -9px; width: 22px; height: 22px; border-radius: 50%;
	background: var(--hot); color: #fff; font-size: 0.75rem; font-weight: 700; display: grid; place-items: center;
}
.pk-tile:disabled { opacity: 0.4; cursor: not-allowed; }

/* The crate: packs peek over the back flap, the front panel is stamped. */
.pk-crate { position: relative; width: 74px; height: 62px; margin-bottom: 0.35rem; }
.pk-crate::before { /* back wall + flap */
	content: ''; position: absolute; left: 6px; right: 6px; top: 16px; height: 18px;
	background: var(--kraft-deep); border-radius: 3px 3px 0 0; transform: skewX(-8deg);
}
.pk-crate img {
	position: absolute; bottom: 20px; left: 50%; width: 34px; height: 34px; object-fit: contain;
	background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.25);
	transform: translateX(calc(-50% + (var(--n) - (var(--of) - 1) / 2) * 13px)) rotate(calc((var(--n) - (var(--of) - 1) / 2) * 9deg));
	transition: transform .25s;
}
.pk-crate::after { /* front panel with tape */
	content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 30px; border-radius: 4px;
	background:
		linear-gradient(90deg, transparent 44%, rgba(255,255,255,.35) 44% 56%, transparent 56%),
		linear-gradient(180deg, var(--kraft) 0%, var(--kraft-deep) 100%);
	box-shadow: inset 0 2px 0 rgba(255,255,255,.25), 0 2px 0 var(--kraft-dark);
}
.pk-tile:hover .pk-crate img, .pk-tile.is-on .pk-crate img {
	transform: translateX(calc(-50% + (var(--n) - (var(--of) - 1) / 2) * 15px)) translateY(-5px) rotate(calc((var(--n) - (var(--of) - 1) / 2) * 12deg));
}
.pk-x {
	position: absolute; z-index: 2; left: 50%; bottom: 4px; transform: translateX(-50%) rotate(-4deg);
	font-family: var(--display); font-size: 0.95rem; line-height: 1; color: #fff;
	text-shadow: 0 1px 0 var(--kraft-dark);
}
.pk-total { font-family: var(--ui); font-weight: 700; font-size: 1.25rem; line-height: 1.1; color: var(--ink); }
.pk-perk { font-family: var(--ui); font-weight: 700; font-size: 0.78rem; letter-spacing: 0.03em; text-transform: uppercase; color: var(--hot-deep); line-height: 1.2; }
.pk-perk s { display: block; font-weight: 600; color: var(--grey); text-transform: none; letter-spacing: 0; }
.pk-perk--ship { color: var(--mint); }
.pk-perk--plain { color: var(--grey); font-weight: 600; }

/* ── Stepper + add ─────────────────────────────────────────────────── */
.pk-buy { display: flex; gap: 0.6rem; align-items: stretch; }
.pk-step {
	display: flex; align-items: center; border: 2px solid var(--ink); border-radius: 99px; background: #fff;
	overflow: hidden; flex: none;
}
.pk-step button {
	width: 42px; height: 100%; min-height: 50px; border: 0; background: none; cursor: pointer;
	font-size: 1.35rem; font-weight: 700; color: var(--ink);
}
.pk-step button:hover:not(:disabled) { background: var(--kraft-pale); }
.pk-step button:disabled { color: #c4c4c4; cursor: default; }
.pk-step button:focus-visible { outline: 3px solid var(--cobalt); outline-offset: -3px; }
.pk-step output { min-width: 2ch; text-align: center; font-family: var(--display); font-size: 1.1rem; }

.pk .pk-add {
	flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 0.55rem;
	background: var(--hot); box-shadow: 0 4px 0 var(--hot-deep); font-size: 1.05rem; letter-spacing: 0.05em;
	text-transform: uppercase; min-height: 54px; transition: transform .1s, box-shadow .1s, background .2s;
}
.pk .pk-add:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 5px 0 var(--hot-deep); }
.pk .pk-add:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--hot-deep); }
.pk .pk-add.is-added { background: var(--mint); box-shadow: 0 4px 0 #075c33; }
.pk .pk-add:disabled { background: #b9b9b9; box-shadow: 0 4px 0 #8d8d8d; cursor: not-allowed; }
/* A tiny open crate icon, drawn in CSS so it inherits the button colour. */
.pk-add-ico { position: relative; width: 20px; height: 15px; flex: none; border: 2.5px solid currentColor; border-top: 0; border-radius: 0 0 3px 3px; }
.pk-add-ico::before, .pk-add-ico::after { content: ''; position: absolute; top: -2px; width: 9px; height: 2.5px; background: currentColor; }
.pk-add-ico::before { left: -6px; transform: rotate(-30deg); }
.pk-add-ico::after { right: -6px; transform: rotate(30deg); }
.pk-add.is-added .pk-add-ico { display: none; }

/* ── The box meter ─────────────────────────────────────────────────── */
.pk-meter {
	margin-top: 1rem; padding: 0.9rem 1rem 0.8rem; border-radius: 14px;
	background: var(--kraft-pale); border: 2px dashed var(--kraft);
}
.pk-meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.pk-meter-title { font-family: var(--ui); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--kraft-dark); }
.pk-meter-title b { color: var(--ink); }
.pk-meter-sum { font-family: var(--ui); font-weight: 700; font-size: 1rem; color: var(--ink); }

.pk-bar { position: relative; height: 12px; margin: 1.45rem 0 1.55rem; border-radius: 99px; background: #fff; box-shadow: inset 0 0 0 1.5px #e3cfb4; }
.pk-fill { position: absolute; inset: 0; display: flex; border-radius: 99px; overflow: hidden; }
.pk-bar-have { height: 100%; background: var(--cobalt); transition: width .35s; }
.pk-bar-add { height: 100%; transition: width .35s; background: repeating-linear-gradient(-45deg, var(--hot) 0 6px, #ff7d9f 6px 12px); }
.pk-tick { position: absolute; top: -3px; width: 3px; height: 18px; margin-left: -1.5px; background: var(--kraft-dark); border-radius: 2px; font-style: normal; }
.pk-tick em {
	position: absolute; top: 20px; left: 50%; transform: translateX(-50%); white-space: nowrap;
	font-family: var(--ui); font-style: normal; font-weight: 700; font-size: 0.68rem; letter-spacing: 0.02em; color: var(--kraft-dark);
}
.pk-tick--up em { top: -19px; }
.pk-tick:last-of-type em { left: auto; right: -2px; transform: none; }
.pk-tick.is-had { background: var(--cobalt); }
.pk-tick.is-had em { color: var(--cobalt); }
.pk-tick.is-hit { background: var(--hot); }
.pk-tick.is-hit em { color: #fff; background: var(--hot); padding: 1px 5px; border-radius: 4px; }
.pk-meter-msg { margin: 0; font-size: 0.86rem; line-height: 1.55; color: var(--ink-soft); }
.pk-meter-msg b { color: var(--hot-deep); }
.pk-meter-link { display: inline-block; margin-top: 0.35rem; font-family: var(--ui); font-weight: 700; font-size: 0.85rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--cobalt); text-decoration: none; }
.pk-meter-link:hover { text-decoration: underline; }

/* The meter gives a little hop when something lands in the box. */
.pk.is-dropped .pk-meter { animation: pk-hop .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes pk-hop { 0% { transform: none; } 35% { transform: translateY(3px) scaleY(.97); } 100% { transform: none; } }

/* Flight from the product photo to the header badge (js/product-pack.js). */
.pk-ghost { position: fixed; z-index: 9999; pointer-events: none; object-fit: contain; background: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.pk-bump { animation: pk-bump .45s cubic-bezier(.3,1.8,.5,1); }
@keyframes pk-bump { 0% { transform: scale(1); } 40% { transform: scale(1.6); } 100% { transform: scale(1); } }

@media (max-width: 520px) {
	.pk-row { grid-template-columns: repeat(2, 1fr); }
	.pk-buy { flex-wrap: wrap; }
	.pk-step { width: 100%; justify-content: space-between; }
	.pk-step button { width: 56px; min-height: 46px; }
	.pk .pk-add { width: 100%; }
	.pk-tick em { font-size: 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
	.pk-tile, .pk-crate img, .pk-bar-have, .pk-bar-add, .pk .pk-add { transition: none; }
	.pk.is-dropped .pk-meter, .pk-bump { animation: none; }
}

/* Sticky bar mirrors the main button's "added" state. */
.pdp-sb-btn.is-added { background: #0b7a44 !important; }
