/* Merlien Flickr Gallery – Frontend
   Modern, responsive, accessible-ish UI using CSS Grid, container queries,
   aspect-ratio, and CSS variables. */

:root {
  --fgg-radius: 14px;
  --fgg-shadow: 0 12px 30px rgba(0,0,0,.10);
  --fgg-shadow-soft: 0 8px 18px rgba(0,0,0,.08);
  --fgg-border: rgba(0,0,0,.10);
  --fgg-bg: rgba(255,255,255,.75);
  --fgg-fg: rgba(15, 23, 42, 1);
  --fgg-muted: rgba(15, 23, 42, .72);

  /* Defaults, overridden per gallery container via inline style vars */
  --fgg-cols-desktop: 4;
  --fgg-cols-tablet: 2;
  --fgg-cols-mobile: 1;
  --fgg-padding: 15px;
  --fgg-row-height: 300px;
  --fgg-box-color: rgba(255,255,255,.70);

  --fgg-gap: 14px;
  --fgg-tab-gap: 8px;
}

.fgg-gallery,
.fgg-album,
.fgg-collection {
  box-sizing: border-box;
}

.fgg-gallery *,
.fgg-album *,
.fgg-collection * {
  box-sizing: border-box;
}

.fgg-gallery {
  color: var(--fgg-fg);
  padding: var(--fgg-padding);
  border-radius: calc(var(--fgg-radius) + 6px);
  background: linear-gradient(180deg, rgba(255,255,255,.68), rgba(255,255,255,.52));
  border: 1px solid var(--fgg-border);
  box-shadow: var(--fgg-shadow-soft);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);

  /* Enable container queries */
  container-type: inline-size;
  container-name: fgg;
}

.fgg-album {
  margin: 0;
  padding: var(--fgg-padding);
  border-radius: calc(var(--fgg-radius) + 6px);
  background: linear-gradient(180deg, rgba(255,255,255,.68), rgba(255,255,255,.52));
  border: 1px solid var(--fgg-border);
  box-shadow: var(--fgg-shadow-soft);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  container-type: inline-size;
  container-name: fgg;
}

.fgg-mode-stack .fgg-album + .fgg-album {
  margin-top: 18px;
}

.fgg-collection-title,
.fgg-album-title {
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
  font-size: clamp(18px, 2.2cqi, 26px);
  margin: 0 0 10px 0;
}

.fgg-album-description {
  color: var(--fgg-muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 12px 0;
}

/* Tabs */
.fgg-tabs-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--fgg-tab-gap);
  margin: 0 0 14px 0;
}

.fgg-tab {
  appearance: none;
  border: 1px solid var(--fgg-border);
  background: rgba(255,255,255,.55);
  color: var(--fgg-fg);
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  user-select: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fgg-tab:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0,0,0,.08);
  background: rgba(255,255,255,.80);
}

.fgg-tab:focus-visible {
  outline: 3px solid rgba(59,130,246,.45);
  outline-offset: 2px;
}

.fgg-tab.fgg-is-active {
  background: rgba(15, 23, 42, .92);
  color: rgba(255,255,255,.96);
  border-color: rgba(15, 23, 42, .92);
  box-shadow: 0 10px 22px rgba(0,0,0,.16);
}

.fgg-tab-panel {
  display: none;
}

.fgg-tab-panel.fgg-is-active {
  display: block;
}

/* Grid */
.fgg-grid {
  display: grid;
  gap: var(--fgg-gap);

  /* fallback if container queries not supported */
  grid-template-columns: repeat(var(--fgg-cols-desktop), minmax(0, 1fr));
}

/* Container query driven columns (modern) */
@container fgg (max-width: 720px) {
  .fgg-grid {
    grid-template-columns: repeat(var(--fgg-cols-tablet), minmax(0, 1fr));
  }
}

@container fgg (max-width: 460px) {
  .fgg-grid {
    grid-template-columns: repeat(var(--fgg-cols-mobile), minmax(0, 1fr));
  }

  .fgg-tabs-nav {
    gap: 6px;
  }

  .fgg-tab {
    padding: 8px 10px;
    font-size: 13px;
  }
}

.fgg-item {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: var(--fgg-radius);
  overflow: hidden;
  border: 1px solid var(--fgg-border);
  background: var(--fgg-box-color);
  box-shadow: 0 10px 22px rgba(0,0,0,.10);
  transform: translateZ(0);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, filter .16s ease;
}

.fgg-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(0,0,0,.16);
  border-color: rgba(0,0,0,.16);
}

.fgg-item:focus-visible {
  outline: 3px solid rgba(59,130,246,.45);
  outline-offset: 2px;
}

.fgg-item-inner {
  display: grid;
  grid-template-rows: 1fr auto;
  position: relative;
}

/* Consistent tile shape */
.fgg-img {
  width: 100%;
  height: auto;
  display: block;

  /* keep a consistent mosaic feel */
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: rgba(0,0,0,.04);
}

@supports (height: 100cqh) {
  /* Optional: if you want row height to influence tile height in the future */
}

/* Caption overlay */
.fgg-caption {
  display: block;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.3;
  color: rgba(255,255,255,.92);
  background: linear-gradient(180deg, rgba(15,23,42,0) 0%, rgba(15,23,42,.80) 70%);
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  transform: translateY(2px);
  transition: transform .16s ease;
  text-shadow: 0 1px 2px rgba(0,0,0,.30);
  pointer-events: none;

  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.fgg-item:hover .fgg-caption {
  transform: translateY(0);
}

/* Album badge (used in merge mode) */
.fgg-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1;
  border-radius: 999px;
  color: rgba(255,255,255,.92);
  background: rgba(15, 23, 42, .82);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 10px 22px rgba(0,0,0,.16);
}

/* Notices */
.fgg-notice {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--fgg-border);
  background: rgba(255,255,255,.62);
  color: var(--fgg-muted);
  font-size: 14px;
  line-height: 1.4;
}

.fgg-notice-error {
  border-color: rgba(239,68,68,.35);
  background: rgba(239,68,68,.08);
  color: rgba(127,29,29,1);
}

/* Lightbox (JS toggles .fgg-lb-open on body) */
.fgg-lb {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 2.5vw, 28px);
  background: rgba(2, 6, 23, .78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

body.fgg-lb-open .fgg-lb {
  display: flex;
}

.fgg-lb-dialog {
  width: min(1100px, 100%);
  max-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
}

.fgg-lb-top {
  display: flex;
  justify-content: flex-end;
}

.fgg-lb-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.92);
  border-radius: 999px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}

.fgg-lb-btn:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,.18);
}

.fgg-lb-btn:focus-visible {
  outline: 3px solid rgba(59,130,246,.55);
  outline-offset: 2px;
}

.fgg-lb-stage {
  border-radius: calc(var(--fgg-radius) + 6px);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(0,0,0,.25);
  box-shadow: 0 24px 50px rgba(0,0,0,.28);
  display: grid;
  place-items: center;
}

.fgg-lb-img {
  max-width: 100%;
  max-height: calc(100vh - 180px);
  width: auto;
  height: auto;
  display: block;
}

.fgg-lb-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.fgg-lb-nav {
  display: flex;
  gap: 10px;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .fgg-item,
  .fgg-tab,
  .fgg-caption,
  .fgg-lb-btn {
    transition: none !important;
  }
}
