/* レスポンシブデザイン */

/* 基本設定 - モバイルファースト */
.app-container {
    width: 100%;
    max-width: 600px;
}

.puzzle-grid {
    width: min(90vw, 400px);
    height: min(90vw, 400px);
}

/* 小さいスマートフォン (320px以下) */
@media (max-width: 320px) {
    .main-title-img {
        max-height: 100px;
    }
    
    .puzzle-grid {
        width: min(85vw, 300px);
        height: min(85vw, 300px);
        gap: 1px;
    }
    
    .start-content {
        padding: 1.5rem;
        gap: 1rem;
    }
    
    .btn-img:not(.game-start-btn) {
        max-width: 150px;
        max-height: 45px;
    }
    
    .start-btn:not(.img-btn), .control-btn:not(.img-btn) {
        font-size: 0.9rem;
        padding: 0.6rem 1.2rem;
    }
    
    .modal-content {
        max-width: 95%;
        padding: 1rem;
    }
    
    .completed-image {
        height: 150px;
        max-width: 250px;
    }
}

/* 標準スマートフォン (321px - 480px) */
@media (min-width: 321px) and (max-width: 480px) {
    .main-title-img {
        max-height: 120px;
    }
    
    .puzzle-grid {
        width: min(85vw, 360px);
        height: min(85vw, 360px);
    }
    
    .btn-img:not(.game-start-btn) {
        max-width: 180px;
        max-height: 55px;
    }
    
    .modal-content {
        max-width: 90%;
    }
    
    .completed-image {
        height: 180px;
        max-width: 280px;
    }
}

/* 大きめスマートフォン・小さめタブレット (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .app-container {
        margin: 1rem auto;
        border-radius: 12px;
        overflow: hidden;
    }
    
    .main-title-img {
        max-height: 140px;
    }
    
    .puzzle-grid {
        width: min(70vw, 400px);
        height: min(70vw, 400px);
    }
    
    .btn-img:not(.game-start-btn) {
        max-width: 200px;
        max-height: 60px;
    }
    
    .start-content {
        gap: 2rem;
        padding: 2rem;
    }
    
    .modal-content {
        padding: 2rem;
        border-radius: 16px;
        max-width: 85%;
    }
    
    .completed-image {
        height: 220px;
        max-width: 320px;
    }
}

/* デスクトップ (769px以上) */
@media (min-width: 769px) {
    body {
        padding: 2rem 0;
    }
    
    .app-container {
        margin: 2rem auto;
        border-radius: 16px;
        overflow: hidden;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.15);
    }
    
    .puzzle-grid {
        width: 400px;
        height: 400px;
    }
    
    .main-title-img {
        max-height: 160px;
    }
    
    .btn-img:not(.game-start-btn) {
        max-width: 220px;
        max-height: 70px;
    }
    
    .start-content {
        padding: 3rem;
        gap: 2.5rem;
    }
    
    .modal-content {
        max-width: 500px;
        padding: 2.5rem;
    }
    
    .completed-image {
        height: 280px;
        max-width: 400px;
    }
    
    /* デスクトップでのホバー効果 */
    .puzzle-piece:hover:not(.empty):not(.completed) {
        transform: scale(1.02);
        box-shadow: 0 2px 10px rgba(74, 144, 226, 0.3);
    }
    
    .start-btn:not(.img-btn):hover,
    .control-btn:not(.img-btn):hover,
    .modal-btn:not(.img-btn):hover,
    .story-btn:not(.img-btn):hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .img-btn:hover {
        transform: translateY(-3px) scale(1.08);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    }
}

/* 超高解像度画面 */
@media (min-width: 1200px) {
    .app-container {
        max-width: 800px;
    }
    
    .puzzle-grid {
        width: 500px;
        height: 500px;
    }
    
    .main-title-img {
        max-height: 180px;
    }
    
    .btn-img:not(.game-start-btn) {
        max-width: 250px;
        max-height: 80px;
    }
}

/* 横向き画面での調整 */
@media (orientation: landscape) and (max-height: 600px) {
    .app-container {
        flex-direction: row;
        max-height: 100vh;
    }
    
    .header {
        writing-mode: vertical-lr;
        width: 120px;
        height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .title {
        writing-mode: vertical-lr;
        margin-bottom: 2rem;
    }
    
    .mode-toggle {
        flex-direction: column;
        writing-mode: horizontal-tb;
    }
    
    .screen {
        flex: 1;
        height: 100vh;
        overflow-y: auto;
    }
    
    .puzzle-grid {
        width: min(50vh, 300px);
        height: min(50vh, 300px);
    }
    
    .mode-select {
        flex-direction: row;
        gap: 1rem;
        align-items: stretch;
    }
    
    .mode-option {
        flex: 1;
    }
}

/* プリント対応 */
@media print {
    body {
        background: white;
    }
    
    .header,
    .game-controls,
    .story-controls,
    .modal {
        display: none;
    }
    
    .app-container {
        box-shadow: none;
        max-width: none;
    }
    
    .puzzle-grid {
        break-inside: avoid;
    }
}

/* 高コントラストモード対応 */
@media (prefers-contrast: high) {
    .puzzle-piece {
        border: 2px solid #000;
    }
    
    .puzzle-piece.empty {
        border: 2px solid #666;
        background: #f0f0f0;
    }
    
    .mode-btn.active {
        background: #000;
        color: #fff;
    }
}

/* 動きを減らす設定への対応 */
@media (prefers-reduced-motion: reduce) {
    .puzzle-piece,
    .start-btn,
    .control-btn,
    .modal-btn,
    .story-btn,
    .mode-option {
        transition: none;
    }
    
    .loading-spinner {
        animation: none;
        border: 4px solid #4a90e2;
    }
    
    .typewriter {
        animation: none;
        border-right: none;
    }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
        color: #ecf0f1;
    }
    
    .app-container {
        background: #2c3e50;
        color: #ecf0f1;
    }
    
    .mode-option {
        background: #34495e;
        border-color: #4a5568;
        color: #ecf0f1;
    }
    
    .story-text {
        background: #34495e;
        color: #ecf0f1;
    }
    
    .modal-content {
        background: #2c3e50;
        color: #ecf0f1;
    }
    
    #pageInput {
        background: #34495e;
        border-color: #4a5568;
        color: #ecf0f1;
    }
}