/* ============================================
   ExamPass - モバイル最適化CSS（統合版）
   更新日: 2025年11月19日
   ============================================ */

/* ============================================
   基本設定
   ============================================ */
:root {
  --mobile-tap-area: 48px;
  --mobile-font-base: 16px; /* iOSズーム防止 */
  --mobile-spacing: 1rem;
  --mobile-border-radius: 12px;
}

/* ============================================
   タブレット対応 (768px - 991px)
   ============================================ */
@media (max-width: 991px) {
  /* コンテナ */
  .container {
    padding-left: 20px;
    padding-right: 20px;
  }
  
  /* カード */
  .card {
    margin-bottom: 1rem;
    border-radius: var(--mobile-border-radius);
  }
  
  .card-body {
    padding: 1.25rem;
  }
  
  /* ボタングループ - 縦並び */
  .btn-group {
    flex-direction: column;
    width: 100%;
  }
  
  .btn-group .btn {
    width: 100%;
    border-radius: 0.375rem !important;
    margin-bottom: 0.5rem;
  }
  
  /* フレックスボックス - 縦並び */
  .d-flex.gap-2,
  .d-flex.gap-3 {
    flex-direction: column;
  }
  
  .d-flex.gap-2 > *,
  .d-flex.gap-3 > * {
    width: 100%;
  }
  
  /* グリッド */
  .row > [class*='col-md-'] {
    margin-bottom: 1rem;
  }
  
  /* テーブル - 横スクロール必須 */
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.9rem;
  }
  
  .table-responsive::-webkit-scrollbar {
    height: 8px;
  }
  
  .table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
  }
  
  .table-responsive::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
  }
  
  .table-responsive::-webkit-scrollbar-thumb:hover {
    background: #555;
  }
  
  /* ナビゲーション */
  .navbar-collapse {
    margin-top: 1rem;
  }
  
  /* モーダル */
  .modal-dialog {
    margin: 1rem;
  }
}

/* ============================================
   スマートフォン対応 (576px - 767px)
   ============================================ */
@media (max-width: 767px) {
  /* 基本フォント - iOSズーム防止 */
  body {
    font-size: 14px;
    line-height: 1.6;
  }
  
  /* 見出し */
  h1 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
  }
  
  h2 {
    font-size: 1.5rem;
    margin-bottom: 0.875rem;
  }
  
  h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
  }
  
  h4 {
    font-size: 1.1rem;
    margin-bottom: 0.625rem;
  }
  
  /* カード */
  .card {
    border-radius: var(--mobile-border-radius);
    margin-bottom: 1rem;
  }
  
  .card-body {
    padding: 1rem;
  }
  
  .card-header {
    padding: 0.75rem 1rem;
  }
  
  /* ボタン - タップエリア確保 */
  .btn {
    min-height: var(--mobile-tap-area);
    padding: 0.625rem 1rem;
    font-size: 0.9rem;
  }
  
  .btn-sm {
    min-height: 44px;
    padding: 0.5rem 0.875rem;
    font-size: 0.85rem;
  }
  
  .btn-lg {
    min-height: 56px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
  }
  
  /* フォーム - iOSズーム防止 */
  .form-control,
  .form-select {
    min-height: var(--mobile-tap-area);
    padding: 0.625rem 0.875rem;
    font-size: var(--mobile-font-base); /* 16px以上でズーム防止 */
  }
  
  .form-label {
    font-size: 0.9rem;
    margin-bottom: 0.375rem;
  }
  
  /* アラート */
  .alert {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }
  
  /* バッジ */
  .badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }
  
  /* ページネーション */
  .pagination {
    font-size: 0.85rem;
  }
  
  .pagination .page-link {
    min-height: 44px;
    padding: 0.375rem 0.75rem;
  }
  
  /* テーブル - 横スクロール必須 */
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
  }
  
  .table {
    font-size: 0.85rem;
    min-width: 600px; /* 最小幅を確保 */
  }
  
  .table th,
  .table td {
    padding: 0.5rem;
    white-space: nowrap; /* 改行防止 */
  }
  
  /* グラフ - 横スクロール対応 */
  .chart-wrapper,
  canvas {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  canvas {
    min-width: 600px !important;
    max-height: 250px !important;
  }
  
  /* リスト */
  .list-group-item {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }
  
  /* ドロップダウン */
  .dropdown-menu {
    font-size: 0.9rem;
  }
  
  .dropdown-item {
    min-height: 44px;
    padding: 0.5rem 1rem;
  }
  
  /* ブレッドクラム */
  .breadcrumb {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
  }
  
  /* プログレスバー */
  .progress {
    height: 1.25rem;
  }
  
  /* スピナー */
  .spinner-border {
    width: 2rem;
    height: 2rem;
  }
  
  /* アイコン */
  .bi {
    font-size: 1.1rem;
  }
  
  /* ヘッダーアクション - 縦並び */
  .d-flex.justify-content-between {
    flex-direction: column;
    gap: 1rem;
  }
  
  .d-flex.justify-content-between > div {
    width: 100%;
  }
  
  /* 問題表示 */
  .question-text {
    font-size: 0.95rem;
    line-height: 1.7;
  }
  
  .choice-label {
    font-size: 0.9rem;
  }
  
  /* 試験タイマー */
  .timer-display {
    font-size: 1.25rem;
  }
  
  /* スコア表示 */
  .score-display {
    font-size: 2rem;
  }
  
  /* ストリークカード */
  .streak-card .row {
    text-align: center;
  }
  
  .streak-card .col-md-4 {
    margin-bottom: 1rem;
  }
  
  /* 統計カード */
  .stat-card {
    margin-bottom: 1rem;
  }
  
  .stat-card h3 {
    font-size: 1.5rem;
  }
}

