/* =========================================================
   SECOND POPUP — full-photo viewer
   CONCEPT D: ADAPTIVE DESKTOP / MOBILE VIEWER
   Mobile and desktop intentionally use DIFFERENT structures
   instead of one layout scaled down:
     - Mobile (base rules): full-bleed, image-first, overlay
       header + a compact pinned metadata bar, swipe-friendly.
     - Desktop (>=900px): a comfortable centered card where the
       photo and a full metadata sidebar sit side by side, with
       a normal (non-overlay) header — the layout literally
       switches from stacked-overlay to a two-column grid.
   ========================================================= */

.pv2 {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.pv2.open { display: flex; }

.pv2-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 2, 2, .95);
  transition: opacity .2s ease;
}

/* ---------- Mobile-first base: image-first, overlay chrome ---------- */

.pv2-dialog {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100svh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
  background: #050202;
  color: #fff;
  transition: transform .25s ease;
  touch-action: pan-y;
}

/* Swipe-down-to-close (mobile, no visible backdrop to tap outside of):
   dragged live in JS via an inline transform/opacity, this class only
   turns the CSS transition off while the finger is moving so the photo
   tracks the touch 1:1, then the transition above eases it back into
   place — or off-screen via hide() — once the finger lifts. */
.pv2-dialog.pv2-dragging { transition: none; }

.pv2-head {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(0, 0, 0, .55) 0%, rgba(0, 0, 0, 0) 100%);
  pointer-events: none;
}

.pv2-title { display: none; }

.pv2-counter {
  pointer-events: auto;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .4);
  border: 1px solid rgba(255, 255, 255, .18);
  font-size: .7rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

.pv2-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 15px);
  left: 17px;
  z-index: 20;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .15);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), background-color .25s ease, color .25s ease;
  pointer-events: auto;
}

.pv2-close:hover,
.pv2-close:focus-visible {
  background: var(--gold);
  color: #35120c;
  transform: rotate(90deg);
}

.pv2-close:active {
  transform: rotate(90deg) scale(.88);
}

.pv2-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.pv2-image-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.pv2-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
}

.pv2-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(0, 0, 0, .38);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.pv2-prev { left: 8px; }
.pv2-next { right: 8px; }

.pv2-info-toggle { display: none; }

/* Compact pinned metadata bar: title + date always visible, description
   truncated to a couple of lines — enough context without eating the
   photo area on a small screen. */
.pv2-meta {
  flex: 0 0 auto;
  padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 10px);
  box-sizing: border-box;
  background: #0b0403;
  border-top: 1px solid rgba(229, 180, 92, .16);
}

.pv2-meta-title {
  display: block;
  font-family: var(--font-tamil, "Noto Sans Tamil", sans-serif);
  font-size: .86rem;
  font-weight: 800;
  line-height: 1.35;
  color: var(--gold, #e5b45c);
}

.pv2-meta-desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin: 3px 0 0;
  color: rgba(255, 255, 255, .68);
  font-size: .74rem;
  line-height: 1.45;
}

.pv2-meta-date {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, .5);
  font-size: .68rem;
  font-weight: 600;
}

.pv2-hint { display: none; }

/* ---------- Desktop (>=900px): two-column card, roomy sidebar ---------- */

@media (min-width: 900px) {
  .pv2 { padding: 24px; }

  .pv2-dialog {
    width: min(1320px, 94vw);
    height: min(840px, 90svh);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "head head"
      "stage meta"
      "hint hint";
    border-radius: var(--radius, 20px);
    border: 1px solid rgba(229, 180, 92, .2);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  }

  .pv2-head {
    grid-area: head;
    position: static;
    justify-content: space-between;
    background: none;
    border-bottom: 1px solid rgba(229, 180, 92, .16);
    padding: 14px 64px 12px 20px;
    pointer-events: auto;
  }

  .pv2-title {
    display: block;
    flex: 1;
    min-width: 0;
    margin: 0;
    font-family: var(--font-tamil, "Noto Sans Tamil", sans-serif);
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .pv2-counter {
    background: none;
    border: none;
    color: rgba(255, 255, 255, .55);
    padding: 0;
  }

  .pv2-close {
    position: absolute;
    top: 15px;
    left: auto;
    right: 17px;
  }

  .pv2-stage { grid-area: stage; }

  .pv2-nav {
    width: 44px;
    height: 44px;
    font-size: 26px;
  }

  .pv2-prev { left: 16px; }
  .pv2-next { right: 16px; }

  .pv2-meta {
    grid-area: meta;
    display: flex;
    flex-direction: column;
    padding: 22px 24px;
    border-top: none;
    border-left: 1px solid rgba(229, 180, 92, .16);
    overflow-y: auto;
  }

  .pv2-meta-title {
    font-size: 1.05rem;
    color: #fff;
  }

  .pv2-meta-desc {
    -webkit-line-clamp: initial;
    margin-top: 10px;
    color: rgba(255, 255, 255, .74);
    font-size: .85rem;
    line-height: 1.65;
  }

  .pv2-meta-date {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(229, 180, 92, .14);
    color: var(--gold, #e5b45c);
    font-size: .78rem;
  }

  .pv2-hint {
    display: block;
    grid-area: hint;
    margin: 0;
    padding: 8px 20px;
    text-align: center;
    color: rgba(255, 255, 255, .35);
    font-size: .65rem;
    border-top: 1px solid rgba(229, 180, 92, .1);
  }
}

@media (min-width: 900px) and (max-width: 1180px) {
  .pv2-dialog { grid-template-columns: minmax(0, 1fr) 280px; }
}

@media (max-width: 760px) and (max-height: 480px) and (orientation: landscape) {
  .pv2-meta { padding: 6px 14px calc(env(safe-area-inset-bottom, 0px) + 6px); }
  .pv2-meta-desc { display: none; }
}
