/* ============================================================
   Family Photo Share — warm, friendly, easy-to-read design
   ============================================================ */

:root {
  --sand: #fdf7ee;
  --sand-deep: #f7ecdb;
  --ocean: #1d5d84;
  --ocean-deep: #14435f;
  --coral: #f0745f;
  --coral-deep: #d95a45;
  --seafoam: #e3f2ef;
  --ink: #2b2b2b;
  --ink-soft: #5b5b5b;
  --white: #ffffff;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(29, 93, 132, 0.12);
  --shadow-lift: 0 12px 32px rgba(29, 93, 132, 0.22);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 18px; }

body {
  font-family: "Avenir Next", "Segoe UI", -apple-system, BlinkMacSystemFont,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--sand);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: min(1200px, 92%);
  margin: 0 auto;
}

main.wrap { flex: 1; padding-bottom: 3rem; }

/* ---------- Header ---------- */

.site-header {
  background: linear-gradient(135deg, var(--ocean) 0%, var(--ocean-deep) 100%);
  color: var(--white);
  padding: 2.2rem 0 2rem;
  border-bottom: 6px solid var(--coral);
}

.brand {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.brand-icon {
  font-size: 3.2rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  width: 5rem;
  height: 5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.site-header h1 {
  font-size: 2.4rem;
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.tagline {
  font-size: 1.05rem;
  opacity: 0.92;
  margin-top: 0.25rem;
}

.back-link {
  display: inline-block;
  color: var(--white);
  background: rgba(255, 255, 255, 0.16);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  margin-bottom: 1.2rem;
  transition: background 0.15s;
}
.back-link:hover, .back-link:focus { background: rgba(255, 255, 255, 0.3); }

/* Compact (scrolled) album header: slimmer padding, smaller brand/title so the
   photo grid moves up into view sooner. Only on album pages (.album-header). */
.album-header {
  transition: padding 0.2s ease;
}
.album-header.compact { padding: 0.7rem 0 0.6rem; }
.album-header.compact .back-link { margin-bottom: 0.4rem; font-size: 0.9rem; padding: 0.35rem 0.9rem; }
.album-header.compact .brand { gap: 0.7rem; }
.album-header.compact .brand-icon { width: 2.6rem; height: 2.6rem; font-size: 1.6rem; }
.album-header.compact .site-header h1,
.album-header.compact h1 { font-size: 1.4rem; }
.album-header.compact .tagline { font-size: 0.85rem; margin-top: 0; }

/* ---------- Helper bar ---------- */

.helper-bar {
  background: var(--seafoam);
  border-bottom: 2px solid #cfe6e0;
  padding: 0.9rem 0;
  font-size: 1.05rem;
  color: var(--ocean-deep);
}
.helper-bar[hidden] { display: none; }
.helper-bar-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.helper-bar-inner p { flex: 1; min-width: 220px; }
.helper-bar-actions { display: flex; align-items: center; gap: 0.5rem; }
.helper-bar .btn-primary { font-size: 1rem; padding: 0.6rem 1.2rem; }
.helper-dismiss {
  color: var(--ocean-deep);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.3rem 0.6rem;
  opacity: 0.6;
}
.helper-dismiss:hover, .helper-dismiss:focus { opacity: 1; }

/* ---------- Home: albums ---------- */

.albums-section { padding-top: 2.5rem; }

.section-title {
  font-size: 1.9rem;
  color: var(--ocean-deep);
  margin-bottom: 0.35rem;
}

.section-help {
  color: var(--ink-soft);
  font-size: 1.1rem;
  margin-bottom: 1.6rem;
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 2rem;
}

.album-card {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  border: 1px solid #eee3d2;
}
.album-card:hover, .album-card:focus {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lift);
}

.album-cover {
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--sand-deep);
}
.album-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.album-info { padding: 1.3rem 1.4rem 1.5rem; }
.album-info h3 { font-size: 1.55rem; color: var(--ocean-deep); }
.album-meta { color: var(--ink-soft); margin-top: 0.15rem; }
.album-count { margin-top: 0.5rem; font-weight: 600; color: var(--coral-deep); }

.album-open-btn {
  display: inline-block;
  margin-top: 1rem;
  background: var(--ocean);
  color: var(--white);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.7rem 1.5rem;
  border-radius: 999px;
}
.album-card:hover .album-open-btn { background: var(--coral); }

/* ---------- Album: photo grid ---------- */

.photo-grid {
  /* Horizontal flow: photos fill left-to-right, then wrap to the next row —
     so timestamp order reads across and down. All photos share a 3:2 aspect
     ratio, so a uniform grid needs no cropping and leaves no gaps. */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  padding-top: 1.8rem;
}

.photo-tile {
  display: block;
  width: 100%;
  /* aspect-ratio set inline per-photo from the manifest (w/h); falls back to
     3/2 when missing. Since every photo is 3:2, tiles line up perfectly. */
  aspect-ratio: 3 / 2;
  border: none;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: var(--sand-deep);
  box-shadow: 0 3px 10px rgba(29, 93, 132, 0.10);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.photo-tile:hover, .photo-tile:focus {
  transform: scale(1.02);
  box-shadow: var(--shadow-lift);
  outline: 3px solid var(--coral);
  outline-offset: 2px;
}
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Blur-up fade-in: thumbnails fade from transparent to opaque once loaded. */
.tile-img { opacity: 0; transition: opacity 0.4s ease; }
.tile-img-in { opacity: 1; }

.loading-msg {
  text-align: center;
  font-size: 1.2rem;
  color: var(--ink-soft);
  padding: 3rem 0;
}

/* ---------- Footer ---------- */

.site-footer {
  background: var(--sand-deep);
  text-align: center;
  padding: 1.4rem 0;
  color: var(--ink-soft);
  font-size: 1rem;
  border-top: 1px solid #eadfca;
}

/* ---------- Buttons ---------- */

.btn {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 0.8rem 1.7rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--ocean); color: var(--white); }
.btn-primary:hover, .btn-primary:focus { background: var(--coral); }

.btn-secondary { background: var(--seafoam); color: var(--ocean-deep); border: 2px solid var(--ocean); }
.btn-secondary:hover, .btn-secondary:focus { background: #d1e9e3; }

.btn-plain {
  background: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
  font-weight: 600;
}

.btn-big {
  font-size: 1.2rem;
  padding: 1rem 2rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  min-height: 56px;
  justify-content: center;
}
.btn-title { font-size: 1.2rem; }
.btn-sub { font-size: 0.9rem; font-weight: 500; opacity: 0.85; }

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(12, 30, 42, 0.94);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }

.lb-figure {
  max-width: min(86vw, 1400px);
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 0;
}

#lbImage {
  max-width: 100%;
  max-height: calc(100vh - 140px);
  border-radius: 10px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
  background: #223;
  cursor: zoom-in;
  transition: transform 0.2s ease;
}