/* ============================================
   小型スマートフォン対応 (〜575px)
   ============================================ */
@media (max-width: 575px) {
  /* 基本フォント */
  body {
    font-size: 14px; /* 読みやすさ重視 */
  }
  
  /* コンテナ */
  .container {
    padding-left: 12px;
    padding-right: 12px;
  }
  
  /* 見出し */
  h1 {
    font-size: 1.5rem;
  }
  
  h2 {
    font-size: 1.25rem;
  }
  
  h3 {
    font-size: 1.1rem;
  }
  
  h4 {
    font-size: 1rem;
  }
  
  /* カード */
  .card {
    border-radius: 10px;
  }
  
  .card-body {
    padding: 0.875rem;
  }
  
  .card-header {
    padding: 0.625rem 0.875rem;
  }
  
  /* ボタン */
  .btn {
    min-height: var(--mobile-tap-area);
    padding: 0.5rem 0.875rem;
    font-size: 0.9rem;
  }
  
  .btn-sm {
    min-height: 44px;
    padding: 0.375rem 0.75rem;
    font-size: 0.85rem;
  }
  
  /* フォーム */
  .form-control,
  .form-select {
    min-height: var(--mobile-tap-area);
    padding: 0.5rem 0.75rem;
    font-size: var(--mobile-font-base);
  }
  
  /* テーブル */
  .table {
    font-size: 0.8rem;
    min-width: 500px;
  }
  
  .table th,
  .table td {
    padding: 0.375rem;
  }
  
  /* グラフ */
  canvas {
    min-width: 500px !important;
    max-height: 200px !important;
  }
  
  /* アイコン */
  .bi {
    font-size: 1rem;
  }
  
  /* モーダル */
  .modal-dialog {
    margin: 0.5rem;
  }
  
  .modal-content {
    border-radius: 10px;
  }
  
  .modal-header,
  .modal-footer {
    padding: 0.75rem 1rem;
  }
  
  .modal-body {
    padding: 1rem;
  }
  
  /* ナビゲーションバー */
  .navbar-brand {
    font-size: 1.1rem;
  }
  
  /* フッター */
  .footer-links {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .footer-link {
    width: 100%;
    justify-content: center;
    min-height: var(--mobile-tap-area);
  }
  
  /* ストリーク表示 */
  .streak-number {
    font-size: 2.5rem;
  }
  
  .streak-icon {
    font-size: 2.5rem;
  }
  
  /* 統計表示 */
  .stat-value {
    font-size: 1.5rem;
  }
}

/* ============================================
   タッチデバイス最適化
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  /* タップエリアを十分に確保 */
  .btn,
  a.btn {
    min-height: var(--mobile-tap-area);
    min-width: var(--mobile-tap-area);
    padding: 12px 20px;
  }
  
  .btn-sm {
    min-height: 44px;
    min-width: 44px;
  }
  
  .form-control,
  .form-select {
    min-height: var(--mobile-tap-area);
    font-size: var(--mobile-font-base);
  }
  
  .form-check-input {
    width: 28px;
    height: 28px;
    cursor: pointer;
  }
  
  .form-check-label {
    cursor: pointer;
    padding-left: 0.5rem;
  }
  
  /* リンク */
  a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  
  /* テーブルの行 */
  .table tbody tr {
    cursor: pointer;
  }
  
  .table tbody tr:active {
    background-color: rgba(102, 126, 234, 0.1);
  }
  
  /* カード */
  .card-modern {
    cursor: pointer;
    transition: background-color 0.1s;
  }
  
  .card-modern:active {
    background-color: rgba(102, 126, 234, 0.05);
  }
  
  /* ホバー効果を無効化 */
  .hover-lift:hover,
  .card-modern:hover,
  .btn:hover {
    transform: none;
  }
  
  /* タップ時のフィードバック */
  .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
  
  /* スクロールバーを見やすく */
  ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
  }
  
  ::-webkit-scrollbar-track {
    background: #f1f1f1;
  }
  
  ::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 6px;
  }
  
  ::-webkit-scrollbar-thumb:active {
    background: #555;
  }
}

