/* --- 基本設定と構造 --- */
body {
  font-family: "Arial", sans-serif;
  background-color: #f4f7f6;
  margin: 0;
  padding: 0;
  color: #333; /* 基本の文字色を設定 */
}

/* メインコンテンツエリアの共通設定 */
main {
  padding: 80px 20px 40px; /* 上(ヘッダー分)・左右・下 の余白 */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
}

/* 各ページのコンテンツコンテナの共通スタイル */
.container,
.settings,
.notes {
  background-color: #fff;
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 500px;
  box-sizing: border-box;
}

/* 各コンテナ内の見出しの共通スタイル */
.container h2,
.settings h2,
.notes h2 {
  text-align: center;
  color: #4c4c4c;
  margin-top: 0;
  margin-bottom: 25px;
}

/* --- ヘッダーとナビゲーション --- */
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #29a2c6;
  padding: 0 20px;
  box-sizing: border-box;
  z-index: 1000;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

header h1 {
  color: white;
  font-size: 24px;
  margin: 0;
}

header nav ul {
  display: flex;
  gap: 20px;
  list-style: none;
  margin: 0;
  padding: 0;
}

header nav a {
  color: white;
  text-decoration: none;
  font-weight: bold;
  padding: 5px;
  transition: opacity 0.3s;
}

header nav a:hover,
header nav a.active {
  /* (修正) activeクラスにもスタイルを適用 */
  opacity: 0.8;
  text-decoration: underline; /* (追加) アクティブなリンクを分かりやすく */
}

/* ハンバーガーメニューアイコン (JSでの表示切替を想定) */
header .fa-bars,
header .fa-xmark {
  display: none; /* (追加) デフォルトでは非表示 */
  color: white;
  font-size: 24px;
  cursor: pointer;
}

/* --- ToDoコンテナ --- */
.input-area {
  display: flex;
  margin-bottom: 20px;
}

#taskInput {
  flex-grow: 1;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
  font-size: 16px;
}

#taskInput:focus {
  outline: none;
  border-color: #29a2c6;
}

#addTaskButton {
  padding: 10px 15px;
  background-color: #29a2c6;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}

#addTaskButton:hover {
  background-color: #1e8bab; /* (修正) 少し明るめのホバー色に変更 */
}

.filter-area {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.filter-btn {
  background-color: #f0f0f0;
  border: 1px solid #ddd;
  color: #555;
  padding: 8px 12px;
  margin: 0 5px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.filter-btn.active {
  background-color: #29a2c6;
  color: white;
  border-color: #29a2c6;
}

.filter-btn:hover:not(.active) {
  background-color: #e0e0e0;
}

#taskList {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

#taskList li {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #eee;
  font-size: 16px;
}

#taskList li:last-child {
  border-bottom: none;
}

#taskList li .task-text {
  flex-grow: 1;
  cursor: pointer;
  margin: 0 10px; /* (修正) 左右にマージンを持たせる */
  word-break: break-all;
}

#taskList li.completed .task-text {
  text-decoration: line-through;
  color: #aaa;
}

#taskList li input[type="checkbox"] {
  /* (削除) margin-right: 10px; task-text側でマージンを管理 */
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: #29a2c6;
  flex-shrink: 0; /* (追加) 縮まないように */
}

/* (追加) タスクボタンのコンテナ */
.task-buttons {
  display: flex;
  flex-shrink: 0; /* (追加) ボタン群が縮まないように */
}

#taskList li .copy-btn {
  background-color: #ffcb18;
  color: #fff;
  border: none;
  padding: 6px 10px; /* (修正) パディング調整 */
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  margin-right: 6px;
  flex-shrink: 0; /* ★修正：ボタンが縮まないようにする */
}

#taskList li .copy-btn:hover {
  background-color: #efc025;
}

#taskList li .delete-btn {
  background-color: #ff6d31;
  color: white;
  border: none;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0; /* ★修正：ボタンが縮まないようにする */
}

#taskList li .delete-btn:hover {
  background-color: #e55a23;
}

/* --- 設定セクション --- */
.setting-item {
  display: flex;
  justify-content: space-between; /* (修正) 両端に配置 */
  align-items: center;
  padding: 10px 0; /* (追加) 上下に余白を追加 */
}

.setting-item:not(:last-child) {
  border-bottom: 1px solid #eee; /* (追加) 区切り線 */
}

/* (削除) .settings div {...} は .setting-item と重複するため不要 */
/* (削除) .switch-label は通常のlabelタグで十分なため不要 */

