/* 全体的なスクロールバー非表示設定 */
* {
    /* スクロールバー非表示の統一設定 */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

*::-webkit-scrollbar {
    display: none;
}

/* スクロール機能は保持しつつ、見た目のみ非表示 */
html, body {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
    display: none;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 100vh;
    margin: 0;
}

.details-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    width: 100%;
}

.details-section {
    margin-top: 5px;
    width: 75%;
}

#detailsModal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    overflow-y: scroll;
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
    /* スクロールバー非表示設定 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */
    /* iOS Safari対応: 最小高さを確保 */
    min-height: 100dvh;
}

/* Webkit系ブラウザ（Chrome、Safari、Edge）のスクロールバー非表示 */
#detailsModal::-webkit-scrollbar {
    display: none;
}

/* モーダルコンテンツのスクロールバー非表示 */
.modal-content {
    background-color: transparent;
    padding: 30px;
    border-radius: 0;
    width: 90%;
    max-width: 800px;
    text-align: center;
    position: relative;
    box-shadow: none;
    margin: 20px auto 40px;
    /* 高さ設定を修正 - 固定値ではなく、コンテンツに応じて調整 */
    min-height: auto;
    max-height: 90vh;
    padding-bottom: 60px;
    /* スクロールバー非表示設定 */
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* iOS Safari対応: コンテンツが潰れないようにする */
    box-sizing: border-box;
    /* レイアウト重複防止 */
    display: flex;
    flex-direction: column;
    align-items: center;
    /* スクロール設定 */
    overflow-y: auto;
    overflow-x: hidden;
}

.modal-content::-webkit-scrollbar {
    display: none;
}

.modal-header {
    width: 100%;
    margin-bottom: 20px;
    position: relative;
}

.modal-header h1 {
    text-align: center;
    margin: 0;
    font-size: 24px;
    line-height: 1.4;
}

/* モーダル左上のXボタンスタイル */
.close-button {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    z-index: 1002;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.close-icon {
    font-size: 24px;
    color: #666;
    font-weight: bold;
    transition: all 0.3s ease;
    line-height: 1;
}

.close-button:hover {
    background-color: #fff;
    border-color: #999;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.close-button:hover .close-icon {
    color: #333;
    transform: rotate(90deg);
}

.close-button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.details-button {
    cursor: pointer;
    border: 4px solid #3498db;
    border-radius: 12px;
    padding: 19.2px;
    width: 125%;
    transition: background-color 0.3s ease;
    overflow-y: hidden;
    display: flex;
    align-items: flex-start;
}

.details-button:hover {
    background-color: #3498db;
    color: #fff;
}

.details-button img {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    margin-right: 14.4px;
    transition: transform 0.3s ease;
}

.details-button:hover img {
    transform: scale(1.2);
}

.initial-info {
    text-align: left;
}

.initial-info p {
    margin: 9.6px 0;
    font-size: 23.04px;
}

.back-button,
.button-link {
    cursor: pointer;
    border: 6px solid #3498db; /* 4px → 6px (1.5倍) */
    border-radius: 18px; /* 12px → 18px (1.5倍) */
    padding: 28.8px; /* 19.2px → 28.8px (1.5倍) */
    transition: background-color 0.3s ease;
    font-size: 34.56px; /* 23.04px → 34.56px (1.5倍) */
    /* レスポンシブ対応の強化 */
    flex: 1;
    min-width: 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
}

.back-button:hover,
.button-link:hover {
    background-color: #3498db;
    color: #fff;
}

.info-box {
    background-color: #f0f0f0;
    padding: 19.2px;
    border-radius: 5px;
    margin-top: 19.2px;
}

.button-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 19.2px;
    gap: 15px;
    /* レイアウト重複防止 */
    position: relative;
    z-index: 10;
    clear: both;
    /* レスポンシブ対応の強化 */
    flex-wrap: nowrap;
    box-sizing: border-box;
}

