/* =========================
 * MD Simple Popups - Full CSS (fit + animation)
 * Updated: 2025-11-26
 * - 메인 팝업: 사이즈에 따라 이미지도 함께 확대/축소
 * - 카드: 세로로 쌓이는 레이아웃 (최신이 위로)
 * - 페이드 인/아웃 + 살짝 아래로 스르륵 모션
 * ========================= */
:root{
  --mdsp-panel-max-h: 84vh;
  --mdsp-vpad: 20px;
  --mdsp-header-h: 0px;
  --mdsp-footer-h: 56px;
  --mdsp-close-h: 44px;
}

/* ===== 공통 ===== */
#mdsp-modal, #mdsp-card {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  color-scheme: light dark;
  box-sizing: border-box;
}
*, *::before, *::after { box-sizing: inherit; }

/* ===== 테마 ===== */
.mdsp-theme-light .mdsp-modal-panel,
.mdsp-theme-light.mdsp-card { background:#ffffff; color:#111111; }
.mdsp-theme-dark .mdsp-modal-panel,
.mdsp-theme-dark.mdsp-card { background:#121212; color:#eaeaea; }
.mdsp-theme-dark .mdsp-card,
.mdsp-theme-dark .mdsp-modal-panel { border:1px solid #2a2a2a; }

/* ===== 모달 컨테이너 ===== */
.mdsp-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}
.mdsp-modal[aria-hidden="false"] {
  opacity: 1;
  pointer-events: auto;
}
.mdsp-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: saturate(120%) blur(1px);
  transition: opacity 220ms ease;
  opacity: 0;
}
.mdsp-modal[aria-hidden="false"] .mdsp-backdrop { opacity: 1; }

/* ===== 모달 패널 ===== */
.mdsp-modal-panel {
  position: relative;
  margin: 8vh auto 0;
  padding: var(--mdsp-vpad) 20px calc(var(--mdsp-vpad) - 4px);
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 30px rgba(0,0,0,0.20);
  width: 90%;
  max-height: var(--mdsp-panel-max-h);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(-6px);
  opacity: 0;
  transition: transform 240ms ease, opacity 240ms ease;
}
.mdsp-modal[aria-hidden="false"] .mdsp-modal-panel {
  transform: translateY(0);
  opacity: 1;
}

/* ===== 헤더/바디/푸터 ===== */
.mdsp-header {
  margin: 0 0 8px;
  padding-right: 48px;
  flex: 0 0 auto;
  min-height: var(--mdsp-header-h);
}
.mdsp-title  { font-size: 18px; font-weight: 700; line-height: 1.35; margin:0; }

.mdsp-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mdsp-media { 
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== 이미지 ===== */
.mdsp-img{
  max-width: 100%;
  width: auto;
  height: auto;
  display: block;
  border-radius: 10px;
  max-height: calc(
    var(--mdsp-panel-max-h)
    - var(--mdsp-header-h)
    - var(--mdsp-footer-h)
    - (var(--mdsp-vpad) * 2)
    - 8px
  );
  object-fit: contain;
  margin: 0 auto;
  z-index: 1;
}

/* ===== 푸터 ===== */
.mdsp-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  min-height: var(--mdsp-footer-h);
  flex: 0 0 auto;
}

/* ===== 버튼 ===== */
.mdsp-btn {
  appearance: none;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #111827;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 150ms ease;
  white-space: nowrap;
}
.mdsp-btn:hover { 
  background:#f3f4f6; 
  border-color: #9ca3af;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.mdsp-btn:active {
  transform: translateY(0);
  box-shadow: none;
}
.mdsp-btn-primary { 
  background:#111827; 
  color:#ffffff; 
  border-color:#111827; 
}
.mdsp-btn-primary:hover { 
  background:#1f2937;
  border-color:#1f2937;
}

.mdsp-btn.mdsp-quiet {
  background: transparent;
  border: none;
  color: #6b7280;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 8px 12px;
}
.mdsp-btn.mdsp-quiet:hover {
  color: #374151;
  background: rgba(0,0,0,0.03);
  transform: none;
  box-shadow: none;
}

/* ===== 사이즈 프리셋 ===== */
.mdsp-size-sm .mdsp-modal-panel { 
  max-width: min(92vw, 420px);
}
.mdsp-size-sm .mdsp-img {
  max-width: 380px;
}

.mdsp-size-md .mdsp-modal-panel { 
  max-width: min(95vw, 620px);
}
.mdsp-size-md .mdsp-img {
  max-width: 580px;
}

.mdsp-size-lg .mdsp-modal-panel { 
  max-width: min(98vw, 800px);
}
.mdsp-size-lg .mdsp-img {
  max-width: 760px;
}

/* ===== 닫기 버튼 (메인) ===== */
.mdsp-close{
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  font-size: 28px;
  line-height: 1;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #666666;
  z-index: 3;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  transition: all 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.mdsp-close:hover  { 
  color:#333333; 
  background: rgba(255, 255, 255, 1);
  transform: scale(1.08);
}
.mdsp-close:active {
  transform: scale(0.96);
}
.mdsp-close:focus  { 
  outline: 2px solid #9ec5fe; 
  outline-offset: 2px; 
}

.mdsp-theme-dark .mdsp-close {
  background: rgba(30, 30, 30, 0.95);
  color: #aaaaaa;
}
.mdsp-theme-dark .mdsp-close:hover {
  background: rgba(40, 40, 40, 1);
  color: #ffffff;
}

/* ===== 카드 컨테이너 ===== */
#mdsp-card-stack {
  position: fixed;
  pointer-events: none; /* 카드만 클릭 가능하도록 */
  z-index: 9998;
}

/* ===== 카드 팝업 (세로 스택) ===== */
.mdsp-card {
  position: fixed; /* JS에서 동적으로 위치 조정 */
  z-index: 9998;
  width: auto;
  max-width: min(92vw, 380px);
  min-width: 280px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  padding: 16px 16px 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 250ms ease, transform 250ms ease, bottom 250ms ease;
  pointer-events: auto; /* 카드 자체는 클릭 가능 */
}

/* 카드 표시 애니메이션 */
.mdsp-card[style*="opacity: 1"] {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

.mdsp-card-header { 
  margin: 0 0 8px; 
  padding-right: 40px; 
}

.mdsp-card-title  { 
  margin: 0; 
  font-size: 15px; 
  font-weight: 600; 
  line-height: 1.4; 
  color: #111827;
}

.mdsp-card-content{ 
  font-size: 14px; 
  line-height: 1.6; 
  color: #374151;
}

.mdsp-card-link   { 
  display:inline-block; 
  margin-top: 6px; 
  text-decoration: underline;
  color: #2563eb;
  font-size: 14px;
  transition: color 150ms ease;
}
.mdsp-card-link:hover {
  color: #1d4ed8;
}

/* 닫기 버튼 (카드) */
.mdsp-card-close{
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #1b1b1b;
  z-index: 3;
  border-radius: 50%;
  transition: all 150ms ease;
  -webkit-tap-highlight-color: transparent;
}
.mdsp-card-close:hover { 
  color:#374151; 
  background: rgba(0,0,0,0.05);
  transform: scale(1.08);
}
.mdsp-card-close:active {
  transform: scale(0.96);
}
.mdsp-card-close:focus { 
  outline: 2px solid #9ec5fe; 
  outline-offset: 2px; 
}

/* 카드 이미지 */
.mdsp-card-img{
  max-width: 100%;
  width: auto;
  height: auto;
  display: block;
  border-radius: 10px;
  object-fit: contain;
  max-height: 280px;
}

/* 다크 테마 카드 */
.mdsp-theme-dark.mdsp-card {
  background: #1a1a1a;
  border-color: #333333;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.mdsp-theme-dark .mdsp-card-title {
  color: #f3f4f6;
}
.mdsp-theme-dark .mdsp-card-content {
  color: #d1d5db;
}
.mdsp-theme-dark .mdsp-card-close {
  color: #9ca3af;
}
.mdsp-theme-dark .mdsp-card-close:hover {
  color: #f3f4f6;
  background: rgba(255,255,255,0.1);
}

/* ===== 보조 유틸 ===== */
.mdsp-hidden { display:none !important; }
.mdsp-center { text-align:center; }
.mdsp-right  { text-align:right; }

/* ===== 접근성 ===== */
.mdsp-modal:focus-within .mdsp-modal-panel {
  outline: none;
}

button:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-radius: 8px;
}

/* ===== 모바일 최적화 ===== */
@media (max-width: 640px) {
  :root { 
    --mdsp-panel-max-h: 90vh; 
    --mdsp-footer-h: 52px; 
  }
  
  .mdsp-modal-panel { 
    margin-top: 5vh; 
    max-width: 94vw !important;
    padding: 16px 16px 12px;
  }
  
  .mdsp-size-sm .mdsp-img,
  .mdsp-size-md .mdsp-img,
  .mdsp-size-lg .mdsp-img {
    max-width: 100%;
  }
  
  .mdsp-card { 
    max-width: 92vw;
    min-width: 260px;
  }
  
  .mdsp-close { 
    top: 6px; 
    right: 8px;
    width: 36px;
    height: 36px;
    font-size: 24px;
  }
  
  .mdsp-card-close { 
    top: 6px; 
    right: 6px;
    width: 30px;
    height: 30px;
    font-size: 20px;
  }
  
  .mdsp-btn {
    font-size: 13px;
    padding: 9px 14px;
  }
  
  .mdsp-card-img {
    max-height: 220px;
  }
}

/* 아주 작은 화면 */
@media (max-width: 375px) {
  :root { 
    --mdsp-panel-max-h: 92vh; 
  }
  
  .mdsp-modal-panel {
    margin-top: 4vh;
  }
  
  .mdsp-btn {
    font-size: 12px;
    padding: 8px 12px;
  }
  
  .mdsp-card {
    max-width: 94vw;
    min-width: 240px;
  }
}

/* 가로 모드 */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --mdsp-panel-max-h: 90vh;
  }
  
  .mdsp-modal-panel {
    margin-top: 3vh;
    padding: 12px 16px 8px;
  }
  
  .mdsp-card {
    max-width: 320px;
  }
  
  .mdsp-card-img {
    max-height: 180px;
  }
}

/* 애니메이션 줄이기 선호 사용자 */
@media (prefers-reduced-motion: reduce) {
  .mdsp-modal,
  .mdsp-modal-panel,
  .mdsp-backdrop,
  .mdsp-card,
  .mdsp-btn,
  .mdsp-close,
  .mdsp-card-close {
    transition: none !important;
    animation: none !important;
  }
}
