/* 基本的なスタイルリセットと設定 */
:root {
    /* ルート要素に変数を定義（フォントサイズ調整用） */
    --base-font-size: 1rem;
    /* 16px相当 */
    --small-font-size: 0.875rem;
    /* 14px相当 */
}

html {
    /* clamp() を使ってウィンドウ幅に応じてフォントサイズを滑らかに変化させる */
    /* 最小14px、推奨 1.8vw (ビューポート幅の1.8%)、最大18px */
    font-size: clamp(var(--small-font-size), 1.8vw, 1.125rem);
}

body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    /* box-sizing: border-box; は * {} に適用する方が一般的 */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    line-height: 1.6;
    /* 行間を少し広げる */
    color: #333;
    /* 基本の文字色 */
}

/* 全要素に適用 */
*,
*::before,
*::after {
    box-sizing: border-box;
}


/* リンクの基本スタイル */
a {
    color: #007bff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- ヘッダーのスタイル (デフォルト: PC) --- */
header {
    background-color: pink;
    padding: 15px 30px;
    display: grid;
    /* 中央(タイトルリンク) | 右(検索+ログアウト) */
    grid-template-columns: 1fr auto; /* タイトルが中央に来るように調整 */
    align-items: center;
    gap: 20px;
}

/* ヘッダータイトル（元h1）のスタイル */
header .header-title {
    grid-column: 1 / 2;
    /* 1列目に配置 */
    justify-self: center;
    /* 中央に配置 */
    font-size: 1.8em;
    /* 少し大きめの文字サイズ */
    font-weight: bold;
    color: #333;
    /* リンク色を上書き */
    text-decoration: none;
    /* 下線を消す */
    margin: 0;
    /* 不要なマージンを削除 */
}

header .header-title:hover {
    text-decoration: none;
    /* ホバー時も下線なし */
    opacity: 0.8;
    /* 少し透明にする */
}

/* 検索とログアウトボタンをまとめるコンテナ (PC用) */
.header-right-group {
    grid-column: 2 / 3;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 15px; /* 検索とログアウトボタンの間隔 */
}

header .search {
    /* grid-column, justify-self は .header-right-group に移動 */
    max-width: 300px;
    /* 最大幅を少し調整 */
    width: 100%;
}

header .search form {
    display: flex;
    width: 100%;
}

header .search input[type="text"] {
    flex-grow: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px 0 0 4px;
    border-right: none;
    font-size: 0.9rem;
    /* フォントサイズ調整 */
}

header .search button {
    padding: 8px 15px;
    border: 1px solid #ccc;
    background-color: #f0f0f0;
    cursor: pointer;
    border-radius: 0 4px 4px 0;
    font-size: 0.9rem;
    /* フォントサイズ調整 */
}

/* ログアウトボタンの基本スタイル */
#logout-button {
    padding: 8px 15px;
    background-color: #dc3545; /* 少し目立つ色 */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}
#logout-button:hover {
    background-color: #c82333;
}


/* メインコンテンツのスタイル */
main {
    padding: 20px;
    flex-grow: 1;
}

main h2 {
    text-align: center;
    background-color: pink;
    padding: 15px;
    margin-top: 30px;
    margin-bottom: 30px;
    border-radius: 5px;
    font-size: 1.5em;
    /* 見出しのサイズ調整 */
}

/* ディレクトリ一覧のスタイル */
.directory-list {
    display: grid;
    gap: 15px;
    /* ★★★ デフォルト (モバイル) を1列表示に変更 ★★★ */
    grid-template-columns: 1fr;
}

