/* hashito.biz 共通モーション（対になる JS: /assets/motion.js）
 *
 * 設計の約束（例外を作らないこと。ops/motion_audit.py が機械的に検査する）
 *   1) 演出（@keyframes / animation / transition）は必ず
 *      @media (prefers-reduced-motion: no-preference) の中にだけ書く。
 *      動きを減らす設定の環境ではブロックごと効かず、静止した見た目が既定になる。
 *   2) 演出のセレクタは必ず html.hb-motion で始める。
 *      このクラスは motion.js が「reduce でないとき」だけ付ける（二重の防波堤）。
 *   3) 見えている要素を CSS だけで隠さない。初期状態の非表示（.hb-reveal）は
 *      motion.js が画面外の要素にだけ付ける。JS が動かない環境では何も隠れない。
 *   4) 動かすのは transform と opacity だけ。幅・高さ・余白には触らないので
 *      レイアウトがずれる（CLS）ことがない。
 *
 * ゲームを壊さないための約束（このサイト固有・いちばん重要）
 *   A) セレクタは「サイト共通の外枠」（ヘッダ・ヒーロー・フッタ・一覧カード）に
 *      しか当てない。* や button、canvas のような広いセレクタは使わない。
 *   B) canvas・ゲームの操作パッド（.snake-pad / .hs-board など）・各ツールページの
 *      main の中身には、transform も pointer-events も一切足さない。
 *      ゲームはポインタ座標を getBoundingClientRect() から計算しているので、
 *      祖先に transform が乗ると当たり判定がずれる。
 *   C) 出現アニメ（.hb-reveal）は canvas のあるページでは motion.js が丸ごと降りる。
 *      「読むページ」（トップ・一覧・電子公告・スキル詳細・404）だけを対象にする。
 *
 * 接頭辞が hb- なのは、このサイトの既存レイアウトが hs-（hs-header / hs-wrap …）を
 * 使っているため。演出用のクラスと素のレイアウトを名前で見分けられるようにしている。
 */

