/*
 * ガチャ詳細ページの横スワイプ比較（グループ単位オプトイン）
 * 比較できるガチャが 2 件以上あるページでだけ読み込まれる。
 * spec: docs/features/lottery-detail-swipe-compare/spec.md §6（指追従は §6.8）
 */

/* 縦スクロールとピンチはブラウザに任せ、横の動きだけ JS が判定する */
.gacha-header .gacha-thumbnail {
    touch-action: pan-y pinch-zoom;
}

/* ───── 矢印（見た目は小さく半透明。タップできる範囲は 44×44px） ───── */
.lottery-detail-swipe-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 6; /* 争奪戦の開始前カウントダウン（inset:0・z-index:2）より上 */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.lottery-detail-swipe-arrow--prev {
    left: 9px;
}

.lottery-detail-swipe-arrow--next {
    right: 9px;
}

/* 明るいサムネイル・ダークモードでも見えるよう、暗い半透明の背景と細い明るい縁を敷く */
.lottery-detail-swipe-arrow__glyph {
    display: block;
    width: 30px;
    height: 44px;
    border-radius: 10px;
    background: rgba(20, 16, 28, 0.42);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    color: #ffffff;
    font-size: 22px;
    line-height: 44px;
    text-align: center;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* 押せることが分かるよう、ホバー・押下・フォーカスで背景を濃くする */
.lottery-detail-swipe-arrow:hover .lottery-detail-swipe-arrow__glyph,
.lottery-detail-swipe-arrow:active .lottery-detail-swipe-arrow__glyph,
.lottery-detail-swipe-arrow:focus-visible .lottery-detail-swipe-arrow__glyph {
    background: rgba(20, 16, 28, 0.6);
}

.lottery-detail-swipe-arrow:focus-visible {
    outline: none;
}

.lottery-detail-swipe-arrow:focus-visible .lottery-detail-swipe-arrow__glyph {
    outline: 3px solid #e8417a;
    outline-offset: 2px;
}

/* ───── ドット（サムネイル直下に 1 行。位置の表示だけで押せない） ───── */
.lottery-detail-swipe-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    height: 20px;
    pointer-events: none;
}

.lottery-detail-swipe-dot {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #d6cfe0;
    transition: background-color 0.15s ease;
}

.lottery-detail-swipe-dot.is-active {
    width: 8px;
    height: 8px;
    background: #e8417a;
}

html.dark-mode-on .lottery-detail-swipe-dot {
    background: #5a5266;
}

html.dark-mode-on .lottery-detail-swipe-dot.is-active {
    background: #ff6f9c;
}

/* ───── 指追従（R10・案 A）: 枠の padding の内側の切り抜き用 viewport（spec §6.8.1） ─────
 * 位置（inset）・角丸は JS が getComputedStyle から入れる。ドラッグ中と遷移中だけ表示する */
.lottery-detail-swipe-viewport {
    display: none;
    position: absolute;
    overflow: hidden;
    /* 元の画像（static）の上、ライブ表示（z-index:1）・カウントダウン（2〜）・矢印（6）の下 */
    z-index: 0;
    /* iOS で角丸の切り抜きが合成された子（translate3d）に効かないことがあるため、自分で合成レイヤーを持つ */
    isolation: isolate;
    transform: translateZ(0);
    /* プレースホルダ・画像のすき間の色（虹枠が透けない）。枠の背景が不透明な単色のときは JS がその色で上書きする */
    background-color: #ffffff;
    pointer-events: none;
}

html.dark-mode-on .lottery-detail-swipe-viewport {
    background-color: #0e1024;
}

.gacha-thumbnail.is-lottery-swipe-active > .lottery-detail-swipe-viewport {
    display: block;
}

/* そのあいだ元の画像は隠す（直下の子のまま動かさないので、既存の `> img` のセレクタは変わらない） */
.gacha-thumbnail.is-lottery-swipe-active > img {
    visibility: hidden;
}

/* すき間（gap）は JS の定数で入れる */
.lottery-detail-swipe-track {
    position: absolute;
    top: 0;
    height: 100%;
    display: flex;
    will-change: transform;
}

