/* ===== くすみカラーのやさしいテーマ ===== */
:root {
  --bg: #F5F1EA;
  --card: #FFFDF9;
  --text: #5B5650;
  --text-sub: #9B948B;
  --line: #E7E0D6;
  --shadow: 0 4px 16px rgba(120, 110, 95, 0.10);
  --shadow-soft: 0 2px 8px rgba(120, 110, 95, 0.08);

  /* カテゴリ色の初期値(実際の値は app.js の applyColors が上書きする) */
  --libe: #5C7EA8;    /* リベ活：濃いめのくすみブルー */
  --life: #C97C6B;    /* 私生活：くすみコーラル */
  --senior: #7E9A6F;  /* シニアマスター：深めのセージグリーン */

  --libe-bg: #E9EDF3;
  --life-bg: #F8EDEA;
  --senior-bg: #ECF1E9;

  --libe-tag-bg: #DCE6F0;   --libe-tag-fg: #3A5578;
  --life-tag-bg: #F5E0DA;   --life-tag-fg: #8C4A3B;
  --senior-tag-bg: #E3ECDD; --senior-tag-fg: #4A6340;

  --danger: #C98A8A;  /* 期限切れ・削除（くすみレッド） */
  --warn: #BE9B5F;    /* 期限間近（くすみアンバー） */

  --radius: 16px;
  font-size: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Maru Gothic ProN", "Zen Maru Gothic", "M PLUS Rounded 1c", "Hiragino Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* ===== ヘッダー ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: rgba(245, 241, 234, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.app-title {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.06em;
}

.header-actions { position: relative; }

.icon-btn {
  border: none;
  background: var(--card);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.94); }

.menu {
  position: absolute;
  right: 0;
  top: 46px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 220px;
  z-index: 30;
}
.menu-item {
  display: block;
  width: 100%;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.menu-item:hover { background: var(--bg); }
.menu-sep { border: none; border-top: 1px solid var(--line); margin: 4px 8px; }

/* ===== レイアウト ===== */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 16px 0;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

/* ===== 週カレンダー ===== */
.calendar { padding: 14px 12px 12px; }

.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}
.calendar-head .icon-btn {
  background: var(--bg);
  box-shadow: none;
  width: 34px;
  height: 34px;
  font-size: 1.3rem;
}
.calendar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.98rem;
}
.today-jump {
  border: none;
  background: var(--bg);
  color: var(--text-sub);
  font: inherit;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 99px;
  cursor: pointer;
}

.week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.day-cell {
  border: none;
  background: none;
  font: inherit;
  color: var(--text);
  border-radius: 12px;
  padding: 7px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  min-height: 66px;
}
.day-cell:active { background: var(--bg); }
.day-dow { font-size: 0.68rem; color: var(--text-sub); }
.day-cell.is-sat .day-dow { color: #8FA8C8; }
.day-cell.is-sun .day-dow { color: #D8A7B1; }

.day-num {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.92rem;
}
.day-cell.is-today .day-num {
  background: var(--text);
  color: var(--card);
  font-weight: 600;
}
.day-cell.is-selected {
  background: var(--bg);
  box-shadow: inset 0 0 0 1.5px var(--line);
}

.day-dots {
  display: flex;
  gap: 3px;
  height: 6px;
  align-items: center;
}
.day-dots .dot { width: 6px; height: 6px; }
.day-more { font-size: 0.6rem; color: var(--text-sub); line-height: 1; }

.date-chip {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 99px;
  padding: 6px 8px 6px 14px;
  font-size: 0.82rem;
}
.date-chip button {
  border: none;
  background: var(--card);
  color: var(--text-sub);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
}

/* ===== カテゴリタブ ===== */
.cat-tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0 14px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cat-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  border: none;
  background: var(--card);
  color: var(--text-sub);
  font: inherit;
  font-size: 0.86rem;
  padding: 8px 15px;
  border-radius: 99px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.cat-tab.is-active {
  background: var(--text);
  color: var(--card);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-libe { background: var(--libe); }
.dot-life { background: var(--life); }
.dot-senior { background: var(--senior); }

/* ===== タスクリスト ===== */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 13px 14px 13px 12px;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  border-left: 4px solid transparent;
  cursor: pointer;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.task-card.cat-libe   { border-left-color: var(--libe);   background: linear-gradient(to right, var(--libe-bg),   var(--card) 46%); }
.task-card.cat-life   { border-left-color: var(--life);   background: linear-gradient(to right, var(--life-bg),   var(--card) 46%); }
.task-card.cat-senior { border-left-color: var(--senior); background: linear-gradient(to right, var(--senior-bg), var(--card) 46%); }

.task-check {
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin: 1px 0 0;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.task-check:checked {
  border-color: var(--senior);
  background: var(--senior);
}
.task-check:checked::after {
  content: "✓";
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
}

.task-body { flex: 1; min-width: 0; }
.task-title {
  font-size: 0.98rem;
  line-height: 1.45;
  word-break: break-word;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-sub);
}
.cat-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2.5px 9px;
  border-radius: 99px;
  white-space: nowrap;
}
.tag-libe   { background: var(--libe-tag-bg);   color: var(--libe-tag-fg); }
.tag-life   { background: var(--life-tag-bg);   color: var(--life-tag-fg); }
.tag-senior { background: var(--senior-tag-bg); color: var(--senior-tag-fg); }
.task-card.is-done .cat-tag { background: var(--bg); color: var(--text-sub); }

.task-due.is-overdue { color: var(--danger); font-weight: 600; }
.task-due.is-soon { color: var(--warn); font-weight: 600; }
.task-memo-mark { font-size: 0.72rem; }

.drag-handle {
  color: var(--line);
  font-size: 1rem;
  padding: 2px 0;
  flex-shrink: 0;
  letter-spacing: -1px;
}

/* 完了タスク */
.task-card.is-done {
  opacity: 0.55;
  box-shadow: none;
}
.task-card.is-done .task-title {
  text-decoration: line-through;
  color: var(--text-sub);
}

.done-heading {
  font-size: 0.82rem;
  color: var(--text-sub);
  font-weight: 600;
  margin: 22px 4px 10px;
}

.empty-msg {
  text-align: center;
  color: var(--text-sub);
  padding: 44px 0;
  font-size: 0.92rem;
}

/* ドラッグ中 */
.task-card.drag-source {
  opacity: 0.35;
  box-shadow: none;
}
.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 12px 28px rgba(120, 110, 95, 0.28);
  transform: scale(1.03) rotate(0.6deg);
  opacity: 0.95;
}
body.is-dragging { cursor: grabbing; }
body.is-dragging * { -webkit-user-select: none; user-select: none; }

/* ===== FAB ===== */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--text);
  color: var(--card);
  font-size: 1.7rem;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(91, 86, 80, 0.35);
  cursor: pointer;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:active { transform: scale(0.92); }

