/* =========================================
   HDR Photo Gallery PoC - Gallery Stylesheet
   ========================================= */

:root {
    --bg-color: #0c0c0c;
    --text-color: #f0f0f0;
    --accent-color: #3a86ff;
    --card-bg: rgba(255, 255, 255, 0.05);
    /* カード背景（半透明） */
    --glass-bg: rgba(255, 255, 255, 0.1);
    /* ガラス効果背景 */
    --glass-border: rgba(255, 255, 255, 0.2);
    /* ガラス効果ボーダー */
    --warning-color: #f59e0b; /* 追加: 注意ガイド用カラー */
}

img {
    -webkit-touch-callout: none; /* iOS Safari長押し保存禁止 */
    -webkit-user-drag: none;      /* Chrome, Safari ドラッグ禁止 */
    user-select: none;            /* 選択禁止 */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow-x: hidden;
    min-height: 100vh;
}

/* -----------------------------------------
   HDR制御ロジック (HDR Control)
   ----------------------------------------- */
.app {
    dynamic-range-limit: standard;
    /* デフォルトはSDR制限あり */
    transition: dynamic-range-limit 0.5s ease;
}

/* 全画面表示時にスクロールを許可する */
.app:-webkit-full-screen {
    overflow-y: auto;
    background-color: var(--bg-color);
}

.app:fullscreen {
    overflow-y: auto;
    background-color: var(--bg-color);
}

.app.hdr-active {
    dynamic-range-limit: no-limit;
    /* HDR有効時は制限解除 */
}

/* -----------------------------------------
   ヘッダー & コントロール (Header)
   ----------------------------------------- */
.header {
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background: rgba(12, 12, 12, 0.8);
    border-bottom: 1px solid var(--glass-border);
    transition: transform 0.3s ease;
    /* hide-on-scroll用 */
}

/* スクロールで隠れるヘッダー */
.header.hidden-by-scroll {
    transform: translateY(-100%);
}

.header h1 {
    font-weight: 300;
    letter-spacing: -0.02em;
    font-size: 1.5rem;
}

/* ホームへ戻るリンク */
.home-link {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    opacity: 0.5;
    transition: opacity 0.3s ease;
    text-decoration: none;
    padding: 4px;
}

.home-link:hover {
    opacity: 1;
}

.controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.hdr-status {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.45;
    /* 控えめな表示 */
}

.control-button {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.control-button:hover {
    background: var(--glass-border);
    transform: translateY(-1px);
}

.control-button.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

.control-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* キーボードフォーカスインジケータ (アクセシビリティ) */
.control-button:focus-visible,
.nav-button:focus-visible,
.close-button:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* 追加: HDR注意ガイドボタン用スタイル */
.notice-guide-btn {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--warning-color) !important;
    border-color: rgba(245, 158, 11, 0.25) !important;
    background: rgba(245, 158, 11, 0.05) !important;
}

.notice-guide-btn:hover {
    background: rgba(245, 158, 11, 0.12) !important;
    border-color: rgba(245, 158, 11, 0.5) !important;
    transform: translateY(-1px);
}

/* -----------------------------------------
   カテゴリフィルター (Category Filters)
   ----------------------------------------- */
.category-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.8rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
    justify-content: center;
}

.filter-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: rgba(255, 255, 255, 0.7);
    padding: 0.35rem 0.8rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.filter-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.filter-btn.active {
    background: #fff;
    color: var(--bg-color);
    border-color: #fff;
    box-shadow: 0 2px 10px rgba(255, 255, 255, 0.2);
    font-weight: 600;
    transform: translateY(0);
}

.filter-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
}

.filter-btn.active .filter-count {
    background: rgba(0, 0, 0, 0.1);
}

/* ギャラリーアイテムの非表示用 */
.gallery-item {
    display: inline-block;
    width: 100%;
}

.gallery-item.hidden {
    display: none;
}

/* -----------------------------------------
   ギャラリーグリッド (Gallery Grid)
   ----------------------------------------- */
.gallery-grid {
    column-count: 3;
    column-gap: 4px;
    padding: 2rem 2rem 4rem;
    max-width: 1400px;
    margin: 0 auto;
    display: block;
}

@media (max-width: 1000px) {
    .gallery-grid {
        column-count: 2;
    }
}

