/* ギャラリーページ */
.gallery-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #111;
    color: #e5e5e5;
}

/* 1行目: ヘッダー */
.gallery-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: #1a1a1a;
    border-bottom: 1px solid #333;
}

.gallery-title {
    font-size: 1rem;
    font-weight: 400;
    margin: 0;
    color: #ccc;
    flex-shrink: 0;
    white-space: nowrap;
}

.gallery-title-link {
    color: inherit;
    text-decoration: none;
}

.gallery-title-link:hover {
    color: #fff;
}

/* ヘッダー内ラベル（タグ名・撮影月名） */
.gallery-header-label {
    display: flex;
    align-items: center;
    color: #888;
    font-size: 1rem;
    min-width: 0;
    margin-left: 0.5rem;
}

.gallery-header-label::before {
    content: "「";
    flex-shrink: 0;
}

.gallery-header-label::after {
    content: "」";
    flex-shrink: 0;
}

.gallery-header-label-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.gallery-home-link {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-left: auto;
    color: #999;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 0.8125rem;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
    flex-shrink: 0;
}

.gallery-home-link:hover {
    color: #fff;
    border-color: #666;
    background-color: #333;
}

/* 2行目: タブ */
.gallery-tabs {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    background-color: #1a1a1a;
    border-bottom: 1px solid #333;
    padding: 0 1rem;
}

.gallery-back-btn {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 0.5rem 0.5rem 0.5rem 0;
    transition: color 0.2s;
}

.gallery-back-btn:hover {
    color: #fff;
}

.gallery-tab {
    background: none;
    border: none;
    color: #888;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.8125rem;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    white-space: nowrap;
}

.gallery-tab:hover {
    color: #ccc;
}

.gallery-tab.active {
    color: #fff;
    border-bottom-color: #fff;
}

/* ヘッダー内カウント（枚数） */
.gallery-header-count {
    flex-shrink: 0;
    color: #888;
    font-size: 0.8125rem;
    margin-left: 0.5rem;
    white-space: nowrap;
}

/* 3行目: フィルターバー */
.gallery-filter-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.375rem;
    padding: 0.3rem 1rem;
    background-color: #1a1a1a;
    border-bottom: 1px solid #333;
}

.gallery-filters {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-wrap: wrap;
    width: 100%;
}

.gallery-filter {
    position: relative;
}

.gallery-filter-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: none;
    border: 1px solid #444;
    color: #999;
    padding: 0.375rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.6875rem;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
    white-space: nowrap;
}

/* フィルター個別幅（モバイル） */
#gallery-filter-body,
#gallery-filter-lens { flex: 0 0 calc(50% - 0.1875rem); min-width: 0; }
#gallery-filter-body .gallery-filter-btn,
#gallery-filter-lens .gallery-filter-btn { width: 100%; overflow: hidden; }
#gallery-filter-fnumber .gallery-filter-btn { width: 3.5rem; }
#gallery-filter-ss .gallery-filter-btn,
#gallery-filter-iso .gallery-filter-btn { width: 4.5rem; }

/* PC: テキスト幅ベース・右寄せ */
@media (min-width: 768px) {
    .gallery-filters { justify-content: flex-end; }
    #gallery-filter-body,
    #gallery-filter-lens { flex: 0 0 auto; }
    #gallery-filter-body .gallery-filter-btn,
    #gallery-filter-lens .gallery-filter-btn { width: auto; min-width: 7rem; }
    #gallery-filter-fnumber .gallery-filter-btn { width: auto; }
    #gallery-filter-ss .gallery-filter-btn,
    #gallery-filter-iso .gallery-filter-btn { width: auto; min-width: 5rem; }
    .gallery-filter-clear-btn { width: auto; }
}

.gallery-filter-label {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.gallery-filter-btn:hover {
    color: #fff;
    border-color: #666;
    background-color: #333;
}

.gallery-filter-btn.active {
    color: #fff;
    border-color: #6b9fff;
    background-color: rgba(107, 159, 255, 0.15);
}

.gallery-filter-popup {
    position: fixed;
    min-width: 180px;
    max-width: calc(100vw - 1rem);
    max-height: 320px;
    overflow-x: hidden;
    overflow-y: auto;
    background-color: #222;
    border: 1px solid #444;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.gallery-filter-popup-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: #ccc;
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background-color 0.15s;
    white-space: nowrap;
}

.gallery-filter-popup-item:hover {
    background-color: #333;
}

.gallery-filter-popup-item.selected {
    color: #6b9fff;
}

.gallery-filter-popup-item.clear-item {
    border-bottom: 1px solid #333;
    color: #888;
}

/* フィルタークリアボタン（フィルターボタンと同じサイズ感） */
.gallery-filter-clear-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 4rem;
    background: none;
    border: 1px solid #664444;
    color: #cc8888;
    padding: 0.375rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.6875rem;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
    flex-shrink: 0;
}

.gallery-filter-clear-btn:hover {
    color: #ff8888;
    border-color: #884444;
    background-color: rgba(255, 100, 100, 0.1);
}

.gallery-filter-clear-btn.visible {
    display: flex;
}

