/* =========================================================
   クリエット君と仲間たち — ロード画面・キャラ演出・ミニゲーム
   ========================================================= */

/* ---------- ページ内に散りばめるキャラクター ---------- */
.cr-char { user-select: none; -webkit-user-drag: none; }
.cr-char.is-clickable { cursor: pointer; }
.cr-char-boing { animation: cr-boing .7s cubic-bezier(.2, .8, .2, 1) !important; }
@keyframes cr-boing {
    0%   { transform: scale(1); }
    20%  { transform: scale(1.18, .82) translateY(6px); }
    45%  { transform: scale(.9, 1.12) translateY(-34px) rotate(-8deg); }
    70%  { transform: scale(1.06, .94) translateY(0); }
    100% { transform: scale(1); }
}
.cr-heart {
    position: fixed;
    z-index: 120;
    pointer-events: none;
    font-size: 22px;
    animation: cr-heart-up .9s ease-out forwards;
}
@keyframes cr-heart-up {
    from { opacity: 1; transform: translate(0, 0) scale(.6); }
    to   { opacity: 0; transform: translate(var(--dx), -90px) scale(1.3) rotate(var(--rot)); }
}

/* ヒーローの大きなキャラ */
.cr-hero-char {
    position: absolute;
    z-index: 1;
    width: clamp(120px, 17vw, 240px);
    height: auto;
    filter: drop-shadow(6px 8px 0 rgba(0, 0, 0, .15));
}
.cr-hero-char > img { width: 100%; height: auto; display: block; animation: cr-sway 3.2s ease-in-out infinite; transform-origin: 50% 100%; }
.cr-hero-char--l { left: -1%; bottom: 4%; }
.cr-hero-char--r { right: -1%; bottom: 10%; }
.cr-hero-char--r > img { animation-delay: -1.6s; }
@keyframes cr-sway {
    0%, 100% { transform: rotate(-4deg) translateY(0); }
    50%      { transform: rotate(4deg) translateY(-10px); }
}
.cr-floater img { width: clamp(48px, 6vw, 84px); height: auto; display: block; }

/* もこもこ変形するブロブ */
.cr-morph {
    position: absolute;
    z-index: 0;
    pointer-events: none;
    opacity: .45;
    filter: blur(2px);
    animation: cr-morph 12s ease-in-out infinite;
}
@keyframes cr-morph {
    0%, 100% { border-radius: 42% 58% 70% 30% / 45% 45% 55% 55%; transform: rotate(0) scale(1); }
    33%      { border-radius: 70% 30% 46% 54% / 30% 39% 61% 70%; transform: rotate(60deg) scale(1.08); }
    66%      { border-radius: 30% 70% 28% 72% / 62% 30% 70% 38%; transform: rotate(-40deg) scale(.95); }
}

/* セクションからひょっこり顔を出すキャラ */
.cr-peek {
    position: absolute;
    z-index: 5;
    width: clamp(78px, 11vw, 150px);
    height: auto;
    pointer-events: auto;
    animation: cr-sway 3.6s ease-in-out infinite;
    transform-origin: 50% 100%;
    filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, .15));
}
.cr-peek--right { right: -10px; top: -30px; }
.cr-peek--left  { left: -10px; top: -30px; }
@keyframes cr-peek-right { from { opacity: 0; transform: translateX(120px) rotate(30deg); } to { opacity: 1; transform: none; } }
@keyframes cr-peek-left  { from { opacity: 0; transform: translateX(-120px) rotate(-30deg); } to { opacity: 1; transform: none; } }
@media (max-width: 767px) {
    .cr-peek { width: 70px; top: -46px; }
}

