/* =========================
   Llanidloes — picture.css (drop-in replacement)
   Works with existing HTML:
   .image-container .image .picture-frame img.thumbnail (or any img)
   Optional .caption element supported. If missing, we use the link's title.
   ========================= */

/* ---- Layout: Grid when possible, Flex fallback ---- */
.image-container{
  max-width: 1200px;
  margin: 0 auto;
  /* Flex fallback */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.image{
  position: relative;
  box-sizing: border-box;
  overflow: hidden;
  /* Flex fallback sizing: three-up, then two-up, then full */
  flex: 1 1 320px;
  max-width: calc(33.333% - 10px);
  min-width: 220px;
  aspect-ratio: 4 / 3;               /* uniform tiles */
  border-radius: 12px;
}

/* Upgrade to CSS Grid if supported */
@supports (display: grid){
  .image-container{
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
    justify-items: stretch;
    align-items: stretch;
  }
  .image{
    max-width: none;
    flex: unset;
  }
}

/* ---- Picture frame & hover polish ---- */
.picture-frame{
  position: relative;
  width: 100%;
  height: 100%;
  background: #ffffff;
  border-radius: 12px;
  box-shadow:
    0 12px 30px rgba(0,0,0,.22),
    0 1px 0 rgba(0,0,0,.06) inset;
  overflow: hidden;
  transition: box-shadow .25s ease, transform .25s ease;
}

.picture-frame:hover{
  box-shadow:
    0 18px 42px rgba(0,0,0,.28),
    0 1px 0 rgba(0,0,0,.06) inset;
  transform: translateY(-2px);
}

/* ---- Images: cover tiles neatly without distortion ---- */
.picture-frame img,
.image img{
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;                  /* neat crop */
  object-position: center;
  cursor: pointer;
  transition: transform .35s ease, filter .35s ease;
  backface-visibility: hidden;
  -webkit-transform: translateZ(0);
}

.picture-frame:hover img{
  transform: scale(1.045);
  filter: saturate(1.05) contrast(1.02);
}

/* ---- Caption overlay (if .caption exists in your HTML) ---- */
.caption{
  position: absolute;
  inset: auto 0 0 0;                  /* bottom overlay */
  background: linear-gradient(to top, rgba(0,0,0,.58), rgba(0,0,0,0));
  color: #fff;
  text-align: left;
  padding: .55rem .7rem;
  box-sizing: border-box;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .25s ease, transform .25s ease;
  font: 600 14px/1.25 "Lato", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image:hover .caption,
.image a:focus .caption{
  opacity: 1;
  transform: translateY(0);
}

/* ---- Fallback caption if .caption is not present: use anchor title ---- */
.image a[title]::after{
  content: attr(title);
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: .55rem .7rem;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,.58), rgba(0,0,0,0));
  font: 600 14px/1.25 "Lato", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .25s ease, transform .25s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.image:hover a[title]::after,
.image a:focus::after{
  opacity: 1;
  transform: translateY(0);
}

/* ---- Modal (kept compatible, refined) ---- */
.modal{
  display: none;                       /* shown via JS */
  position: fixed;
  inset: 0;
  z-index: 9999;
  background-color: rgba(0,0,0,.92);
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
  padding: 4vw;
}

.modal-content{
  max-width: min(1200px, 90vw);
  max-height: 90vh;
  background: #111;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}

.modal img{
  display: block;
  width: 100%;
  height: auto;
}

/* Close button */
.close{
  position: absolute;
  top: 12px;
  right: 16px;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  font-weight: 700;
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
  user-select: none;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(0,0,0,.25);
}
.close:hover{
  background: rgba(255,255,255,.08);
}

/* ---- Responsive steps (fallback sizing when grid unsupported) ---- */
@media (max-width: 1200px){
  .image{ max-width: calc(50% - 10px); }
}
@media (max-width: 1000px){
  .image{ max-width: calc(50% - 10px); }
}
@media (max-width: 600px){
  .image{ max-width: 100%; min-width: 0; }
}

/* ---- Accessibility: reduce motion ---- */
@media (prefers-reduced-motion: reduce){
  .picture-frame,
  .picture-frame img,
  .caption,
  .image a[title]::after{
    transition: none !important;
  }
}
