 /* ページ全体 */
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 20px;
        background-color: #f5f5f5;
    }

    .gallery{
        display:flex;
        flex-wrap:wrap;
        margin-left: 5px;
    }

    .gallery figure{
        margin:2px;
        width:280px; /* 画像240px + 枠 */
        text-align:center;
    }

    .gallery figcaption{
        margin-top:5px;
        margin-bottom:12px;
        font-size:15px;
        line-height:1.2;
    }
        
    /* ギャラリーには1枚目だけを表示 */
    .gallery img {
        width: 275px;
        height: 205px;
        object-fit: contain;
        background-color: #fff;
        cursor: pointer;
        border: 2px solid #ccc;
        border-radius: 5px;
        transition:
            transform 0.2s,
            border-color 0.2s;
    }

    .gallery img:hover {
        transform: scale(1.05);
        border-color: #666;
    }

    /* キーボード操作時のフォーカス表示 */
    .gallery img:focus {
        outline: 3px solid #0066cc;
        outline-offset: 3px;
    }

    /*ギャラリーの後の回り込み解除*/
    .gallery::after {
        content: "";
        display: block;
        clear: both;
    }

    /* モーダル背景 */
    .modal {
        display: none;
        position: fixed;
        z-index: 1000;
        inset: 0;
        width: 100%;
        height: 100%;
        overflow: auto;
        background-color: rgba(0, 0, 0, 0.7);
    }

    /* モーダル表示時 */
    .modal.show {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    /* モーダル本体 */
    .modal-content {
        box-sizing: border-box;
        width: 95%;
        max-width: 1600px;
        height: 95vh;

        padding: 10px;

        background-color: #fff;
        border-radius: 8px;
        text-align: center;

        display: flex;
        flex-direction: column;
    }

    /* ポップアップ内の画像領域 */
    .modal-images {
        flex: 1;

        overflow-y: auto;

        display: flex;
        justify-content: center;
        align-items: flex-start;
        gap: 10px;
    }

    /* 画像と個別説明をまとめる領域 */
    .modal-image-item {
        flex: 1 1 0;
        min-width: 0;
    }

    #modalImageItem1 {
        flex: 7;
    }

    #modalImageItem2 {
        flex: 3;
    }

    /*
      * 画像が1枚だけの場合にもう少し大きく表示する
      */
    .modal-images.single-image .modal-img {
        height: 76vh;
        max-width: 100%;
    }

    .modal-images.single-image .modal-image-item {
        max-width: 95%;
    }

    /* 非表示用 */
    .hidden {
        display: none;
    }

    /* ポップアップ画像 */
    .modal-img {
        display: block;
        width: 100%;
        max-width: 100%;
        height: 66vh;
        object-fit: contain;
        background-color: #f5f5f5;
        border-radius: 5px;
    }

    /* 各画像の説明 */
    .image-caption {
        white-space: pre-line;
        margin-top: 8px;
        font-size: 14px;
        color: #333;
    }

    /* 説明が空の場合は非表示 */
    .image-caption:empty {
        display: none;
    }

    /* 全体の解説テキスト */
    .caption {
        flex-shrink: 0;

        margin: 4px;
        font-size: 18px;
        color: #333;
        white-space: pre-wrap;
        font-weight: bold;
    }

    /* 全体説明が空の場合は非表示 */
    .caption:empty {
        display: none;
    }

    .modal-controls{
        flex-shrink: 0;

        position: relative;
        text-align: center;

        padding-top: 0px;
        margin-top: 0px;

        border-top: 1px solid #ddd;
        background: #fff;
    }

    #imageCounter{
        position: absolute;
        left: 10px;
        top: 80%;

        transform: translateY(-50%);

        color: #888;
        font-size: 0.85em;
    }

    /* モーダル部分のボタン */
    .modal-btn {
        display: inline-block;
        margin-top: 10px;
        padding: 10px 25px;
        border: none;
        border-radius: 5px;
        background-color: #333;
        color: #fff;
        font-size: 16px;
        cursor: pointer;
    }

    .modal-btn:hover {
        background-color: #555;
    }

    .modal-btn:focus {
        outline: 3px solid #0066cc;
        outline-offset: 3px;
    }

    /*
      * 画面幅が狭い場合は、
      * ポップアップ画像を縦並びにする
      */
    @media screen and (max-width: 900px) {
        .modal {
            align-items: flex-start;
        }

        .modal-content {
            margin: 20px auto;
            max-height: none;
        }

        .modal-images {
            flex-direction: column;
            align-items: stretch;
        }

        .modal-images.single-image .modal-image-item {
            width: 100%;
            max-width: none;
        }

        .modal-img {
            height: auto;
            max-height: 60vh;
        }
    }