/* --------------------------------------------------------------------------
 * reduce 側のブロックはここだけ。「無効化」しか書かない。
 * 各ページが持っている演出のうち、**サイト共通の外枠**のぶんだけを止める。
 * ゲーム本体（canvas の周り・css.animation のデモ）は各ページが
 * 自前で prefers-reduced-motion を見ているので、ここからは触らない。
 * ------------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }

  .nav a, .hs-nav a,
  .work, .work .thumb img,
  .skill-card, .skill-card .thumb img,
  .site-links a, .contact-grid a, .chip,
  .tool, .tool .shot img, .game, .game .shot img, .game-link,
  .btn, a.home {
    transition-duration: 0s !important;
    transition-delay: 0s !important;
  }
  .work:hover, .work:focus-visible,
  .skill-card:hover, .skill-card:focus-visible,
  .tool:hover, .tool:focus-visible,
  .game:hover, .game:focus-visible,
  .work:hover .thumb img, .skill-card:hover .thumb img {
    transform: none !important;
  }
}

@media (prefers-reduced-motion: no-preference) {

  /* === 1. ページの入り ==================================================
   * 遷移のたびに紙面が静かに立ち上がる。
   *
   * transform は使わない。body に transform が乗ると position:fixed の
   * ヘッダーが body 基準になって固定が壊れる（全ページのヘッダが fixed）。
   *
   * .hb-enter は motion.js が「表で開かれたとき」だけ付け、2秒後に必ず外す。
   * 裏で開かれたタブは **animation の時計まで止まる**ので、fill:both の
   * 起点（不透明度0）でページ全体が凍る。実測でそうなることを確かめた
   * （2026-08-04・このサイトの14ページ中13ページが body 不透明度0だった）。
   * 入りの演出のためにページ全体が見えなくなる取引は割に合わないので、
   * 「裏なら演出しない・出したら必ず片付ける」を JS 側の条件にしている。
   * ------------------------------------------------------------------ */
  html.hb-motion.hb-enter body {
    animation: hb-page-in .34s cubic-bezier(.22, .61, .36, 1) both;
  }
  @keyframes hb-page-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  /* === 2. ヒーローの入り ===============================================
   * トップの大見出しと、下層ページの見出し帯。読み込み直後に一度だけ動く。
   * 子要素は transform だけを動かす。ページ側が不透明度を指定している要素に
   * opacity のキーフレームを重ねると、fill:both で終端が居座って
   * 既定の見た目を書き換えてしまうため（淡く出す役目は body 側が持つ）。
   * 高さに触らない＝上から下へ文字が飛ぶ（CLS）ことがない。
   * ------------------------------------------------------------------ */
  @keyframes hb-rise {
    from { transform: translateY(12px); }
    to   { transform: none; }
  }

  html.hb-motion.hb-enter .hero-inner > *,
  html.hb-motion.hb-enter .hs-hero .hs-wrap > *,
  html.hb-motion.hb-enter .hero .hs-wrap > *,
  html.hb-motion.hb-enter .box > * {
    animation: hb-rise .66s cubic-bezier(.22, .61, .36, 1) both;
  }
  /* 見出し・説明・ボタンの順に、わずかにずらして立ち上げる */
  html.hb-motion.hb-enter .hero-inner > :nth-child(2),
  html.hb-motion.hb-enter .hs-hero .hs-wrap > :nth-child(2),
  html.hb-motion.hb-enter .hero .hs-wrap > :nth-child(2),
  html.hb-motion.hb-enter .box > :nth-child(2) { animation-delay: .07s; }
  html.hb-motion.hb-enter .hero-inner > :nth-child(3),
  html.hb-motion.hb-enter .hs-hero .hs-wrap > :nth-child(3),
  html.hb-motion.hb-enter .hero .hs-wrap > :nth-child(3),
  html.hb-motion.hb-enter .box > :nth-child(3) { animation-delay: .14s; }
  html.hb-motion.hb-enter .hero-inner > :nth-child(4),
  html.hb-motion.hb-enter .box > :nth-child(4) { animation-delay: .21s; }

  /* トップのヒーローは背景の斜めグラデーションを一度だけ引き寄せる。
     ::before は装飾専用（pointer-events は元から無い）ので操作を邪魔しない。 */
  html.hb-motion.hb-enter .hero::before {
    animation: hb-hero-bg 1.6s cubic-bezier(.22, .61, .36, 1) both;
  }
  @keyframes hb-hero-bg {
    from { opacity: 0; transform: scale(1.04); }
    to   { opacity: 1; transform: none; }
  }

  /* === 3. スクロール出現 ===============================================
   * .hb-reveal は motion.js が「初期表示で画面外だった要素」にだけ付ける。
   * canvas のあるページでは motion.js が出現アニメごと降りるので付かない。
   * ------------------------------------------------------------------ */
  html.hb-motion .hb-reveal {
    opacity: 0;
    transform: translateY(14px);
  }
  html.hb-motion .hb-reveal.hb-reveal-sm {
    transform: translateY(8px);
  }
  html.hb-motion .hb-reveal.hb-in {
    opacity: 1;
    transform: none;
    transition:
      opacity   .5s cubic-bezier(.22, .61, .36, 1),
      transform .5s cubic-bezier(.22, .61, .36, 1);
    transition-delay: var(--hb-delay, 0ms);
  }

  /* 見出し下の金色の短い罫線を、見出しが出たあとに中央から引く。
     position:absolute の擬似要素なので、幅が変わっても本文は動かない。 */
  html.hb-motion .section-head.hb-reveal h2::after {
    transform: translateX(-50%) scaleX(.15);
    opacity: .35;
  }
  html.hb-motion .section-head.hb-reveal.hb-in h2::after {
    transform: translateX(-50%);
    opacity: 1;
    transition:
      transform .55s cubic-bezier(.22, .61, .36, 1) .1s,
      opacity   .55s cubic-bezier(.22, .61, .36, 1) .1s;
  }

  /* === 4. ヘッダー ======================================================
   * スクロールし始めたら影だけ足す。高さも余白も変えないので何もずれない。
   * .hb-scrolled は motion.js が付ける。
   * ------------------------------------------------------------------ */
  html.hb-motion .site-header,
  html.hb-motion .hs-header {
    transition: box-shadow .28s ease, background-color .28s ease;
  }
  html.hb-motion .site-header.hb-scrolled,
  html.hb-motion .hs-header.hb-scrolled {
    box-shadow: 0 6px 22px rgba(26, 26, 46, .10);
  }

  /* ナビは下線を左から引く。擬似要素なので文字の位置は動かない。 */
  html.hb-motion .nav a,
  html.hb-motion .hs-nav a {
    position: relative;
  }
  html.hb-motion .nav a::after,
  html.hb-motion .hs-nav a::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -5px;
    height: 1px;
    background: var(--accent, #c9a04e);
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform .24s cubic-bezier(.22, .61, .36, 1);
  }
  html.hb-motion .nav a:hover::after,
  html.hb-motion .nav a:focus-visible::after,
  html.hb-motion .hs-nav a:hover::after,
  html.hb-motion .hs-nav a:focus-visible::after {
    transform: scaleX(1);
  }

  /* === 5. カードの反応 ==================================================
   * カード本体の浮き上がりは各ページの CSS が前から持っている。ここでは
   * 持っていないものだけを足す（二重に定義して打ち消し合わないようにする）。
   * 対象はすべて一覧ページのカード。ゲーム画面の中には1つも無い。
   * ------------------------------------------------------------------ */
  html.hb-motion .site-links a,
  html.hb-motion .contact-grid a,
  html.hb-motion .game-link {
    transition:
      transform .2s cubic-bezier(.22, .61, .36, 1),
      border-color .2s ease,
      background-color .2s ease,
      box-shadow .2s ease;
  }
  html.hb-motion .site-links a:hover,
  html.hb-motion .site-links a:focus-visible,
  html.hb-motion .contact-grid a:hover,
  html.hb-motion .contact-grid a:focus-visible,
  html.hb-motion .game-link:hover,
  html.hb-motion .game-link:focus-visible {
    transform: translateY(-2px);
  }

  /* 一覧カードのサムネイルは、カードに乗ったときだけ静かに寄る。
     .shot は overflow:hidden なので、角の丸みを保ったまま拡大される。 */
  html.hb-motion .tool .shot img,
  html.hb-motion .game .shot img {
    transition: transform .38s cubic-bezier(.22, .61, .36, 1);
  }
  html.hb-motion .tool:hover .shot img,
  html.hb-motion .tool:focus-visible .shot img,
  html.hb-motion .game:hover .shot img,
  html.hb-motion .game:focus-visible .shot img {
    transform: scale(1.045);
  }

  /* キーボードで辿ったときも、ホバーと同じだけ反応させる
     （輪郭線そのものは各ページの :focus-visible が出す） */
  html.hb-motion .work:focus-visible,
  html.hb-motion .skill-card:focus-visible {
    transform: translateY(-6px);
  }
  html.hb-motion .tool:focus-visible,
  html.hb-motion .game:focus-visible {
    transform: translateY(-3px);
  }

  /* 技術スタックのチップと、ツール一覧の絞り込みチップ。
     どちらも一覧ページの飾りで、ゲームの操作ボタンではない。 */
  html.hb-motion .chip {
    transition:
      transform .18s cubic-bezier(.22, .61, .36, 1),
      border-color .18s ease,
      background-color .18s ease,
      color .18s ease;
  }
  html.hb-motion .chip:hover { transform: translateY(-2px); }
  html.hb-motion button.chip:active { transform: translateY(0) scale(.97); }

  /* トップのヒーローのボタンと 404 の戻り導線だけ。
     ツールページの .btn（ゲームの操作ボタン）には当てない。 */
  html.hb-motion .hero .btn,
  html.hb-motion a.home {
    transition:
      transform .18s cubic-bezier(.22, .61, .36, 1),
      background-color .18s ease,
      border-color .18s ease,
      color .18s ease,
      opacity .18s ease;
  }
  html.hb-motion .hero .btn:hover,
  html.hb-motion .hero .btn:focus-visible,
  html.hb-motion a.home:hover,
  html.hb-motion a.home:focus-visible { transform: translateY(-2px); }
  html.hb-motion .hero .btn:active,
  html.hb-motion a.home:active { transform: translateY(0) scale(.985); }

  /* 経歴の丸印は、その行が出たときにだけ一度ふくらむ */
  html.hb-motion .career li.hb-reveal.hb-in .dot {
    animation: hb-pop .5s cubic-bezier(.22, .61, .36, 1) both;
    animation-delay: var(--hb-delay, 0ms);
  }
  @keyframes hb-pop {
    0%   { transform: scale(.4); }
    60%  { transform: scale(1.18); }
    100% { transform: none; }
  }

  /* === 6. 読み進みバー（長い読み物ページのみ・JS が挿入） ===============
   * 位置も大きさも固定で、動かすのは scaleX だけ。文書の中身には触らない。
   * ------------------------------------------------------------------ */
  html.hb-motion .hb-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    z-index: 2000;
    transform: scaleX(0);
    transform-origin: 0 50%;
    background: linear-gradient(90deg, #c9a04e, #1a1a2e);
    pointer-events: none;
    will-change: transform;
  }
}