/* ============================================
   問題解答画面の最適化
   ============================================ */
@media (max-width: 768px) {
  /* 問題文 */
  .question-text {
    font-size: 1rem;
    line-height: 1.7;
    padding: 1rem 0.875rem;
  }
  
  /* 選択肢 - 押しやすく */
  .choice-button {
    min-height: 72px;
    padding: 1.25rem 1rem;
    font-size: 1rem;
  }
  
  .choice-label {
    min-height: 68px;
    padding: 1rem;
  }
  
  .choice-marker {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
  }
  
  .choice-text {
    font-size: 1rem;
    line-height: 1.7;
  }
  
  .choice-item {
    margin-bottom: 0.875rem;
  }
  
  /* 問題ヘッダー */
  .question-header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }
  
  /* 問題アクション */
  .question-actions {
    flex-direction: column;
    padding: 1rem;
  }
  
  .question-actions .btn,
  .question-actions form {
    width: 100%;
  }
  
  /* 結果バナー */
  .result-banner {
    flex-direction: column;
    text-align: center;
    padding: 1.5rem;
  }
  
  .result-icon {
    font-size: 3rem;
  }
  
  /* 選択肢結果 */
  .choice-item-result {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .choice-status {
    width: 100%;
  }
  
  /* 解説 */
  .explanation-box {
    padding: 1rem;
    margin-top: 1.25rem;
  }
  
  .explanation-title {
    font-size: 1rem;
  }
  
  .explanation-text {
    font-size: 0.95rem;
    line-height: 1.7;
  }
  
  /* 練習モードヘッダー */
  .practice-header-card,
  .exam-header-card {
    padding: 1.25rem;
  }
  
  .practice-header-content,
  .exam-header-content {
    flex-direction: column;
    align-items: stretch;
  }
  
  .exam-timer-box {
    justify-content: center;
  }
  
  /* AIキャラクター応答 */
  .character-bubble {
    flex-direction: column;
    text-align: center;
  }
  
  .character-icon {
    font-size: 2.5rem;
  }
}

@media (max-width: 576px) {
  .choice-button {
    min-height: 68px;
    padding: 1rem 0.875rem;
  }
  
  .choice-label {
    padding: 1rem;
  }
  
  .choice-marker {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }
}

/* ============================================
   ダッシュボードの最適化
   ============================================ */
@media (max-width: 768px) {
  /* フィルターフォーム */
  .card-body form .row {
    flex-direction: column;
  }
  
  .card-body form .col-md-3,
  .card-body form .col-md-2,
  .card-body form .col-md-1 {
    width: 100%;
    margin-bottom: 0.75rem;
  }
  
  /* サマリーカード */
  .stat-card {
    margin-bottom: 1rem;
  }
  
  /* グラフ */
  #weeklyProgressChart,
  #monthlyProgressChart,
  #categoryChart {
    max-height: 250px !important;
  }
  
  /* カレンダー */
  .calendar-grid {
    gap: 2px;
  }
  
  .calendar-day {
    width: 100%;
    aspect-ratio: 1;
  }
}