/* キャラクターパレード（流れる仲間たち） */
.cr-parade {
    position: relative;
    margin: 0 0 6rem;
    padding: 2.5rem 0 1.5rem;
    background: #fff;
    border: 4px solid #000;
    border-radius: 40px;
    box-shadow: 10px 10px 0 #000;
    overflow: hidden;
}
.cr-parade-title { text-align: center; font-weight: 900; font-size: clamp(1.4rem, 3.4vw, 2.2rem); margin: 0 1rem .4rem; }
.cr-parade-lead { text-align: center; font-weight: 700; color: #4B5563; margin: 0 1rem 1.5rem; }
.cr-parade-track {
    display: flex;
    gap: 18px;
    width: max-content;
    animation: cr-marquee 50s linear infinite;
}
.cr-parade:hover .cr-parade-track { animation-play-state: paused; }
.cr-parade-item {
    flex-shrink: 0;
    width: 150px;
    text-align: center;
}
.cr-parade-item img {
    width: 130px;
    height: 130px;
    object-fit: contain;
    margin: 0 auto;
    display: block;
    transition: transform .35s cubic-bezier(.175, .885, .32, 1.275);
}
.cr-parade-item:nth-child(odd) img { animation: cr-sway 2.8s ease-in-out infinite; }
.cr-parade-item:nth-child(even) img { animation: cr-sway 3.4s ease-in-out infinite reverse; }
.cr-parade-item:hover img { transform: translateY(-14px) scale(1.12); }
.cr-parade-item span {
    display: inline-block;
    margin-top: 6px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 900;
    background: #FFF6CC;
    border: 2px solid #000;
    border-radius: 999px;
    white-space: nowrap;
}

/* スクロール進捗バーの先端を走るクリエット君 */
.cr-progress-kun {
    position: fixed;
    top: -2px;
    left: 0;
    z-index: 101;
    width: 34px;
    height: 34px;
    margin-left: -17px;
    pointer-events: none;
    animation: crl-hop .5s ease-in-out infinite;
}

/* フッターに並ぶ仲間たち */
.cr-footer-chars {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 0;
    pointer-events: none;
}
.cr-footer-chars .cr-char {
    position: absolute;
    bottom: -14px;
    width: clamp(60px, 9vw, 120px);
    height: auto;
    pointer-events: auto;
    animation: cr-sway 3s ease-in-out infinite;
    transform-origin: 50% 100%;
}

/* 案内役のクリエット君（画面左下） */
.cr-buddy {
    position: fixed;
    left: 14px;
    bottom: 10px;
    z-index: 59;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    opacity: 0;
    transform: translateY(140%);
    transition: opacity .3s ease, transform .5s cubic-bezier(.175, .885, .32, 1.275);
    pointer-events: none;
}
.cr-buddy.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.cr-buddy-btn {
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}
.cr-buddy-btn img { width: 78px; height: 78px; display: block; animation: cr-sway 2.6s ease-in-out infinite; transform-origin: 50% 100%; }
.cr-buddy-btn:focus-visible { outline: 3px solid #3B82F6; outline-offset: 2px; border-radius: 12px; }
.cr-buddy-bubble {
    position: relative;
    max-width: 210px;
    margin-bottom: 44px;
    padding: 8px 12px;
    background: #fff;
    border: 3px solid #000;
    border-radius: 16px;
    box-shadow: 3px 3px 0 #000;
    font-size: 12px;
    font-weight: 900;
    line-height: 1.5;
    transform-origin: 0 100%;
}
.cr-buddy-bubble.is-pop { animation: cr-bubble-pop .45s cubic-bezier(.175, .885, .32, 1.275); }
@keyframes cr-bubble-pop { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }
.cr-buddy-bubble a { color: #2563EB; text-decoration: underline; }
.cr-buddy-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 26px;
    height: 26px;
    border: 2px solid #000;
    border-radius: 999px;
    background: #FFD93D;
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
}
@media (max-width: 640px) {
    .cr-buddy-btn img { width: 58px; height: 58px; }
    .cr-buddy-bubble { max-width: 160px; font-size: 11px; margin-bottom: 30px; }
}

/* ---------- ミニゲーム：クリエット君の大ジャンプ ---------- */
.cr-runner { max-width: 960px; margin: 0 auto; }
.cr-runner-stage {
    position: relative;
    border: 4px solid #000;
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 10px 10px 0 #000;
    background: #BDE7FF;
    touch-action: manipulation;
}
.cr-runner-canvas { display: block; width: 100%; height: auto; aspect-ratio: 960 / 420; cursor: pointer; }
.cr-runner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    text-align: center;
    background: rgba(255, 251, 240, .82);
    backdrop-filter: blur(2px);
}
.cr-runner-overlay[hidden] { display: none; }
.cr-runner-hero { width: clamp(70px, 14vw, 130px); height: auto; animation: crl-hop .8s ease-in-out infinite; }
.cr-runner-title { margin: 0; font-weight: 900; font-size: clamp(1.2rem, 3.4vw, 2rem); }
.cr-runner-text { margin: 0; font-weight: 700; font-size: clamp(.8rem, 1.8vw, 1rem); color: #374151; }
.cr-runner-start { margin-top: 6px; padding: .6rem 2rem; background: #FFD93D; border-radius: 999px; font-weight: 900; font-size: 1.1rem; }
.cr-runner-keys { margin: 0; font-size: 11px; font-weight: 700; color: #6B7280; }
.cr-runner-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 18px;
    font-weight: 900;
}
.cr-runner-jumpbtn {
    display: none;
    padding: .7rem 1.6rem;
    background: #EC4899;
    color: #fff;
    border: 4px solid #000;
    border-radius: 999px;
    box-shadow: 4px 4px 0 #000;
    font-weight: 900;
    touch-action: manipulation;
}
.cr-runner-jumpbtn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 #000; }
@media (hover: none) and (pointer: coarse) {
    .cr-runner-jumpbtn { display: inline-block; }
}

/* ---------- 動きを減らす設定 ---------- */
@media (prefers-reduced-motion: reduce) {
    .cr-hero-char > img, .cr-peek, .cr-parade-track, .cr-parade-item img,
    .cr-progress-kun, .cr-footer-chars .cr-char, .cr-buddy-btn img, .cr-morph, .cr-runner-hero {
        animation: none !important;
    }
}

/* 下層ページのヒーローキャラ */
.cr-page-hero-char {
    position: absolute;
    bottom: -10px;
    width: clamp(100px, 13vw, 180px);
    z-index: 0;
}
.cr-page-hero-char img { width: 100%; height: auto; display: block; animation: cr-sway 3.4s ease-in-out infinite; transform-origin: 50% 100%; }
.cr-page-hero-char--l { left: 0; }
.cr-page-hero-char--r { right: 0; }
.cr-page-hero-char--r img { animation-delay: -1.7s; }

/* スマホ：キャンバスが低いので、スタート画面を詰めて表示 */
@media (max-width: 640px) {
    .cr-runner-overlay { gap: 4px; padding: 8px; }
    .cr-runner-hero, .cr-runner-keys { display: none; }
    .cr-runner-text { font-size: 11px; }
    .cr-runner-start { padding: .4rem 1.4rem; font-size: 1rem; margin-top: 2px; }
    .cr-runner-stage { border-radius: 20px; box-shadow: 6px 6px 0 #000; }
}

/* =========================================================
   全ページに散りばめるキャラクター（assets/js/cast.js）
   ========================================================= */

/* カーソルを合わせると、ぷるんと大きく傾く（既存のアニメーションと重ねられる scale / rotate を使用） */
.cr-char {
    transition: scale .35s cubic-bezier(.175, .885, .32, 1.275), rotate .35s cubic-bezier(.175, .885, .32, 1.275), filter .3s;
}
.cr-char.is-hovered {
    scale: 1.14;
    rotate: -7deg;
    filter: drop-shadow(0 0 10px rgba(255, 217, 61, .9)) drop-shadow(5px 6px 0 rgba(0, 0, 0, .18));
}

/* セリフ吹き出し */
.cr-say {
    position: fixed;
    z-index: 140;
    left: 0;
    top: 0;
    max-width: 230px;
    padding: 8px 14px;
    background: #fff;
    border: 3px solid #111;
    border-radius: 18px;
    box-shadow: 4px 4px 0 #111;
    font-weight: 900;
    font-size: 13px;
    line-height: 1.5;
    color: #111;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px) scale(.6);
    transform-origin: var(--tail, 50%) 100%;
    transition: opacity .15s ease, transform .15s ease;
}
.cr-say::after {
    content: "";
    position: absolute;
    left: var(--tail, 50%);
    bottom: -11px;
    width: 14px;
    height: 14px;
    margin-left: -7px;
    background: #fff;
    border-right: 3px solid #111;
    border-bottom: 3px solid #111;
    transform: rotate(45deg);
}
.cr-say.is-below { transform-origin: var(--tail, 50%) 0; }
.cr-say.is-below::after { bottom: auto; top: -11px; transform: rotate(225deg); }
.cr-say.is-show {
    opacity: 1;
    transform: none;
    animation: cr-say-pop .45s cubic-bezier(.175, .885, .32, 1.275);
}
@keyframes cr-say-pop {
    0%   { transform: translateY(8px) scale(.4); }
    60%  { transform: translateY(-3px) scale(1.06); }
    100% { transform: none; }
}

/* いろいろな動き */
@keyframes cr-a-bob   { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-18px); } }
@keyframes cr-a-swing { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(12deg); } }
@keyframes cr-a-jelly {
    0%, 100% { transform: scale(1, 1); }
    25% { transform: scale(1.1, .9); }
    50% { transform: scale(.92, 1.08) translateY(-6px); }
    75% { transform: scale(1.04, .96); }
}
@keyframes cr-a-hop {
    0%, 55%, 100% { transform: translateY(0) scale(1, 1); }
    10% { transform: translateY(0) scale(1.12, .88); }
    30% { transform: translateY(-38px) scale(.94, 1.06) rotate(-6deg); }
    48% { transform: translateY(0) scale(1.08, .92); }
}
@keyframes cr-a-drift {
    0%, 100% { transform: translate(0, 0) rotate(-4deg); }
    33% { transform: translate(10px, -14px) rotate(5deg); }
    66% { transform: translate(-8px, -6px) rotate(-2deg); }
}
@keyframes cr-a-tilt { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-14deg); } 40% { transform: rotate(10deg); } 60% { transform: rotate(0); } }
.cr-a-bob   { animation: cr-a-bob 3s ease-in-out infinite; }
.cr-a-swing { animation: cr-a-swing 2.6s ease-in-out infinite; transform-origin: 50% 0; }
.cr-a-jelly { animation: cr-a-jelly 1.8s ease-in-out infinite; transform-origin: 50% 100%; }
.cr-a-hop   { animation: cr-a-hop 2.2s ease-in-out infinite; transform-origin: 50% 100%; }
.cr-a-drift { animation: cr-a-drift 5s ease-in-out infinite; }
.cr-a-tilt  { animation: cr-a-tilt 3.4s ease-in-out infinite; transform-origin: 50% 100%; }

