:root {
  --bg: #ffffff;
  --surface: #f4f5f7;
  --surface2: #eceef2;
  --text: #1b1d22;
  --muted: #6b7080;
  --line: #e6e8ec;
  --circle: #b4b8c2;
  --accent: #2f6bea;
  --accent-soft: #e3ebfd;
  --on-accent: #ffffff;
  --danger: #d93a3a;
  --shadow: 0 8px 30px rgba(20, 24, 33, .14);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #141518;
  --surface: #1e2024;
  --surface2: #272a30;
  --text: #e6e7ea;
  --muted: #9ba0ad;
  --line: #2a2d33;
  --circle: #5d626d;
  --accent: #8ab0ff;
  --accent-soft: #223a73;
  --on-accent: #0b2560;
  --danger: #ff7b72;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }

/* ---- 上部：グループのタブとアイコン ---- */
.top {
  display: flex; align-items: center; gap: 2px;
  padding: calc(env(safe-area-inset-top) + 6px) 4px 4px 0;
}
.tabs {
  flex: 1; min-width: 0; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  padding: 0 8px 0 12px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 8px 14px; border-radius: 999px; white-space: nowrap;
  color: var(--muted); font-size: 16px; transition: background .15s, color .15s;
}
.tab.on { background: var(--surface2); color: var(--text); font-weight: 700; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:active { background: var(--surface2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---- 横にスワイプするページ（1グループ＝1ページ） ---- */
.pager {
  flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
.pager::-webkit-scrollbar { display: none; }
.page {
  flex: 0 0 100%; width: 100%; height: 100%; overflow-y: auto; scroll-snap-align: start;
  scroll-snap-stop: always; overscroll-behavior-y: contain;
}
.filters { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: 4px 0 6px; }
.chips-row {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px 16px; align-items: center;
}
.chips-row::-webkit-scrollbar { display: none; }
.chips-row .lead { flex: none; color: var(--muted); }
.chips-row .lead svg { width: 18px; height: 18px; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 4px;
  height: 34px; padding: 0 13px; border-radius: 10px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px;
}
.chip svg { width: 16px; height: 16px; }
.chip.on { background: var(--accent-soft); border-color: transparent; color: var(--text); font-weight: 600; }
.chip.dim { color: var(--muted); }
.chip .x { margin-right: -6px; padding: 4px; border-radius: 50%; display: grid; place-items: center; }
.chip-select { position: relative; flex: none; }
.chip-select select {
  position: absolute; inset: 0; opacity: 0; width: 100%; font-size: 16px;
}

/* ---- タスクの行 ---- */
.list { padding-bottom: 24px; }
.section-title { padding: 14px 20px 4px; font-size: 13px; font-weight: 700; color: var(--accent); }
.task { display: flex; align-items: center; min-height: 52px; padding-right: 16px; border-bottom: 1px solid var(--line); margin-left: 0; }
.task .check { flex: none; width: 52px; height: 52px; display: grid; place-items: center; }
.task .check i {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--circle);
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.task .check i svg { width: 14px; height: 14px; color: var(--on-accent); opacity: 0; }
.task.checked .check i { background: var(--accent); border-color: var(--accent); }
.task.checked .check i svg { opacity: 1; }
.task.checked .title { color: var(--muted); text-decoration: line-through; }
.task .body { flex: 1; min-width: 0; padding: 12px 0; cursor: pointer; }
.task .title { overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 2px; font-size: 13px; color: var(--muted); }
.meta span { display: inline-flex; align-items: center; gap: 3px; }
.meta svg { width: 13px; height: 13px; }
.meta .today { color: var(--accent); }
.meta .over { color: var(--danger); }
.task.leaving { animation: leave .25s ease forwards; }
@keyframes leave { to { opacity: 0; transform: translateX(24px); } }
.empty { padding: 72px 32px; text-align: center; color: var(--muted); white-space: pre-line; }

/* ---- 下の追加欄 ---- */
.addbar {
  background: var(--surface); padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--line);
}
.add-opts { display: flex; gap: 8px; padding-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.add-form { display: flex; gap: 8px; align-items: center; }
.add-form input {
  flex: 1; min-width: 0; height: 46px; border: 0; border-radius: 23px; padding: 0 18px;
  background: var(--bg); outline: none; font-size: 16px;
}
.add-form input::placeholder { color: var(--muted); }
.send {
  flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); transition: opacity .15s;
}
.send:disabled { opacity: .35; }
.send svg { width: 22px; height: 22px; }

/* ---- 全画面（完了済み・グループ） ---- */
.screen {
  position: fixed; inset: 0; z-index: 10; background: var(--bg);
  display: flex; flex-direction: column; max-width: 720px; margin: 0 auto;
}
.screen-top {
  display: flex; align-items: center; gap: 4px; padding: calc(env(safe-area-inset-top) + 6px) 8px 4px 4px;
}
.screen-top h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; }
.screen-body { flex: 1; overflow-y: auto; padding-bottom: calc(env(safe-area-inset-bottom) + 16px); }
.screen-foot { padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); border-top: 1px solid var(--line); }
.text-btn { padding: 8px 12px; border-radius: 8px; color: var(--accent); font-size: 15px; }
.text-btn.danger { color: var(--danger); }
.btn {
  height: 42px; padding: 0 18px; border-radius: 21px; border: 1px solid var(--line); font-weight: 600; font-size: 15px;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.wide { width: 100%; height: 48px; border-radius: 24px; }

.arch { display: flex; align-items: center; gap: 10px; padding: 10px 4px 10px 18px; border-bottom: 1px solid var(--line); }
.arch .done-mark { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--circle); display: grid; place-items: center; color: var(--bg); }
.arch .done-mark svg { width: 14px; height: 14px; }
.arch .body { flex: 1; min-width: 0; }
.arch .title { color: var(--muted); text-decoration: line-through; overflow-wrap: anywhere; }
.arch .icon-btn { color: var(--muted); }

.grp { padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--line); }
.grp-row { display: flex; align-items: center; gap: 4px; }
.grp-row input {
  flex: 1; min-width: 0; font-size: 17px; font-weight: 600; border: 0; border-bottom: 1px dashed transparent;
  background: none; padding: 6px 2px; outline: none;
}
.grp-row input:focus { border-bottom-color: var(--accent); }
.grp-sub { display: flex; align-items: center; gap: 10px; padding: 2px 8px 2px 2px; color: var(--muted); font-size: 13px; }
.grp-sub .spacer { flex: 1; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 12px; background: var(--surface2); position: relative; margin: 0; transition: background .15s; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.icon-btn:disabled { opacity: .25; }

/* ---- 下から出るシート ---- */
dialog.sheet {
  width: 100%; max-width: 720px; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--bg); color: var(--text);
  max-height: 90dvh;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .35); }
