body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  max-width: 1800px;
  margin: 20px auto;
  padding: 0 20px;
  background-color: #f4f7f6;
  color: #333;
}

.app-description {
  margin: -6px 0 14px;
  color: #5f6b7a;
  font-size: 0.95rem;
  line-height: 1.6;
}

.main-container {
  display: flex; /* 左右に並べる */
  gap: 40px; /* 左右の余白 */
  align-items: flex-start;
  justify-content: space-between; /* 両端に寄せる */
}

.left-column {
  width: 880px; /* 授業欄の横幅を2倍に拡大 (440px * 2) */
  flex: 0 0 auto;
}

.right-column {
  width: 440px; /* 履修管理状況を全体の約1/3の幅に調整 */
  position: sticky;
  top: 150px; /* 固定ヘッダーの高さに合わせて調整 */
  max-height: calc(100vh - 170px); /* 画面からはみ出さないよう高さを制限 */
  overflow-y: auto; /* 科目が増えた場合にリスト内スクロールを可能にする */
  /* 枠のような見た目にする */
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.summary-box {
  background: #e9ecef;
  padding: 15px;
  border-radius: 4px;
  margin-bottom: 20px;
  font-weight: bold;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

@keyframes slideIn {
  /* アニメーションを削除するため、このキーフレームは不要になります */
}

.input-area {
  display: flex;
  gap: 10px;
  margin-bottom: 0;
  align-items: center;
}

.input-area select {
  padding: 10px;
  border: 2px solid #007bff;
  border-radius: 4px;
  background: white;
}

.input-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#search-bar {
  flex: 1;
  padding: 10px;
  border: 2px solid #007bff;
  border-radius: 4px;
  box-sizing: border-box;
}

#addBtn {
  width: 100%;
  padding: 12px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

#addBtn:hover { background-color: #0056b3; }

.class-item {
  background: white;
  border-left: 5px solid #d1d5db;
  padding: 15px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* 追加済みアイテムのグレーアウト表示 */
.class-item.added {
  background-color: #f0f0f0 !important;
  border-left-color: #adb5bd !important;
  opacity: 0.7;
}

.class-item.added .add-predefined, .class-item.added .complete-predefined {
  background-color: #6c757d !important;
  cursor: not-allowed;
}

.delete-btn {
  background: #ff4d4f;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.add-predefined {
  background: #007bff;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
}
.add-predefined:hover { background: #0056b3; }

.complete-predefined {
  background: #28a745;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
}
.complete-predefined:hover { background: #218838; }

.complete-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 5px;
}

.detail-btn {
  background: #6c757d;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 5px;
}

.predefined-item {
  margin-bottom: 10px;
}

.class-detail {
  /* 「詳細」エリアの初期状態：高さを0にして隠す */
  max-height: 0;
  overflow: hidden;
  transition: all 0.3s ease-out;
  background: #fff;
  padding: 0 15px;
  border-radius: 0 0 4px 4px;
}

.class-detail.open {
  max-height: 1000px;
  padding: 10px 15px;
  border: 1px solid #ddd;
  border-top: none;
}

/* 右カラム見出しの装飾線 */
.scheduled-title {
  border-top: 5px solid #007bff;
  padding-top: 10px;
  margin-top: 20px;
}

.completed-title {
  border-top: 5px solid #28a745;
  padding-top: 10px;
  margin-top: 30px;
}

/* 必修分析ボタン */
#analysis-btn {
  padding: 12px 18px;
  background-color: #1d4ed8;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 8px 18px rgba(29, 78, 216, 0.25);
  border: 2px solid rgba(29, 78, 216, 0.35);
}
#analysis-btn:hover {
  background-color: #1e40af;
  transform: translateY(-1px);
}
#analysis-btn:active {
  transform: translateY(0px);
  box-shadow: 0 6px 14px rgba(29, 78, 216, 0.2);
}

/* アプリタイトル行 */
.app-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.app-title-row h1 {
  margin: 0;
  font-size: 28px;
}

.top-credit-gauge {
  min-width: 320px;
  background: #ffffff;
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  border: 1px solid #e6eefc;
}

.top-credit-gauge .gauge-label {
  display: inline-block;
  font-size: 12px;
  color: #4b5563;
  margin-right: 8px;
  font-weight: 700;
}

.top-credit-gauge .gauge-value {
  font-weight: 900;
  color: #0f172a;
}