/* 左右の余白のキャラ：見えたらくるっと登場 */
.cr-cast-layer { position: absolute; left: 0; top: 0; width: 100%; height: 0; z-index: 4; pointer-events: none; }
.cr-cast {
    position: absolute;
    pointer-events: auto;
    opacity: 0;
    transform: scale(.3) rotate(-40deg);
    transition: opacity .4s ease, transform .7s cubic-bezier(.175, .885, .32, 1.275);
}
.cr-cast.is-in { opacity: 1; transform: none; }
.cr-cast img { width: 100%; height: auto; display: block; filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, .15)); }

/* 見出しまわりのキャラ */
.cr-title-kun {
    display: block;
    width: 96px;
    height: 96px;
    margin: 0 auto 8px;
    animation: cr-a-hop 2.4s ease-in-out infinite;
    transform-origin: 50% 100%;
}
.cr-h1-buddy {
    display: inline-block;
    width: 1.4em;
    height: 1.4em;
    margin-left: .2em;
    vertical-align: middle;
    animation: cr-a-hop 2.4s ease-in-out infinite;
    transform-origin: 50% 100%;
}

/* 画面のはしからひょっこり */
.cr-edge {
    position: fixed;
    z-index: 58;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
    transition: transform .6s cubic-bezier(.175, .885, .32, 1.275);
}
.cr-edge img { width: clamp(80px, 11vw, 130px); height: auto; filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, .15)); }
.cr-edge--right { right: 0; flex-direction: row-reverse; transform: translateX(110%) rotate(25deg); }
.cr-edge--left  { left: 0; transform: translateX(-110%) rotate(-25deg); }
.cr-edge--right img { margin-right: -24px; }
.cr-edge--left img  { margin-left: -24px; scale: -1 1; }
.cr-edge.is-in { transform: none; }
.cr-edge.is-in img { animation: cr-a-tilt 1.2s ease-in-out .5s 2; }
.cr-edge-say {
    padding: 6px 12px;
    background: #fff;
    border: 3px solid #111;
    border-radius: 16px;
    box-shadow: 3px 3px 0 #111;
    font-weight: 900;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transform: scale(.4);
    transition: opacity .2s ease .45s, transform .35s cubic-bezier(.175, .885, .32, 1.275) .45s;
}
.cr-edge.is-in .cr-edge-say { opacity: 1; transform: none; }

