/* 모바일 최적화 공통 스타일 */

/* 기본 최적화 */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    box-sizing: border-box;
}

/* 성능 최적화: 하드웨어 가속 */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* contain 제거: position: fixed 요소가 제대로 작동하도록 */
    position: static; /* fixed 요소가 제대로 작동하도록 명시 */
}

body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1;
    /* contain 제거: position: fixed 요소가 제대로 작동하도록 */
    /* will-change 제거: stacking context 생성 방지 */
    position: static; /* fixed 요소가 제대로 작동하도록 명시 */
}

/* 터치 타겟 최소 크기 보장 */
button,
a,
input[type="submit"],
input[type="button"],
select {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* 폰트 렌더링 최적화 */
body {
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1;
}

/* 이미지 최적화 */
img {
    max-width: 100%;
    height: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    loading: lazy;
    decoding: async;
    contain: layout style paint;
}

/* 스크롤 최적화 */
* {
    scroll-behavior: smooth;
}

/* 성능 최적화: GPU 가속 */
/* transform 제거: position: fixed 요소가 제대로 작동하도록 */
/* .container에 transform이 있으면 fixed 요소가 container 기준으로 작동함 */
.prayer-item,
.fb-card,
.stat-item {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* 모바일 기본 스타일 (768px 이하) */
@media (max-width: 768px) {
    body {
        font-size: 16px; /* iOS 줌 방지 */
        line-height: 1.8; /* 가독성 향상 */
        padding: 12px;
        word-break: keep-all;
        overflow-wrap: break-word;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* 컨테이너 최적화 */
    .container {
        padding: 16px;
        margin: 0 auto;
        border-radius: 16px;
        max-width: 100%;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    /* 제목 최적화 */
    h1 {
        font-size: clamp(1.75rem, 5vw, 2.25rem);
        line-height: 1.3;
        margin-bottom: 16px;
        font-weight: 600;
    }
    
    h2 {
        font-size: clamp(1.5rem, 4.5vw, 2rem);
        line-height: 1.35;
        margin-bottom: 14px;
        font-weight: 600;
    }
    
    h3 {
        font-size: clamp(1.25rem, 4vw, 1.75rem);
        line-height: 1.4;
        margin-bottom: 12px;
        font-weight: 600;
    }

    /* 텍스트 가독성 향상 */
    p, span, div, li {
        font-size: clamp(1rem, 2.8vw, 1.1rem);
        line-height: 1.8;
        letter-spacing: 0.02em;
        word-spacing: 0.05em;
    }

    /* 버튼 최적화 */
    button,
    .btn,
    a.button,
    input[type="submit"],
    input[type="button"] {
        padding: 14px 24px;
        font-size: 1rem;
        min-height: 48px;
        min-width: 48px;
        border-radius: 12px;
        touch-action: manipulation;
        font-weight: 500;
        letter-spacing: 0.02em;
        transition: transform 0.1s ease, box-shadow 0.1s ease;
    }
    
    button:active,
    .btn:active {
        transform: scale(0.98);
    }

    /* 입력 필드 최적화 */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px; /* iOS 줌 방지 */
        padding: 14px 16px;
        min-height: 48px;
        border-radius: 10px;
        line-height: 1.6;
        -webkit-appearance: none;
        appearance: none;
    }
    
    textarea {
        min-height: 120px;
        resize: vertical;
    }

    /* 간격 최적화 */
    .form-group,
    .section {
        margin-bottom: 20px;
    }
    
    .form-group label {
        font-size: 1rem;
        font-weight: 500;
        margin-bottom: 8px;
        display: block;
    }

    /* 그리드 최적화 */
    .grid,
    .flex-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    /* 리스트 최적화 */
    ul, ol {
        padding-left: 20px;
        margin-bottom: 16px;
    }
    
    li {
        margin-bottom: 8px;
    }
}

/* 작은 모바일 (480px 이하) */
@media (max-width: 480px) {
    body {
        padding: 10px;
        font-size: 15px;
        line-height: 1.65;
    }

    .container {
        padding: 14px;
        border-radius: 14px;
    }

    h1 {
        font-size: clamp(1.5rem, 6vw, 2rem);
        margin-bottom: 14px;
    }
    
    h2 {
        font-size: clamp(1.35rem, 5.5vw, 1.85rem);
        margin-bottom: 12px;
    }
    
    h3 {
        font-size: clamp(1.2rem, 5vw, 1.65rem);
        margin-bottom: 10px;
    }

    p, span, div, li {
        font-size: clamp(0.9rem, 3vw, 1rem);
        line-height: 1.65;
    }

    button,
    .btn,
    a.button,
    input[type="submit"],
    input[type="button"] {
        padding: 13px 20px;
        font-size: 0.95rem;
        min-height: 46px;
        border-radius: 11px;
    }

    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        padding: 13px 14px;
        font-size: 16px;
        min-height: 46px;
    }
    
    .form-group {
        margin-bottom: 18px;
    }
}

/* 초소형 화면 (375px 이하) */
@media (max-width: 375px) {
    body {
        padding: 8px;
        font-size: 15px;
        line-height: 1.6;
    }

    .container {
        padding: 12px;
        border-radius: 12px;
    }

    h1 {
        font-size: clamp(1.4rem, 7vw, 1.9rem);
        margin-bottom: 12px;
    }
    
    h2 {
        font-size: clamp(1.25rem, 6.5vw, 1.75rem);
        margin-bottom: 10px;
    }
    
    h3 {
        font-size: clamp(1.1rem, 6vw, 1.6rem);
        margin-bottom: 8px;
    }

    p, span, div, li {
        font-size: clamp(0.875rem, 3.5vw, 0.975rem);
        line-height: 1.6;
    }

    button,
    .btn,
    a.button,
    input[type="submit"],
    input[type="button"] {
        padding: 12px 18px;
        font-size: 0.925rem;
        min-height: 44px;
        border-radius: 10px;
    }
    
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        padding: 12px;
        font-size: 16px;
        min-height: 44px;
    }
}

/* 가로 모드 최적화 */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 8px;
    }
    
    .container {
        padding: 12px;
    }
    
    h1 {
        font-size: clamp(1.5rem, 4vw, 2rem);
        margin-bottom: 12px;
    }
}