/* ソートボタン（タブ行内） */
.gallery-sort-btn {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
    background: none;
    border: 1px solid #444;
    color: #999;
    cursor: pointer;
    font-size: 0.6875rem;
    padding: 0.375rem 0.5rem;
    border-radius: 4px;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.gallery-sort-btn:hover {
    color: #fff;
    border-color: #666;
    background-color: #333;
}

.gallery-sort-btn svg {
    transition: transform 0.2s;
}

/* 編集モードバー */
.gallery-edit-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 1rem;
    background-color: #c2410c;
    color: #fff;
    font-size: 0.8125rem;
}

.gallery-edit-done-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    padding: 0.25rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8125rem;
    transition: background-color 0.2s;
}

.gallery-edit-done-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* コンテンツエリア */
.gallery-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 2px;
}

/* セクションカードグリッド（ディレクトリビュー） */
.gallery-sections-grid {
    display: grid;
    grid-template-columns: repeat(var(--gallery-columns-mobile, 3), 1fr);
    gap: 2px;
}

@media (min-width: 768px) {
    .gallery-sections-grid {
        grid-template-columns: repeat(var(--gallery-columns-pc, 10), 1fr);
    }
}

/* セクションカード */
.gallery-section-card {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
    background-color: #222;
}

.gallery-section-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.gallery-section-card:hover img {
    transform: scale(1.05);
}

.gallery-section-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0.375rem 0.5rem;
    background:
        linear-gradient(rgba(0, 0, 0, 0.5), transparent 50%),
        linear-gradient(transparent 50%, rgba(0, 0, 0, 0.5));
    pointer-events: none;
}

.gallery-section-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.3;
    word-break: break-word;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8), 0 0 2px rgba(0, 0, 0, 0.6);
}

.gallery-section-num {
    align-self: flex-end;
    font-size: 0.625rem;
    color: #ccc;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* 画像グリッド */
.gallery-images-grid {
    display: grid;
    grid-template-columns: repeat(var(--gallery-columns-mobile, 3), 1fr);
    gap: 2px;
}

@media (min-width: 768px) {
    .gallery-images-grid {
        grid-template-columns: repeat(var(--gallery-columns-pc, 10), 1fr);
    }
}

/* 画像サムネイル */
.gallery-thumb {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
    background-color: #222;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s;
}

.gallery-thumb img[data-src] {
    opacity: 0;
}

/* 撮影日時ラベル */
.gallery-date-label {
    position: absolute;
    bottom: 0;
    right: 0;
    padding: 2px 5px;
    font-size: 0.5625rem;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(0, 0, 0, 0.5);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    line-height: 1.3;
    z-index: 2;
}

/* 編集モード: 除外ボタン */
.gallery-thumb .gallery-remove-btn {
    display: none;
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    z-index: 5;
    transition: background-color 0.2s;
}

.gallery-thumb .gallery-remove-btn:hover {
    background: rgba(220, 38, 38, 0.8);
}

.gallery-page.edit-mode .gallery-thumb .gallery-remove-btn {
    display: flex;
}

/* フェードアウト */
.gallery-thumb.removing {
    animation: fadeOut 0.3s ease-out forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* グリッド内広告行 */
.gallery-ad-row {
    grid-column: 1 / -1;
    display: flex;
    align-items: flex-end;
    padding: 0.5rem 0;
    background-color: #1a1a1a;
}

/* 広告セル */
.gallery-ad-cell {
    flex: 1;
    text-align: center;
}

/* モバイル: 広告セルは1つだけ表示（JSとCSSの判定ずれ防止） */
@media (max-width: 767px) {
    .gallery-ad-cell:nth-child(n+2) {
        display: none;
    }
}

/* AdSense: 各セル内で幅いっぱい */
.gallery-ad-cell ins.adsbygoogle {
    width: 100%;
}

/* プレビュー: モバイル 320:100 比率 */
.gallery-ad-cell .gallery-ad-placeholder {
    width: 100%;
    aspect-ratio: 320 / 100;
}

/* PC: プレビュー 728:90 比率 */
@media (min-width: 768px) {
    .gallery-ad-cell .gallery-ad-placeholder {
        aspect-ratio: 728 / 90;
    }
}

.gallery-ad-row .pmt-placeholder--admin {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 1rem;
    background: repeating-linear-gradient(45deg, #2a2a2a, #2a2a2a 10px, #252525 10px, #252525 20px);
    border: 1px dashed #444;
    border-radius: 4px;
    color: #888;
    font-size: 0.75rem;
}

/* ローディング */
.gallery-loading {
    display: flex;
    justify-content: center;
    padding: 2rem;
}

.gallery-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #333;
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 空メッセージ */
.gallery-empty {
    text-align: center;
    padding: 3rem;
    color: #666;
    font-size: 0.875rem;
}

/* フッター（常時表示） */
.gallery-footer {
    flex-shrink: 0;
    padding: 0.375rem 1rem;
    text-align: center;
    font-size: 0.625rem;
    color: #666;
    background-color: #1a1a1a;
    border-top: 1px solid #333;
}

.gallery-footer-inner {
    line-height: 1.6;
}

.gallery-footer-link {
    color: #888;
    text-decoration: none;
    transition: color 0.2s;
}

.gallery-footer-link:hover {
    color: #ccc;
}