.details-content {
    display: block; /* モーダル内では表示する */
    margin-top: 19.2px;
    width: 100%;
    white-space: normal; /* テキストの折り返しを許可 */
    overflow-x: visible; /* 横スクロールを無効化 */
    overflow-y: visible; /* 縦スクロールを無効化 */
    /* スクロールバー非表示設定 */
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* スタイルの優先順位を明確化 */
    position: relative;
    z-index: 1;
    /* スクロール動作の最適化 */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: y proximity;
    /* iOS Safari対応: 最小高さを確保してコンテンツが潰れないようにする */
    box-sizing: border-box;
    /* レイアウト重複防止 */
    clear: both;
}

.details-content::-webkit-scrollbar {
    display: none;
}

.details-content img {
    width: 100%;
    height: auto;
    border-radius: 5px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: transform 0.3s ease;
    /* スタイルの優先順位を設定 */
    position: relative;
    z-index: 1;
}

/* P要素のスタイルを明確化 */
.details-content p {
    margin: 10px 0;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 16px;
    line-height: 1.6;
    color: #333;
    /* スタイルの優先順位を高く設定 */
    position: relative;
    z-index: 2;
    /* テキストの折り返しを確実に有効化 */
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 備考セクションのスタイルを明確化 */
.details-content h2 {
    margin: 20px 0 10px 0;
    padding: 10px 0;
    border-bottom: 2px solid #007bff;
    color: #007bff;
    font-size: 18px;
    /* スタイルの優先順位を高く設定 */
    position: relative;
    z-index: 2;
    /* テキストの折り返しを確実に有効化 */
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.details-content img:hover {
    transform: scale(1.2);
}

 /* 画像の読み込み最適化 */
.modal-image {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 遅延読み込み用のプレースホルダー */
img[loading="lazy"] {
    background: #f0f0f0;
    transition: opacity 0.3s ease-in-out;
}

/* 画像読み込み中の表示 */
.image-loading {
    opacity: 0.7;
}

/* 画像読み込み完了後の表示 */
.image-loaded {
    opacity: 1;
}


/* 730pxから600pxの間で横並びを強制 */
@media only screen and (max-width: 730px) and (min-width: 601px) {
    .button-container {
        flex-direction: row !important; /* 横並びを強制 */
        gap: 0; /* 間隔をなくす */
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap !important;
    }
    
    .back-button,
    .button-link {
        flex: 1 !important; /* 均等に幅を取る */
        min-width: 0;
        padding: 20px 16px; /* 適切なサイズ */
        font-size: 18px; /* 適切なフォントサイズ */
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border-radius: 12px; /* 角丸を復活 */
    }
}

@media only screen and (max-width: 600px) {
    .details-button {
        border-width: 2px;
        padding: 9.6px;
        width: 131%;
        box-sizing: border-box;
    }

    .details-button img {
        width: 120px;
        height: 120px;
    }

    .initial-info p {
        font-size: 14.4px;
    }
    
    /* モバイル用スタイル */
    .modal-content {
        width: 95%;
        padding: 30px 15px;
        margin: 10px auto 30px;
        min-height: calc(100vh - 60px);
        padding-bottom: 15px;
    }

    .close-button {
        width: 32px;
        height: 32px;
        top: 10px;
        left: 10px;
    }

    #detailsModal {
        padding: 10px;
    }

    .button-container {
        margin-top: 20px;
        padding-bottom: 20px;
        /* 小さい画面でのボタンレイアウト修正 */
        flex-direction: row !important; /* 横並びを強制 */
        justify-content: space-between;
        align-items: center;
        gap: 0; /* 間隔をなくす */
        flex-wrap: nowrap !important;
    }
    
    /* 小さい画面でのボタンサイズ調整 */
    .back-button,
    .button-link {
        flex: 1 !important; /* 均等に幅を取る */
        min-width: 0;
        padding: 18px 12px; /* 12px 8px → 18px 12px (1.5倍) */
        font-size: 21px; /* 14px → 21px (1.5倍) */
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border-radius: 12px; /* 角丸を復活 */
    }
    
    .close-icon {
        font-size: 20px;
    }
    
    .modal-content {
        padding: 15px;
        width: 90%;
    }

    .modal-header h1 {
        font-size: 20px;
        padding: 5px 0;
    }
}

/* 極小画面対応（400px以下） */
@media only screen and (max-width: 400px) {
    .button-container {
        flex-direction: row !important; /* 横並びを強制 */
        gap: 6px; /* 間隔を少し狭める */
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap !important;
    }
    
    .back-button,
    .button-link {
        flex: 1 !important; /* 均等に幅を取る */
        min-width: 0;
        padding: 12px 6px; /* 8px 4px → 12px 6px (1.5倍) */
        font-size: 18px; /* 12px → 18px (1.5倍) */
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border-radius: 10px; /* 角丸を復活 */
    }
    
    /* 単一ボタン時の中央配置 */
    .button-container:has(.back-button:only-child),
    .button-container:has(.button-link:only-child) {
        align-items: center;
        justify-content: center;
    }
    
    .button-container:has(.back-button:only-child) .back-button,
    .button-container:has(.button-link:only-child) .button-link {
        width: 80%;
        max-width: 180px;
    }
    
    /* フォールバック: 古いブラウザ対応 */
    .button-container.single-button {
        align-items: center;
        justify-content: center;
    }
    
    .button-container.single-button .back-button,
    .button-container.single-button .button-link {
        width: 80%;
        max-width: 180px;
    }
    
    .modal-content {
        width: 98%;
        padding: 10px;
    }
    
    .modal-header h1 {
        font-size: 18px;
    }
}

/* 400pxから430pxの間で横並びを強制 */
@media only screen and (max-width: 430px) and (min-width: 401px) {
    .button-container {
        flex-direction: row !important; /* 横並びを強制 */
        gap: 5px; /* 適切な間隔 */
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap !important;
    }
    
    .back-button,
    .button-link {
        flex: 1 !important; /* 均等に幅を取る */
        min-width: 0;
        padding: 11px 5px; /* 適切なサイズ */
        font-size: 17px; /* 適切なフォントサイズ */
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border-radius: 10px; /* 角丸を復活 */
    }
}

/* 超極小画面対応（340px以下） */
@media only screen and (max-width: 340px) {
    .button-container {
        flex-direction: row !important; /* 横並びを強制 */
        gap: 4px; /* 間隔をさらに狭める */
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap !important;
    }
    
    .back-button,
    .button-link {
        flex: 1 !important; /* 均等に幅を取る */
        min-width: 0;
        padding: 10px 4px; /* さらに小さく調整 */
        font-size: 16px; /* フォントサイズを調整 */
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border-radius: 8px; /* 角丸を復活 */
    }
    
    .modal-content {
        width: 99%;
        padding: 8px;
    }
    
    .modal-header h1 {
        font-size: 16px;
    }
}

/* 亀の状態表示スタイル */
.turtle-status {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    color: white;
    text-align: center;
    min-width: 60px;
}

.status-available {
    background-color: #28a745; /* 緑色 - 里親募集 */
}

.status-decided {
    background-color: #007bff; /* 青色 - 里親決定 */
    color: white; /* 青色背景では白文字の方が見やすい */
}

.status-completed {
    background-color: #6c757d; /* グレー - 譲渡済み */
}

.status-ended {
    background-color: #6c757d; /* グレー - 掲載終了（赤色から変更） */
}

.status-unknown {
    background-color: #6f42c1; /* 紫色 - 状態不明 */
}

/* 画像ギャラリーのスタイル */
.image-gallery {
    margin: 20px 0;
    text-align: center;
    position: relative;
    z-index: 5; /* 適切なz-indexを設定 */
    /* レイアウト重複防止 */
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.main-image-container {
    margin-bottom: 15px;
    position: relative;
    width: min(85vw, 90vh, 500px);
    height: min(85vw, 90vh, 500px);
    margin: 0 auto 15px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    border-radius: 8px;
    overflow: hidden;
    box-sizing: border-box;
}

.main-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    /* スムーズな切り替えのためのトランジション */
    transition: opacity 0.15s ease;
    touch-action: pan-y; /* 縦スクロールは許可、横スワイプを制御 */
    /* 画像切り替え時の白い反転を防ぐ */
    backface-visibility: hidden;
    /* GPU加速（必要最小限に制限） */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: opacity;
    -webkit-backface-visibility: hidden;
    position: absolute;
    top: 0;
    left: 0;
    /* 画像品質最適化（統一された設定） */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    /* GPU合成レイヤーの最適化 */
    contain: layout style paint;
    /* 3D変換の最適化 */
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    /* 画像の鮮明さを保持 */
    filter: contrast(1.02) brightness(1.01);
    /* アンチエイリアシング最適化 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.main-image:hover {
    transform: scale(1.02);
}

/* Canvas用のスタイル（Double Buffering対応） */
#mainCanvas {
    display: none; /* 一時的にCanvasを無効化 */
    z-index: 20;
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    background-color: #000000;
    /* 高品質レンダリング設定 */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: -moz-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    /* アンチエイリアシング最適化 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Canvas特有の最適化 */
    image-rendering: high-quality;
    image-rendering: smooth;
    /* 確実な表示 */
    opacity: 1;
    visibility: visible;
}

#bufferCanvas {
    display: none; /* バッファCanvasは非表示 */
    z-index: 1;
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    /* 同じ品質設定をバッファにも適用 */
    image-rendering: high-quality;
    image-rendering: smooth;
}

.fallback-image {
    z-index: 50 !important; /* 最前面に表示 */
    display: block !important; 
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    background-color: #808080; /* 灰色背景 */
}

.buffer-canvas {
    position: absolute !important;
    top: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
}

.sub-images-container {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    margin: 0 auto;
    padding: 5px 0;
    position: relative;
    z-index: 5; /* メイン画像より低いz-index */
    /* スクロールバー非表示設定 */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sub-images-container::-webkit-scrollbar {
    display: none;
}

.sub-image {
    width: 55px;
    height: 55px;
    min-width: 55px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    /* 軽量化されたトランジション */
    transition: border-color 0.15s ease, opacity 0.15s ease;
    opacity: 0.7;
    flex-shrink: 0;
    position: relative;
    z-index: 5; /* メイン画像より低いz-index */
    background-color: #f0f0f0;
    background-image: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: sub-loading 1.5s infinite;
    /* 高品質画像表示のための設定 */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    /* 画像の鮮明さを保持 */
    filter: contrast(1.01) brightness(1.01);
    /* アンチエイリアシング最適化 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.sub-image[src] {
    background-image: none;
    animation: none;
}

@keyframes sub-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.sub-image:hover {
    opacity: 1;
    transform: scale(1.1);
}

.sub-image.active {
    border-color: #007bff;
    opacity: 1;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.3);
}

/* 画像ギャラリーのモバイル対応 */
@media only screen and (max-width: 600px) {
    .main-image-container {
        height: 250px;
    }
    
    .sub-image {
        width: 45px;
        height: 45px;
        min-width: 45px;
    }
    
    .sub-images-container {
        gap: 6px;
        padding: 5px 10px;
    }
}

/* 画像読み込み最適化のスタイル - ちらつき防止強化 */
.image-gallery img {
    opacity: 1;
    transition: opacity 0.1s ease-out; /* 極短時間のスムーズなopacity変更 */
    visibility: visible !important;
    backface-visibility: hidden; /* GPU加速でちらつき防止 */
    transform: translateZ(0); /* ハードウェア加速を有効化 */
    will-change: auto;
    /* 統一された高品質画像レンダリング設定 */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    /* 画像の鮮明さを保持 */
    filter: contrast(1.01) brightness(1.01);
    /* アンチエイリアシング最適化 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* メイン画像専用の最適化 */
.fallback-image {
    transition: opacity 0.05s ease-out !important; /* より高速なopacity変更 */
}

/* メイン画像コンテナのクリーンなスタイル */
.main-image-container {
    background-color: #f5f5f5; /* 落ち着いた灰色背景 */
}

.image-gallery img.image-loaded {
    opacity: 1;
}

/* 画像読み込み中のプレースホルダー（画像が読み込まれていない場合のみ表示） */
.main-image:not([src]), .main-image[src=""] {
    position: relative;
}

.main-image:not([src])::before, .main-image[src=""]::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 10px;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 画像読み込み完了時のスムーズ表示 */
.main-image-container {
    position: relative;
}

.main-image {
    position: absolute;
    z-index: 1;
}

/* モバイル用レスポンシブ対応 - 1:1比率維持 */
@media (max-width: 600px) {
    .main-image-container {
        width: min(95vw, 95vh, 400px);
        height: min(95vw, 95vh, 400px);
        margin: 0 auto 10px;
    }
}

/* 極小画面対応 */
@media (max-width: 400px) {
    .main-image-container {
        width: min(98vw, 98vh, 350px);
        height: min(98vw, 98vh, 350px);
        margin: 0 auto 5px;
    }
}

/* 統一された画像設定 */
.primary-image {
    display: block;
    max-width: 100%;
    height: auto;
    object-fit: cover;
    aspect-ratio: 1;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    filter: contrast(1.02) brightness(1.01);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
}

/* サブ画像ピクチャー要素 */
.sub-image-picture {
    width: 55px;
    height: 55px;
    min-width: 55px;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.sub-image-picture img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    opacity: 0.7;
    background-color: #f0f0f0;
}

.sub-image-picture:hover img {
    opacity: 1;
    transform: scale(1.1);
}

.sub-image-picture img.active {
    border-color: #007bff;
    opacity: 1;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.3);
}

/* レスポンシブ対応 */
@media only screen and (max-width: 600px) {
    .sub-image-picture {
        width: 45px;
        height: 45px;
        min-width: 45px;
    }
}

@media (max-width: 400px) {
    .sub-image-picture {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
}

/* 統一されたデザイン設定 */
.main-image,
.sub-image,
.primary-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
}

/* スクロール最適化 */
.modal-content {
    overflow-x: hidden;
    overscroll-behavior-x: none;
    -webkit-overflow-scrolling: touch;
}

/* アニメーション最適化 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 画像プリロード最適化 */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* クリティカルパス最適化 */
.primary-image {
    display: block;
    opacity: 1;
    visibility: visible;
}

/* メモリ最適化 */
img[data-cleanup="true"] {
    will-change: auto;
}

.image-quality-medium {
    image-rendering: -webkit-optimize-contrast;
}

.image-quality-low {
    image-rendering: pixelated;
}



/* 統一されたパフォーマンス設定 */
.main-image,
.sub-image {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* スクロール最適化 */
.modal-content {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;

}



/* 画像品質向上のための統一設定 */
.main-image,
.sub-image,
.fallback-image,
.details-button img {
    /* 高品質画像レンダリング（統一設定） */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    
    /* スムーズなスケーリング */
    transform-origin: center center;
    
    /* アンチエイリアシング最適化 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* 画像の鮮明さを保持 */
    filter: contrast(1.02) brightness(1.01);
    
    /* GPU加速最適化 */
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
}

/* 高解像度ディスプレイ対応（強制適用） */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .main-image,
    .sub-image,
    .fallback-image,
    .image-gallery img,
    .details-button img,
    .modal-image,
    .neural-progressive,
    .primary-image {
        /* 高解像度ディスプレイ用の最適化（強制適用） */
        image-rendering: -webkit-optimize-contrast !important;
        image-rendering: crisp-edges !important;
        image-rendering: auto !important;
        /* より鮮明な表示 */
        filter: contrast(1.03) brightness(1.02) !important;
        /* 高解像度用の強制設定 */
        -webkit-image-rendering: -webkit-optimize-contrast !important;
        -moz-image-rendering: crisp-edges !important;
        -o-image-rendering: crisp-edges !important;
    }
}

/* 超高解像度ディスプレイ対応（4K、5Kなど） */
@media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 288dpi) {
    .main-image,
    .sub-image,
    .fallback-image,
    .image-gallery img,
    .details-button img,
    .modal-image,
    .neural-progressive,
    .primary-image {
        /* 超高解像度用の最適化（強制適用） */
        image-rendering: crisp-edges !important;
        filter: contrast(1.05) brightness(1.03) !important;
        /* 超高解像度用の強制設定 */
        -webkit-image-rendering: crisp-edges !important;
        -moz-image-rendering: crisp-edges !important;
        -o-image-rendering: crisp-edges !important;
    }
}

/* 画像ホバー時の品質保持 */
.main-image:hover,
.sub-image:hover,
.details-button:hover img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    filter: contrast(1.05) brightness(1.02);
}

/* 画像ギャラリー全体の品質設定 */
.image-gallery img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
}