/* --- スイッチのCSS (HTML構造の変更に合わせて修正) --- */
/*
  HTMLを以下のように変更することを推奨します。
  <div class="setting-item">
    <label for="confirmSwitch">削除時に確認する</label>
    <label class="switch">
      <input type="checkbox" id="confirmSwitch" />
      <span class="slider round"></span>
    </label>
  </div>
  このCSSは、input[type="checkbox"]を直接スタイリングする方法に切り替えます。
  これにより、.switchクラスの複雑なCSSが不要になります。
*/
input[type="checkbox"]#confirmSwitch,
input[type="checkbox"]#addPositionSwitch {
  appearance: none; /* ブラウザのデフォルトスタイルを無効化 */
  -webkit-appearance: none;
  position: relative;
  width: 40px;
  height: 24px;
  background-color: #ccc;
  border-radius: 23px;
  cursor: pointer;
  transition: background-color 0.3s;
}

input[type="checkbox"]#confirmSwitch::before,
input[type="checkbox"]#addPositionSwitch::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: white;
  top: 3px;
  left: 3px;
  transition: transform 0.3s;
}

input[type="checkbox"]#confirmSwitch:checked,
input[type="checkbox"]#addPositionSwitch:checked {
  background-color: #29a2c6;
}

input[type="checkbox"]#confirmSwitch:checked::before,
input[type="checkbox"]#addPositionSwitch:checked::before {
  transform: translateX(16px);
}

/* --- 記録(MEMOS)セクション --- */
.notes .memos {
  list-style-type: disc;
  padding-left: 20px;
  margin: 0;
  color: #555;
}

.notes .memos li {
  margin-bottom: 15px; /* (修正) 少し調整 */
}

/* --- フッター --- */
footer {
  text-align: center;
  padding: 20px;
  color: #888;
  font-size: 14px;
}

/* --- ユーティリティ --- */
.hidden {
  display: none;
}

/* ドラッグ中のタスクのスタイル */
#taskList li.dragging {
  opacity: 0.5;
  background: #f0f8ff;
}

/* タスクがない時のメッセージ用のスタイル */
#taskList li.empty-message {
  color: #888;
  text-align: center;
  padding: 15px;
  list-style-type: none;
  justify-content: center; /* (追加) 中央揃え */
  border-bottom: none;
}

/* --- レスポンシブ対応 (モバイル表示) --- */
@media (max-width: 768px) {
  header nav {
    /* ここにモバイル用のナビゲーションメニューのスタイルを記述します。 */
    /* 例: ハンバーガーメニュークリックで表示されるドロップダウンメニューなど */
    display: none; /* デスクトップ用ナビは非表示に */
  }
  header .fa-bars {
    display: block; /* モバイルではハンバーガーアイコンを表示 */
  }
  /* (JSで `.nav-open` のようなクラスをbodyに付与することを想定) */
  body.nav-open header .fa-bars {
    display: none;
  }
  body.nav-open header .fa-xmark {
    display: block;
  }
  body.nav-open header nav {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 60px;
    left: 0;
    width: 100%;
    background-color: #29a2c6;
    padding: 10px 0;
  }
  body.nav-open header nav li {
    text-align: center;
    padding: 10px 0;
  }
}

/* --- 並び替え機能の改善のためのCSS --- */

/* 各タスク項目の設定 */
#taskList li {
  display: flex; /* Flexboxで要素を横並びにする */
  align-items: center; /* 要素を垂直方向中央に揃える */
  gap: 8px; /* 要素間の隙間 */
}

/* タスクテキストが長くなってもレイアウトが崩れないようにする */
#taskList .task-text {
  flex-grow: 1; /* 残りのスペースをすべて埋める */
  margin-right: auto; /* 右側の要素を押し出す */
  cursor: pointer;
}

/* 並び替えハンドルのスタイル */
.drag-handle {
  cursor: grab; /* PCで掴めることを示すカーソル */
  color: #aaa;
  font-size: 1.2em;
  padding: 0 8px;
  /* タッチ操作時にページのスクロールを無効化する（重要） */
  touch-action: none;
}
/* ドラッグ（掴んでいる）最中のカーソル */
.drag-handle:active {
  cursor: grabbing;
}

/* ドラッグ中のリストアイテムのスタイル（既存のものを流用・強化） */
#taskList li.dragging {
  opacity: 0.5;
  background: #cce5ff; /* ドラッグ中を分かりやすく色付け */
}
