body {
    font-family: sans-serif;
    margin: 0;
}

body.modal-open {
    overflow: hidden;
}

header {
    background-color: #f8f9fa;
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid #dee2e6;
}

#search-box {
    width: 80%;
    max-width: 500px;
    padding: 0.5rem;
    font-size: 1rem;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
}

#content-area {
    padding: 1rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.card {
    border: 1px solid #dee2e6;
    border-radius: 0.25rem;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.card-content {
    padding: 1rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: bold;
    margin: 0 0 0.5rem 0;
}

.card-date {
    color: #6c757d;
    font-size: 0.875rem;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-sizing: border-box; /* はみ出し防止 */
    position: relative; /* 閉じるボタンの基準点 */
}

.close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2; /* 他要素より手前に */
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
}

/* --- ★★★ モーダル内レイアウト用のスタイル ★★★ --- */
#modal-body {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden; /* 二重スクロールバー防止 */
}

.modal-header {
    flex-shrink: 0; /* ヘッダーが縮まないようにする */
    padding-bottom: 1rem;
    border-bottom: 1px solid #dee2e6;
    padding-right: 30px; /* 閉じるボタンとの重なり回避 */
}

.modal-scroll-container {
    flex-grow: 1; /* 残りのスペースをすべて使う */
    overflow-y: auto; /* 内容が多い場合にスクロール */
    padding-top: 1rem;
}
/* --- ここまで --- */


.modal-gallery {
    display: none; /* 初期状態では非表示 */
    position: relative;
    width: 100%;
    max-width: 600px; /* 画像の最大幅 */
    margin: 0 auto 20px; /* 中央揃えと下に余白 */
    align-items: center;
    justify-content: center;
}

#modal-image {
    width: 100%;
    height: auto;
    max-height: 35vh; /* ビューポートの高さの35%を最大値に */
    object-fit: contain; /* アスペクト比を保ってコンテナに収める */
    border-radius: 4px;
}

.prev-button, .next-button {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    cursor: pointer;
    padding: 16px;
    font-size: 20px;
    border-radius: 50%;
    user-select: none; /* テキスト選択を防ぐ */
    z-index: 2;
}

.prev-button {
    left: 10px;
}

.next-button {
    right: 10px;
}

.prev-button:hover, .next-button:hover {
    background-color: rgba(0, 0, 0, 0.8);
}


.modal-meta-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

#modal-body h2 {
    font-size: 1.25rem;
    margin-top: 0;
    margin-bottom: 0; /* h2のデフォルトマージンをリセット */
}

.modal-link-button {
    display: inline-block;
    padding: 8px 12px;
    background-color: #007bff;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.9rem;
    white-space: nowrap; /* ボタンテキストが改行しないように */
    margin-left: 15px; /* タイトルとの間に余白 */
}

.modal-link-button:hover {
    background-color: #0056b3;
}

#modal-body p {
    margin-bottom: 1em;
}

#initial-message {
    text-align: center;
    color: #6c757d;
}

mark {
    background-color: yellow;
    padding: 0.2em;
}

@media (max-width: 600px) {
    .grid {
        grid-template-columns: 1fr;
    }
    .modal-content {
        margin: 5% auto;
        width: 95%;
        max-height: 90vh;
    }
}
