/*
 * 🎆 システム崩壊アニメーション効果
 * クラシック映画風サイト崩壊エフェクト
 */

/* =============================================================================
   崩壊画像モーダル
   ============================================================================= */

.balus-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.balus-modal.show {
    opacity: 1;
    pointer-events: all;
}

.balus-image {
    max-width: 80vw;
    max-height: 80vh;
    object-fit: contain;
    animation: balus-appear 0.8s ease-out;
}

@keyframes balus-appear {
    0% {
        transform: scale(0.3) rotate(-10deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotate(5deg);
        opacity: 0.8;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* =============================================================================
   青い光の放射エフェクト
   ============================================================================= */

.blue-radial-light {
    position: absolute;
    top: 55%;
    left: 45%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: radial-gradient(circle at center,
        rgba(0, 150, 255, 0.8) 0%,
        rgba(0, 100, 255, 0.6) 30%,
        rgba(0, 50, 255, 0.3) 60%,
        transparent 100%);
    opacity: 0;
    z-index: 9998;
    pointer-events: none;
}

.blue-radial-light.active {
    animation: blue-light-expand 2s ease-out forwards;
}

@keyframes blue-light-expand {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    40% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(5);
    }
    60% {
        opacity: 0.6;
        transform: translate(-50%, -50%) scale(10);
    }
    80% {
        opacity: 0.3;
        transform: translate(-50%, -50%) scale(20);
        box-shadow: 0 0 100px rgba(0, 150, 255, 0.6);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(30);
        box-shadow: 0 0 200px rgba(0, 150, 255, 0.2);
    }
}

/* 複数の光線エフェクト */
.blue-radial-light::before,
.blue-radial-light::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle at center,
        rgba(100, 200, 255, 0.6) 0%,
        rgba(50, 150, 255, 0.4) 40%,
        transparent 70%);
}

.blue-radial-light::before {
    width: 80px;
    height: 80px;
    animation: blue-light-pulse-1 2s ease-out 0.3s forwards;
}

.blue-radial-light::after {
    width: 120px;
    height: 120px;
    animation: blue-light-pulse-2 2s ease-out 0.6s forwards;
}

@keyframes blue-light-pulse-1 {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0);
    }
    30% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1);
    }
    70% {
        opacity: 0.4;
        transform: translate(-50%, -50%) scale(8);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(15);
    }
}

@keyframes blue-light-pulse-2 {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0);
    }
    40% {
        opacity: 0.6;
        transform: translate(-50%, -50%) scale(1);
    }
    80% {
        opacity: 0.2;
        transform: translate(-50%, -50%) scale(6);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(12);
    }
}

/* =============================================================================
   宝石風正八面体アニメーション
   ============================================================================= */

.jewel-octahedron {
    position: absolute;
    left: 50%;
    bottom: -100px; /* 画面下から開始 */
    width: 80px;
    height: 80px;
    transform: translateX(-50%);
    z-index: 9999;
    pointer-events: none;
    opacity: 0; /* 初期状態は非表示 */
}

.jewel-octahedron.active {
    animation: jewel-ascend 3s linear forwards;
}

/* 3D立方体宝石の構造 */
.jewel-cube {
    position: relative;
    width: 120px;
    height: 120px;
    transform-style: preserve-3d;
    transform: rotateX(45deg) rotateY(45deg); /* ダイヤモンド角度 */
    animation: jewel-rotate 2s linear infinite; /* 高速回転のみ */
}

.cube-face {
    position: absolute;
    width: 120px;
    height: 120px;
    background: linear-gradient(135deg,
        rgba(180, 200, 255, 0.4) 0%,
        rgba(30, 58, 138, 0.8) 20%,
        rgba(55, 80, 160, 0.6) 40%,
        rgba(80, 110, 180, 0.4) 60%,
        rgba(55, 80, 160, 0.6) 80%,
        rgba(20, 40, 100, 0.9) 100%);
    border: 2px solid rgba(30, 58, 138, 0.6);
    box-shadow:
        inset 0 0 15px rgba(255, 255, 255, 0.2), /* 内部反射 */
        inset 0 5px 2px rgba(255, 255, 255, 0.4), /* 上部光沢ライン */
        0 0 35px rgba(30, 58, 138, 0.8), /* 外部グロー */
        0 0 5px rgba(30, 58, 138, 0.4); /* エッジ光 */
    backdrop-filter: blur(1px); /* 軽量ガラス効果 */
}


