/**
 * 画像ライトボックスのスタイル
 */

/* ライトボックスコンテナ */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lightbox.active {
    display: block;
}

.lightbox.active {
    opacity: 1;
}

/* オーバーレイ（背景） */
.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    cursor: zoom-out;
}

/* コンテンツコンテナ */
.lightbox-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100vw - 40px);  /* 左右20pxずつのマージン */
    height: calc(100vh - 40px); /* 上下20pxずつのマージン */
    max-width: 1200px;          /* 最大幅を制限 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* 画像 */
.lightbox-image {
    width: 100%;                /* 親要素の幅いっぱいに */
    height: 100%;               /* 親要素の高さいっぱいに */
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;        /* アスペクト比を維持して収める */
    display: none;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    transform-origin: center center;
    cursor: zoom-in;
}

.lightbox-image.loaded {
    opacity: 1;
    transform: scale(1);
}

/* 閉じるボタン */
.lightbox-close {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: white;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: rotate(90deg);
}

/* ローディング表示 */
.lightbox-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 16px;
    display: none;
}

/* 記事内画像のホバー効果 */
.post-body img:not(.url-card img) {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.post-body img:not(.url-card img):hover {
    opacity: 0.95;
    transform: scale(1.02);
}

/* モバイル対応 */
@media (max-width: 768px) {
    .lightbox-content {
        width: calc(100vw - 20px);  /* モバイルでは左右10pxずつのマージン */
        height: calc(100vh - 60px); /* 上下のUIを考慮 */
        padding: 10px;
    }
    
    .lightbox-close {
        width: 40px;
        height: 40px;
        font-size: 24px;
        top: 10px;
        right: 10px;
    }
}

/* より大きな画面用の調整 */
@media (min-width: 1400px) {
    .lightbox-content {
        width: calc(100vw - 100px);  /* 大画面では左右50pxずつのマージン */
        max-width: 1600px;           /* 最大幅を広げる */
    }
}

/* タッチデバイス用の調整 */
@media (hover: none) {
    .post-body img:not(.url-card img):hover {
        opacity: 1;
        transform: none;
    }
}

/* アニメーション無効化（アクセシビリティ） */
@media (prefers-reduced-motion: reduce) {
    .lightbox,
    .lightbox-image,
    .lightbox-close,
    .post-body img {
        transition: none !important;
    }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    .lightbox-overlay {
        background: rgba(0, 0, 0, 0.95);
    }
}

/* キャプション */
.lightbox-caption {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 14px;
    max-width: calc(100vw - 80px);
    text-align: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    z-index: 1;
}

@media (max-width: 768px) {
    .lightbox-caption {
        bottom: 20px;
        font-size: 12px;
        padding: 8px 16px;
        max-width: calc(100vw - 40px);
    }
}