/* =====================================
   アニメーション定義
   ===================================== */

/* キーフレームアニメーション */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(255, 167, 38, 0.3);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 6px 25px rgba(255, 167, 38, 0.5);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(255, 167, 38, 0.3);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-50px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(50px);
    }
}

@keyframes wobble {
    0% {
        transform: translateX(0%);
    }
    15% {
        transform: translateX(-25px) rotate(-5deg);
    }
    30% {
        transform: translateX(20px) rotate(3deg);
    }
    45% {
        transform: translateX(-15px) rotate(-3deg);
    }
    60% {
        transform: translateX(10px) rotate(2deg);
    }
    75% {
        transform: translateX(-5px) rotate(-1deg);
    }
    100% {
        transform: translateX(0%);
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}

@keyframes glow {
    0% {
        box-shadow: 0 0 5px rgba(102, 126, 234, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(102, 126, 234, 0.8), 0 0 30px rgba(102, 126, 234, 0.6);
    }
    100% {
        box-shadow: 0 0 5px rgba(102, 126, 234, 0.5);
    }
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-20px);
    }
}

@keyframes rotateIn {
    from {
        opacity: 0;
        transform: rotate(-200deg) scale(0.8);
    }
    to {
        opacity: 1;
        transform: rotate(0) scale(1);
    }
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes rubberBand {
    0% {
        transform: scale(1);
    }
    30% {
        transform: scaleX(1.25) scaleY(0.75);
    }
    40% {
        transform: scaleX(0.75) scaleY(1.25);
    }
    50% {
        transform: scaleX(1.15) scaleY(0.85);
    }
    65% {
        transform: scaleX(0.95) scaleY(1.05);
    }
    75% {
        transform: scaleX(1.05) scaleY(0.95);
    }
    100% {
        transform: scale(1);
    }
}

/* =====================================
   インタラクション用アニメーションクラス
   ===================================== */

/* ドラッグ中のアニメーション */
.dragging {
    opacity: 0.8;
    transform: rotate(5deg) scale(1.1);
    z-index: 1000 !important;
    pointer-events: none;
    animation: float 0.8s ease-in-out infinite;
}

/* ドロップ可能エリアのアニメーション */
.drop-zone.drag-over {
    animation: glow 1s ease-in-out infinite;
}

/* ブロック追加時のアニメーション */
.block-added {
    animation: slideInRight 0.5s ease, glow 0.5s ease;
}

/* ブロック削除時のアニメーション */
.block-removing {
    animation: slideOutRight 0.3s ease forwards;
}

/* エラー時のアニメーション */
.error-shake {
    animation: shake 0.6s ease-in-out;
}

/* 成功時のアニメーション */
.success-bounce {
    animation: bounce 0.8s ease;
}

/* ロボット移動アニメーション */
.character.moving {
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.character.turning {
    animation: wobble 0.6s ease;
}

/* ゴール到達時のアニメーション */
.goal.reached {
    animation: rubberBand 1s ease, glow 2s ease-in-out infinite;
}

/* ブロック実行中のハイライト */
.program-block.executing {
    animation: glow 0.8s ease-in-out;
    transform: scale(1.05);
}

/* レベルクリア時のセレブレーションアニメーション */
.celebration-active {
    animation: zoomIn 0.8s ease;
}

/* ローディングアニメーション */
.loading {
    position: relative;
    overflow: hidden;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* パーティクル効果 */
.particle {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
}

.particle.star {
    color: #ffa726;
    font-size: 1.2rem;
    animation: sparkle 1s ease-out forwards;
}

.particle.heart {
    color: #ff6b9d;
    font-size: 1rem;
    animation: float 2s ease-out forwards;
}

/* ホバー効果の強化 */
.code-block:hover,
.control-btn:hover,
.footer-btn:hover {
    animation: none; /* 基本のアニメーションを停止 */
}

/* フォーカス効果 */
.focusable:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
    animation: glow 1s ease-in-out;
}

/* スクロール時のアニメーション */
.scroll-animate {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.6s ease;
}

.scroll-animate.visible {
    opacity: 1;
    transform: translateY(0);
}

/* =====================================
   特殊効果
   ===================================== */

/* 虹色のボーダーアニメーション */
.rainbow-border {
    position: relative;
    background: white;
    border-radius: 15px;
}

.rainbow-border::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border-radius: 18px;
    background: linear-gradient(45deg, #ff6b9d, #ffa726, #4caf50, #2196f3, #9c27b0, #ff6b9d);
    background-size: 400% 400%;
    animation: rainbow-rotate 3s linear infinite;
    z-index: -1;
}

@keyframes rainbow-rotate {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* 星の軌跡効果 */
.star-trail {
    position: relative;
    overflow: hidden;
}

.star-trail::after {
    content: '✨';
    position: absolute;
    top: 50%;
    left: -30px;
    transform: translateY(-50%);
    opacity: 0;
    animation: star-trail-move 2s ease-in-out infinite;
}

@keyframes star-trail-move {
    0% {
        left: -30px;
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        left: calc(100% + 30px);
        opacity: 0;
    }
}

/* 成功時のコンフェティ効果 */
.confetti {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #ff6b9d;
    animation: confetti-fall 2s linear forwards;
}

.confetti-piece:nth-child(odd) {
    background: #ffa726;
    animation-delay: 0.1s;
}

.confetti-piece:nth-child(3n) {
    background: #4caf50;
    animation-delay: 0.2s;
}

.confetti-piece:nth-child(4n) {
    background: #2196f3;
    animation-delay: 0.3s;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

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

/* 動きを減らす設定に対応 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .character.moving {
        transition-duration: 0.2s !important;
    }
}

/* ハイコントラストモード対応 */
@media (prefers-contrast: high) {
    .code-block {
        border-width: 3px;
        border-color: currentColor;
    }
    
    .drop-zone {
        border-width: 4px;
    }
    
    .modal-content {
        border: 3px solid #333;
    }
}