:root {
  --bg: #faf7f9;
  --surface: #ffffff;
  --surface-2: #f3eef2;
  --text: #221a20;
  --muted: #7a6d76;
  --line: #e6dce3;
  --accent: #e4007f;
  --accent-ink: #ffffff;
  --ok: #1f9d55;
  --warn: #c77700;
  --danger: #d02a2a;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17131a;
    --surface: #221c25;
    --surface-2: #2c2530;
    --text: #f1eaf0;
    --muted: #a99ca6;
    --line: #3a3140;
    --accent: #ff4fa8;
    --accent-ink: #1b0010;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%;
}
input[type=checkbox], input[type=radio], input[type=color] { width: auto; }
input[type=color] { padding: 0; height: 34px; width: 44px; border: none; background: none; }
textarea { min-height: 140px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--text); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }

header.top {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 8px 16px; flex-wrap: wrap;
}
header.top .brand { font-weight: 700; color: var(--accent); margin-right: 6px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav.tabs a {
  text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; position: relative;
}
nav.tabs a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 18px;
  background: var(--accent); color: var(--accent-ink); text-align: center; font-weight: 700;
}
main { padding: 16px; max-width: 1200px; margin: 0 auto; }
h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 8px; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.pending { background: #fff3d6; color: #8a5a00; border-color: #f0d38a; }
@media (prefers-color-scheme: dark) { .pending { background: #3b2e10; color: #ffcf6b; border-color: #5c4718; } }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: none; }
table { border-collapse: collapse; width: 100%; }
td, th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.plus { color: var(--ok); } .minus { color: var(--danger); }

/* ---------- カレンダー */
.cal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.cal-head h2 { margin: 0; min-width: 120px; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.legend .chip { cursor: pointer; user-select: none; }
.legend .chip.off { opacity: .4; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: var(--surface); text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal .dow.sun, .day.sun .dnum { color: #d0342c; }
.cal .dow.sat, .day.sat .dnum { color: #1c62c7; }
.day { background: var(--surface); min-height: 108px; padding: 3px; display: flex; flex-direction: column; gap: 2px; min-width: 0; cursor: pointer; }
.day.other { background: var(--surface-2); }
.day.other > * { opacity: .55; }
.day.today .dnum { background: var(--accent); color: var(--accent-ink); border-radius: 50%; width: 22px; text-align: center; }
.dnum { font-size: 12px; font-weight: 600; line-height: 22px; height: 22px; padding: 0 3px; }
.vac { font-size: 10px; line-height: 14px; border-radius: 3px; padding: 0 3px; background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, transparent 4px 8px); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px dashed var(--line); }
.ev {
  font-size: 11px; line-height: 15px; border-radius: 4px; padding: 1px 4px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 0 2px rgba(0,0,0,.45); cursor: pointer; border: 1px solid transparent;
}
.ev.suggested { opacity: .55; border: 1px dashed rgba(255,255,255,.9); }
.ev.mine { box-shadow: inset 0 0 0 2px rgba(255,255,255,.85); font-weight: 700; }
.ev .ic { margin-right: 2px; }
/* メンバーの参加マーク: 行く=塗り、行きたい=輪 */
i.m { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(255,255,255,.9); }
i.m.going { background: var(--c); }
i.m.wish { background: transparent; border: 2px solid var(--c); }
.att { display: inline-flex; gap: 2px; margin-right: 3px; vertical-align: middle; }
.legend i.m { box-shadow: none; }
.more { font-size: 11px; color: var(--muted); padding-left: 3px; }
@media (max-width: 700px) {
  main { padding: 10px; }
  header.top { padding: 6px 10px 0; gap: 4px 8px; }
  header.top .brand { flex: 1; }
  nav.tabs { order: 3; flex-basis: 100%; margin: 0 -10px; padding: 0 6px 4px; }
  nav.tabs a { padding: 6px 8px; font-size: 14px; }
  .day { min-height: 76px; padding: 2px; }
  .ev { font-size: 10px; padding: 0 2px; }
  .ev .t, .ev .ic { display: none; }
}

/* ---------- 一覧カード */
.evcard { display: flex; gap: 10px; align-items: flex-start; }
.evcard .bar { width: 6px; align-self: stretch; border-radius: 3px; flex: none; }
.evcard .body { flex: 1; min-width: 0; }
.evcard .title { font-weight: 600; cursor: pointer; }
.evcard .meta { font-size: 13px; color: var(--muted); }
.diff { font-size: 13px; }
.diff del { color: var(--danger); } .diff ins { color: var(--ok); text-decoration: none; font-weight: 600; }
.trace { font-size: 12px; color: var(--muted); padding-left: 18px; margin: 6px 0; }
.cand { border-left: 4px solid var(--accent); }

/* ---------- モーダル */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 14px; width: 100%; max-width: 680px; padding: 18px; box-shadow: var(--shadow); position: relative; }
.modal-card .close { position: absolute; right: 10px; top: 10px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: var(--surface); padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.field-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: end; }
.field-row .tbd { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 3px; padding-bottom: 8px; white-space: nowrap; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; align-items: center; gap: 4px; color: var(--text); font-size: 14px; }

/* ---------- 登録グループ管理（コンパクトなタイル） */
.gtiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; margin-bottom: 10px; }
.gtile {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.gtile:hover, .gtile:focus-visible { border-color: var(--muted); outline: none; }
.gtile.unfollowed { opacity: .55; }
.gsw { width: 14px; height: 36px; border-radius: 4px; flex: none; }
.gbody { flex: 1; min-width: 0; }
.gname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gmeta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gmeta .warn { color: var(--warn); }
.gfollow { display: flex; flex-direction: column; align-items: center; font-size: 10px; color: var(--muted); flex: none; cursor: pointer; }
.gfollow input { margin: 0 0 2px; width: 18px; height: 18px; }
.gtile[hidden] { display: none; }
@media (max-width: 700px) {
  .gtiles { gap: 6px; }
  .gtile { padding: 5px 10px; gap: 8px; }
  .gsw { height: 28px; width: 10px; }
}

.auth { max-width: 360px; margin: 10vh auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: 90vw; }
.toast[hidden] { display: none; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }
details > summary { cursor: pointer; color: var(--muted); font-size: 13px; }