.gallery-item {
    break-inside: avoid-column;
    -webkit-column-break-inside: avoid;
    margin-bottom: 4px;
    display: inline-block;
    width: 100%;
    overflow: hidden;
    border-radius: 2px;
    cursor: pointer;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.03) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    position: relative;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 150px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (hover: hover) {
    .gallery-item:hover {
        transform: scale(1.02);
        z-index: 1;
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
    }
}

.gallery-item:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    z-index: 1;
}

@media (hover: hover) {
    .gallery-item:hover img.loaded {
        filter: brightness(1.12);
    }
}

.gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    opacity: 0;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), filter 0.3s ease;
    pointer-events: none; /* 長押し・右クリックでの画像保存対策（タップ操作は透過） */
}

.gallery-item img.loaded {
    opacity: 1;
}

/* 読み込み中のインジケーター（ギャラリーアイテムタップ時） */
.gallery-item.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    pointer-events: none;
    z-index: 2;
    animation: viewer-fade-in 0.2s ease forwards;
}

.gallery-item.is-loading::before {
    content: "";
    position: absolute;
    top: calc(50% - 16px);
    left: calc(50% - 16px);
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 3;
}

/* スマホ: 2列表示で一覧性と選びやすさを最優先 */
@media (max-width: 600px) {
    html {
        scroll-snap-type: none;
    }

    .gallery-grid {
        column-count: 2; /* 2列表示に変更 */
        column-gap: 6px;
        padding: 6px 6px 4rem;
    }

    .gallery-item {
        border-radius: 4px;
        margin-bottom: 6px;
        min-height: 100px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
}

/* -----------------------------------------
   ビューア (Viewer / Lightbox)
   ----------------------------------------- */
.viewer {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #080808 0%, #000 100%);
    /* 縦スクロールはブラウザに任せ、横はJSで制御 */
    touch-action: pan-y;
}

/* ズーム中は全タッチ操作をJS制御 */
.viewer.zoomed {
    touch-action: none;
    cursor: grab;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* ビネット効果: 四隅を暗くして写真を引き立てる */
.viewer::after {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.35) 100%);
    pointer-events: none;
    z-index: 6;
}

.viewer.hidden {
    display: none;
}

/* PC向け: UI非表示時はマウスカーソルも隠す */
.viewer.viewer-ui-hidden {
    cursor: none;
}

.viewer-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.viewer-image-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    will-change: transform;
    /* GPU アクセラレーション */
    transform-origin: center center;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
}

.viewer.loading .viewer-image-container {
    background: #141414;
}

.main-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: scale-down;
    /* 元画像より大きく引き伸ばさない */
    /* view-transition-name is managed dynamically in JS */
    user-select: none;
    /* テキスト選択禁止 (簡易コピー防止) */
    -webkit-user-drag: none;
    /* ドラッグ禁止 (簡易コピー防止) */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.viewer.loading .main-image {
    opacity: 0;
}

/* 読み込み中スピナー */
.loading-spinner {
    position: absolute;
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2;
}

.loading-spinner.hidden {
    display: none;
}

.loading-note {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, calc(-50% + 44px));
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.75);
    text-align: center;
    z-index: 2;
    pointer-events: none;
}

.loading-note.hidden {
    display: none;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ビューア内コントロール */
.viewer-controls {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2rem;
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.3s ease;
}

/* コントロール非表示状態 */
.viewer-ui-hidden .viewer-controls,
.viewer-ui-hidden .close-button,
.viewer-ui-hidden .fullscreen-btn,
.viewer-ui-hidden .viewer-hdr-btn,
.viewer-ui-hidden .image-info {
    opacity: 0;
    pointer-events: none;
}

.nav-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    /* ボタン自体はクリック可能に */
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}

.nav-label {
    display: none;
    /* デスクトップではラベル非表示 */
}

.nav-button:hover {
    background: var(--glass-border);
}

.close-button {
    position: absolute;
    top: 2rem;
    right: 2rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    backdrop-filter: blur(10px);
    z-index: 20;
    transition: opacity 0.3s ease, background 0.2s ease;
}

.viewer-hdr-btn {
    position: absolute;
    top: 2rem;
    left: 2rem;
    z-index: 20;
    height: 48px;
    border-radius: 24px;
    padding: 0 1.5rem;
    transition: opacity 0.3s ease;
}