/* Zoom wrapper: scales the image up and lets the lightbox scroll/pan. On
   touch devices the browser handles pinch-zoom natively (touch-action). */
.lb-zoom-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: min(86vw, 1400px);
  max-height: calc(100vh - 140px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* Allow native pinch-zoom on the photo (don't let our swipe handler steal it). */
  touch-action: pinch-zoom;
}
.lb-zoom-wrap.zoomed #lbImage {
  max-width: none;
  max-height: none;
  transform: scale(2.2);
  transform-origin: center center;
  cursor: zoom-out;
}

.lb-date {
  color: #bcd4e2;
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0.85;
}
.lb-date[hidden] { display: none !important; }

.lb-change-size {
  color: #cfe2ee !important;
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  text-decoration: underline;
}
.lb-change-size[hidden] { display: none !important; }
.lb-change-size:hover, .lb-change-size:focus { color: #fff !important; }

.lb-caption {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.lb-counter {
  color: #dceaf3;
  font-size: 1.1rem;
  font-weight: 600;
}

.lb-close {
  position: absolute;
  top: 1.1rem;
  right: 1.2rem;
  background: rgba(255, 255, 255, 0.14);
  color: var(--white);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  z-index: 102;
}
.lb-close:hover, .lb-close:focus { background: rgba(255, 255, 255, 0.32); }

.lb-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.14);
  color: var(--white);
  border: 2px solid rgba(255, 255, 255, 0.4);
  font-size: 2.6rem;
  line-height: 1;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 102;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 6px;
}
.lb-arrow:hover, .lb-arrow:focus { background: rgba(255, 255, 255, 0.32); }
.lb-prev { left: 1.2rem; }
.lb-next { right: 1.2rem; }

