/* Panots: paving tiles that turn over to show what they mean, on hover
   with a mouse, on tap, or with Enter/Space (main.js). Both faces are always
   in the page, so screen readers read title and text. Shared by every
   version of the home page. */

.pave {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.panot {
  display: grid;
  container-type: inline-size; /* titles size to the tile, not the window */
  aspect-ratio: 1;
  perspective: 1200px;
  border-radius: 0.4rem;
  cursor: pointer;
}

.panot:has(:focus-visible) {
  outline: 3px solid var(--wine);
  outline-offset: 3px;
}

/* Faces share one grid cell, so the tile is always as tall as its longer side */
.panot-card {
  display: grid;
  transform-style: preserve-3d;
}

.panot-face {
  grid-area: 1 / 1;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: clamp(1.1rem, 2vw, 1.6rem);
  border-radius: 0.4rem;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.panot-face::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  -webkit-mask: url("../img/panot.svg") center / 100% 100% no-repeat;
  mask: url("../img/panot.svg") center / 100% 100% no-repeat;
  pointer-events: none;
}

.panot-front {
  justify-content: flex-end;
  background: var(--rosa-deep);
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.2rem, 1rem + 0.5vw, 1.45rem);
  /* The title size wherever the tile has room for it; only the narrow
     four-across tiles just above 64rem step down, so "autoconeixement"
     still fits on one line */
  font-size: clamp(1.2rem, 9cqi, var(--text-title));
  line-height: 1.2;
}

.panot-front::after {
  background: var(--groove);
}

.panot-front button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.panot-front button:focus-visible {
  outline: none;
}

/* A small turn arrow says the tile has another side */
/* A small drawn turn arrow says the tile has another side; same stroke
   as the path's drawings */
.panot-hint {
  position: absolute;
  top: clamp(1.1rem, 2vw, 1.6rem);
  right: clamp(1.1rem, 2vw, 1.6rem);
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.6;
}

/* The tile turned over: paper with a rose edge, garnatxa text. The edge
   keeps the tile visible on a calç section. */
.panot-back {
  justify-content: center;
  background: var(--paper);
  box-shadow: inset 0 0 0 1.5px var(--rosa-deep);
  font-size: var(--text-small);
  line-height: 1.5;
  transform: rotateY(180deg);
}

.panot-back::after {
  background: var(--groove-faint);
}

.panot.is-turned .panot-card {
  transform: rotateY(180deg);
}

@media (hover: hover) {
  .panot:hover .panot-card {
    transform: rotateY(180deg);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .panot-card {
    transition: transform 700ms cubic-bezier(0.3, 0.8, 0.3, 1);
  }
}

/* No turning for reduced motion: the back simply fades in over the front */
@media (prefers-reduced-motion: reduce) {
  .panot .panot-card,
  .panot.is-turned .panot-card,
  .panot:hover .panot-card {
    transform: none;
  }

  .panot-face {
    transition: opacity 200ms ease;
  }

  .panot-back {
    transform: none;
    opacity: 0;
  }

  .panot.is-turned .panot-back {
    opacity: 1;
  }

  @media (hover: hover) {
    .panot:hover .panot-back {
      opacity: 1;
    }
  }
}

@media (max-width: 64rem) {
  .pave {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 36rem) {
  .pave {
    grid-template-columns: 1fr;
  }

  .panot {
    aspect-ratio: auto;
    min-height: 9rem;
  }

  /* Wide tiles: a row of whole panots instead of one stretched across */
  .panot-face::after {
    -webkit-mask-size: auto 100%;
    mask-size: auto 100%;
    -webkit-mask-repeat: space no-repeat;
    mask-repeat: space no-repeat;
  }
}
