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

/* ให้ attribute hidden ชนะเสมอ (กัน element ที่ตั้ง display:flex/grid โชว์ทั้งที่ควรซ่อน) */
[hidden] { display: none !important; }

:root {
  --accent: #1f7a44;
  --bg: #ffffff;
  --text: #333;
  --muted: #9aa0a6;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans Thai', 'Segoe UI', Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
}

.gallery-title {
  font-family: 'Sriracha', 'Noto Sans Thai', cursive;
  font-size: 26px;
  font-weight: 400;
  color: #2b2b2b;
  text-align: center;
  line-height: 1.3;
  padding: 0 60px;
  word-break: break-word;
}

.header-actions {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: #5f6368;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: #f1f3f4; }

/* ---------- States ---------- */
.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 20px;
  color: var(--muted);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #e8eaed;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 900px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 16px; } }
@media (max-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 12px; } }

.grid-item {
  position: relative;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  background: #f4f5f7;
  aspect-ratio: 1 / 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.grid-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }

@supports not (aspect-ratio: 1 / 1) {
  .grid-item { height: 0; padding-bottom: 100%; }
}

.grid-item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ไอคอนมุมบนขวา: มีวิดีโอ/หลายไฟล์ */
.badge-corner {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.0);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

/* play overlay สำหรับรายการที่มีวิดีโอ */
.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.play-overlay svg {
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
  opacity: 0.92;
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content {
  position: relative;
  z-index: 1;
  max-width: 92vw;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  overflow-y: auto;
  /* เว้นบน (ปุ่ม X) และล่าง (toolbar) ไม่ให้เนื้อหาชนปุ่ม */
  padding: 64px 0 84px;
  -webkit-overflow-scrolling: touch;
}

.lightbox-content img,
.lightbox-content video {
  max-width: 92vw;
  max-height: 72vh;
  width: auto;
  height: auto;
  border-radius: 6px;
  background: #000;
  object-fit: contain;
}

.lb-error {
  color: #fff;
  font-size: 16px;
  padding: 40px 20px;
  opacity: 0.85;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 10;
  width: 44px;
  height: 44px;
  font-size: 30px;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.95;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-close:hover { opacity: 1; background: rgba(0, 0, 0, 0.75); }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  font-size: 30px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-nav:hover { background: rgba(0, 0, 0, 0.75); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

.lightbox-toolbar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 10px;
}
.lb-tool {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  transition: background 0.15s ease;
}
.lb-tool:hover { background: rgba(255, 255, 255, 0.28); }

@media (max-width: 640px) {
  .lightbox-nav { width: 40px; height: 40px; font-size: 24px; }
  .lightbox-prev { left: 6px; }
  .lightbox-next { right: 6px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 11px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
