/* ====== :root 定義（カラーテーマ） ====== */
:root {
  --bg-color: #fdfaf6;
  --text-color: #2c1f14;
  --primary-color: #4a7c59;
  --sunday-bg: #fbeaea;
  --saturday-bg: #e8f1f8;
  --today-border: 2px solid #a4d4a4;
  --event-bg: #a0cba0;

  --dark-bg: #122212;
  --dark-text: #a6d6a6;
  --dark-primary: #7db87d;
}

/* ====== ダークモード設定 ====== */
@media (prefers-color-scheme: dark) {
  body {
    background: var(--dark-bg);
    color: var(--dark-text);
  }
  header h1, #calendar-header button {
    color: var(--dark-primary);
  }
  table, th, td {
    border-color: var(--dark-primary);
  }
  td.sunday {
    background: #330000;
    color: #ff8888;
  }
  td.saturday {
    background: #001144;
    color: #88ccff;
  }
  td.today {
    border: 2px solid var(--dark-primary);
    background: #224422;
  }
  #modal, #settings-modal {
    background: #223322;
    color: var(--dark-text);
  }
  #modal-bg, #settings-modal-bg {
    background: rgba(10,30,10,0.85);
  }
  button {
    background: var(--dark-primary);
    color: var(--dark-bg);
  }
  button:hover {
    background: #a4d4a4;
    color: var(--dark-bg);
  }
}

/* ====== ボディとレイアウト ====== */
body {
  background: var(--bg-color);
  color: var(--text-color);
  font-family: "Yu Mincho", serif;
  margin: 0;
  padding: 20px;
  min-height: 100vh;

  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ====== ヘッダー ====== */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

/* ヘッダーアイコン */
#header-icon-light, #header-icon-dark {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 0 1px #333);
  display: none;
}
@media (prefers-color-scheme: dark) {
  #header-icon-dark { display: inline; }
}
@media (prefers-color-scheme: light) {
  #header-icon-light { display: inline; }
}

/* タイトル */
h1 {
  color: var(--primary-color);
  margin: 0;
  font-size: 1.6rem;
}

/* 設定ボタン */
#settings-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  margin-left: auto;
  color: var(--primary-color);
  transition: color 0.3s ease;
}
#settings-btn:hover,
#settings-btn:focus {
  color: #357a32;
  outline: none;
}

/* ====== カレンダー全体 ====== */
#calendar {
  max-width: 720px;
  width: 100%;
  background: white;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 0 8px rgba(0,0,0,0.1);
  flex-grow: 1;

  display: flex;
  flex-direction: column;
}

/* カレンダー操作ヘッダー（年月と左右ボタン） */
#calendar-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

/* 月と年表示 */
#month-year {
  font-weight: bold;
  font-size: 1.2rem;
  min-width: 140px;
  text-align: center;
}

/* ====== ボタン全般 ====== */
button {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.3s ease;
}
button:hover {
  background-color: #357a32;
}

/* ====== カレンダーテーブル ====== */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  word-break: break-word;
}
th, td {
  border: 1px solid #ccc;
  padding: 6px;
  height: 80px;
  text-align: left;
  vertical-align: top;
  user-select: none;
  overflow: hidden;
}

/* 日曜・土曜背景色 */
td.sunday {
  background: var(--sunday-bg);
  color: #d00;
}
td.saturday {
  background: var(--saturday-bg);
  color: #0078d7;
}

/* 今日の枠線 */
td.today {
  border: var(--today-border);
  background: #e6f4e6;
}

/* 月の範囲外セル */
td.adjacent-month {
  color: #999;
  background: #f0f0f0;
  cursor: default !important;
}

/* ====== 予定表示 ====== */
.event {
  background: var(--event-bg);
  color: #111;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 13px;
  margin: 4px 0 2px 0;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* タグのラベル */
.event-tag {
  padding: 0 4px;
  margin-left: 6px;
  border-radius: 4px;
  font-size: 0.75em;
  color: white;
  display: inline-block;
}

/* ====== モーダル背景 ====== */
.modal-bg, #settings-modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

/* ====== モーダル本体 ====== */
#modal, #settings-modal {
  background: white;
  border-radius: 10px;
  padding: 20px;
  width: 90%;
  max-width: 480px;
  box-sizing: border-box;
  max-height: 90vh;
  overflow-y: auto;
}

/* テキスト入力系 */
textarea, input[type="time"], input[type="color"], input[type="text"] {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 14px;
  box-sizing: border-box;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 6px;
  resize: vertical;
}

/* モーダル内ボタン配置 */
.modal-buttons {
  text-align: right;
}
.modal-buttons button {
  margin-left: 8px;
  font-size: 14px;
}

/* 今日ボタン */
#today-button {
  margin: 15px auto 30px auto;
  width: 140px;
}

/* タグ色設定リスト */
#tag-color-list > div {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* タグ名ラベル */
#tag-color-list label {
  flex-grow: 1;
  font-weight: bold;
}

/* カラーピッカー */
#tag-color-list input[type="color"] {
  width: 40px;
  height: 30px;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 4px;
}

/* タグ行 */
.tag-row {
  border: 1px solid #ccc;
  padding: 6px 8px;
  border-radius: 6px;
  background: #f7f7f7;
  transition: background-color 0.2s ease;
}
.tag-row:hover {
  background: #e0e0e0;
}

/* タグ削除ボタン */
.tag-row button {
  background: #4a7c59;
  border: none;
  color: white;
  cursor: pointer;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.85em;
}
.tag-row button:hover {
  background: #357a32;
}

/* ====== レスポンシブ（スマホ対応） ====== */
@media (max-width: 600px) {
  #calendar {
    padding: 8px;
  }
  th, td {
    font-size: 12px;
    height: 60px;
    padding: 4px;
  }
  #month-year {
    font-size: 1rem;
  }
  button {
    padding: 5px 8px;
    font-size: 14px;
  }
  textarea, input[type="time"] {
    font-size: 13px;
  }
}
