/* ---------- BASE ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fff8f1;
  --ink: #1f1a17;
  --muted: #7a6f66;
  --card: #ffffff;
  --accent: #ff6a3d;
  --accent-dark: #e24e22;
  --ok: #16a34a;
  --radius: 20px;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
body.locked { overflow: hidden; }   /* stop the page scrolling behind the open cart */

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* ---------- END BASE ---------- */

/* ---------- HEADER ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgba(255, 248, 241, .85);
  backdrop-filter: blur(10px);
}
.brand { font-size: 26px; font-weight: 800; color: var(--ink); text-decoration: none; letter-spacing: -1px; }
.brand span { color: var(--accent); }

.cart-btn {
  position: relative;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  display: grid;
  place-items: center;
}
.cart-btn svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cart-btn.wiggle { animation: wiggle .5s ease; }

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  transform: scale(0);
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
.badge.has { transform: scale(1); }
.badge.bump { animation: bump .4s ease; }
/* ---------- END HEADER ---------- */

/* ---------- PRODUCT GRID ---------- */
.shop { max-width: 1100px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 48px) 60px; }
.shop h1 { font-size: clamp(30px, 5vw, 46px); letter-spacing: -1px; }
.sub { color: var(--muted); margin: 6px 0 28px; }

.grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.product {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .04), 0 12px 30px rgba(80, 40, 10, .07);
  transition: transform .3s cubic-bezier(.2, .9, .3, 1.3), box-shadow .3s;
  animation: enter .6s cubic-bezier(.2, .9, .3, 1.2) both;
  animation-delay: calc(var(--i) * 80ms);   /* cards arrive one after another */
}
.product:hover { transform: translateY(-6px); box-shadow: 0 20px 40px rgba(80, 40, 10, .14); }

.thumb {
  height: 170px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--tint);
  overflow: hidden;
}
.emoji {
  font-size: 84px;
  line-height: 1;
  transition: transform .4s cubic-bezier(.2, .9, .3, 1.4);
  filter: drop-shadow(0 12px 10px rgba(0, 0, 0, .15));
}
.product:hover .emoji { transform: scale(1.12) rotate(-8deg); }

.info { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 4px 12px; gap: 8px; }
.info h3 { font-size: 16px; }
.price { font-weight: 800; }

.add {
  position: relative;
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  overflow: hidden;
  transition: background .3s, transform .15s;
}
.add:hover { background: var(--accent); }
.add:active { transform: scale(.97); }
.add.added { background: var(--ok); }
/* ---------- END PRODUCT GRID ---------- */

/* ---------- FLYING ITEM ---------- */
/* Two layers: .fly moves left-right at a steady speed,
   .fly-inner moves up-down with easing. Together they draw an arc. */
.fly, .fly-inner { position: fixed; top: 0; left: 0; pointer-events: none; z-index: 50; }
.fly-inner { position: static; display: block; width: 60px; height: 60px; font-size: 52px; line-height: 60px; text-align: center; }
/* ---------- END FLYING ITEM ---------- */

/* ---------- CART DRAWER ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(31, 26, 23, .45);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .3s;
}
.backdrop.show { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .2);
  transform: translateX(calc(100% + 80px));   /* + 80px hides the shadow too */
  transition: transform .45s cubic-bezier(.2, .9, .3, 1);
}
.drawer.open { transform: none; }

.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px 10px; }
.drawer-head h2 { font-size: 22px; }
.close { width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .06); font-size: 15px; transition: transform .3s; }
.close:hover { transform: rotate(90deg); }

.ship { padding: 6px 22px 14px; border-bottom: 1px solid rgba(0, 0, 0, .07); }
.ship-text { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.ship-text b { color: var(--ink); }
.ship-bar { height: 8px; border-radius: 4px; background: rgba(0, 0, 0, .08); overflow: hidden; }
.ship-bar span {
  display: block;
  height: 100%;
  width: var(--p, 0%);
  border-radius: 4px;
  background: linear-gradient(90deg, #ffb547, var(--accent));
  transition: width .6s cubic-bezier(.2, .9, .3, 1), background .4s;
}
.ship.done .ship-bar span { background: linear-gradient(90deg, #4ade80, var(--ok)); }
.ship.done .ship-text { color: var(--ok); font-weight: 600; }

.items { list-style: none; flex: 1; overflow-y: auto; padding: 8px 22px; }
.item {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(0, 0, 0, .06);
  animation: slide-in .4s cubic-bezier(.2, .9, .3, 1.2);
}
.item-thumb { width: 58px; height: 58px; border-radius: 12px; display: grid; place-items: center; font-size: 32px; background: var(--tint); }
.item h3 { font-size: 15px; }
.item .each { font-size: 13px; color: var(--muted); }

.qty { display: inline-flex; align-items: center; gap: 2px; margin-top: 6px; border-radius: 10px; background: rgba(0, 0, 0, .05); }
.qty button { width: 28px; height: 28px; border: 0; background: none; font-size: 16px; font-weight: 700; border-radius: 8px; }
.qty button:hover { background: rgba(0, 0, 0, .07); }
.qty output { min-width: 20px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.qty output.tick { animation: tick .3s ease; }

.item-right { text-align: right; }
.line { display: block; font-weight: 800; font-variant-numeric: tabular-nums; }
.remove { margin-top: 6px; border: 0; background: none; font-size: 12px; color: var(--muted); text-decoration: underline; }
.remove:hover { color: var(--accent-dark); }

.empty { display: none; flex: 1; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); }
.drawer.is-empty .empty { display: flex; }
.drawer.is-empty .items, .drawer.is-empty .drawer-foot, .drawer.is-empty .ship { display: none; }
.empty-bag { font-size: 64px; animation: float 2.4s ease-in-out infinite; }
.keep { padding: 10px 18px; border: 2px solid var(--ink); border-radius: 12px; background: none; font-weight: 700; }

.drawer-foot { padding: 16px 22px 22px; border-top: 1px solid rgba(0, 0, 0, .07); }
.total { display: flex; justify-content: space-between; margin-bottom: 14px; font-size: 17px; }
.subtotal { font-variant-numeric: tabular-nums; }

.checkout {
  position: relative;
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  overflow: hidden;
  transition: background .3s;
}
.checkout:hover { background: var(--accent-dark); }
.checkout .truck {
  position: absolute;
  top: 50%;
  left: -40px;
  font-size: 26px;
  transform: translateY(-50%) scaleX(-1);   /* the emoji faces left; flip it to drive right */
}
.checkout .label { transition: opacity .2s; }
.checkout.going { background: var(--ink); }
.checkout.going .label { opacity: 0; }           /* the truck is the message now */
.checkout.going .truck { animation: drive 1.6s cubic-bezier(.5, 0, .5, 1) forwards; }
.checkout.done { background: var(--ok); }
/* ---------- END CART DRAWER ---------- */

/* ---------- KEYFRAMES ---------- */
@keyframes enter { from { opacity: 0; transform: translateY(30px) scale(.95); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-14deg) scale(1.1); } 50% { transform: rotate(10deg) scale(1.1); } 75% { transform: rotate(-6deg); } }
@keyframes bump { 50% { transform: scale(1.5); } }
@keyframes tick { 0% { transform: translateY(-8px); opacity: 0; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(40px); } }
@keyframes float { 50% { transform: translateY(-10px) rotate(4deg); } }
@keyframes drive { to { left: calc(100% + 40px); } }
/* ---------- END KEYFRAMES ---------- */

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
  }
}
/* ---------- END REDUCED MOTION ---------- */
