/* ===================================================
   GALLERY MODAL – Polished Version
   =================================================== */

.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.94);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0s 0.4s;
}

.modal.active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s ease, visibility 0s 0s;
}

.modal-close {
  position: absolute;
  top: 20px; right: 20px;
  width: 48px; height: 48px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50%;
  color: white;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 10;
}

.modal-close:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  transform: rotate(90deg) scale(1.1);
}

.modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 54px; height: 54px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50%;
  color: rgba(255,255,255,0.8);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 10;
  opacity: 0;
}

.modal:hover .modal-nav { opacity: 1; }

.modal-nav:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.3);
  transform: translateY(-50%) scale(1.12);
  color: white;
}

.modal-nav:active { transform: translateY(-50%) scale(0.95); }
.modal-nav.prev { left: 24px; }
.modal-nav.next { right: 24px; }

.modal-image-container {
  max-width: 85vw;
  max-height: 80vh;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal.active .modal-image-container {
  animation: modalContentIn 0.5s cubic-bezier(0.16,1,0.3,1) forwards;
}

@keyframes modalContentIn {
  from { opacity:0; transform:scale(0.92) translateY(16px); }
  to { opacity:1; transform:scale(1) translateY(0); }
}

.modal-image {
  max-width: 100%;
  max-height: 68vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 25px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.05);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.modal-image.slide-left { opacity:0; transform:translateX(-50px) scale(0.97); }
.modal-image.slide-right { opacity:0; transform:translateX(50px) scale(0.97); }

.modal-gradient-display {
  width: 70vw; max-width: 700px;
  height: 50vh; max-height: 500px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 80px;
  box-shadow: 0 25px 80px rgba(0,0,0,0.6);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.modal-gradient-display.slide-left { opacity:0; transform:translateX(-50px) scale(0.97); }
.modal-gradient-display.slide-right { opacity:0; transform:translateX(50px) scale(0.97); }

.modal-info {
  margin-top: 28px;
  text-align: center;
  max-width: 600px;
  animation: infoFadeIn 0.6s 0.2s ease both;
}

@keyframes infoFadeIn {
  from { opacity:0; transform:translateY(8px); }
  to { opacity:1; transform:translateY(0); }
}

.modal-title-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.modal-info .modal-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 0;
  cursor: default;
  transition: color 0.2s ease;
}

body.is-admin .modal-info .modal-title {
  cursor: pointer;
}

body.is-admin .modal-info .modal-title:hover {
  color: #ffccd5;
  text-decoration: underline dotted 2px rgba(255, 77, 109, 0.6);
}

/* Edit button - hidden by default, visible only to admin */
.modal-title-edit-btn {
  display: none !important;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

body.is-admin .modal-title-edit-btn {
  display: inline-flex !important;
}

.modal-title-edit-btn:hover {
  background: var(--accent, #FF4D6D);
  border-color: var(--accent, #FF4D6D);
  color: #fff;
  transform: scale(1.1);
}

/* Preview edit button - hidden by default, visible only to admin */
.preview-btn.preview-edit {
  display: none !important;
}

body.is-admin .preview-btn.preview-edit {
  display: inline-flex !important;
}

.modal-title-edit-form {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  animation: infoFadeIn 0.2s ease;
}

.modal-title-input {
  background: rgba(20, 20, 20, 0.95);
  border: 2px solid var(--accent, #FF4D6D);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  outline: none;
  min-width: 240px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 0 15px rgba(255, 77, 109, 0.3);
}

.btn-title-save,
.btn-title-cancel {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-title-save {
  background: var(--accent, #FF4D6D);
  color: #fff;
}

.btn-title-save:hover {
  background: #ff2a51;
  transform: translateY(-1px);
}

.btn-title-cancel {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.8);
}

.btn-title-cancel:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.modal-info .modal-date { font-size:14px; color:var(--accent-light, #FF8FA3); margin-bottom:6px; font-weight:300; }
.modal-info .modal-desc { font-size:14px; color:rgba(255,255,255,0.6); line-height:1.7; font-weight:300; }

/* Toast notification */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 77, 109, 0.6);
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 15px rgba(255, 77, 109, 0.3);
  backdrop-filter: blur(10px);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16,1,0.3,1), transform 0.3s cubic-bezier(0.16,1,0.3,1);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-dots { display:flex; gap:10px; margin-top:20px; justify-content:center; }

.modal-dot {
  width:8px; height:8px;
  border-radius:50%;
  background:rgba(255,255,255,0.2);
  border:none;
  cursor:pointer;
  transition:all 0.3s ease;
  padding:0;
}

.modal-dot:hover { background:rgba(255,255,255,0.4); transform:scale(1.3); }

.modal-dot.active {
  background:var(--accent, #FF4D6D);
  transform:scale(1.4);
  box-shadow:0 0 12px rgba(255,77,109,0.5);
}

.modal-counter {
  position:absolute;
  top:24px; left:50%;
  transform:translateX(-50%);
  font-size:14px;
  color:rgba(255,255,255,0.4);
  font-variant-numeric:tabular-nums;
  letter-spacing:0.1em;
  z-index:5;
}

.swipe-hint {
  position:absolute;
  bottom:30px; left:50%;
  transform:translateX(-50%);
  font-size:12px;
  color:rgba(255,255,255,0.25);
  display:none;
}

@media (max-width:768px) {
  .modal-nav { display:none; }
  .modal-image-container { max-width:95vw; max-height:85vh; }
  .modal-image { max-height:55vh; border-radius:6px; }
  .modal-gradient-display { width:90vw; height:40vh; font-size:60px; }
  .modal-info { margin-top:20px; padding:0 16px; }
  .modal-info h2 { font-size:20px; }
  .modal-close { top:12px; right:12px; width:40px; height:40px; font-size:18px; }
  .swipe-hint { display:block; }
}

/* =========================================================
   뷰어 진행 막대 + 썸네일 띠 (사진이 많은 폴더용)
   ========================================================= */
.modal-progress {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
  z-index: 12;
  display: none;
}
.modal-progress.show { display: block; }
.modal-progress-bar {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ff6b9d, #ffa8c5);
  transition: width 0.25s ease;
}

.modal-filmstrip {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: none;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  overflow-x: auto;
  overflow-y: hidden;
  background: linear-gradient(to top, rgba(0,0,0,0.92), rgba(0,0,0,0.55) 70%, transparent);
  scrollbar-width: none;
  z-index: 12;
  -webkit-overflow-scrolling: touch;
}
.modal-filmstrip::-webkit-scrollbar { display: none; }
.modal-filmstrip.show { display: flex; }

.filmstrip-thumb {
  flex: 0 0 auto;
  width: 58px; height: 58px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  opacity: 0.55;
  cursor: pointer;
  background: #222;
  padding: 0;
  transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.filmstrip-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.filmstrip-thumb:hover { opacity: 0.85; }
.filmstrip-thumb.active {
  opacity: 1;
  border-color: #ff6b9d;
  transform: scale(1.08);
}
.filmstrip-thumb .filmstrip-video-icon {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  pointer-events: none;
}
.filmstrip-thumb { position: relative; }

/* 썸네일 띠가 뜨면 설명이 가리지 않도록 살짝 올린다 */
.modal.has-filmstrip .modal-info { padding-bottom: 92px; }
.modal.has-filmstrip .swipe-hint { display: none; }

@media (max-width: 600px) {
  .filmstrip-thumb { width: 46px; height: 46px; }
  .modal.has-filmstrip .modal-info { padding-bottom: 78px; }
}

/* =========================================================
   격자 보기 (인스타그램식) — 모바일 우선
   ========================================================= */
.grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: #0d0d0d;
  display: none;
  flex-direction: column;
}
.grid-overlay.active { display: flex; }

.grid-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(13, 13, 13, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.grid-back, .grid-play {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.grid-play { font-size: 15px; }
.grid-back:active, .grid-play:active { background: rgba(255, 255, 255, 0.22); }

.grid-heading { flex: 1 1 auto; min-width: 0; }
.grid-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid-count { font-size: 12px; color: #ff9ebd; }

.grid-items {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 14px 14px calc(28px + env(safe-area-inset-bottom));
  align-content: start;
}
.grid-cell {
  position: relative;
  border: none;
  padding: 0;
  margin: 0;
  background: #1c1c1c;
  cursor: pointer;
  overflow: hidden;
  border-radius: 18px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  width: 100%;
  height: 100%;
  display: block;
}
/* 행 높이를 JS가 픽셀로 지정하면 스페이서는 필요 없다 */
.grid-items.rows-sized .grid-cell { height: 100%; }
.grid-items.rows-sized .grid-ratio { display: none; }
.grid-cell:focus-visible {
  outline: 2px solid #ff6b9d;
  outline-offset: 2px;
}
/* 1x1 투명 GIF를 너비 100%로 늘려 높이를 만든다 -> 항상 정확한 정사각 */
.grid-cell .grid-ratio {
  display: block;
  width: 100%;
  height: auto;
  border: 0;
}
.grid-cell .grid-photo {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.15s ease;
}
.grid-cell:active .grid-photo { transform: scale(0.97); }
.grid-cell .grid-video-icon {
  position: absolute;
  top: 10px; right: 11px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  font-size: 11px;
  color: #fff;
  pointer-events: none;
}

/* 화면이 넓어지면 열을 늘리되 간격과 둥근 모서리는 유지한다 */
@media (min-width: 640px) {
  .grid-items { grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 16px 16px 40px; }
  .grid-title { font-size: 17px; }
}
@media (min-width: 1000px) {
  .grid-items { grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 20px 20px 48px; }
}
