/* モバイル最適化 CSS */

/* タッチ操作の改善 */
* {
  -webkit-tap-highlight-color: transparent;
}

button, a, [onclick] {
  touch-action: manipulation;
}

/* スクロールの最適化 */
html {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* フォーカス時のズーム防止 */
input, select, textarea {
  font-size: 16px !important;
}

/* 小画面での調整 */
@media (max-width: 640px) {
  /* ヘッダーの調整 */
  header h1 {
    font-size: 1.5rem !important;
  }
  
  header p {
    font-size: 0.75rem !important;
  }
  
  /* ユーザーレベル表示を小さく */
  #user-level {
    font-size: 0.875rem !important;
  }
  
  /* ログアウトボタンを小さく */
  #logout-btn {
    padding: 0.5rem !important;
    font-size: 0.75rem !important;
  }
  
  /* 習慣カードのパディング調整 */
  .bg-white.rounded-xl.shadow-md {
    padding: 1rem !important;
  }
  
  /* 習慣カードのタイトル */
  .bg-white.rounded-xl.shadow-md h3 {
    font-size: 1.125rem !important;
  }
  
  /* チェックボタンを少し小さく */
  button[onclick^="toggleHabit"] {
    width: 3rem !important;
    height: 3rem !important;
    font-size: 1.5rem !important;
  }
  
  /* 統計カードのフォントサイズ */
  .text-3xl.font-bold {
    font-size: 1.875rem !important;
  }
  
  /* モーダルの調整 */
  #habit-modal > div {
    max-width: 100% !important;
    margin: 1rem !important;
  }
  
  /* レベルアップモーダルの調整 */
  #level-up-modal > div {
    max-width: 90% !important;
    padding: 1.5rem !important;
  }
  
  #level-up-modal h2 {
    font-size: 1.875rem !important;
  }
  
  #level-up-modal h3 {
    font-size: 1.5rem !important;
  }
  
  /* マイルストーン通知のサイズ調整 */
  #milestone-notification {
    max-width: 90% !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
  }
  
  /* 週次グラフのバー高さ */
  #weekly-chart .h-8 {
    height: 1.5rem !important;
  }
  
  /* グリッドレイアウトを1カラムに */
  .grid.md\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
  
  .grid.md\\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }
  
  /* ヒートマップのスクロール */
  #heatmap-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

/* 中画面（タブレット）での調整 */
@media (min-width: 641px) and (max-width: 1024px) {
  /* ヘッダーの調整 */
  header h1 {
    font-size: 2rem !important;
  }
  
  /* 2カラムグリッド */
  .grid.md\\:grid-cols-3 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* タッチデバイス用のホバーエフェクト無効化 */
@media (hover: none) {
  button:hover,
  a:hover {
    transform: none !important;
  }
}

/* ランドスケープモード（横向き）での調整 */
@media (max-height: 500px) and (orientation: landscape) {
  /* モーダルの高さ調整 */
  #habit-modal,
  #level-up-modal {
    overflow-y: auto !important;
  }
  
  #habit-modal > div,
  #level-up-modal > div {
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
}

/* iOS Safari のセーフエリア対応 */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  header {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* アニメーションのパフォーマンス最適化 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* タッチターゲットのサイズ最適化 */
button,
a,
[onclick] {
  min-height: 44px;
  min-width: 44px;
}

/* スワイプジェスチャーの改善 */
.swipeable {
  touch-action: pan-y;
}

/* スクロールコンテナの最適化 */
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.overflow-x-auto::-webkit-scrollbar {
  height: 4px;
}

.overflow-x-auto::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

/* ダブルタップズーム防止 */
.no-zoom {
  touch-action: manipulation;
}
