/* Global reset & box sizing */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Protocol-inspired theming */
:root {
  /* NASA+ themed palette (simpler + higher contrast) */
  --nasa-blue: #0B3D91;      /* primary brand blue */
  --nasa-blue-alt: #0d4fbf;  /* hover/active tint */
  --nasa-red: #FC3D21;       /* brand red accent */
  --space-bg: #05070A;       /* deep near-black */
  --panel: #0D1117;          /* surface panels */
  --panel-alt: #121821;      /* subtle hover */
  --text: #F5F7FA;
  --muted: #8896A8;
  --border: #1f2730;
  --focus: rgba(11,61,145,0.55);
  --shadow-soft: 0 4px 12px rgba(0,0,0,0.5);
  --plus-accent: #dd3328; /* specific '+' color */
}

/* Base page styles */
body {
  font-family: 'Public Sans', Arial, Helvetica, sans-serif;
  background: var(--space-bg);
  color: var(--text);
  padding: 20px;
  line-height: 1.5;
  position: relative;                /* host ::before mesh */
}

/* Remove background mesh so black reads solid */
body::before {
  content: "";
  position: fixed;
  inset: -10%;
  pointer-events: none;
  z-index: 0;
  background: none;
  -webkit-mask-image: none;
  mask-image: none;
}

/* Centered container */
.container {
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  margin-bottom: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: none;
  backdrop-filter: none;
  position: relative;
  z-index: 1; /* lift above mesh */
}
.site-header h1 {
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--text);
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
  background: none; /* ensure override without gradients */
}

/* Logo */
.logo {
  width: 140px;
  margin-right: 15px;
  filter: drop-shadow(0 4px 10px var(--shadow));
}

/* Plus accent */
.plus-accent {
  color: var(--plus-accent); /* use dedicated accent */
  margin: 0 6px 0 2px;
  font-weight: 800;
}

/* Random Fact */
.fact-section {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: none;
  backdrop-filter: none;
  padding: 16px 20px;
  margin-bottom: 16px;
  border-radius: 12px;
}
.fact-title {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--muted);
}
.fact-text { color: var(--text); }

/* Date‐picker & button row */
.filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
  padding: 0 20px;
}

/* Inputs and buttons */
input[type="date"],
button {
  font-family: inherit;
  font-weight: 600;
  color: var(--text);
  padding: 12px 18px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  font-size: 16px;
  line-height: 1.4;
  width: 100%;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.0)),
    var(--card-bg);
  border: 1px solid rgba(148,163,184,0.18);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset;
}

/* Button specific */
button {
  background: var(--nasa-blue);
  border: 1px solid var(--nasa-blue);
  box-shadow: none;
  transition: background .18s ease, transform .18s ease;
  color: #fff;
  cursor: pointer;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1.4;
  width: 100%;
}
button:hover {
  background: var(--nasa-blue-alt);
  transform: translateY(-2px);
}
button:active { transform: translateY(0); }
button:focus-visible {
  box-shadow: 0 0 0 3px var(--focus);
  outline: none;
}

/* Focus states for gallery items */
.gallery-item:focus-visible {
  outline: 2px solid var(--nasa-blue);
  outline-offset: 2px;
}

/* Stack horizontally on wider screens */
@media (min-width: 600px) {
  .filters {
    flex-direction: row;
    padding: 0;
  }
  
  input[type="date"],
  button {
    width: auto;
  }
}

/* Gallery grid container */
.gallery {
  /* grid: force 3 columns on larger screens */
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  padding: 24px;
  justify-items: stretch;
}

/* Override previous flex-based item sizing */
.gallery-item {
  flex: none;          /* disable flex growth */
  width: 100%;         /* fill grid cell */
}

