/* ใช้ร่วมกันระหว่างแกลเลอรีและบทความ (คู่กับ site/lightbox.js)
   1) lightbox ดูภาพเต็มจอ  2) สไลเดอร์ก่อน/หลังซ่อม (markup จาก lib/render/compare.cjs)  3) fade-in ของรูป (img.sn-fade) */

/* ---------- fade-in: JS ใส่ .sn-fade-wait ให้รูปที่ยังโหลดไม่เสร็จ แล้วย้าย lqip ไปเป็นพื้นของกล่องแม่ ---------- */
.sn-fade { transition: opacity .5s ease; }
.sn-fade-wait { opacity: 0; }
.sn-fade-box { background-size: cover; background-position: center; }

/* ---------- lightbox ---------- */
html.lb-lock { overflow: hidden; }
.lb { position: fixed; inset: 0; z-index: 1000; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; color: #eaf3fb; background: rgba(1,8,15,var(--lb-a, .96)); opacity: 0; transition: opacity .22s ease; overscroll-behavior: contain; -webkit-tap-highlight-color: transparent; }
.lb[hidden] { display: none; }
.lb.is-open { opacity: 1; }
.lb:focus { outline: none; }
.lb-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 12px 8px 20px; }
.lb-count { margin: 0; font-size: .9rem; color: #a8c2d8; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.lb-tools { display: flex; gap: 8px; }
.lb-btn, .lb-nav { appearance: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06); color: #fff; cursor: pointer; transition: background .15s, border-color .15s, transform .15s, opacity .2s; }
.lb-btn:hover, .lb-nav:hover { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.32); }
.lb-btn svg, .lb-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lb-btn:focus-visible, .lb-nav:focus-visible, .lb-thumb:focus-visible { outline: 3px solid #0093fe; outline-offset: 2px; }
.lb-zoom[aria-pressed="true"] { background: var(--acc, #d9ff5c); border-color: transparent; color: #021525; }
.lb-stage { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.lb-slide { position: absolute; inset: 0 12px; margin: 0; opacity: 0; pointer-events: none; transition: opacity .32s ease, transform .32s cubic-bezier(.2,.7,.2,1); }
.lb-slide.is-active { opacity: 1; pointer-events: auto; }
/* ภาพย่อที่โหลดไว้แล้วในหน้า เป็นตัวคั่นระหว่างรอภาพเต็ม (วางตรงตำแหน่งเดียวกับ object-fit: contain) */
.lb-slide::before { content: ''; position: absolute; inset: 0; background: var(--lb-ph, none) center / contain no-repeat; }
.lb-slide.is-ready::before { visibility: hidden; }
.lb-slide.is-loading::after { content: ''; position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; border: 3px solid rgba(255,255,255,.18); border-top-color: #fff; animation: lb-spin .8s linear infinite; }
@keyframes lb-spin { to { transform: rotate(360deg); } }
.lb-img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: contain; transform-origin: 50% 50%; transition: transform .26s cubic-bezier(.2,.7,.2,1), opacity .3s ease; cursor: zoom-in; -webkit-user-drag: none; user-select: none; }
.lb-img.is-wait { opacity: 0; }
.lb.is-zoomed .lb-img { cursor: grab; }
.lb.is-dragging .lb-img, .lb.is-dragging .lb-slide { transition: none; }
.lb.is-dragging.is-zoomed .lb-img { cursor: grabbing; }
.lb-nav { position: absolute; top: 50%; z-index: 2; width: 52px; height: 52px; margin-top: -26px; background: rgba(2,21,37,.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-nav[hidden] { display: none; }
.lb.is-zoomed .lb-nav { opacity: 0; pointer-events: none; }
.lb-cap { margin: 0 auto; padding: 12px 20px 4px; max-width: 760px; min-height: 1.6em; text-align: center; font-size: .95rem; line-height: 1.6; color: #d6e5f2; }
.lb-cap:empty { display: none; }
.lb-strip { display: none; }
@media (min-width: 900px) and (hover: hover) {
  .lb-strip { display: flex; gap: 8px; overflow-x: auto; padding: 12px 20px 18px; justify-content: flex-start; justify-content: safe center; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
  .lb-strip[hidden] { display: none; }
}
.lb-thumb { flex: none; width: 72px; height: 54px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: #0c2e49; opacity: .5; cursor: pointer; transition: opacity .15s, border-color .15s; }
.lb-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lb-thumb:hover { opacity: .85; }
.lb-thumb[aria-current="true"] { opacity: 1; border-color: var(--acc, #d9ff5c); }
@media (max-width: 640px) {
  .lb-top { padding-left: 16px; }
  .lb-slide { inset: 0; }
  .lb-nav { top: auto; bottom: 10px; margin-top: 0; width: 44px; height: 44px; }
  .lb-prev { left: 10px; }
  .lb-next { right: 10px; }
  .lb-cap { padding: 10px 64px max(14px, env(safe-area-inset-bottom)); font-size: .9rem; }
}

/* ---------- สไลเดอร์ก่อน/หลังซ่อม ([data-ba]) ----------
   --ba-pos = ตำแหน่งเส้นแบ่ง (ภาพก่อนอยู่ซ้าย) — JS อัปเดตจาก <input type=range>; ไม่มี JS = ครึ่งต่อครึ่ง */
.ba { margin: 0; }
.ba-frame { position: relative; aspect-ratio: var(--ba-ratio, 3 / 2); overflow: hidden; border-radius: 16px; background: #0c2e49; touch-action: pan-y; user-select: none; -webkit-user-select: none; box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.ba-img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; max-width: none; object-fit: cover; pointer-events: none; -webkit-user-drag: none; }
.ba-before-wrap { position: absolute; inset: 0; clip-path: inset(0 calc(100% - var(--ba-pos, 50%)) 0 0); }
.ba-handle { position: absolute; top: 0; bottom: 0; left: var(--ba-pos, 50%); z-index: 2; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 12px rgba(0,0,0,.45); pointer-events: none; }
.ba-handle::after { content: ''; position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: var(--acc, #d9ff5c) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23021525' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l-6 6 6 6M15 6l6 6-6 6'/%3E%3C/svg%3E") center / 24px no-repeat; box-shadow: 0 4px 18px rgba(0,0,0,.4), 0 0 0 4px rgba(255,255,255,.25); transition: transform .2s; }
.ba-frame.is-dragging .ba-handle::after { transform: scale(1.08); }
.ba-tag { position: absolute; top: 12px; z-index: 2; padding: 4px 12px; border-radius: 999px; font-size: .8rem; font-weight: 700; letter-spacing: .02em; color: #fff; background: rgba(2,21,37,.6); border: 1px solid rgba(255,255,255,.2); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); pointer-events: none; }
.ba-tag-before { left: 12px; }
.ba-tag-after { right: 12px; background: rgba(var(--acc-rgb, 217,255,92),.92); color: #021525; border-color: transparent; }
.ba-range { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
/* มี JS: ลากบนกรอบได้ทั้งภาพ (สัมผัส: ลากแนวนอน, เลื่อนจอแนวตั้งได้ตามปกติ) — range ยังรับคีย์บอร์ด/screen reader */
.ba-js .ba-frame { cursor: ew-resize; }
.ba-js .ba-range { pointer-events: none; }
.ba:has(.ba-range:focus-visible) .ba-handle::after { outline: 3px solid #0093fe; outline-offset: 3px; }
.ba figcaption { margin-top: 12px; text-align: center; color: var(--sn-muted, #a8c2d8); font-size: .9rem; line-height: 1.6; }

@media (prefers-reduced-motion: reduce) {
  .lb, .lb-slide, .lb-img, .sn-fade, .ba-handle::after { transition: none !important; }
  .lb-slide.is-loading::after { animation: none; }
}