/* メイン画像の高品質表示設定 */
.main-image,
.details-button img,
.modal-image {
    /* 高品質画像レンダリング（統一設定） */
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
    image-rendering: auto !important;
    image-rendering: high-quality !important;
    
    /* 画像の鮮明さを保持 */
    filter: contrast(1.02) brightness(1.01) !important;
    
    /* スムーズなスケーリング */
    transform-origin: center center;
    
    /* アンチエイリアシング最適化 */
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    
    /* GPU加速最適化 */
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
    
    /* 画像品質の強制適用 */
    -webkit-image-rendering: -webkit-optimize-contrast !important;
    -moz-image-rendering: crisp-edges !important;
    -o-image-rendering: crisp-edges !important;
}

/* スクロール動作の最適化（重複を削除） */
#detailsModal,
.modal-content,
.sub-images-container {
    /* スムーズスクロール */
    scroll-behavior: smooth;
    /* タッチデバイスでのスクロール最適化 */
    -webkit-overflow-scrolling: touch;
    /* スクロールスナップ */
    scroll-snap-type: y proximity;
}

/* スクロール可能要素のホバー時の視覚的フィードバック（重複を削除） */
#detailsModal:hover,
.modal-content:hover,
.sub-images-container:hover {
    /* ホバー時の微細な影効果 */
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}

