/* Mobile Optimization for Cosmic Typing Adventure */
/* UX改善: WCAG 2.1 AAA準拠のタッチターゲットサイズ (48x48px) */

/* Touch-friendly sizing */
@media (max-width: 768px) {
    /* Ensure minimum touch target size - WCAG 2.1 AAA requires 44x44px, we use 48x48px for better UX */
    button, .btn, .planet-card, .nav-link, .mission-btn, .time-attack-btn {
        min-height: 48px;
        min-width: 48px;
        padding: 12px 16px;
    }
    
    /* ミッションボタンの改善 */
    .mission-btn {
        padding: 16px;
        min-height: 120px;
    }
    
    /* タイムアタックボタンの改善 */
    .time-attack-btn {
        padding: 12px 8px;
        min-height: 80px;
    }
    
    /* Larger text for better readability */
    body {
        font-size: 16px;
        line-height: 1.6;
    }
    
    /* Optimize text display for mobile */
    .text-content {
        font-size: 1.1rem;
        line-height: 1.8;
        padding: 1rem;
    }
    
    /* Larger typing input - 16px以上でズーム防止 */
    .typing-input,
    #typingInput,
    #timeAttackInput {
        font-size: 16px !important;
        min-height: 120px;
        padding: 1rem;
        line-height: 1.6;
        border-width: 3px;
    }
    
    /* フォーカス時のビジュアルフィードバック強化 */
    .typing-input:focus,
    #typingInput:focus,
    #timeAttackInput:focus {
        border-width: 4px;
        transform: none; /* モバイルでは変形なし */
    }
    
    /* Optimize planet cards for mobile */
    .planets-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 0 1rem;
    }
    
    .planet-card {
        padding: 1.5rem;
        margin-bottom: 1rem;
    }
    
    .planet-image {
        width: 80px;
        height: 80px;
    }
    
    /* Stack practice stats vertically */
    .practice-stats {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
    }
    
    .stat-item {
        min-width: 120px;
        text-align: center;
    }
    
    /* Optimize results display */
    .result-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .result-stat {
        padding: 1rem;
        min-height: 80px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    /* Larger buttons for mobile */
    .practice-controls {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .btn {
        width: 100%;
        min-height: 56px;
        font-size: 1.125rem;
        font-weight: 600;
        padding: 1rem 1.5rem;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    /* ボタンのアクティブ状態をより明確に */
    .btn:active {
        transform: scale(0.96);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    }
    
    /* 無効状態のボタン */
    .btn:disabled {
        opacity: 0.5;
        cursor: not-allowed;
        transform: none !important;
    }
    
    /* Optimize navigation */
    .nav-menu {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

/* Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) {
    .planets-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
    
    .planet-card {
        padding: 2rem;
    }
    
    .practice-stats {
        gap: 1.5rem;
    }
    
    .result-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* Touch gesture support */
@media (hover: none) and (pointer: coarse) {
    /* Add touch feedback - より明確なフィードバック */
    .planet-card:active,
    .btn:active,
    .nav-link:active,
    .mission-btn:active,
    .time-attack-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
        opacity: 0.85;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }
    
    /* タッチデバイス用のホバー効果を無効化 */
    .planet-card:hover,
    .btn:hover,
    .mission-btn:hover {
        transform: none;
    }
    
    /* タッチハイライトをカスタマイズ */
    * {
        -webkit-tap-highlight-color: rgba(6, 182, 212, 0.2);
    }
    
    /* Optimize scrolling */
    .app-container {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
    
    /* Prevent zoom on input focus - 16px以上必須 */
    .typing-input,
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
    
    /* プレースホルダーのサイズも調整 */
    .typing-input::placeholder,
    input::placeholder,
    textarea::placeholder {
        font-size: 16px;
    }
    
    /* Larger hit areas for touch */
    .planet-card {
        cursor: pointer;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Touch-friendly spacing */
    .planet-selection {
        padding: 1rem;
    }
    
    .typing-practice {
        padding: 1rem;
    }
    
    .results {
        padding: 1rem;
    }
}

/* Landscape orientation optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .planet-selection {
        padding: 0.5rem;
    }
    
    .planets-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .planet-card {
        padding: 1rem;
    }
    
    .planet-image {
        width: 60px;
        height: 60px;
    }
    
    .planet-name {
        font-size: 1rem;
    }
    
    .planet-description {
        font-size: 0.8rem;
    }
    
    .typing-practice {
        padding: 0.5rem;
    }
    
    .text-content {
        font-size: 1rem;
        padding: 0.5rem;
    }
    
    .typing-input {
        min-height: 80px;
        font-size: 1rem;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .planet-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    /* Sharper text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}

/* Dark mode support for mobile */
@media (prefers-color-scheme: dark) {
    .planet-card {
        background: rgba(30, 30, 30, 0.95);
        color: #ffffff;
    }
    
    .typing-practice {
        background: rgba(30, 30, 30, 0.95);
        color: #ffffff;
    }
    
    .text-display {
        background: #2a2a2a;
        border-color: #444;
    }
    
    .typing-input {
        background: #2a2a2a;
        color: #ffffff;
        border-color: #444;
    }
    
    .btn {
        background: #667eea;
        color: #ffffff;
    }
    
    .btn-secondary {
        background: #444;
        color: #ffffff;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .planet-card:hover {
        transform: none;
    }
    
    .btn:hover {
        transform: none;
    }
}

/* Mobile-specific animations */
@media (max-width: 768px) {
    /* Smooth page transitions */
    .planet-selection,
    .typing-practice,
    .results {
        transition: opacity 0.3s ease, transform 0.3s ease;
    }
    
    /* Loading animations */
    .loading-spinner {
        width: 40px;
        height: 40px;
        border-width: 3px;
    }
    
    /* Progress animations */
    .progress-fill {
        transition: width 0.3s ease;
    }
    
    /* Notification animations */
    .notification {
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .notification.show {
        transform: translateY(0);
    }
}

/* Mobile keyboard optimization */
@media (max-width: 768px) {
    /* Prevent viewport issues with mobile keyboard */
    .app-container {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    /* Optimize for virtual keyboard */
    .typing-input {
        resize: none;
        overflow: hidden;
    }
    
    /* Ensure content is visible above keyboard */
    .typing-area {
        margin-bottom: 2rem;
    }
    
    /* Mobile-friendly navigation */
    .nav {
        position: sticky;
        top: 0;
        z-index: 1000;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
    }
}

/* Mobile performance optimizations */
@media (max-width: 768px) {
    /* Reduce animations for better performance */
    .planet-card {
        will-change: transform;
    }
    
    /* Optimize images */
    .planet-image {
        object-fit: cover;
        object-position: center;
    }
    
    /* Reduce shadow complexity */
    .planet-card,
    .typing-practice,
    .results {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    /* Optimize text rendering */
    .text-content {
        text-rendering: optimizeSpeed;
    }
}

/* Mobile-specific utilities */
.mobile-only {
    display: block;
}

.desktop-only {
    display: none;
}

@media (min-width: 769px) {
    .mobile-only {
        display: none;
    }
    
    .desktop-only {
        display: block;
    }
}

/* Touch feedback utilities */
.touch-feedback {
    position: relative;
    overflow: hidden;
}

.touch-feedback::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.touch-feedback:active::after {
    width: 100px;
    height: 100px;
}

/* Mobile scroll optimization */
.mobile-scroll {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Mobile input optimization */
.mobile-input {
    font-size: 16px;
    -webkit-appearance: none;
    border-radius: 0;
}

/* Mobile button optimization */
.mobile-button {
    -webkit-appearance: none;
    border: none;
    outline: none;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile layout utilities */
.mobile-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mobile-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 480px) {
    .mobile-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .mobile-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Mobile spacing utilities */
.mobile-padding {
    padding: 1rem;
}

.mobile-margin {
    margin: 1rem;
}

@media (min-width: 768px) {
    .mobile-padding {
        padding: 2rem;
    }
    
    .mobile-margin {
        margin: 2rem;
    }
}

/* Mobile typography */
.mobile-text {
    font-size: 1rem;
    line-height: 1.6;
}

.mobile-text-large {
    font-size: 1.2rem;
    line-height: 1.5;
}

.mobile-text-small {
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Mobile color utilities */
.mobile-highlight {
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    padding: 0.5rem;
}

.mobile-border {
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 8px;
}

/* Mobile animation utilities */
.mobile-fade-in {
    opacity: 0;
    transform: translateY(20px);
    animation: mobileFadeIn 0.3s ease forwards;
}

@keyframes mobileFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mobile-slide-in {
    transform: translateX(-100%);
    animation: mobileSlideIn 0.3s ease forwards;
}

@keyframes mobileSlideIn {
    to {
        transform: translateX(0);
    }
}

/* Mobile responsive images */
.mobile-responsive-image {
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: cover;
}

/* Mobile form optimization */
.mobile-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mobile-form input,
.mobile-form textarea,
.mobile-form select {
    font-size: 16px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
}

.mobile-form input:focus,
.mobile-form textarea:focus,
.mobile-form select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Mobile loading states */
.mobile-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.mobile-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
} 