/* ===== 追加・編集シート ===== */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(91, 86, 80, 0.32);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--card);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 560px;
  padding: 10px 22px calc(22px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -8px 32px rgba(120, 110, 95, 0.18);
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: var(--line);
  margin: 4px auto 12px;
}
.sheet-title {
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-sub);
  margin-bottom: 6px;
}
.field-label em {
  font-style: normal;
  font-size: 0.68rem;
  color: var(--danger);
  margin-left: 4px;
}

input[type="text"], input[type="date"], textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  padding: 11px 13px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-height: 46px;
}
input:focus, textarea:focus { border-color: var(--libe); background: var(--card); }
textarea { resize: vertical; }

.cat-choice { display: flex; gap: 8px; flex-wrap: wrap; }
.cat-choice label { cursor: pointer; }
.cat-choice input { position: absolute; opacity: 0; pointer-events: none; }

.cat-pill {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 99px;
  font-size: 0.88rem;
  border: 1.5px solid var(--line);
  color: var(--text-sub);
  background: var(--card);
  transition: all 0.15s;
}
.pill-libe   { border-color: var(--libe); }
.pill-life   { border-color: var(--life); }
.pill-senior { border-color: var(--senior); }
input:checked + .pill-libe   { background: var(--libe);   color: #fff; }
input:checked + .pill-life   { background: var(--life);   color: #fff; }
input:checked + .pill-senior { background: var(--senior); color: #fff; }

/* カラー設定 */
.color-row { margin-bottom: 20px; }
.color-row-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  margin-bottom: 9px;
}
.color-row-label .dot { width: 12px; height: 12px; }
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.swatch:active { transform: scale(0.9); }
.swatch.is-selected {
  box-shadow: 0 0 0 2.5px var(--card), 0 0 0 4.5px var(--text);
}
.swatch-input {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px dashed var(--text-sub);
  padding: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  overflow: hidden;
}
.swatch-input::-webkit-color-swatch-wrapper { padding: 3px; }
.swatch-input::-webkit-color-swatch { border: none; border-radius: 50%; }

.sheet-note {
  font-size: 0.82rem;
  color: var(--text-sub);
  line-height: 1.7;
  margin: 0 0 16px;
}
.sync-status {
  font-size: 0.82rem;
  color: var(--text-sub);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 1em;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
}
.spacer { flex: 1; }

.btn {
  border: none;
  font: inherit;
  font-size: 0.92rem;
  padding: 11px 20px;
  border-radius: 99px;
  cursor: pointer;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--text); color: var(--card); }
.btn-ghost { background: var(--bg); color: var(--text-sub); }
.btn-danger { background: none; color: var(--danger); padding-left: 4px; }

/* ===== 広い画面（MacBook） ===== */
@media (min-width: 720px) {
  :root { font-size: 17px; }
  .container { padding: 8px 24px 0; }
  .calendar { padding: 18px 20px 16px; }
  .day-cell { min-height: 74px; }
  .task-card { padding: 15px 18px 15px 14px; }
  .fab { right: calc(50% - 360px + 20px); }
}