/* ============================================
   横向き対応
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
  /* ナビゲーション */
  .navbar-modern {
    padding: 0.5rem 0;
  }
  
  /* カード */
  .card {
    margin-bottom: 0.75rem;
  }
  
  /* モーダル */
  .modal-dialog {
    max-width: 90%;
    margin: 1rem auto;
  }
  
  /* グラフ */
  canvas {
    max-height: 180px !important;
  }
}

/* ============================================
   アクセシビリティ
   ============================================ */
@media (max-width: 768px) {
  /* フォーカス表示を強化 */
  .btn:focus,
  .form-control:focus,
  .form-select:focus,
  a:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
  }
}

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

/* ============================================
   固定要素を非固定に（スクロール可能なレイアウト）
   ============================================ */
@media (max-width: 768px) {
  /* ボトムナビゲーションを非固定に */
  .quiz-bottom-nav,
  .mobile-action-bar,
  .mobile-bottom-action {
    position: relative !important;
    margin-top: 1rem;
    margin-bottom: 1rem;
    border-radius: 12px;
  }
  
  /* コンテンツエリアの下部余白を削除 */
  body {
    padding-bottom: 0 !important;
  }
  
  /* メインコンテンツの余白調整 */
  main,
  .container,
  .main-content {
    padding-bottom: 1rem !important;
  }
  
  /* quiz-modeクラスのpadding-bottomも削除 */
  body.quiz-mode {
    padding-bottom: 0 !important;
  }
}

/* ============================================
   Live2D看板娘のモバイル非表示
   ============================================ */
@media (max-width: 768px) {
  /* Live2Dウィジェット全体を非表示 */
  #live2d-widget,
  .live2d-widget-container,
  canvas[id^="live2dcanvas"] {
    display: none !important;
    visibility: hidden !important;
  }
  
  /* Live2Dメッセージボックスも非表示 */
  .live2d-message,
  #live2d-message {
    display: none !important;
  }
  
  /* Live2D表示復帰ボタンも非表示 */
  #live2d-show-button {
    display: none !important;
  }
}

/* ============================================
   印刷対応
   ============================================ */
@media print {
  .navbar,
  .footer,
  .btn,
  .alert {
    display: none !important;
  }
  
  /* Live2D看板娘も印刷時は非表示 */
  #live2d-widget,
  .live2d-widget-container,
  canvas[id^="live2dcanvas"],
  .live2d-message,
  #live2d-message,
  #live2d-show-button {
    display: none !important;
  }
  
  .card {
    border: 1px solid #000;
    box-shadow: none;
  }
  
  body {
    font-size: 12pt;
    color: #000;
    background: #fff;
  }
}

/* ============================================
   ユーティリティクラス
   ============================================ */
/* モバイルのみ表示 */
.mobile-only {
  display: none !important;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block !important;
  }
  
  .mobile-only-flex {
    display: flex !important;
  }
  
  .mobile-only-inline {
    display: inline !important;
  }
  
  .mobile-only-inline-block {
    display: inline-block !important;
  }
}

/* モバイルで非表示 */
@media (max-width: 768px) {
  .mobile-hidden {
    display: none !important;
  }
}

/* タブレット以上で非表示 */
@media (min-width: 769px) {
  .desktop-hidden {
    display: none !important;
  }
}

/* 横スクロール対応 */
.mobile-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.mobile-scroll-x::-webkit-scrollbar {
  height: 8px;
}

.mobile-scroll-x::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.mobile-scroll-x::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.mobile-scroll-x::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* テーブルラッパー */
.table-mobile-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.table-mobile-wrapper .table {
  margin-bottom: 0;
  min-width: 600px;
}

@media (max-width: 576px) {
  .table-mobile-wrapper .table {
    min-width: 500px;
    font-size: 0.85rem;
  }
}

/* グラフラッパー */
.chart-mobile-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

.chart-mobile-wrapper canvas {
  min-width: 600px;
}

@media (max-width: 576px) {
  .chart-mobile-wrapper canvas {
    min-width: 500px;
  }
}
