/* The two <dialog>s: containers and motion, shared parts (close button, arrows,
   monogram) and the editorial product view. The cart drawer is in
   store-cart.css. Loaded without blocking first paint: both dialogs start closed. */

/* ---------- Containers and motion ---------- */

.dialog {
  padding: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow-2);
  overscroll-behavior: contain;
}

/* showModal() may focus the container itself; the ring belongs on the controls inside. */
.dialog:focus-visible { outline: none; }

.dialog::backdrop {
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

/* Cart: a full-height drawer pinned to the right edge. */
#cart-dialog {
  width: 100%;
  max-width: 460px;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  box-shadow: var(--shadow-drawer);
}

#cart-dialog[open] { display: flex; flex-direction: column; }

/* Product: centred, editorial; gallery and details side by side from 900px. */
#product-dialog {
  width: calc(100% - 2 * var(--space-3));
  max-width: 1120px;
  max-height: calc(100dvh - 2 * var(--space-3));
  margin: auto;
  overflow-y: auto;
  border-radius: var(--radius-lg);
}

#product-dialog[open] { display: grid; }

/* Where the top layer can be animated (`overlay`), dialogs ease in slowly and
   leave quickly. Elsewhere they get the entry keyframes and close instantly. */
@supports not (overlay: auto) {
  .dialog[open]::backdrop { animation: fade-in var(--dur-base) var(--ease-out-soft); }
  #cart-dialog[open] { animation: slide-in-right var(--dur-slow) var(--ease-out-expo); }
  #product-dialog[open] { animation: fade-up var(--dur-slow) var(--ease-out-expo); }
}

@supports (overlay: auto) {
  .dialog,
  .dialog::backdrop {
    transition:
      opacity 240ms var(--ease-in-soft),
      transform 240ms var(--ease-in-soft),
      overlay 240ms allow-discrete,
      display 240ms allow-discrete;
  }

  .dialog[open],
  .dialog[open]::backdrop {
    transition-duration: var(--dur-slow);
    transition-timing-function: var(--ease-out-expo);
  }

  .dialog::backdrop { opacity: 0; }
  .dialog[open]::backdrop { opacity: 1; }
  #cart-dialog { transform: translateX(100%); }
  #cart-dialog[open] { transform: none; }
  #product-dialog { opacity: 0; transform: translateY(24px); }
  #product-dialog[open] { opacity: 1; transform: none; }

  @starting-style {
    .dialog[open]::backdrop { opacity: 0; }
    #cart-dialog[open] { transform: translateX(100%); }
    #product-dialog[open] { opacity: 0; transform: translateY(24px); }
  }
}

/* The global reduced-motion rule matches elements, not ::backdrop. */
@media (prefers-reduced-motion: reduce) {
  .dialog::backdrop,
  .dialog[open]::backdrop {
    animation: none;
    transition-duration: 0.01ms;
  }
}

/* ---------- Shared parts ---------- */

/* Some parts set display; [hidden] must still win. */
.dialog [hidden] { display: none !important; }

/* Round hairline buttons: dialog close and gallery arrows. Icons are drawn in CSS. */
.dialog__close,
.gallery__prev,
.gallery__next {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--glass);
  color: var(--text);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition:
    border-color var(--dur-fast) var(--ease-out-soft),
    background-color var(--dur-fast) var(--ease-out-soft),
    transform var(--dur-fast) var(--ease-out-soft);
}

.dialog__close:hover,
.gallery__prev:hover,
.gallery__next:hover { border-color: var(--text); background: var(--surface); }

.dialog__close:active,
.gallery__prev:active,
.gallery__next:active { transform: scale(0.95); }

/* Hairline "×". */
.dialog__close::before,
.dialog__close::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 15px;
  height: 1px;
  margin: auto;
  background: currentColor;
  rotate: 45deg;
}

.dialog__close::after { rotate: -45deg; }

/* Hairline chevrons: two borders of a small square, turned to point. */
.gallery__prev::before,
.gallery__next::before {
  content: '';
  position: absolute;
  inset: 0;
  width: 8px;
  height: 8px;
  margin: auto;
  border-top: 1px solid currentColor;
  border-left: 1px solid currentColor;
}

.gallery__prev::before { translate: 2px 0; rotate: -45deg; }
.gallery__next::before { translate: -2px 0; rotate: 135deg; }

.gallery__slide img,
.gallery__thumb img { width: 100%; height: 100%; object-fit: contain; }

/* Cut-out photos float inside the frame instead of being cropped by it. */
.gallery__slide img { padding: 6%; }
.gallery__thumb img { padding: 8%; }

/* No photo: the shared placeholder (store.css), sized for each frame. */
.gallery__placeholder .photo-placeholder__mark { font-size: clamp(3rem, 14vw, 5rem); }

