:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-sub: #475569;
  --border-color: #e2e8f0;

  --g3-color: #059669;
  --g2-color: #2563eb;
  --g1-color: #7c3aed;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  padding-bottom: 40px;
}

/* ヘッダー＆級タブ */
header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 16px 0 16px;
}

.site-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
  border-radius: 8px;
}

.site-title:hover {
  color: var(--primary);
}

.site-title:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 4px;
}

.site-title i {
  color: var(--primary);
}

/* 級切替タブ */
.grade-tabs {
  display: flex;
  gap: 8px;
}

.grade-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: #f1f5f9;
  color: var(--text-sub);
  font-weight: 700;
  font-size: 0.95rem;
  font-family: inherit;
  text-decoration: none;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.grade-tab:hover {
  background: #e2e8f0;
}

.grade-tab.active[data-grade="3"] {
  background: var(--g3-color);
  color: white;
}

.grade-tab.active[data-grade="2"] {
  background: var(--g2-color);
  color: white;
}

.grade-tab.active[data-grade="1"] {
  background: var(--g1-color);
  color: white;
}

/* メインコンテンツ配置 */
main {
  max-width: 800px;
  margin: 20px auto 0;
  padding: 0 16px;
}

/* 表示切り替え用ユーティリティ */
.is-hidden {
  display: none !important;
}

/* 広告枠スペース（AdSense 審査通過後に広告タグを設置する場合に使用） */
.ad-container {
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.8rem;
  margin-bottom: 20px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* モード切替ナビゲーション */
.mode-nav {
  display: flex;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 20px;
}

.mode-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn.active {
  background: var(--card-bg);
  color: var(--text-main);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* コントロールバー（ステータス＆フィルター） */
.control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-sub);
  flex-wrap: wrap;
  gap: 8px;
}

.badge-grade {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  color: white;
  font-size: 0.75rem;
}

.badge-g3 {
  background-color: var(--g3-color);
}

.badge-g2 {
  background-color: var(--g2-color);
}

.badge-g1 {
  background-color: var(--g1-color);
}

/* メインカード */
.app-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.category-tag {
  background: #eff6ff;
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}

