:root{
  --bg:#fff;
  --border:#e7e7ea;
  --text:#222;
  --muted:#666;
  --radius:14px;
  --shadow: 0 10px 30px rgba(0,0,0,.08);

  --primary:#5a2982;
  --secondary:#fcaf1a;
}

.gallery{
  width: min(920px, 100%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display:grid;
  gap:12px;
  margin-bottom: 20px;
}

/* ===== Main viewer ===== */
.gallery .viewer{
  border:1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  overflow:hidden;
  position:relative;
  aspect-ratio: 16 / 9;
  background:#f2f2f4;
  cursor: pointer;
  user-select:none;
}
.gallery .viewer img{
  width:100%;
  height:100%;
  object-fit: contain;
  display:block;
      background: white;
}

.gallery .controls{
  position:absolute;
  inset: 10px 10px auto 10px;
  display:flex;
  justify-content: space-between;
  gap:10px;
  pointer-events:none;
}
.gallery .btn{
  pointer-events:auto;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 10px 12px;
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-size: 14px;
  color: var(--text);
  cursor:pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,.06);
}
.gallery .btn:active{ transform: translateY(1px); }

.gallery .hint{
  position:absolute;
  inset: auto 12px 12px 12px;
  display:flex;
  justify-content: space-between;
  gap:10px;
  color: var(--muted);
  font-size: 13px;
  pointer-events:none;
}
.gallery .pill{
  background: rgba(255,255,255,.92);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 14px rgba(0,0,0,.06);
  max-width: 70%;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Thumbnails ===== */
.gallery .thumbs{
  display:flex;
  gap:10px;
  padding: 6px 2px;
  overflow:auto;
  scroll-snap-type: x mandatory;
}
.gallery .thumbs::-webkit-scrollbar{ height: 10px; }
.gallery .thumbs::-webkit-scrollbar-thumb{
  background:#d9d9de;
  border-radius:999px;
}

.gallery .thumb{
  flex:0 0 auto;
  width:92px;
  height:62px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#f4f4f7;
  overflow:hidden;
  cursor:pointer;
  scroll-snap-align:start;
  padding:0;
}
.gallery .thumb img{
  width:100%;
  height:100%;
  object-fit: cover;
  display:block;
}
.gallery .thumb[aria-current="true"]{
  outline: 3px solid rgba(90,41,130,.25);
  border-color: rgba(90,41,130,.6);
}
.gallery .thumb:focus-visible{
  outline: 3px solid rgba(0,0,0,.25);
  outline-offset: 2px;
}

.gallery .meta{
  display:flex;
  justify-content: space-between;
  gap:12px;
  color: var(--muted);
  font-size:13px;
}

/* ===== Modal fullscreen ===== */
.gallery .modal{
  position: fixed;
  inset: 0;
  display: none;
  z-index: 9999;
}
.gallery .modal[aria-hidden="false"]{
  display:block;
}

.gallery .modal__backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.7);
}

.gallery .modal__panel{
  position:absolute;
  inset: 0;
  display:grid;
  grid-template-rows: auto 1fr auto;
}

.gallery .modal__topbar{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap:12px;
  padding: 14px 16px;
  color: #fff;
}

.gallery .modal__title{
  font-size: 14px;
  color: rgba(255,255,255,.85);
  overflow:hidden;
  white-space:nowrap;
  text-overflow: ellipsis;
  max-width: 70vw;
}

.gallery .modal__close{
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25);
  color:#fff;
  border-radius: 999px;
  padding: 10px 12px;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  gap:8px;
}
.gallery .modal__close:hover{
  border-color: rgba(255,255,255,.45);
  background: rgba(0,0,0,.35);
}

.gallery .modal__stage{
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 10px 16px 16px;
}

.gallery .modal__imgWrap{
  width: min(1200px, 96vw);
  height: min(78vh, 900px);
  border-radius: 18px;
  overflow:hidden;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  display:flex;
  align-items:center;
  justify-content:center;
}

.gallery .hidden {
    display: none;
}


.gallery .modal__img{
  width: 100%;
  height: 100%;
  object-fit: contain;
  display:block;
  background: white;
}

.gallery .modal__nav{
  display:flex;
  justify-content:center;
  gap: 10px;
  padding: 0 16px 18px;
}
.gallery .modal__nav .btn{
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.18);
  color:#fff;
  box-shadow:none;
}
.gallery .modal__nav .btn:hover{
  background: rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.25);
}

@media (max-width: 600px){
  .gallery .viewer{ aspect-ratio: 4 / 3; }
  .gallery .thumb{ width:78px; height:56px; }
  .gallery .modal__imgWrap{
    width: 96vw;
    height: 72vh;
    border-radius: 16px;
  }
  .gallery .modal__title{ max-width: 58vw; }
}