/* A thumbnail is too small for the note; the mark alone reads as "no photo". */
.gallery__thumb-placeholder { gap: 0; }
.gallery__thumb-placeholder .photo-placeholder__mark { font-size: 0.875rem; letter-spacing: 0.1em; padding-left: 0.1em; }
.gallery__thumb-placeholder .photo-placeholder__note { display: none; }

/* Uppercase micro-labels. */
.product-detail__kind,
.product-sizes__label,
.cart-summary dt {
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}

/* ---------- Product dialog ----------
   One column on phones, gallery and details side by side from 900px. The close
   button spans every grid cell, so `position: sticky` keeps it in view. */

#product-dialog[open] { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; }

#product-dialog .dialog__close {
  position: sticky;
  top: var(--space-3);
  z-index: 2;
  grid-area: 1 / 1 / 3 / 2;
  align-self: start;
  justify-self: end;
  margin: var(--space-3) var(--space-3) 0 0;
}

.gallery {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--media-bg);
}

.product-detail {
  grid-area: 2 / 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--space-6) var(--space-5) var(--space-7);
}

@media (min-width: 900px) {
  #product-dialog[open] { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); grid-template-rows: auto; }
  #product-dialog .dialog__close { grid-area: 1 / 1 / 2 / 3; margin: var(--space-5) var(--space-5) 0 0; }
  .product-detail { grid-area: 1 / 2; justify-content: center; padding: var(--space-9) var(--space-8) var(--space-8); }

  /* The photo fills the viewport height, so the thumbnails stay in view. */
  .gallery__slide { aspect-ratio: auto; height: min(760px, calc(100dvh - 2 * var(--space-3) - 84px)); }
}

/* Gallery: a scroll-snap track (swipe on touch), arrows and thumbnails. */

.gallery__viewport { position: relative; }

.gallery__track {
  display: flex;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
}

.gallery__track::-webkit-scrollbar { display: none; }
.gallery__track:focus-visible { outline-offset: -4px; }

.gallery__slide {
  flex: 0 0 100%;
  aspect-ratio: 3 / 4;
  background: radial-gradient(70% 55% at 50% 42%, rgba(244, 241, 236, 0.07), transparent 75%), var(--media-bg);
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.gallery__prev,
.gallery__next { position: absolute; top: 50%; margin-top: -22px; }
.gallery__prev { left: var(--space-4); }
.gallery__next { right: var(--space-4); }

.gallery__thumbs {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
}

.gallery__thumb {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  aspect-ratio: 3 / 4;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: var(--bg-2);
  opacity: 0.45;
  transition: opacity var(--dur-base) var(--ease-out-soft);
}

/* The active thumbnail gets a hairline underneath, not a heavy frame. */
.gallery__thumb::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: var(--text);
  transform: scaleX(0);
  transition: transform var(--dur-base) var(--ease-out-soft);
}

.gallery__thumb:hover { opacity: 0.8; }
.gallery__thumb[aria-current='true'] { opacity: 1; }
.gallery__thumb[aria-current='true']::after { transform: scaleX(1); }

@media (min-width: 900px) {
  .gallery__thumb { width: 60px; }
}

/* Details: type, name, price, sizes, description, add button. */

.product-detail__name {
  margin-top: var(--space-3);
  color: var(--text);
  font-size: var(--fs-xl);
  font-weight: 400;
  line-height: 1.08;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.product-detail__price {
  margin-top: var(--space-4);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--fs-lg);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.product-sizes {
  min-inline-size: 0;
  margin: var(--space-6) 0 0;
  padding: 0;
  border: 0;
}

.product-sizes:focus-visible { outline-offset: 8px; }

/* The rendered legend is a full-width row: label left, error right. */
.product-sizes__legend {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: 20px;
  margin-bottom: var(--space-4);
  padding: 0;
}

.product-sizes__error { color: var(--danger); font-size: var(--fs-xs); font-weight: 500; }
.product-sizes__options { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* Sizes are square, tactile tiles: hairline at rest, solid off-white when chosen. */
.size-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 52px;
  padding: 0 var(--space-3);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: var(--fs-sm);
  letter-spacing: 0.1em;
  cursor: pointer;
}

/* The radio covers its tile: invisible, but it takes the click and the focus. */
.size-pill input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.size-pill:has(input:focus-visible) { outline: 1px solid var(--text); outline-offset: 3px; }

.product-sizes:has(.product-sizes__error:not(:empty)) .size-pill:not(:has(input:checked)) {
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
}

.product-sizes:disabled .size-pill { cursor: not-allowed; opacity: 0.4; }

.product-detail__description {
  margin-top: var(--space-6);
  color: var(--muted);
  font-size: var(--fs-base);
  line-height: 1.75;
}

.product-detail__add { min-height: 56px; margin-top: var(--space-7); }