/* ---------- Modals ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 30, 42, 0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2.2rem 2.4rem;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lift);
  border-top: 8px solid var(--coral);
  text-align: center;
}

.modal-card h2 {
  color: var(--ocean-deep);
  font-size: 1.6rem;
  margin-bottom: 0.6rem;
}

.modal-help {
  color: var(--ink-soft);
  font-size: 1.05rem;
  margin-bottom: 1.4rem;
}

.size-options {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-bottom: 1.1rem;
}
.size-options .btn { width: 100%; }

.pw-input {
  width: 100%;
  font-size: 1.35rem;
  padding: 0.85rem 1rem;
  border: 3px solid var(--ocean);
  border-radius: 12px;
  text-align: center;
  letter-spacing: 0.06em;
  margin-bottom: 0.7rem;
}
.pw-input:focus { outline: 3px solid var(--coral); outline-offset: 1px; }

.pw-show-label {
  display: block;
  font-size: 1rem;
  color: var(--ink-soft);
  margin-bottom: 0.8rem;
  cursor: pointer;
}
.pw-show-label input { width: 1.1rem; height: 1.1rem; margin-right: 0.35rem; }

.pw-error {
  background: #fdecea;
  color: #b3352a;
  font-weight: 600;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
}
.modal-actions .btn-primary { width: 100%; }

/* ---------- Admin mode ---------- */

.admin-link {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  color: #b9ad97;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}
.admin-link:hover, .admin-link:focus { color: var(--ocean); }

.admin-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #3b2f2f;
  color: var(--white);
  padding: 0.7rem 0;
  border-bottom: 4px solid var(--coral);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.admin-bar[hidden] { display: none; }

.admin-bar-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.admin-label { font-weight: 700; }
.admin-count { opacity: 0.9; font-weight: 600; }
.admin-actions {
  margin-left: auto;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}
.admin-actions .btn { font-size: 0.95rem; padding: 0.55rem 1.1rem; }
.admin-bar .btn-plain { color: #d8cdc4; }

.btn-danger { background: #c0392b; color: var(--white); }
.btn-danger:hover:not(:disabled), .btn-danger:focus:not(:disabled) { background: #a02c20; }
.btn-danger:disabled { opacity: 0.45; cursor: not-allowed; }

.admin-active .photo-tile { position: relative; }
.admin-active .photo-tile::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--white);
  background: rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.admin-active .photo-tile.selected::after {
  content: "✓";
  color: var(--white);
  font-weight: 900;
  font-size: 17px;
  line-height: 26px;
  text-align: center;
  background: #c0392b;
  border-color: var(--white);
}
.admin-active .photo-tile.selected {
  outline: 4px solid #c0392b;
  outline-offset: 2px;
  opacity: 0.85;
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  html { font-size: 17px; }
  .site-header h1 { font-size: 1.8rem; }
  .brand-icon { width: 3.6rem; height: 3.6rem; font-size: 2.2rem; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .photo-tile { border-radius: 10px; }
  /* Lightbox arrows sit just outside the image on phones so they don't occlude it. */
  .lb-arrow { width: 48px; height: 48px; font-size: 1.9rem; }
  .lb-prev { left: 0.5rem; }
  .lb-next { right: 0.5rem; }
  #lbImage { max-height: calc(100vh - 190px); }
  .modal-card { padding: 1.6rem 1.4rem; }
}