/* 立方体の6面配置（面ごとの光の明暗差を強化） */
.cube-front  {
    transform: translateZ(60px);
    opacity: 0.9; /* 少し透明に */
    filter: brightness(1.2);
    box-shadow:
        inset 0 0 30px rgba(255, 255, 255, 0.5),
        0 0 40px rgba(30, 58, 138, 1),
        0 0 80px rgba(30, 58, 138, 0.5);
}

.cube-back   {
    transform: rotateY(180deg) translateZ(60px);
    opacity: 0.3; /* 後ろ面はより透明に */
    filter: brightness(0.7);
}

.cube-right  {
    transform: rotateY(90deg) translateZ(60px);
    opacity: 0.75; /* 透明度を下げる */
    filter: brightness(1.0);
}

.cube-left   {
    transform: rotateY(-90deg) translateZ(60px);
    opacity: 0.65; /* 透明度を下げる */
    filter: brightness(0.9);
}

.cube-top    {
    transform: rotateX(90deg) translateZ(60px);
    opacity: 0.8; /* 透明度を下げる */
    filter: brightness(1.1);
    box-shadow:
        inset 0 0 25px rgba(255, 255, 255, 0.4),
        0 0 35px rgba(30, 58, 138, 0.9),
        0 0 70px rgba(30, 58, 138, 0.4);
}

.cube-bottom {
    transform: rotateX(-90deg) translateZ(60px);
    opacity: 0.5; /* 透明度を下げる */
    filter: brightness(0.8);
}

/* 上昇アニメーション */
@keyframes jewel-ascend {
    0% {
        opacity: 0;
        bottom: -100px;
        filter: blur(0px);
        box-shadow: 0 0 50px rgba(30, 58, 138, 0.8);
    }
    10% {
        opacity: 1;
        filter: blur(0px);
        box-shadow: 0 0 80px rgba(30, 58, 138, 0.9);
    }
    50% {
        opacity: 1;
        filter: blur(1px);
        box-shadow: 0 0 120px rgba(30, 58, 138, 1);
    }
    90% {
        opacity: 0.8;
        filter: blur(2px);
        box-shadow: 0 0 150px rgba(30, 58, 138, 0.6);
    }
    100% {
        opacity: 0;
        bottom: 120vh;
        filter: blur(3px);
        box-shadow: 0 0 200px rgba(30, 58, 138, 0.3);
    }
}

/* 美しい3軸回転アニメーション */
@keyframes jewel-rotate {
    0% {
        transform: rotateX(45deg) rotateY(45deg) rotateZ(0deg);
    }
    25% {
        transform: rotateX(135deg) rotateY(135deg) rotateZ(90deg);
    }
    50% {
        transform: rotateX(225deg) rotateY(225deg) rotateZ(180deg);
    }
    75% {
        transform: rotateX(315deg) rotateY(315deg) rotateZ(270deg);
    }
    100% {
        transform: rotateX(405deg) rotateY(405deg) rotateZ(360deg);
    }
}


/* 控えめな背景光線（正八面体の形状を邪魔しない程度） */
.jewel-octahedron::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px; /* 140px → 100px に縮小 */
    height: 100px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle at center,
        rgba(0, 200, 255, 0.25) 0%,
        rgba(50, 180, 255, 0.2) 30%,
        rgba(100, 220, 255, 0.1) 50%,
        transparent 70%);
    border-radius: 50%;
    animation: jewel-energy-pulse 0.8s ease-in-out infinite alternate;
    z-index: -1;
    filter: blur(1px);
}

.jewel-octahedron::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150px; /* 220px → 150px に縮小 */
    height: 150px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle at center,
        rgba(120, 240, 255, 0.15) 0%,
        rgba(80, 200, 255, 0.1) 20%,
        rgba(40, 160, 255, 0.05) 40%,
        transparent 60%);
    border-radius: 50%;
    animation: jewel-energy-pulse 1.2s ease-in-out infinite alternate;
    z-index: -2;
    filter: blur(2px);
}

/* 内部光源削除: 純粋な正八面体のため */