dialog.sheet[open] { animation: up .2s ease; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
dialog.sheet form { padding: 8px 20px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 8px; }
.grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 8px; }
.label { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 8px; }
.field {
  width: 100%; height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px;
  background: var(--bg); outline: none; font-size: 16px;
}
.field:focus { border-color: var(--accent); }
.field.big { font-size: 18px; height: 52px; }
.chips-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-wrap:empty { display: none; }
.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.spacer { flex: 1; }
.date-chip-input { position: relative; }
.date-chip-input input { position: absolute; inset: 0; opacity: 0; width: 100%; }

/* ---- メニュー・トースト ---- */
.menu {
  position: fixed; z-index: 30; min-width: 170px; padding: 6px 0; border-radius: 12px;
  background: var(--bg); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.menu button { display: block; width: 100%; text-align: left; padding: 11px 18px; font-size: 15px; }
.menu button:active { background: var(--surface2); }
.hidden-date { position: fixed; bottom: 0; left: 50%; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.toast {
  position: fixed; z-index: 40; left: 12px; right: 12px; max-width: 560px; margin: 0 auto;
  bottom: calc(var(--addbar-h, 80px) + 12px);
  display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 16px; border-radius: 12px;
  background: #2b2e35; color: #fff; box-shadow: var(--shadow); font-size: 14px;
}
.toast span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { color: #9cbcff; font-weight: 700; padding: 6px 10px; }
.offline-dot { position: fixed; top: calc(env(safe-area-inset-top) + 4px); left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); }