.question-text {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* 選択肢ボタン */
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.option-btn {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 1.5px solid var(--border-color);
  border-radius: 10px;
  background: white;
  font-size: 0.95rem;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.option-btn:hover {
  border-color: var(--primary);
  background: #f8fafc;
}

.option-num {
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

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

.header-actions {
  display: flex;
  align-items: center;
}

.header-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: #eff6ff;
  color: var(--primary);
  padding: 8px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1rem;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
}

.header-icon-btn.active {
  background: var(--primary);
  color: white;
}

.landing-card {
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.landing-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 10px;
}

.landing-text {
  color: var(--text-sub);
  margin-bottom: 16px;
  line-height: 1.8;
}

.landing-choices {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.landing-choice {
  border: none;
  border-radius: 12px;
  padding: 14px;
  background: white;
  color: var(--text-main);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.landing-choice:hover {
  transform: translateY(-1px);
}

.landing-note {
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--text-sub);
}

.landing-note i {
  color: var(--primary);
  margin-right: 4px;
}

/* トップページの説明セクション */
.info-section {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  margin-top: 20px;
}

.info-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.info-text {
  color: var(--text-sub);
  line-height: 1.9;
}

.info-text + .info-grid,
.info-grid + .info-text {
  margin-top: 16px;
}

.info-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.info-item {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 16px;
}

.info-item h3 {
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.info-item p {
  font-size: 0.88rem;
  color: var(--text-sub);
  line-height: 1.8;
}

.step-list {
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.step-list li {
  counter-increment: step;
  position: relative;
  padding-left: 44px;
}

.step-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-list strong {
  display: block;
  margin-bottom: 2px;
}

.step-list span {
  color: var(--text-sub);
  font-size: 0.9rem;
  line-height: 1.8;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.faq-item h3 {
  font-size: 0.98rem;
  margin-bottom: 6px;
  padding-left: 10px;
  border-left: 4px solid var(--primary);
}

.faq-item p {
  color: var(--text-sub);
  font-size: 0.92rem;
  line-height: 1.9;
}

.info-section a,
.landing-note a {
  color: var(--primary);
}

.study-controls {
  display: block;
}

.study-filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.view-btn {
  flex: 1;
  min-width: 120px;
  border: none;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  color: var(--text-sub);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.view-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.question-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bookmark-toggle {
  border: none;
  background: #f8fafc;
  color: var(--text-sub);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bookmark-toggle.active {
  background: #fef3c7;
  color: #d97706;
}

.question-id {
  font-size: 0.8rem;
  color: #64748b;
}

.list-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  color: var(--text-main);
}

.list-subtitle {
  font-size: 0.9rem;
  color: var(--text-sub);
}

.list-item {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
}

.list-item-main {
  flex: 1;
}

.list-item-title {
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-main);
}

.list-item-meta {
  font-size: 0.85rem;
  color: var(--text-sub);
}

.list-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 即時回答表示 */
.explanation-box {
  margin-top: 16px;
  padding: 16px;
  border-radius: 10px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  font-size: 0.9rem;
  display: none;
}

.explanation-box.wrong {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.explanation-title {
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* フラッシュカードスタイル */
.flashcard-wrapper {
  perspective: 1000px;
  min-height: 240px;
  cursor: pointer;
  margin-bottom: 16px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 240px;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  border-radius: 12px;
  border: 2px dashed #cbd5e1;
  background: #f8fafc;
}

.flashcard-wrapper.flipped .flashcard-inner {
  transform: rotateY(180deg);
  border-style: solid;
  border-color: var(--primary);
  background: #ffffff;
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.flashcard-front {
  color: var(--text-main);
}

.flashcard-back {
  transform: rotateY(180deg);
  color: var(--primary);
}

.flashcard-hint {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 10px;
}

/* フッターアクションナビ */
.action-bar {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.btn-action {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text-sub);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

/* 空状態メッセージ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-sub);
}

.empty-state i {
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: #cbd5e1;
}

/* フッター・法務ページ */
.site-footer {
  max-width: 800px;
  margin: 32px auto 0;
  padding: 20px 16px 40px;
  border-top: 1px solid var(--border-color);
  text-align: center;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 10px;
}

.footer-links a {
  color: var(--text-sub);
  text-decoration: none;
  font-size: 0.95rem;
}

.footer-links a:hover {
  color: var(--primary);
}

.footer-copy {
  font-size: 0.85rem;
  color: #64748b;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
}

.back-link:hover {
  text-decoration: underline;
}

/* 法務・案内ページ */
.legal-page {
  max-width: 800px;
  margin: 24px auto 0;
  padding: 0 16px 40px;
}

.legal-page-head {
  margin-bottom: 20px;
}

.legal-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 10px 0 6px;
}

.legal-updated {
  font-size: 0.85rem;
  color: #64748b;
}

.legal-section {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.legal-section h2 {
  font-size: 1.05rem;
  margin-top: 28px;
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 4px solid var(--primary);
  line-height: 1.4;
}

.legal-section h2:first-child {
  margin-top: 0;
}

.legal-section h3 {
  font-size: 0.95rem;
  margin-top: 18px;
  margin-bottom: 6px;
}

.legal-section p,
.legal-section li {
  color: var(--text-sub);
  line-height: 1.9;
}

.legal-section p + p {
  margin-top: 12px;
}

.legal-section a {
  color: var(--primary);
  word-break: break-all;
}

.legal-list {
  padding-left: 22px;
  margin: 8px 0;
}

.legal-list li + li {
  margin-top: 6px;
}

/* 補足・注意ボックス */
.legal-note {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 16px;
  font-size: 0.9rem;
}

.legal-note strong {
  color: var(--text-main);
}

/* 定義リスト風の表 */
.legal-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 4px;
  font-size: 0.9rem;
}

.legal-table th,
.legal-table td {
  border: 1px solid var(--border-color);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  color: var(--text-sub);
  line-height: 1.8;
}

.legal-table th {
  background: #f8fafc;
  color: var(--text-main);
  white-space: nowrap;
  width: 30%;
}

.legal-table-wrap {
  overflow-x: auto;
}

@media (max-width: 600px) {
  .app-card {
    padding: 16px;
  }

  .question-text {
    font-size: 1rem;
  }

  .grade-tab {
    font-size: 0.85rem;
    padding: 8px;
  }

  .landing-choices {
    grid-template-columns: 1fr;
  }

  .site-title {
    font-size: 1.05rem;
  }

  .legal-title {
    font-size: 1.35rem;
  }

  .legal-section {
    padding: 18px 16px;
  }

  .legal-table th {
    white-space: normal;
    width: 34%;
  }

  .info-section {
    padding: 18px 16px;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }
}