@keyframes jewel-energy-pulse {
    0% {
        opacity: 0.3;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1.2);
    }
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .jewel-octahedron {
        width: 60px;
        height: 60px;
    }


    /* モバイル用の正三角形サイズ調整 */
    .octahedron-face {
        border-width: 22px 12.73px 0 12.73px; /* 小さくした正三角形 */
    }

    .face-bottom-1, .face-bottom-2, .face-bottom-3, .face-bottom-4 {
        border-width: 0 12.73px 22px 12.73px;
    }

    /* 3D配置の距離調整 */
    .face-top-1, .face-top-2, .face-top-3, .face-top-4 {
        transform: rotateX(-35.26deg) rotateY(var(--rotation)) translateZ(18px);
    }

    .face-bottom-1, .face-bottom-2, .face-bottom-3, .face-bottom-4 {
        transform: rotateX(35.26deg) rotateY(var(--rotation)) translateZ(18px);
    }

    /* 光の演出も縮小 */
    .jewel-octahedron::before {
        width: 100px;
        height: 100px;
    }

    .jewel-octahedron::after {
        width: 160px;
        height: 160px;
    }

    .octahedron-core::before {
        width: 15px;
        height: 15px;
    }
}

@media (max-width: 420px) {
    .jewel-octahedron {
        width: 50px;
        height: 50px;
    }

    .octahedron-face {
        border-width: 18px 10.39px 0 10.39px;
    }

    .face-bottom-1, .face-bottom-2, .face-bottom-3, .face-bottom-4 {
        border-width: 0 10.39px 18px 10.39px;
    }

    .jewel-octahedron::before {
        width: 80px;
        height: 80px;
    }

    .jewel-octahedron::after {
        width: 120px;
        height: 120px;
    }
}

/* =============================================================================
   サイト崩壊アニメーション
   ============================================================================= */

/* 崩壊モード時の全体コンテナ */
.balus-destruction-mode {
    overflow: hidden !important;
    position: relative;
}

/* 段階的崩壊クラス */
.balus-collapse-1 {
    animation: balus-shake 0.8s ease-in-out;
}

.balus-collapse-2 {
    animation: balus-tilt 1.2s ease-in-out forwards;
}

.balus-collapse-3 {
    animation: balus-fall 1.5s ease-in forwards;
}

.balus-collapse-final {
    animation: balus-disintegrate 2s ease-in forwards;
}

/* 震動エフェクト */
@keyframes balus-shake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    10% { transform: translate(-2px, -1px) rotate(-0.5deg); }
    20% { transform: translate(2px, 1px) rotate(0.5deg); }
    30% { transform: translate(-1px, 2px) rotate(-0.3deg); }
    40% { transform: translate(1px, -2px) rotate(0.3deg); }
    50% { transform: translate(-2px, 1px) rotate(-0.2deg); }
    60% { transform: translate(2px, -1px) rotate(0.2deg); }
    70% { transform: translate(-1px, -2px) rotate(-0.1deg); }
    80% { transform: translate(1px, 2px) rotate(0.1deg); }
    90% { transform: translate(-2px, -1px) rotate(-0.05deg); }
}

/* 傾斜エフェクト */
@keyframes balus-tilt {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 1;
    }
    25% {
        transform: rotate(-2deg) scale(0.98);
        opacity: 0.9;
    }
    50% {
        transform: rotate(3deg) scale(0.95);
        opacity: 0.8;
    }
    75% {
        transform: rotate(-5deg) scale(0.9);
        opacity: 0.7;
    }
    100% {
        transform: rotate(-8deg) scale(0.85);
        opacity: 0.6;
    }
}

/* 落下エフェクト */
@keyframes balus-fall {
    0% {
        transform: rotate(-8deg) scale(0.85) translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: rotate(-15deg) scale(0.7) translateY(50px);
        opacity: 0.5;
    }
    60% {
        transform: rotate(-25deg) scale(0.5) translateY(200px);
        opacity: 0.3;
    }
    100% {
        transform: rotate(-45deg) scale(0.2) translateY(1000px);
        opacity: 0;
    }
}

/* 崩壊エフェクト */
@keyframes balus-disintegrate {
    0% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
        filter: blur(0px);
    }
    25% {
        transform: scale(0.9) rotate(-5deg);
        opacity: 0.8;
        filter: blur(1px);
    }
    50% {
        transform: scale(0.7) rotate(-15deg);
        opacity: 0.6;
        filter: blur(3px);
    }
    75% {
        transform: scale(0.4) rotate(-30deg);
        opacity: 0.3;
        filter: blur(5px);
    }
    100% {
        transform: scale(0) rotate(-90deg) translateY(2000px);
        opacity: 0;
        filter: blur(10px);
    }
}

/* =============================================================================
   グリッチエフェクト
   ============================================================================= */