/* モーダル表示の軽微な最適化 */
#detailsModal {
    /* 既存のスタイルを保持しつつ、軽微な最適化を追加 */
    will-change: opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 画像ギャラリーの軽微な最適化 */
.image-gallery {
    /* 既存のスタイルを保持しつつ、軽微な最適化を追加 */
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* メイン画像の軽微な最適化 */
.main-image {
    /* 既存のスタイルを保持しつつ、軽微な最適化を追加 */
    will-change: opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* サブ画像の軽微な最適化 */
.sub-image {
    /* 既存のスタイルを保持しつつ、軽微な最適化を追加 */
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* モーダル表示アニメーションの軽微な最適化 */
#detailsModal[style*="display: block"] {
    animation: modalFadeIn 0.15s ease-out;
}

@keyframes modalFadeIn {
    0% {
        opacity: 0;
        transform: scale(0.98);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* 画像切り替えアニメーションの軽微な最適化 */
.main-image {
    transition: opacity 0.1s ease-out !important;
}

/* タッチレスポンスの軽微な最適化 */
.details-button {
    /* 既存のスタイルを保持しつつ、軽微な最適化を追加 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* スクロールパフォーマンスの軽微な最適化（重複を削除） */
#detailsModal,
.modal-content,
.sub-images-container {
    /* 既存のスタイルを保持しつつ、軽微な最適化を追加 */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* 統一されたデザイン設定 */
.main-image,
.sub-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    filter: contrast(1.02) brightness(1.01);
    transition: all 0.2s ease;
}

.details-button {
    transition: all 0.2s ease;
}

.details-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.details-button:hover img {
    transform: scale(1.1);
}

.sub-image:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* モーダルコンテンツの基本レイアウト */
.modal-content {
    background-color: transparent;
    padding: 30px;
    border-radius: 0;
    width: 90%;
    max-width: 800px;
    text-align: center;
    position: relative;
    box-shadow: none;
    margin: 20px auto 40px;
    min-height: calc(100vh - 80px);
    padding-bottom: 60px;
}

/* 画像ギャラリーの基本レイアウト */
.image-gallery {
    margin: 20px 0;
    text-align: center;
    position: relative;
    z-index: 5;
}

/* メイン画像コンテナの基本レイアウト */
.main-image-container {
    margin-bottom: 15px;
    position: relative;
    width: min(85vw, 90vh, 500px);
    height: min(85vw, 90vh, 500px);
    margin: 0 auto 15px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    border-radius: 8px;
    overflow: hidden;
    box-sizing: border-box;
}

/* サブ画像コンテナの基本レイアウト */
.sub-images-container {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    margin: 0 auto;
    padding: 5px 0;
    position: relative;
    z-index: 5;
}

/* レスポンシブ対応 */
@media (max-width: 600px) {
    .main-image-container {
        width: min(95vw, 95vh, 400px);
        height: min(95vw, 95vh, 400px);
        margin: 0 auto 10px;
    }
    
    .sub-image {
        width: 45px;
        height: 45px;
        min-width: 45px;
    }
    
    /* レスポンシブでも常に横並びを維持 */
    .details-container {
        flex-direction: row !important;
    }
}

/* 極小画面対応 */
@media (max-width: 400px) {
    .main-image-container {
        width: min(98vw, 98vh, 350px);
        height: min(98vw, 98vh, 350px);
        margin: 0 auto 5px;
    }
    
    .sub-image {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    
    /* 極小画面でも常に横並びを維持 */
    .details-container {
        flex-direction: row !important;
    }
}

/* 画像表示の修正 - 切れる問題の解決 */

/* メイン画像コンテナの修正 */
.main-image-container {
    margin-bottom: 15px;
    position: relative;
    /* 高さ制限を緩和し、アスペクト比を考慮 */
    width: min(85vw, 600px);
    height: min(85vw, 600px);
    max-height: 70vh; /* ビューポート高さの70%まで */
    margin: 0 auto 15px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f0f0;
    border-radius: 8px;
    overflow: hidden;
    box-sizing: border-box;
}

/* メイン画像の修正 */
.main-image {
    width: 100%;
    height: 100%;
    /* object-fitをcontainに変更して画像全体を表示 */
    object-fit: contain;
    /* または、coverを使用する場合はpositionを調整 */
    /* object-fit: cover; */
    /* object-position: center; */
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    /* スムーズな切り替えのためのトランジション */
    transition: opacity 0.15s ease;
    touch-action: pan-y;
    /* 画像切り替え時の白い反転を防ぐ */
    backface-visibility: hidden;
    /* GPU加速（必要最小限に制限） */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: opacity;
    -webkit-backface-visibility: hidden;
    position: relative;
    /* 画像品質最適化（統一された設定） */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: auto;
    image-rendering: high-quality;
    /* GPU合成レイヤーの最適化 */
    contain: layout style paint;
    /* 3D変換の最適化 */
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    /* 画像の鮮明さを保持 */
    filter: contrast(1.02) brightness(1.01);
    /* アンチエイリアシング最適化 */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* レスポンシブ対応の修正 */
@media (max-width: 600px) {
    .main-image-container {
        width: min(95vw, 400px);
        height: min(95vw, 400px);
        max-height: 60vh; /* モバイルでは60%まで */
        margin: 0 auto 10px;
    }
}

@media (max-width: 400px) {
    .main-image-container {
        width: min(98vw, 350px);
        height: min(98vw, 350px);
        max-height: 55vh; /* 極小画面では55%まで */
        margin: 0 auto 5px;
    }
}

/* 高さが制限される場合の代替設定 */
@media (max-height: 600px) {
    .main-image-container {
        height: min(70vh, 400px);
        width: min(70vh, 400px);
    }
}

@media (max-height: 500px) {
    .main-image-container {
        height: min(60vh, 300px);
        width: min(60vh, 300px);
    }
}

/* 画像が切れる場合の代替表示オプション */
.main-image.full-image {
    object-fit: contain;
    background-color: #f8f8f8;
}

.main-image.cropped-image {
    object-fit: cover;
    object-position: center;
}

/* 画像表示モード切り替え用のクラス */
.image-display-mode-contain .main-image {
    object-fit: contain;
}

.image-display-mode-cover .main-image {
    object-fit: cover;
    object-position: center;
}

/* 画像のアスペクト比を保持する設定 */
.main-image.aspect-ratio-preserved {
    object-fit: contain;
    background-color: #f0f0f0;
}



/* 画像が切れる場合の警告表示 */
.image-crop-warning {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 193, 7, 0.9);
    color: #000;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    z-index: 10;
    display: none;
}

.image-crop-warning.show {
    display: block;
}