/* SPI3 学習アプリ - モバイル最適化CSS (Safe Area & PWA強化) */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #e0e7ff;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.03);
  position: relative;
}

/* トップバー */
.app-header {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  z-index: 50;
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-badge {
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.network-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.network-online {
  background: #dcfce7;
  color: #15803d;
}
.network-offline {
  background: #f1f5f9;
  color: #475569;
}

/* ナビゲーションバー (下部) - セーフエリア対応 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px)) 0;
  z-index: 50;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.03);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  padding: 4px 12px;
  border-radius: 8px;
  transition: all 0.15s ease;
  min-width: 60px;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item svg {
  width: 22px;
  height: 22px;
}

/* カード共通 */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.content-area {
  padding: 14px;
  flex: 1;
}

/* 統計ダッシュボードカード */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.stat-item {
  background: #f1f5f9;
  padding: 12px;
  border-radius: var(--radius-md);
  text-align: center;
}

.stat-val {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 学習モード選択カード */
.mode-card {
  display: flex;
  align-items: center;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-card:active {
  transform: scale(0.98);
  background: #f8fafc;
}

.mode-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
  font-size: 1.3rem;
}

.mode-info {
  flex: 1;
  min-width: 0;
}

.mode-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mode-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.35;
}

.mode-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
}

/* 解答画面 */
.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: monospace;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 8px;
  border-radius: 999px;
}

.question-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.6;
  margin-bottom: 18px;
  word-break: break-word;
}

/* 選択肢ボタン (大押し・スマホ最適化) */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 18px;
}

.option-btn {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 12px 14px;
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.12s ease;
  color: var(--text-main);
  word-break: break-word;
}

.option-btn:active:not(:disabled) {
  background: #f1f5f9;
}

.option-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

.option-btn.correct {
  border-color: var(--success);
  background: #ecfdf5;
  color: #065f46;
  font-weight: 700;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: #fef2f2;
  color: #991b1b;
}

.option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #334155;
  font-weight: 700;
  font-size: 0.8rem;
  margin-right: 10px;
  flex-shrink: 0;
}

.option-btn.correct .option-letter {
  background: var(--success);
  color: #ffffff;
}

.option-btn.wrong .option-letter {
  background: var(--danger);
  color: #ffffff;
}

/* 解説ボックス */
.explanation-card {
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-top: 14px;
  animation: fadeIn 0.2s ease;
}

.explanation-title {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.explanation-text {
  font-size: 0.88rem;
  color: #334155;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* アクションボタン */
.btn-primary {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
  transition: all 0.15s ease;
}

.btn-primary:active {
  background: var(--primary-dark);
  transform: scale(0.98);
}

.btn-secondary {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  background: #ffffff;
  color: var(--text-main);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.btn-secondary:active {
  background: #f1f5f9;
}

/* 進捗バー */
.progress-bar-container {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
/* ヒントボタン & モーダル & 理解度評価ボタンの追加スタイル */

/* わからない・ヒントを見るボタン */
.btn-hint {
  width: 100%;
  padding: 12px 16px;
  background: #fef3c7;
  color: #92400e;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  transition: all 0.15s ease;
}

.btn-hint:active {
  background: #fde68a;
  transform: scale(0.98);
}

/* ヒントモーダル */
.hint-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.hint-modal-content {
  background: #ffffff;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom, 0px)) 18px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
}

.hint-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.hint-step-1 {
  background: #fef3c7;
  color: #92400e;
}

.hint-step-2 {
  background: #e0f2fe;
  color: #0369a1;
}

.hint-step-3 {
  background: #ecfdf5;
  color: #065f46;
}

.hint-body-box {
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 14px 0;
  font-size: 0.95rem;
  line-height: 1.65;
  color: #1e293b;
}

/* 理解度自己評価カード */
.comprehension-card {
  background: #f1f5f9;
  border-radius: var(--radius-md);
  padding: 14px;
  margin: 14px 0;
  text-align: center;
}

.comp-btn-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.comp-btn {
  padding: 10px 6px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.comp-btn.green {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}
.comp-btn.yellow {
  background: #fefce8;
  border-color: #fef08a;
  color: #854d0e;
}
.comp-btn.red {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.comp-btn:active {
  transform: scale(0.96);
}

.comp-btn.selected {
  outline: 2px solid var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