.balus-glitch {
    animation: balus-glitch-effect 0.3s infinite;
}

@keyframes balus-glitch-effect {
    0% {
        transform: translate(0);
        filter: hue-rotate(0deg);
    }
    20% {
        transform: translate(-2px, 2px);
        filter: hue-rotate(90deg);
    }
    40% {
        transform: translate(-2px, -2px);
        filter: hue-rotate(180deg);
    }
    60% {
        transform: translate(2px, 2px);
        filter: hue-rotate(270deg);
    }
    80% {
        transform: translate(2px, -2px);
        filter: hue-rotate(360deg);
    }
    100% {
        transform: translate(0);
        filter: hue-rotate(0deg);
    }
}

/* =============================================================================
   システムクラッシュ画面
   ============================================================================= */

.balus-crash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    color: #ff4444;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    z-index: 10000;
    font-family: 'Courier New', monospace;
    font-size: 1.5rem;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem 1rem;
    box-sizing: border-box;
}

.balus-crash-screen.show {
    opacity: 1;
    pointer-events: all;
}

.balus-crash-title {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: 1rem;
    animation: balus-crash-blink 1s infinite;
    padding: 1rem 0;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 8px;
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
    border: 2px solid rgba(255, 68, 68, 0.3);
}

.balus-crash-message {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    line-height: 1.6;
}

@keyframes balus-crash-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* =============================================================================
   コマンド解説セクション
   ============================================================================= */

.balus-command-explanation {
    margin-top: 3rem;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid #ff6666;
    border-radius: 10px;
    max-width: 800px;
    opacity: 0;
    transform: translateY(20px);
    animation: explanationFadeIn 1s ease-out 2s forwards;
}

.command-explanation-title {
    font-size: 1.8rem;
    font-weight: bold;
    color: #ffff00;
    margin-bottom: 1.5rem;
    text-align: center;
    text-shadow: 0 0 10px rgba(255, 255, 0, 0.5);
}

.command-breakdown {
    background: rgba(0, 0, 0, 0.8);
    padding: 1.5rem;
    border-radius: 8px;
    border-left: 4px solid #ff4444;
}

.command-line {
    font-size: 1.6rem;
    font-weight: bold;
    color: #00ff00;
    margin-bottom: 1.5rem;
    padding: 0.8rem;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 6px;
    border: 1px solid #00ff00;
    text-shadow: 0 0 8px rgba(0, 255, 0, 0.6);
    letter-spacing: 2px;
}

.command-parts {
    margin-bottom: 1.5rem;
}

.command-part {
    display: flex;
    align-items: center;
    margin: 0.8rem 0;
    padding: 0.6rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
}

