/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    background-color: #f5f5f5;
    color: #333;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background-color: white;
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 20px;
    color: #333;
}

/* Brand cluster (logo + fluid title), mirrors index.html behaviour */
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.header-logo {
    height: clamp(28px, 7vw, 36px);
    display: block;
}

/* More specific than `.header h1` so the fluid size wins */
.gallery-header .header-title {
    margin: 0;
    white-space: nowrap;
    font-size: clamp(16px, 4vw, 20px);
}

/* Toggled by the shared header-title helper (JS) */
.header-title.hidden {
    display: none;
}

.gallery-nav {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.lang-selector {
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 4px 6px;
    background-color: white;
    color: #374151;
    cursor: pointer;
    margin-left: 4px;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

.gallery-nav .nav-link {
    text-decoration: none;
    color: #666;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
}

.gallery-nav .nav-link:hover {
    background-color: #f0f0f0;
    color: #333;
}

.gallery-nav .nav-link.active {
    color: #6c5ce7;
    font-weight: 700;
    background-color: #f0edff;
}

.gallery-nav .nav-select {
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid #ddd;
    background-color: white;
    color: #666;
    cursor: pointer;
    outline: none;
    transition: background-color 0.2s, color 0.2s;
}

.gallery-nav .nav-select:hover {
    background-color: #f0f0f0;
    color: #333;
}

.gallery-nav .nav-select.active {
    color: #6c5ce7;
    font-weight: 700;
    background-color: #f0edff;
    border-color: #6c5ce7;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 50px;
    font-size: 18px;
    color: #666;
}

.loading i {
    margin-right: 10px;
}

/* Gallery Grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    padding: 10px;
}

.image-card {
    position: relative;
    background-color: white;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.image-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.image-card img,
.image-card video {
    width: 100%;
    height: 280px;
    object-fit: cover;
    display: block;
}

/* 숏폼 탭(2026-09-22, docs/GALLERY_SHORTFORM_TAB_PLAN.md) — 9:16 세로 카드.
   기본 카드는 height:280px + object-fit:cover 라 세로 영상의 위아래가 잘린다.
   .image-card img 보다 특이도가 높아(0,2,1 vs 0,1,1) 아래 모바일 규칙도 이긴다. */
.gallery-grid--portrait {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.gallery-grid--portrait .image-card img,
.gallery-grid--portrait .image-card video {
    height: auto;
    aspect-ratio: 9 / 16;
}

.gallery-grid--portrait .part-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
    padding: 3px 7px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 10;
}

/* 캡션 = 제목 2줄 + 통계. 세로 카드에는 hover 오버레이를 두지 않는다(JS 가 지운다):
   캡션이 카드 아래에 붙으면 bottom:0 오버레이가 캡션을 덮고, 모바일엔 hover 가 없다. */
.gallery-grid--portrait .card-caption {
    padding: 8px 10px 10px;
    font-size: 12px;
    line-height: 1.35;
    color: #333;
}

.gallery-grid--portrait .card-caption .cap-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.gallery-grid--portrait .card-caption .image-stats {
    color: #8a8a8a;
    font-size: 11px;
    gap: 12px;
    margin-top: 6px;
}

.image-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    padding: 15px;
    opacity: 0;
    transition: opacity 0.3s;
}

.image-card:hover .image-overlay {
    opacity: 1;
}

.image-stats {
    display: flex;
    gap: 15px;
    color: white;
    font-size: 14px;
}

.image-stats span {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    background-color: white;
    border-radius: 8px;
    color: #999;
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
}

.empty-state p {
    font-size: 18px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.modal-content {
    background-color: white;
    border-radius: 8px;
    max-width: 1200px;
    width: 100%;
    height: calc(100vh - 40px);
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 8px;
    font-size: 20px;
    line-height: 1;
    color: #666;
    cursor: pointer;
    z-index: 1001;
    background-color: rgba(255, 255, 255, 0.9);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    transition: background-color 0.3s;
}

.modal-close:hover {
    background-color: #f0f0f0;
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    color: #666;
    cursor: pointer;
    z-index: 1001;
    background-color: rgba(255, 255, 255, 0.9);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.modal-nav:hover {
    background-color: #f0f0f0;
}

.modal-nav:disabled {
    opacity: 0.3;
    cursor: default;
}

.modal-nav-prev {
    left: 15px;
}

.modal-nav-next {
    right: 15px;
}

/* Fullscreen Button */
.fullscreen-btn {
    position: absolute;
    bottom: 15px;
    right: 15px;
    font-size: 16px;
    color: #fff;
    cursor: pointer;
    z-index: 1001;
    background-color: rgba(0, 0, 0, 0.5);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.fullscreen-btn:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

/* Fullscreen Mode */
.modal.fullscreen-mode {
    padding: 0;
    background-color: #000;
}

.modal.fullscreen-mode .modal-content {
    max-width: 100%;
    width: 100%;
    height: 100%;
    border-radius: 0;
    background-color: #000;
}

.modal.fullscreen-mode .modal-body {
    height: 100%;
}

/* 컨테이너 max-height 해제가 핵심 — 모바일 미디어쿼리(아래 @media 768px)의 .image-section{max-height:40vh} 가
   전체화면에서 살아남아 overflow:hidden 으로 위 40vh 만 보이던 결함(MOBILE_FULLSCREEN_MEDIA_PLAN §1-1) */
.modal.fullscreen-mode .image-section {
    width: 100%;
    height: 100%;
    max-height: none;
}

/* 100dvh: 의사 전체화면(iOS, requestFullscreen 없음)에서 주소창 높이 오차 제거. 네이티브에선 vh 와 같다 */
.modal.fullscreen-mode .image-section img,
.modal.fullscreen-mode .image-section video {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    object-fit: contain;
}

.modal.fullscreen-mode .image-section .video-wrapper {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
}

.modal.fullscreen-mode .image-section .video-wrapper video {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: contain;
}

/* 줌·팬(fullscreen-viewer.js 가 --fs-scale / --fs-tx / --fs-ty 를 인라인 CSS 변수로 갱신) — 이미지에만.
   translate 가 scale 앞(=화면 좌표 px 이동)이라 회전 여부와 무관하게 같은 팬 좌표계를 쓴다.
   touch-action:none 은 브라우저 고유 핀치줌·스크롤을 끊어 우리 제스처만 남긴다 */
.modal.fullscreen-mode .image-section img {
    transform: translate(var(--fs-tx, 0px), var(--fs-ty, 0px)) scale(var(--fs-scale, 1));
    transform-origin: center center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    cursor: var(--fs-cursor, zoom-in);
    will-change: transform;
}

/* 방향 불일치 회전(fullscreen-viewer.js 가 .fs-rotated 토글) — 세로 이미지를 가로 화면에, 가로 이미지를 세로 화면에.
   치수를 서로 바꾸고 부모(.image-section / .video-wrapper, 둘 다 position:relative) 중앙에 절대 배치 후 90° */
.modal.fullscreen-mode .image-section img.fs-rotated,
.modal.fullscreen-mode .image-section .video-wrapper video.fs-rotated {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 100vh;
    width: 100dvh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
}

.modal.fullscreen-mode .image-section img.fs-rotated {
    transform: translate(-50%, -50%) translate(var(--fs-tx, 0px), var(--fs-ty, 0px)) scale(var(--fs-scale, 1)) rotate(90deg);
}

/* 의사 전체화면 — 네이티브 API 없이 .modal 자체를 뷰포트에 고정(.modal 은 이미 position:fixed) */
.modal.fullscreen-mode.fullscreen-pseudo {
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    z-index: 10000;
}

.modal.fullscreen-mode .info-section {
    display: none;
}

.modal.fullscreen-mode .modal-close {
    top: 15px;
    right: 15px;
    font-size: 24px;
    width: 36px;
    height: 36px;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal.fullscreen-mode .modal-close:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

.modal.fullscreen-mode .modal-nav {
    color: #fff;
    background-color: rgba(0, 0, 0, 0.5);
    width: 48px;
    height: 48px;
    font-size: 24px;
}

.modal.fullscreen-mode .modal-nav:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

.modal.fullscreen-mode .fullscreen-btn {
    bottom: 15px;
    right: 15px;
}

.modal-body {
    display: flex;
    height: 100%;
}

.image-section {
    flex: 1;
    position: relative;
    background-color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-section img,
.image-section video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.image-section .video-wrapper {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.info-section {
    width: 400px;
    display: flex;
    flex-direction: column;
    background-color: white;
    max-height: 90vh;
    overflow-y: auto;
}

.user-interaction-row {
    padding: 10px 50px 10px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Image title / description header (above comments) */
.modal-image-title {
    padding: 10px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-image-title .mit-title {
    font-size: 15px;
    font-weight: 700;
    color: #222;
    line-height: 1.4;
    word-break: break-word;
}

.modal-image-title .mit-desc {
    font-size: 13px;
    color: #666;
    margin-top: 4px;
    line-height: 1.5;
    word-break: break-word;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
}

.user-info i {
    font-size: 24px;
    color: #666;
}

.interaction-bar {
    display: flex;
    gap: 20px;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    color: #333;
    transition: color 0.3s;
}

.btn-icon:hover {
    color: #007bff;
}

.btn-icon.liked {
    color: #e74c3c;
}

.btn-icon i {
    font-size: 20px;
}

/* Comments Section */
.comments-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.comments-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.loading-comments {
    text-align: center;
    padding: 20px;
    color: #666;
}

.loading-comments i {
    font-size: 24px;
}

.error-message {
    text-align: center;
    padding: 20px;
    color: #e74c3c;
}

.no-comments {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.comment-item {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #f0f0f0;
}

.comment-item:last-child {
    border-bottom: none;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.comment-user {
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.comment-user i {
    margin-right: 5px;
    color: #666;
}

.comment-time {
    font-size: 12px;
    color: #999;
}

.comment-content {
    font-size: 14px;
    color: #333;
    margin-bottom: 8px;
    word-wrap: break-word;
}

.comment-actions {
    display: flex;
    gap: 10px;
}

.comment-like-btn {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #666;
    transition: color 0.3s;
}

.comment-like-btn:hover {
    color: #e74c3c;
}

.comment-input-container {
    display: flex;
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    gap: 10px;
}

.comment-input-container input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
}

.comment-input-container input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

.comment-input-container .btn-primary {
    background-color: #007bff;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.comment-input-container .btn-primary:hover:not(:disabled) {
    background-color: #0056b3;
}

.comment-input-container .btn-primary:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Login Prompt Modal */
.modal-content-small {
    background-color: white;
    border-radius: 8px;
    padding: 30px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.modal-content-small h3 {
    margin-bottom: 15px;
    font-size: 20px;
}

.modal-content-small p {
    margin-bottom: 25px;
    color: #666;
    font-size: 14px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-primary {
    background-color: #007bff;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.btn-primary:hover {
    background-color: #0056b3;
}

/* Stored Images Section (Card style) */
.card {
    background-color: white;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stored-image-card {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: border-color 0.3s, transform 0.2s;
    text-align: center;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    background-color: white;
}

.stored-image-card:hover {
    border-color: #007bff;
    transform: translateY(-2px);
}

.stored-image-card.selected {
    border-color: #28a745;
    background-color: #f8fff8;
}

.stored-image-card img,
.stored-image-card video {
    width: 100%;
    flex: 1;
    object-fit: cover;
    border-radius: 4px;
    min-height: 100px;
    max-height: 180px;
    background-color: #f0f0f0;
}

.stored-image-card .file-name {
    font-size: 11px;
    color: #666;
    margin-top: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive Design */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }

    .image-card img,
    .image-card video {
        height: 150px;
    }

    /* 숏폼 세로 카드 — 위 height:150px 를 명시적으로 되돌린다(특이도로도 이기지만,
       고정 높이와 aspect-ratio 가 싸우면 카드가 찌그러지므로 값으로 못 박는다). */
    .gallery-grid--portrait {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .gallery-grid--portrait .image-card img,
    .gallery-grid--portrait .image-card video {
        height: auto;
        aspect-ratio: 9 / 16;
    }

    .modal-body {
        flex-direction: column;
    }

    .info-section {
        width: 100%;
        max-height: 50vh;
    }

    .image-section {
        max-height: 40vh;
    }

    .image-section img,
    .image-section video {
        max-height: 40vh;
    }

    .image-section .video-wrapper {
        max-height: 40vh;
    }

    .header h1 {
        font-size: 18px;
    }

    .modal-nav-next {
        right: 15px;
    }
}

/* Video Merge Mode */
.merge-mode .stored-image-card:not(.merge-selectable) {
    opacity: 0.4;
    pointer-events: none;
}

.merge-mode .stored-image-card.merge-selectable {
    cursor: pointer;
}

.stored-image-card.merge-selected {
    border-color: #007bff !important;
    background-color: #f0f7ff;
    box-shadow: 0 0 0 2px #007bff;
}

.merge-badge {
    position: absolute;
    top: 5px;
    left: 5px;
    background-color: #007bff;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