.top-credit-gauge .gauge-bar {
  margin-top: 8px;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.top-credit-gauge .gauge-fill {
  height: 100%;
  width: 0%;
  background: #3b82f6;
  transition: width 0.25s ease;
}

/* モーダル基本設定 */
.modal-overlay {
  display: none;
  position: fixed;
  z-index: 2000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  padding: 30px;
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 28px;
  cursor: pointer;
  color: #888;
}
.close-btn:hover { color: #333; }

.class-detail .description {
  font-size: 0.9em;
  margin: 8px 0;
  color: #555;
  line-height: 1.4;
}

.class-detail .meta {
  color: #888;
}

.syllabus-link {
  font-size: 0.85em;
  color: #007bff;
  text-decoration: none;
}

/* フィルターUIのスタイル */
.filter-container {
  background: #fff;
  padding: 15px;
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-container select {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}

.category-highlight {
  color: #e53e3e; /* 赤系の色 */
  font-weight: bold;
  background-color: #fff5f5; /* 薄い赤の背景 */
  padding: 0 4px;
  border-radius: 3px;
  border: 1px solid #feb2b2;
}

/* 詳細画面のレイアウト改善 */
.detail-subject {
  margin: 0 0 10px 0;
  font-size: 1.1em;
  color: #2d3748;
  border-bottom: 2px solid #edf2f7;
  padding-bottom: 5px;
}

.detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.badge-cat, .badge-item {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.85em;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  height: 24px; /* 高さを一定にしてズレを防止 */
  box-sizing: border-box;
  border: 1px solid transparent; /* 枠線の有無による1〜2pxのガタつきを防止 */
}

.badge-cat { background: #edf2f7; color: #4a5568; border-color: #edf2f7; }
.badge-cat.important { background: #fff5f5; color: #e53e3e; border: 1px solid #feb2b2; }
.badge-item { background: #ebf8ff; color: #2b6cb0; border: 1px solid #bee3f8; }

.detail-sections p {
  margin: 6px 0;
  font-size: 0.9em;
  line-height: 1.5;
}

.detail-sections .description {
  background: #f8fafc;
  padding: 8px;
  border-radius: 4px;
}

.difficulty-section {
  margin-top: 15px;
  padding: 12px;
  border: 1px solid #dbeafe;
  border-left: 4px solid #2563eb;
  border-radius: 4px;
  background: #f8fafc;
  color: #334155;
}

.difficulty-section p {
  margin: 0 0 6px;
}

.difficulty-title {
  margin: 0 0 10px;
  color: #1e3a8a;
  font-size: 1em;
  font-weight: 700;
}

.difficulty-source-row {
  margin-bottom: 0 !important;
}

.difficulty-source {
  color: #1d4ed8;
  text-decoration: underline;
}

.difficulty-source:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
  border-radius: 2px;
}

/* Footer Styles */
.app-footer {
  margin-top: 60px; /* メインコンテンツからの上部余白 */
  padding: 30px 20px; /* 上下左右のパディング */
  background-color: #f8f9fa; /* 薄いグレーの背景色 */
  color: #6c757d; /* テキストの色 */
  text-align: center; /* テキストを中央揃え */
  font-size: 0.875em; /* 本文より少し小さい文字サイズ (例: 14px) */
  line-height: 1.6; /* 行の高さ */
  border-top: 1px solid #e9ecef; /* 上部に控えめな境界線 */
}

.app-footer p {
  margin: 0; /* 段落のデフォルトマージンをリセット */
  padding: 2px 0; /* 各行の上下にわずかなパディング */
}

.app-footer a {
  color: #1d4ed8;
}

.app-footer a:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

/* Search Count Styles */
.search-count {
  font-size: 0.95em;
  color: #666;
  margin: -10px 0 15px 5px; /* 見出しとのバランス調整 */
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  font-size: 0.75rem;
  border-radius: 4px;
  background-color: #f3f4f6;
  color: #4b5563;
  border: 1px solid #d1d5db;
  white-space: nowrap;
}

.badge.required {
  background-color: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

/* 上部操作エリアの固定表示 */
.sticky-controls {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: white;
  padding: 15px 0 20px 0;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 25px;
  /* 背景を透過させないため、bodyの背景色に合わせた透過防止（または完全な白） */
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* 使い方ボタン（右下固定） */
#tutorial-btn {
  position: fixed;
  bottom: 25px;
  right: 20px; /* 少し内側に調整 */
  padding: 10px 18px; /* テキストに合わせてパディングを調整 */
  border-radius: 25px; /* 角丸の長方形に */
  background-color: #007bff; /* 青色 */
  color: white;
  border: none;
  font-size: 18px; /* 文字サイズを調整 */
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  z-index: 3000; /* 他の要素より上に表示 */
  transition: transform 0.2s, background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tutorial-btn:hover {
  transform: scale(1.1);
  background-color: #0056b3;
}

@media (max-width: 768px) {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    margin: 0;
    padding: 0 12px 80px;
  }

  .sticky-controls {
    position: static;
    left: auto;
    right: auto;
    transform: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px 0 16px;
    margin-bottom: 18px;
  }

  .app-title-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .app-title-row h1 {
    font-size: 24px;
    line-height: 1.25;
  }

  .app-description {
    margin: 0 0 12px;
    font-size: 0.9rem;
  }

  .top-credit-gauge {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .input-area {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #search-bar,
  #analysis-btn {
    grid-column: 1 / -1;
  }

  #search-bar,
  .input-area select,
  #analysis-btn {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .main-container {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    gap: 24px;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow-x: hidden;
  }

  .left-column,
  .right-column {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 0 0 100% !important;
    flex-basis: 100% !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  /* スマホでは履修状況を先に確認できるよう、右カラムを一覧より前へ移動 */
  .right-column {
    order: 1 !important;
    position: static !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    transform: none !important;
    align-self: stretch !important;
  }

  .left-column {
    order: 2 !important;
    position: static !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    transform: none !important;
    align-self: stretch !important;
  }

  .predefined-classes-section {
    box-sizing: border-box;
  }

  .right-column {
    max-height: none;
    overflow-y: visible;
    padding: 16px;
  }

  #predefined-classes-list,
  #list,
  #completed-list {
    margin: 0;
    padding-left: 0;
    list-style: none;
    width: 100%;
    max-width: 100%;
  }

  .predefined-item,
  .class-item {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .class-item {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px;
  }

  .class-info {
    min-width: 0;
  }

  .class-info strong {
    display: block;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  .class-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
  }

  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .actions button,
  .detail-btn,
  .add-predefined,
  .complete-predefined,
  .delete-btn {
    flex: 1 1 88px;
    min-width: 0;
    margin-right: 0;
    box-sizing: border-box;
    white-space: nowrap;
  }

  .class-detail {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-left: 12px;
    padding-right: 12px;
  }

  .class-detail.open {
    max-height: none;
    padding: 10px 12px;
  }

  .detail-subject,
  .detail-sections p,
  .difficulty-section {
    overflow-wrap: anywhere;
  }

  .difficulty-section {
    padding: 10px;
  }

  .modal-content {
    width: calc(100% - 24px);
    max-width: calc(100% - 24px);
    padding: 22px 16px;
    box-sizing: border-box;
  }

  #tutorial-btn {
    right: 12px;
    bottom: 14px;
    padding: 9px 14px;
    font-size: 15px;
  }
}

@media (max-width: 420px) {
  .input-area {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* 使い方モーダル内のレイアウト調整 */
.tutorial-content {
  max-width: 500px;
}

.tutorial-content h1 {
  font-size: 1.5rem;
  border-bottom: 2px solid #007bff;
  padding-bottom: 8px;
  margin-bottom: 15px;
}

.tutorial-section {
  margin-top: 15px;
  text-align: left;
}

.disclaimer-box {
  background: #f8f9fa;
  padding: 12px;
  border-radius: 5px;
  margin-top: 15px;
  border: 1px solid #e9ecef;
}

/*
 * モバイル最終上書き（このファイルの末尾でPC向け指定との競合を解消）
 * Safariでデスクトップ用の固定幅が残らないよう、親子の幅とflex-basisを明示する。
 */
@media screen and (max-width: 768px) {
  html,
  body {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  body {
    margin: 0 !important;
    padding: 0 12px 80px !important;
  }

  .sticky-controls,
  .app-title-row,
  .input-area,
  .main-container,
  .left-column,
  .right-column,
  .predefined-classes-section,
  .class-item {
    box-sizing: border-box !important;
    min-width: 0 !important;
  }

  .sticky-controls,
  .app-title-row {
    width: 100% !important;
    max-width: 100% !important;
  }

  .app-title-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .top-credit-gauge {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .input-area {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 18px !important;
  }

  #search-bar,
  #analysis-btn {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .input-area select {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .main-container {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    gap: 24px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .right-column,
  .left-column {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 0 0 100% !important;
    flex-basis: 100% !important;
    position: static !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    transform: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    align-self: stretch !important;
  }

  .right-column {
    order: 1 !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  .left-column {
    order: 2 !important;
  }

  .predefined-classes-section,
  #predefined-classes-list,
  #list,
  #completed-list,
  .predefined-item,
  .class-item,
  .class-detail,
  .difficulty-section {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .class-info,
  .class-detail,
  .detail-sections,
  .difficulty-section {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

@media screen and (max-width: 420px) {
  .input-area {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}