/* マウスを追うキラキラ */
.cr-spark {
    position: fixed;
    z-index: 150;
    pointer-events: none;
    font-size: 14px;
    font-weight: 900;
    line-height: 1;
    margin: -7px 0 0 -7px;
    animation: cr-spark .8s ease-out forwards;
}
@keyframes cr-spark {
    from { opacity: 1; transform: translate(0, 0) scale(1) rotate(0); }
    to   { opacity: 0; transform: translate(var(--dx), 28px) scale(.3) rotate(160deg); }
}

/* フッターのふちを歩くクリエット君 */
.cr-walker {
    position: absolute;
    bottom: -12px;
    left: 0;
    width: clamp(54px, 7vw, 84px);
    height: auto;
    pointer-events: auto;
    animation: cr-walk 26s linear infinite;
}
.cr-walker img { width: 100%; height: auto; display: block; animation: cr-a-hop .55s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes cr-walk {
    0%      { left: -8%;  scale: 1 1; }
    49.9%   { left: 102%; scale: 1 1; }
    50%     { left: 102%; scale: -1 1; }
    99.9%   { left: -8%;  scale: -1 1; }
    100%    { left: -8%;  scale: 1 1; }
}

/* 背景をゆっくりのぼる双葉と星 */
.cr-sky { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.cr-sky span {
    position: absolute;
    bottom: -40px;
    left: calc(var(--x) * 1%);
    font-size: calc(14px + var(--s) * 1px);
    opacity: .28;
    animation: cr-rise calc(18s + var(--d) * 1s) linear infinite;
    animation-delay: calc(var(--d) * -1.7s);
}
@keyframes cr-rise {
    from { transform: translateY(0) rotate(0); }
    to   { transform: translateY(-115vh) rotate(260deg); }
}

@media (prefers-reduced-motion: reduce) {
    .cr-a-bob, .cr-a-swing, .cr-a-jelly, .cr-a-hop, .cr-a-drift, .cr-a-tilt,
    .cr-title-kun, .cr-h1-buddy, .cr-walker, .cr-walker img, .cr-sky span, .cr-edge.is-in img { animation: none !important; }
    .cr-cast { transition: none; opacity: 1; transform: none; }
    .cr-char { transition: none; }
}

/* 余白が狭い画面：はしから半分だけ顔を出し、カーソルを合わせると出てくる */
.cr-cast--peek { transition: opacity .4s ease, transform .5s cubic-bezier(.175, .885, .32, 1.275), translate .4s cubic-bezier(.175, .885, .32, 1.275); }
.cr-cast--peek.cr-cast--left  { rotate: 18deg; }
.cr-cast--peek.cr-cast--right { rotate: -18deg; }
.cr-cast--peek.cr-cast--left:hover  { translate: 46px 0; }
.cr-cast--peek.cr-cast--right:hover { translate: -46px 0; }
