:root {
  --bg: #fff;
  --fg: #111;
  --muted: #8a8a8a;
  --tile: #f2f2f2;
  --tile-hover: #ececec;
  --line: #e6e6e6;
  --bar-h: 48px;
  --gutter: 16px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: "Helvetica Neue", Helvetica, "SF Pro Text", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
html.lock { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 12px/1.5 var(--font);
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; letter-spacing: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, p { margin: 0; font-size: inherit; font-weight: 400; }
img, svg { display: block; max-width: 100%; }

:focus-visible { outline: 1px solid var(--fg); outline-offset: 3px; }

/* ---------- top bar ---------- */
.bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  height: var(--bar-h);
  padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}
.bar__right { display: flex; gap: 24px; }
.bar__link { text-transform: uppercase; display: inline-flex; gap: 6px; min-height: 44px; align-items: center; }
.bar__link[aria-current="page"] { text-decoration: underline; text-underline-offset: 4px; }
#cart-count:not(:empty)::before { content: "("; }
#cart-count:not(:empty)::after  { content: ")"; }

main { flex: 1 0 auto; padding-top: calc(var(--bar-h) + env(safe-area-inset-top)); outline: none; }

.foot {
  padding: 28px var(--gutter) calc(28px + env(safe-area-inset-bottom));
  color: var(--muted);
}
.foot:empty { display: none; }
@media (min-width: 900px) { .foot { padding-left: 32px; padding-right: 32px; } }
#view > * { animation: fade 260ms ease-out both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  padding-bottom: 2px;
}
@media (min-width: 720px)  { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1180px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tile { display: block; }
.media {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--tile);
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: background-color 200ms var(--ease);
}
.media svg { width: 100%; height: 100%; }
/* Photos fill the tile and fit inside it without cropping. They are shot on
   white: multiply lets that white take the grey tile colour. */
.media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; }
/* A bundle: its first two photos side by side, overlapping a little. */
.media img.pair-a { right: auto; width: 56%; }
.media img.pair-b { left: auto; width: 56%; }
.media svg { padding: 6%; }
@media (hover: hover) { .tile:hover .media { background: var(--tile-hover); } }

.cap {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px var(--gutter) 22px;
  text-transform: uppercase;
}
.cap .price, .cap .muted { white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------- product page ---------- */
.pdp { display: grid; grid-template-columns: minmax(0, 1fr); }
.pdp .media { height: min(100vw, 75vh); }
.pdp .media svg { padding: 10%; }
@media (min-width: 900px) { .pdp .media { height: auto; aspect-ratio: 1 / 1; } }

/* Several photos: stacked on wide screens, a swipeable row on phones. */
.gallery { display: grid; gap: 2px; min-width: 0; align-content: start; }
@media (max-width: 899px) {
  .gallery {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .gallery::-webkit-scrollbar { display: none; }
  .gallery .media { flex: 0 0 100%; scroll-snap-align: start; }
  .gallery .media:not(:only-child) { flex-basis: 88%; } /* the next photo peeks in */
}

.pdp__info {
  padding: 20px var(--gutter) 40px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}
.pdp__head { display: grid; gap: 14px; }
.pdp__title { text-transform: uppercase; display: flex; justify-content: space-between; gap: 16px; }
.pdp__blurb { max-width: 36ch; color: var(--muted); }

.sizes { border: 0; margin: 0; padding: 0; min-width: 0; }
.sizes legend { padding: 0; margin-bottom: 10px; text-transform: uppercase; color: var(--muted); }
.sizes__row { display: flex; flex-wrap: wrap; gap: 6px; }
.sizes input { position: absolute; opacity: 0; pointer-events: none; }
.sizes label {
  min-width: 48px;
  height: 44px;
  padding: 0 14px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  transition: border-color 150ms, background-color 150ms, color 150ms;
}
@media (hover: hover) { .sizes label:hover { border-color: var(--fg); } }
.sizes input:checked + label { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.sizes input:focus-visible + label { outline: 1px solid var(--fg); outline-offset: 3px; }
/* A size that is sold out stays visible but cannot be picked. */
.sizes input:disabled + label { color: var(--muted); border-color: var(--line); text-decoration: line-through; cursor: not-allowed; opacity: 0.6; }

.btn {
  width: 100%;
  height: 48px;
  background: var(--fg);
  color: var(--bg);
  text-transform: uppercase;
  transition: opacity 150ms, transform 120ms var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.99); }
.btn:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }
@media (hover: hover) { .btn:hover:not(:disabled) { opacity: 0.85; } }

.pdp__buy { display: grid; gap: 28px; }
.buy { display: grid; gap: 14px; }
.details { color: var(--muted); display: grid; gap: 2px; }

@media (min-width: 900px) {
  .pdp { grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr); }
  .pdp__info {
    position: sticky;
    top: var(--bar-h);
    height: calc(100vh - var(--bar-h));
    padding: 24px 32px 32px;
    justify-content: space-between;
    gap: 32px;
    overflow-y: auto;
  }
}

.back { display: inline-block; padding: 8px var(--gutter) 0; text-transform: uppercase; color: var(--muted); }
@media (min-width: 900px) { .back { display: none; } }

/* ---------- info ---------- */
.info { max-width: 560px; padding: 32px var(--gutter) 96px; display: grid; gap: 40px; }
.info h2 { text-transform: uppercase; margin-bottom: 8px; }
.info p { color: var(--muted); max-width: 52ch; }
.info #thanks-msg { color: var(--fg); }
@media (min-width: 900px) { .info { padding-left: 32px; } }

/* ---------- not found / empty ---------- */
.empty { padding: 48px var(--gutter); color: var(--muted); }
.empty a { color: var(--fg); text-decoration: underline; text-underline-offset: 4px; }

/* ---------- cart ---------- */
dialog#cart {
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  width: min(100vw, 420px);
  max-width: none;
  height: 100dvh;
  max-height: none;
  background: var(--bg);
  color: var(--fg);
}
dialog#cart[open] { display: flex; flex-direction: column; animation: slide 280ms var(--ease) both; }
dialog#cart::backdrop { background: rgba(0, 0, 0, 0.18); animation: fade 200ms ease-out both; }
@keyframes slide { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }

.cart__top {
  height: var(--bar-h);
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-transform: uppercase;
  flex: none;
}
.cart__top button { min-height: 44px; }

.cart__list { flex: 1; overflow-y: auto; padding: 0 var(--gutter); overscroll-behavior: contain; }
.cart__empty { color: var(--muted); padding-top: 8px; }

.line { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.line .media { aspect-ratio: 1 / 1; }
.line .media svg { padding: 4%; }
.line__body { display: flex; flex-direction: column; justify-content: space-between; gap: 10px; min-width: 0; }
.line__row { display: flex; justify-content: space-between; gap: 12px; text-transform: uppercase; }
.line__row .price { white-space: nowrap; }
.line__meta { color: var(--muted); text-transform: uppercase; }
.line__ctl { display: flex; justify-content: space-between; align-items: center; }
.qty { display: inline-flex; align-items: center; }
.qty button { width: 32px; height: 32px; display: grid; place-items: center; }
.qty button:disabled { opacity: 0.3; cursor: default; }
.qty output { min-width: 20px; text-align: center; }
.link { text-decoration: underline; text-underline-offset: 4px; color: var(--muted); }
@media (hover: hover) { .link:hover { color: var(--fg); } }

.cart__foot {
  flex: none;
  padding: 16px var(--gutter) calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
}
.cart__sub { display: flex; justify-content: space-between; text-transform: uppercase; }
.cart__note { color: var(--muted); min-height: 1.5em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