/* `.gacha-thumbnail img`（width:100%）などの既存ルールに負けないよう幅は JS がインラインで入れる */
.gacha-thumbnail .lottery-detail-swipe-track > img {
    flex: 0 0 auto;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ───── 遷移中（読み込み待ち）の誤操作防止（§6.8.4） ─────
 * 固定フッター（1000）・オークションの入札オーバーレイ（1000）より上、下部ナビ（99999）・PWA 表示（99998〜）より下 */
.lottery-detail-swipe-blocker {
    position: fixed;
    inset: 0;
    z-index: 1001;
    background: transparent;
}

/* opacity だけを使う（filter / transform は固定フッターの位置を崩すため使わない） */
.is-lottery-swipe-dimmed {
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

/* 固定フッターは既存の bottom の transition（lottery-page.css）を残す */
.gacha-fixed-footer.is-lottery-swipe-dimmed {
    transition: opacity 0.15s ease, bottom 0.3s ease;
}

/* 読み込み表示・案内の置き場所。ドット行（無いときは高さ 0 の要素）に重ねて置き、レイアウトをずらさない */
.lottery-detail-swipe-dots,
.lottery-detail-swipe-anchor {
    position: relative;
}

.lottery-detail-swipe-anchor {
    height: 0;
}

.lottery-detail-swipe-loading {
    position: absolute;
    top: 50%;
    left: calc(50% + 12px);
    width: 10px;
    height: 10px;
    margin-top: -7px;
    border: 2px solid #d6cfe0;
    border-top-color: #e8417a;
    border-radius: 50%;
    animation: lottery-detail-swipe-spin 0.8s linear infinite;
}

.lottery-detail-swipe-anchor > .lottery-detail-swipe-loading {
    top: 4px;
    left: 50%;
    margin: 0 0 0 -7px;
}

@keyframes lottery-detail-swipe-spin {
    to { transform: rotate(360deg); }
}

/* 案内はドット行の直下（引くボタンに重ねない）。読み上げはライブリージョンで行う */
.lottery-detail-swipe-toast {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 7;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 8px 14px;
    border-radius: 10px;
    background: rgba(20, 16, 28, 0.88);
    color: #ffffff;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    pointer-events: none;
}

.lottery-detail-swipe-anchor > .lottery-detail-swipe-toast {
    top: 4px;
}

html.dark-mode-on .lottery-detail-swipe-toast {
    border: 1px solid rgba(255, 255, 255, 0.35);
}

.lottery-detail-swipe-live {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ───── 新しいページでの見え方（View Transitions・§6.8.5） ─────
 * 旧ページは pageswap の中で JS が枠に名前を付け、記録に named を入れる。
 * 新ページは、旧ページが名前を付けたとき（<html data-lottery-swipe-thumb>）だけ枠に同じ名前を付ける。
 * 動きを減らす設定では base.blade.php の !important（名前付きのグループにも効く）がそのまま効く */
:root[data-lottery-swipe-thumb] .gacha-header > .gacha-thumbnail {
    view-transition-name: lottery-detail-thumb;
}

@keyframes lottery-detail-swipe-fade-in {
    from { opacity: 0; }
}

@keyframes lottery-detail-swipe-fade-out {
    to { opacity: 0; }
}

/* 枠は据え置き: 旧スナップショットは不透明のまま下に残し、新しいほうを約 150ms でフェードイン（デコードが遅れても空白が見えない）。
 * animation の一括指定で UA の合成指定が外れるため、サムネイルは normal（加算で白飛びしない）を明示する */
::view-transition-group(lottery-detail-thumb) {
    animation-duration: 200ms;
}

::view-transition-old(lottery-detail-thumb) {
    animation: none;
    opacity: 1;
    mix-blend-mode: normal;
}

::view-transition-new(lottery-detail-thumb) {
    animation: 150ms ease both lottery-detail-swipe-fade-in;
    mix-blend-mode: normal;
}

/* ページ全体は短いクロスフェード。途中が透けないよう plus-lighter を明示する */
:root[data-lottery-swipe]::view-transition-old(root) {
    animation: 150ms ease both lottery-detail-swipe-fade-out;
    mix-blend-mode: plus-lighter;
}

:root[data-lottery-swipe]::view-transition-new(root) {
    animation: 150ms ease both lottery-detail-swipe-fade-in;
    mix-blend-mode: plus-lighter;
}

@media (prefers-reduced-motion: reduce) {
    .is-lottery-swipe-dimmed {
        transition: none;
    }

    .gacha-fixed-footer.is-lottery-swipe-dimmed {
        transition: bottom 0.3s ease;
    }

    .lottery-detail-swipe-loading {
        animation: none;
    }
}