/* ディレクトリリンクのスタイル */
.directory-link {
    display: block;
    padding: 20px;
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
    color: #333;
    font-weight: bold;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.directory-link:hover {
    background-color: #eee;
    text-decoration: none;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
}


/* PC（画面幅が大きい場合）: ディレクトリ2列表示 */
@media (min-width: 768px) {
    .directory-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* フッターのスタイル */
footer {
    background-color: pink;
    padding: 20px;
    text-align: center;
    margin-top: 30px;
    font-size: 0.9em;
    color: #333;
}

footer p {
    margin: 8px 0;
}

footer a {
    color: #0056b3;
}

footer a:hover {
    color: #000;
}

/* 画像一覧のスタイル */
.image-list {
    display: grid;
    gap: 15px;
    /* ★★★ デフォルト (モバイル) を1列表示に変更 ★★★ */
    grid-template-columns: 1fr;
}

/* 少し大きい画面: 2列 */
@media (min-width: 576px) { /* ★ブレークポイント調整 (例) */
    .image-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* PC画面: 3列 */
@media (min-width: 768px) {
    .image-list {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* さらに大きい画面: 4列 */
@media (min-width: 1024px) {
    .image-list {
        grid-template-columns: repeat(4, 1fr);
    }
}

.image-item img {
    cursor: pointer; /* クリック可能を示す */
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}
.image-item img:hover {
    transform: scale(1.03);
}

/* 画像読み込み失敗時のスタイル */
.image-item.error {
    border: 1px dashed red;
    color: red;
    padding: 10px;
    text-align: center;
    font-size: 0.8em;
    word-break: break-all;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- ログイン画面のスタイル --- */
#login-section {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.login-header {
    background-color: pink;
    padding: 15px 30px;
    text-align: center;
    color: #333;
}

.login-header h1 {
    margin: 0;
    font-size: 1.8em;
}

.login-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

#login-form {
    width: 100%;
    max-width: 400px;
    padding: 30px;
    background-color: #f9f9f9;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#login-form div {
    margin-bottom: 20px;
}

#login-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

#login-form input[type="text"],
#login-form input[type="password"] {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#login-form input[type="text"]:focus,
#login-form input[type="password"]:focus {
    outline: none;
    border-color: pink;
    box-shadow: 0 0 0 3px rgba(255, 192, 203, 0.3);
}

.login-button {
    width: 100%;
    padding: 12px 15px;
    background-color: pink;
    color: #333;
    border: none;
    border-radius: 4px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.login-button:hover {
    background-color: #f8b0c0;
}
.login-button:active {
    transform: scale(0.98);
}

#login-error {
    margin-top: 15px;
    text-align: center;
}

/* --- ライトボックスのスタイル --- */
.lightbox {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lightbox.show {
    opacity: 1;
    visibility: visible;
}

.lightbox-content {
    display: block;
    margin: auto;
    max-width: 90%;
    max-height: 85vh;
    animation: lightboxZoom 0.3s ease;
}

@keyframes lightboxZoom {
    from {transform: scale(0.8);}
    to {transform: scale(1);}
}

.lightbox-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.lightbox-close:hover,
.lightbox-close:focus {
    color: #bbb;
    text-decoration: none;
}

.lightbox-prev,
.lightbox-next {
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    padding: 16px;
    margin-top: -50px;
    color: white;
    font-weight: bold;
    font-size: 30px;
    transition: 0.3s ease;
    border-radius: 0 3px 3px 0;
    user-select: none;
    background-color: rgba(0, 0, 0, 0.3);
}

.lightbox-next {
    right: 0;
    border-radius: 3px 0 0 3px;
}
.lightbox-prev {
    left: 0;
}

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

.lightbox-prev.disabled,
.lightbox-next.disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

/* ★★★ モバイル用ヘッダーレイアウト ★★★ */
@media (max-width: 767px) { /* 768px未満の画面幅で適用 */
    header {
        display: flex; /* Flexboxに変更 */
        flex-direction: column; /* 縦積みに変更 */
        align-items: center; /* 中央揃え */
        padding: 15px; /* パディング調整 */
        gap: 15px; /* 要素間のスペース */
    }

    header .header-title {
        /* grid関連の指定は不要になる */
        justify-self: initial; /* リセット */
        text-align: center; /* 中央揃え */
        order: 1; /* 表示順: 1番目 */
    }

    /* 検索とログアウトボタンをまとめるコンテナはモバイルでは不要 */
    .header-right-group {
        display: contents; /* コンテナ自体はレイアウトに影響させない */
    }

    header .search {
        /* grid関連の指定は不要になる */
        justify-self: initial; /* リセット */
        max-width: 100%; /* 幅を画面に合わせる */
        width: 90%; /* 少し左右に余白 */
        order: 2; /* 表示順: 2番目 */
    }

    #logout-button {
        margin-left: 0; /* PC用のマージンをリセット */
        width: auto; /* 幅を自動に */
        padding: 8px 20px; /* パディング調整 */
        order: 3; /* 表示順: 3番目 */
    }
}
