body {
  background-color: #471c48;
  font-family: sans-serif;
  color: #f2f2f2;
  margin: 0;
}

/* =========================
   LINKS + NAV
   ========================= */

.topnav {overflow: hidden}
.topnav a {float: left;font-size: 17px;color: #f2f2f2; text-align: center; padding: 12px 16px; text-decoration: none}
.topnav a:hover, .dropdown:hover .dropbtn {background-color: white; color:black}
.topnav a.active {background-color: #504161; color: white}

.gallery-index h3 a,
.gallery-index p a {
  color: #f2f2f2;
  text-decoration: none;
}

.gallery-index h3 a:hover
{
  background-color: white;
  color: black;
}

/* =========================
   INDEX PAGE (gallery tiles)
   Detected by presence of .gallery-wrapper
   ========================= */

.gallery-wrapper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.gallery-index {
  text-align: center;
  max-width: 200px;  /* <-- maximum size for each thumbnail */
  margin: 0 auto;    /* center them if fewer items */
}

.gallery-index img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  max-width: 100%
}

.gallery-index h3 {
  margin: 0.3em 0 0.1em 0;
  font-size: 0.95em;
}

.gallery-index p {
  margin: 0;
  font-size: 0.85em;
  opacity: 0.9;
}

/* =========================
   SUBGALLERY PAGE (NOW GRID)
   ========================= */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.2em;
  padding: 0.5em;
  justify-items: center;
  grid-auto-flow: dense;
}

.gallery-image-wrapper {
  width: 100%;
}

.gallery-image {
  width: 100%;
  height: auto;
  display: block;
}

.gallery-image-wrapper:has(img.landscape) {
  grid-column: span 2;
}

.gallery-image-wrapper:has(img.square),
.gallery-image-wrapper:has(img.portrait) {
  grid-column: span 1;
}

h1 {
    padding-left: 16px;
}

/* =========================
   FULL IMAGE VIEW (auto-detected)
   Trigger: page has ONLY body > img (no wrapper)
   ========================= */

body > img {
  display: block;
  height: 90vh;
  max-height: 100%;
  margin-left: auto;
  margin-right: auto;
  margin-top: auto;
}

/* ensure image pages can scroll if needed */
body:not(:has(.gallery-wrapper)) {
  overflow: auto;
}