.command-part:nth-child(1) { border-left-color: #ff6b5d; animation-delay: 2.2s; }
.command-part:nth-child(2) { border-left-color: #ffc843; animation-delay: 2.4s; }
.command-part:nth-child(3) { border-left-color: #32d74b; animation-delay: 2.6s; }
.command-part:nth-child(4) { border-left-color: #007aff; animation-delay: 2.8s; }
.command-part:nth-child(5) { border-left-color: #af52de; animation-delay: 3.0s; }

.command-token {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    margin-right: 1.2rem;
    min-width: 80px;
    text-align: center;
    font-size: 1.1rem;
}

.command-token.sudo {
    background: linear-gradient(135deg, #ff6b5d, #ff4a42);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.command-token.rm {
    background: linear-gradient(135deg, #ffc843, #ffb018);
    color: #333;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.3);
}

.command-token.option {
    background: linear-gradient(135deg, #32d74b, #1fc932);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.command-token.path {
    background: linear-gradient(135deg, #af52de, #8e44ad);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.command-desc {
    flex: 1;
    color: #cccccc;
    font-size: 1.1rem;
    line-height: 1.4;
}

.command-result {
    display: flex;
    align-items: center;
    margin-top: 1.5rem;
    padding: 1rem;
    background: linear-gradient(135deg, rgba(255, 68, 68, 0.2), rgba(255, 0, 0, 0.1));
    border: 2px solid #ff4444;
    border-radius: 8px;
    animation: resultPulse 2s ease-in-out infinite 3.5s;
}

.result-arrow {
    font-size: 1.5rem;
    color: #ff4444;
    margin-right: 1rem;
    text-shadow: 0 0 10px rgba(255, 68, 68, 0.8);
}

.result-text {
    font-size: 1.3rem;
    font-weight: bold;
    color: #ff6666;
    text-shadow: 0 0 8px rgba(255, 102, 102, 0.6);
}

/* アニメーション定義 */
@keyframes explanationFadeIn {
    0% {
        opacity: 0;
        transform: translateY(30px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes resultPulse {
    0%, 100% {
        box-shadow: 0 0 20px rgba(255, 68, 68, 0.3);
        border-color: #ff4444;
    }
    50% {
        box-shadow: 0 0 40px rgba(255, 68, 68, 0.8);
        border-color: #ff6666;
    }
}

/* =============================================================================
   グライダー滑空アニメーション
   ============================================================================= */

.glider-flyby {
    position: absolute;
    width: 128px;
    height: 128px;
    top: 50%;
    right: -150px; /* 画面外から開始 */
    z-index: 10001; /* クラッシュ画面より前面 */
    opacity: 0;
    transform-origin: center center;
    pointer-events: none;
}

.glider-flyby.flying {
    animation: glider-flyby-animation 5s linear forwards;
}

@keyframes glider-flyby-animation {
    0% {
        transform: translateX(0) translateY(0) rotate(0deg);
        right: -150px;
        opacity: 0;
    }
    3% {
        opacity: 1;
    }
    10% {
        transform: translateX(-300px) translateY(15px) rotate(-2deg);
    }
    25% {
        transform: translateX(-600px) translateY(25px) rotate(-3deg);
    }
    50% {
        transform: translateX(-900px) translateY(35px) rotate(-2deg);
    }
    75% {
        transform: translateX(-1200px) translateY(45px) rotate(-1deg);
        opacity: 0.8;
    }
    90% {
        transform: translateX(-1400px) translateY(50px) rotate(0deg);
        opacity: 0.4;
    }
    100% {
        transform: translateX(-1600px) translateY(55px) rotate(0deg);
        opacity: 0;
    }
}


/* =============================================================================
   レスポンシブ対応
   ============================================================================= */

@media (max-width: 768px) {
    .balus-image {
        max-width: 90vw;
        max-height: 70vh;
    }

    .blue-radial-light {
        top: 54%;
        left: 44%;
    }

    .jewel-octahedron {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    .balus-crash-screen {
        padding: 1.5rem 0.8rem;
        font-size: 1.3rem;
    }

    .balus-crash-title {
        font-size: 2rem;
        margin-bottom: 1.5rem;
        padding: 1rem 0;
        background: rgba(0, 0, 0, 0.9);
        border-radius: 8px;
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .balus-crash-message {
        font-size: 1rem;
        padding: 0 1rem;
        margin-bottom: 1.5rem;
    }

    /* モバイル対応：コマンド解説セクション */
    .balus-command-explanation {
        margin-top: 2rem;
        padding: 1.5rem;
        max-width: 95vw;
    }

    .command-explanation-title {
        font-size: 1.4rem;
        margin-bottom: 1rem;
    }

    .command-breakdown {
        padding: 1rem;
    }

    .command-line {
        font-size: 1.2rem;
        padding: 0.6rem;
        letter-spacing: 1px;
    }

    .command-part {
        flex-direction: column;
        align-items: flex-start;
        margin: 0.6rem 0;
        padding: 0.8rem;
    }

    .command-token {
        margin-right: 0;
        margin-bottom: 0.5rem;
        min-width: auto;
        padding: 0.4rem 0.6rem;
        font-size: 1rem;
    }

    .command-desc {
        font-size: 1rem;
        margin-left: 0;
    }

    .command-result {
        padding: 0.8rem;
        flex-direction: column;
        text-align: center;
    }

    .result-arrow {
        margin-right: 0;
        margin-bottom: 0.5rem;
    }

    .result-text {
        font-size: 1.1rem;
    }
}

/* 小画面（420px以下）での更なる最適化 */
@media (max-width: 420px) {
    .blue-radial-light {
        top: 53%;
        left: 45%;
    }

    .jewel-octahedron {
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    .balus-crash-screen {
        padding: 1rem 0.5rem;
        font-size: 1.2rem;
    }

    .balus-crash-title {
        font-size: 1.6rem;
        margin-bottom: 1rem;
        padding: 0.8rem 0;
    }

    .balus-crash-message {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    .balus-command-explanation {
        padding: 1rem;
        margin-top: 1.5rem;
    }

    .command-explanation-title {
        font-size: 1.2rem;
        line-height: 1.3;
    }

    .command-line {
        font-size: 1.1rem;
        padding: 0.5rem;
        word-break: break-all;
    }

    .command-token {
        font-size: 0.9rem;
        padding: 0.3rem 0.5rem;
    }

    .command-desc {
        font-size: 0.95rem;
        line-height: 1.3;
    }

    .result-text {
        font-size: 1rem;
        line-height: 1.3;
    }
}

/* グライダーレスポンシブ対応 */
@media (max-width: 768px) {
    .glider-flyby {
        top: 60%; /* タブレット：中央やや下寄り */
        width: 100px;
        height: 100px;
    }
}

@media (max-width: 420px) {
    .glider-flyby {
        top: 70%; /* モバイル：下寄り配置 */
        width: 80px;
        height: 80px;
    }
}

/* =============================================================================
   個別要素崩落アニメーション（hinge効果）
   ============================================================================= */

/* Animate.css inspired hinge animation */
.collapse-hinge {
    animation: hingeCollapse 2s ease-in-out forwards;
    transform-origin: top left;
}

@keyframes hingeCollapse {
    0% {
        transform-origin: top left;
        animation-timing-function: ease-in-out;
    }
    20%, 60% {
        transform: rotate3d(0, 0, 1, 80deg);
        transform-origin: top left;
        animation-timing-function: ease-in-out;
    }
    40%, 80% {
        transform: rotate3d(0, 0, 1, 60deg);
        transform-origin: top left;
        animation-timing-function: ease-in-out;
        opacity: 1;
    }
    to {
        transform: translate3d(0, 700px, 0);
        opacity: 0;
    }
}

/* 要素タイプ別の崩落バリエーション */
.collapse-hinge-left {
    animation: hingeCollapseLeft 1.8s ease-in-out forwards;
    transform-origin: top left;
}

.collapse-hinge-right {
    animation: hingeCollapseRight 1.8s ease-in-out forwards;
    transform-origin: top right;
}

@keyframes hingeCollapseLeft {
    0% {
        transform-origin: top left;
    }
    20%, 60% {
        transform: rotate3d(0, 0, 1, 80deg);
        transform-origin: top left;
    }
    40%, 80% {
        transform: rotate3d(0, 0, 1, 60deg);
        transform-origin: top left;
        opacity: 1;
    }
    to {
        transform: translate3d(-100px, 700px, 0) rotate3d(0, 0, 1, 90deg);
        opacity: 0;
    }
}

@keyframes hingeCollapseRight {
    0% {
        transform-origin: top right;
    }
    20%, 60% {
        transform: rotate3d(0, 0, 1, -80deg);
        transform-origin: top right;
    }
    40%, 80% {
        transform: rotate3d(0, 0, 1, -60deg);
        transform-origin: top right;
        opacity: 1;
    }
    to {
        transform: translate3d(100px, 700px, 0) rotate3d(0, 0, 1, -90deg);
        opacity: 0;
    }
}

/* 個別要素用の段階的遅延クラス */
.collapse-delay-1 { animation-delay: 0.1s; }
.collapse-delay-2 { animation-delay: 0.2s; }
.collapse-delay-3 { animation-delay: 0.3s; }
.collapse-delay-4 { animation-delay: 0.4s; }
.collapse-delay-5 { animation-delay: 0.5s; }
.collapse-delay-6 { animation-delay: 0.6s; }
.collapse-delay-7 { animation-delay: 0.7s; }
.collapse-delay-8 { animation-delay: 0.8s; }

/* 要素サイズ別の落下距離調整 */
.collapse-small {
    --collapse-distance: 500px;
}
.collapse-medium {
    --collapse-distance: 700px;
}
.collapse-large {
    --collapse-distance: 900px;
}

/* GPU加速最適化 */
.collapse-hinge,
.collapse-hinge-left,
.collapse-hinge-right {
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* =============================================================================
   アクセシビリティ対応
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
    .balus-modal,
    .balus-collapse-1,
    .balus-collapse-2,
    .balus-collapse-3,
    .balus-collapse-final,
    .balus-glitch,
    .balus-crash-screen,
    .glider-flyby {
        animation: none !important;
        transition: none !important;
    }

    .glider-flyby {
        display: none; /* アニメーション無効時はグライダーを非表示 */
    }

    .balus-modal.show {
        opacity: 1;
    }

    .balus-crash-screen.show {
        opacity: 1;
    }
}