/*!
 * fx.css — サイト共通の演出部品 v1.0（2026-11-07）。fx.js とセットで使う。
 *
 * 約束
 *  - 初期状態を隠すのは html.js のときだけ（<head> 先頭に <script>document.documentElement.classList.add('js')</script>）
 *  - fx.js が起動しなくても、3 秒後に CSS だけで全部表示する（フェイルセーフ）
 *  - 動かすのは opacity / translate / scale のみ（clip-path・mask は表示演出の局所だけ）
 *  - prefers-reduced-motion: reduce では移動・拡大・視差・ループを止め、フェードだけ残す
 *  - ヒーローの見出し・メイン画像（LCP 要素）には data-fx を付けない
 * 調整は CSS 変数で行う（:root か各要素で上書き）。
 */

:root {
    --fx-ease: cubic-bezier(.2, .8, .2, 1);
    --fx-dur: .8s;
    --fx-dist: 28px;
    --fx-accent: currentColor;
}

/* ===== 1. 表示（data-fx） ===== */
/* 隠れた状態 → is-in が付くと animation で戻る（backwards）。終われば素の状態に戻るので、サイト側の hover transition を壊さない */
html.js [data-fx]:not(.is-in) { opacity: 0; }
html.js [data-fx=""]:not(.is-in),
html.js [data-fx="up"]:not(.is-in) { translate: 0 var(--fx-dist); }
html.js [data-fx="left"]:not(.is-in) { translate: calc(var(--fx-dist) * -1.6) 0; }
html.js [data-fx="right"]:not(.is-in) { translate: calc(var(--fx-dist) * 1.6) 0; }
html.js [data-fx="zoom"]:not(.is-in) { scale: .92; }
html.js [data-fx="clip"]:not(.is-in) { opacity: 1; clip-path: inset(0 100% 0 0); }
html.js [data-fx="mask"].is-in {
    -webkit-mask-image: linear-gradient(90deg, #000 40%, transparent 60%);
    mask-image: linear-gradient(90deg, #000 40%, transparent 60%);
    -webkit-mask-size: 250% 100%;
    mask-size: 250% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: 0 0;
    mask-position: 0 0;
}
html.js [data-fx="mask"]:not(.is-in) {
    opacity: 1;
    -webkit-mask-image: linear-gradient(90deg, #000 40%, transparent 60%);
    mask-image: linear-gradient(90deg, #000 40%, transparent 60%);
    -webkit-mask-size: 250% 100%;
    mask-size: 250% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: 100% 0;
    mask-position: 100% 0;
}
html.js [data-fx].is-in {
    animation-duration: var(--fx-dur);
    animation-timing-function: var(--fx-ease);
    animation-delay: var(--fx-delay, 0s);
    animation-fill-mode: backwards;
}
html.js [data-fx=""].is-in,
html.js [data-fx="up"].is-in { animation-name: fx-up; }
html.js [data-fx="left"].is-in { animation-name: fx-left; }
html.js [data-fx="right"].is-in { animation-name: fx-right; }
html.js [data-fx="zoom"].is-in { animation-name: fx-zoom; }
html.js [data-fx="clip"].is-in { animation-name: fx-clip; animation-duration: calc(var(--fx-dur) * 1.3); }
html.js [data-fx="mask"].is-in { animation-name: fx-mask; animation-duration: calc(var(--fx-dur) * 1.5); }

@keyframes fx-up { from { opacity: 0; translate: 0 var(--fx-dist); } }
@keyframes fx-left { from { opacity: 0; translate: calc(var(--fx-dist) * -1.6) 0; } }
@keyframes fx-right { from { opacity: 0; translate: calc(var(--fx-dist) * 1.6) 0; } }
@keyframes fx-zoom { from { opacity: 0; scale: .92; } }
@keyframes fx-clip { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes fx-mask {
    from { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
    to { -webkit-mask-position: 0 0; mask-position: 0 0; }
}
@keyframes fx-fade { from { opacity: 0; } }

/* フェイルセーフ：fx.js が起動しなかったら 3 秒後に全部表示（fx.js が起動すると html.fx-ready が付いて無効になる） */
html.js:not(.fx-ready) [data-fx] { animation: fx-failsafe .01s 3s forwards; }
/* フェイルセーフの後に fx.js が遅れて起動した（html.fx-late）ときは、表示済みのまま動かさない */
html.js.fx-late [data-fx] { opacity: 1 !important; translate: none !important; scale: none !important; clip-path: none !important; -webkit-mask-image: none !important; mask-image: none !important; animation: none !important; }
@keyframes fx-failsafe {
    to {
        opacity: 1;
        translate: none;
        scale: none;
        clip-path: none;
        -webkit-mask-image: none;
        mask-image: none;
    }
}

/* ===== 2. カウントアップ ===== */
[data-fx-count] { font-variant-numeric: tabular-nums; }

/* ===== 3. マーキー（data-fx-marquee） ===== */
.fx-marquee { display: flex; overflow: hidden; }
.fx-marquee__track {
    display: flex;
    flex-shrink: 0;
    gap: var(--fx-marquee-gap, 2rem);
    min-width: 100%;
    padding-inline-end: var(--fx-marquee-gap, 2rem); /* 継ぎ目の余白（gap と同じ幅） */
    animation: fx-marquee var(--fx-marquee-dur, 30s) linear infinite;
}
.fx-marquee--rev .fx-marquee__track { animation-direction: reverse; }
.fx-marquee:hover .fx-marquee__track,
.fx-marquee:focus-within .fx-marquee__track,
.fx-marquee.is-stopped .fx-marquee__track,
.fx-marquee.is-off .fx-marquee__track { animation-play-state: paused; }
@keyframes fx-marquee { to { translate: -100% 0; } }
.fx-marquee__btn {
    display: block;
    margin: .4rem 0 0 auto;
    padding: .25rem .8rem;
    font: inherit;
    font-size: .75rem;
    color: inherit;
    background: transparent;
    border: 1px solid currentColor;
    border-radius: 999px;
    opacity: .7;
    cursor: pointer;
}
.fx-marquee__btn:hover,
.fx-marquee__btn:focus-visible { opacity: 1; }
/* 視差オフ：流さず、折り返して全部見せる */
.fx-marquee--static { flex-wrap: wrap; gap: var(--fx-marquee-gap, 1.5rem); }

/* ===== 4. 進捗バー（data-fx-progress） ===== */
.fx-progress {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 9999;
    height: var(--fx-progress-h, 4px);
    background: var(--fx-accent);
    transform: scaleX(0);
    transform-origin: 0 50%;
    pointer-events: none;
}

/* ===== 5. 背景色の切り替え（data-fx-bg → body[data-fx-theme]） ===== */
html.fx-has-bg body { transition: background-color .6s ease, color .6s ease; }
body[data-fx-theme="night"] { background-color: var(--fx-night-bg, #0b1030); color: var(--fx-night-fg, #eef1ff); }
body[data-fx-theme="dark"] { background-color: var(--fx-dark-bg, #111); color: var(--fx-dark-fg, #fff); }
body[data-fx-theme="warm"] { background-color: var(--fx-warm-bg, #fff6ec); color: var(--fx-warm-fg, #3a2a1a); }

/* ===== 6. マウス反応（マウスがあるときだけ。fx.js が html.fx-fine を付ける） ===== */
html.fx-fine [data-fx-tilt] {
    transform: perspective(900px) rotateX(var(--fx-rx, 0deg)) rotateY(var(--fx-ry, 0deg));
    transition: transform .25s var(--fx-ease);
}
html.fx-fine [data-fx-magnetic] {
    translate: var(--fx-mx, 0px) var(--fx-my, 0px);
    transition: translate .3s var(--fx-ease);
}

/* ===== 7. 飛行物体（.fx-flyby）— ヤマト方式を transform 系で書いたもの =====
 * 使い方: <div class="fx-flyby" aria-hidden="true"><img src="rocket.svg" alt=""></div>
 * 既定は「奥から手前へ」。cubic-bezier(1,0,1,0) で大半は小さく遠くに見え、最後に急加速して巨大化して通り過ぎる。
 * .fx-flyby--side は「横から画面に入って横切る」（トレーラーハウスなど）。
 * 周期・方向・大きさは CSS 変数で変える。本文より後ろに出すため z-index は -1（不透明な背景の親があると隠れる）。 */
.fx-flyby {
    --fx-fly-dur: 15s;
    --fx-fly-delay: 0s;
    --fx-fly-size: 160px;
    --fx-fly-x0: 35vw;
    --fx-fly-y0: 25vh;
    --fx-fly-x1: -45vw;
    --fx-fly-y1: -45vh;
    --fx-fly-s0: .08;
    --fx-fly-s1: 5;
    --fx-fly-rot: 0deg;
    --fx-fly-ease: cubic-bezier(1, 0, 1, 0);
    position: fixed;
    inset: 0;
    z-index: var(--fx-fly-z, -1);
    overflow: hidden;
    pointer-events: none;
}
.fx-flyby > * {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--fx-fly-size);
    height: auto;
    translate: calc(-50% + var(--fx-fly-x0)) calc(-50% + var(--fx-fly-y0));
    scale: var(--fx-fly-s0);
    rotate: var(--fx-fly-rot);
    opacity: 0;
    animation:
        fx-fly var(--fx-fly-dur) var(--fx-fly-ease) var(--fx-fly-delay) infinite,
        fx-fly-fade var(--fx-fly-dur) linear var(--fx-fly-delay) infinite;
}
.fx-flyby--side {
    --fx-fly-dur: 26s;
    --fx-fly-size: 320px;
    --fx-fly-x0: -70vw;
    --fx-fly-y0: 30vh;
    --fx-fly-x1: 70vw;
    --fx-fly-y1: 30vh;
    --fx-fly-s0: 1;
    --fx-fly-s1: 1;
    --fx-fly-ease: linear;
}
@keyframes fx-fly {
    from {
        translate: calc(-50% + var(--fx-fly-x0)) calc(-50% + var(--fx-fly-y0));
        scale: var(--fx-fly-s0);
    }
    to {
        translate: calc(-50% + var(--fx-fly-x1)) calc(-50% + var(--fx-fly-y1));
        scale: var(--fx-fly-s1);
    }
}
@keyframes fx-fly-fade { 0% { opacity: 0; } 6% { opacity: 1; } 94% { opacity: 1; } 100% { opacity: 0; } }
@media (max-width: 767px) {
    .fx-flyby { --fx-fly-size: 100px; }
    .fx-flyby--side { --fx-fly-size: 200px; }
}
html.fx-paused .fx-flyby > * { animation-play-state: paused; }

/* ===== 8. 粒子（.fx-particles）— 親を position: relative にして、その中に置く =====
 * <section class="hero" style="position:relative"><div class="fx-particles" data-mode="stars"></div>…</section>
 * 色: --fx-particle-color（点）, --fx-link-rgb（線。"154,176,255" の形式） */
.fx-particles {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}
.fx-particles canvas { display: block; width: 100%; height: 100%; }

/* ===== 9. 「背景の動きを止める」共通ボタン（flyby / particles があるとき fx.js が自動で付ける） ===== */
.fx-controls {
    position: fixed;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 40; /* ヘッダー・開いたメニューより下（多くのテーマは 50 以上） */
    padding: .35rem .9rem;
    font: inherit;
    font-size: .75rem;
    color: #fff;
    background: rgba(20, 20, 40, .72);
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 999px;
    cursor: pointer;
}
.fx-controls:hover,
.fx-controls:focus-visible { background: rgba(20, 20, 40, .92); }

/* ===== 視差オフ（prefers-reduced-motion: reduce）：移動・拡大・視差・ループを止め、フェードだけ残す ===== */
@media (prefers-reduced-motion: reduce) {
    html.js [data-fx]:not(.is-in) {
        opacity: 0;
        translate: none;
        scale: none;
        clip-path: none;
        -webkit-mask-image: none;
        mask-image: none;
    }
    html.js [data-fx].is-in {
        animation-name: fx-fade;
        animation-duration: .4s;
        animation-delay: 0s;
    }
    html.js:not(.fx-ready) [data-fx] { animation: fx-failsafe .01s 3s forwards; }
    .fx-marquee__track { animation: none !important; }
    .fx-marquee__btn, .fx-controls, .fx-progress { display: none; }
    .fx-flyby { display: none; }
    html.fx-fine [data-fx-tilt], html.fx-fine [data-fx-magnetic] { transform: none; translate: none; transition: none; }
    html body, html.fx-has-bg body { transition: none; }
}