.fullscreen-btn {
    position: absolute;
    top: 2rem;
    right: 6.5rem;
    /* 閉じるボタンから少し離す */
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    cursor: auto;
    /* cursor:none継承防止 */
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    z-index: 20;
    transition: opacity 0.3s ease, background 0.2s ease;
}

.fullscreen-btn:hover {
    background: var(--glass-border);
}

.image-info {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.9rem;
    opacity: 0.85;
    background: rgba(0, 0, 0, 0.5);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    z-index: 15;
    letter-spacing: 0.05em;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

.image-info-error {
    color: #ff4d4d !important;
}

/* -----------------------------------------
   View Transitions API 設定
   ----------------------------------------- */
::view-transition-group(*) {
    animation-duration: 0.5s;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* View Transitions API 非対応ブラウザ向けフォールバック */
@keyframes viewer-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes viewer-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

.viewer.viewer-fade-in {
    animation: viewer-fade-in 0.3s ease forwards;
}

.viewer.viewer-fade-out {
    animation: viewer-fade-out 0.3s ease forwards;
}

/* -----------------------------------------
   ユーティリティ
   ----------------------------------------- */
/* ビューア表示中はスクロール禁止 */
body.viewer-mode {
    overflow: hidden;
}

/* -----------------------------------------
   モバイル対応 (Mobile Responsive)
   ----------------------------------------- */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.2rem;
    }

    .hdr-status {
        font-size: 0.7rem;
        opacity: 0.4;
    }

    /* スマホ向け：操作ボタンを下に配置 */
    .viewer-controls {
        top: auto;
        bottom: 0;
        height: 120px;
        padding: 1rem;
        background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
        /* 下部グラデーション */
        align-items: flex-end;
    }

    .nav-button {
        width: auto;
        height: 48px;
        padding: 0 1.2rem;
        border-radius: 24px;
        gap: 0.5rem;
    }

    .nav-label {
        display: inline;
        font-size: 0.9rem;
    }

    .close-button {
        top: 1rem;
        right: 1rem;
        width: 40px;
        height: 40px;
    }

    .fullscreen-btn {
        top: 1rem;
        right: 4.5rem;
        width: 40px;
        height: 40px;
    }

    .viewer-hdr-btn {
        top: 1rem;
        left: 1rem;
        height: 40px;
        padding: 0 1rem;
        font-size: 0.7rem;
    }

    .category-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        padding: 0.8rem 1rem 1rem;
        -ms-overflow-style: none;
        scrollbar-width: none;
        scroll-behavior: smooth;
    }

    .category-filters::-webkit-scrollbar {
        display: none;
    }

    .category-filters::after {
        content: '';
        padding-right: 1rem;
    }
}

/* -----------------------------------------
   アクセシビリティ (A11y) & エラー表示の拡張
   ----------------------------------------- */

/* フォーカスキューの改善 */
button:focus-visible,
a:focus-visible,
.gallery-item:focus-visible {
    outline: 3px solid var(--accent-color, #ff4d4d);
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(255, 77, 77, 0.2);
}

/* エラー表示コンテナ */
.viewer-error-container {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2.5rem 2rem;
    z-index: 15;
    background: rgba(15, 15, 15, 0.9);
    border: 1px solid rgba(255, 77, 77, 0.4);
    border-radius: 16px;
    max-width: 90%;
    width: 320px;
    backdrop-filter: blur(15px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    animation: viewer-fade-in 0.3s ease forwards;
}

.viewer-error-container.hidden {
    display: none !important;
}

.viewer-error-container .error-icon {
    width: 56px;
    height: 56px;
    color: #ff4d4d;
    margin-bottom: 1.2rem;
    filter: drop-shadow(0 2px 8px rgba(255, 77, 77, 0.3));
}

.viewer-error-container .error-message {
    color: #f3f3f3;
    font-size: 1.05rem;
    margin: 0 0 1.5rem 0;
    font-weight: 500;
    line-height: 1.5;
}

.viewer-error-container .retry-btn {
    padding: 0.8rem 2rem;
    background: #ff4d4d;
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 4px 15px rgba(255, 77, 77, 0.3);
    transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

.viewer-error-container .retry-btn:hover {
    background: #ff3333;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 77, 77, 0.5);
}

.viewer-error-container .retry-btn:active {
    transform: translateY(0);
}

.viewer-error-container .retry-btn:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}
