/* ゲーム画面専用スタイル */

.puzzle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    justify-content: center;
    padding: 0;
}

.puzzle-canvas {
    display: none; /* 画像処理用、非表示 */
}

.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    width: 100%;
    max-width: 70vw;
    max-height: 70vh;
    aspect-ratio: 1;
    background: #333;
    border-radius: 8px;
    padding: 2px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.puzzle-grid.size-4 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.puzzle-piece {
    background-size: 300% 300%; /* 3x3グリッド用 */
    background-repeat: no-repeat;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.puzzle-grid.size-4 .puzzle-piece {
    background-size: 400% 400%; /* 4x4グリッド用 */
}

.puzzle-piece.empty {
    background: rgba(255, 255, 255, 0.1);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 6px;
}

.puzzle-piece.moveable {
    transform: scale(0.95);
    box-shadow: 0 0 15px rgba(74, 144, 226, 0.6);
    border: 2px solid #4a90e2;
}

.puzzle-piece.completed {
    border-radius: 0;
    border: none;
}

.puzzle-piece.completed:first-child {
    border-top-left-radius: 6px;
}

.puzzle-piece.completed:nth-child(3) {
    border-top-right-radius: 6px;
}

.puzzle-piece.completed:nth-child(7) {
    border-bottom-left-radius: 6px;
}

.puzzle-piece.completed:last-child {
    border-bottom-right-radius: 6px;
}

/* 4x4用の完成時角丸 */
.puzzle-grid.size-4 .puzzle-piece.completed:first-child {
    border-top-left-radius: 6px;
}

.puzzle-grid.size-4 .puzzle-piece.completed:nth-child(4) {
    border-top-right-radius: 6px;
}

.puzzle-grid.size-4 .puzzle-piece.completed:nth-child(13) {
    border-bottom-left-radius: 6px;
}

.puzzle-grid.size-4 .puzzle-piece.completed:last-child {
    border-bottom-right-radius: 6px;
}

/* タッチフィードバック */
.puzzle-piece:active {
    transform: scale(0.9);
}

/* 絵本モード用テキスト表示 */
.story-text {
    margin-top: 2rem;
    padding: 1.5rem;
    background: #f8f9fa;
    border-radius: 12px;
    border-left: 4px solid #4a90e2;
}

.story-paragraph {
    font-size: 1.1rem;
    line-height: 1.6;
    color: #333;
    margin-bottom: 1rem;
    min-height: 3em;
}

.story-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.story-btn {
    background: #28a745;
    color: white;
}

.story-btn:hover {
    background: #218838;
}

.story-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* 完成画像表示 */
.completed-image {
    width: 100%;
    max-width: 300px;
    height: 200px;
    margin: 0 auto;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f8f9fa;
}

.completed-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
    border-radius: 6px;
}

/* アニメーション */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

.puzzle-piece.sliding {
    animation: slideIn 0.3s ease;
}

.story-text.show {
    animation: fadeIn 0.5s ease;
}

/* タイプライター効果 */
.typewriter {
    overflow: hidden;
    border-right: 2px solid #4a90e2;
    white-space: nowrap;
    margin: 0 auto;
    animation: blink-caret 1s step-end infinite;
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: #4a90e2; }
}

/* パフォーマンス最適化 */
.puzzle-piece {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* レスポンシブ対応 */
@media (max-width: 480px) {
    .puzzle-grid {
        max-width: 85vw;
        max-height: 60vh;
    }
}

@media (max-width: 320px) {
    .puzzle-grid {
        max-width: 90vw;
        max-height: 55vh;
    }
}

/* タッチデバイス最適化 */
@media (hover: none) and (pointer: coarse) {
    .puzzle-piece:hover {
        transform: none;
    }
    
    .puzzle-piece.moveable:hover {
        transform: scale(0.95);
    }
}