/* --- 全体基本設定 --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: #f4f6f8;
  color: #333;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* --- コンテナ・ヘッダー --- */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.btn-menu {
  background: #007bff;
  color: #fff;
  border: none;
  font-size: 1.2rem;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

h1 {
  font-size: 1.4rem;
  font-weight: bold;
}

/* --- 設定バー --- */
.settings-bar {
  display: flex;
  gap: 12px;
  background: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  flex-wrap: wrap;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.setting-item select, .setting-item input {
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

/* --- クイズカード --- */
.quiz-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  position: relative;
}

.quiz-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: bold;
  color: #666;
  margin-bottom: 8px;
}

.level-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: bold;
}

.status-text {
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 14px;
}

/* 問題・解答テキスト */
.question-container {
  position: relative;
  margin-bottom: 16px;
}

.question-text {
  font-size: 1.2rem;
  font-weight: bold;
  color: #222;
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-icon-edit {
  position: relative;
  top: 1;
  right: 1;
  background: none;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 4px 6px;
  font-size: 0.75rem;
  cursor: pointer;
  color: #666;
}

.image-container img {
  max-width: 100%;
  max-height: 250px;
  border-radius: 8px;
  margin-top: 10px;
  object-fit: contain;
}

.answer-container {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px dashed #eee;
}

.answer-title, .explanation-title {
  font-size: 0.85rem;
  font-weight: bold;
  color: #28a745;
  margin-bottom: 4px;
}

.answer-text {
  font-size: 1.1rem;
  font-weight: bold;
  color: #155724;
  white-space: pre-wrap;
  word-break: break-word;
}

.explanation-container {
  margin-top: 10px;
  background-color: #f8f9fa;
  padding: 10px;
  border-radius: 6px;
}

.explanation-text {
  font-size: 0.9rem;
  color: #555;
  white-space: pre-wrap;
}

/* メモ入力 */
.memo-container {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.memo-container label {
  font-size: 0.8rem;
  color: #666;
}

.memo-container input {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* ボタン群 */
.action-area {
  margin-top: 20px;
}

.btn-show-answer {
  width: 100%;
  padding: 12px;
  background: #007bff;
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.action-group {
  display: flex;
  gap: 12px;
}

.btn-action {
  flex: 1;
  padding: 12px;
  font-size: 1rem;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: #fff;
}

.btn-action.dont-know { background: #dc3545; }
.btn-action.know { background: #28a745; }

.custom-interval-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-interval {
  padding: 10px;
  background: #6c757d;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
}

.card-footer {
  margin-top: 14px;
  text-align: left;
}

.btn-prev {
  background: none;
  border: none;
  color: #007bff;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

/* --- サイドバー --- */
.overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100dvh;
  background: rgba(0,0,0,0.4);
  display: none;
  z-index: 900;
}

.overlay.active { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100dvh;
  background: #fff;
  z-index: 1000;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px rgba(0,0,0,0.15);
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: border-box;
}

.sidebar.open {
  left: 0;
}

.deck-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.sidebar-footer {
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid #eee;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.btn-import, .btn-create {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  border: none;
}

.btn-import { background: #e9ecef; color: #333; }
.btn-create { background: #17a2b8; color: #fff; }

/* --- モーダル (標準・自作問題用) --- */
.modal {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100dvh;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1100;
}

.modal-content {
  background: #fff;
  width: 90%;
  max-width: 500px;
  border-radius: 8px;
  padding: 20px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.btn-close-icon {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-body input, .modal-body textarea {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.modal-footer {
  margin-top: 16px;
  text-align: right;
}

/* ==========================================
   ★ デッキ内問題一覧モーダル (画面中央・大型表示) ★
   ========================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.modal-container {
  position: relative;
  background-color: #ffffff;
  width: 90%;
  max-width: 800px; /* 画面中央に大きく表示 */
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 30px 24px 24px 24px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

/* 右上の × 印ボタン */
.close-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 28px;
  font-weight: bold;
  color: #888;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  transition: color 0.2s;
}

.close-btn:hover {
  color: #222;
}

.modal-header-large {
  border-bottom: 2px solid #eee;
  padding-bottom: 10px;
  margin-bottom: 16px;
}

.modal-header-large h2 {
  font-size: 1.25rem;
  color: #222;
}

.deck-quiz-list-container {
  overflow-y: auto;
  flex: 1;
  padding-right: 6px;
}

/* モーダル内の各問題カード */
.deck-quiz-item {
  background-color: #f8f9fa;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.deck-quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.deck-quiz-num {
  font-size: 0.85rem;
  font-weight: bold;
  color: #666;
}

.deck-quiz-q {
  font-size: 1rem;
  font-weight: bold;
  color: #1a202c;
  margin-bottom: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}

.deck-quiz-a {
  font-size: 0.95rem;
  font-weight: bold;
  color: #2b6cb0;
  white-space: pre-wrap;
  word-break: break-word;
}

.deck-quiz-img-thumb {
  max-width: 80px;
  max-height: 80px;
  border-radius: 4px;
  margin-top: 8px;
  object-fit: cover;
  border: 1px solid #ccc;
}

.level-badge-list {
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  white-space: nowrap;
}

/* 汎用ボタン */
.btn-primary { background: #007bff; color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: bold; }
.btn-secondary { background: #6c757d; color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; }
.btn-large { width: 100%; padding: 12px; font-size: 1rem; margin-top: 16px; }

/* 編集画面のスタイル */
.edit-mode-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-mode-container label {
  font-size: 0.8rem;
  font-weight: bold;
  color: #555;
  margin-top: 4px;
}

.edit-mode-container textarea {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.9rem;
}

.edit-btn-group {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.image-preview-wrapper {
  position: relative;
  display: inline-block;
  margin-top: 6px;
}

.image-preview-wrapper img {
  max-width: 100px;
  max-height: 100px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.btn-remove-img {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #dc3545;
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 0.7rem;
  padding: 2px 6px;
  cursor: pointer;
}

/* リザルト表示 */
.result-screen {
  background: #fff;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.result-summary {
  font-size: 1.1rem;
  margin: 12px 0 20px 0;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  text-align: center;
}

.review-list {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.review-item {
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
}

.review-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.review-time { color: #888; margin-left: 6px; }
.review-q { font-weight: bold; font-size: 0.95rem; }
.review-a { color: #1e88e5; font-size: 0.85rem; margin-top: 2px; }
.review-next-schedule { font-size: 0.75rem; color: #666; margin-top: 4px; }
.review-level-change { display: flex; justify-content: space-between; font-size: 0.75rem; margin-top: 6px; padding-top: 6px; border-top: 1px dashed #eee; }
.level-badge-sm { padding: 2px 6px; border-radius: 8px; font-weight: bold; }
.level-up { color: #28a745; font-weight: bold; }
.level-down { color: #dc3545; font-weight: bold; }

/* 1. 大きな角丸の四角（問題カード） */
.question-card {
  width: 100%;
  max-width: 640px;
  min-height: 400px; /* カードの高さを確保 */
  margin: 20px auto;
  padding: 32px;
  
  /* カードの外観 */
  background-color: #ffffff;
  border-radius: 20px; /* 大きな角丸 */
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);

  /* 左下に配置するためのFlexbox設定 */
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* 上部コンテンツと下部ボタンを上下に分離 */
}

/* 2. カード下部のエリア */
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between; /* ボタン同士を左右端に配置（左下に「戻る」が来ます） */
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid #f3f4f6; /* 区切り線 */
}

/* 3. 「前の問題に戻る」ボタン（リンク化） */
.btn-back {
  /* リンクの基本打ち消し */
  text-decoration: none;
  
  /* レイアウトと見た目 */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  
  /* 文字と背景 */
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  background-color: #f9fafb;
  
  /* 枠線と角丸 */
  border: 1px solid #d1d5db;
  border-radius: 10px;
  
  /* ホバーアニメーション */
  transition: all 0.2s ease;
}

.btn-back:hover {
  background-color: #f3f4f6;
  border-color: #9ca3af;
  color: #111827;
  transform: translateX(-2px); /* 左に少し動く演出 */
}

/* （参考）右下に置く「次の問題へ」ボタン */
.btn-next {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background-color: #2563eb;
  border-radius: 10px;
  transition: all 0.2s ease;
}

.btn-next:hover {
  background-color: #1d4ed8;
  transform: translateX(2px);
}

@media (max-width: 600px) {
  .sidebar-footer {
    padding-bottom: calc(90px + env(safe-area-inset-bottom));
  }
}

