:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1c1e24;
  --sub: #6b7080;
  --line: #e3e5ec;
  --accent: #4f8cff;
  --danger: #e5484d;
  --done: #9aa0ad;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121317;
    --card: #1d1f25;
    --text: #eceef3;
    --sub: #9aa0ad;
    --line: #2c2f37;
    --done: #6b7080;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea { -webkit-user-select: text; user-select: text; }
button { cursor: pointer; }
.loading { text-align: center; color: var(--sub); margin-top: 40vh; }

/* ---------- 共通部品 ---------- */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.center-page {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(48px + var(--safe-top)) 16px 32px;
}
.center-page h1 { font-size: 24px; margin: 0 0 4px; text-align: center; }
.center-page .lead { text-align: center; color: var(--sub); margin: 0 0 24px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 64px; }
.btn {
  display: block;
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn:disabled { opacity: .5; }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.danger.armed { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn + .btn { margin-top: 10px; }
.link { background: none; border: 0; color: var(--accent); padding: 8px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.5em; margin: 4px 0 8px; }
.hint { font-size: 13px; color: var(--sub); margin: 4px 0 0; }
.divider { height: 1px; background: var(--line); margin: 20px 0; }
.card-title { font-weight: 700; margin: 0 0 12px; }
.card .hint:last-child { text-align: center; margin-top: 10px; }
.notice { margin-bottom: 16px; border: 1px solid var(--accent); }
.notice .hint { text-align: left !important; }
.or { text-align: center; color: var(--sub); font-size: 13px; margin: 16px 0; }
.code-input { text-transform: uppercase; letter-spacing: .15em; }

.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.colors label { position: relative; }
.colors input { position: absolute; opacity: 0; }
.colors span {
  display: block; width: 36px; height: 36px; border-radius: 50%;
  background: var(--c); border: 3px solid transparent;
}
.colors input:checked + span { border-color: var(--text); }
/* 好きな色：まだ選んでいないときは虹色、選んだらその色の周りに虹色の輪 */
.colors .custom span {
  background: conic-gradient(#ff3b30, #ff9f0a, #ffd60a, #34c759, #5ac8fa, #4f8cff, #af52de, #ff3b30);
}
.colors .custom.picked span {
  background:
    radial-gradient(circle, var(--c) 0 58%, transparent 60%),
    conic-gradient(#ff3b30, #ff9f0a, #ffd60a, #34c759, #5ac8fa, #4f8cff, #af52de, #ff3b30);
}
.colors .custom input[type="color"] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; cursor: pointer;
}

.segment { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.segment button {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; color: var(--sub);
}
.segment button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.segment button:disabled { opacity: .4; }

/* ---------- メイン画面 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(12px + var(--safe-top)) 16px 10px;
  background: var(--bg);
}
.topbar h1 { font-size: 22px; margin: 0; flex: 1; }
.topbar select {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 8px; font-size: 14px;
}
.icon-btn { border: 0; background: none; font-size: 20px; padding: 4px 6px; }

.list { padding: 0 16px calc(150px + var(--safe-bottom)); }
.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.task {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--card); border-radius: 12px; padding: 12px; box-shadow: var(--shadow);
}
.task .check {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent; color: #fff; font-size: 14px; line-height: 1; padding: 0;
}
.task.done .check { background: var(--done); border-color: var(--done); }
.task .body { flex: 1; min-width: 0; }
.task .title { word-break: break-word; }
.task.done .title { color: var(--done); text-decoration: line-through; }
.task .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 13px; color: var(--sub); margin-top: 2px; }
.task .meta .overdue { color: var(--danger); font-weight: 600; }
.task .bell { flex: none; border: 0; background: none; font-size: 20px; padding: 0 2px; opacity: .35; touch-action: manipulation; -webkit-touch-callout: none; }
.task .bell.on { opacity: 1; }
.who {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  color: var(--text); font-weight: 600;
}
.who::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.arrow { color: var(--sub); }

.empty { text-align: center; color: var(--sub); padding: 48px 0; }
.done-group { margin-top: 20px; }
.done-group summary { color: var(--sub); font-size: 14px; padding: 6px 0; list-style: none; }
.done-group summary::-webkit-details-marker { display: none; }
.done-group summary::before { content: "▸ "; }
.done-group[open] summary::before { content: "▾ "; }
.done-group .tasks { margin-top: 6px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; padding: 8px 0 6px; color: var(--sub); font-size: 11px;
}
.tabbar button b { display: block; font-size: 22px; font-weight: normal; line-height: 1.2; }
.tabbar button.on { color: var(--accent); font-weight: 600; }
.fab {
  position: fixed; right: 16px; bottom: calc(72px + var(--safe-bottom)); z-index: 6;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 4px 12px rgba(79, 140, 255, .4);
}

/* ---------- 下から出るシート ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + var(--safe-bottom));
  animation: up .2s ease-out;
}
.sheet-head { display: flex; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; font-size: 17px; margin: 0; text-align: center; }
.sheet-head button { min-width: 64px; }
.section-title { font-size: 13px; color: var(--sub); margin: 18px 0 8px; }
.notify-box { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; }
.row {
  display: flex; align-items: center; gap: 10px; min-height: 46px;
}
.row + .row { border-top: 1px solid var(--line); }
.row > span { flex: 1; }
.row small { display: block; color: var(--sub); font-size: 12px; }
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.row input[type="datetime-local"] { width: auto; padding: 6px 8px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i {
  position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .2s;
}
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}
.switch input:checked + i { background: #34c759; }
.switch input:checked + i::after { transform: translateX(20px); }
.invite-code {
  font-size: 32px; font-weight: 700; letter-spacing: .2em; text-align: center;
  padding: 12px; background: var(--bg); border-radius: 10px; -webkit-user-select: all; user-select: all;
}
.members { display: flex; gap: 8px; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(140px + var(--safe-bottom)); z-index: 30;
  transform: translateX(-50%) translateY(10px);
  background: rgba(30, 32, 38, .92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
