
  .card-grid-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow-y: auto;
    background: white;
    z-index: 1000;
    padding: 1rem;
  }
  
  .card-grid-overlay.active {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    justify-content: center;
  }

  .card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgb(0 0 0 / 0.1);
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    aspect-ratio: 3 / 4;
    position: relative;
  }

  .card img, .card video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: none;
    border-radius: 12px;
  }


.page-layout {
  background-color: rgba(255, 255, 255, 0.6) !important;
  position: relative;
  display: flex;
  flex-direction: row;
  min-height: 100vh;
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem;
  gap: 2rem;
  border-left: 1px solid #eee;
  border-right: 1px solid #eee;
  box-shadow: 0 0 10px rgba(0,0,0,0.05);
}

  /* Keep card-layout visually distinct */
  #card-layout {
    background: white;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    position: relative;
    z-index: 2;
  }

  @media (max-width: 768px) {
    .page-layout {
      flex-direction: column;
      padding: 1rem;
    }
  }

  .card-panel {
    flex-shrink: 0;
    order: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    width: auto;
    padding: 0;
    margin: 0;
  }

  .media-container {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    z-index: 3;
    display: flex;
    flex-direction: row;
    gap: 1rem;
    align-items: flex-start;
    justify-content: center;
    width: auto;
    max-width: 420px;
    aspect-ratio: 3 / 4;
    margin: 0;
    padding: 0;
  }
  #card-layout.side-by-side .media-container {
    aspect-ratio: auto;
    max-width: none;
    margin-top: 0 !important;
    padding-top: 0 !important;
  }

  #card-layout.side-by-side .card-panel {
    align-items: flex-start;
    justify-content: flex-start;
    margin-top: 0 !important;
    padding-top: 0 !important;
  }

  .media-flip-inner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.8s;
    transform-style: preserve-3d;
    z-index: 3;
  }

  .media-flip-inner.flipped {
    transform: rotateY(180deg);
  }

  .media-front, .media-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    transition: opacity 0.4s ease, z-index 0s linear 0.4s;
    border-radius: 12px;
    overflow: hidden;
  }

  .media-back {
    transform: rotateY(180deg);
  }

  .card-media {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    position: relative;
    z-index: 1;
  }

  .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    z-index: 2;
  }

  .gallery-icon {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 4;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ccc;
    border-radius: 50%;
    padding: 4px;
    cursor: pointer;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.4;
    transition: opacity 0.3s ease;
    animation: gallery-flash 2s ease-in-out 1;
  }

  .gallery-icon:hover {
    opacity: 1.0;
  }

  @keyframes gallery-flash {
    0%, 100% { opacity: 0.4; box-shadow: none; }
    50% { opacity: 1; box-shadow: 0 0 8px 4px rgba(255, 255, 255, 0.8); }
  }

  .gallery-icon img {
    width: 40px;  /* doubled from 20px */
    height: 40px; /* doubled from 20px */
  }

  .content-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    order: 3;
  }

  .tile {
    margin-bottom: 1rem;
    background: #f5f5f5;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    transition: box-shadow 0.15s;
    cursor: pointer;
    border: 1px solid #eee;
  }
  .tile:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    background: #e9f5ff;
  }

#cards-grid {
  display: none;
  padding: 2rem;
  background-color: #fafafa;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  max-height: 100vh;
  bottom: 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  z-index: 1000;
  box-sizing: border-box;
}

#cards-grid.active {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 5rem 2rem 8rem; /* increased bottom padding from 5rem to 8rem */
  box-sizing: border-box;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

#cards-grid .card {
  width: 200px;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  background-color: #fff;
  cursor: pointer;
}

#cards-grid .card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#cards-grid .back-button {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: white;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-weight: bold;
  cursor: pointer;
  z-index: 1001;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

#grid-back-button {
  background-color: #007acc;       /* same blue background */
  color: white;                    /* white text */
  border: none;                    /* no border or subtle */
  border-radius: 6px;              /* slightly rounded corners */
  padding: 0.5rem 1.5rem;          /* similar padding */
  font-weight: bold;               /* bold text */
  font-size: 1rem;                 /* font size */
  cursor: pointer;
  position: fixed;                 /* keep position */
  top: 1rem;
  left: 1rem;
  z-index: 1001;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);  /* subtle shadow */
  transition: background-color 0.3s ease;
}

#grid-back-button:hover {
  background-color: #005fa3;       /* slightly darker blue on hover */
}

#cards-grid.active ~ #grid-back-button {
  display: block;
}
  .media-front {
    z-index: 2;
    opacity: 1;
  }

  .media-back {
    z-index: 1;
    opacity: 0;
  }

  .media-flip-inner.flipped .media-front {
    opacity: 0;
    z-index: 1;
    transition-delay: 0s;
  }

  .media-flip-inner.flipped .media-back {
    opacity: 1;
    z-index: 2;
    transition-delay: 0s;
  }
  .flip-help {
    position: absolute;
    bottom: 8px;
    right: 8px;
    transform: none;
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 1rem;
    color: white;
    text-align: right;
    z-index: 5;
  }

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  15% { transform: rotate(10deg); }
  30% { transform: rotate(-10deg); }
  45% { transform: rotate(8deg); }
  60% { transform: rotate(-8deg); }
  75% { transform: rotate(4deg); }
  90% { transform: rotate(-4deg); }
}

.flip-help {
  animation: wiggle 1.5s ease-in-out 1;
  }

/* Temporary fully opaque test to verify style application */
.page-layout.test-opaque {
  background-color: rgba(255, 255, 255, 1) !important;
}
/* Spacer div for scroll padding at bottom of cards grid */
.scroll-spacer {
  height: 15rem;
  width: 100%;
  pointer-events: none;
}

.media-static {
  width: 420px;
  height: 560px; /* assuming 3:4 aspect ratio */
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
/* Limit width of card-layout when showing side by side */
#card-layout.side-by-side {
  max-width: fit-content;
}