: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.25rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}

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;
}

/* ============================================
   Upload Section
   ============================================ */
.upload-section {
  padding: 2rem 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);
}

/* ============================================
   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);
}

/* ============================================
   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;
  }
}
