/* メニュー用書体（自前ホスティング・SIL OFLライセンス: assets/fonts/OFL.txt） */
@font-face {
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/assets/fonts/instrument-serif-latin.woff2') format('woff2');
}

:root {
  --menu-fs: clamp(28px, 4.2vh, 44px);
  --logo-size: clamp(40px, 5vw, 56px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: "Times New Roman", Times, Georgia, "Hiragino Mincho ProN", serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- 背景 ---- */
#bg {
  position: fixed;
  inset: -4vmax;               /* パララックス用に外側へはみ出しておく */
  will-change: transform;
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
#bg canvas { width: 100%; height: 100%; display: block; }

/* ---- 中央ロゴ ---- */
main {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

#logo {
  position: relative;
  z-index: 2;
  width: var(--logo-size);
  height: var(--logo-size);
  background: none;
  border: 0;
  cursor: pointer;
  will-change: transform, opacity, filter;
  transition:
    transform 0.7s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.7s ease,
    filter 0.7s ease;
}
#logo:focus-visible { outline: 1px solid rgba(255,255,255,0.5); outline-offset: 8px; }

#logo-shader { position: absolute; inset: 0; display: block; }
#logo-shader canvas { width: 100%; height: 100%; display: block; }

#logo-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
/* シェーダー起動後はフォールバック画像を隠す */
body.shader-ready #logo-fallback { visibility: hidden; }

/* ---- メニュー ---- */
/* コンテナ自体はフェードさせない(見え方は全て項目側で制御)。
   閉じる際は、最後の項目が消え終わるまで表示を保ってから隠す */
#menu {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 1s;
}
#menu ul { list-style: none; text-align: center; }
/* 閉時 = 「手前」(大きく・ボケて・透明)。開くと奥へ引いて定位置に収まり、
   閉じる時は同じ経路を逆走してこちらへ飛んで来ながら消える。
   ここ(閉じ側)のカーブは出現カーブの時間反転(鏡像)。
   「最初はゆっくり、最後に一気に離れる」= 出現の逆再生に見える */
#menu li {
  opacity: 0;
  transform: scale(1.32);
  filter: blur(9px);
  transition-property: opacity, transform, filter;
  transition-duration: 0.5s, 0.65s, 0.55s;
  transition-timing-function:
    cubic-bezier(0.75, 0, 0.75, 0.9),
    cubic-bezier(0.64, 0, 0.78, 0),
    cubic-bezier(0.75, 0, 0.75, 0.9);
}
#menu a {
  display: inline-block;
  padding: 0.28em 0.9em;
  font-family: 'Instrument Serif', "Times New Roman", Times, serif;
  color: #fff;
  text-decoration: none;
  font-size: var(--menu-fs);
  letter-spacing: 0.02em;
  opacity: 0.92;
  transition: opacity 0.25s ease, transform 0.35s ease, text-shadow 0.35s ease;
}
#menu a:hover, #menu a:focus-visible {
  opacity: 1;
  transform: scale(1.045);
  text-shadow: 0 0 22px rgba(255,255,255,0.55);
  outline: none;
}

/* ---- 状態:メニュー表示 ---- */
body[data-state="menu"] #menu {
  visibility: visible;
  pointer-events: auto;
  transition: visibility 0s;
}
/* 開き側(出現)のカーブ:「最初に一気に動き、最後にゆっくりピントが合う」 */
body[data-state="menu"] #menu li {
  opacity: 1;
  transform: none;
  filter: none;
  transition-timing-function:
    ease,
    cubic-bezier(0.22, 1, 0.36, 1),
    ease;
}

/* 時間差は出現・消失の両方向に同じく効かせる(1番目から順に0.05秒ずつ) */
#menu li:nth-child(1) { transition-delay: 0.05s; }
#menu li:nth-child(2) { transition-delay: 0.10s; }
#menu li:nth-child(3) { transition-delay: 0.15s; }
#menu li:nth-child(4) { transition-delay: 0.20s; }
#menu li:nth-child(5) { transition-delay: 0.25s; }
#menu li:nth-child(6) { transition-delay: 0.30s; }

body[data-state="menu"] #logo {
  opacity: 0.22;
  filter: blur(1px);
  transform: scale(0.92);
  pointer-events: none;
}

/* ---- ロゴのアイドル呼吸 ---- */
@keyframes breathe {
  0%, 100% { scale: 1; }
  50% { scale: 1.06; }
}
body[data-state="logo"] #logo { animation: breathe 6s ease-in-out infinite; }
#logo:hover { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  #logo { animation: none !important; }
  #bg, #logo, #menu, #menu li, #menu a { transition: none !important; }
}

/* JSが無効でも全リンクへ到達できるように */
noscript ~ * #menu, body.no-js #menu { visibility: visible; opacity: 1; }
