:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --btn: #1c1c1e;
  --btn-text: #ffffff;
  --dot: #d4d4d4;
  --radius: 16px;
  --gap: 14px;
  /* Mobile card width: fits the screen width and leaves room for the title and button below */
  --card-w: min(76vw, calc((100svh - 270px) / 2), 320px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 0 32px;
}

.hero {
  text-align: center;
  padding: 0 16px;
  margin-bottom: 18px;
}
.hero h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.hero p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Mobile: one card at a time, swipe sideways, neighbours peek in */
.gallery {
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  padding: 4px calc((100% - var(--card-w)) / 2) 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.gallery::-webkit-scrollbar { display: none; }

.card {
  flex: 0 0 var(--card-w);
  scroll-snap-align: center;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
  object-fit: cover;
  border-radius: var(--radius);
  background: #eee;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 6px 18px rgb(0 0 0 / 0.08);
  user-select: none;
  -webkit-user-drag: none;
  /* Press-and-hold here would save the small preview, not the wallpaper */
  -webkit-touch-callout: none;
}

.card h2 {
  margin: 14px 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
}

.btn {
  display: block;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--btn);
  color: var(--btn-text);
  text-align: center;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.88; }
.btn:active { opacity: 0.75; }
.btn:focus-visible { outline: 3px solid #8ab4f8; outline-offset: 2px; }

.dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}
.dots button {
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--dot);
  cursor: pointer;
  transition: width 0.2s, background 0.2s;
}
.dots button[aria-current="true"] {
  width: 22px;
  background: var(--btn);
}

.hero .hint {
  margin: 8px auto 0;
  max-width: 320px;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Full-size viewer: the picture fills the screen so press-and-hold saves the real file */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: #111;
}
.viewer[hidden] { display: none; }
.viewer img {
  display: block;
  max-width: 100%;
  max-height: calc(100svh - 170px);
  border-radius: 12px;
  -webkit-touch-callout: default;
  user-select: auto;
}
.viewer-panel { text-align: center; color: #fff; max-width: 340px; }
.viewer-tip { margin: 0; font-size: 1rem; line-height: 1.45; }
.viewer-tip b { font-weight: 700; }
.viewer-external {
  display: inline-block;
  margin-top: 10px;
  color: #fff;
  font-size: 0.85rem;
  text-decoration: underline;
  opacity: 0.85;
}
.viewer-external[hidden] { display: none; }
.viewer-close {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.15);
  color: #fff;
  font-size: 28px;
  line-height: 44px;
  cursor: pointer;
}
.viewer-close:focus-visible { outline: 3px solid #8ab4f8; outline-offset: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}
.toast[hidden] { display: none; }

/* Tablet and desktop: all cards in a grid, no carousel */
@media (min-width: 768px) {
  .page { padding: 40px 24px 48px; }
  .hero h1 { font-size: 2rem; }
  .gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    overflow: visible;
    padding: 0;
  }
  .dots { display: none; }
}