/* 성능 최적화 */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* GPU 가속 */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 애니메이션 최적화 */
@media (prefers-reduced-motion: no-preference) {
    .smooth-transition {
        transition: transform 0.2s ease, opacity 0.2s ease;
        will-change: transform, opacity;
    }
    
    /* 호버 효과 최적화 */
    button:hover,
    .btn:hover,
    a.button:hover {
        will-change: transform;
    }
    
    /* 스크롤 최적화 */
    .scroll-container {
        will-change: scroll-position;
    }
}

/* 애니메이션 비활성화 (접근성) */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* 터치 최적화 */
.touch-optimized {
    touch-action: manipulation;
    -webkit-touch-callout: none;
    user-select: none;
}

/* 스크롤 최적화 */
.scroll-optimized {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* 폰트 로딩 최적화 */
@font-face {
    font-display: swap;
}

/* 접근성 개선 */
@media (prefers-contrast: high) {
    * {
        border-width: 2px;
    }
}

/* 다크 모드 지원 (선택적) */
@media (prefers-color-scheme: dark) {
    /* 필요시 다크 모드 스타일 추가 */
}

/* 인쇄 최적화 */
@media print {
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
    
    .no-print {
        display: none !important;
    }
}

/* 성능 최적화: 컨테이너 쿼리 대체 */
.container-optimized {
    contain: layout style paint;
}

/* 텍스트 선택 최적화 */
::selection {
    background-color: rgba(102, 126, 234, 0.3);
    color: inherit;
}

::-moz-selection {
    background-color: rgba(102, 126, 234, 0.3);
    color: inherit;
}

/* 스크롤바 최적화 (WebKit) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