/* Responsive fallbacks: 2 columns then 1 */
@media (max-width: 900px) {
  .gallery {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 560px) {
  .gallery {
    grid-template-columns: 1fr;
  }
}

/* Gallery items */
.gallery-item {
  flex: 1 1 100%;  /* full width by default */
  min-width: 280px;
  max-width: 500px;
  background: var(--panel);
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: none;
  transition: background .18s ease, border-color .18s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* Defer rendering when offscreen to speed up initial load */
  content-visibility: auto;
  contain-intrinsic-size: 320px 260px; /* reserve space to avoid jumps */
}
.gallery-item:hover {
  background: var(--panel-alt);
  border-color: var(--nasa-blue);
}

.gallery-item img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 10px;
  filter: brightness(0.95) saturate(1.05);
  transition: transform .22s ease;
}
.gallery-item:hover img { transform: scale(1.03); }

/* Mobile: let images size naturally so they don't disappear */
@media (max-width: 480px) {
  .gallery-item img {
    height: auto;
    max-height: 160px;
  }
}

/* Skeleton placeholder while loading */
.skeleton {
  background: linear-gradient(90deg,#18222c 0%,#243240 50%,#18222c 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 10px;
  width: 100%;
  height: 180px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Hover Zoom Effect */
.gallery-item:hover img {
  transform: scale(1.04);
  filter: brightness(1.05);
}

.gallery-item p {
  margin-top: 10px;
  padding: 5px;
  font-size: 14px;
}

/* Placeholder content */
.placeholder {
  flex: 1 1 100%;
  text-align: center;
  padding: 40px;
  color: var(--muted);
  display: grid;         /* center children both ways */
  place-items: center;   /* shorthand for align-items + justify-items */
  min-height: 40vh;      /* enough height to center visually */
}

/* Make placeholder span all columns and center its content */
.gallery > .placeholder {
  grid-column: 1 / -1;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 20px;
}

/* Loading */
.loading {
  text-align: center;
  margin: 10px 20px 0;
  padding: 12px 16px;
  background: rgba(11,61,145,0.25);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none; /* toggled via JS */
  z-index: 1000; /* ensure modal is above header/logo */
}
.modal[aria-hidden="false"] { display: block; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75); /* darker for readability */
  backdrop-filter: none;
  z-index: 0; /* behind modal content, above page */
}

.modal-content {
  position: relative;
  z-index: 1; /* above backdrop */
  max-width: 504px;        /* smaller modal */
  margin: 24px auto;       /* tighter top/bottom spacing */
  background: var(--panel);
  color: var(--text);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.0)),
    var(--card-bg);
  touch-action: pan-y; /* allow vertical pan, we handle horizontal swipes in JS */
}

.modal-image {
  width: 100%;
  max-height: 49vh;
  object-fit: contain;
  display: block;
  background: #000;
  touch-action: pan-y; /* keep vertical drag for tall images */
}

.modal-meta { padding: 16px 20px 22px; }
.modal-title { font-weight: 700; margin-bottom: 4px; }
.modal-date { color: var(--muted); margin-bottom: 10px; }
.modal-desc { color: #e8edf6; }

.modal-close {
  position: absolute;
  top: 12px;               /* align with modal edge */
  right: 12px;             /* align with modal edge */
  display: inline-flex;     /* center with flexbox */
  align-items: center;      /* vertical centering */
  justify-content: center;  /* horizontal centering */
  padding: 0;               /* remove default padding */
  line-height: 0;           /* remove baseline offset */
  background: var(--nasa-red);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;         /* balanced size inside 36px circle */
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
}
.modal-close:hover { filter: brightness(1.15); }

/* Footer */
.site-footer {
  margin: 28px auto 0;
  padding: 28px 24px 36px;
  max-width: 1200px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: center;
}

.footer-brand {
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 14px;
  letter-spacing: .5px;
  color: var(--text);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-bottom: 12px;
}

.footer-links a {
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
  transition: color .18s ease, background .18s ease;
}

.footer-links a:hover,
.footer-links a:focus {
  color: var(--text);
  background: var(--panel-alt);
  outline: none;
}

.footer-copy {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
