:root {
  --bg: #faf8f4;
  --bg-warm: #f3ede4;
  --surface: #ffffff;
  --primary: #7c6a56;
  --primary-dark: #5c4d3c;
  --accent: #c4a265;
  --accent-light: rgba(196, 162, 101, 0.1);
  --text: #3a3028;
  --text-secondary: #8a7e72;
  --text-light: #b0a89e;
  --border: #e5ddd3;
  --shadow: 0 2px 12px rgba(58, 48, 40, 0.08);
  --shadow-lg: 0 8px 30px rgba(58, 48, 40, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s ease;
  --font-serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ============================================
   Header
   ============================================ */
header {
  background: linear-gradient(160deg, #f5efe7 0%, #ebe3d7 50%, #f0e8dc 100%);
  padding: 3rem 1.5rem 2.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.header-content {
  max-width: 600px;
  margin: 0 auto;
}

header h1 {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 0.35rem;
  line-height: 1.1;
}

/* Honoree name sits directly under the "Celebration of Life" title
   when HONOREE_NAME is set. The em dashes on either side are added
   by CSS pseudo-elements so the middleware only needs to inject the
   raw name text. When the element is empty it collapses entirely. */
.honoree-name {
  display: none;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
  margin: 0 0 0.75rem;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.honoree-name:not(:empty) {
  display: block;
}

.honoree-name:not(:empty)::before {
  content: "\2014\00a0";
}

.honoree-name:not(:empty)::after {
  content: "\00a0\2014";
}

.honoree-dates {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  letter-spacing: 0.02em;
}

header .subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-weight: 300;
  margin-bottom: 1.5rem;
}

.qr-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.qr-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.qr-btn svg {
  flex-shrink: 0;
}

/* ============================================
   Share card (Photo / Memory tabs)
   ============================================ */
.share-section {
  padding: 2rem 0 1.5rem;
}

.share-tabs {
  display: flex;
  gap: 4px;
  max-width: 360px;
  margin: 0 auto 1.5rem;
  padding: 4px;
  background: var(--bg-warm);
  border-radius: 999px;
  border: 1px solid var(--border);
}

.share-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 999px;
  transition: background-color var(--transition), color var(--transition),
    box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.share-tab svg {
  flex-shrink: 0;
}

.share-tab:hover:not(.active) {
  color: var(--text);
}

.share-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(58, 48, 40, 0.08);
}

.share-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.share-pane {
  display: none;
}

.share-pane.active {
  display: block;
}

/* ============================================
   Upload Section (legacy wrapper — kept empty
   so any old cached HTML that still references
   the class does not collapse its children)
   ============================================ */
.upload-section {
  padding: 0;
}

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
  outline: none;
}

.upload-area:hover,
.upload-area:focus-visible {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-area.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: scale(1.01);
}

.upload-icon {
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.upload-area h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text);
}

.upload-area p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Upload Preview */
.upload-preview {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  justify-content: center;
}

.preview-item {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Upload Button */
.upload-btn {
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 1.25rem auto 0;
  padding: 0.85rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.upload-btn:hover {
  background: #b89455;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.upload-btn:active {
  transform: translateY(0);
}

/* Upload Progress */
.upload-status {
  max-width: 400px;
  margin: 1.25rem auto 0;
  text-align: center;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.4s ease;
}

.upload-status p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ============================================
   Gallery Section
   ============================================ */
.gallery-section {
  padding: 1.5rem 0 4rem;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 500;
  text-align: center;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.gallery-divider {
  width: 40px;
  height: 2px;
  background: var(--accent);
  margin: 0 auto 2rem;
  border-radius: 1px;
}

/* Masonry Gallery */
.gallery {
  column-count: 3;
  column-gap: 12px;
}

.gallery-item {
  break-inside: avoid;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  min-height: 120px;
  background: var(--bg-warm);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.gallery-item::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, var(--bg-warm) 8%, #f7f2ea 18%, var(--bg-warm) 33%);
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
  z-index: 1;
}

.gallery-item.loaded {
  opacity: 1;
  transform: translateY(0);
  min-height: auto;
  background: transparent;
}

.gallery-item.loaded::before {
  display: none;
}

@keyframes shimmer {
  to {
    background-position-x: -200%;
  }
}

.gallery-item img {
  width: 100%;
  display: block;
  cursor: pointer;
  transition: transform var(--transition);
  position: relative;
  z-index: 2;
}

.gallery-item:hover img {
  transform: scale(1.03);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
  display: none;
}

.empty-state.visible {
  display: block;
}

.empty-state p {
  font-size: 1rem;
  line-height: 1.8;
}

/* Loading Indicator */
.loading-indicator {
  text-align: center;
  padding: 2rem;
  display: none;
}

.loading-indicator.visible {
  display: block;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   Lightbox
   ============================================ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  cursor: pointer;
}

.lightbox.active {
  display: flex;
}

.lightbox img {
  max-width: 100%;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background var(--transition);
  z-index: 1001;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Share pill in the lower-left of the lightbox */
.lightbox-share {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  max-width: calc(100% - 2rem);
  padding: 0.65rem 0.9rem 0.75rem;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  color: #fff;
  font-family: var(--font-sans);
  cursor: default;
  z-index: 1002;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s ease 0.15s, transform 0.3s ease 0.15s;
  pointer-events: none;
}

.lightbox.active .lightbox-share,
.lightbox[style*="flex"] .lightbox-share {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.lightbox-share-label {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  font-weight: 400;
  font-style: italic;
  color: rgba(255, 255, 255, 0.82);
  margin-bottom: 0.5rem;
  letter-spacing: 0.02em;
}

.lightbox-share-buttons {
  display: flex;
  gap: 0.4rem;
}

.share-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.share-btn svg {
  width: 17px;
  height: 17px;
  display: block;
}

.share-btn:hover,
.share-btn:focus-visible {
  background: rgba(255, 255, 255, 0.24);
  outline: none;
}

.share-btn:active {
  transform: scale(0.94);
}

@media (max-width: 480px) {
  .lightbox-share {
    left: 0.75rem;
    bottom: 0.75rem;
    padding: 0.55rem 0.75rem 0.65rem;
    border-radius: 12px;
  }

  .lightbox-share-label {
    font-size: 0.78rem;
    margin-bottom: 0.4rem;
  }

  .share-btn {
    width: 34px;
    height: 34px;
  }

  .share-btn svg {
    width: 15px;
    height: 15px;
  }
}

/* ============================================
   QR / Share Modal
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  max-width: 380px;
  width: 100%;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background var(--transition);
}

.modal-close:hover {
  background: var(--bg-warm);
}

.modal-content h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.modal-content > p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.modal-content canvas,
.qr-canvas {
  margin: 0 auto 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  min-height: 240px;
}

.qr-canvas img,
.qr-canvas canvas {
  display: block;
  border-radius: var(--radius-sm);
}

.url-display {
  display: flex;
  gap: 0.5rem;
}

.url-display input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg);
  font-family: var(--font-sans);
  min-width: 0;
}

.url-display button {
  padding: 0.6rem 1rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
  font-family: var(--font-sans);
  white-space: nowrap;
}

.url-display button:hover {
  background: var(--primary-dark);
}

/* ============================================
   Toast Notification
   ============================================ */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 2000;
  transition: transform 0.35s ease;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   Footer
   ============================================ */
footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-light);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: color var(--transition), border-color var(--transition);
}

footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ============================================
   Memory form (written tributes, inside the share card)
   ============================================ */
.memory-section {
  padding: 0;
}

.memory-form {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.memory-input,
.memory-textarea {
  width: 100%;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.memory-input::placeholder,
.memory-textarea::placeholder {
  color: var(--text-light);
}

.memory-input:focus,
.memory-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.memory-textarea {
  min-height: 110px;
  resize: vertical;
  font-family: var(--font-sans);
}

.memory-submit {
  align-self: center;
  min-width: 220px;
  padding: 0.85rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.memory-submit:hover:not(:disabled) {
  background: #b89455;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.memory-submit:active:not(:disabled) {
  transform: translateY(0);
}

.memory-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.memory-status {
  min-height: 1.25em;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.memory-status.success {
  color: #6b8e4e;
}

.memory-status.error {
  color: #b86a5f;
}

/* ============================================
   Memory cards in the gallery
   ============================================ */
.gallery-memory {
  /* Memories don't need the image shimmer or fade-in delay */
  opacity: 1;
  transform: none;
  min-height: auto;
  background: transparent;
}

.gallery-memory::before {
  display: none;
}

.memory-card {
  background: linear-gradient(160deg, #fbf7ef 0%, #f6f0e4 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1.1rem;
  font-family: var(--font-serif);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(58, 48, 40, 0.05);
}

.memory-text {
  font-size: 1rem;
  line-height: 1.55;
  font-style: italic;
  white-space: pre-wrap;
  word-break: break-word;
}

.memory-author {
  margin-top: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-style: normal;
  color: var(--text-secondary);
  text-align: right;
}

.memory-date {
  margin-top: 0.25rem;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  color: var(--text-light);
  text-align: right;
}

/* ============================================
   Footer — warmer
   ============================================ */
.footer-memory {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

/* ============================================
   Accessibility helper
   ============================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   Image download deterrents
   ============================================ */
.gallery-item img,
.lightbox img,
.preview-item img {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  header {
    padding: 2.5rem 1rem 2rem;
  }

  header h1 {
    font-size: 1.8rem;
  }

  .container {
    padding: 0 1rem;
  }

  .upload-area {
    padding: 2rem 1rem;
  }

  .gallery {
    column-count: 2;
    column-gap: 8px;
  }

  .gallery-item {
    margin-bottom: 8px;
    border-radius: 6px;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 1.5rem;
  }

  header .subtitle {
    font-size: 0.95rem;
  }

  .preview-item {
    width: 60px;
    height: 60px;
  }
}

@media (min-width: 1200px) {
  .gallery {
    column-count: 4;
  }
}
